Is it possible to grep or filter the output of info sources in gdb? Something like:
(gdb) info sources | grep bob.cpp
Thanks
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With