This is the mail archive of the gdb@sourceware.org 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: Getting pissed off by gdb. Please help with stepping in.


On Thu, Mar 18, 2010 at 03:06:15PM +0100, André Pönitz wrote:
> This means a 'next' effectively jumps over two lines, which is rather nasty.
> So I have been removing this optimization in gdb for a while (as the stub 
> is not under my control) without experiencing any bad side effects. Most
> notably, stepping over  for (;;) does not seem to be affected at all.

It's not an "optimization" - it's to improve the user experience, not
to improve performance.

> I dug a bit in gdb's history, and the code is older than anything I could 
> access, i.e. before 1991 or so.  Together with the comment "That is said 
> to make things like for (;;) statements work better" one might get the 
> impression that it was a workaround for some particular compiler or such.
> 
> Does anybody happen to remember what triggered the inclusion of this
> optimization into gdb code?

I certainly don't remember, but I can make an educated guess.  It
depends how your compiler lays out for loops.  If the
condition on the for statement is adjacent to the initial operation:

  for-init
  for-cond
  loop-body
  for-increment
  unconditional branch to for-cond

Then stepping past the last line in loop-body will take you to the
middle of the "line" containing all of init, cond, and increment.

I don't think that's how GCC lays out loops nowadays, I think it's
more:

  for-init
  branch-forwards-to-cond
  loop-body
  for-increment
  for-cond

Whether the current behavior matters in practice, there I have no
idea.

One thing I've found helpful is to diff gdb testsuite log files with
such a change; the diff is noisy, but you can see if there was any
meaningful impact.

-- 
Daniel Jacobowitz
CodeSourcery


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