Mail Archives: djgpp/2001/04/11/08:05:00
> From: Dennis Yelle <dennis51 AT jps DOT net>
> Newsgroups: comp.os.msdos.djgpp
> Date: Tue, 10 Apr 2001 09:23:58 -0700
>
> My understanding is that the command 'n' is
> 'step over'.
That's true.
> That is, if the next line to be
> executed is line 20, and line 20 calls a function,
> or method, then the 'n' command would
> be equivalent to setting a breakpoint on line 21 and
> running the program until line 21 is reached.
Yes, provided that the compiler produces enough debugging information
for GDB to do that, `n' is indeed equivalent to this.
> Here is the source code again, just so
> everyone can see just how simple this program is:
> ----------------------------------------
> int count;
> int i, k;
>
> class Paths {
> public:
> static void car7()
> {
> for( i=0; i<10; i++) {
> for( k=0; k<1000000; k++) {
> if ( (i | k) == 127)
> ++count;
> }
> }
> }
> };
>
> int main()
> {
> count = 0;
> Paths::car7();
> count += 2;
> return count;
> }
Here's what I did, after extracting the above source to a file called
car.cc:
gxx -Wall -Os -g -o car.exe car.cc
gdb car.exe
(gdb) b main
(gdb) run
(gdb) n
This ran very fast. I cannot see any slow-down.
I do see that after "run", the program doesn't stop on the first
executable line of the `main' function, which is this:
count = 0;
Instead, it stops here:
count += 2;
which is _after_ Paths::car7() was called.
So I set a breakpoint on the first executable line of `main':
(gdb) b 19
(gdb) run
(gdb) n
And _now_ it indeed runs very slowly.
The problem seems to be that GCC inlines the call to Paths::car7(),
and that confuses GDB's "next" command. When "next" sees a call to a
function, it single-steps into the function over which it wants to
step, then sets a temporary breakpoint at the return address of that
function. But with an inlined function, there is no return address to
put a breakpoint on, and so GDB ends up single-stepping the whole
region of the instructions in the inlined call.
One way to avoid this is tell GCC not to inline (with the
"-fno-default-inline" option). Another way is to not use the `n'
command, and instead use "tb +1" and "c" commands. The first sets a
temporary breakpoint on the next source line, the second runs the
program until that breakpoint.
- Raw text -