Skip to content

Commit

Permalink
Refactor GetSoftwareBreakpointTrapOpcode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bit-hack committed Feb 22, 2016
1 parent 46e39cc commit 933d8db
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 250 deletions.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Target/Platform.h
Expand Up @@ -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
Expand Down
78 changes: 13 additions & 65 deletions lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
Expand Up @@ -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);
}
}


Expand Down
92 changes: 0 additions & 92 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
Expand Up @@ -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)
{
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.h
Expand Up @@ -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;

Expand Down
22 changes: 6 additions & 16 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
{
Expand All @@ -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))
Expand Down
28 changes: 0 additions & 28 deletions lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
Expand Up @@ -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 ()
{
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
Expand Up @@ -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;

Expand Down
36 changes: 0 additions & 36 deletions lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
Expand Up @@ -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 ()
{
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/Platform/Windows/PlatformWindows.h
Expand Up @@ -72,10 +72,6 @@ class PlatformWindows : public Platform
return GetPluginDescriptionStatic(IsHost());
}

size_t
GetSoftwareBreakpointTrapOpcode(lldb_private::Target &target,
lldb_private::BreakpointSite *bp_site) override;

bool
GetRemoteOSVersion() override;

Expand Down

0 comments on commit 933d8db

Please sign in to comment.