🌐
Prevanders
prevanders.net › libdwarfdoc
libdwarf: A Consumer Library Interface to DWARF
Project page is at https://github.com/davea42/libdwarf-code · There is a Releases area on the project page, click Latest and you will be presented with options to download the source in three different forms. For details on licensing, see COPYING in the files list. README.md may be of interest (automatically shown on the project page on github). Examples of using libdwarf are in doc/checkexamples.c and src/bin/dwarfexamples.
🌐
GitHub
gist.github.com › jsoffer › 9e63f2e58ebd90e81b24
libdwarf example · GitHub
libdwarf example. GitHub Gist: instantly share code, notes, and snippets.
🌐
Dwarfstd
wiki.dwarfstd.org › Libdwarf_And_Dwarfdump.md
Libdwarf And Dwarfdump - Wiki - DWARF Debugging Standard
Dwarfdump is an application using libdwarf to print dwarf information in a human readable format. It is also open sourced and is copyrighted GPL. It provides an example of using libdwarf to read DWARF2/¾/5 information as well as providing readable text output.
🌐
GitHub
github.com › davea42 › libdwarf-code
GitHub - davea42/libdwarf-code: Contains source for libdwarf, a library for reading DWARF2 and later DWARF. Contains source to create dwarfdump, a program which prints DWARF2 and later DWARF in readable format. Has a very limited DWARF writer set of functions in libdwarfp (producer library). Builds using GNU configure, meson, or cmake. · GitHub
These examples show doing a build in a directory different than the source as that is generally recommended practice. Note: if you get a build failure that mentions something about test/ and missing .Po object files add --disable-dependency-tracking to the configure command. rm -rf /tmp/build mkdir /tmp/build cd /tmp tar xf <path to>/libdwarf-0.4.2.tar.xz cd /tmp/build /tmp/libdwarf-0.4.2/configure make make check
Starred by 256 users
Forked by 87 users
Languages   C 86.3% | HTML 6.7% | C++ 3.7% | Shell 0.8% | Python 0.7% | CMake 0.6%
🌐
Dwarfstd
wiki.dwarfstd.org › index.php
Libdwarf And Dwarfdump - wiki.dwarfstd.org
Dwarfdump is an application using libdwarf to print dwarf information in a human readable format. It is also open sourced and is copyrighted GPL. It provides an example of using libdwarf to read DWARF2/3/4/5 information as well as providing readable text output.
🌐
Prevanders
prevanders.net › dwarf.html
DWARF Page
BIG-ENDIAN system support has been provided by the IBM linuxone project starting in 2019. We now can test on a big-endian s390 system in a Linux VM. Thank you IBM. As of 06 October 2019 libdwarf dwarfdump and readelfobj/readobjpe/readobjmacho pass -all- tests on an IBM big endian machine, one is happy to report.
🌐
Kamalmarhubi
kamalmarhubi.com › blog › 2016 › 07 › 25 › some-things-i-learned-about-libdwarf
Some things I learned about libdwarf
July 25, 2016 - Most libdwarf functions take a Dwarf_Error* as their last argument. If you pass a non-null pointer, then error data will stored there. If a null pointer is passed, then the library calls abort() on your behalf instead. Except if you passed an error handler callback when creating the Dwarf_Debug instance: errors will get passed to your callback.
Top answer
1 of 1
1

So it seems like I misunderstood what objdump -S ./tracedprog2 showed me which led to the wrong conclusion that I stated above.

For instance, dumping with DWARF information will show disassembly + source code like this:

