Skip to content

Commit

Permalink
Fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
theIDinside committed Nov 19, 2024
1 parent d18f874 commit 25c7506
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 41 deletions.
17 changes: 8 additions & 9 deletions src/GdbServerConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ GdbServerConnection::GdbServerConnection(ThreadGroupUid tguid, const Features& f
multiprocess_supported_(false),
hwbreak_supported_(false),
swbreak_supported_(false),
list_threads_in_stop_reply_(false) {
list_threads_in_stop_reply_(false),
target_description(nullptr) {
#ifndef REVERSE_EXECUTION
features_.reverse_execution = false;
#endif
Expand Down Expand Up @@ -112,8 +113,7 @@ unique_ptr<GdbServerConnection> GdbServerConnection::await_connection(
Task* t, ScopedFd& listen_fd, const GdbServerConnection::Features& features) {
auto dbg = unique_ptr<GdbServerConnection>(
new GdbServerConnection(t->thread_group()->tguid(), features));
const auto arch = t->arch();
dbg->set_cpu_features(arch, get_cpu_features(arch));
dbg->set_cpu_features(t->arch());
dbg->await_debugger(listen_fd);
return dbg;
}
Expand Down Expand Up @@ -588,7 +588,7 @@ bool GdbServerConnection::xfer(const char* name, char* args) {
return false;
}

const auto desc = (strcmp(annex, "") && strcmp(annex, "target.xml") ? read_target_desc(annex) : target_decription->to_xml());
const auto desc = strcmp(annex, "") && strcmp(annex, "target.xml") ? read_target_desc(annex) : target_description->to_xml();
write_xfer_response(desc.c_str(), desc.size(), offset, len);
return false;
}
Expand Down Expand Up @@ -2311,12 +2311,11 @@ bool GdbServerConnection::is_connection_alive() { return connection_alive_; }

bool GdbServerConnection::is_pass_signal(int sig) { return pass_signals.find(to_gdb_signum(sig)) != pass_signals.end(); }

void GdbServerConnection::set_cpu_features(SupportedArch arch,
uint32_t features) {
cpu_features_ = features;
DEBUG_ASSERT(target_decription == nullptr &&
void GdbServerConnection::set_cpu_features(SupportedArch arch) {
cpu_features_ = get_cpu_features(arch);
DEBUG_ASSERT(target_description == nullptr &&
"Target description already created");
target_decription = std::make_unique<TargetDescription>(arch, cpu_features_);
target_description = std::make_unique<TargetDescription>(arch, cpu_features_);
}

} // namespace rr
4 changes: 2 additions & 2 deletions src/GdbServerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class GdbServerConnection {
CPU_PKU = 0x8
};

void set_cpu_features(SupportedArch arch, uint32_t features);
void set_cpu_features(SupportedArch arch);
uint32_t cpu_features() const { return cpu_features_; }

GdbServerConnection(ThreadGroupUid tguid, const Features& features);
Expand Down Expand Up @@ -879,7 +879,7 @@ class GdbServerConnection {
bool hwbreak_supported_; // client supports hwbreak extension
bool swbreak_supported_; // client supports swbreak extension
bool list_threads_in_stop_reply_; // client requested threads: and thread-pcs: in stop replies
std::unique_ptr<TargetDescription> target_decription{nullptr};
std::unique_ptr<TargetDescription> target_description;
};

} // namespace rr
Expand Down
30 changes: 15 additions & 15 deletions src/TargetDescription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
#include "GdbServerConnection.h"
#include "kernel_abi.h"
#include <sstream>

namespace rr {

class FeatureStream {
std::stringstream stream{};
const char* arch_prefix{nullptr};

public:
std::string result() noexcept { return stream.str(); }
std::string result() { return stream.str(); }

template <typename Any>
friend FeatureStream& operator<<(FeatureStream& stream, Any any) noexcept;
friend FeatureStream& operator<<(FeatureStream& stream, Any any);

private:
std::stringstream stream;
const char* arch_prefix;
};

template <typename Any>
FeatureStream& operator<<(FeatureStream& stream, Any any) noexcept {
FeatureStream& operator<<(FeatureStream& stream, Any any) {
stream.stream << any;
return stream;
}

template <>
FeatureStream& operator<<(FeatureStream& stream,
rr::SupportedArch arch) noexcept {
FeatureStream& operator<<(FeatureStream& stream, rr::SupportedArch arch) {
stream << "<architecture>";
switch (arch) {
case rr::x86:
Expand All @@ -44,8 +45,7 @@ FeatureStream& operator<<(FeatureStream& stream,
}

template <>
FeatureStream& operator<<(FeatureStream& stream,
TargetFeature feature) noexcept {
FeatureStream& operator<<(FeatureStream& stream, TargetFeature feature) {
DEBUG_ASSERT(stream.arch_prefix != nullptr &&
"No architecture has been provided to description");
stream << R"( <xi:include href=")" << stream.arch_prefix;
Expand Down Expand Up @@ -77,7 +77,7 @@ FeatureStream& operator<<(FeatureStream& stream,
}

TargetDescription::TargetDescription(rr::SupportedArch arch,
u32 cpu_features) noexcept
uint32_t cpu_features)
: arch(arch), target_features() {

// default-assumed registers per arch
Expand Down Expand Up @@ -110,14 +110,14 @@ TargetDescription::TargetDescription(rr::SupportedArch arch,
}
}

static constexpr auto Header = R"(<?xml version="1.0"?>
static const char header[] = R"(<?xml version="1.0"?>
<!DOCTYPE target SYSTEM "gdb-target.dtd">
<target>
)";

std::string TargetDescription::to_xml() const noexcept {
FeatureStream fs{};
fs << Header << arch << "<osabi>GNU/Linux</osabi>\n";
std::string TargetDescription::to_xml() const {
FeatureStream fs;
fs << header << arch << "<osabi>GNU/Linux</osabi>\n";
for (const auto feature : target_features) {
fs << feature;
}
Expand Down
29 changes: 14 additions & 15 deletions src/TargetDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ namespace rr {

struct GdbServerRegisterValue;

using u32 = std::uint32_t;

enum class TargetFeature : u32 {
Core = 0,
SSE,
Linux,
Segment,
AVX,
PKeys,
FPU,
enum class TargetFeature : uint32_t {
Core = 0,
SSE,
Linux,
Segment,
AVX,
PKeys,
FPU,
};

class TargetDescription {
SupportedArch arch;
std::vector<TargetFeature> target_features;
SupportedArch arch;
std::vector<TargetFeature> target_features;

public:
explicit TargetDescription(rr::SupportedArch arch, u32 cpu_features) noexcept;
std::string to_xml() const noexcept;
explicit TargetDescription(rr::SupportedArch arch, uint32_t cpu_features);
std::string to_xml() const;
};
}
} // namespace rr

0 comments on commit 25c7506

Please sign in to comment.