-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added dynamic TargetDescription
#3780
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "TargetDescription.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put
on the first line like our other .cc files. |
||
#include "GdbServerConnection.h" | ||
#include "kernel_abi.h" | ||
#include <sstream> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Order #includes like our other files: first |
||
namespace rr { | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class FeatureStream { | ||
std::stringstream stream{}; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const char* arch_prefix{nullptr}; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public: | ||
std::string result() noexcept { return stream.str(); } | ||
|
||
template <typename Any> | ||
friend FeatureStream& operator<<(FeatureStream& stream, Any any) noexcept; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
template <typename Any> | ||
FeatureStream& operator<<(FeatureStream& stream, Any any) noexcept { | ||
stream.stream << any; | ||
return stream; | ||
} | ||
|
||
template <> | ||
FeatureStream& operator<<(FeatureStream& stream, | ||
rr::SupportedArch arch) noexcept { | ||
stream << "<architecture>"; | ||
switch (arch) { | ||
case rr::x86: | ||
stream << "i386"; | ||
stream.arch_prefix = "32bit-"; | ||
break; | ||
case rr::x86_64: | ||
stream << "i386:x86-64"; | ||
stream.arch_prefix = "64bit-"; | ||
break; | ||
case rr::aarch64: | ||
stream << "aarch64"; | ||
stream.arch_prefix = "aarch64-"; | ||
break; | ||
} | ||
stream << "</architecture>\n"; | ||
return stream; | ||
} | ||
|
||
template <> | ||
FeatureStream& operator<<(FeatureStream& stream, | ||
TargetFeature feature) noexcept { | ||
DEBUG_ASSERT(stream.arch_prefix != nullptr && | ||
"No architecture has been provided to description"); | ||
stream << R"( <xi:include href=")" << stream.arch_prefix; | ||
switch (feature) { | ||
case TargetFeature::Core: | ||
stream << "core.xml"; | ||
break; | ||
case TargetFeature::Linux: | ||
stream << "linux.xml"; | ||
break; | ||
case TargetFeature::SSE: | ||
stream << "sse.xml"; | ||
break; | ||
case TargetFeature::AVX: | ||
stream << "avx.xml"; | ||
break; | ||
case TargetFeature::PKeys: | ||
stream << "pkeys.xml"; | ||
break; | ||
case TargetFeature::Segment: | ||
stream << "seg.xml"; | ||
break; | ||
} | ||
stream << R"("/>)" << '\n'; | ||
return stream; | ||
} | ||
|
||
TargetDescription::TargetDescription(rr::SupportedArch arch, | ||
u32 cpu_features) noexcept | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: arch(arch), target_features() { | ||
|
||
// default-assumed registers per arch | ||
switch (arch) { | ||
case rr::x86: | ||
target_features.push_back(TargetFeature::Core); | ||
target_features.push_back(TargetFeature::SSE); | ||
target_features.push_back(TargetFeature::Linux); | ||
break; | ||
case rr::x86_64: | ||
target_features.push_back(TargetFeature::Core); | ||
target_features.push_back(TargetFeature::SSE); | ||
target_features.push_back(TargetFeature::Linux); | ||
target_features.push_back(TargetFeature::Segment); | ||
break; | ||
case rr::aarch64: | ||
target_features.push_back(TargetFeature::Core); | ||
break; | ||
} | ||
|
||
if (cpu_features & rr::GdbServerConnection::CPU_AVX) { | ||
DEBUG_ASSERT((arch == rr::x86 || arch == rr::x86_64) && "unexpected arch"); | ||
target_features.push_back(TargetFeature::AVX); | ||
} | ||
|
||
if (cpu_features & rr::GdbServerConnection::CPU_PKU) { | ||
DEBUG_ASSERT((arch == rr::x86 || arch == rr::x86_64) && "unexpected arch"); | ||
target_features.push_back(TargetFeature::PKeys); | ||
} | ||
} | ||
|
||
static constexpr auto Header = R"(<?xml version="1.0"?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... or else just write it inline, that's fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to |
||
<!DOCTYPE target SYSTEM "gdb-target.dtd"> | ||
<target> | ||
)"; | ||
|
||
std::string TargetDescription::to_xml() const noexcept { | ||
FeatureStream fs{}; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fs << Header << arch << "<osabi>GNU/Linux</osabi>\n"; | ||
for (const auto feature : target_features) { | ||
fs << feature; | ||
} | ||
fs << "</target>"; | ||
|
||
return fs.result(); | ||
} | ||
} // namespace rr |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use this. Use #define guards instead like our other .h files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, put
on the first line like our other source files. |
||
#include "kernel_abi.h" | ||
#include <cstdint> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, reorder these includes. |
||
|
||
namespace rr { | ||
|
||
struct GdbServerRegisterValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove this since it's not used. |
||
|
||
using u32 = std::uint32_t; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
enum class TargetFeature : u32 { | ||
Core = 0, | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SSE, | ||
Linux, | ||
Segment, | ||
AVX, | ||
PKeys | ||
}; | ||
|
||
class TargetDescription { | ||
SupportedArch arch; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::vector<TargetFeature> target_features; | ||
public: | ||
explicit TargetDescription(rr::SupportedArch arch, u32 cpu_features) noexcept; | ||
theIDinside marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::string to_xml() const noexcept; | ||
}; | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just drop this hunk.