hanchenye-llvm-project/lldb
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
..
cmake LLGS Android target support (r221570) missed adding some files: http://reviews.llvm.org/D6166 2014-11-10 15:06:15 +00:00
docs Fix lldb(1) man page formatting 2014-11-24 15:01:11 +00:00
examples Improved the TreeItem delegate which simplifies making tree items: 2014-10-07 17:30:23 +00:00
gtest Added StringExtractor::DecodeHexU8 && GetHexBytesAvail 2014-12-01 22:19:33 +00:00
include Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
lib Fix some bugs from D5988 2014-10-31 15:57:52 +00:00
lldb.xcodeproj The lldb unwinder can now use the unwind information from the compact-unwind 2014-12-08 03:09:00 +00:00
lldb.xcworkspace Fixup gtest layout, add Linux ThreadStateCoordinator.cpp. 2014-09-25 19:25:07 +00:00
resources Bump the verison number in the xcode project files. 2014-08-21 23:27:02 +00:00
scripts Add the ability for an SBValue to create a persisted version of itself. 2014-12-08 23:13:56 +00:00
source Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
test Extend ValueObject::GetExpressionPath() to do something reasonable for synthetic children 2014-12-09 21:41:16 +00:00
tools Handle thumb IT instructions correctly all the time. 2014-12-09 23:31:02 +00:00
utils LUI: Fix some issues causing crashes in the source view 2013-10-23 01:18:21 +00:00
www Add an initial description of the rules for constructing new SB API classes. 2014-12-06 00:28:05 +00:00
.arcconfig Update .arcconfig to point to reviews.llvm.org 2014-05-20 21:24:59 +00:00
.clang-format Fix .clang-format file to adhere to LLDB 140 column limit. 2014-08-19 17:18:38 +00:00
.gitignore Update .gitignore for MacOSX 2014-08-14 20:19:57 +00:00
CMakeLists.txt LLGS Android target support - for Andy Chien : http://reviews.llvm.org/D6166 2014-11-08 01:41:49 +00:00
INSTALL.txt Revert "git-svn test commit" 2014-11-18 22:45:59 +00:00
LICENSE.TXT
Makefile Remove the -Wno-unused-function option. We are clean 2014-09-09 07:49:15 +00:00