Bug 20926 - gdb misses breakpoint and stops one line after
Summary: gdb misses breakpoint and stops one line after
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: 7.7
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2016-12-05 04:49 UTC by jerry.marbas
Modified: 2017-11-06 18:32 UTC (History)
1 user (show)

See Also:
Last reconfirmed: 2017-01-05 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description jerry.marbas 2016-12-05 04:49:19 UTC
I am trying to debug a simple assembly language program in gdb and setting a breakpoint at the _start label(line 5), but when I run it, the program stops one line after on line 6, not on line 5.

I cannot find the reason for this behaviour on google or from my searches on the Raspbian bug database.

To repeat the steps below, run the program on a Raspberry Pi 3 running Raspbian 8.0 Jessie and gdb version 7.7.1

1 @filename: P2_1.s -- program adds contents of two registers together.
3 .text
4 .global _start
5 _start:  MOV R1, #0x25     @storing 25 hex in R1
6          MOV R2, #0x34     @storing 34 hex in R2
7          ADD R3, R2, R1    @adding R1 and R2
8 HERE:   B   HERE           @infinite loop
9 .end    
Compile and link including debug symbols like this:

$ as -g -o P2_1.o P2_1.s; ld -o P2_1 P2_1.o
Then run gdb like this:

$ gdb P2_1
Then in gdb add a breakpoint at the _start label like this:

(gdb) break _start
Breakpoint 1 at 0x10058: file P2_1.s, line 6.

The breakpoint is added to line 6 not line 5. When you run it, it should stop at line 5, but it doesnt. It stops at line 6.

I posted this issue on stackexchange but maybe that wasnt the right place for it so Im submitting a bug report about it here.

Comment 1 Luis Machado 2017-01-05 20:06:05 UTC
I think you want "b *_start" if you want to stop at the first instruction of the function. Otherwise "b _start" will cause gdb to attempt to skip what it thinks is the prologue of the function, which is probably causing the breakpoint to be moved to line 6.

This doesn't look like a bug.
Comment 2 Luis Machado 2017-11-06 18:32:31 UTC
No longer working on it.