llvm-project/lldb/tools/debugserver/source
Greg Clayton a97c4d2154 Handle thumb IT instructions correctly all the time.
The issue with Thumb IT (if/then) instructions is the IT instruction preceeds up to four instructions that are made conditional. If a breakpoint is placed on one of the conditional instructions, the instruction either needs to match the thumb opcode size (2 or 4 bytes) or a BKPT instruction needs to be used as these are always unconditional (even in a IT instruction). If BKPT instructions are used, then we might end up stopping on an instruction that won't get executed. So if we do stop at a BKPT instruction, we need to continue if the condition is not true.

When using the BKPT isntructions are easy in that you don't need to detect the size of the breakpoint that needs to be used when setting a breakpoint even in a thumb IT instruction. The bad part is you will now always stop at the opcode location and let LLDB determine if it should auto-continue. If the BKPT instruction is used, the BKPT that is used for ARM code should be something that also triggers the BKPT instruction in Thumb in case you set a breakpoint in the middle of code and the code is actually Thumb code. A value of 0xE120BE70 will work since the lower 16 bits being 0xBE70 happens to be a Thumb BKPT instruction. 

The alternative is to use trap or illegal instructions that the kernel will translate into breakpoint hits. On Mac this was 0xE7FFDEFE for ARM and 0xDEFE for Thumb. The darwin kernel currently doesn't recognize any 32 bit Thumb instruction as a instruction that will get turned into a breakpoint exception (EXC_BREAKPOINT), so we had to use the BKPT instruction on Mac. The linux kernel recognizes a 16 and a 32 bit instruction as valid thumb breakpoint opcodes. The benefit of using 16 or 32 bit instructions is you don't stop on opcodes in a IT block when the condition doesn't match. 

To further complicate things, single stepping on ARM is often implemented by modifying the BCR/BVR registers and setting the processor to stop when the PC is not equal to the current value. This means single stepping is another way the ARM target can stop on instructions that won't get executed.

This patch does the following:
1 - Fix the internal debugserver for Apple to use the BKPT instruction for ARM and Thumb
2 - Fix LLDB to catch when we stop in the middle of a Thumb IT instruction and continue if we stop at an instruction that won't execute
3 - Fixes this in a way that will work for any target on any platform as long as it is ARM/Thumb
4 - Adds a patch for ignoring conditions that don't match when in ARM mode (see below)

This patch also provides the code that implements the same thing for ARM instructions, though it is disabled for now. The ARM patch will check the condition of the instruction in ARM mode and continue if the condition isn't true (and therefore the instruction would not be executed). Again, this is not enable, but the code for it has been added.

<rdar://problem/19145455> 

