GithubHelp home page GithubHelp logo

sevaa / dwex Goto Github PK

View Code? Open in Web Editor NEW
185.0 7.0 16.0 407 KB

DWARF Explorer - a GUI utility for navigating the DWARF debug information

Python 99.27% Batchfile 0.73%
dwarf-tree dwarf-information pe-files pyelftools dwarf-explorer debugger-visualizer debugging debugging-tools elf elf-parser

dwex's Introduction

DWARF Explorer

A cross-platform GUI utility for visualizing the DWARF debugging information in executable files, built on top of pyelftools and filebytes. Runs on Windows, MacOS X, and Linux. Supports parsing the following file types for DWARF data:

  • ELF (Linux, Android)
  • Mach-O (MacOS X, iOS)
  • PE (Windows, Cygwin)
  • WASM (aka WebAssembly)

This project came from my desire to see and navigate the DWARF tree of compiled Android and iOS binaries. Seeing the DIEs is easy enough with utilities like readelf or dwarfdump. However, chasing inter-DIE references back and forth is not straightforward with those.

The utility might be of use for anyone who is building DWARF parsers for one or another reason, especially if their preferred parsing library is pyelftools.

Note that regular Windows executables (EXE/DLL files) are PE files but don't, as a rule, contain DWARF information. The Microsoft toolchains (Visual Studio and the like) produce debugging information in Microsoft's own format, Program Database (PDB). There are, though, a couple of toolchains that produce PE files with DWARF debug info in them - notably GCC under Cygwin. DWARF Explorer is compatible with those.

The pyelftools library that dwex is based on supports DWARF versions 2-5, and so does dwex. DWARFv5 support might be unstable. DWARF v1 is supported experimentally, in ELF files only.

Requirements and Dependencies

  • Python 3.6.1+
  • PyQt6
  • filebytes 0.10.1+
  • pyelftools 0.30+

Installation

If necessary, install the latest Python in the way that's appropriate for your OS. Run pip install dwex from the command line, under sudo or elevated command line if necessary.

On Windows, if pip and/or Python is not in PATH, use c:\Python39\python -m pip install dwex, substituting your own path to Python 3.

Alternatively, get the dwex source tree from Github, and run python setup.py install in the root folder of the package. In this scenario, you'd have to install the dependencies separately - with pip install pyqt6 filebytes pyelftools.

On Linux, sometimes the python command defaults to Python 2 while Python 3 is installed side by side. In this case, use python3 and pip3, respectively. Use python -V to check.

Once you install it, there will be a dwex command. On Windows, there will be a dwex.exe in the Scripts folder under the Python folder, and also a start menu item "DWARF Explorer". On Linux, there will be a "DWARF Explorer" in the app menu (tested under GNOME).

In January 2022, the utility was migrated from PyQt5 to PyQt6, and the major version was bumped to 2. That cut off support for Python 3.5. The 1.x version that is compatible with Python 3.5 is still out in the repository, and pip should resolve it. If it does not, install by running pip install "dwex<2".

Usage

Click Open in the File menu, choose your executable, and eyeball the DWARF tree. Alternatively, drag and drop an executable onto the main window. You can open by dropping a dSYM bundle folder, too.

On the most basic level, the debug information in a compiled file is an array of compilation units (CUs). Each CU contains a tree of data items called Debugging Information Entries (DIEs). Each DIE has a title called tag, and contains a name-value dictionary called attributes. Each CU has exactly one root DIE, and the rest of the DIEs are in its subtree.

The UI of DWARF Explorer was meant for eyeballing that data structure:

dwex

The left hand tree displays the DIEs, with CU root DIEs on the top level. Expand the tree and click on DIEs to see their attributes. DIE attributes that have a substructure or point at larger data structures are clickable.

DIEs generally correspond to source level entities in the program - variables, functions, classes, members, methods, etc. The DIE tag tells you which one is it. The exact way the compiler builds a DIE tree to describe the program varies between source languages, compiler versions, target platforms and architectures. The official home of the DWARF spec is at dwarfstd.org, but there's considerable leeway for implementations to improvise upon. On top of that, the DWARF spec contains explicit extension points for compiler vendors to tap into.

