This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gdb shows source line multiple times before executing !!


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]