void do_stuff(int my_arg)                                                                                                                                     
{                                                                                                                                                             
    1135:       55                      push   %rbp                                                                                                           
    1136:       48 89 e5                mov    %rsp,%rbp                                                                                                      
    1139:       48 83 ec 20             sub    $0x20,%rsp                                                                                                     
    113d:       89 7d ec                mov    %edi,-0x14(%rbp)
    int my_local = my_arg + 2;                                                 
    1140:       8b 45 ec                mov    -0x14(%rbp),%eax
    1143:       83 c0 02                add    $0x2,%eax
    1146:       89 45 f8                mov    %eax,-0x8(%rbp)
    int i;                                                                     
                                                                               
    for (i = 0; i < my_local; ++i)
    1149:       c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%rbp)
    1150:       eb 1a                   jmp    116c <do_stuff+0x37>
        printf("i = %d\n", i);                                                 
    1152:       8b 45 fc                mov    -0x4(%rbp),%eax
    1155:       89 c6                   mov    %eax,%esi
    1157:       48 8d 3d a6 0e 00 00    lea    0xea6(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    115e:       b8 00 00 00 00          mov    $0x0,%eax
    1163:       e8 c8 fe ff ff          callq  1030 <printf@plt>
    for (i = 0; i < my_local; ++i)

where as you can see, my_local is right above the line

1140: 8b 45 ec mov -0x14(%rbp),%eax

Which made me believe I was trying to find the offset calculation of -0x14(%rbp).

Now I think I have a good idea of what is happening upon reading many additional sources which took a bit to find (I will cite them below in case anyone wants to verify my answer).

So long story short, let me expand the information I have shown above to see whether I can clarify my understanding and how I was able to reach the solution:

00000000 0000000000000014 00000000 CIE                                                                                                                        
  Version:               1                                                                                                                                    
  Augmentation:          "zR"                                                                                                                                 
  Code alignment factor: 1                                                                                                                                    
  Data alignment factor: -8                                                                                                                                   
  Return address column: 16                                                                                                                                   
  Augmentation data:     1b                                                                                                                                   
  DW_CFA_def_cfa: r7 (rsp) ofs 8                                                                                                                              
  DW_CFA_offset: r16 (rip) at cfa-8                                                                                                                           
  DW_CFA_undefined: r16 (rip) 
...
00000088 000000000000001c 0000005c FDE cie=00000030 pc=0000000000001135..0000000000001178
  DW_CFA_advance_loc: 1 to 0000000000001136
  DW_CFA_def_cfa_offset: 16
  DW_CFA_offset: r6 (rbp) at cfa-16
  DW_CFA_advance_loc: 3 to 0000000000001139
  DW_CFA_def_cfa_register: r6 (rbp)

Contents of the .debug_loc section:

    Offset   Begin            End              Expression
    00000000 0000000000001178 0000000000001179 (DW_OP_breg7 (rsp): 8)
    00000014 0000000000001179 000000000000117c (DW_OP_breg7 (rsp): 16)
    00000028 000000000000117c 000000000000118c (DW_OP_breg6 (rbp): 16)
    0000003c 000000000000118c 000000000000118d (DW_OP_breg7 (rsp): 8)
    00000050 <End of list>
    00000060 0000000000001135 0000000000001136 (DW_OP_breg7 (rsp): 8)
    00000074 0000000000001136 0000000000001139 (DW_OP_breg7 (rsp): 16)
    00000088 0000000000001139 0000000000001177 (DW_OP_breg6 (rbp): 16)
    0000009c 0000000000001177 0000000000001178 (DW_OP_breg7 (rsp): 8)
    000000b0 <End of list>

The above additional information can be found by compiling with DWARF2 rather than default DWARF5 (Source: https://blog.tartanllama.xyz/writing-a-linux-debugger-variables/).

OK, so at first, the CFA register is initially set to rsp + 8 (Source: https://lists.dwarfstd.org/pipermail/dwarf-discuss/2010-August/000915.html).

Then upon reaching the do_stuff frame at the address 0x1135, we insert a new row in the FDE table at 0x1136 (hence, that's what the value 1 represents). Now, this column will have an offset of 16 due to the statement DF_CFA_def_cfa_offset.

What does this mean? Instead of rsp + 8 as we saw earlier, now from 0x1136 until wherever this row finishes, it will now be rsp + 16.

So next, we create a new row after adding 3 to the current address (e.g., 0x1139 and from here, we will define the CFA register to rbp. Because we did not change the offset until now, all this means is that from 0x1139 onward, it will be rbp + 16 instead of rsp + 16.

Basically, that's it, frame base that we are looking for in order to calculate the local variable my_local is rsp + 16. Now we take a look at the contents of the .debug_loc section, and the result seems to align with my explanation above.

Now go back to the

 <2><b3>: Abbrev Number: 7 (DW_TAG_variable)
    <b4>   DW_AT_name        : (indirect string, offset: 0x0): my_local
...
    <bb>   DW_AT_type        : <0x57>
    <bf>   DW_AT_location    : 2 byte block: 91 68      (DW_OP_fbreg: -24)

and there is DW_OP_fbreg: -24 value, you simply add this to the frame base we found, so that would mean rbp + 16 - 24 = rbp - 8, and that would be an equivalent mov %eax, -0x8(%rbp).

Now that I looked at Mr. Bendersky's post again, this seems to align with his answer, but I somehow missed it, and apparently starting DWARF version 5, .debug_loc seems to be not included by default, which misled me to pursue the wrong conclusion initially.

I hope this solution is correct (I think it makes sense to me) and please let me know if it is incorrect as I'm also still uncertain about DWARF (it's very complicated for a newbie like me).

🌐
GitHub
github.com › WolfgangSt › libdwarf › blob › master › dwarfexample › simplereader.c
libdwarf/dwarfexample/simplereader.c at master · WolfgangSt/libdwarf
modified libdwarf that compiles with VC. Contribute to WolfgangSt/libdwarf development by creating an account on GitHub.
Author   WolfgangSt
🌐
Indiana University
legacy.cs.indiana.edu › scheme-repository › libscheme-vhll › node7.html
An Example
DWARF is a full-featured and complex debugging information format [7]. Our example program, dwarfscheme, is an interface that allows the user to browse DWARF information in an object file by providing stubs to the libdwarf [8] library.
Find elsewhere
🌐
Debian
sources.debian.org › src › dwarfutils › 20210528-1 › libdwarf › libdwarf2.1.pdf pdf
A Consumer Library Interface to DWARF David Anderson 1. INTRODUCTION
Figure 7. Example1 dwarf_attrlist() ... Dwarf_Debug type. In particular, it will deallocate all dynamically allocated space · associated with the Dwarf_Debug descriptor, and finally make the descriptor invalid. ... September 2020 and later libdwarf.
🌐
Prevanders
prevanders.net › libdwarfreadme.html
This is libdwarf README.md
January 28, 2026 - These examples show doing a build in a directory different than the source as that is generally recommended practice. Note: if you get a build failure that mentions something about test/ and missing .Po object files add --disable-dependency-tracking to the configure command. rm -rf /tmp/build mkdir /tmp/build cd /tmp tar xf <path to>/libdwarf-0.4.2.tar.xz cd /tmp/build /tmp/libdwarf-0.4.2/configure make make check
🌐
GitHub
github.com › davea42 › libdwarf-code › blob › main › README.md
libdwarf-code/README.md at main · davea42/libdwarf-code
These examples show doing a build in a directory different than the source as that is generally recommended practice. Note: if you get a build failure that mentions something about test/ and missing .Po object files add --disable-dependency-tracking to the configure command. rm -rf /tmp/build mkdir /tmp/build cd /tmp tar xf <path to>/libdwarf-0.4.2.tar.xz cd /tmp/build /tmp/libdwarf-0.4.2/configure make make check
Author   davea42
🌐
GitHub
github.com › avast › libdwarf › blob › master › libdwarf › dwarfexample › simplereader.c
libdwarf/libdwarf/dwarfexample/simplereader.c at master · avast/libdwarf
January 27, 2020 - specials used by the libdwarf regresson test suite). Examples given assuming dwp object fissionb-ld-new.dwp · from the regressiontests · --tuhash=hashvalue · example: --tuhash=b0dd19898e8aa823 · It prints a DIE. · --cuhash=hashvalue ·
Author   avast
🌐
IBM
ibm.com › docs › en › zos › 2.4.0
Reading DWARF data from an ELF object file with libelf ...
Get assistance for the IBM products, services and software you own · Provides fixes and updates for your system's software, hardware, and operating system
🌐
Prevanders
prevanders.net › libdwarfdoc › group__jitreader.html
libdwarf: Demonstrating reading DWARF without a file.
Used to access DWARF information in memory or in an object format unknown to libdwarf.
🌐
GitHub
github.com › alexanderkyte › libdwarf
GitHub - alexanderkyte/libdwarf
./configure make all To also build ... to create a new distro, do ./CPTOPUBLIC ./BLDLIBDWARF yyyymmdd where that could be ./BLDLIBDWARF 20140131 as an example....
Forked by 22 users
Languages   C 78.8% | Objective-C++ 13.5% | C++ 6.0% | Roff 0.7% | Shell 0.6% | Python 0.2% | C 78.8% | Objective-C++ 13.5% | C++ 6.0% | Roff 0.7% | Shell 0.6% | Python 0.2%
🌐
GitHub
github.com › stephenrkell › libdwarfpp
GitHub - stephenrkell/libdwarfpp: A high-level API for accessing DWARF debugging information, in C++ · GitHub
(You don't need to worry about that if you're using the libdwarf submodule.) There's not much documentation for the library. The easiest way to get started is probably to look at the (smaller) examples in examples/. What's included: - an iterator-based DIE tree abstraction (root_die) - friendly abstraction of DIE attributes, location lists etc.
Starred by 29 users
Forked by 14 users
Languages   C++ 92.3% | Python 4.5% | Makefile 2.0%
🌐
OpenSUSE Manpages
manpages.opensuse.org › tumbleweed › libdwarf-tools › dwarfdump(1)
dwarfdump(1) — libdwarf-tools
March 30, 2025 - For example, "DW_AT_const_value 176(as signed = -80)". For normal DWARF consumers that correctly and fully evaluate all attributes there is no ambiguity of signedness: the ambiguity for dwarfdump is due to dwarfdump evaluating DIEs in a simple order and not keeping track of much context.
🌐
Arch Linux
archlinux.org › packages › extra › x86_64 › libdwarf
Arch Linux - libdwarf 1:2.3.1-1 (x86_64)
View the file list for libdwarf · View the soname list for libdwarf · Copyright © 2002-2026 Judd Vinet, Aaron Griffin and Levente Polyák. The Arch Linux name and logo are recognized trademarks. Some rights reserved.