public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* gdb shows source line multiple times before executing !!
@ 2003-07-24 14:28 mohanlal jangir
  2003-07-24 14:39 ` Nikola Kolev
  0 siblings, 1 reply; 9+ messages in thread
From: mohanlal jangir @ 2003-07-24 14:28 UTC (permalink / raw)
  To: gdb

While single stepping with gdb, quite frequently I see sorce lines appearing
multiple times i.e. gdb shows some line that will be executed on command
"next", but that is actully not. After next "next" command, I see same line
appearing. This happens two or three times and then finally that line is
executed.

gdb --version command gives following output:
GNU gdb Red Hat Linux 7.x (5.0rh-15) (MI_OUT)
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux".


Regards
Mohanlal

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:28 gdb shows source line multiple times before executing !! mohanlal jangir
@ 2003-07-24 14:39 ` Nikola Kolev
  2003-07-24 14:44   ` mohanlal jangir
  0 siblings, 1 reply; 9+ messages in thread
From: Nikola Kolev @ 2003-07-24 14:39 UTC (permalink / raw)
  To: mohanlal jangir; +Cc: gdb

the executable is probably optimized (gcc/g++ -O2 ...)

mohanlal jangir wrote:

>While single stepping with gdb, quite frequently I see sorce lines appearing
>multiple times i.e. gdb shows some line that will be executed on command
>"next", but that is actully not. After next "next" command, I see same line
>appearing. This happens two or three times and then finally that line is
>executed.
>
>gdb --version command gives following output:
>GNU gdb Red Hat Linux 7.x (5.0rh-15) (MI_OUT)
>Copyright 2001 Free Software Foundation, Inc.
>GDB is free software, covered by the GNU General Public License, and you are
>welcome to change it and/or distribute copies of it under certain
>conditions.
>Type "show copying" to see the conditions.
>There is absolutely no warranty for GDB.  Type "show warranty" for details.
>This GDB was configured as "i386-redhat-linux".
>
>
>Regards
>Mohanlal
>
>  
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:39 ` Nikola Kolev
@ 2003-07-24 14:44   ` mohanlal jangir
  2003-07-24 14:48     ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: mohanlal jangir @ 2003-07-24 14:44 UTC (permalink / raw)
  To: gdb

Actully yes. I will try to figure out if this is only reason, but can you
explain why this happens if executable is optimized.

> the executable is probably optimized (gcc/g++ -O2 ...)
>
> mohanlal jangir wrote:
>
> >While single stepping with gdb, quite frequently I see sorce lines
appearing
> >multiple times i.e. gdb shows some line that will be executed on command
> >"next", but that is actully not. After next "next" command, I see same
line
> >appearing. This happens two or three times and then finally that line is
> >executed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:44   ` mohanlal jangir
@ 2003-07-24 14:48     ` Daniel Jacobowitz
  2003-07-24 14:56       ` mohanlal jangir
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2003-07-24 14:48 UTC (permalink / raw)
  To: mohanlal jangir; +Cc: gdb

Because GCC splits the code for the line into multiple parts.  Part of
the line has executed when you step over it, but it may not be
immediately obvious how.  For instance, given:
  a = b + c;
the first time you step over it may load b and c from memory; the
second time may add them; and only the third will store the result into
a.