llvm-svn: 223851
2014-12-09 23:31:02 +00:00
..
MacOSX Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
ARM_DWARF_Registers.h Various fixes for armv7 floating point/vector register support. 2013-03-13 00:14:30 +00:00
ARM_GCC_Registers.h Various fixes for armv7 floating point/vector register support. 2013-03-13 00:14:30 +00:00
CMakeLists.txt Fix codesigning of MacOSX debugserver when built with cmake. 2014-10-02 16:59:30 +00:00
ChangeLog Fix typos. 2014-07-01 21:22:11 +00:00
DNB.cpp Fix unused-variable warnings from the clang static analyzer. 2014-10-15 23:13:51 +00:00
DNB.h Fix typos. 2014-07-08 18:05:41 +00:00
DNBArch.cpp lldb arm64 import. 2014-03-29 18:54:20 +00:00
DNBArch.h lldb arm64 import. 2014-03-29 18:54:20 +00:00
DNBBreakpoint.cpp Huge performance improvements when one breakpoint contains many locations. 2013-06-12 00:46:38 +00:00
DNBBreakpoint.h Huge performance improvements when one breakpoint contains many locations. 2013-06-12 00:46:38 +00:00
DNBDataRef.cpp <rdar://problem/13069948> 2013-01-25 18:06:21 +00:00
DNBDataRef.h Simplify the logic for DNBDataRef::ValidOffsetForDataOfSize() and DNBDataRef::ValidOffset() functions. 2013-03-21 00:24:59 +00:00
DNBDefs.h __arm64__ and __aarch64__ #ifdef adjustments 2014-07-09 01:29:05 +00:00
DNBError.cpp lldb arm64 import. 2014-03-29 18:54:20 +00:00
DNBError.h lldb arm64 import. 2014-03-29 18:54:20 +00:00
DNBLog.cpp Added support for the qCmd monitor packet command. Currently it can only do: 2013-02-02 01:13:48 +00:00
DNBLog.h <rdar://problem/15172417> 2013-11-13 23:28:31 +00:00
DNBRegisterInfo.cpp Patch from Filipe Cabecinhas. 2012-04-26 17:09:38 +00:00
DNBRegisterInfo.h
DNBRuntimeAction.h
DNBThreadResumeActions.cpp
DNBThreadResumeActions.h
DNBTimer.h After discussing with Chris Lattner, we require C++11, so lets get rid of the macros and just use C++11. 2013-04-18 22:45:39 +00:00
Makefile Make lldb build with Makefiles on OS X. 2014-01-18 08:05:32 +00:00
PThreadCondition.h
PThreadEvent.cpp
PThreadEvent.h Fix a few typos. 2014-06-27 02:42:12 +00:00
PThreadMutex.cpp
PThreadMutex.h
PseudoTerminal.cpp Remove unused include of deprecated header. 2011-10-23 16:31:38 +00:00
PseudoTerminal.h
RNBContext.cpp Increase the gdb-remote packet timeout for the first packet we send 2014-07-24 01:36:24 +00:00
RNBContext.h lldb arm64 import. 2014-03-29 18:54:20 +00:00
RNBDefs.h __arm64__ and __aarch64__ #ifdef adjustments 2014-07-09 01:29:05 +00:00
RNBRemote.cpp Fix unused-variable warnings from the clang static analyzer. 2014-10-15 23:13:51 +00:00
RNBRemote.h Fix a few typos. 2014-06-27 02:42:12 +00:00
RNBServices.cpp Fix unused-variable warnings from the clang static analyzer. 2014-10-15 23:13:51 +00:00
RNBServices.h lldb arm64 import. 2014-03-29 18:54:20 +00:00
RNBSocket.cpp Replace all in_port_t with uint16_t to avoid compilation issues on different systems. 2013-12-06 17:46:35 +00:00
RNBSocket.h Replace all in_port_t with uint16_t to avoid compilation issues on different systems. 2013-12-06 17:46:35 +00:00
SysSignal.cpp
SysSignal.h
TTYState.cpp
TTYState.h Revert the debugserver part of r211868. While formally a fine change, debugserver 2014-06-27 16:02:55 +00:00
com.apple.debugserver.applist.internal.plist Added the plists to the debugserver project and fixed the labels for the new plists. 2012-10-31 23:49:14 +00:00
com.apple.debugserver.applist.plist Clarify the launch style for debugserver to use. 2014-10-28 03:15:33 +00:00
com.apple.debugserver.internal.plist Added the plists to the debugserver project and fixed the labels for the new plists. 2012-10-31 23:49:14 +00:00
com.apple.debugserver.plist Clarify the launch style for debugserver to use. 2014-10-28 03:15:33 +00:00
com.apple.debugserver.posix.plist Correct the label for the com.apple.debugserver.posix plist. 2012-11-29 00:01:49 +00:00
debugserver-entitlements.plist Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
debugserver-macosx-entitlements.plist Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
debugserver.cpp Increase the gdb-remote packet timeout for the first packet we send 2014-07-24 01:36:24 +00:00
libdebugserver.cpp Add support for building debugserver with CMake (on Mac OS X) 2013-08-09 16:29:10 +00:00
libdebugserver.h Add the standard LLVM copyright notice to the top of 2013-03-01 00:11:36 +00:00