I have checked in fixes for Thumb IT support into the top of tree code. 

Now we still have a case where in ARM mode we can stop at instructions that are 
conditional and the condition isn't true to the opcodes won't get executed 
(just like what was happening in the Thumb IT instruction). I have a "#if 0" in 
my patch in ArchSpec.cpp:1145. I would encourage anyone involved in ARM 
development to read what it does and see why it is in there. I believe we 
should enable this fix in LLDB, but I wanted to check with everyone on the list 
first before doing so. The main issue is that you can set a breakpoint in an 
"then" or "else" clause of an "if" statement and it will stop in both if you 
set a breakpoint on a conditional opcode. Like the Thumb patch, if we stop here 
we should continue with our step or run if an opcode won't be executed IMHO.

The details from the commit are:

"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> 
"



_______________________________________________
lldb-dev mailing list
lldb-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

Reply via email to