Saturday, 10 September 2022

Disabling debuginfods and manually loading symbols

Fedora 32 introduced debuginfod which is meant to provide dynamic debug symbols to debugging tools. The problem I've found is that using valgrind is horrifically slow as the debug symbols are downloaded and processed. One way to avoid the debug is to disable debuginfod is to rm /etc/debuginfod/*.urls; echo "set debuginfod enabled off" > /etc/gdbinit.d/debuginfo.gdb. But how do we get our debug symbols for gdb? The following example we're looking at a locally built version of ffmpeg but the installed libraries are stripped.
$ gdb ffmpeg_g (gdb) br av_rescale_rnd (gdb) set args -i /tmp/input.wav -ar 22050 -ac 2 /tmp/output.mp3 (gdb) run ... Breakpoint 1, 0x00007ffff6059c90 in av_rescale_rnd () from /usr/local/lib64/ffmpeg5/libavutil.so.57 Missing separate debuginfos, use: dnf debuginfo-install alsa-lib-1.2.7.1-1.fc35.x86_64 fdk-aac-2.0.2-2.fc35.x86_64 glibc-2.34-40.fc35.x86_64 lame-libs-3.100-11.fc35.x86_64 xz-libs-5.2.5-9.fc35.x86_64 zlib-1.2.11-31.fc35.x86_64 (gdb) bt #0 0x00007ffff6059c90 in av_rescale_rnd () from /usr/local/lib64/ffmpeg5/libavutil.so.57 #1 0x00007ffff767dc1a in ?? () from /usr/local/lib64/ffmpeg5/libavformat.so.59 #2 0x00007ffff767f754 in ?? () from /usr/local/lib64/ffmpeg5/libavformat.so.59 #3 0x00007ffff7681426 in avformat_find_stream_info () from /usr/local/lib64/ffmpeg5/libavformat.so.59 #4 0x0000000000415240 in open_input_file (o=o@entry=0x7fffffffd8b0, filename=) at fftools/ffmpeg_opt.c:1286 #5 0x00000000004190d2 in open_files (open_file=0x414620 , inout=0x431838 "input", l=0x441058) at fftools/ffmpeg_opt.c:3500 #6 ffmpeg_parse_options (argc=argc@entry=8, argv=argv@entry=0x7fffffffde68) at fftools/ffmpeg_opt.c:3540 #7 0x0000000000408717 in main (argc=8, argv=0x7fffffffde68) at fftools/ffmpeg.c:4538
We can see that there are no symbols - we have the debug symbols in our pre-installed libraries that we can load into the debugger - we can load the extracted debug symbols only or the full non-stripped library. Note that the debug versions are loaded at the specific base address that is already mapped in memory.
$ objcopy --only-keep-debug libavutils/libavutils.so.57 /tmp/libavutils.so.57.debug # in gdb (gdb) info sharedlibrary From To Syms Read Shared Object Library 0x00007ffff7fc9090 0x00007ffff7fee693 Yes /lib64/ld-linux-x86-64.so.2 0x00007ffff7fb08e0 0x00007ffff7fb73d8 Yes (*) /usr/local/lib64/ffmpeg5/libavdevice.so.59 0x00007ffff7a766d0 0x00007ffff7cdd936 Yes (*) /usr/local/lib64/ffmpeg5/libavfilter.so.8 0x00007ffff7638b70 0x00007ffff77ba9ec Yes (*) /usr/local/lib64/ffmpeg5/libavformat.so.59 0x00007ffff625f6a0 0x00007ffff6b9f618 Yes (*) /usr/local/lib64/ffmpeg5/libavcodec.so.59 0x00007ffff7f8e290 0x00007ffff7fa1acc Yes (*) /usr/local/lib64/ffmpeg5/libswresample.so.4 0x00007ffff7eee2e0 0x00007ffff7f6d94b Yes (*) /usr/local/lib64/ffmpeg5/libswscale.so.6 0x00007ffff603a510 0x00007ffff60c8c8c Yes (*) /usr/local/lib64/ffmpeg5/libavutil.so.57 0x00007ffff7e0a390 0x00007ffff7e7a048 Yes (*) /lib64/libm.so.6 0x00007ffff5e28700 0x00007ffff5f9b1ad Yes (*) /lib64/libc.so.6 0x00007ffff7924ef0 0x00007ffff79bbd8b Yes (*) /lib64/libasound.so.2 0x00007ffff7de65f0 0x00007ffff7df375b Yes (*) /lib64/libz.so.1 0x00007ffff78c89f0 0x00007ffff78e270e Yes (*) /lib64/liblzma.so.5 0x00007ffff74d3270 0x00007ffff75b67de Yes (*) /usr/lib64/fdk-aac/libfdk-aac.so.2 0x00007ffff5d8fbf0 0x00007ffff5dbe35f Yes (*) /lib64/libmp3lame.so.0 (*): Shared library is missing debugging information. (gdb) add-symbol-file ./libavformat/libavformat.so.59 0x00007ffff7638b70 add symbol table from file "./libavformat/libavformat.so.59" at .text_addr = 0x7ffff7638b70 (y or n) y Reading symbols from ./libavformat/libavformat.so.59... (gdb) add-symbol-file /tmp/libavutil.so.57.debug 0x00007ffff603a510 add symbol table from file "/tmp/libavutil.so.57.debug" at .text_addr = 0x7ffff603a510 (y or n) y Reading symbols from /tmp/libavutil.so.57.debug... (gdb) bt #0 av_rescale_rnd (a=a@entry=1, b=45158400, c=44100, rnd=rnd@entry=AV_ROUND_DOWN) at libavutil/mathematics.c:65 #1 0x00007ffff767dc1a in compute_pkt_fields (s=s@entry=0x441480, st=st@entry=0x442200, pc=pc@entry=0x0, pkt=pkt@entry=0x441780, next_dts=next_dts@entry=-9223372036854775808, next_pts=next_pts@entry=-9223372036854775808) at libavformat/demux.c:1006 #2 0x00007ffff767f754 in read_frame_internal (s=s@entry=0x441480, pkt=pkt@entry=0x441780) at libavformat/demux.c:1324 #3 0x00007ffff7681426 in avformat_find_stream_info (ic=0x441480, options=0x442d00) at libavformat/demux.c:2611 #4 0x0000000000415240 in open_input_file (o=o@entry=0x7fffffffd8b0, filename=) at fftools/ffmpeg_opt.c:1286 #5 0x00000000004190d2 in open_files (open_file=0x414620 , inout=0x431838 "input", l=0x441058) at fftools/ffmpeg_opt.c:3500 #6 ffmpeg_parse_options (argc=argc@entry=8, argv=argv@entry=0x7fffffffde68) at fftools/ffmpeg_opt.c:3540 #7 0x0000000000408717 in main (argc=8, argv=0x7fffffffde68) at fftools/ffmpeg.c:4538
Once loaded we can see the symbols are available.

No comments:

Post a Comment