Reading DWARF debug information from a PE executable

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading DWARF debug information from a PE executable

ArtemRazin
Hi,

This is my first question here and I hope it is suitable for this list.

I need (Windows/C++) to read DWARF debug information from a PE
executable. For example, mingw places debug information in this
format.

I've tried to adopt libdwarf but it seems to be able to read files in
ELF format only. At the same time mingw places debug information to
several PE sections.

Is there any way to pass raw data from these sections to libdwarf to
read debug information?

Or probably there are other ways to work with DWARF in case of PE executables...

Thank you!

--
Best regards,
Artem A. Razin
Reply | Threaded
Open this post in threaded view
|

Re: Reading DWARF debug information from a PE executable

Nick Clifton
Hi Artem,

> This is my first question here and I hope it is suitable for this list.

Actually you might find it more helpful ask this question on the elfutils
mailing list ([hidden email]) since libdwarf is part of that
project.  Or you could try the binutils mailing list ([hidden email])
as the facilities that you are asking for are available in the BFD library,
which is part of the binutils project.


> I've tried to adopt libdwarf but it seems to be able to read files in
> ELF format only. At the same time mingw places debug information to
> several PE sections.

One possible solution - albeit rather of a hack - is to extract the debug
sections from the PE file and then insert them into an ELF file and the
use libdwarf to examine them.

> Or probably there are other ways to work with DWARF in case of PE executables...

Check out the BFD library from the binutils project.  It has the ability
to read PE format files, and to traverse the debug information in them.
For example the objdump utility from the binutils project supports a -w
command line option to display debug information which works even on PE
format files.

Cheers
  Nick


Reply | Threaded
Open this post in threaded view
|

Re: Reading DWARF debug information from a PE executable

Mark Wielaard
On Thu, 2019-04-18 at 10:17 +0100, Nick Clifton wrote:
> Actually you might find it more helpful ask this question on the elfutils
> mailing list ([hidden email]) since libdwarf is part of that
> project.  Or you could try the binutils mailing list ([hidden email])
> as the facilities that you are asking for are available in the BFD library,
> which is part of the binutils project.

elfutils contains libdw, a library for reading DWARF data and some ELF
and (linux) process introspection functions. libdwarf is its own
project for low level DWARF data:
https://sourceforge.net/projects/libdwarf/

Cheers,

Mark
Reply | Threaded
Open this post in threaded view
|

Re: Reading DWARF debug information from a PE executable

Jan Kratochvil-2
In reply to this post by ArtemRazin
On Wed, 17 Apr 2019 18:20:58 +0200, Artem Razin wrote:
> Or probably there are other ways to work with DWARF in case of PE
> executables...

liblldb parses DWARF in PE for you with its SB* public C++ and Python API.

(lldb) target create "2.exe"
Current executable set to '2.exe' (x86_64).
(lldb) b main
Breakpoint 1: where = 2.exe`main + 13 at 2.c:4:10, address = 0x000000000040156d
(lldb) p s
(s) $0 = (i = 0)


Jan
Reply | Threaded
Open this post in threaded view
|

Re: Reading DWARF debug information from a PE executable

Nick Clifton
In reply to this post by Mark Wielaard
Hi Mark,

> On Thu, 2019-04-18 at 10:17 +0100, Nick Clifton wrote:
>> Actually you might find it more helpful ask this question on the elfutils
>> mailing list ([hidden email]) since libdwarf is part of that

> elfutils contains libdw, a library for reading DWARF data and some ELF
> and (linux) process introspection functions. libdwarf is its own
> project for low level DWARF data:
> https://sourceforge.net/projects/libdwarf/

Doh!  Sorry - my bad.

Cheers
  Nick