Search code examples
c++gdb

How can we step over a function call in GDB?


I want to understand how we can step over a function call. For instance, consider the following program:

 #include <iostream>
 #include "test.h"

 using std::cout;
 using std::endl;

 Uint u;

 int main()
 {
     cout << "execution starting..." << endl;
     cout << u.a << endl;
     cout << "execution completed" << endl;
 }

In GDB, I set a breakpoint at the 11th line (cout << "execution starting..." << endl;) with break 11.

Now I want to step over all instructions which are going to be invoked in printing "execution starting..." and stop at the << operator call that prints the endl symbol.

How can I do that? Which command should I use?


Solution

  • In GDB, step means stepping into (will go inside functions called), and next means stepping over (continue and stop at the next line).

    But in your particular case, next may not be what you want, and I would suggest to first step into the function printing "execution starting...", then use finish to continue until it returns, so that the program will stop at << endl.