8 readblock(int fd, DwarfBlock *b, ulong off, ulong len)
10 b->data = malloc(len);
13 if(seek(fd, off, 0) < 0 || readn(fd, b->data, len) != len){
23 findsection(Elf *elf, char *name, ulong *off, ulong *len)
27 if((s = elfsection(elf, name)) == nil)
35 loadsection(Elf *elf, char *name, DwarfBlock *b)
39 if(findsection(elf, name, &off, &len) < 0)
41 return readblock(elf->fd, b, off, len);
50 werrstr("nil elf passed to dwarfopen");
54 d = mallocz(sizeof(Dwarf), 1);
59 if(loadsection(elf, ".debug_abbrev", &d->abbrev) < 0
60 || loadsection(elf, ".debug_aranges", &d->aranges) < 0
61 || loadsection(elf, ".debug_line", &d->line) < 0
62 || loadsection(elf, ".debug_pubnames", &d->pubnames) < 0
63 || loadsection(elf, ".debug_info", &d->info) < 0)
65 loadsection(elf, ".debug_frame", &d->frame);
66 loadsection(elf, ".debug_ranges", &d->ranges);
67 loadsection(elf, ".debug_str", &d->str);
69 /* make this a table once there are more */
70 switch(d->elf->hdr.machine){
72 d->reg = dwarf386regs;
73 d->nreg = dwarf386nregs;
76 werrstr("unsupported machine");
84 free(d->aranges.data);
87 free(d->pubnames.data);
99 free(d->aranges.data);
102 free(d->pubnames.data);
103 free(d->ranges.data);