Library to read ELF file DWARF debug information

后端 未结 4 410
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 13:55

Any recommendations for a good cross-platform library for reading ELF file debug information in DWARF format? I\'d like to read the DWARF debug info in a Python program.

4条回答
  •  猫巷女王i
    2020-12-05 14:41

    Your options for reading the DWARF debugging information are unfortunately quite limited.

    As far as I know there is only one general purpose library for parsing DWARF debugging information and that is libdwarf. Unfortunately no one has written Python bindings for libdwarf (maybe you could take it up upon yourself and share it with everyone else :) ) You could certainly attempt to access the library's functions using ctypes or the Python C API.

    A much less elegant solution, however, is to use an existing DWARF parser and parse the textual information it outputs. Your options for this (on Linux) are

    objdump -W
    readelf --debug-dump=[OPTIONS]
    

    I currently use a project that builds off of readelf and it's support for the DWARF debugging information is very full featured. You could simply use Python to execute either command in the shell and then parse the information as you need. Certainly not as ideal as a library, but should do the trick.

    EDIT: I noticed in a previous comment you mentioned Windows. Both of these programs(objdump and readelf) are part of GNU-binutils, so they should be available with Cygwin or mingw.

提交回复
热议问题