Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB grep info sources files

Tags:

gdb

Is it possible to grep or filter the output of info sources in gdb? Something like:

(gdb) info sources | grep bob.cpp

Thanks

like image 670
BaldDude Avatar asked Jan 31 '17 19:01

BaldDude


1 Answers

Is it possible to grep or filter the output of info sources in gdb?

Update:

Yes. As of commit ae60f04e08bf (GDB version 9 and above) info sources can accept regexp and other arguments. From help info sources:

All source files in the program or those matching REGEXP.
Usage: info sources [OPTION]... [REGEXP]
By default, REGEXP is used to match anywhere in the filename.

Options:
  -dirname
    Show only the files having a dirname matching REGEXP.

  -basename
    Show only the files having a basename matching REGEXP.

Stale previous answer:

No. This could be considered a bug: info shared takes an optional regex to filter shared libraries, but info sources does not.

Workaround:

(gdb) set logging on  # GDB output will now be copied into gdb.txt
(gdb) info sources
(gdb) set logging off
(gdb) shell grep bob.cpp gdb.txt
(gdb) shell rm gdb.txt

If you need to do this often, you could put above commands into a user-defined command.

like image 96
Employed Russian Avatar answered Sep 23 '22 09:09

Employed Russian