forked from OSchip/llvm-project
Simplify NativeProcessProtocol::GetArchitecture/GetByteOrder
Summary: These functions used to return bool to signify whether they were able to retrieve the data. This is redundant because the ArchSpec and ByteOrder already have their own "invalid" states, *and* because both of the current implementations (linux, netbsd) can always provide a valid result. This allows us to simplify bits of the code handling these values. Reviewers: eugene, krytarowski Subscribers: javed.absar, lldb-commits Differential Revision: https://reviews.llvm.org/D39733 llvm-svn: 317779
This commit is contained in:
parent
3a7044ef78
commit
578a425890
|
@ -13,6 +13,7 @@
|
|||
#include "NativeBreakpointList.h"
|
||||
#include "NativeThreadProtocol.h"
|
||||
#include "NativeWatchpointList.h"
|
||||
#include "lldb/Core/ArchSpec.h"
|
||||
#include "lldb/Host/Host.h"
|
||||
#include "lldb/Host/MainLoop.h"
|
||||
#include "lldb/Utility/Status.h"
|
||||
|
@ -100,7 +101,7 @@ public:
|
|||
|
||||
virtual size_t UpdateThreads() = 0;
|
||||
|
||||
virtual bool GetArchitecture(ArchSpec &arch) const = 0;
|
||||
virtual const ArchSpec &GetArchitecture() const = 0;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Breakpoint functions
|
||||
|
@ -151,7 +152,9 @@ public:
|
|||
|
||||
bool CanResume() const { return m_state == lldb::eStateStopped; }
|
||||
|
||||
bool GetByteOrder(lldb::ByteOrder &byte_order) const;
|
||||
lldb::ByteOrder GetByteOrder() const {
|
||||
return GetArchitecture().GetByteOrder();
|
||||
}
|
||||
|
||||
virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
|
||||
GetAuxvData() const = 0;
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "lldb/Host/common/NativeProcessProtocol.h"
|
||||
|
||||
#include "lldb/Core/ArchSpec.h"
|
||||
#include "lldb/Core/ModuleSpec.h"
|
||||
#include "lldb/Core/State.h"
|
||||
#include "lldb/Host/Host.h"
|
||||
|
@ -116,14 +114,6 @@ bool NativeProcessProtocol::IsAlive() const {
|
|||
m_state != eStateInvalid && m_state != eStateUnloaded;
|
||||
}
|
||||
|
||||
bool NativeProcessProtocol::GetByteOrder(lldb::ByteOrder &byte_order) const {
|
||||
ArchSpec process_arch;
|
||||
if (!GetArchitecture(process_arch))
|
||||
return false;
|
||||
byte_order = process_arch.GetByteOrder();
|
||||
return true;
|
||||
}
|
||||
|
||||
const NativeWatchpointList::WatchpointMap &
|
||||
NativeProcessProtocol::GetWatchpointMap() const {
|
||||
return m_watchpoint_list.GetWatchpointMap();
|
||||
|
|
|
@ -368,13 +368,8 @@ Status NativeRegisterContext::ReadRegisterValueFromMemory(
|
|||
// TODO: we might need to add a parameter to this function in case the byte
|
||||
// order of the memory data doesn't match the process. For now we are assuming
|
||||
// they are the same.
|
||||
lldb::ByteOrder byte_order;
|
||||
if (process.GetByteOrder(byte_order)) {
|
||||
error.SetErrorString("NativeProcessProtocol::GetByteOrder () failed");
|
||||
return error;
|
||||
}
|
||||
|
||||
reg_value.SetFromMemoryData(reg_info, src, src_len, byte_order, error);
|
||||
reg_value.SetFromMemoryData(reg_info, src, src_len, process.GetByteOrder(),
|
||||
error);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -393,12 +388,8 @@ Status NativeRegisterContext::WriteRegisterValueToMemory(
|
|||
// order of the memory data doesn't match the process. For now we are
|
||||
// assuming
|
||||
// they are the same.
|
||||
lldb::ByteOrder byte_order;
|
||||
if (!process.GetByteOrder(byte_order))
|
||||
return Status("NativeProcessProtocol::GetByteOrder () failed");
|
||||
|
||||
const size_t bytes_copied =
|
||||
reg_value.GetAsMemoryData(reg_info, dst, dst_len, byte_order, error);
|
||||
const size_t bytes_copied = reg_value.GetAsMemoryData(
|
||||
reg_info, dst, dst_len, process.GetByteOrder(), error);
|
||||
|
||||
if (error.Success()) {
|
||||
if (bytes_copied == 0) {
|
||||
|
|
|
@ -1542,11 +1542,6 @@ size_t NativeProcessLinux::UpdateThreads() {
|
|||
return m_threads.size();
|
||||
}
|
||||
|
||||
bool NativeProcessLinux::GetArchitecture(ArchSpec &arch) const {
|
||||
arch = m_arch;
|
||||
return true;
|
||||
}
|
||||
|
||||
Status NativeProcessLinux::GetSoftwareBreakpointPCOffset(
|
||||
uint32_t &actual_opcode_size) {
|
||||
// FIXME put this behind a breakpoint protocol class that can be
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
|
||||
size_t UpdateThreads() override;
|
||||
|
||||
bool GetArchitecture(ArchSpec &arch) const override;
|
||||
const ArchSpec &GetArchitecture() const override { return m_arch; }
|
||||
|
||||
Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
|
||||
bool hardware) override;
|
||||
|
|
|
@ -26,15 +26,7 @@ NativeRegisterContextLinux::NativeRegisterContextLinux(
|
|||
reg_info_interface_p) {}
|
||||
|
||||
lldb::ByteOrder NativeRegisterContextLinux::GetByteOrder() const {
|
||||
// Get the target process whose privileged thread was used for the register
|
||||
// read.
|
||||
lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
|
||||
|
||||
if (!m_thread.GetProcess().GetByteOrder(byte_order)) {
|
||||
// FIXME log here
|
||||
}
|
||||
|
||||
return byte_order;
|
||||
return m_thread.GetProcess().GetByteOrder();
|
||||
}
|
||||
|
||||
Status NativeRegisterContextLinux::ReadRegisterRaw(uint32_t reg_index,
|
||||
|
|
|
@ -872,12 +872,8 @@ Status NativeRegisterContextLinux_arm64::DoReadRegisterValue(
|
|||
error = NativeProcessLinux::PtraceWrapper(
|
||||
PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, sizeof regs);
|
||||
if (error.Success()) {
|
||||
ArchSpec arch;
|
||||
if (m_thread.GetProcess().GetArchitecture(arch))
|
||||
value.SetBytes((void *)(((unsigned char *)(®s)) + offset), 16,
|
||||
arch.GetByteOrder());
|
||||
else
|
||||
error.SetErrorString("failed to get architecture");
|
||||
value.SetBytes((void *)(((unsigned char *)(®s)) + offset), 16,
|
||||
m_thread.GetProcess().GetByteOrder());
|
||||
}
|
||||
} else {
|
||||
elf_gregset_t regs;
|
||||
|
@ -889,12 +885,8 @@ Status NativeRegisterContextLinux_arm64::DoReadRegisterValue(
|
|||
error = NativeProcessLinux::PtraceWrapper(
|
||||
PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, sizeof regs);
|
||||
if (error.Success()) {
|
||||
ArchSpec arch;
|
||||
if (m_thread.GetProcess().GetArchitecture(arch))
|
||||
value.SetBytes((void *)(((unsigned char *)(regs)) + offset), 8,
|
||||
arch.GetByteOrder());
|
||||
else
|
||||
error.SetErrorString("failed to get architecture");
|
||||
value.SetBytes((void *)(((unsigned char *)(regs)) + offset), 8,
|
||||
m_thread.GetProcess().GetByteOrder());
|
||||
}
|
||||
}
|
||||
return error;
|
||||
|
|
|
@ -1033,13 +1033,11 @@ Status NativeRegisterContextLinux_mips64::Read_SR_Config(uint32_t offset,
|
|||
Status error = NativeProcessLinux::PtraceWrapper(
|
||||
PTRACE_GETREGS, m_thread.GetID(), NULL, ®s, sizeof regs);
|
||||
if (error.Success()) {
|
||||
lldb_private::ArchSpec arch;
|
||||
if (m_thread.GetProcess().GetArchitecture(arch)) {
|
||||
void *target_address = ((uint8_t *)®s) + offset +
|
||||
4 * (arch.GetMachine() == llvm::Triple::mips);
|
||||
value.SetUInt(*(uint32_t *)target_address, size);
|
||||
} else
|
||||
error.SetErrorString("failed to get architecture");
|
||||
const lldb_private::ArchSpec &arch =
|
||||
m_thread.GetProcess().GetArchitecture();
|
||||
void *target_address = ((uint8_t *)®s) + offset +
|
||||
4 * (arch.GetMachine() == llvm::Triple::mips);
|
||||
value.SetUInt(*(uint32_t *)target_address, size);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
|
|
@ -144,14 +144,10 @@ NativeRegisterContextSP NativeThreadLinux::GetRegisterContext() {
|
|||
if (m_reg_context_sp)
|
||||
return m_reg_context_sp;
|
||||
|
||||
ArchSpec target_arch;
|
||||
if (!m_process.GetArchitecture(target_arch))
|
||||
return NativeRegisterContextSP();
|
||||
|
||||
const uint32_t concrete_frame_idx = 0;
|
||||
m_reg_context_sp.reset(
|
||||
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
|
||||
target_arch, *this, concrete_frame_idx));
|
||||
m_process.GetArchitecture(), *this, concrete_frame_idx));
|
||||
|
||||
return m_reg_context_sp;
|
||||
}
|
||||
|
|
|
@ -678,11 +678,6 @@ lldb::addr_t NativeProcessNetBSD::GetSharedLibraryInfoAddress() {
|
|||
|
||||
size_t NativeProcessNetBSD::UpdateThreads() { return m_threads.size(); }
|
||||
|
||||
bool NativeProcessNetBSD::GetArchitecture(ArchSpec &arch) const {
|
||||
arch = m_arch;
|
||||
return true;
|
||||
}
|
||||
|
||||
Status NativeProcessNetBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size,
|
||||
bool hardware) {
|
||||
if (hardware)
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
|
||||
size_t UpdateThreads() override;
|
||||
|
||||
bool GetArchitecture(ArchSpec &arch) const override;
|
||||
const ArchSpec &GetArchitecture() const override { return m_arch; }
|
||||
|
||||
Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
|
||||
bool hardware) override;
|
||||
|
|
|
@ -144,14 +144,10 @@ NativeRegisterContextSP NativeThreadNetBSD::GetRegisterContext() {
|
|||
if (m_reg_context_sp)
|
||||
return m_reg_context_sp;
|
||||
|
||||
ArchSpec target_arch;
|
||||
if (!m_process.GetArchitecture(target_arch))
|
||||
return NativeRegisterContextSP();
|
||||
|
||||
const uint32_t concrete_frame_idx = 0;
|
||||
m_reg_context_sp.reset(
|
||||
NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(
|
||||
target_arch, *this, concrete_frame_idx));
|
||||
m_process.GetArchitecture(), *this, concrete_frame_idx));
|
||||
|
||||
return m_reg_context_sp;
|
||||
}
|
||||
|
|
|
@ -2041,17 +2041,6 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
|
|||
return SendIllFormedResponse(
|
||||
packet, "P packet missing '=' char after register number");
|
||||
|
||||
// Get process architecture.
|
||||
ArchSpec process_arch;
|
||||
if (!m_debugged_process_up ||
|
||||
!m_debugged_process_up->GetArchitecture(process_arch)) {
|
||||
if (log)
|
||||
log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to retrieve "
|
||||
"inferior architecture",
|
||||
__FUNCTION__);
|
||||
return SendErrorResponse(0x49);
|
||||
}
|
||||
|
||||
// Parse out the value.
|
||||
uint8_t reg_bytes[32]; // big enough to support up to 256 bit ymmN register
|
||||
size_t reg_size = packet.GetHexBytesAvail(reg_bytes);
|
||||
|
@ -2109,7 +2098,9 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
|
|||
// Build the reginfos response.
|
||||
StreamGDBRemote response;
|
||||
|
||||
RegisterValue reg_value(reg_bytes, reg_size, process_arch.GetByteOrder());
|
||||
RegisterValue reg_value(
|
||||
reg_bytes, reg_size,
|
||||
m_debugged_process_up->GetArchitecture().GetByteOrder());
|
||||
Status error = reg_context_sp->WriteRegister(reg_info, reg_value);
|
||||
if (error.Fail()) {
|
||||
if (log)
|
||||
|
|
Loading…
Reference in New Issue