addr2line

package module
v0.0.0-...-6bb65f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 10 Imported by: 0

README

Go addr2line

Do you have memory addresses from an ELF file (say, kernel core dump)?

Do you want to find out where are they located in source programatically?

Including inline function information?

This library would give you this information, by running addr2line once, and feeding it with the address to the standard input. Hence minimizing the overhead for each address resolution.

In Go (golang)?

package main

import (
    "fmt"
    "log"
	"github.com/elazarl/addr2line"
)

func main() {
	a, err := addr2line.New("a.out")
    if err != nil {
        log.Fatalln("New", err)
    }
rs, err := a.Resolve(0xff)
    if err != nil {
        log.Fatalln("Resolve", err)
    }
    fmt.Println(rs[0].Function, "@", rs[0].File, rs[0].Line)
    for _, r := range rs[1:] {
        fmt.Println("Inlined by", r.Function, "@", r.File, r.Line)
    }
}

If you know that the source file's root directory was /home/elazar/project, let addr2line know about it, it'll strip the prefix from the files.

a, _ := addr2line.New("a.out")
a.FilePrefix = []byte("/home/foo")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr2line

type Addr2line struct {
	FilePrefix []byte
	// contains filtered or unexported fields
}

func New

func New(elf string) (*Addr2line, error)

func NewFromCmd

func NewFromCmd(cmd *exec.Cmd) (*Addr2line, error)

func (*Addr2line) Close

func (a *Addr2line) Close() error

func (*Addr2line) Resolve

func (a *Addr2line) Resolve(addr uint64) ([]Result, error)

func (*Addr2line) ResolveString

func (a *Addr2line) ResolveString(addr string) ([]Result, error)

type Result

type Result struct {
	Function string
	File     string
	Line     int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL