After a breakpoint or a signal suspends program execution, you can execute a single function in your program by using the call command, or by including a function call in the expression argument of a debugger command. Calling a function lets you test the function's operation with a specific set of parameters.
call_command
Specify the function as if you were calling it from within the program. If the function has no parameters, specify empty parentheses (()). For multithreaded applications, the call is made in the context of the current thread. For C++ applications, when you set the $overloadmenu debugger variable to 1 and call an overloaded function, the debugger lists the overloaded functions and calls the function you specify. When the function you call completes normally, the debugger restores the stack and the current context that existed before the function was called.
While the program counter is saved and restored, calling a function does not shield the program state from alteration if the function you call allocates memory or alters global variables. If the function affects global program variables, for instance, those variables will be changed permanently.
Functions compiled without the debugger option to include debugging information may lack important parameter information and are less likely to yield consistent results when called.
The call command executes the specified function with the parameters you supply and then returns control to you (at the debugger prompt) when the function returns. The call command discards the return value of the function. If you embed the function call in the expression argument of a print command, the debugger prints the return value after the function returns. The following example shows both methods of calling a function:
(idb) call earth->distance()
(idb) print earth->distance()
149600
In the previous example, the call command results in the return value being discarded while the embedded call passes the return value of the function to the print command, which in turn prints the value. You can also embed the call within a more involved expression, as shown in the following example:
(idb) print earth->distance() - 100000
49600
(idb) print mars->distance() - earth->distance()
78340
(idb) call io->printBody(3)
(3) Moon [Io], radius [1815] km; <Jupiter 1> orbits at 422 Megameters
All breakpoints or tracepoints defined and enabled during the session are active when a called function is executing. When program execution halts during function execution, you can examine program information, execute one line or instruction, continue execution of the function, or call another function.
When you call a function when execution is suspended in a called function, you are nesting function calls, as shown in the following example:
(idb) where 2
>0 0x080581c6 in buildOurSolarSystem(sun=0x806e168) "/home/user/examples/solarSystemSrc/main/solarSystem.cxx":55
#1 0x08058bda in main() "/home/user/examples/solarSystemSrc/main/solarSystem.cxx":119
(idb) stop in Planet::printBody
[#2: stop in virtual void Planet::printBody(unsigned int)]
(idb) call mars->printBody(1)
[2] stopped at [virtual void Planet::printBody(unsigned int):19 0x080553fd]
19 std::cout << "(" << i
(idb) where
>0 0x080553fd in ((Planet*)0x806e3a0)->Planet::printBody(i=1) "/home/user/examples/solarSystemSrc/planet.cxx":19
#1 0xb7387cec in __do_global_ctors_aux(...) in /lib/libdl-2.3.2.so
(idb) next
stopped at [virtual void Planet::printBody(unsigned int):20 0x08055403]
20 << ") Planet [" << HeavenlyBody::name() << "]; ";
(idb) stop in Orbit::distance
[#3: stop in Megameters Orbit::distance(void)]
(idb) print distance()
[3] stopped at [Megameters Orbit::distance(void):41 0x08054ea7]
41 return _distance;
(idb) where
>0 0x08054ea7 in ((Orbit*)0x806e3b8)->Orbit::distance() "/home/user/examples/solarSystemSrc/orbit.cxx":41
#1 0xb7387cec in __do_global_ctors_aux(...) in /lib/libdl-2.3.2.so
(idb) disable 3
(idb) cont
Called Procedure Returned
stopped at [virtual void Planet::printBody(unsigned int):20 0x08055403]
20 << ") Planet [" << HeavenlyBody::name() << "]; ";
(idb) where
>0 0x08055403 in ((Planet*)0x806e3a0)->Planet::printBody(i=1) "/home/user/examples/solarSystemSrc/planet.cxx":20
#1 0xb7387cec in __do_global_ctors_aux(...) in /lib/libdl-2.3.2.so
(idb) cont
(1) Planet [Mars]; <Sol 4> orbits at 227940 Megameters
Called Procedure Returned
stopped at [void buildOurSolarSystem(class Star*):55 0x080581c6]
55 Planet *pluto = new Planet("Pluto", 5913520, sun);
The debugger supports function calls and expression evaluations that call functions, with the following limitations: