Skip to content
EndstoneMCPublic

About

Generate C++ headers from DWARF Debugging Information Format

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

12 stars

Watchers

1 watching

Forks

Repository files navigation

dwarf2cpp

Build Status License: MIT Python Version

Generate C++ headers from DWARF Debugging Information Format (DWARF).

Warning

This tool requires binaries that contain DWARF debug information in order to generate headers. Make sure your input binary includes DWARF debug info, which is often not publicly available in proprietary software.

Installation

The easiest way to get started is the prebuilt package. No C++ toolchain or LLVM required.

uvx dwarf2cpp

or with pip

pip install dwarf2cpp

Build from Source

Building from source is only needed when no prebuilt wheel is available for your platform. Since dwarf2cpp uses nanobind to access LLVM's DWARF DebugInfo module from Python, it requires a working C++ toolchain:

  • On Windows: MSVC (Visual Studio Build Tools)
  • On Linux: GCC (g++)
  • On macOS: Apple Clang (Xcode Command Line Tools)
git clone https://github.com/EndstoneMC/dwarf2cpp.git
cd dwarf2cpp
pip install .

Usage

Usage: dwarf2cpp [OPTIONS] PATH

Options:
  --base-dir TEXT         Base directory used during compilation.  [required]
  -o, --output-path PATH  Output directory for generated files. Defaults to
                          'out' inside the input file's directory.
  --strict                Raise on unhandled DWARF attributes and tags instead
                          of logging them.
  --help                  Show this message and exit.

The PATH argument must point to a binary containing DWARF debug information.

  • --base-dir should point to the root directory used during compilation. This helps resolve relative include paths when reconstructing headers.
  • --output-path controls where the generated headers are stored. If not specified, the tool creates an out/ folder next to the input file.
  • --strict stops at the first DWARF attribute or child tag dwarf2cpp does not handle. Without it, dwarf2cpp skips it, logs it once per tag and carries on.

Examples

Extract from libminecraftpe.so

dwarf2cpp path/to/libminecraftpe.so --base-dir D:/a/_work/1/s

Extract from bedrock_server (Linux)

dwarf2cpp path/to/bedrock_server --base-dir /mnt/vss/_work/1/s

Motivation / Purpose

Typical use cases include:

  • Analysing the internals of proprietary software.
  • Supporting the development of plugin frameworks such as Endstone.
  • Research on automated source reconstruction from DWARF.

Limitations

  • Generated headers may not compile out-of-the-box. Manual adjustments may be required.
  • Templates, inline functions, and macros cannot always be reconstructed accurately.
  • Only works with binaries compiled with DWARF debug info. Stripped binaries will not work.
  • Only trivially tested. It may fail with certain binaries.

What DWARF does not record

Clang leaves the following out of the debug info, so dwarf2cpp cannot print them:

  • Default arguments, noexcept, constexpr and consteval, friend declarations and attributes such as [[nodiscard]].
  • Default member initializers, and the expressions behind enumerator values: only the values are recorded.
  • Templates that are never instantiated. Only the specializations the code uses appear.
  • Member typedefs that nothing uses.
  • The members of a class that no compile unit in the binary defines. DWARF holds only a declaration of such a class.
  • In DWARF 4, Clang's default for Android, = delete and the alignment of a typedef. DWARF 5 records both.
  • thread_local on aarch64, the Android target. LLVM writes no location for a thread-local variable there, and only its location marks a variable as thread-local.
  • final on classes and virtual functions. A final class prints without it, and a final overrider prints like any other overrider.
  • = default. dwarf2cpp prints it only on the copy constructor, move constructor and destructor of a class passed by value, which its calling convention requires. In DWARF 4, a deleted one of these prints = default too.
  • The column of a lambda or an unnamed struct, union or enum. Such a type prints as Clang spells it in a template argument, (lambda at main.cpp:4:12), and as (lambda at main.cpp:4) or (unnamed struct at main.cpp:4) when no template argument names it.

Acknowledgements

This project makes use of the following open-source technologies:

Security / Legal Disclaimer

Important

This tool is provided for research and educational purposes only. It is not affiliated with Mojang or Microsoft.

Warning

Do not redistribute or publish headers generated from proprietary binaries without proper rights. Respect the terms of service and licensing agreements of any binaries you analyse.

Releasing

  1. Add changes under ## [Unreleased] in CHANGELOG.md
  2. Bump version in pyproject.toml, then commit and push to main
  3. Go to Actions > Release > Run workflow

Use dry run to preview without making changes.

Contributing

Contributions are welcome. Open an issue or pull request on GitHub.

License

This project is distributed under the MIT License. See the LICENSE file for more details.

About

Generate C++ headers from DWARF Debugging Information Format

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages