gdb step not working as expected

16,273

Solution 1

What could be the reason of this behavior?

It's a bug in GDB. It sets a temporary breakpoint and expects it to be hit. But the breakpoint doesn't get hit (possibly because it was set in the wrong place), and GDB's internal state machine gets all confused.

Is there any workarounds besides using stepi?

You can try upgrading to top-of-trunk GDB version from CVS, and if GDB is still broken, report the bug in GDB bugzilla.

Solution 2

It's a bit old post. I still beleive there can be someone benefited with this.

I hit the same issue. In my case the process was multi-threaded. And I happened to notice that the thread which hit a break point was stopped and the other threads were executing:

  6 Thread 1000368545  (running)
  5 Thread 1000368389  (running)
  4 Thread 1000368388  (running)
  3 Thread 1000368387  (running)
  2 Thread 1000368386  myBreakPointFunction () at location/in/my/sourcefile.c:linenumber
* 1 Thread 1000367766  (running)

while issuing the 'bt' command it did display 'Target is executing.' Once I moved to thread 2 (by issuing 'thread 2') and issuing a bt, I could see my call trace. For more inforomation or if your would like to do some experimentation, I suggest "set scheduler-locking" may prove to be helpful. Details for this mode are available at: https://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html

Solution 3

Step command Warning:

If you use the step command while control is within a function that was compiled without debugging information, execution proceeds until control reaches a function that does have debugging information. Likewise, it will not step into a function which is compiled without debugging information.

Also, the step command only enters a function if there is line number information for the function. Otherwise it acts like the next command.

Share:
16,273
ks1322
Author by

ks1322

Apparently, this user prefers to keep an air of mystery about them.

Updated on June 17, 2022

Comments

  • ks1322
    ks1322 almost 2 years

    I am debugging static multi-threaded x86-64 C++ application on Linux.

    I can set breakpoints on functions and stop on them and I can walk step by step over function body. But when I try to step into another function, gdb not stops at it's beginning and it seems that it just continues execution. When I interrupt program execution, gdb goes to broken state and becomes unusable:

    (gdb) bt
    Target is executing.
    (gdb) c
    Continuing.
    Cannot execute this command while the selected thread is running.
    (gdb) 
    

    As a workaround I can use stepi several times instead of step, stepi works as expected. What could be the reason of this behavior? Is there any workarounds besides using stepi? I am using gdb 7.6 and gcc 4.7.1.