Author Topic: Why is single stepping with gdb so "jumpy"?  (Read 4035 times)

Offline Yamakuzure

  • Multiple posting newcomer
  • *
  • Posts: 20
Why is single stepping with gdb so "jumpy"?
« on: November 06, 2013, 10:31:43 pm »
Hi everybody!

I am using Code::Blocks SVN 9425 with gdb 7.6.1.

Whenever I single step a program the display is completely funky. It is like this:
Line with assignement is highlighted (value is shown as <optimized out>)
"Next Line": two lines down
"Next Line": two lines up
"Next Line": three or four lines down
"Next Line": back up
"Next Line": three or four lines down
"Next Line": back up
"Next Line": one line down. (Now the value is shown with its value and no longer <optimized out>.

Although this is annoying, it is not this critical. More critical are function calls like this:
Line with function call is highlighted.
"Step into": First line of function body shown
"Next Line": Back to function call
"Step into": Any of the first few lines in the function body shown
"Next Line": Back to some lines *above* the function call
"Next Line": Jump to function call
"Step into": First line of function body shown
"Next Line": From hereon the funky behavior above within the function is "performed".

As far as I can tell using "gdb --tui ..." gdb does show the steps correctly. Is this an issue with MI versus CLI interface? Or the gdb version I have nstalled?

Another (not so important) issue is the backtrace. When I double click any frame, a log message is generated "file not found", but when I right click and select "switch to frame", the correct file and location are opened.

Thanks in advance!

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: Why is single stepping with gdb so "jumpy"?
« Reply #1 on: November 06, 2013, 11:11:54 pm »
Sounds like what your seeing is when GDB doesn't have debugging symbols to use. You may want check if debugging symbols are enabled or not (-g) in your project and/or libraries.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2566
Re: Why is single stepping with gdb so "jumpy"?
« Reply #2 on: November 06, 2013, 11:29:52 pm »
look also if you have enabled any optimization... They should be turned off on debug builds (at least i think the line jumping comes from the optimization)

greetings
« Last Edit: November 07, 2013, 01:43:59 am by BlueHazzard »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Why is single stepping with gdb so "jumpy"?
« Reply #3 on: November 07, 2013, 12:10:18 am »
From your description, this is definitively debugging optimized code. Which is funny that you should complain about, because debugging optimized code is not even possible at all with most compilers.

It's already a great convenience that GCC+GDB allows you to do this at all. Seriously.

If you expect stepping in the debugger to go in a perfectly smooth manner, don't compile with optimizations. It is simply an impossible task for the debugger to display values that have been optimized out and to step through code that has been reordered, unrolled, dead-code-eliminated, and instruction-scheduled in a strictly linear fashion.
That's like trying to read next week's lotto draw in a crystal ball -- the information you want is simply not in there.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Yamakuzure

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Why is single stepping with gdb so "jumpy"?
« Reply #4 on: November 07, 2013, 10:33:37 am »
Ah! That's the catch. I found a typo that moved "-O2" back into the flags in debugging mode in my Makefile.

However, "debugging optimized code is not even possible at all with most compilers.", yes, but luckily "GCC allows you to use -g with -O. (...) it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.". (GCC-4.7.3 Debugging Options)
This is not only convenient, it is the only possiblility to make bugs debuggable that simply do not show up in non-optimized code.

However, thank you very much for your help!

I just fixed the error in the Makefile. And it works. It puzzles me a bit that I didn't think of that, but it never came to my mind that a (harmless!) change in the Makefile some months ago (found the offending commit) could have such consequences. ;)