libdl: How to debug dl object with GDB

Chris Johns chrisj at
Thu Nov 19 20:56:12 UTC 2020

On 19/11/20 5:33 pm, Hesham Almatary wrote:
> Thanks for the info, Chris.
> On Wed, 18 Nov 2020 at 02:43, Chris Johns <chrisj at> wrote:
>> On 17/11/20 10:43 pm, Hesham Almatary wrote:
>>> Hello,
>>> I am trying to debug a dynamically loaded ELF object with GDB: My setup is:
>>> rtems-riscv64:
>>> GDB: GNU gdb (GDB) (build with RSB/rtems6)
>>> Host: Ubuntu 20.04.1 LTS
>>> GDB doesn't seem to notice when I dlopen an object (which gets loaded,
>>> linked and run fine).
>> libdl has the NetBSD type support built in for debugging. A function is called
>> when a module is loaded and there is a table of modules GDB reads and then loads
>> the object file.
> Is that expected to work on Linux with recent GDB versions? 

We need a patch for GDB to add the support needed for RTEMS.

> doesn't seem to detect when "_rtld_debug_state" is called from dlopen,
> and consequently isn't aware of the list of objects. Does that need
> GDB to be modified with solib-rtems* or something?

A patch was created as part the 2013 RTL GSoC project (an excellent year for
students :)). The repo is The
only problem is GDB has moved to C++ since then and I am not sure what effect
that has had on the patch.

>>> Any instructions or idea how to troubleshoot that further?
>> At this point the simplest path is to get the load address(es) and load the
>> symbols with the VMA.
> I can use "add-symbol-file" filename for each object and give it the
> text_base address. This only allows me to break on functions within
> loaded objects. If that's not what you mean, how can I load the
> symbols with the VMA?

I think using a command is always going to be a bit of a hack. The patch Peng
created allowed you to set breakpoints in code that was not loaded and it would
break when loaded _and_ executed.


More information about the devel mailing list