llvm-project/lldb/tools/debugserver/source/MacOSX
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
..
arm Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
arm64 __arm64__ and __aarch64__ #ifdef adjustments 2014-07-09 01:29:05 +00:00
i386 Add comment explaining the dwarf v. eh_frame register numbering used 2014-08-13 00:21:31 +00:00
ppc Fix typos. 2014-07-08 18:05:41 +00:00
x86_64 Fix typos. 2014-07-08 18:05:41 +00:00
CFBundle.cpp Resolve any bundle paths we are given when the specified executable is a bundle. 2012-10-31 21:44:39 +00:00
CFBundle.h Resolve any bundle paths we are given when the specified executable is a bundle. 2012-10-31 21:44:39 +00:00
CFData.cpp
CFData.h
CFString.cpp
CFString.h
CFUtils.h
CMakeLists.txt Fix codesigning of MacOSX debugserver when built with cmake. 2014-10-02 16:59:30 +00:00
Genealogy.cpp Fix unused-variable warnings from the clang static analyzer. 2014-10-15 23:13:51 +00:00
Genealogy.h Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
GenealogySPI.h Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
HasAVX.h Added support for dynamic detection of AVX, and 2011-07-16 00:49:19 +00:00
HasAVX.s Fixed a problem where the HasAVX() code in 2011-08-09 18:10:15 +00:00
MachException.cpp <rdar://problem/14814689> 2013-11-13 23:33:41 +00:00
MachException.h lldb arm64 import. 2014-03-29 18:54:20 +00:00
MachProcess.h whitespace cleanup 2014-06-13 02:44:21 +00:00
MachProcess.mm Clarify the launch style for debugserver to use. 2014-10-28 03:15:33 +00:00
MachTask.h Allow for a task port to change when we exec. 2014-04-30 20:27:01 +00:00
MachTask.mm Fix unused-variable warnings from the clang static analyzer. 2014-10-15 23:13:51 +00:00
MachThread.cpp Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
MachThread.h Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
MachThreadList.cpp __arm64__ and __aarch64__ #ifdef adjustments 2014-07-09 01:29:05 +00:00
MachThreadList.h Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
MachVMMemory.cpp rdar://problem/18221417 2014-09-03 22:33:37 +00:00
MachVMMemory.h <rdar://problem/13963648> 2013-05-22 21:32:42 +00:00
MachVMRegion.cpp Always return a valid answer for qMemoryRegionInfo if the packet is supported. 2011-12-12 18:51:14 +00:00
MachVMRegion.h Always return a valid answer for qMemoryRegionInfo if the packet is supported. 2011-12-12 18:51:14 +00:00
Makefile Make lldb build with Makefiles on OS X. 2014-01-18 08:05:32 +00:00
ThreadInfo.h Initial merge of some of the iOS 8 / Mac OS X Yosemite specific 2014-06-13 02:37:02 +00:00
dbgnub-mig.defs
stack_logging.h Basic infrastructure code to exploit malloc stack logging as available on Mac OS X to track the allocation history of pointers on the target process 2011-09-09 00:04:24 +00:00