DIE attribute values are relatively small scalars - integers, strings, sometimes short byte arrays. However, they sometimes refer at larger data structures. Physically, it's an integer, but logically, it's a pointer to some data elsewhere. Also, DIE attribute values may contain references to other DIEs - for example, a DIE for a variable would contain a reference to a DIE that describes its datatype. DIE attributes that contain references to other DIEs are rendered in blue; the link can be followed by a double-click or a Ctrl+Enter. To come back to the original DIE, use Navigate/Back, the Back mouse button, or an appropriate keyboard shortcut (Alt-Left on Windows and Linux, Ctrl-[ on Mac).

In DWARF, tag and attribute names are prefixed with DW_TAG_ and DW_AT_, respectively. DWARF Explorer elides those by default to reduce visual clutter. Use View/DWARF prefix in the menu to bring them back.

Disclaimer

This project is unrelated to ragundo/DwarfExplorer. That one deals with a different kind of dwarves. Although, interestingly enough, they also use the Qt library for their GUI.

Prior art

There is also a GUI DWARF visualizer at simark/dwarftree. Also based on pyelftools, with gtk based UI. It's been inactive since 2015. I didn't know about it when I started.

dwex's People

Contributors

sevaa avatar supervacuus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dwex's Issues

Error opening file with DWARF5

Hi,

I've just upgraded to the latest "version 2". When I open files on my Mac (M1 Pro) it fails with an error "Error opening file:"

I've attached the binary, with the hope that you can reproduce.
PS. dwarfdump is able to report from the same file.

Tx
nrf52833.zip
,

Dark mode option

Is it possible to add dark mode?
I think that would be great thing to have ngl

Image base address

Code addresses in unrelocated DWARF assume the file is loaded at its preferred base address, which is available in file headers. This affects the "Search by IP" window. It's clearly observable on iOS and Windows. At least display it.

Cannot load Playstation 2 ELF.

I get this message upon loading the PS2 ELF I've uploaded below.
"The file contains no DWARF information, or it is in an unsupported format."

My understanding is that there is dwarf debug info in this elf, as other dwarf utilities work on it.

Could it be fixed to support this?
Thanks!

sles_507.zip

Dependency graph

Given a DIE, follow all refs and display the logical tree. Modal window or the same?

shortcut for going back and forth in click history with left mouse or keyboard shortcut

It would be great if it would be possible to jump back to the previous highlighted element/node.
Usecase: for example you follow a ref, afterwards you want to go back to the node which contained the ref.

In addition, going forward in history could also be handy (such that you can jump back and forth again). I would suggest to bind mouse4 + mouse5 to this events.

LocationParser blocks improper DWARF version

Hi there,

I believe that there is a mistake on the LocationParser. I guess that it restricts to version 4 and above the usage of expression as
0x00003939: DW_TAG_variable
DW_AT_name ("myVariable")
DW_AT_type (0x0000294a "const myType")
DW_AT_external (true)
DW_AT_decl_file ("/mySource.c")
DW_AT_decl_line (133)
DW_AT_location (DW_OP_addr 0x2320)

DWEX only parsers the DW_OP_addr if the DWARF version is >4, but I have found these expressions on files with DWARF v4

I recommend the following change to the code:

locationlists.py::_attribute_has_loc_expr
Change the condition from
return ((dwarf_version < 4 and attr.form == 'DW_FORM_block1' and
to
return ((dwarf_version <= 4 and attr.form == 'DW_FORM_block1' and

and same change in _attribute_has_loc_list (not tested)

Need an icon

I'm rather out of ideas. We have a GUI app here, no reason it shouldn't have a nice icon. What would be a good design for this? A dwarf next to a tree (because the primary data structure is a tree)?

Also, I can't draw.

LocationListsPair.get_location_list_at_offset is broken

The said function is only invoked if the binary has both loc and loclists (a mix of DWARF 4 and 5). It tries to forward the call to the right section, and it makes a reference to CompileUnit.version - there is no such property, should be .header.version. This doesn't come up on the autotest - I don't think we have a test file with both loc sections.

Windows app doesn't launch

I installed dwex using pip install dwex on my Windows machine but it won't start. I'm assuming crash on launch? I used Procmon but didn't see anything suspicious.

My CPU is Intel Xeon x64, and Windows 10 version is 19041.630.

Happy to investigate further, please let me know how and what other info you need to debug this.

Error opening the file: 'DW_FORM_line_strp'

It looks like there is an issue in processing an ELF file that i'm trying to view in dwex.
After selecting the ELF file from the open file menu I get a dialog box stating:
Error opening the file: 'DW_FORM_line_strp'

Looking at the code, this is some exception thrown when parsing the file, that is only handled at the file_open handler.

  1. It would be good if this exception could be handled earlier to translate it to a better error message.
  2. It would be nice if the issue that causes the exception gets resolved.

options to sort

Hi,

first of all thanks for the great tool - it helps investigating the DWARF structure.
It is neverthelss quite hard to navigate in a bigger dwarf file. A major improvement for navigating the DIEs would be the possibility to give the option to sort also by name instead of debug_info address (applicable for all hierarchy levels simulatnously)

Screenshot in README

I'd love to see what this looks like so that I can quickly evaluate whether it might be useful to me without downloading and building it ๐Ÿ˜„ Thanks!

Visualization problem: columns not showns

Hi sevaa,

when a DIE is being displayed, which has a very long raw value inside an attribute, the column "Value" is not visible

see screenshot
grafik

probably swapping the column "Raw" and "Value" would resolve this issue

Opening object files

Attempting to open an object file (ELF REL) display the message:

Error opening the file:

without any further path or reason behind the failure.

Is this tool able to analyze ELF REL files?

Linux GUI integration

On Gnome under Linux, a GUI app like dwex should list itself in the apps menu. Not sure about other environments, but there might be an equivalent. Right now, dwex is not there. Should it be? Upvote to agree.

"File contains no DWARF information..." on Mac

First of all, let me tell you I'm very excited to try this tool as I'm working on adding DWARF metadata to a compiler :)

It's very possible I'm doing something wrong here, please let me know.

OS: MacOS
Arch: arm64 (M1)
Version: 2.30
Python: 3.10.9

I get this on both the binary and the bundle

image

I thought it was an issue with my work, but I get the same when compiling this C file:

#include "stdio.h"
void hello(int i) {
  printf("%d", i);
}

int main() {
  hello(25);
  return 0;
}
$ clang -g test.c -o test.out

Then to confirm I ran dwarfdump on it:

> dwarfdump test.out
test.out:       file format Mach-O arm64

.debug_info contents:

and if I feed the result dSYM bundle to llvm-dwarfdump:

> ~/projects/llvm-project/build/bin/llvm-dwarfdump test.out.dSYM/
test.out.dSYM/Contents/Resources/DWARF/test.out:	file format Mach-O arm64

.debug_info contents:
0x00000000: Compile Unit: length = 0x00000073, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000077)

0x0000000b: DW_TAG_compile_unit
              DW_AT_producer	("Apple clang version 14.0.0 (clang-1400.0.29.202)")
              DW_AT_language	(DW_LANG_C99)
              DW_AT_name	("test.c")
              DW_AT_LLVM_sysroot	("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
              DW_AT_APPLE_sdk	("MacOSX.sdk")
              DW_AT_stmt_list	(0x00000000)
              DW_AT_comp_dir	("<...>/projects/scala-native")
              DW_AT_low_pc	(0x0000000100003f40)
              DW_AT_high_pc	(0x0000000100003fa8)

0x00000032:   DW_TAG_subprogram
                DW_AT_low_pc	(0x0000000100003f40)
                DW_AT_high_pc	(0x0000000100003f78)
                DW_AT_frame_base	(DW_OP_reg29 W29)
                DW_AT_name	("hello")
                DW_AT_decl_file	("<...>/projects/scala-native/test.c")
                DW_AT_decl_line	(2)
                DW_AT_prototyped	(true)
                DW_AT_external	(true)

0x00000047:     DW_TAG_formal_parameter
                  DW_AT_location	(DW_OP_fbreg -4)
                  DW_AT_name	("i")
                  DW_AT_decl_file	("<...>/projects/scala-native/test.c")
                  DW_AT_decl_line	(2)
                  DW_AT_type	(0x0000006f "int")

0x00000055:     NULL

0x00000056:   DW_TAG_subprogram
                DW_AT_low_pc	(0x0000000100003f78)
                DW_AT_high_pc	(0x0000000100003fa8)
                DW_AT_frame_base	(DW_OP_reg29 W29)
                DW_AT_name	("main")
                DW_AT_decl_file	("<...>/projects/scala-native/test.c")
                DW_AT_decl_line	(6)
                DW_AT_type	(0x0000006f "int")
                DW_AT_external	(true)

0x0000006f:   DW_TAG_base_type
                DW_AT_name	("int")
                DW_AT_encoding	(DW_ATE_signed)
                DW_AT_byte_size	(0x04)

0x00000076:   NULL

test.zip

Will not install on Apple Silicon

Installation fails with AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' on Apple Silicon based hardware.

The solution is to install AND run from a Terminal that is running with the "Open in Rosetta" option.

I suspect that is because pyqt5 is not supported on Apple Silicon, and if dwex upgraded to pyqt6, the problem should fix itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.