No debugging symbols found in binary despite using -g flag

I’m on Ubuntu 20.04 and I was testing different versions of clang. I downloaded clang-13.0.0, clang-14.0.0 and clang-15.0.6 all from LLVM Releases. I extracted and renamed the directories clang13, clang14 and clang15.

I wrote a hello world C++ program and named it main.cxx and then compiled it by the 3 versions of clang:

$ clang13/bin/clang++ -g main.cxx -o 13
$ clang14/bin/clang++ -g main.cxx -o 14
$ clang15/bin/clang++ -g main.cxx -o 15

Then I ran 13 under GDB doing gdb ./13 I got:

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from 13...
(gdb)

So it’s working fine.
But if I do the same with 14 and 15, I get:

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from 15...
Dwarf Error: DW_FORM_strx1 found in non-DWO CU [in module /home/metal888/Downloads/clang_d/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04/15]
(No debugging symbols found in 15)
(gdb)

So why GDB cannot read debugging symbols from 14 and 15? What’s wrong? How can i fix this?

Additional info:

$ file 13 14 15
13: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
14: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
15: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped

Also:

$ clang13/bin/clang++ --version
clang version 13.0.0 (https://github.com/llvm/llvm-project/ 24c8eaec9467b2aaf70b0db33a4e4dd415139a50)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: blabla

$ clang14/bin/clang++ --version
clang version 14.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: blabla

$ clang15/bin/clang++ --version
clang version 15.0.6
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: blabla

Some older versions of GDB don’t have full support for the DWARF5 features that clang/llvm produces, and clang switched to producing DWARF5 by default around about the 14 release. If you pass -gdwarf-4 on your command line then the older DWARF version will be produced, and your version of GDB should be able to load it.

1 Like

Oh I see. The version of GDB that I’m using is installed from the linux official package repository. Should I try upgrading it and check? Which version of GDB do you suggest? GDB 9.2 seems to be the latest one in package repository.

This is one of the reasons why clang on Fedora still produces dwarf 4 by default: https://src.fedoraproject.org/rpms/clang/blob/rawhide/f/0010-PATCH-clang-Produce-DWARF4-by-default.patch

1 Like

I built GDB 13.1 from source and it supports dwarf-5. So everything is working well. Thanks everyone.

Clang on Ubuntu also defaults to dwarf-4. The latest available clang version in package repo is clang-12 (produces dwarf-4) while I was testing clang-15 which produces dwarf-5 by default.

It’s unfortunate that gdb seems to fail in the middle of parsing the DWARF, instead of checking the version number and bailing out when it sees a version it isn’t ready to parse.