GDB – how to step into uClibc if you have .debug files
1. Make sure your debuginfo files are part of LD_LIBRARY_PATH.
To do this, either
a) add the path where you stored the .debug files to your LD_LIBRARY_PATH environment variable, e.g.:
$ export LD_LIBRARY_PATH=/opt/STM/STLinux-2.3/devkit/sh4_uclibc/target/usr/lib/debug:/opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin/../lib:/opt/STM/STMCR1.5.0/lib:/opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin/../../../host/stmc/lib
Then restart gdb.
OR
b) start gdb and set the LD_LIBRARY_PATH from within gdb:
(gdb) set env LD_LIBRARY_PATH /opt/STM/STLinux-2.3/devkit/sh4_uclibc/target/usr/lib/debug:/opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin/../lib:/opt/STM/STMCR1.5.0/lib:/opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin/../../../host/stmc/lib
In my case the debug info symbol files for my uClibc lib are in /opt/STM/STLinux-2.3/devkit/sh4_uclibc/target/usr/lib/debug, so, as you can see I’ve added that dir to the beginning of my LD_LIBRARY_PATH var.
2. Use the directory
command in gdb to examine and set the path to your sorce files:
(gdb) directory
Reinitialize source path to empty? (y or n) n
Source directories searched: /opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin//.././stdcmd:$cdir:$cwd
(gdb) directory data/downloads/st/libc/uClibc-0.9.30-svn/libc/:/opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin//.././stdcmd:$cdir:$cwd
Source directories searched: /data/downloads/st/libc/uClibc-0.9.30-svn/libc:/opt/STM/STLinux-2.3/devkit/sh4_uclibc/bin//.././stdcmd:$cdir:$cwd
My uClibc sources are kept in directory /data/downloads/st/libc/uClibc-0.9.30-svn, more particularly in the libc folder, so that is what I’ve prepended to the gdb “directory”. It may be enough to add just the top directory (e.g. /data/downloads/st/libc/uClibc-0.9.30-svn) or youmay need to be more specific, adding the libc sub-directory like I did, or you may even need to add the specific sub0system directory, (e.g. /data/downloads/st/libc/uClibc-0.9.30-svn/libc/stdio if you want to debug stdio). You’ll need to experiment with that and see what works in your case.
3. Tell gdb to step into .so’s:
(gdb) set step-mode on
———
The above should do it. Now if you set a breakpoint in a libc function, e.g. fopen gdb should tell you where it put he breakpoint iun the source files, so instead of seeing something like:
(gdb) b fopen
Breakpoint 3 at 0x400a50
, you should now see the file name and line number of the uClibc source file reported by gdb:
(gdb) b fopen
Breakpoint 3, *__GI_fopen (filename=0x7bd57e6f "stats.txt", mode=0x403d84 "w") at libc/stdio/fopen.c:20
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum