示例#1
0
文件: gatos.go 项目: refnum/gatos
//============================================================================
//		readNextEntry : Read the next entry.
//----------------------------------------------------------------------------
func readNextEntry(theReader *dwarf.Reader) *dwarf.Entry {

	// Read the entry
	theEntry, theErr := theReader.Next()
	if theErr != nil {
		fmt.Printf("ERROR: %v\n", theErr.String())
		theEntry = nil
	}

	return (theEntry)
}
示例#2
0
文件: gatos.go 项目: refnum/gatos
//============================================================================
//		processChildren : Process an entry's children.
//----------------------------------------------------------------------------
func processChildren(theReader *dwarf.Reader, depth int, canSkip bool) {

	// Process the children
	if canSkip {
		theReader.SkipChildren()
	} else {
		for {
			theChild := readNextEntry(theReader)
			if theChild == nil || theChild.Tag == 0 {
				break
			}

			processEntry(theReader, depth, theChild)
		}
	}
}
示例#3
0
// dwarfSourceLineEntry tries to get file/line information from a
// DWARF compilation unit. Returns nil if it doesn't find anything.
func (f *file) dwarfSourceLineEntry(r *dwarf.Reader, entry *dwarf.Entry, addr uint64) []plugin.Frame {
	lines, err := f.dwarf.LineReader(entry)
	if err != nil {
		return nil
	}
	var lentry dwarf.LineEntry
	if err := lines.SeekPC(addr, &lentry); err != nil {
		return nil
	}

	// Try to find the function name.
	name := ""
FindName:
	for entry, err := r.Next(); entry != nil && err == nil; entry, err = r.Next() {
		if entry.Tag == dwarf.TagSubprogram {
			ranges, err := f.dwarf.Ranges(entry)
			if err != nil {
				return nil
			}
			for _, pcs := range ranges {
				if pcs[0] <= addr && addr < pcs[1] {
					var ok bool
					// TODO: AT_linkage_name, AT_MIPS_linkage_name.
					name, ok = entry.Val(dwarf.AttrName).(string)
					if ok {
						break FindName
					}
				}
			}
		}
	}

	// TODO: Report inlined functions.

	frames := []plugin.Frame{
		{
			Func: name,
			File: lentry.File.Name,
			Line: lentry.Line,
		},
	}

	return frames
}