I typed help while I was in the GDB but didn't find anything about step-into, step-over and step-out. I put a breakpoint in an Assembly program in _start (break _start). Afterwards I typed next and it finished the debugging. I guess it was because it finished _start and didn't step-into as I wanted.
- Read the full GDB docs. As I recall, they were quite helpful about this, when I was first learning it. Unfortunately, I haven't needed to debug any program at that level for several decades, so the actual commands seem to have gotten swapped out in my brain. So, I can't really write an answer. But, if you do figure it out from the manuals, then you can answer your own question for a bonus.MAP– MAP2016-07-24 17:32:41 +00:00Commented Jul 24, 2016 at 17:32
- @MAP I'll try again. I tried to use a better debugger (KDbg) but I don't succeed to use it in Ubuntu.Pichi Wuana– Pichi Wuana2016-07-24 17:38:54 +00:00Commented Jul 24, 2016 at 17:38
- gdb is a good debugger. You may want to use Emacs as its frontend.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2020-01-02 06:50:16 +00:00Commented Jan 2, 2020 at 6:50
3 Answers
help running provides some hints:
There are step and next instuctions (and also nexti and stepi).
(gdb) help next Step program, proceeding through subroutine calls. Usage: next [N] Unlike "step", if the current source line calls a subroutine, this command does not enter the subroutine, but instead steps over the call, in effect treating it as a single source line. So we can see that step steps into subroutines, but next will step over subroutines.
The step and stepi (and the next and nexti) are distinguishing by "line" or "instruction" increments.
step -- Step program until it reaches a different source line stepi -- Step one instruction exactly Related is finish:
(gdb) help finish Execute until selected stack frame returns. Usage: finish Upon return, the value returned is printed and put in the value history. A lot more useful information is at https://sourceware.org/gdb/onlinedocs/gdb/Continuing-and-Stepping.html
- 1What does it mean by until it reaches a different source line?Pichi Wuana– Pichi Wuana2016-07-24 18:04:21 +00:00Commented Jul 24, 2016 at 18:04
- 2
for(i=0;i<10;i++) { printf("%d\n",i); }is one source line but multiple instructions.Stephen Harris– Stephen Harris2016-07-24 18:06:14 +00:00Commented Jul 24, 2016 at 18:06 - 7Is there a way to step-out? I couldn't find it in help running.nukeguy– nukeguy2017-08-23 16:34:16 +00:00Commented Aug 23, 2017 at 16:34
- 6What do you mean by "step-out"? The
finishcommand will complete the current stack frame, which will normally complete the current subroutine and return to the caller.Stephen Harris– Stephen Harris2017-08-24 02:03:03 +00:00Commented Aug 24, 2017 at 2:03 - 8
finishorfinin GDB, is thestep-outinIDEAorEclipse.Eric– Eric2020-02-23 08:18:43 +00:00Commented Feb 23, 2020 at 8:18
Use command 'finish'; this sometimes does the same thing as 'step-out'. It'll finish what the stack is doing (a function, usually), and go to the next line after that. Look up the command for more info.
I came here because I had the same question. I eventually figured that for my purpose any time I could use something like "step-out" of a loop I can just set another breakpoint after the loop and then let the program continue to finish the loop and run into the breakpoint afterward. Sorry if that is obvious to most people but it is probably helpful for someone looking for an answer to this question.
- 1"Step out" in most other debuggers is "finish" in gdb. Not really to do with exiting a loop.RichieHH– RichieHH2021-03-02 19:00:58 +00:00Commented Mar 2, 2021 at 19:00
- I think that's the
untilcommand that you ought to use for that.Johan Boulé– Johan Boulé2023-04-03 11:50:26 +00:00Commented Apr 3, 2023 at 11:50