mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
Refactor GetSoftwareBreakpointTrapOpcode
This patch aims to reduce the code duplication among all of the platforms in GetSoftwareBreakpointTrapOpcode by pushing all common code into the Platform base class. Differential Revision: http://reviews.llvm.org/D17395 llvm-svn: 261536
This commit is contained in:
@@ -427,7 +427,7 @@ class ModuleCache;
|
||||
|
||||
virtual size_t
|
||||
GetSoftwareBreakpointTrapOpcode (Target &target,
|
||||
BreakpointSite *bp_site) = 0;
|
||||
BreakpointSite *bp_site);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
/// Launch a new process on a platform, not necessarily for
|
||||
|
||||
@@ -614,84 +614,32 @@ PlatformFreeBSD::GetStatus (Stream &strm)
|
||||
size_t
|
||||
PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site)
|
||||
{
|
||||
ArchSpec arch = target.GetArchitecture();
|
||||
const uint8_t *trap_opcode = NULL;
|
||||
size_t trap_opcode_size = 0;
|
||||
|
||||
switch (arch.GetMachine())
|
||||
switch (target.GetArchitecture().GetMachine())
|
||||
{
|
||||
default:
|
||||
assert(false && "Unhandled architecture in PlatformFreeBSD::GetSoftwareBreakpointTrapOpcode()");
|
||||
break;
|
||||
case llvm::Triple::aarch64:
|
||||
{
|
||||
static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xd4 };
|
||||
trap_opcode = g_aarch64_opcode;
|
||||
trap_opcode_size = sizeof(g_aarch64_opcode);
|
||||
}
|
||||
break;
|
||||
// TODO: support big-endian arm and thumb trap codes.
|
||||
case llvm::Triple::arm:
|
||||
{
|
||||
static const uint8_t g_arm_breakpoint_opcode[] = { 0xfe, 0xde, 0xff, 0xe7 };
|
||||
static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde };
|
||||
|
||||
lldb::BreakpointLocationSP bp_loc_sp (bp_site->GetOwnerAtIndex (0));
|
||||
lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0));
|
||||
AddressClass addr_class = eAddressClassUnknown;
|
||||
|
||||
if (bp_loc_sp)
|
||||
addr_class = bp_loc_sp->GetAddress ().GetAddressClass ();
|
||||
{
|
||||
addr_class = bp_loc_sp->GetAddress().GetAddressClass();
|
||||
if (addr_class == eAddressClassUnknown && (bp_loc_sp->GetAddress().GetFileAddress() & 1))
|
||||
addr_class = eAddressClassCodeAlternateISA;
|
||||
}
|
||||
|
||||
if (addr_class == eAddressClassCodeAlternateISA
|
||||
|| (addr_class == eAddressClassUnknown && (bp_site->GetLoadAddress() & 1)))
|
||||
if (addr_class == eAddressClassCodeAlternateISA)
|
||||
{
|
||||
// TODO: Enable when FreeBSD supports thumb breakpoints.
|
||||
// FreeBSD kernel as of 10.x, does not support thumb breakpoints
|
||||
trap_opcode = g_thumb_breakpoint_opcode;
|
||||
trap_opcode_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
trap_opcode = g_arm_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::mips64:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = { 0x00, 0x00, 0x00, 0x0d };
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::mips64el:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = { 0x0d, 0x00, 0x00, 0x00 };
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::ppc:
|
||||
case llvm::Triple::ppc64:
|
||||
{
|
||||
static const uint8_t g_ppc_opcode[] = { 0x7f, 0xe0, 0x00, 0x08 };
|
||||
trap_opcode = g_ppc_opcode;
|
||||
trap_opcode_size = sizeof(g_ppc_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
{
|
||||
static const uint8_t g_i386_opcode[] = { 0xCC };
|
||||
trap_opcode = g_i386_opcode;
|
||||
trap_opcode_size = sizeof(g_i386_opcode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
|
||||
return trap_opcode_size;
|
||||
return 0;
|
||||
// Fall through...
|
||||
default:
|
||||
return Platform::GetSoftwareBreakpointTrapOpcode(target, bp_site);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -522,98 +522,6 @@ PlatformLinux::GetStatus (Stream &strm)
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t
|
||||
PlatformLinux::GetSoftwareBreakpointTrapOpcode (Target &target,
|
||||
BreakpointSite *bp_site)
|
||||
{
|
||||
ArchSpec arch = target.GetArchitecture();
|
||||
const uint8_t *trap_opcode = NULL;
|
||||
size_t trap_opcode_size = 0;
|
||||
|
||||
switch (arch.GetMachine())
|
||||
{
|
||||
default:
|
||||
assert(false && "CPU type not supported!");
|
||||
break;
|
||||
|
||||
case llvm::Triple::aarch64:
|
||||
{
|
||||
static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xd4 };
|
||||
trap_opcode = g_aarch64_opcode;
|
||||
trap_opcode_size = sizeof(g_aarch64_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
{
|
||||
static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
|
||||
trap_opcode = g_i386_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::hexagon:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = { 0x0c, 0xdb, 0x00, 0x54 };
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::arm:
|
||||
{
|
||||
// The ARM reference recommends the use of 0xe7fddefe and 0xdefe
|
||||
// but the linux kernel does otherwise.
|
||||
static const uint8_t g_arm_breakpoint_opcode[] = { 0xf0, 0x01, 0xf0, 0xe7 };
|
||||
static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde };
|
||||
|
||||
lldb::BreakpointLocationSP bp_loc_sp (bp_site->GetOwnerAtIndex (0));
|
||||
AddressClass addr_class = eAddressClassUnknown;
|
||||
|
||||
if (bp_loc_sp)
|
||||
{
|
||||
addr_class = bp_loc_sp->GetAddress ().GetAddressClass ();
|
||||
|
||||
if (addr_class == eAddressClassUnknown &&
|
||||
(bp_loc_sp->GetAddress ().GetFileAddress () & 1))
|
||||
{
|
||||
addr_class = eAddressClassCodeAlternateISA;
|
||||
}
|
||||
}
|
||||
|
||||
if (addr_class == eAddressClassCodeAlternateISA)
|
||||
{
|
||||
trap_opcode = g_thumb_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_thumb_breakpoint_opcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
trap_opcode = g_arm_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::mips:
|
||||
case llvm::Triple::mips64:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = { 0x00, 0x00, 0x00, 0x0d };
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
case llvm::Triple::mipsel:
|
||||
case llvm::Triple::mips64el:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = { 0x0d, 0x00, 0x00, 0x00 };
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
|
||||
return trap_opcode_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t
|
||||
PlatformLinux::GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info)
|
||||
{
|
||||
|
||||
@@ -87,10 +87,6 @@ namespace platform_linux {
|
||||
bool
|
||||
GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) override;
|
||||
|
||||
size_t
|
||||
GetSoftwareBreakpointTrapOpcode (Target &target,
|
||||
BreakpointSite *bp_site) override;
|
||||
|
||||
int32_t
|
||||
GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) override;
|
||||
|
||||
|
||||
@@ -583,22 +583,13 @@ PlatformDarwin::GetSharedModule (const ModuleSpec &module_spec,
|
||||
size_t
|
||||
PlatformDarwin::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site)
|
||||
{
|
||||
const uint8_t *trap_opcode = NULL;
|
||||
const uint8_t *trap_opcode = nullptr;
|
||||
uint32_t trap_opcode_size = 0;
|
||||
bool bp_is_thumb = false;
|
||||
|
||||
|
||||
llvm::Triple::ArchType machine = target.GetArchitecture().GetMachine();
|
||||
switch (machine)
|
||||
{
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
{
|
||||
static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
|
||||
trap_opcode = g_i386_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::aarch64:
|
||||
{
|
||||
// TODO: fix this with actual darwin breakpoint opcode for arm64.
|
||||
@@ -635,7 +626,7 @@ PlatformDarwin::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite
|
||||
trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case llvm::Triple::ppc:
|
||||
case llvm::Triple::ppc64:
|
||||
{
|
||||
@@ -644,12 +635,11 @@ PlatformDarwin::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite
|
||||
trap_opcode_size = sizeof(g_ppc_breakpoint_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
assert(!"Unhandled architecture in PlatformDarwin::GetSoftwareBreakpointTrapOpcode()");
|
||||
break;
|
||||
return Platform::GetSoftwareBreakpointTrapOpcode(target, bp_site);
|
||||
}
|
||||
|
||||
|
||||
if (trap_opcode && trap_opcode_size)
|
||||
{
|
||||
if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
|
||||
|
||||
@@ -585,34 +585,6 @@ PlatformNetBSD::GetStatus (Stream &strm)
|
||||
Platform::GetStatus(strm);
|
||||
}
|
||||
|
||||
size_t
|
||||
PlatformNetBSD::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site)
|
||||
{
|
||||
ArchSpec arch = target.GetArchitecture();
|
||||
const uint8_t *trap_opcode = NULL;
|
||||
size_t trap_opcode_size = 0;
|
||||
|
||||
switch (arch.GetMachine())
|
||||
{
|
||||
default:
|
||||
assert(false && "Unhandled architecture in PlatformNetBSD::GetSoftwareBreakpointTrapOpcode()");
|
||||
break;
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
{
|
||||
static const uint8_t g_i386_opcode[] = { 0xCC };
|
||||
trap_opcode = g_i386_opcode;
|
||||
trap_opcode_size = sizeof(g_i386_opcode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
|
||||
return trap_opcode_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlatformNetBSD::CalculateTrapHandlerSymbolNames ()
|
||||
{
|
||||
|
||||
@@ -86,10 +86,6 @@ namespace platform_netbsd {
|
||||
lldb::ModuleSP &module_sp,
|
||||
const FileSpecList *module_search_paths_ptr) override;
|
||||
|
||||
size_t
|
||||
GetSoftwareBreakpointTrapOpcode(Target &target,
|
||||
BreakpointSite *bp_site) override;
|
||||
|
||||
bool
|
||||
GetRemoteOSVersion () override;
|
||||
|
||||
|
||||
@@ -321,42 +321,6 @@ PlatformWindows::ResolveExecutable (const ModuleSpec &ms,
|
||||
return error;
|
||||
}
|
||||
|
||||
size_t
|
||||
PlatformWindows::GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site)
|
||||
{
|
||||
ArchSpec arch = target.GetArchitecture();
|
||||
const uint8_t *trap_opcode = nullptr;
|
||||
size_t trap_opcode_size = 0;
|
||||
|
||||
switch (arch.GetMachine())
|
||||
{
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
{
|
||||
static const uint8_t g_i386_opcode[] = { 0xCC };
|
||||
trap_opcode = g_i386_opcode;
|
||||
trap_opcode_size = sizeof(g_i386_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::hexagon:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = { 0x0c, 0xdb, 0x00, 0x54 };
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unhandled architecture in PlatformWindows::GetSoftwareBreakpointTrapOpcode()");
|
||||
break;
|
||||
}
|
||||
|
||||
if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
|
||||
return trap_opcode_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
PlatformWindows::GetRemoteOSVersion ()
|
||||
{
|
||||
|
||||
@@ -72,10 +72,6 @@ public:
|
||||
return GetPluginDescriptionStatic(IsHost());
|
||||
}
|
||||
|
||||
size_t
|
||||
GetSoftwareBreakpointTrapOpcode(lldb_private::Target &target,
|
||||
lldb_private::BreakpointSite *bp_site) override;
|
||||
|
||||
bool
|
||||
GetRemoteOSVersion() override;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// Project includes
|
||||
#include "lldb/Target/Platform.h"
|
||||
#include "lldb/Breakpoint/BreakpointIDList.h"
|
||||
#include "lldb/Breakpoint/BreakpointLocation.h"
|
||||
#include "lldb/Core/DataBufferHeap.h"
|
||||
#include "lldb/Core/Debugger.h"
|
||||
#include "lldb/Core/Error.h"
|
||||
@@ -2046,3 +2047,105 @@ Platform::ConnectToWaitingProcesses(lldb_private::Debugger& debugger, lldb_priva
|
||||
error.Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
Platform::GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site)
|
||||
{
|
||||
ArchSpec arch = target.GetArchitecture();
|
||||
const uint8_t *trap_opcode = nullptr;
|
||||
size_t trap_opcode_size = 0;
|
||||
|
||||
switch (arch.GetMachine())
|
||||
{
|
||||
case llvm::Triple::aarch64:
|
||||
{
|
||||
static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xd4};
|
||||
trap_opcode = g_aarch64_opcode;
|
||||
trap_opcode_size = sizeof(g_aarch64_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
// TODO: support big-endian arm and thumb trap codes.
|
||||
case llvm::Triple::arm:
|
||||
{
|
||||
// The ARM reference recommends the use of 0xe7fddefe and 0xdefe
|
||||
// but the linux kernel does otherwise.
|
||||
static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
|
||||
static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
|
||||
|
||||
lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0));
|
||||
AddressClass addr_class = eAddressClassUnknown;
|
||||
|
||||
if (bp_loc_sp)
|
||||
{
|
||||
addr_class = bp_loc_sp->GetAddress().GetAddressClass();
|
||||
if (addr_class == eAddressClassUnknown && (bp_loc_sp->GetAddress().GetFileAddress() & 1))
|
||||
addr_class = eAddressClassCodeAlternateISA;
|
||||
}
|
||||
|
||||
if (addr_class == eAddressClassCodeAlternateISA)
|
||||
{
|
||||
trap_opcode = g_thumb_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_thumb_breakpoint_opcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
trap_opcode = g_arm_breakpoint_opcode;
|
||||
trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::mips64:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::mips64el:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = {0x0d, 0x00, 0x00, 0x00};
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::hexagon:
|
||||
{
|
||||
static const uint8_t g_hex_opcode[] = {0x0c, 0xdb, 0x00, 0x54};
|
||||
trap_opcode = g_hex_opcode;
|
||||
trap_opcode_size = sizeof(g_hex_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::ppc:
|
||||
case llvm::Triple::ppc64:
|
||||
{
|
||||
static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};
|
||||
trap_opcode = g_ppc_opcode;
|
||||
trap_opcode_size = sizeof(g_ppc_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
{
|
||||
static const uint8_t g_i386_opcode[] = {0xCC};
|
||||
trap_opcode = g_i386_opcode;
|
||||
trap_opcode_size = sizeof(g_i386_opcode);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(!"Unhandled architecture in Platform::GetSoftwareBreakpointTrapOpcode");
|
||||
break;
|
||||
}
|
||||
|
||||
assert(bp_site);
|
||||
if (bp_site->SetTrapOpcode(trap_opcode, trap_opcode_size))
|
||||
return trap_opcode_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user