3

I use gdb (ddd) to debug my C/C++ projects.

Whenever an assert fails, I can debug the program as normal and backtrace to the assert which failed, but first I get an annoying popup

enter image description here

I assume raise.c defines assert, but ddd is looking within my home directory instead of /usr/... or something like that.

I may or may not have the debugging packages installed (I'm on Ubuntu), but the main question is: why is gdb looking within $HOME for this source?

spraff
  • 32,570
  • 22
  • 121
  • 229
  • The assert macro expands to call a function that reports the error. That function is defined, it seems, in `raise.c` — and for some reason, the debugger thinks it was compiled under what is presumably your home directory. More than that, I can't say — I've not seen the problem, but that's not surprising since I don't use `ddd`. – Jonathan Leffler Feb 11 '18 at 17:35
  • Can you run just gdb (not ddd) and see if the error message is the same? Gdb typically complains about `../sysdeps/unix/sysv/...`. It could be that ddd is trying to be helpful by canonicalizing the pathname. 99% of the time, that would indeed be helpful, but not here. – Mark Plotnick Feb 11 '18 at 19:39
  • Yes, gdb is using a relative path to ../`sysdeps` – spraff Feb 12 '18 at 13:30

1 Answers1

3

Since the glibc debuginfo package libc6-dbg is installed on your system, gdb will look in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.23.so to map instruction addresses into source file names and line numbers.

The section of that file that contains the info for __GI_raise has the following attributes that indicate where the source code might be found (on Ubuntu 16.04):

<0><688bd>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <688c3>   DW_AT_name        : (indirect string, offset: 0x9137): ../sysdeps/unix/sysv/linux/raise.c
    <688c7>   DW_AT_comp_dir    : (indirect string, offset: 0x9010): /build/glibc-Cl5G7W/glibc-2.23/signal

Ubuntu doesn't ship source code in the base distribution, so your system doesn't have any glibc source in /build/glibc-Cl5G7W/glibc-2.23, so gdb looks (unsuccessfully) for raise.c in a few other directories according to its rules Specifying Source Directories and eventually gives up, with the error message

54  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

Then, ddd calls SourceView::full_path("../sysdeps/unix/sysv/linux/raise.c") to canonicalize the pathname, taking your working directory into account, and displays the error dialog box in your question.

See GDB complaining about missing raise.c for how to install glibc source on Ubuntu.

Mark Plotnick
  • 9,598
  • 1
  • 24
  • 40