56

Is there a single command in gdb which can set breakpoints on all the functions in a given file ? I know about rbreak regex which sets breakpoints in matching regular expression functions, but my file doesnt have fixed patterned functions.

In another way, is there a command by which I can set a breakpoint on a filename. Which will mean, whenever control gets inside this file, it should break ?

I personally think this should not be much difficult to implement in gdb, but just wondering if somebody has already done this.

Smash
  • 839
  • 1
  • 9
  • 10
  • 2
    possible duplicate of [Using gdb stop the program when it is using any function from file X](http://stackoverflow.com/questions/475283/using-gdb-stop-the-program-when-it-is-using-any-function-from-file-x) – Employed Russian Feb 01 '12 at 16:03

2 Answers2

49
(gdb) rbreak file:.

from http://sourceware.org/gdb/download/onlinedocs/gdb/Set-Breaks.html#Set-Breaks

Shaun Lebron
  • 2,501
  • 28
  • 29
  • That doesn't work, and isn't expected to work: http://stackoverflow.com/questions/9096624/putting-breakpoint-in-a-file-using-rbreak-filename-c-doesnt-work – Employed Russian Feb 01 '12 at 16:04
  • 7
    Look for "rbreak file:regex" on the page I linked. I confirmed that it works in my own examples. – Shaun Lebron Feb 09 '12 at 22:45
10
(gdb) set height 0
(gdb) rbreak file.cpp:.*

worked fine for me.

In my case it was useful to shrink the result set a little bit by specifying a template argument for the functions contained in the file:

(gdb) rbreak file.cpp:.*TemplateClass.*
gnod
  • 407
  • 3
  • 9