<p>I'm working on a utility which needs to resolve hex addresses to a symbolic function name and source code line number within a binary. The utility will run on Linux on x86, though the binaries it analyzes will be for a MIPS-based embedded system. The MIPS binaries are in ELF format, using DWARF for the symbolic debugging information.</p>

<p>I'm currently planning to fork objdump, passing in a list of hex addresses and parsing the output to get function names and source line numbers. I have compiled an objdump with support for MIPS binaries, and it is working.</p>

<p>I'd prefer to have a package allowing me to look things up natively from the Python code without forking another process. I can find no mention of libdwarf, libelf, or libbfd on python.org, nor any mention of python on dwarfstd.org.</p>

<p>Is there a suitable module available somewhere?</p>

[{'answer_id': 46028, 'author': 'Douglas Leeder', 'author_id': 3978, 'author_profile': 'https://Stackoverflow.com/users/3978', 'pm_score': 2, 'selected': False, 'text': '<p>I don\'t know of any, but if all else fails you could use <a href="http://docs.python.org/lib/module-ctypes.html" rel="nofollow noreferrer">ctypes</a> to directly use libdwarf, libelf or libbfd.</p>\n'}, {'answer_id': 510623, 'author': 'Ber', 'author_id': 11527, 'author_profile': 'https://Stackoverflow.com/users/11527', 'pm_score': 2, 'selected': False, 'text': '<p>You should give <a href="http://construct.wikispaces.com/" rel="nofollow noreferrer">Construct</a> a try. It is very useful to parse binary data into python objects. </p>\n\n<p>There is even an example for the <a href="http://sebulbasvn.googlecode.com/svn/trunk/construct/formats/executable/elf32.py" rel="nofollow noreferrer">ELF32</a> file format.</p>\n'}, {'answer_id': 1352742, 'author': 'Craig McQueen', 'author_id': 60075, 'author_profile': 'https://Stackoverflow.com/users/60075', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve been developing a DWARF parser using <a href="http://construct.wikispaces.com/" rel="nofollow noreferrer">Construct</a>. Currently fairly rough, and parsing is slow. But I thought I should at least let you know. It may suit your needs, with a bit of work.</p>\n\n<p>I\'ve got the code in Mercurial, hosted at bitbucket:</p>\n\n<ul>\n<li><a href="http://bitbucket.org/cmcqueen1975/pythondwarf/" rel="nofollow noreferrer">http://bitbucket.org/cmcqueen1975/pythondwarf/</a></li>\n<li><a href="http://bitbucket.org/cmcqueen1975/construct/" rel="nofollow noreferrer">http://bitbucket.org/cmcqueen1975/construct/</a> (necessary modifications to Construct library)</li>\n</ul>\n\n<p><a href="http://construct.wikispaces.com/" rel="nofollow noreferrer">Construct</a> is a very interesting library. DWARF is a complex format (as I\'m discovering) and pushes Construct to its limits I think.</p>\n'}, {'answer_id': 3023558, 'author': 'Brian', 'author_id': 334707, 'author_profile': 'https://Stackoverflow.com/users/334707', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://bitbucket.org/haypo/hachoir/wiki/Home" rel="nofollow noreferrer">hachior</a> is another library for parsing binary data</p>\n'}, {'answer_id': 3647010, 'author': 'emilmont', 'author_id': 318098, 'author_profile': 'https://Stackoverflow.com/users/318098', 'pm_score': 3, 'selected': False, 'text': '<p>You might be interested in the DWARF library from <a href="http://code.google.com/p/pydevtools/" rel="nofollow noreferrer">pydevtools</a>:</p>\n\n<pre><code>&gt;&gt;&gt; from bintools.dwarf import DWARF\n&gt;&gt;&gt; dwarf = DWARF(\'test/test\')\n&gt;&gt;&gt; dwarf.get_loc_by_addr(0x8048475)\n(\'/home/emilmont/Workspace/dbg/test/main.c\', 36, 0)\n</code></pre>\n'}, {'answer_id': 8754578, 'author': 'Eli Bendersky', 'author_id': 8206, 'author_profile': 'https://Stackoverflow.com/users/8206', 'pm_score': 4, 'selected': True, 'text': '<p>Please check <a href="https://github.com/eliben/pyelftools" rel="nofollow">pyelftools</a> - a new pure Python library meant to do this.</p>\n'}]
['https://Stackoverflow.com/questions/45954', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4761/']