2011-05-16 13:12:07 +00:00
|
|
|
|
2011-08-14 18:12:05 +00:00
|
|
|
#include <precomp.h>
|
2011-05-16 13:12:07 +00:00
|
|
|
#define NDEBUG
|
2011-08-14 21:17:14 +00:00
|
|
|
#include <debug.h>
|
2011-05-16 13:12:07 +00:00
|
|
|
|
|
|
|
/* Adapted for PE */
|
|
|
|
|
|
|
|
Dwarf*
|
|
|
|
dwarfopen(Pe *pe)
|
|
|
|
{
|
|
|
|
Dwarf *d;
|
|
|
|
|
|
|
|
if(pe == nil){
|
|
|
|
werrstr("nil pe passed to dwarfopen");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = mallocz(sizeof(Dwarf), 1);
|
|
|
|
if(d == nil)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
d->pe = pe;
|
|
|
|
if(pe->loadsection(pe, ".debug_abbrev", &d->abbrev) < 0
|
|
|
|
|| pe->loadsection(pe, ".debug_aranges", &d->aranges) < 0
|
|
|
|
|| pe->loadsection(pe, ".debug_line", &d->line) < 0
|
2011-06-01 20:36:40 +00:00
|
|
|
|| pe->loadsection(pe, ".debug_info", &d->info) < 0
|
|
|
|
|| pe->loadsection(pe, ".debug_loc", &d->loc) < 0)
|
2011-05-16 13:12:07 +00:00
|
|
|
goto err;
|
2011-07-08 11:16:26 +00:00
|
|
|
pe->loadsection(pe, ".debug_pubnames", &d->pubnames);
|
2011-05-16 13:12:07 +00:00
|
|
|
pe->loadsection(pe, ".debug_frame", &d->frame);
|
|
|
|
pe->loadsection(pe, ".debug_ranges", &d->ranges);
|
|
|
|
pe->loadsection(pe, ".debug_str", &d->str);
|
|
|
|
|
|
|
|
return d;
|
|
|
|
|
|
|
|
err:
|
|
|
|
DPRINT("Failed to open dwarf\n");
|
|
|
|
free(d->abbrev.data);
|
|
|
|
free(d->aranges.data);
|
|
|
|
free(d->frame.data);
|
|
|
|
free(d->line.data);
|
|
|
|
free(d->pubnames.data);
|
|
|
|
free(d->ranges.data);
|
|
|
|
free(d->str.data);
|
|
|
|
free(d->info.data);
|
2011-06-01 20:36:40 +00:00
|
|
|
free(d->loc.data);
|
2011-05-16 13:12:07 +00:00
|
|
|
free(d);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dwarfclose(Dwarf *d)
|
|
|
|
{
|
|
|
|
free(d->abbrev.data);
|
|
|
|
free(d->aranges.data);
|
|
|
|
free(d->frame.data);
|
|
|
|
free(d->line.data);
|
|
|
|
free(d->pubnames.data);
|
|
|
|
free(d->ranges.data);
|
|
|
|
free(d->str.data);
|
|
|
|
free(d->info.data);
|
|
|
|
pefree(d->pe);
|
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
|