On Thu, Jul 24, 2003 at 08:08:24PM +0530, mohanlal jangir wrote:
> Actully yes. I will try to figure out if this is only reason, but can you
> explain why this happens if executable is optimized.
> 
> > the executable is probably optimized (gcc/g++ -O2 ...)
> >
> > mohanlal jangir wrote:
> >
> > >While single stepping with gdb, quite frequently I see sorce lines
> appearing
> > >multiple times i.e. gdb shows some line that will be executed on command
> > >"next", but that is actully not. After next "next" command, I see same
> line
> > >appearing. This happens two or three times and then finally that line is
> > >executed.
> 
> 

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:48     ` Daniel Jacobowitz
@ 2003-07-24 14:56       ` mohanlal jangir
  2003-07-24 15:17         ` Nikola Kolev
                           ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: mohanlal jangir @ 2003-07-24 14:56 UTC (permalink / raw)
  To: gdb


> Because GCC splits the code for the line into multiple parts.  Part of
> the line has executed when you step over it, but it may not be
> immediately obvious how.  For instance, given:
>   a = b + c;
> the first time you step over it may load b and c from memory; the
> second time may add them; and only the third will store the result into
> a.
hmm... but sometimes it behaves even worse. For example there are two lines
a = b + c;
d = e + f;
then first gdb shows line a = b + c; then d = e + f and then again a = b +
c. And while showing d = e + f first time if I try to print value of a, it
will be some uninitialised (that indicates that a = b + c has not been
executed). Then on next "next" command I will see line a = b +c again and
then valute of a will be correct one.

> > mohanlal jangir wrote:
> >
> >While single stepping with gdb, quite frequently I see sorce lines
> appearing
> >multiple times i.e. gdb shows some line that will be executed on command
> >"next", but that is actully not. After next "next" command, I see same
> line
> >appearing. This happens two or three times and then finally that line is
> >executed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:56       ` mohanlal jangir
@ 2003-07-24 15:17         ` Nikola Kolev
  2003-07-24 15:20         ` Daniel Jacobowitz
  2003-07-24 15:20         ` Elena Zannoni
  2 siblings, 0 replies; 9+ messages in thread
From: Nikola Kolev @ 2003-07-24 15:17 UTC (permalink / raw)
  To: mohanlal jangir; +Cc: gdb

why don't you take the optimization flags (-ON) out, live the debug flag 
(-g) in, recompile, fire up the debugger, do your stuff, instead of 
wasting time, energy, bandwidth, etc. to explain something that is 
obvious to why it's happening...

--Nik

mohanlal jangir wrote:

>>Because GCC splits the code for the line into multiple parts.  Part of
>>the line has executed when you step over it, but it may not be
>>immediately obvious how.  For instance, given:
>>  a = b + c;
>>the first time you step over it may load b and c from memory; the
>>second time may add them; and only the third will store the result into
>>a.
>>    
>>
>hmm... but sometimes it behaves even worse. For example there are two lines
>a = b + c;
>d = e + f;
>then first gdb shows line a = b + c; 
>
that's when it loded b and c from memory, and possibly stored their sum 
in a temporary register

>then d = e + f and then again a = b +
>c. And while showing d = e + f first time if I try to print value of a, it
>will be some uninitialised (that indicates that a = b + c has not been
>executed). 
>
It is uninitialized, because it has not assigned the the sum to a yet, 
but skipped to load e and f because it determined it will be faster that 
way (here's where optimization comes to play)...

>Then on next "next" command I will see line a = b +c again and
>then valute of a will be correct one.
>  
>
Well, that's when it assigned a with what you're looking for...


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:56       ` mohanlal jangir
  2003-07-24 15:17         ` Nikola Kolev
  2003-07-24 15:20         ` Daniel Jacobowitz
