delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/04/11/08:05:00

Date: Wed, 11 Apr 2001 15:00:06 +0300
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: Dennis Yelle <dennis51 AT jps DOT net>
Message-Id: <1858-Wed11Apr2001145958+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9
CC: djgpp AT delorie DOT com
In-reply-to: <3AD3339E.2C1F2F32@jps.net> (message from Dennis Yelle on Tue, 10
Apr 2001 09:23:58 -0700)
Subject: Re: gdb still doesn't work for me
References: <3AD0B992 DOT 44D0D3C3 AT jps DOT net> <4634-Sun08Apr2001234906+0300-eliz AT is DOT elta DOT co DOT il> <3AD10B71 DOT 9019CC9 AT jps DOT net> <3AD1E414 DOT 8D811D08 AT jps DOT net> <9auqog$6ah$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <3AD3339E DOT 2C1F2F32 AT jps DOT net>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019