Skip to content
Advertisement

GDB doesn’t recognize some C functions

So I’m new to Linux and just got Ubuntu 16.04.2 running on a VM. I’ve installed gcc/g++ on here in the terminal, but when I run my program in GDB, as soon as I get to a strcmp function, this pops up for many lines.

strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:24
24  ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S: No such file or directory.

And when I go further down:

strlen () at ../sysdeps/x86_64/strlen.S:66
66  ../sysdeps/x86_64/strlen.S: No such file or directory.

So I’m guessing it just doesn’t recognize my C library.. I realize I can step through this after a couple of tries, but this comes up for all my c functions and when I use GDB on my school server, I don’t run into this issue. Any help would be appreciated.

Advertisement

Answer

I get to a strcmp function, this pops up for many lines.

When you does s (single step) or si (Step single instruction), what you see for string and memory functions like strcmp, memcpy, memcmp, strlen etc is correct, and GDB does recognize your C library (Ubuntu 16.04.2 amd64 started from iso in VM already has libc6-dbg debugging package preinstalled for your libc – C library).

strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:24
24  ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S: No such file or directory.
strlen () at ../sysdeps/x86_64/strlen.S:66
66  ../sysdeps/x86_64/strlen.S: No such file or directory.

What we see here is that GDB was able to find debugging information for both functions strcmp and strlen to get line numbers, but these functions of standard C library are not C functions! They are assembler functions (one is optimiezed with SSE2), we can see this from .S suffix of their source reference. You can try to do several s or si after entering to them to see incrementing source file lines.

it just doesn’t recognize

GDB did all what it can do: it finds debugging info for your system C library (it is not easiest as debug info is separated to other file somewhere in /usr/lib/debug/lib/x86_64-linux-gnu/ with other name), and finds which instruction comes from which line of source. What it can’t do is to open source file, as it is not part of preinstalled ubuntu image not part of any ubuntu (debian) binary package.

What can you do if you want to look inside this system library function:

1) Check disassembly of the function with GDB command disassemble (by default it will print current function). It will be very close to the source of this function implementation as it was originally written in assembler and what you lose are comments and structure of macro:

Dump of assembler code for function strlen:

   0x000address70 <+0>:   pxor %xmm0, %xmm0
=> 0x000address74 <+0>:   pxor %xmm1, %xmm1
   0x000address78 <+0>:   pxor %xmm2, %xmm2
   0x000address7c <+0>:   pxor %xmm3, %xmm3
...

2) Or you can see instructions as they are executed with “display” command like display/i $pc or disp/2i $pc (print one instruction at current PC which is universal just name of EIP or RIP; or print two instructions: current and next)

3) Or you can create the path required by gdb and copy original source to it: mkdir -p ../sysdeps/x86_64/ and save to this directory assembler source for your version of library. There is glibc-2.23 version for strlen.S (github mirror of authors GIT): https://github.com/bminor/glibc/blob/glibc-2.23/sysdeps/x86_64/strlen.S#L66

4) Or you can download ubuntu source for libc with apt source libc (in some stable path like ~/src after mkdir ~/src) and point gdb to this directory (adding some real subdirectory accounting to ../ relative part of libc build in ubuntu) with directory ~/src/glibc-2.23/sysdeps)

this comes up for all my c functions

No, for your c functions you have other kind of output (not ... something.S: No such file or directory). And you should enable debugging symbols when you built your program by adding -g argument to gcc (or other compiler).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement