Index: lldb/trunk/include/lldb/Target/Platform.h =================================================================== --- lldb/trunk/include/lldb/Target/Platform.h +++ lldb/trunk/include/lldb/Target/Platform.h @@ -427,7 +427,7 @@ virtual size_t GetSoftwareBreakpointTrapOpcode (Target &target, - BreakpointSite *bp_site) = 0; + BreakpointSite *bp_site); //------------------------------------------------------------------ /// Launch a new process on a platform, not necessarily for Index: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp +++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp @@ -614,84 +614,32 @@ 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; + return 0; } - 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::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); + } } Index: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h =================================================================== --- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h +++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h @@ -87,10 +87,6 @@ bool GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) override; - size_t - GetSoftwareBreakpointTrapOpcode (Target &target, - BreakpointSite *bp_site) override; - int32_t GetResumeCountForLaunchInfo (ProcessLaunchInfo &launch_info) override; Index: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp +++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -522,98 +522,6 @@ #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) { Index: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -583,22 +583,13 @@ 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 @@ trap_opcode_size = sizeof(g_arm_breakpoint_opcode); } break; - + case llvm::Triple::ppc: case llvm::Triple::ppc64: { @@ -644,12 +635,11 @@ 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)) Index: lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h =================================================================== --- lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h +++ lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h @@ -86,10 +86,6 @@ lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr) override; - size_t - GetSoftwareBreakpointTrapOpcode(Target &target, - BreakpointSite *bp_site) override; - bool GetRemoteOSVersion () override; Index: lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp +++ lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp @@ -585,34 +585,6 @@ 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 () { Index: lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.h =================================================================== --- lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.h +++ lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.h @@ -72,10 +72,6 @@ return GetPluginDescriptionStatic(IsHost()); } - size_t - GetSoftwareBreakpointTrapOpcode(lldb_private::Target &target, - lldb_private::BreakpointSite *bp_site) override; - bool GetRemoteOSVersion() override; Index: lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp =================================================================== --- lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ lldb/trunk/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -321,42 +321,6 @@ 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 () { Index: lldb/trunk/source/Target/Platform.cpp =================================================================== --- lldb/trunk/source/Target/Platform.cpp +++ lldb/trunk/source/Target/Platform.cpp @@ -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 @@ 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; +}