p-x9/swift-dwarf
A Swift library for parsing binary files to obtain DWARF information.
Usage
Basic
DWARF information from binary files can be retrieved via the dwarf property. Import the format-specific adapter that matches the binary type you want to inspect.
import MachOKit
import DWARF
import DWARFMachO
let machO: MachOFile = ...
// string table in `.debug_str` section
let strings = machO.dwarf.strings
// abbreviations tables in `.debug_abbrev` section
let abbreviationSets = machO.dwarf.abbreviationsSets
// compilation units in `.debug_info` section
let compilationUnits = machO.dwarf.compilationUnits
/* ... */import ELFKit
import DWARF
import DWARFELF
let elf: ELFFile = ...
let elfStrings = elf.dwarf.strings
let elfCompilationUnits = elf.dwarf.compilationUnitsDWARFMachOPrintTests.swift provides test cases that generate output similar to dwarfdump. DWARFELFPrintTests.swift provides the same for ELF binaries. Please use these as a reference.
Status
Support is tracked by section and feature below. A supported section does not imply complete support for every DWARF version, form, or related object-file feature.
Legend: β supported, π‘ partially supported, β not implemented.
Binary formats
| Format | Status | Notes | | --- | --- | --- | | Mach-O | β | Thin and fat binaries are supported. Full big-endian DWARF support is not guaranteed. | | ELF | π‘ | ELFKit currently limits parsing to binaries with the same endianness as the host. Compressed debug sections are not supported. |
DWARF sections
| Section | DWARF version | Status | Notes | | --- | --- | --- | --- | | .debug_abbrev | 2β5 | β
| Abbreviation tables and attribute specifications. | | .debug_info | 2β5 | π‘ | Compilation units and DIEs. Some forms and external-file references remain unsupported. | | .debug_line | 4β5 | π‘ | Headers, file tables, line programs, and VLIW operation state. DWARF 5 DW_LNE_define_file format descriptors and DWARF 2β3 headers are not supported. | | .debug_str | 2β5 | β
| String table lookup. | | .debug_line_str | 5 | β
| Line string table lookup. | | .debug_str_offsets | 5 | β
| String offsets tables. | | .debug_addr | 5 | β
| Address tables. | | .debug_aranges | 2β5 | β
| Address range table headers and tuples. | | .debug_rnglists | 5 | β
| Range list tables and entries. | | .debug_loclists | 5 | β
| Location list tables and entries. | | .debug_names | 5 | β
| Name index tables and lookup. | | .debug_ranges | 2β4 | β | Legacy range lists. | | .debug_loc | 2β4 | β | Legacy location lists. | | .debug_types | 4 | β | Type unit headers and signature lookup are not implemented. | | .debug_macro | 5 | β | Macro information. | | .debug_macinfo | 2β4 | β | Legacy macro information. | | .debug_frame / .eh_frame | β | β | Call frame information and unwinding. | | .debug_pubnames / .debug_pubtypes | 2β4 | β | Legacy public name and type indexes. |
Known limitations
- Split DWARF
.dwoloading and supplementary object files are not supported. DW_FORM_ref_sig8,DW_FORM_ref_sup4,DW_FORM_ref_sup8,
DW_FORM_strp_sup, and GNU alternate reference/string forms are read but not resolved.
- ELF compressed debug sections are not supported.
- Endianness is handled by several DWARF readers, but the library does not yet
claim complete big-endian coverage across every section and container.
License
swift-dwarf is released under the MIT License. See LICENSE
Package Metadata
Repository: p-x9/swift-dwarf
Default branch: main
README: README.md