Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging a programmatically called function with GDB

Tags:

c

gdb

I am debugging a piece of software for an ARM32. I have been able to programmatically call functions in GDB using call, or even print. The problem is that I cannot seem to be able to set a breakpoint on a function, and then call it programmatically. For example, if I do:

break test_function
call test_function()

then I get the error message

The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function. When the function is done executing, GDB will silently stop.

Is there a way to programmatically call a function using GDB and step through it?

like image 487
Randomblue Avatar asked Apr 25 '12 16:04

Randomblue


People also ask

Can I call a function in gdb?

To call a function in the program, GDB has to temporarily modify the state of the inferior. This has potentially undesired side effects. Also, having GDB call nested functions is likely to be erroneous and may even crash the program being debugged.

What is Backtrace in gdb?

A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.

How do I create a breakpoint in gdb?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.


1 Answers

then I get the error message

The program being debugged stopped while in a function called from GDB. Evaluation of the expression containing the function. When the function is done executing, GDB will silently stop.

This isn't an error. This is exactly what you wanted to happen: a breakpoint fired, and you are now ready to debug.

like image 51
Employed Russian Avatar answered Oct 13 '22 11:10

Employed Russian