addr2line

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 10 Imported by: 0

README

Addr2line Package in Go

This is a Golang package that provides functionality equivalent to GNU addr2line.

Prerequisites

To support the demangling feature, the addr2line package relies on the ianlancetaylor/demangle package. Be sure to install this package before using addr2line.

Install the demangle package using:

go get -u github.com/ianlancetaylor/demangle

Usage

The addr2line package is simple to use.

Install the addr2line package using:

go get -u github.com/Asphaltt/addr2line

Example usage:

import "github.com/Asphaltt/addr2line"

a2l, err := addr2line.New("/path/to/so/file/with/debug/symbols")
if err != nil {
    fmt.Println(err)
    return
}

e, err := a2l.Get(address, true)
if err != nil {
    fmt.Println(err)
} else {
    //t.Logf("%v\n", e)
    fmt.Printf("Library  : %s\n", e.SoPath)
    fmt.Printf("Address  : 0x%xu\n", e.Address)
    fmt.Printf("Function : %s\n", e.Func)
    fmt.Printf("File     : %s\n", e.File)
    fmt.Printf("Line     : %d\n", e.Line)
}

For more detailed examples, refer to addr2line_test.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr2Line

type Addr2Line struct {
	// contains filtered or unexported fields
}

Addr2Line is a struct that contains the debug information of an ELF file.

func New

func New(soPath string) (*Addr2Line, error)

New parses the ELF file at soPath, extracts the debug information and symbols. Then returns an Addr2Line struct.

func NewAt added in v0.1.1

func NewAt(r io.ReaderAt, soPath string) (*Addr2Line, error)

NewAt parses the ELF file from the reader r, extracts the debug information and symbols. Then returns an Addr2Line struct.

soPath is an optional parameter to provide more specific error messages.

func (*Addr2Line) FindBySymbol added in v0.1.2

func (a2l *Addr2Line) FindBySymbol(symbol string) (*Addr2LineEntry, error)

func (*Addr2Line) Get

func (a2l *Addr2Line) Get(address uint64, doDemangle bool) (*Addr2LineEntry, error)

Get returns the Addr2LineEntry for the given address.

type Addr2LineEntry

type Addr2LineEntry struct {
	// Address in an executable or an offset in a section of a relocatable object
	Address uint64

	// SoPath is the name of the library for which addresses should be translated
	SoPath string

	// Func is the name of function at Addr2LineEntry.Address in
	// Addr2LineEntry.SoPath
	Func string

	// File is the name of the source file in which the Func is located in
	// Addr2LineEntry.Address of Addr2LineEntry.SoPath library.
	File string

	// Line is the number of line in Addr2LineEntry.File at Address
	Line uint

	// Inline is the flag that indicates whether the function is inlined or not.
	Inline bool
}

Addr2LineEntry represents debug information for a address in the debug symbol.

Jump to

Keyboard shortcuts

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