def parse_cda(): import cachegen return cachegen.parse_files([], [])
def parse_dwarf(): files = set() dirs = set() dwarves = {} rdwarves = {} from elftools.elf.elffile import ELFFile elf = ELFFile(open(self.program)) if elf.has_dwarf_info(): fn = None di = elf.get_dwarf_info() for cu in di.iter_CUs(): try: basedir = None # get the base directory for die in cu.iter_DIEs(): if die.tag == "DW_TAG_compile_unit": basedir = die.attributes[ 'DW_AT_comp_dir'].value + "/" if basedir == None: continue dirs.add(basedir) # get the line program? fns = [] lines = [] lp = di.line_program_for_CU(cu) print "DWARF: CU", basedir, lp['file_entry'][0] for f in lp['file_entry']: if f == "<built-in>": continue if f.dir_index > 0 and lp['include_directory'][ f.dir_index - 1][0] == '/': fn = "" else: fn = basedir if f.dir_index > 0: fn += lp['include_directory'][f.dir_index - 1] + "/" # now we have the filename fn += f.name files.add(fn) fns.append(fn) lines.append(open(fn).read().split("\n")) #print " DWARF: parsing",fn # add all include dirs for entry in lp.get_entries(): s = entry.state #print s if s != None: #print filename, s.line, len(lines) dwarves[s.address] = (fns[s.file - 1], s.line, lines[s.file - 1][s.line - 1]) rd = fns[s.file - 1] + "#" + str(s.line) if rd not in rdwarves: rdwarves[rd] = s.address except Exception as e: print "DWARF: error on", fn, "got", e # parse in CDA if qira_config.WITH_CDA: import cachegen cfiles = filter(lambda x: x[-2:] != ".h", fns) hfiles = filter(lambda x: x[-2:] == ".h", fns) ldirs = set() for fn in hfiles: ep = fn[len(basedir):].split("/") for i in range(len(ep)): ldirs.add(basedir + "/" + '/'.join(ep[0:i])) tmp = [] for ld in ldirs: tmp.append("-I") tmp.append(ld) #print tmp cachegen.parse_files(cfiles, tmp) return (list(files), dwarves, rdwarves, list(dirs))
def parse_dwarf(): files = set() dirs = set() dwarves = {} rdwarves = {} from elftools.elf.elffile import ELFFile elf = ELFFile(open(self.program)) if elf.has_dwarf_info(): fn = None di = elf.get_dwarf_info() for cu in di.iter_CUs(): try: basedir = None # get the base directory for die in cu.iter_DIEs(): if die.tag == "DW_TAG_compile_unit": basedir = die.attributes['DW_AT_comp_dir'].value + "/" if basedir == None: continue dirs.add(basedir) # get the line program? fns = [] lines = [] lp = di.line_program_for_CU(cu) print "DWARF: CU", basedir, lp['file_entry'][0] for f in lp['file_entry']: if f == "<built-in>": continue if f.dir_index > 0 and lp['include_directory'][f.dir_index-1][0] == '/': fn = "" else: fn = basedir if f.dir_index > 0: fn += lp['include_directory'][f.dir_index-1]+"/" # now we have the filename fn += f.name files.add(fn) fns.append(fn) lines.append(open(fn).read().split("\n")) #print " DWARF: parsing",fn # add all include dirs for entry in lp.get_entries(): s = entry.state #print s if s != None: #print filename, s.line, len(lines) dwarves[s.address] = (fns[s.file-1], s.line, lines[s.file-1][s.line-1]) rd = fns[s.file-1]+"#"+str(s.line) if rd not in rdwarves: rdwarves[rd] = s.address except Exception as e: print "DWARF: error on",fn,"got",e # parse in CDA if qira_config.WITH_CDA: import cachegen cfiles = filter(lambda x: x[-2:] != ".h", fns) hfiles = filter(lambda x: x[-2:] == ".h", fns) ldirs = set() for fn in hfiles: ep = fn[len(basedir):].split("/") for i in range(len(ep)): ldirs.add(basedir + "/" + '/'.join(ep[0:i])) tmp = [] for ld in ldirs: tmp.append("-I") tmp.append(ld) #print tmp cachegen.parse_files(cfiles, tmp) return (list(files), dwarves, rdwarves, list(dirs))