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.
Related
The project has CMakeLists.txt (codes folder), and have multiple subdirectories, each having separate CMakeLists.txt. Started to use VSCode. Build process I got working. Now, moving forward I am stuck in debugging process using VSCode.
I open VSCode with the codes folder (from here I run Build). The files I edit in mainFolder/codes/projectA/mySubProj/*.*.
Normally debug process is I open terminal and go to mainFolder/qa/scripts/ folder and run sh project.sh -u /inputDirFullPath/. The related shell scripts contents are as follows:
mainFolder/qa/scripts/project.sh:
<several shell commands>
myProj.sh -f filePath1 -h filePath2 -o dirName
<several other shell commands>
mainFolder/qa/scripts/mySubProj.sh
gdb --args mySubProj $1 $2 $3 $4 $5 $6
<some other shell commands>
Now, my question is how to set this up in VSCode? Any help?
Edit 1:
Got it working, help from this page.
I have a binary abc.so which get crash, and its in stripped format so not able to get the other symbols details other than the address.
I wanted to debug the following address.
(gdb) bt #0 0xb438f92a in ?? () from /usr/lib/abc.so #1 0xb2aaac38 in ?? () from /usr/lib/abc.so
I tried using addr2line to find the file, linenumber and other info by running the following command:
addr2line -i -f -e libvega_webview.so 0xb438f92a
The above did not worked, so I realised may the the address which I am passing might not be the one. So I tried find the offset:
objdump -f adb.so output: adb.so: file format ittle start address 0x055f1300
offset: 0xb2aaac38 - 0x055f1300 ==> 0xad4b9938
and then:
addr2line -i -f -e libvega_webview.so 0xad4b9938
but still no luck, not sure what I am missing.
Can anyone please help me on this, not sure if I'm still calculating the correct offset.
I am trying to figure out where a segmentation error is made. Thesame issue has been solved below for a different compiler. I am using CMake and am wondering if this compiler also has this function. CMake has no -g build option so I have no idea where to look.
Determine the line of code that causes a segmentation fault?
Here is also some info on what build options there are available for the debugger, maybe this points out what debugger I use since I have no idea.
/usr/bin/make: invalid option -- 'g'
Usage: make [options] [target] ...
Options:
-b, -m Ignored for compatibility.
-B, --always-make Unconditionally make all targets.
-C DIRECTORY, --directory=DIRECTORY
Change to DIRECTORY before doing anything.
-d Print lots of debugging information.
--debug[=FLAGS] Print various types of debugging information.
-e, --environment-overrides
Environment variables override makefiles.
--eval=STRING Evaluate STRING as a makefile statement.
-f FILE, --file=FILE, --makefile=FILE
Read FILE as a makefile.
-h, --help Print this message and exit.
-i, --ignore-errors Ignore errors from recipes.
-I DIRECTORY, --include-dir=DIRECTORY
Search DIRECTORY for included makefiles.
-j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.
-k, --keep-going Keep going when some targets can't be made.
-l [N], --load-average[=N], --max-load[=N]
Don't start multiple jobs unless load is below N.
-L, --check-symlink-times Use the latest mtime between symlinks and target.
-n, --just-print, --dry-run, --recon
Don't actually run any recipe; just print them.
-o FILE, --old-file=FILE, --assume-old=FILE
Consider FILE to be very old and don't remake it.
-O[TYPE], --output-sync[=TYPE]
Synchronize output of parallel jobs by TYPE.
-p, --print-data-base Print make's internal database.
-q, --question Run no recipe; exit status says if up to date.
-r, --no-builtin-rules Disable the built-in implicit rules.
-R, --no-builtin-variables Disable the built-in variable settings.
-s, --silent, --quiet Don't echo recipes.
-S, --no-keep-going, --stop
Turns off -k.
-t, --touch Touch targets instead of remaking them.
--trace Print tracing information.
-v, --version Print the version number of make and exit.
-w, --print-directory Print the current directory.
--no-print-directory Turn off -w, even if it was turned on implicitly.
-W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
Consider FILE to be infinitely new.
--warn-undefined-variables Warn when an undefined variable is referenced.
This program built for x86_64-pc-linux-gnu
Report bugs to <bug-make#gnu.org>
I use Ubuntu 14.04
I try using https://github.com/KDE/heaptrack for detect memory leaks in my running C++ program
when heaptrack shell script running
gdb --batch-silent -n -iex="set auto-solib-add off" -p $pid \
--eval-command="sharedlibrary libdl" \
--eval-command="call (void) dlmopen(0x00, \"$LIBHEAPTRACK_INJECT\", 0x002)" \
--eval-command="sharedlibrary libheaptrack_inject" \
--eval-command="call (void) heaptrack_inject(\"$pipe\")" \
--eval-command="detach"
i see following error messages
No symbol "dlmopen" in current context.
No symbol "heaptrack_inject" in current context.
and when i run gdb manually
gdb -p XXX
(gdb) sharedlibrary libdl
i see other error message
No loaded shared libraries match the pattern `libdl'.
but libdl.so exists in my filesystem
# find / -name libdl*.so
/usr/lib/debug/lib/x86_64-linux-gnu/libdl-2.19.so
/usr/lib/x86_64-linux-gnu/libdl.so
/lib/x86_64-linux-gnu/libdl-2.19.so
Why gdb don't load libdl over sharedlibrary command ?
Why gdb don't load libdl over sharedlibrary command ?
This message:
No loaded shared libraries match the pattern `libdl'.
means that your inferior (being debugged) process does not link against libdl. You can find all libraries that your inferior has with (gdb) info shared, and confirm that libdl is not among them.
GDB does not by itself modify the set of loaded libraries.
find / -name libdl*.so
This is irrelevant. The libdl.so exists, but that doesn't mean that every process loads it (your process doesn't).
I am debugging a while loop using conditional breakpoints in gdb. There are multiple large arrays that are getting created in while loop. I would like to print them in a file while debugging so that I can compare using diff later.
I am able to visualize content at the console using the following command :
(gdb) p *&ff[0]#10
where ff is my array. Kindly tell how I can redirect them to text file.
You can use:
(gdb) set logging file large_array.txt
(gdb) set logging on
By default the logging file name is gdb.txt
You can find more details at: https://sourceware.org/gdb/onlinedocs/gdb/Logging-Output.html
There is also one WA gdb --args a.out arg1 ... |& tee gdb_out.txt
You set logging by using
(gdb) set logging on
after this, all command output will be output in a file called "gdb.txt". You can find the array content in the file.