Solved libc with symbols

Is there an easy way to get a libc that has symbols?

I.e., one that doesn't do this:

Code:
paulf> nm /lib/libc.so.7                                                        
nm: /lib/libc.so.7: no symbols
 
OK. I didn't install the -dbg packages during install.

Just to have a look, I tried to extract base-dbg into /tmp, and it doesn't look good

Code:
file libc.so.7.debug

libc.so.7.debug: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), corrupted program header size, with debug_info, not stripped

and

Code:
paulf> export LD_PRELOAD=/tmp/dbg_test/usr/lib/debug/lib/libc.so.7.debug
paulf> ./leakc.clang
ld-elf.so.1: /tmp/dbg_test/usr/lib/debug/lib/libc.so.7.debug: invalid shared object: e_phentsize != sizeof(Elf_Phdr)

So, two more questions

  1. How do I use these libraries?
  2. If I just untar base-dbg into "/", will freebsd-update cope? I'm on 12.1-RELEASE-p2
 
Partial answer to my own question. The debug files aren't full dynamic libraries - they don't contain .text for instance, just .debuginfo.

I still haven't figured out if a postinstall is possible, and if not where to get the files for my current patch level.
 
Paul Floyd Not sure what you're trying to do. But if you are trying to debug a binary that uses libc and missing symbols you can install them on the system. If you don't want to install them on the system you can unpack them to your directory and then specify the its location with gdb. (or in ~/.gdbinitfile).

Such as:

cd && mkdir forums && cd forums && tar -zxf base-dbg.txz
Code:
(gdb) set debug-file-directory /home/martin/forums/usr/lib/debug/
(gdb) file /bin/ls
Reading symbols from /bin/ls...
Reading symbols from /home/martin/forums/usr/lib/debug///bin/ls.debug...
(gdb) b main
Breakpoint 1 at 0x2037ca: file /usr/src/bin/ls/ls.c, line 236.
(gdb) r
Starting program: /bin/ls

Breakpoint 1, main (argc=1, argv=0x7fffffffeb78) at /usr/src/bin/ls/ls.c:236
warning: Source file is more recent than executable.
236        const char *errstr = NULL;
=> 0x00000000002037ca <main+26>:    48 c7 45 d0 00 00 00 00    mov    QWORD PTR [rbp-0x30],0x0
   0x00000000002037d2 <main+34>:    48 8d 85 b0 fd ff ff    lea    rax,[rbp-0x250]
(gdb) info symbol readdir
readdir in section .text of /lib/libc.so.7
(gdb)

gdb) b readdir
Breakpoint 2 at 0x800222dbd: readdir. (3 locations)
(gdb) c
Continuing.

Breakpoint 2, readdir (dirp=0x8006dc000) at /usr/src/lib/libc/gen/readdir.c:99
warning: Source file is more recent than executable.
99        if (__isthreaded)
=> 0x0000000800472d7d <readdir+13>:    4c 8b 3d 24 59 02 00    mov    r15,QWORD PTR [rip+0x25924]        # 0x8004986a8
   0x0000000800472d84 <readdir+20>:    41 83 3f 00    cmp    DWORD PTR [r15],0x0
   0x0000000800472d88 <readdir+24>:    74 09    je     0x800472d93 <readdir+35>
(gdb)
 
Paul Floyd Not sure what you're trying to do. But if you are trying to debug a binary that uses libc and missing symbols you can install them on the system. If you don't want to install them on the system you can unpack them to your directory and then specify the its location with gdb. (or in ~/.gdbinitfile).

Such as:

cd && mkdir forums && cd forums && tar -zxf base-dbg.txz

snip

This isn't with gdb, it is with Valgrind.

Unfortunately I didn't install either base-dbg or lib32-dbg when I installed FreeBSD. I don't particularly want to do a reinstall.

I have tried downloading 12.1-RELEASE and STABLE versions of base-dbg, but neither seem to be correct.

When I run

Code:
./vg-in-place --extra-debuginfo-path=/home/paulf/Downloads/12.1/usr/lib/debug/ --trace-symtab=yes -v -v --allow-mismatched-debuginfo=yes ./leakcpp.clang++

then I see

Code:
--92401--   Considering /home/paulf/Downloads/12.1/usr/lib/debug//libexec/ld-elf.so.1.debug ..
--92401--   .. CRC is valid

...

--92401--   Considering /home/paulf/Downloads/12.1/usr/lib/debug//lib/libc.so.7.debug ..
--92401--   .. CRC mismatch (computed bdd90bdb wanted cd37d86a)

(a few other libs also seem OK, it's only libc that fails).
 
You can install (add to system) dbg packages any time. Or, as I stated, you can unpack them to an arbitrary directory and point tools to that. In my showcase I used gdb.

You can't use any dbg packages you want; you need to use ones that come with the exact release you have installed. Also you can't use them (those release dbg packages) if you installed FreeBSD from src.
 
You can use any mirror, such as this one: FreeBSD mirror to download it. I'm showing you the 12.1 amd64 release.

You can either unpack them or install, it's up to you. To download:
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.1-RELEASE/base-dbg.txz

Code:
# install to /
tar -zvxf base-dbg.txz -C /   

# just unpack to cwd (current working dir)
tar -zvxf base-dbg.txz
 
My previous post showing the CRC error was with a locally unpacked 12.1-RELEASE base-dbg.txz

Installing to root and then running freebsed-update seems to have done the trick, thanks.
 
Back
Top