llvm-project/lldb/tools
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
..
compact-unwind The lldb unwinder can now use the unwind information from the compact-unwind 2014-12-08 03:09:00 +00:00
darwin-debug Fix typos. 2014-07-01 21:22:11 +00:00
darwin-threads Fix examine-threads to build for arm64. 2014-11-14 22:58:25 +00:00
debugserver Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
driver Make the sourcing of the local .lldbinit file quiet. 2014-11-22 01:33:22 +00:00
install-headers Fixed our install-headers script to set version 2014-07-17 17:26:38 +00:00
lldb-gdbserver Make LLGS to open a named pipe and write a listening port to it only when a proper port value is received. 2014-11-27 20:51:24 +00:00
lldb-mi Fix a bug where global variable can be reported as local. 2014-12-08 18:07:40 +00:00
lldb-perf Cleanup how we listen for process events by using the broadcaster class name instead of having to catch each process instance as it comes alive. 2014-08-18 21:09:50 +00:00
lldb-platform Remove unused change to argc/argv after long option parsing has been completed. 2014-10-16 01:50:14 +00:00
CMakeLists.txt LLGS Android target support - for Andy Chien : http://reviews.llvm.org/D6166 2014-11-08 01:41:49 +00:00
Makefile Avoid building lldb-mi when --enable-werror is set 2014-11-04 23:30:30 +00:00