Libdw, part of elfutils, is more recent than libdwarf. Unfortunately there is virtually no available documentation, nor examples.
I just finished writing a program that, given an instruction pointer of a running program, finds and prints the name of the function that that is in (which is not always available by calling dladdr, which can only show dynamic (aka public/visible) symbols). I will post this here as answer to the following question:
How can one use libdw to extract the name of a function (with hidden visibility) from the DWARF info in an ELF executable, when only having an instruction pointer?
The following code snippet does so. The
mainfunction callsget_test_address()to get aDwarf_Addrinside that function. I used libunwind functions for that, but that is kind of irrelevant.I used
dladdrto find and get the ELF object file and its load address.Compile and link this test program as follows: