def parse_dwarf(infile, cuname): if not os.path.isfile(infile): error("No such file %s" % infile) exit(1) dwarf = DWARF(infile) # Keep track of what has been written to the syntax tree # Indexed by (tag,name) # Instead of using this, it may be better to just collect and # to dedup later, so that we can check that there are no name conflicts. written = defaultdict(int) if cuname: # TODO: handle multiple specific compilation units cu = None for i, c in enumerate(dwarf.info.cus): if c.name.endswith(cuname[0]): cu = c break if cu is None: print("Can't find compilation unit %s" % cuname, file=sys.stderr) statements = process_compile_unit(dwarf, cu, written) else: statements = [] for cu in dwarf.info.cus: progress("Processing %s" % cu.name) statements.extend(process_compile_unit(dwarf, cu, written)) return statements
def parse_dwarf(infile, root): if not os.path.isfile(infile): error("No such file %s" % infile) exit(1) dwarf = DWARF(infile) for cu in dwarf.info.cus: progress("Processing %s" % cu.name) types = process_compile_unit(dwarf, cu, root) if types: return types
def parse_dwarf(infile, roots): if not os.path.isfile(infile): error("No such file %s" % infile) exit(1) dwarf = DWARF(infile) for cu in dwarf.info.cus: progress("Processing %s" % cu.name) types = process_compile_unit(dwarf, cu, roots) if all(x in types for x in roots): # return if all roots found return types return None # not found
class TestDwarfQuery(TestCase): def setUp(self): self.dwarf = DWARF('../test/test') def test_loc_by_addr(self): loc = self.dwarf.get_loc_by_addr(0x8048475) self.assertEqual(loc, ('/home/emilmont/Workspace/dbg/test/main.c', 36, 0)) def test_loc_by_sym(self): loc = self.dwarf.get_loc_by_sym('main') self.assertEqual(loc, ('/home/emilmont/Workspace/dbg/test/main.c', 54, 0)) loc = self.dwarf.get_loc_by_sym('temp') self.assertEqual(loc, ('/home/emilmont/Workspace/dbg/test/main.c', 15, 0)) def test_addr_by_sym(self): addr = self.dwarf.get_addr_by_sym('main') self.assertEqual(addr, 0x80484ac) def test_addr_by_loc(self): addr = self.dwarf.get_addr_by_loc('a/test.c', 10) self.assertEqual(addr, 0x8048403)
def setUp(self): self.dwarf = DWARF('../test/test')