Esempio n. 1
0
func (u *Usercorn) Symbolicate(addr uint64, includeFile bool) (string, error) {
	var sym models.Symbol
	var dist uint64
	fileLine := ""
	for _, f := range u.mappedFiles {
		if f.Contains(addr) {
			sym, dist = f.Symbolicate(addr)
			if sym.Name != "" && includeFile {
				fileLine = f.FileLine(addr)
			}
			break
		}
	}
	name := sym.Name
	if name != "" {
		if u.config.Demangle {
			name = models.Demangle(name)
		}
		if dist > 0 {
			name = fmt.Sprintf("%s+0x%x", name, dist)
		}
		if fileLine != "" {
			name = fmt.Sprintf("%s (%s)", name, fileLine)
		}
	}
	return name, nil
}
Esempio n. 2
0
func (u *Usercorn) Symbolicate(addr uint64) (string, error) {
	var symbolicate = func(addr uint64, symbols []models.Symbol) (result models.Symbol, distance uint64) {
		if len(symbols) == 0 {
			return
		}
		nearest := make(map[uint64][]models.Symbol)
		var min int64 = -1
		for _, sym := range symbols {
			if sym.Start == 0 {
				continue
			}
			dist := int64(addr - sym.Start)
			if dist >= 0 && (sym.Start+uint64(dist) <= sym.End || sym.End == 0) && sym.Name != "" {
				if dist < min || min == -1 {
					min = dist
				}
				nearest[uint64(dist)] = append(nearest[uint64(dist)], sym)
			}
		}
		if len(nearest) > 0 {
			sym := nearest[uint64(min)][0]
			return sym, uint64(min)
		}
		return
	}
	symbols, _ := u.loader.Symbols()
	var interpSym []models.Symbol
	if u.interpLoader != nil {
		interpSym, _ = u.interpLoader.Symbols()
	}
	sym, sdist := symbolicate(addr-u.base, symbols)
	isym, idist := symbolicate(addr-u.interpBase, interpSym)
	if idist < sdist && isym.Name != "" || sym.Name == "" {
		sym = isym
		sdist = idist
	}
	if sym.Name != "" {
		if u.Demangle {
			sym.Name = models.Demangle(sym.Name)
		}
		if sdist > 0 {
			return fmt.Sprintf("%s+0x%x", sym.Name, sdist), nil
		}
	}
	return sym.Name, nil
}