Clear all breakpoints in gdb - 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.

Related

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.

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.

Easily comment (C++) code in vim

I have looked at the following question:
How to comment out a block of Python code in Vim
But that does not seem to work for me. How do I comment code easily without resorting to plugins/scripts?
Use ctrl-V to do a block selection and then hit I followed by //[ESC].
Alternatively, use shift-V to do a line-based select and then type :s:^://[Enter]. The latter part could easily go into a mapping. eg:
:vmap // :s:^://<CR>
Then you just shift-V, select the range, and type // (or whatever you bind it to).
You can add this to your .vimrc file
map <C-c> :s/^/\/\//<Enter>
Then when you need to comment a section just select all lines (Shift-V + movement) and then press CtrlC.
To un-comment you can define in a similar way
map <C-u> :s/^\/\///<Enter>
that removes a // at begin of line from the selected range when pressing CtrlU.
You can use the NERD commenter plugin for vim, which has support for a whole bunch of languages (I'm sure C++ is one of them). With this installed, to comment/uncomment any line, use <Leader>ci. To do the same for a block of text, select text by entering the visual mode and use the same command as above.
There are other features in this such as comment n lines by supplying a count before the command, yank before comment with <Leader>cy, comment to end of line with <Leader>c$, and many others, which you can read about in the link. I've found this plugin to be extremely useful and is one of my 'must have' plugins.
There's always #ifdef CHECK_THIS_LATER ... #endif which has the advantage of not causing problems with nested C-style comments (if you use them) and is easy to find and either uncomment or remove completely later.

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

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.

Bash reg-exp substitution

Is there a way to run a regexp-string replace on the current line in the bash?
I find myself rather often in the situation, where I have typed a long commandline and then realize, that I would like to change a word somewhere in the line.
My current approach is to finish the line, press Ctrl+A (to get to the start of the line), insert a # (to comment out the line), press enter and then use the ^oldword^newword syntax (^oldword^newword executes the previous command after substituting oldword by newword).
But there has to be a better (faster) way to achieve this. (The mouse is not possible, since I am in an ssh-sessions most of the time).
Probably there is some emacs-like key-command for this, that I don't know about.
Edit: I have tried using vi-mode. Something strange happened. Although I am a loving vim-user, I had serious trouble using my beloved bash. All those finger-movements, that have been burned into my subconscious suddenly stopped working. I quickly returned to emacs-mode and considered, giving emacs a try as my favorite editor (although I guess, the same thing might happen again).
in ksh, in vi mode, if you hit 'v' while in command mode it will spawn a full vi session on the contents of your current command line. You can then edit using the full range of vi commands (global search and replace in your case). When :wq from vi, the edited command is executed. I'm sure something similar exists for bash. Since bash tends to extend its predecessors, there's probably something similar.
G'day,
What about using vi mode instead? Just enter set -o vi
Then you can go to the word you want to change and just do a cw or cW depending on what's in the word?
Oops, forgot to add you enter a ESC k to o to the previous line in the command history.
What do you normally use for an editor?
cheers,
Rob
Edit: What I forgot to say in my original reply was that you need to think of the vi command line in bash using the commands you enter when you are in "ex" mode in vi, i.e. after you've entered the colon.
Worst thing is that you need to move around through your command history using the ancient vi commands of h (to the left) and l (to the right). You can use w (or W) to bounce across words though.
Once you get used to it though, you have all sorts of commands available, e.g. entering ESC / my_command will look back through you r history, most recent first, to find the first occurrance of the command line containing the text my_command. Once it has found that, you can then use n to find the next occurrance, etc. And N to reverse the direction of the search.
I'd go have a read of the man page for bash to see what's available under vi mode. Once you get over the fact that up-arrow and down-arrow are replaced by ESC k, and then j, you'll see that vi mode offers more than emacs mode for command line editing in bash.
IMHO natchurly! (-:
Emacs? Eighty megs and constantly swapping!
cheers,
Rob
Unfortunately, no, there's not really a better way. If you're just tired of making the keystrokes, you can use macros to trim them down. Add the following to your ~/.inputrc:
"\C-x6": "\C-a#\C-m^"
"\C-x7": "\C-m\C-P\C-a\C-d\C-m"
Now, in a new bash instance (or after reloading .inputrc in your current shell by pressing C-x C-r), you can do the following:
Type a bogus command (e.g., ls abcxyz).
Press Ctrl-x, then 6. The macro inserts a # at the beginning of the line, executes the commented line, and types your first ^.
Type your correction (e.g., xyz^def).
Press Ctrl-x, then 7. The macro completes your substitution, then goes up to the previous (commented) line, removes the comment character, and executes it again.
It's not exactly elegant, but I think it's the best you're going to get with readline.