def _backtrace2line(name, ldpath=None, srcpath=None):
    '''Get a backtrace file and use addr2line
       on every stack frame line in that file,
       with adjusted line number if requested.
    '''
    try:
        f = open(name, 'rt')
        ts = f.readlines()
        f.close()
    except:
        _print("open failed: %r", name)
        return  # None
     # skip till start of path
    s = ' ' + os.path.sep
     # create a _Frame instance for each stack
     # frame line and collect all _Frames of a
     # library or executable in a separate list
    pfs, f = {}, None
    for i, t in enumerate(ts):
        f = _Frame(t, i, f, skip=s)
        p = f.path
        if p in pfs:
            pfs[p].append(f)
        elif p:
            pfs[p] = [f,]
        else:  # not a <path> frame
            f = None
     # for each library or executable, get a list
     # of addresses, pass those to add2line, save
     # the file name and (adjusted) line number in
     # the _Frame and append the final result to
     # the original line of the input file
    r = 0
    for p, fs in pfs.iteritems():
        p = _which(p, ldpath)
        if p:
            a = [f.addr for f in fs]
            s = _addr2line(p, *a)
            if s:
                for i, f in enumerate(fs):
                    f.file, f.line = s[i].split(':')
                if srcpath:
                    r += _adjust(fs, srcpath)
                for f in fs:
                    i = f.lino
                    t = ts[i].rstrip()  # line break
                    ts[i] = t + '  ' + f.file + ':' + f.line
    ##_print("%d adjusted line numbers*", r)
    return ''.join(ts)  # as string
Get a backtrace file and use addr2line
       on every stack frame line in that file,
       with adjusted line number if requested.
    
recipes/Python/534147_backtrace2line__stack_traces_source_file_name/recipe-534147.py