Skip to content
This repository
tree: d46ff57488
Fetching contributors…

Cannot retrieve contributors at this time

file 93 lines (73 sloc) 2.106 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include <map>

#include "bstream.h"
#include "dbg_elf.h"
#include "dwf_abbrv.h"
#include "dwf_cunit.h"
#include "dwf_info.h"

void read_cunits_sect(ELF* elf, std::istream* is, DwInfo* dwarf) {
   BVector info = elf->get_section(*is, ".debug_info");
   BStream bs(info, false);

   while (!bs.eof()) {
      bool is_dwf64 = false;
      Offset cu_offset;
      Offset unit_len;
      Offset end_spos;
      Offset abb_off;
      int dwf_ver;
      int ptr_size;
      DwCUnit* cunit;

      cu_offset = bs.offset();
      unit_len = bs.read4u();
      if (unit_len == 0) continue;

      if (unit_len == 0xffffffffL) {
         is_dwf64 = true;
         unit_len = bs.read8u();
      }

      end_spos = bs.offset() + unit_len;

      dwf_ver = bs.read2u();
      if (is_dwf64) {
         abb_off = bs.read8u();
      } else {
         abb_off = bs.read4u();
      }

      ptr_size = bs.read1u();

      cunit = new DwCUnit(dwarf);
      cunit->set_sec_offset(cu_offset);
      cunit->set_sec_length(unit_len);
      cunit->set_dwf_ver(dwf_ver);
      cunit->set_abb_offset(abb_off);
      cunit->set_ptr_size(ptr_size);

      DwAbbrvMap* cu_abb = dwarf->get_abb_map(abb_off);
      cunit->set_abb_map(cu_abb);
      if (cu_abb == NULL) {
         throw Exception("invalid DWARF");
      }

      DwEntry* dbg_info = DwEntry::read_tree(cunit, NULL, bs);
      cunit->set_dbg_info(dbg_info);
      dwarf->add_cunit(cunit);

      bs.seek(end_spos, BSTREAM_SET);
   }
}

void read_abbrv_sect(ELF* elf, std::istream* is, DwInfo* dwarf)
{
   BVector abbrv = elf->get_section(*is, ".debug_abbrev");

   DwAbbrvTab* tab = new DwAbbrvTab(dwarf);
   if (tab == NULL) {
      throw Exception("out of memory");
   }

   BStream bs(abbrv, false);
   tab->read(bs);
   dwarf->set_abb_tab(tab);
}

int main(int argc, char* argv[])
{
   ELF* elf = new ELF(argv[1], 0);
   std::istream* is = elf->open(0);

   DwInfo dwarf(elf, *is);
   dwarf.read_string_table();

   read_abbrv_sect(elf, is, &dwarf);
   //dwarf.dump_abb_tab();

   read_cunits_sect(elf, is, &dwarf);
   dwarf.dump_dbg_info();

   //sleep(100);
}
Something went wrong with that request. Please try again.