How to break on every method of a class in GDB? - c++

I have a class with a regrettable number of methods. I would like gdb to break whenever I enter the class, so through any of the methods. Is there a way to do this without setting break points individually for each method?

I never tried it myself, but it seems you can try the rbreak command :
rbreak regex
Set breakpoints on all functions matching the regular expression regex. This command sets an unconditional breakpoint on all matches, printing a list of all breakpoints it set. Once these breakpoints are set, they are treated just like the breakpoints set with the break command.

Related

Clear all breakpoints in gdb

I get into situations in gdb/ddd where there are too many breakpoints.
I want to disable or remove all of them at once, or all except for one. I find the ddd breakpoints menu confusing and unreliable. How can I do this with a gdb command?
use delete command with no arguments; it can be abbreviated to del or d.
I want to disable or remove all of them at once, or all except for one.
Use disable (with no arguments) to disable all breakpoints, followed by enable N, where N is the breakpoint you want to keep.

Can you disable all print statements in SML

I currently have a lot of print statements in SML code, and I'm traversing a very large tree, so it takes a while for all the print statements to be printed, but right now I don't want to see any print statements and just want to see it run as fast as possible. But I don't want to comment all the prints because I later need them again to debug something else.
So I just want to be able to temporarily disable them for this run of the code.
I'm using the SML/NJ compiler.
As the first line in your code put the definition
fun print x = ();
Then -- your code will still work but the prints will do nothing.
Delete that line when you want to re-enable print.

Regular expression breakpoint in GDB

I am trying to set breakpoints on all functions that start with "dc_api" but I must exclude functions that start with "dc_api_port_counter" and "dc_api_send_reply".
Regarding the "dc_api_port_counter" exclusion, note that I do want to include functions that start with "dc_api_port_something".
I used regex online tester and came up with the following regex:
dc_api_(?!port_counter|send_reply).*
However, when using it, I get the following error:
(gdb) rbreak dc_api_(?!port_counter|send_reply).*
!port_counter|send_reply).*: event not found
(gdb)
Appreciate your help.
There's no simple, built-in way to do this. However, it can be done a couple of ways.
First, use rbreak to set "too many" breakpoints. Then, the trick is to find an automated way to delete the extra breakpoints.
A straightforward way to do this is to write a bit of code in Python that loops over all the gdb breakpoints. For each breakpoint it would examine the location attribute, and, if it should be excluded, call the breakpoint's delete method.

Tell LLDB to ignore files

Is there a way to tell LLDB to ignore a file, i.e. step over code in that file when debugging?
(This could be used as a workaround for 1, 2, 3)
There is a setting to avoid stepping into functions whose name match a regular expression,
(lldb) set list target.process.thread.step-avoid-regexp
step-avoid-regexp -- A regular expression defining functions step-in won't stop in.
e.g. put this in your ~/.lldbinit file
settings set target.process.thread.step-avoid-regexp ^[^ ]+ std::|^std::
but in Xcode 4.5.x that's the best that can be done. I mentioned in #2 of your links that inlined stepping support has been added to the LLDB sources at http://lldb.llvm.org/ but that won't be in Xcode until the next release.

putting breakpoint in a file using "rbreak filename.c:." doesn't work

I want to put breakpoint on all functions of a file. I came across this link : http://sourceware.org/gdb/download/onlinedocs/gdb/Set-Breaks.html#Set-Breaks
It suggest the use of rbreak command for this purpose. When i use "rbreak ." , it works fine as expected and puts breakpoint in all functions of a prog. But when is use
rbreak filename.c:.
This doesn't work at all and no breakpoint is put anywhere. I even tried a variation of this putting spaces around :, but even that doesn't work.
Any idea on how this can be done ? Is it possible at all ?
Any help will be greatly appreciated.
thanks,
vikas
rbreak filename.cpp:.* works fine for me.
Note that in order to put breakpoint in a file you need to compile the program with debug info, e.g
g++ -g filename.cpp
rbreak filename.c:.
That isn't supposed to work. From the document you linked to:
rbreak regex
Set breakpoints on all *functions* matching the regular expression regex.
This is different from locations, where filename.c:... is intended to be used.
I want to put breakpoint on all functions of a file.
This is an unusual request. In my many years of debugging, I've never needed to do that.
You'll have to prepare a list, and set the breakpoints individually. A recipe for doing this can be found here.