Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB: Is there a command that allows you to see how many times a function has been called?

Tags:

c

gdb

I am currently having to write implementations of malloc() and free(), and am given a driver program that will run my two implementations.

But currently, I am segfaulting because free() is trying to free a payload size that is well in the billions of bytes (which is wrong). I have the line and line number from running GDB, but I need to know if malloc() and free() have been called more than once, to confirm that there is indeed at least one case where it runs smoothly.

like image 519
Dark Templar Avatar asked Oct 20 '11 03:10

Dark Templar


People also ask

How can I see all functions in gdb?

If specified, the info functions command will list the functions matching the regex. If omitted, the command wil list all functions in all loaded modules (main program and shared libraries).

What are gdb commands?

A GDB command is a single line of input. There is no limit on how long it can be. It starts with a command name, which is followed by arguments whose meaning depends on the command name. For example, the command step accepts an argument which is the number of times to step, as in `step 5' .

What does the command up do in gdb?

The command up can be used to examine the contents of other active frames, by moving the focus up the stack, that is to say from callee to caller, one frame at a time. Inspect the frame with the given number. The value 0 denotes the frame of the current breakpoint, that is to say the top of the call stack.

Which command enables automatic displaying the current contents of certain variables each time gdb stops at a breakpoint?

Enables automatic displaying of certain expressions each time GDB stops at a breakpoint or after a step.


1 Answers

Just to complete the information of Martin, run gdb and then, on the gdb prompt:

b <file:line_number or function name>
ignore <breakpoint identifier> 100000

Then you run your executable (or you resume) and then, when you want to check the number of times the breakpoint has been hit, on the gdb prompt:

info breakpoints
like image 165
Andrea Araldo Avatar answered Sep 28 '22 01:09

Andrea Araldo