sometimes i want to debug functions like this: my_func1(my_func2(my_func3(val)));
is there a way i can step through this nested call in gdb? I want to step through my_func3, then my_func2, then my_func1 etc
sometimes i want to debug functions like this: my_func1(my_func2(my_func3(val)));
is there a way i can step through this nested call in gdb? I want to step through my_func3, then my_func2, then my_func1 etc
What command are you stepping with? next
would go to next line when debugging my_func1(my_func2(my_func3(val)));
, but step
should enter my_func3.
Example:
int my_func1(int i)
{
return i;
}
int my_func2(int i)
{
return i;
}
int my_func3(int i)
{
return i;
}
int main(void)
{
return my_func1(my_func2(my_func3(1)));
}
Debugged:
(gdb) b main
Breakpoint 1 at 0x4004a4: file c.c, line 19.
(gdb) run
Starting program: test
Breakpoint 1, main () at c.c:19
19 return my_func1(my_func2(my_func3(1)));
(gdb) step
my_func3 (i=1) at c.c:14
14 return i;
(gdb) step
15 }
(gdb) step
my_func2 (i=1) at c.c:9
9 return i;
(gdb) step
10 }
(gdb) step
my_func1 (i=1) at c.c:4
4 return i;
(gdb) step
5 }
(gdb) step
main () at c.c:20
20 }
(gdb) cont
Continuing.
Program exited with code 01.
(gdb)
Yes, although you may have get your hands dirty with the disassembly. First try the step
command (abbreviation s
). If that doesn't put you into my_func3()
, try instead the stepi
command (abbreviation si
) to step one instruction at a time. This may take several invocations, since there can be a lot of instructions setting up the function call arguments and cleaning up afterwards.