DWARF

{{short description|Standardized debugging data format}}

{{other uses|Dwarf (disambiguation)}}

{{primary sources|date=July 2017}}

DWARF is a widely used, standardized debugging data format. DWARF was originally designed along with Executable and Linkable Format (ELF), although it is independent of object file formats.{{cite web | url = https://dwarfstd.org/doc/Debugging%20using%20DWARF-2012.pdf | title = Introduction to the DWARF Debugging Format | accessdate = 2015-01-08 | author = Michael J. Eager | date = April 2012 }} The name is a medieval fantasy complement to "ELF" that had no official meaning, although the name "Debugging With Arbitrary Record Formats" has since been proposed as a backronym.

DWARF originated with the C compiler and sdb debugger in Unix System V Release 4 (SVR4).

History

The first version of DWARF proved to use excessive amounts of storage, and an incompatible successor, DWARF-2, superseded it and added various encoding schemes to reduce data size. DWARF did not immediately gain universal acceptance; for instance, when Sun Microsystems adopted ELF as part of their move to Solaris, they opted to continue using stabs, in an embedding known as "stabs-in-elf". Linux followed suit, and DWARF-2 did not become the default until the late 1990s.

The DWARF Workgroup of the Free Standards Group released DWARF version 3 in January 2006,{{cite press release | publisher = Free Standards Group | title = DWARF Version 3 Standard Released | date = January 4, 2006 | accessdate = 2007-06-25 | url = http://dwarfstd.org/PressRelease.php | archive-date = 2011-07-25 | archive-url = https://web.archive.org/web/20110725074306/http://dwarfstd.org/PressRelease.php | url-status = dead }} adding (among other things) support for C++ namespaces, Fortran 90 {{mono|allocatable}} data and additional compiler optimization techniques.

The DWARF committee published version 4 of DWARF, which offers "improved data compression, better description of optimized code, and support for new language features in C++", in 2010.{{cite web |url=http://dwarfstd.org/Announcement.php |title=DWARF Version 4 Released |publisher=The DWARF committee |date=June 16, 2010 |accessdate=2010-06-24 |archive-date=2020-07-30 |archive-url=https://web.archive.org/web/20200730064541/http://dwarfstd.org/Announcement.php |url-status=dead }}

Version 5 of the DWARF format was published in February 2017.{{cite web |url=http://dwarfstd.org/DWARF5PressRelease.php |title=DWARF Version 5 Standard Released |publisher=The DWARF committee |date= February 15, 2017 |accessdate = 2017-08-07 }}{{cite web |url=http://dwarfstd.org/Dwarf5Std.php |title=DWARF 5 Standard |publisher=The DWARF committee |date= February 15, 2017 |accessdate = 2017-08-07}} It "incorporates improvements in many areas: better data compression, separation of debugging data from executable files, improved description of macros and source files, faster searching for symbols, improved debugging of optimized code, as well as numerous improvements in functionality and performance."

Structure

DWARF uses a data structure called a Debugging Information Entry (DIE) to represent each variable, type, procedure, etc. A DIE has a tag (e.g., {{mono|DW_TAG_variable}}, {{mono|DW_TAG_pointer_type}}, {{mono|DW_TAG_subprogram}}) and attributes (key-value pairs). A DIE can have nested (child) DIEs, forming a tree structure. A DIE attribute can refer to another DIE anywhere in the tree—for instance, a DIE representing a variable would have a {{mono|DW_AT_type}} entry pointing to the DIE describing the variable's type.

To save space, two large tables needed by symbolic debuggers are represented as byte-coded instructions for simple, special-purpose finite-state machines. The Line Number Table, which maps code locations to source code locations and vice versa, also specifies which instructions are part of function prologues and epilogues. The Call Frame Information table allows debuggers to locate frames on the call stack.

DWARF has been divided into different sections such as .debug_info,{{cite web |url=https://developer.ibm.com/articles/au-dwarf-debug-format/ |title=Exploring the DWARF debug format information}} .debug_frame, etc.

class="wikitable"
Section Name

!Description

.debug_types

|Contains the non-trivial types. Stored as a hash structure so that duplicate type definition can be removed easily.

.debug_str

|Contains strings that are not placed in the .debug_info and .debug_types sections. The linker merges the string tables to eliminate duplicates.

.debug_aranges

|Contain range lists to define what pieces of a program's text belong to which subprograms and compilation units.

.debug_loc

|Contain lists of expressions that describe to the debugger the location of a variable based on the PC value.

.debug_line

|Contain a description of the mapping from PC values to source locations.

.debug_abbrev

|Provide the definitions for abbreviation codes used in describing the debug info in the .debug_info and .debug_types sections.

.debug_pubnames

|Is an index to help fetching of symbol debug information without having to scan object files.

.debug_pubtypes

|Is an index to help fetching of type information.

=.debug_info=

The .debug_info section of an ELF contains information generated by compilers to describe the source code while debugging by keeping symbols and its type, scope, file, line number, etc. The .debug_info{{Cite web|url=https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html|title=Debugging Options (Using the GNU Compiler Collection (GCC))|website=gcc.gnu.org}} section is one of the main components of DWARF{{Cite web|url=https://gcc.gnu.org/wiki/DebugFission|title=Dwarf Extensions |website=gcc.gnu.org}}{{Cite book |last1=You |first1=Ilsun |url=https://books.google.com/books?id=K-irEAAAQBAJ&dq=The+debug_info+section+in+DWARF&pg=PA228 |title=Information Security Applications: 23rd International Conference, WISA 2022, Jeju Island, South Korea, August 24–26, 2022, Revised Selected Papers |last2=Youn |first2=Taek-Young |date=2023-02-03 |publisher=Springer Nature |isbn=978-3-031-25659-2 |language=en}} debug info files.{{Cite web |title=ELF section retrieval with debuginfod |url=https://www.redhat.com/en/blog/elf-section-retrieval-debuginfod |access-date=2023-09-25 |website=www.redhat.com |language=en}} This is generated by a compiler when -g switch or its variants are used.

Tools

Libdwarf is a library that provides access to the DWARF debugging information in executable files and object files.{{Cite web |title=libdwarf: A Consumer Library Interface to DWARF |url=https://www.prevanders.net/libdwarfdoc/ |access-date=2023-12-06 |website=www.prevanders.net}}

Further reading

Michael Eager, chair of the DWARF Standards Committee, has written an introduction to debugging formats and DWARF 3, Introduction to the DWARF Debugging Format.

References

{{refs}}