Getting debug info from GCC

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Getting debug info from GCC

Postby Robert'); DROP TABLE *; » Sun Aug 10, 2014 2:10 am UTC

I've recently started on a project involving creating new tools for the Arduino/ATmega328 microcontroller. I was planning to re-use most of the normal Arduino build process using avr-gcc, but I've ran into a problem: I need some idea of what parts of the compiled machine code correspond to parts of the original C program being compiled.

I have an approximate idea of how to get general debugging information from GCC. (i.e. compile with -g and then use obj-dump to extract debugging symbols) However, I have no idea about how to go about reading the resulting file, or what exactly it contains. When I tried searching for this, most of the results I got on the subject boiled down to "use gdb," which isn't particularly helpful for a graphical tool.

Can anyone help me with this, or at least point me in the right direction for learning how to work out what GCC's up to? :)
...And that is how we know the Earth to be banana-shaped.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Getting debug info from GCC

Postby EvanED » Sun Aug 10, 2014 4:26 am UTC

Black Magic. :-)

You might also look at libdwarf/dwarfdump. Though I don't know how well-documented that is either though; my impression is not very well.

Another idea is to hijack GDB. GDB now (7.0+ I think) has a Python API, and it seems quite possible that you'd be able to use that to pull out some information. (Although now that I think about it, I don't think I know how to use GDB to go from address->source information even at the prompt without having a process stopped in it at that point.)

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Getting debug info from GCC

Postby korona » Sun Aug 10, 2014 10:17 am UTC

What exactly do you want to do? Do you want to print function addresses at runtime? Do you want to disassemble executables in a GUI?

What file format is your GCC targetting? ELF is well-documented and can be parsed easily.

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: Getting debug info from GCC

Postby Robert'); DROP TABLE *; » Tue Aug 12, 2014 1:40 am UTC

korona wrote:What exactly do you want to do? Do you want to print function addresses at runtime? Do you want to disassemble executables in a GUI?

There's a software emulator involved, and I want to be able to tell what part of the source code its executing based on where it is in the machine code. Being able to learn function addresses at runtime would also be useful, since it'd let me show the current stack trace in a human-readable way.

What file format is your GCC targetting? ELF is well-documented and can be parsed easily.

The standard build process actually produces three or four different formats. I was originally looking at the Intel HEX output, but it also produces ELF and the intermediate .o files. Having had the ELF decoded, I got what look like the function addresses (although I think I need to do more research about what libraries are being implicitly pulled in) so thanks for pointing that out. :)

EvanED wrote:Black Magic. :-)

...Yeah. :(

You might also look at libdwarf/dwarfdump. Though I don't know how well-documented that is either though; my impression is not very well.

Thanks, I hadn't heard of DWARF before. I'll see if I can coax GCC into producing something they can work with.

Another idea is to hijack GDB. GDB now (7.0+ I think) has a Python API, and it seems quite possible that you'd be able to use that to pull out some information. (Although now that I think about it, I don't think I know how to use GDB to go from address->source information even at the prompt without having a process stopped in it at that point.)

I was actually intending to use C#, but I guess I might be able to jury-rig up something that talks Python to GDB as a last resort.
...And that is how we know the Earth to be banana-shaped.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 6 guests