Wrong breakpoint location, -Og, dwarf & gdb
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Fix Released
|
Undecided
|
Terry Guo |
Bug Description
I received a report from one of the GNU ARM Eclipse users that, for some instructions inside loops, the breakpoints are not placed properly.
I checked and the problem is real, probably due to common subexpression optimisations, for statements that have some parts moved outside the loop, when breakpoints are set, they use the address of the part outside the loop, not the address of the part inside the loop.
For tests, I used -mcpu=cortex-m4 -mthumb -Og, -g3, -gdwarf-4, and a code like this:
for (int i=0, i < 5; ++i)
printf("%d\n", i);
printf("done\n");
Set two breakpoints, one on the inner printf(), and one on the final printf().
For the first run, execution will stop as expected on the first printf(), but after a continue execution will stop at the final printf(), although the loop is performed correctly and the first breakpoint is still active.
As I already mentioned, the printf() statement has a common part (setting the address of the string in a register) that is moved outside the loop, and a part with the actual call, inside the loop.
When the breakpoint is set, the location used by GDB is the address of the code outside the loop. This makes execution stop for the firs time, but a 'continue' at this point will make execution never reach the first breakpoint, and the program will run up to the final printf() without any problems.
Since switching from dwarf to stubs+ seems ok, I expect the problem to be either in the way the dwarf sections are generated by GCC, or in the way these sections are used by GDB.
I don't know details about dwarf internals, and how would it be possible for gdb to set breakpoints to both outer and inner addresses, but the current behaviour is not ok.
Since on -O0 the problem is not present, one possible way to avoid the problem would be to configure -Og so that moving code outside the loop be disabled.
Regards,
Liviu
Changed in gcc-arm-embedded: | |
status: | In Progress → Fix Released |
Thanks for reporting. We are trying to improve the overall debugging experience of Og option. Welcome to report more Og related issues/ concerns/ comments.