[Lldb-commits] [lldb] 5849219 - [lldb] [ABI] Apply AugmentRegisterInfo() to DynamicRegisterInfo::Registers
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 11 08:03:25 PDT 2021
Author: Michał Górny
Date: 2021-10-11T17:02:26+02:00
New Revision: 58492191265759e952a032c0de48a9231c526b55
URL: https://github.com/llvm/llvm-project/commit/58492191265759e952a032c0de48a9231c526b55
DIFF: https://github.com/llvm/llvm-project/commit/58492191265759e952a032c0de48a9231c526b55.diff
LOG: [lldb] [ABI] Apply AugmentRegisterInfo() to DynamicRegisterInfo::Registers
Call ABI::AugmentRegisterInfo() once with a vector of all defined
registers rather than calling it for every individual register. Move
and rename RemoteRegisterInfo from gdb-remote to
DynamicRegisterInfo::Register, and use this class when augmenting
registers.
Differential Revision: https://reviews.llvm.org/D111142
Added:
Modified:
lldb/include/lldb/Target/ABI.h
lldb/include/lldb/Target/DynamicRegisterInfo.h
lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
lldb/source/Target/ABI.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/ABI.h b/lldb/include/lldb/Target/ABI.h
index 8fbb6aae68c4c..8ac6003554d5e 100644
--- a/lldb/include/lldb/Target/ABI.h
+++ b/lldb/include/lldb/Target/ABI.h
@@ -11,6 +11,7 @@
#include "lldb/Core/PluginInterface.h"
#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/DynamicRegisterInfo.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-private.h"
@@ -127,7 +128,8 @@ class ABI : public PluginInterface {
llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
- virtual void AugmentRegisterInfo(RegisterInfo &info) = 0;
+ virtual void
+ AugmentRegisterInfo(std::vector<DynamicRegisterInfo::Register> ®s) = 0;
virtual bool GetPointerReturnRegister(const char *&name) { return false; }
@@ -159,7 +161,8 @@ class ABI : public PluginInterface {
class RegInfoBasedABI : public ABI {
public:
- void AugmentRegisterInfo(RegisterInfo &info) override;
+ void AugmentRegisterInfo(
+ std::vector<DynamicRegisterInfo::Register> ®s) override;
protected:
using ABI::ABI;
@@ -171,12 +174,14 @@ class RegInfoBasedABI : public ABI {
class MCBasedABI : public ABI {
public:
- void AugmentRegisterInfo(RegisterInfo &info) override;
+ void AugmentRegisterInfo(
+ std::vector<DynamicRegisterInfo::Register> ®s) override;
/// If the register name is of the form "<from_prefix>[<number>]" then change
/// the name to "<to_prefix>[<number>]". Otherwise, leave the name unchanged.
static void MapRegisterName(std::string ®, llvm::StringRef from_prefix,
- llvm::StringRef to_prefix);
+ llvm::StringRef to_prefix);
+
protected:
using ABI::ABI;
diff --git a/lldb/include/lldb/Target/DynamicRegisterInfo.h b/lldb/include/lldb/Target/DynamicRegisterInfo.h
index 1bc6b1dccc296..9a115802394bf 100644
--- a/lldb/include/lldb/Target/DynamicRegisterInfo.h
+++ b/lldb/include/lldb/Target/DynamicRegisterInfo.h
@@ -24,6 +24,22 @@ class DynamicRegisterInfo {
DynamicRegisterInfo &operator=(DynamicRegisterInfo &) = default;
public:
+ struct Register {
+ ConstString name;
+ ConstString alt_name;
+ ConstString set_name;
+ uint32_t byte_size = LLDB_INVALID_INDEX32;
+ uint32_t byte_offset = LLDB_INVALID_INDEX32;
+ lldb::Encoding encoding = lldb::eEncodingUint;
+ lldb::Format format = lldb::eFormatHex;
+ uint32_t regnum_dwarf = LLDB_INVALID_REGNUM;
+ uint32_t regnum_ehframe = LLDB_INVALID_REGNUM;
+ uint32_t regnum_generic = LLDB_INVALID_REGNUM;
+ uint32_t regnum_remote = LLDB_INVALID_REGNUM;
+ std::vector<uint32_t> value_regs;
+ std::vector<uint32_t> invalidate_regs;
+ };
+
DynamicRegisterInfo() = default;
DynamicRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
diff --git a/lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
index 66a38ab6e3e99..f3165999f7e5f 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
+++ b/lldb/source/Plugins/ABI/AArch64/ABIAArch64.cpp
@@ -71,10 +71,14 @@ uint32_t ABIAArch64::GetGenericNum(llvm::StringRef name) {
.Default(LLDB_INVALID_REGNUM);
}
-void ABIAArch64::AugmentRegisterInfo(lldb_private::RegisterInfo &info) {
- lldb_private::MCBasedABI::AugmentRegisterInfo(info);
+void ABIAArch64::AugmentRegisterInfo(
+ std::vector<lldb_private::DynamicRegisterInfo::Register> ®s) {
+ lldb_private::MCBasedABI::AugmentRegisterInfo(regs);
- // GDB sends x31 as "sp". Add the "x31" alt_name for convenience.
- if (!strcmp(info.name, "sp") && !info.alt_name)
- info.alt_name = "x31";
+ lldb_private::ConstString sp_string{"sp"};
+ for (lldb_private::DynamicRegisterInfo::Register &info : regs) {
+ // GDB sends x31 as "sp". Add the "x31" alt_name for convenience.
+ if (info.name == sp_string && !info.alt_name)
+ info.alt_name.SetCString("x31");
+ }
}
diff --git a/lldb/source/Plugins/ABI/AArch64/ABIAArch64.h b/lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
index 13dcfdd4c6d74..e771f69d7dbc7 100644
--- a/lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
+++ b/lldb/source/Plugins/ABI/AArch64/ABIAArch64.h
@@ -11,7 +11,7 @@
#include "lldb/Target/ABI.h"
-class ABIAArch64: public lldb_private::MCBasedABI {
+class ABIAArch64 : public lldb_private::MCBasedABI {
public:
static void Initialize();
static void Terminate();
@@ -31,7 +31,8 @@ class ABIAArch64: public lldb_private::MCBasedABI {
uint32_t GetGenericNum(llvm::StringRef name) override;
- void AugmentRegisterInfo(lldb_private::RegisterInfo &info) override;
+ void AugmentRegisterInfo(
+ std::vector<lldb_private::DynamicRegisterInfo::Register> ®s) override;
using lldb_private::MCBasedABI::MCBasedABI;
};
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 74bebcd1df4c3..80c3b957a16e7 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -442,7 +442,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
return;
char packet[128];
- std::vector<RemoteRegisterInfo> registers;
+ std::vector<DynamicRegisterInfo::Register> registers;
uint32_t reg_num = 0;
for (StringExtractorGDBRemote::ResponseType response_type =
StringExtractorGDBRemote::eResponse;
@@ -458,7 +458,7 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
if (response_type == StringExtractorGDBRemote::eResponse) {
llvm::StringRef name;
llvm::StringRef value;
- RemoteRegisterInfo reg_info;
+ DynamicRegisterInfo::Register reg_info;
while (response.GetNameColonValue(name, value)) {
if (name.equals("name")) {
@@ -4223,7 +4223,7 @@ struct GdbServerTargetInfo {
};
bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
- std::vector<RemoteRegisterInfo> ®isters) {
+ std::vector<DynamicRegisterInfo::Register> ®isters) {
if (!feature_node)
return false;
@@ -4231,7 +4231,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
"reg", [&target_info, ®isters](const XMLNode ®_node) -> bool {
std::string gdb_group;
std::string gdb_type;
- RemoteRegisterInfo reg_info;
+ DynamicRegisterInfo::Register reg_info;
bool encoding_set = false;
bool format_set = false;
@@ -4356,7 +4356,8 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
// for nested register definition files. It returns true if it was able
// to fetch and parse an xml file.
bool ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess(
- ArchSpec &arch_to_use, std::string xml_filename, std::vector<RemoteRegisterInfo> ®isters) {
+ ArchSpec &arch_to_use, std::string xml_filename,
+ std::vector<DynamicRegisterInfo::Register> ®isters) {
// request the target xml file
llvm::Expected<std::string> raw = m_gdb_comm.ReadExtFeature("features", xml_filename);
if (errorToBool(raw.takeError()))
@@ -4466,16 +4467,12 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess(
}
void ProcessGDBRemote::AddRemoteRegisters(
- std::vector<RemoteRegisterInfo> ®isters, const ArchSpec &arch_to_use) {
- // Don't use Process::GetABI, this code gets called from DidAttach, and
- // in that context we haven't set the Target's architecture yet, so the
- // ABI is also potentially incorrect.
- ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use);
-
+ std::vector<DynamicRegisterInfo::Register> ®isters,
+ const ArchSpec &arch_to_use) {
std::map<uint32_t, uint32_t> remote_to_local_map;
uint32_t remote_regnum = 0;
for (auto it : llvm::enumerate(registers)) {
- RemoteRegisterInfo &remote_reg_info = it.value();
+ DynamicRegisterInfo::Register &remote_reg_info = it.value();
// Assign successive remote regnums if missing.
if (remote_reg_info.regnum_remote == LLDB_INVALID_REGNUM)
@@ -4487,10 +4484,7 @@ void ProcessGDBRemote::AddRemoteRegisters(
remote_regnum = remote_reg_info.regnum_remote + 1;
}
- for (auto it : llvm::enumerate(registers)) {
- uint32_t local_regnum = it.index();
- RemoteRegisterInfo &remote_reg_info = it.value();
-
+ for (DynamicRegisterInfo::Register &remote_reg_info : registers) {
auto proc_to_lldb = [&remote_to_local_map](uint32_t process_regnum) {
auto lldb_regit = remote_to_local_map.find(process_regnum);
return lldb_regit != remote_to_local_map.end() ? lldb_regit->second
@@ -4501,6 +4495,17 @@ void ProcessGDBRemote::AddRemoteRegisters(
remote_reg_info.value_regs.begin(), proc_to_lldb);
llvm::transform(remote_reg_info.invalidate_regs,
remote_reg_info.invalidate_regs.begin(), proc_to_lldb);
+ }
+
+ // Don't use Process::GetABI, this code gets called from DidAttach, and
+ // in that context we haven't set the Target's architecture yet, so the
+ // ABI is also potentially incorrect.
+ if (ABISP abi_sp = ABI::FindPlugin(shared_from_this(), arch_to_use))
+ abi_sp->AugmentRegisterInfo(registers);
+
+ for (auto it : llvm::enumerate(registers)) {
+ uint32_t local_regnum = it.index();
+ DynamicRegisterInfo::Register &remote_reg_info = it.value();
auto regs_with_sentinel = [](std::vector<uint32_t> &vec) -> uint32_t * {
if (!vec.empty()) {
@@ -4520,9 +4525,6 @@ void ProcessGDBRemote::AddRemoteRegisters(
regs_with_sentinel(remote_reg_info.value_regs),
regs_with_sentinel(remote_reg_info.invalidate_regs),
};
-
- if (abi_sp)
- abi_sp->AugmentRegisterInfo(reg_info);
m_register_info_sp->AddRegister(reg_info, remote_reg_info.set_name);
};
@@ -4540,7 +4542,7 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
if (!m_gdb_comm.GetQXferFeaturesReadSupported())
return false;
- std::vector<RemoteRegisterInfo> registers;
+ std::vector<DynamicRegisterInfo::Register> registers;
if (GetGDBServerRegisterInfoXMLAndProcess(arch_to_use, "target.xml",
registers))
AddRemoteRegisters(registers, arch_to_use);
@@ -4590,14 +4592,12 @@ llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() {
root_element.ForEachChildElementWithName(
"library", [log, &list](const XMLNode &library) -> bool {
-
LoadedModuleInfoList::LoadedModuleInfo module;
// FIXME: we're silently ignoring invalid data here
library.ForEachAttribute(
[&module](const llvm::StringRef &name,
const llvm::StringRef &value) -> bool {
-
uint64_t uint_value = LLDB_INVALID_ADDRESS;
if (name == "name")
module.set_name(value.str());
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index e61702227a34e..ce74b34974aa0 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -19,6 +19,7 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/ThreadSafeValue.h"
#include "lldb/Host/HostThread.h"
+#include "lldb/Target/DynamicRegisterInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/ArchSpec.h"
@@ -44,22 +45,6 @@ class Loader;
}
namespace process_gdb_remote {
-struct RemoteRegisterInfo {
- ConstString name;
- ConstString alt_name;
- ConstString set_name;
- uint32_t byte_size = LLDB_INVALID_INDEX32;
- uint32_t byte_offset = LLDB_INVALID_INDEX32;
- lldb::Encoding encoding = lldb::eEncodingUint;
- lldb::Format format = lldb::eFormatHex;
- uint32_t regnum_dwarf = LLDB_INVALID_REGNUM;
- uint32_t regnum_ehframe = LLDB_INVALID_REGNUM;
- uint32_t regnum_generic = LLDB_INVALID_REGNUM;
- uint32_t regnum_remote = LLDB_INVALID_REGNUM;
- std::vector<uint32_t> value_regs;
- std::vector<uint32_t> invalidate_regs;
-};
-
class ThreadGDBRemote;
class ProcessGDBRemote : public Process,
@@ -411,11 +396,11 @@ class ProcessGDBRemote : public Process,
bool GetGDBServerRegisterInfoXMLAndProcess(
ArchSpec &arch_to_use, std::string xml_filename,
- std::vector<RemoteRegisterInfo> ®isters);
+ std::vector<DynamicRegisterInfo::Register> ®isters);
- // Convert RemoteRegisterInfos into RegisterInfos and add to the dynamic
- // register list.
- void AddRemoteRegisters(std::vector<RemoteRegisterInfo> ®isters,
+ // Convert DynamicRegisterInfo::Registers into RegisterInfos and add
+ // to the dynamic register list.
+ void AddRemoteRegisters(std::vector<DynamicRegisterInfo::Register> ®isters,
const ArchSpec &arch_to_use);
// Query remote GDBServer for register information
bool GetGDBServerRegisterInfo(ArchSpec &arch);
diff --git a/lldb/source/Target/ABI.cpp b/lldb/source/Target/ABI.cpp
index 03810cdcd6523..6e8772cbd1427 100644
--- a/lldb/source/Target/ABI.cpp
+++ b/lldb/source/Target/ABI.cpp
@@ -214,33 +214,39 @@ std::unique_ptr<llvm::MCRegisterInfo> ABI::MakeMCRegisterInfo(const ArchSpec &ar
return info_up;
}
-void RegInfoBasedABI::AugmentRegisterInfo(RegisterInfo &info) {
- if (info.kinds[eRegisterKindEHFrame] != LLDB_INVALID_REGNUM &&
- info.kinds[eRegisterKindDWARF] != LLDB_INVALID_REGNUM)
- return;
-
- RegisterInfo abi_info;
- if (!GetRegisterInfoByName(info.name, abi_info))
- return;
-
- if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
- info.kinds[eRegisterKindEHFrame] = abi_info.kinds[eRegisterKindEHFrame];
- if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
- info.kinds[eRegisterKindDWARF] = abi_info.kinds[eRegisterKindDWARF];
- if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
- info.kinds[eRegisterKindGeneric] = abi_info.kinds[eRegisterKindGeneric];
+void RegInfoBasedABI::AugmentRegisterInfo(
+ std::vector<DynamicRegisterInfo::Register> ®s) {
+ for (DynamicRegisterInfo::Register &info : regs) {
+ if (info.regnum_ehframe != LLDB_INVALID_REGNUM &&
+ info.regnum_dwarf != LLDB_INVALID_REGNUM)
+ continue;
+
+ RegisterInfo abi_info;
+ if (!GetRegisterInfoByName(info.name.GetStringRef(), abi_info))
+ continue;
+
+ if (info.regnum_ehframe == LLDB_INVALID_REGNUM)
+ info.regnum_ehframe = abi_info.kinds[eRegisterKindEHFrame];
+ if (info.regnum_dwarf == LLDB_INVALID_REGNUM)
+ info.regnum_dwarf = abi_info.kinds[eRegisterKindDWARF];
+ if (info.regnum_generic == LLDB_INVALID_REGNUM)
+ info.regnum_generic = abi_info.kinds[eRegisterKindGeneric];
+ }
}
-void MCBasedABI::AugmentRegisterInfo(RegisterInfo &info) {
- uint32_t eh, dwarf;
- std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name);
-
- if (info.kinds[eRegisterKindEHFrame] == LLDB_INVALID_REGNUM)
- info.kinds[eRegisterKindEHFrame] = eh;
- if (info.kinds[eRegisterKindDWARF] == LLDB_INVALID_REGNUM)
- info.kinds[eRegisterKindDWARF] = dwarf;
- if (info.kinds[eRegisterKindGeneric] == LLDB_INVALID_REGNUM)
- info.kinds[eRegisterKindGeneric] = GetGenericNum(info.name);
+void MCBasedABI::AugmentRegisterInfo(
+ std::vector<DynamicRegisterInfo::Register> ®s) {
+ for (DynamicRegisterInfo::Register &info : regs) {
+ uint32_t eh, dwarf;
+ std::tie(eh, dwarf) = GetEHAndDWARFNums(info.name.GetStringRef());
+
+ if (info.regnum_ehframe == LLDB_INVALID_REGNUM)
+ info.regnum_ehframe = eh;
+ if (info.regnum_dwarf == LLDB_INVALID_REGNUM)
+ info.regnum_dwarf = dwarf;
+ if (info.regnum_generic == LLDB_INVALID_REGNUM)
+ info.regnum_generic = GetGenericNum(info.name.GetStringRef());
+ }
}
std::pair<uint32_t, uint32_t>
More information about the lldb-commits
mailing list