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 Thursday 18 March 2010 15:13:38 Daniel Jacobowitz wrote:
> 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 used the term from the comment 

  "Optimize by setting the stepping range to the line."

For me it's in fact the opposite to an optimization as the single stepping 
through the rest of the second line leads to one round trip through the 
stub for each of the remaining instructions which easily sums up to a
couple of seconds for lines that generate a hundred instructions.

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

I see. Thanks for the explanation.

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

I'll do that.

Andre'


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