diff --git a/src/GdbServerConnection.cc b/src/GdbServerConnection.cc index ebda908395e..eba06202da7 100644 --- a/src/GdbServerConnection.cc +++ b/src/GdbServerConnection.cc @@ -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 @@ -112,8 +113,7 @@ unique_ptr GdbServerConnection::await_connection( Task* t, ScopedFd& listen_fd, const GdbServerConnection::Features& features) { auto dbg = unique_ptr( 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; } @@ -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; } @@ -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(arch, cpu_features_); + target_description = std::make_unique(arch, cpu_features_); } } // namespace rr diff --git a/src/GdbServerConnection.h b/src/GdbServerConnection.h index c9a7273052c..a8a9aa18fc6 100644 --- a/src/GdbServerConnection.h +++ b/src/GdbServerConnection.h @@ -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); @@ -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 target_decription{nullptr}; + std::unique_ptr target_description; }; } // namespace rr diff --git a/src/TargetDescription.cc b/src/TargetDescription.cc index 469a006b13d..4b042579aba 100644 --- a/src/TargetDescription.cc +++ b/src/TargetDescription.cc @@ -2,28 +2,29 @@ #include "GdbServerConnection.h" #include "kernel_abi.h" #include + 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 - friend FeatureStream& operator<<(FeatureStream& stream, Any any) noexcept; + friend FeatureStream& operator<<(FeatureStream& stream, Any any); + +private: + std::stringstream stream; + const char* arch_prefix; }; template -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 << ""; switch (arch) { case rr::x86: @@ -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"( +static const char header[] = R"( )"; -std::string TargetDescription::to_xml() const noexcept { - FeatureStream fs{}; - fs << Header << arch << "GNU/Linux\n"; +std::string TargetDescription::to_xml() const { + FeatureStream fs; + fs << header << arch << "GNU/Linux\n"; for (const auto feature : target_features) { fs << feature; } diff --git a/src/TargetDescription.h b/src/TargetDescription.h index 78c148e810d..469ba8fa164 100644 --- a/src/TargetDescription.h +++ b/src/TargetDescription.h @@ -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 target_features; + SupportedArch arch; + std::vector 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; }; -} \ No newline at end of file +} // namespace rr \ No newline at end of file