@ 2003-07-24 15:20         ` Elena Zannoni
  2 siblings, 0 replies; 9+ messages in thread
From: Elena Zannoni @ 2003-07-24 15:20 UTC (permalink / raw)
  To: mohanlal jangir; +Cc: gdb

mohanlal jangir writes:
 > 
 > > Because GCC splits the code for the line into multiple parts.  Part of
 > > the line has executed when you step over it, but it may not be
 > > immediately obvious how.  For instance, given:
 > >   a = b + c;
 > > the first time you step over it may load b and c from memory; the
 > > second time may add them; and only the third will store the result into
 > > a.
 > hmm... but sometimes it behaves even worse. For example there are two lines
 > a = b + c;
 > d = e + f;
 > then first gdb shows line a = b + c; then d = e + f and then again a = b +
 > c. And while showing d = e + f first time if I try to print value of a, it
 > will be some uninitialised (that indicates that a = b + c has not been
 > executed). Then on next "next" command I will see line a = b +c again and
 > then valute of a will be correct one.

Yes, only part of the assembly instructions that correspond to the
line a = b+c; has been executed at that time, and the result hasn't
been transfered into the location of a yet.  Try to use stepi.  Also
compare with the execution on the same program compiled with -O0 or just
with -g.

elena

 > 
 > > > mohanlal jangir wrote:
 > > >
 > > >While single stepping with gdb, quite frequently I see sorce lines
 > > appearing
 > > >multiple times i.e. gdb shows some line that will be executed on command
 > > >"next", but that is actully not. After next "next" command, I see same
 > > line
 > > >appearing. This happens two or three times and then finally that line is
 > > >executed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 14:56       ` mohanlal jangir
  2003-07-24 15:17         ` Nikola Kolev
@ 2003-07-24 15:20         ` Daniel Jacobowitz
  2003-07-24 15:53           ` Doug Evans
  2003-07-24 15:20         ` Elena Zannoni
  2 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2003-07-24 15:20 UTC (permalink / raw)
  To: gdb

On Thu, Jul 24, 2003 at 08:21:02PM +0530, mohanlal jangir wrote:
> 
> > Because GCC splits the code for the line into multiple parts.  Part of
> > the line has executed when you step over it, but it may not be
> > immediately obvious how.  For instance, given:
> >   a = b + c;
> > the first time you step over it may load b and c from memory; the
> > second time may add them; and only the third will store the result into
> > a.
> hmm... but sometimes it behaves even worse. For example there are two lines
> a = b + c;
> d = e + f;
> then first gdb shows line a = b + c; then d = e + f and then again a = b +
> c. And while showing d = e + f first time if I try to print value of a, it
> will be some uninitialised (that indicates that a = b + c has not been
> executed). Then on next "next" command I will see line a = b +c again and
> then valute of a will be correct one.

Then there's some other cleanup to be done that the compiler hasn't
finished with yet.  I recommend either not worrying about it, or
looking at the assembly to understand what's going on.

> 
> > > mohanlal jangir wrote:
> > >
> > >While single stepping with gdb, quite frequently I see sorce lines
> > appearing
> > >multiple times i.e. gdb shows some line that will be executed on command
> > >"next", but that is actully not. After next "next" command, I see same
> > line
> > >appearing. This happens two or three times and then finally that line is
> > >executed.
> 
> 

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: gdb shows source line multiple times before executing !!
  2003-07-24 15:20         ` Daniel Jacobowitz
@ 2003-07-24 15:53           ` Doug Evans
  0 siblings, 0 replies; 9+ messages in thread
From: Doug Evans @ 2003-07-24 15:53 UTC (permalink / raw)
  To: mohanlal jangir; +Cc: Daniel Jacobowitz, gdb

Daniel Jacobowitz writes:
 > I recommend either not worrying about it, or
 > looking at the assembly to understand what's going on.

It might also help to step through the assembly
instead of stepping line-by-line.

(gdb) display/i $pc
(gdb) stepi
[and keep repeating stepi, which will happen if at this point
you just keep hitting <return>]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-07-24 15:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-24 14:28 gdb shows source line multiple times before executing !! mohanlal jangir
2003-07-24 14:39 ` Nikola Kolev
2003-07-24 14:44   ` mohanlal jangir
2003-07-24 14:48     ` Daniel Jacobowitz
2003-07-24 14:56       ` mohanlal jangir
2003-07-24 15:17         ` Nikola Kolev
2003-07-24 15:20         ` Daniel Jacobowitz
2003-07-24 15:53           ` Doug Evans
2003-07-24 15:20         ` Elena Zannoni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).