Re: gdb not breaking on break statements
Re: gdb not breaking on break statements
- Subject: Re: gdb not breaking on break statements
- From: Jason Molenda <email@hidden>
- Date: Thu, 8 Nov 2007 16:44:09 -0800
On Nov 8, 2007, at 4:28 PM, Steve Checkoway wrote:
When I set a breakpoint on a line containing a break statement, gdb
will always break on the line following it.
For example, breaking on line 7 (the break statement) of
int main()
{
int i = 0;
while( 1 )
{
if( i == 10 )
break;
++i;
}
return 0;
}
It may help if you look at the i386 assembly for this function:
0x00001fde <main+0>: push ëp
0x00001fdf <main+1>: mov %esp,ëp
0x00001fe1 <main+3>: sub $0x18,%esp
0x00001fe4 <main+6>: movl $0x0,-0xc(ëp) ; set i to 0
0x00001feb <main+13>: jmp 0x1ff2 <main+20>
0x00001fed <main+15>: lea -0xc(ëp),êx ; get the address of i
0x00001ff0 <main+18>: incl (êx) ; increment i
0x00001ff2 <main+20>: cmpl $0xa,-0xc(ëp) ; compare i to 10
0x00001ff6 <main+24>: jne 0x1fed <main+15> ; do the loop if not
equal
0x00001ff8 <main+26>: mov $0x0,êx
0x00001ffd <main+31>: leave
0x00001ffe <main+32>: ret
line 7 doesn't really correspond to anything here. The compiler only
tells the debugger that a couple of lines of code contribute
instructions:
(gdb) info line 1
Line 1 of "l.c" is at address 0x1fde <main> but contains no code.
(gdb) i line 2
Line 2 of "l.c" starts at address 0x1fde <main> and ends at 0x1fe4
<main+6>.
(gdb) i line 3
Line 3 of "l.c" starts at address 0x1fe4 <main+6> and ends at 0x1fed
<main+15>.
(gdb) i line 4
Line 4 of "l.c" is at address 0x1ff2 <main+20> but contains no code.
(gdb) i line 5
Line 5 of "l.c" is at address 0x1ff2 <main+20> but contains no code.
(gdb) i line 6
Line 6 of "l.c" starts at address 0x1ff2 <main+20> and ends at 0x1ff8
<main+26>.
(gdb) i line 7
Line 7 of "l.c" is at address 0x1fed <main+15> but contains no code.
(gdb) i line 8
Line 8 of "l.c" starts at address 0x1fed <main+15> and ends at 0x1ff2
<main+20>.
(gdb) i line 9
Line 9 of "l.c" is at address 0x1ff8 <main+26> but contains no code.
(gdb) i line 10
Line 10 of "l.c" is at address 0x1ff8 <main+26> but contains no code.
(gdb)
As far as the debugger knows, line 7 is a blank line or a comment or
something like that. Even though this is compiled without
optimization, the way that the compiler generates assembly for this
source code is not exactly what you might have expected. The older
compilers that you compared against may have generated code in a
different way, or possibly you were comparing a ppc compiler which
would result in different codegen.
Jason
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden