Clean up NativeRegisterContext
Summary:
This commit removes the concrete_frame_idx member from
NativeRegisterContext and related functions, which was always set to
zero and never used.
I also change the native thread class to store a NativeRegisterContext
as a unique_ptr (documenting the ownership) and make sure it is always
initialized (most of the code was already blindly dereferencing the
register context pointer, assuming it would always be present -- this
makes its treatment consistent).
Reviewers: eugene, clayborg, krytarowski
Subscribers: aemerson, sdardis, nemanjai, javed.absar, arichardson, kristof.beyls, kbarton, uweigand, alexandreyy, lldb-commits
Differential Revision: https://reviews.llvm.org/D39837
llvm-svn: 317881
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 3f4842a..a10bd86 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -702,7 +702,7 @@
{
// If a watchpoint was hit, report it
uint32_t wp_index;
- Status error = thread.GetRegisterContext()->GetWatchpointHitIndex(
+ Status error = thread.GetRegisterContext().GetWatchpointHitIndex(
wp_index, (uintptr_t)info.si_addr);
if (error.Fail())
LLDB_LOG(log,
@@ -716,7 +716,7 @@
// If a breakpoint was hit, report it
uint32_t bp_index;
- error = thread.GetRegisterContext()->GetHardwareBreakHitIndex(
+ error = thread.GetRegisterContext().GetHardwareBreakHitIndex(
bp_index, (uintptr_t)info.si_addr);
if (error.Fail())
LLDB_LOG(log, "received error while checking for hardware "
@@ -739,7 +739,7 @@
{
// If a watchpoint was hit, report it
uint32_t wp_index;
- Status error = thread.GetRegisterContext()->GetWatchpointHitIndex(
+ Status error = thread.GetRegisterContext().GetWatchpointHitIndex(
wp_index, LLDB_INVALID_ADDRESS);
if (error.Fail())
LLDB_LOG(log,
@@ -910,13 +910,13 @@
namespace {
struct EmulatorBaton {
- NativeProcessLinux *m_process;
- NativeRegisterContext *m_reg_context;
+ NativeProcessLinux &m_process;
+ NativeRegisterContext &m_reg_context;
// eRegisterKindDWARF -> RegsiterValue
std::unordered_map<uint32_t, RegisterValue> m_register_values;
- EmulatorBaton(NativeProcessLinux *process, NativeRegisterContext *reg_context)
+ EmulatorBaton(NativeProcessLinux &process, NativeRegisterContext ®_context)
: m_process(process), m_reg_context(reg_context) {}
};
@@ -928,7 +928,7 @@
EmulatorBaton *emulator_baton = static_cast<EmulatorBaton *>(baton);
size_t bytes_read;
- emulator_baton->m_process->ReadMemory(addr, dst, length, bytes_read);
+ emulator_baton->m_process.ReadMemory(addr, dst, length, bytes_read);
return bytes_read;
}
@@ -948,11 +948,11 @@
// the generic register numbers). Get the full register info from the
// register context based on the dwarf register numbers.
const RegisterInfo *full_reg_info =
- emulator_baton->m_reg_context->GetRegisterInfo(
+ emulator_baton->m_reg_context.GetRegisterInfo(
eRegisterKindDWARF, reg_info->kinds[eRegisterKindDWARF]);
Status error =
- emulator_baton->m_reg_context->ReadRegister(full_reg_info, reg_value);
+ emulator_baton->m_reg_context.ReadRegister(full_reg_info, reg_value);
if (error.Success())
return true;
@@ -976,17 +976,17 @@
return length;
}
-static lldb::addr_t ReadFlags(NativeRegisterContext *regsiter_context) {
- const RegisterInfo *flags_info = regsiter_context->GetRegisterInfo(
+static lldb::addr_t ReadFlags(NativeRegisterContext ®siter_context) {
+ const RegisterInfo *flags_info = regsiter_context.GetRegisterInfo(
eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
- return regsiter_context->ReadRegisterAsUnsigned(flags_info,
- LLDB_INVALID_ADDRESS);
+ return regsiter_context.ReadRegisterAsUnsigned(flags_info,
+ LLDB_INVALID_ADDRESS);
}
Status
NativeProcessLinux::SetupSoftwareSingleStepping(NativeThreadLinux &thread) {
Status error;
- NativeRegisterContextSP register_context_sp = thread.GetRegisterContext();
+ NativeRegisterContext& register_context = thread.GetRegisterContext();
std::unique_ptr<EmulateInstruction> emulator_ap(
EmulateInstruction::FindPlugin(m_arch, eInstructionTypePCModifying,
@@ -995,7 +995,7 @@
if (emulator_ap == nullptr)
return Status("Instruction emulator not found!");
- EmulatorBaton baton(this, register_context_sp.get());
+ EmulatorBaton baton(*this, register_context);
emulator_ap->SetBaton(&baton);
emulator_ap->SetReadMemCallback(&ReadMemoryCallback);
emulator_ap->SetReadRegCallback(&ReadRegisterCallback);
@@ -1008,9 +1008,9 @@
bool emulation_result =
emulator_ap->EvaluateInstruction(eEmulateInstructionOptionAutoAdvancePC);
- const RegisterInfo *reg_info_pc = register_context_sp->GetRegisterInfo(
+ const RegisterInfo *reg_info_pc = register_context.GetRegisterInfo(
eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
- const RegisterInfo *reg_info_flags = register_context_sp->GetRegisterInfo(
+ const RegisterInfo *reg_info_flags = register_context.GetRegisterInfo(
eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
auto pc_it =
@@ -1028,15 +1028,14 @@
if (flags_it != baton.m_register_values.end())
next_flags = flags_it->second.GetAsUInt64();
else
- next_flags = ReadFlags(register_context_sp.get());
+ next_flags = ReadFlags(register_context);
} else if (pc_it == baton.m_register_values.end()) {
// Emulate instruction failed and it haven't changed PC. Advance PC
// with the size of the current opcode because the emulation of all
// PC modifying instruction should be successful. The failure most
// likely caused by a not supported instruction which don't modify PC.
- next_pc =
- register_context_sp->GetPC() + emulator_ap->GetOpcode().GetByteSize();
- next_flags = ReadFlags(register_context_sp.get());
+ next_pc = register_context.GetPC() + emulator_ap->GetOpcode().GetByteSize();
+ next_flags = ReadFlags(register_context);
} else {
// The instruction emulation failed after it modified the PC. It is an
// unknown error where we can't continue because the next instruction is
@@ -2012,12 +2011,7 @@
// Find out the size of a breakpoint (might depend on where we are in the
// code).
- NativeRegisterContextSP context_sp = thread.GetRegisterContext();
- if (!context_sp) {
- error.SetErrorString("cannot get a NativeRegisterContext for the thread");
- LLDB_LOG(log, "failed: {0}", error);
- return error;
- }
+ NativeRegisterContext &context = thread.GetRegisterContext();
uint32_t breakpoint_size = 0;
error = GetSoftwareBreakpointPCOffset(breakpoint_size);
@@ -2029,8 +2023,7 @@
// First try probing for a breakpoint at a software breakpoint location: PC -
// breakpoint size.
- const lldb::addr_t initial_pc_addr =
- context_sp->GetPCfromBreakpointLocation();
+ const lldb::addr_t initial_pc_addr = context.GetPCfromBreakpointLocation();
lldb::addr_t breakpoint_addr = initial_pc_addr;
if (breakpoint_size > 0) {
// Do not allow breakpoint probe to wrap around.
@@ -2077,7 +2070,7 @@
LLDB_LOG(log, "pid {0} tid {1}: changing PC from {2:x} to {3:x}", GetID(),
thread.GetID(), initial_pc_addr, breakpoint_addr);
- error = context_sp->SetPC(breakpoint_addr);
+ error = context.SetPC(breakpoint_addr);
if (error.Fail()) {
LLDB_LOG(log, "pid {0} tid {1}: failed to set PC: {2}", GetID(),
thread.GetID(), error);
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
index 91fbd22..c8a8355 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
@@ -14,16 +14,16 @@
#include "lldb/Host/common/NativeThreadProtocol.h"
#include "lldb/Host/linux/Ptrace.h"
+#include "Plugins/Process/Linux/NativeProcessLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
using namespace lldb_private;
using namespace lldb_private::process_linux;
NativeRegisterContextLinux::NativeRegisterContextLinux(
- NativeThreadProtocol &native_thread, uint32_t concrete_frame_idx,
+ NativeThreadProtocol &native_thread,
RegisterInfoInterface *reg_info_interface_p)
- : NativeRegisterContextRegisterInfo(native_thread, concrete_frame_idx,
- reg_info_interface_p) {}
+ : NativeRegisterContextRegisterInfo(native_thread, reg_info_interface_p) {}
lldb::ByteOrder NativeRegisterContextLinux::GetByteOrder() const {
return m_thread.GetProcess().GetByteOrder();
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
index 26074a6..2cea497 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.h
@@ -10,10 +10,8 @@
#ifndef lldb_NativeRegisterContextLinux_h
#define lldb_NativeRegisterContextLinux_h
-#include "lldb/Host/common/NativeThreadProtocol.h"
-
-#include "Plugins/Process/Linux/NativeProcessLinux.h"
#include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"
+#include "lldb/Host/common/NativeThreadProtocol.h"
namespace lldb_private {
namespace process_linux {
@@ -21,20 +19,15 @@
class NativeRegisterContextLinux : public NativeRegisterContextRegisterInfo {
public:
NativeRegisterContextLinux(NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx,
RegisterInfoInterface *reg_info_interface_p);
// This function is implemented in the NativeRegisterContextLinux_* subclasses
- // to create a new
- // instance of the host specific NativeRegisterContextLinux. The
- // implementations can't collide
- // as only one NativeRegisterContextLinux_* variant should be compiled into
- // the final
- // executable.
- static NativeRegisterContextLinux *
+ // to create a new instance of the host specific NativeRegisterContextLinux.
+ // The implementations can't collide as only one NativeRegisterContextLinux_*
+ // variant should be compiled into the final executable.
+ static std::unique_ptr<NativeRegisterContextLinux>
CreateHostNativeRegisterContextLinux(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
protected:
lldb::ByteOrder GetByteOrder() const;
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
index 22b7d10..cb05416 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
@@ -11,15 +11,15 @@
#include "NativeRegisterContextLinux_arm.h"
+#include "Plugins/Process/Linux/NativeProcessLinux.h"
+#include "Plugins/Process/Linux/Procfs.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
-#include "Plugins/Process/Linux/Procfs.h"
-#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
-#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
-
#include <elf.h>
#include <sys/socket.h>
@@ -95,20 +95,18 @@
#if defined(__arm__)
-NativeRegisterContextLinux *
+std::unique_ptr<NativeRegisterContextLinux>
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx) {
- return new NativeRegisterContextLinux_arm(target_arch, native_thread,
- concrete_frame_idx);
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
+ return llvm::make_unique<NativeRegisterContextLinux_arm>(target_arch,
+ native_thread);
}
#endif // defined(__arm__)
NativeRegisterContextLinux_arm::NativeRegisterContextLinux_arm(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx)
- : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
+ : NativeRegisterContextLinux(native_thread,
new RegisterInfoPOSIX_arm(target_arch)) {
switch (target_arch.GetMachine()) {
case llvm::Triple::arm:
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
index ec99c05..40e3b80 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
@@ -23,8 +23,7 @@
class NativeRegisterContextLinux_arm : public NativeRegisterContextLinux {
public:
NativeRegisterContextLinux_arm(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index b66117b..c483260 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -112,26 +112,24 @@
{"Floating Point Registers", "fpu", k_num_fpr_registers_arm64,
g_fpu_regnums_arm64}};
-NativeRegisterContextLinux *
+std::unique_ptr<NativeRegisterContextLinux>
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx) {
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
switch (target_arch.GetMachine()) {
case llvm::Triple::arm:
- return new NativeRegisterContextLinux_arm(target_arch, native_thread,
- concrete_frame_idx);
+ return llvm::make_unique<NativeRegisterContextLinux_arm>(target_arch,
+ native_thread);
case llvm::Triple::aarch64:
- return new NativeRegisterContextLinux_arm64(target_arch, native_thread,
- concrete_frame_idx);
+ return llvm::make_unique<NativeRegisterContextLinux_arm64>(target_arch,
+ native_thread);
default:
llvm_unreachable("have no register context for architecture");
}
}
NativeRegisterContextLinux_arm64::NativeRegisterContextLinux_arm64(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx)
- : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
+ : NativeRegisterContextLinux(native_thread,
new RegisterInfoPOSIX_arm64(target_arch)) {
switch (target_arch.GetMachine()) {
case llvm::Triple::aarch64:
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
index 9877dec..ab3c881 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
@@ -23,8 +23,7 @@
class NativeRegisterContextLinux_arm64 : public NativeRegisterContextLinux {
public:
NativeRegisterContextLinux_arm64(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
index 792f2de..32c04a4 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
@@ -80,12 +80,11 @@
using namespace lldb_private;
using namespace lldb_private::process_linux;
-NativeRegisterContextLinux *
+std::unique_ptr<NativeRegisterContextLinux>
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx) {
- return new NativeRegisterContextLinux_mips64(target_arch, native_thread,
- concrete_frame_idx);
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
+ return llvm::make_unique<NativeRegisterContextLinux_mips64>(target_arch,
+ native_thread);
}
#define REG_CONTEXT_SIZE \
@@ -110,9 +109,8 @@
}
NativeRegisterContextLinux_mips64::NativeRegisterContextLinux_mips64(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx)
- : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
+ : NativeRegisterContextLinux(native_thread,
CreateRegisterInfoInterface(target_arch)) {
switch (target_arch.GetMachine()) {
case llvm::Triple::mips:
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.h
index 3e14da5..88ad123 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.h
@@ -26,8 +26,7 @@
class NativeRegisterContextLinux_mips64 : public NativeRegisterContextLinux {
public:
NativeRegisterContextLinux_mips64(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
index 6e275d1..ea854df 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
@@ -111,23 +111,21 @@
g_vsx_regnums_ppc64le},
};
-NativeRegisterContextLinux *
+std::unique_ptr<NativeRegisterContextLinux>
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx) {
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
switch (target_arch.GetMachine()) {
case llvm::Triple::ppc64le:
- return new NativeRegisterContextLinux_ppc64le(target_arch, native_thread,
- concrete_frame_idx);
+ return llvm::make_unique<NativeRegisterContextLinux_ppc64le>(target_arch,
+ native_thread);
default:
llvm_unreachable("have no register context for architecture");
}
}
NativeRegisterContextLinux_ppc64le::NativeRegisterContextLinux_ppc64le(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx)
- : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
+ : NativeRegisterContextLinux(native_thread,
new RegisterInfoPOSIX_ppc64le(target_arch)) {
if (target_arch.GetMachine() != llvm::Triple::ppc64le) {
llvm_unreachable("Unhandled target architecture.");
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
index d83250b..bb25af8 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
@@ -30,8 +30,7 @@
class NativeRegisterContextLinux_ppc64le : public NativeRegisterContextLinux {
public:
NativeRegisterContextLinux_ppc64le(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
index c2a696e..021394a 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
@@ -97,12 +97,11 @@
#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
-NativeRegisterContextLinux *
+std::unique_ptr<NativeRegisterContextLinux>
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx) {
- return new NativeRegisterContextLinux_s390x(target_arch, native_thread,
- concrete_frame_idx);
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
+ return llvm::make_unique<NativeRegisterContextLinux_s390x>(target_arch,
+ native_thread);
}
// ----------------------------------------------------------------------------
@@ -117,9 +116,8 @@
}
NativeRegisterContextLinux_s390x::NativeRegisterContextLinux_s390x(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx)
- : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
+ : NativeRegisterContextLinux(native_thread,
CreateRegisterInfoInterface(target_arch)) {
// Set up data about ranges of valid registers.
switch (target_arch.GetMachine()) {
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.h
index 3ffbaee..57b1a04 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.h
@@ -24,8 +24,7 @@
class NativeRegisterContextLinux_s390x : public NativeRegisterContextLinux {
public:
NativeRegisterContextLinux_s390x(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
index e44e03b..b86b825 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
@@ -243,12 +243,11 @@
#define mask_XSTATE_BNDCFG (1ULL << 4)
#define mask_XSTATE_MPX (mask_XSTATE_BNDREGS | mask_XSTATE_BNDCFG)
-NativeRegisterContextLinux *
+std::unique_ptr<NativeRegisterContextLinux>
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx) {
- return new NativeRegisterContextLinux_x86_64(target_arch, native_thread,
- concrete_frame_idx);
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
+ return std::unique_ptr<NativeRegisterContextLinux>(
+ new NativeRegisterContextLinux_x86_64(target_arch, native_thread));
}
// ----------------------------------------------------------------------------
@@ -270,9 +269,8 @@
}
NativeRegisterContextLinux_x86_64::NativeRegisterContextLinux_x86_64(
- const ArchSpec &target_arch, NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx)
- : NativeRegisterContextLinux(native_thread, concrete_frame_idx,
+ const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
+ : NativeRegisterContextLinux(native_thread,
CreateRegisterInfoInterface(target_arch)),
m_xstate_type(XStateType::Invalid), m_fpr(), m_iovec(), m_ymm_set(),
m_mpx_set(), m_reg_info(), m_gpr_x86_64() {
diff --git a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
index abb0dba..792ed35 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
@@ -24,8 +24,7 @@
class NativeRegisterContextLinux_x86_64 : public NativeRegisterContextLinux {
public:
NativeRegisterContextLinux_x86_64(const ArchSpec &target_arch,
- NativeThreadProtocol &native_thread,
- uint32_t concrete_frame_idx);
+ NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index 71324a4..0db3bd5 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -88,7 +88,11 @@
NativeThreadLinux::NativeThreadLinux(NativeProcessLinux &process,
lldb::tid_t tid)
: NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
- m_stop_info(), m_reg_context_sp(), m_stop_description() {}
+ m_stop_info(),
+ m_reg_context_up(
+ NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
+ process.GetArchitecture(), *this)),
+ m_stop_description() {}
std::string NativeThreadLinux::GetName() {
NativeProcessLinux &process = GetProcess();
@@ -139,19 +143,6 @@
llvm_unreachable("unhandled StateType!");
}
-NativeRegisterContextSP NativeThreadLinux::GetRegisterContext() {
- // Return the register context if we already created it.
- if (m_reg_context_sp)
- return m_reg_context_sp;
-
- const uint32_t concrete_frame_idx = 0;
- m_reg_context_sp.reset(
- NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
- m_process.GetArchitecture(), *this, concrete_frame_idx));
-
- return m_reg_context_sp;
-}
-
Status NativeThreadLinux::SetWatchpoint(lldb::addr_t addr, size_t size,
uint32_t watch_flags, bool hardware) {
if (!hardware)
@@ -161,8 +152,8 @@
Status error = RemoveWatchpoint(addr);
if (error.Fail())
return error;
- NativeRegisterContextSP reg_ctx = GetRegisterContext();
- uint32_t wp_index = reg_ctx->SetHardwareWatchpoint(addr, size, watch_flags);
+ uint32_t wp_index =
+ m_reg_context_up->SetHardwareWatchpoint(addr, size, watch_flags);
if (wp_index == LLDB_INVALID_INDEX32)
return Status("Setting hardware watchpoint failed.");
m_watchpoint_index_map.insert({addr, wp_index});
@@ -175,7 +166,7 @@
return Status();
uint32_t wp_index = wp->second;
m_watchpoint_index_map.erase(wp);
- if (GetRegisterContext()->ClearHardwareWatchpoint(wp_index))
+ if (m_reg_context_up->ClearHardwareWatchpoint(wp_index))
return Status();
return Status("Clearing hardware watchpoint failed.");
}
@@ -189,8 +180,7 @@
if (error.Fail())
return error;
- NativeRegisterContextSP reg_ctx = GetRegisterContext();
- uint32_t bp_index = reg_ctx->SetHardwareBreakpoint(addr, size);
+ uint32_t bp_index = m_reg_context_up->SetHardwareBreakpoint(addr, size);
if (bp_index == LLDB_INVALID_INDEX32)
return Status("Setting hardware breakpoint failed.");
@@ -205,7 +195,7 @@
return Status();
uint32_t bp_index = bp->second;
- if (GetRegisterContext()->ClearHardwareBreakpoint(bp_index)) {
+ if (m_reg_context_up->ClearHardwareBreakpoint(bp_index)) {
m_hw_break_index_map.erase(bp);
return Status();
}
@@ -227,7 +217,7 @@
NativeProcessLinux &process = GetProcess();
const auto &watchpoint_map = process.GetWatchpointMap();
- GetRegisterContext()->ClearAllHardwareWatchpoints();
+ m_reg_context_up->ClearAllHardwareWatchpoints();
for (const auto &pair : watchpoint_map) {
const auto &wp = pair.second;
SetWatchpoint(wp.m_addr, wp.m_size, wp.m_watch_flags, wp.m_hardware);
@@ -239,7 +229,7 @@
NativeProcessLinux &process = GetProcess();
const auto &hw_breakpoint_map = process.GetHardwareBreakpointMap();
- GetRegisterContext()->ClearAllHardwareBreakpoints();
+ m_reg_context_up->ClearAllHardwareBreakpoints();
for (const auto &pair : hw_breakpoint_map) {
const auto &bp = pair.second;
SetHardwareBreakpoint(bp.m_addr, bp.m_size);
@@ -361,7 +351,7 @@
lldbassert(wp_index != LLDB_INVALID_INDEX32 && "wp_index cannot be invalid");
std::ostringstream ostr;
- ostr << GetRegisterContext()->GetWatchpointAddress(wp_index) << " ";
+ ostr << m_reg_context_up->GetWatchpointAddress(wp_index) << " ";
ostr << wp_index;
/*
@@ -375,7 +365,7 @@
* stop-info
* packet.
*/
- ostr << " " << GetRegisterContext()->GetWatchpointHitAddress(wp_index);
+ ostr << " " << m_reg_context_up->GetWatchpointHitAddress(wp_index);
m_stop_description = ostr.str();
diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
index 01b54d9..a7c4e98 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -10,7 +10,8 @@
#ifndef liblldb_NativeThreadLinux_H_
#define liblldb_NativeThreadLinux_H_
-#include "SingleStepCheck.h"
+#include "Plugins/Process/Linux/NativeRegisterContextLinux.h"
+#include "Plugins/Process/Linux/SingleStepCheck.h"
#include "lldb/Host/common/NativeThreadProtocol.h"
#include "lldb/lldb-private-forward.h"
@@ -40,7 +41,9 @@
bool GetStopReason(ThreadStopInfo &stop_info,
std::string &description) override;
- NativeRegisterContextSP GetRegisterContext() override;
+ NativeRegisterContextLinux &GetRegisterContext() override {
+ return *m_reg_context_up;
+ }
Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
bool hardware) override;
@@ -103,7 +106,7 @@
// ---------------------------------------------------------------------
lldb::StateType m_state;
ThreadStopInfo m_stop_info;
- NativeRegisterContextSP m_reg_context_sp;
+ std::unique_ptr<NativeRegisterContextLinux> m_reg_context_up;
std::string m_stop_description;
using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
WatchpointIndexMap m_watchpoint_index_map;