This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using BFD to get debugging information from .elf files


Hi. I'm working on some Mac OS X (Darwin)-based AVR debugging tools. I built the avr-gcc toolchain and have used it successfully, even with gdb, to build for and debug various AVR microcontrollers. My builds produce a .elf file that gdb then uses for debugging.

I figured I should be able to build binutils, enabling all targets, and use BFD from my Mac OS X app to get debugging information out of the .elf file. So, I wrote code like this:

bfd_init();
bfd* bfdRef = bfd_openr(argv[1], "elf32-avr");
if (bfdRef == NULL)
{
    printf("Failed to open BFD");
    return 1;
}

if (!bfd_check_format(bfdRef, bfd_archive))
{
    printf("Format matches\n");
}

const char** ts = bfd_target_list();
int i = 0;
while (ts[i] != NULL)
{
    const char* t = ts[i];
    printf("Arch: %s\n", t);
    i++;
}

if ((bfd_get_file_flags (bfdRef) & HAS_SYMS) == 0)
{
    printf("NO SYMS\n");
}

long storageNeeded = bfd_get_symtab_upper_bound(bfdRef);
printf("%ld\n", storageNeeded);


This works, up until the call to bfd_get_symtab_upper_bound(), at which point I get a bus error. It prints that the format matches, "elf32-avr" shows up as one of the available targets, and it shows that there are no symbols. Then it waits a long time before Bus Erroring.


If I specify NULL for the target to bfd_openr(), I get an assertion failure before the crash: "BFD: BFD 2.17 assertion fail ../../bfd/ mach-o.c:168"

So, I realize I must be making some rookie mistake, but I'm not sure what that is. Can anyone enlighten me? Thanks!


-- Rick



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]