In the following code:
1 #include <iostream>
2
3 using namespace std;
4
5 int funcA(){
6 cout << "A" << endl;
7 return 1;
8 }
9
10 int funcB(){
11 cout << "B" << endl;
12 return 1;
13 }
14
15 int funcC(){
16 cout << "C" << endl;
17 return 1;
18 }
19
20 int funcAll( int a, int b, int c ){
21 return 1;
22 }
23
24 int main(){
25 cout << funcAll( funcA(), funcB(), funcC() ) << endl;
26 return 0;
27 }
28
Will be printed C, B, then A.
But when debuging and staying on line 25 if we command next on gdb the cursor goes to the line 26, if we command step gdb will step from funcC until funcA, but how to directly step on funcB OR funcA without setting a breakpoint or steping inside funcC.
The order of evaluation of the arguments of a function in C and C++ is unspecified. The compiler is free to reorder/interleave them however it sees fit, within certain constraints. So you cannot rely on
funcC()getting called beforefuncA().If you want to ensure that the arguments will get evaluated in a certain order, break them up into separate statements like this:
This will also make debugging easier.
If you don’t want to rewrite your code, you still have some alternatives. The easiest thing to do is just set a breakpoint inside your function of interest, e.g.:
Or if you only need to do this once, use a
tbreakinstead ofbreakto set a temporary breakpoint which will clear itself after it’s hit for the first time.You can also use the
nextiandstepiinstructions to step one assembly instruction at a time. By looking at the disassembly with thedisassemblecommand, you can step up to the appropriate call site (e.g. thecallinstruction on x86 or x86-64, orblon PowerPC) usingnexti, thenstepito step into it.stepiandnextiwork likestepandnext, except they operate on assembly instructions instead of lines of code.