file

package
v0.0.0-...-d7c0310 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const FileSymPrefix = "gofile.."

Added from cmd/internal/src

Variables

This section is empty.

Functions

func GetStringType

func GetStringType(t dwarf.Type) string

Given a type, return a string representation

func GetUnderlyingType

func GetUnderlyingType(entry *dwarf.Entry, data *dwarf.Data) (dwarf.Type, error)

GetUnderlyingType for a parameter or return value from AttrType

func OpenElf

func OpenElf(r io.ReaderAt) (rawFile, error)

func ParseCallSites

func ParseCallSites(d *dwarf.Data, callSites *[]CallSite, subprograms *map[dwarf.Offset]dwarf.Entry, functions map[string]DwarfEntry) map[string]DwarfEntry

Parse Call sites into a map of DwarfEntry

func ParseDwarf

func ParseDwarf(dwf *dwarf.Data) map[string]map[string]DwarfEntry

ParseDwarf and populate a lookup of Dwarf entries

func PrintRelocationTable

func PrintRelocationTable(relocs []Relocation)

Print the relocation table - currently not used

Types

type CachedFile

type CachedFile struct {
	FileName string
	Lines    [][]byte
}

CachedFile contains the content of a file split into lines.

type CallSite

type CallSite struct {
	Entry  dwarf.Entry
	Params []dwarf.Entry
}

Preparing a call site to link to a function / caller

type Component

type Component struct {
	Name      string
	Class     string
	Size      int64
	Type      string
	Framebase string
	RawType   interface{} // the original type
}

A Component can be a Field or param

type Disasm

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

Disasm is a disassembler for a given File.

func (*Disasm) Decode

func (d *Disasm) Decode(start, end uint64, relocs []Relocation, gnuAsm bool, f func(pc, size uint64, file string, line int, text string))

Decode disassembles the text segment range [start, end), calling f for each instruction.

func (*Disasm) DecodeGNUAssembly

func (d *Disasm) DecodeGNUAssembly(start, end uint64, relocs []Relocation, f func(pc, size uint64, file string, line int, text string) Instruction) []Instruction

DecodeGNUAssembly disassembles the text segment range [start, end), calling f for each instruction.

func (*Disasm) GetGNUAssembly

func (d *Disasm) GetGNUAssembly() GNUAssemblyLookup

GetAssembly returns a full data structure of instructions to further parse

func (*Disasm) Lookup

func (d *Disasm) Lookup(addr uint64) (name string, base uint64)

lookup finds the symbol name containing addr.

func (*Disasm) Print

func (d *Disasm) Print(w io.Writer, filter *regexp.Regexp, start, end uint64, printCode bool, gnuAsm bool)

Print prints a disassembly of the file to w. If filter is non-nil, the disassembly only includes functions with names matching filter. If printCode is true, the disassembly includs corresponding source lines. The disassembly only includes functions that overlap the range [start, end).

type DwarfEntry

type DwarfEntry interface {
	GetComponents() []Component // Can be fields, params, etc.
	Name() string
	GetData() *dwarf.Data
	GetEntry() *dwarf.Entry
	GetType() *dwarf.Type
}

A common interface to represent a dwarf entry (what we need)

func ParseFunction

func ParseFunction(d *dwarf.Data, entry *dwarf.Entry, params []FormalParamEntry) DwarfEntry

Populate a function entry

func ParseVariable

func ParseVariable(d *dwarf.Data, entry *dwarf.Entry) DwarfEntry

Populate a variable entry

type ElfFile

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

func (*ElfFile) Dwarf

func (f *ElfFile) Dwarf() (*dwarf.Data, error)

func (*ElfFile) DynamicSymbols

func (f *ElfFile) DynamicSymbols() ([]Symbol, error)

Get dynamic symbols for the elf file

func (*ElfFile) GetRelocations

func (f *ElfFile) GetRelocations() []Relocation

GetRelocations from te entire elf file - yes this is ugly and redundant, please improve!

func (*ElfFile) GoArch

func (f *ElfFile) GoArch() string

GoArch returns the architecture of the elf file

func (*ElfFile) PCLineTable

func (f *ElfFile) PCLineTable() (textStart uint64, symtab, pclntab []byte, err error)

PCLineTable is renamed from pcln

func (*ElfFile) ParseDwarf

func (f *ElfFile) ParseDwarf() map[string]map[string]DwarfEntry

Parse dwarf into the file object

func (*ElfFile) Symbols

func (f *ElfFile) Symbols() ([]Symbol, error)

Get all symbols for the elf file (but not imported)

type ElfSymbol

type ElfSymbol struct {
	Name        string       // symbol name
	Address     uint64       // virtual address of symbol
	Size        int64        // size in bytes
	Code        rune         // nm code (T for text, D for data, and so on)
	Type        string       // string of type calculated from s.Info
	Binding     string       // binding calculated from s.Info
	Library     string       // Library name
	Version     string       // Library name
	Relocations []Relocation // in increasing Addr order
	Original    elf.Symbol   // hold the original symbol
	ArchInt     int
}

An Elf Symbol found in a file (e.g., ELF?)

func (*ElfSymbol) GetAddress

func (s *ElfSymbol) GetAddress() uint64

func (*ElfSymbol) GetBinding

func (s *ElfSymbol) GetBinding() string

func (*ElfSymbol) GetCode

func (s *ElfSymbol) GetCode() rune

func (*ElfSymbol) GetDirection

func (s *ElfSymbol) GetDirection() string

GetDirection determines if we have import/export based on definition

func (*ElfSymbol) GetIntArch

func (s *ElfSymbol) GetIntArch() int

func (*ElfSymbol) GetLibrary

func (s *ElfSymbol) GetLibrary() string

func (*ElfSymbol) GetName

func (s *ElfSymbol) GetName() string

And functions required for an elf symbol

func (*ElfSymbol) GetOriginal

func (s *ElfSymbol) GetOriginal() interface{}

func (*ElfSymbol) GetRelocations

func (s *ElfSymbol) GetRelocations() []Relocation

func (*ElfSymbol) GetSize

func (s *ElfSymbol) GetSize() int64

func (*ElfSymbol) GetType

func (s *ElfSymbol) GetType() string

func (*ElfSymbol) GetVersion

func (s *ElfSymbol) GetVersion() string

type Entry

type Entry struct {
	Name string
	// contains filtered or unexported fields
}

A generic Entry in a file has a name and data

func (*Entry) Disasm

func (e *Entry) Disasm() (*Disasm, error)

Disasm returns a disassembler for the file f.

func (*Entry) Dwarf

func (e *Entry) Dwarf() (*dwarf.Data, error)

Return Dwarf debug information (if it exists)

func (*Entry) DynamicSymbols

func (e *Entry) DynamicSymbols() ([]Symbol, error)

func (*Entry) GOARCH

func (e *Entry) GOARCH() string

GOARCH returns the GOARCH assocaited with the entry

func (*Entry) GetRelocations

func (e *Entry) GetRelocations() []Relocation

func (*Entry) LoadAddress

func (e *Entry) LoadAddress() (uint64, error)

LoadAddress returns the EXPECTED (not actual) address of the file.

func (*Entry) PCLineTable

func (e *Entry) PCLineTable() (Liner, error)

func (*Entry) Symbols

func (e *Entry) Symbols() ([]Symbol, error)

func (*Entry) Text

func (e *Entry) Text() (uint64, []byte, error)

Text returns the text assocaited with the entry

type File

type File struct {
	Entries []*Entry
	// contains filtered or unexported fields
}

An opened File - can be multiple types

func Open

func Open(name string) (*File, error)

Open the named file (please close f.Close after finishing)

func (*File) Close

func (f *File) Close() error

Close the file handle

func (*File) DWARF

func (f *File) DWARF() (*dwarf.Data, error)

Since this returns the top node (root), it returns all the dwarf

func (*File) Disasm

func (f *File) Disasm() (*Disasm, error)

Added back to support getting assembly to parse call sites

func (*File) DynamicSymbols

func (f *File) DynamicSymbols() ([]Symbol, error)

func (*File) GetRelocations

func (f *File) GetRelocations() []Relocation

func (*File) GoArch

func (f *File) GoArch() string

The architecture has to be consistent throughout the file

func (*File) LoadAddress

func (f *File) LoadAddress() (uint64, error)

func (*File) PCLineTable

func (f *File) PCLineTable() (Liner, error)

func (*File) ParseDwarf

func (f *File) ParseDwarf() map[string]map[string]DwarfEntry

func (*File) Symbols

func (f *File) Symbols() ([]Symbol, error)

func (*File) Text

func (f *File) Text() (uint64, []byte, error)

type FileCache

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

FileCache is a simple LRU cache of file contents.

func NewFileCache

func NewFileCache(maxLen int) *FileCache

NewFileCache returns a FileCache which can contain up to maxLen cached file contents.

func (*FileCache) Line

func (fc *FileCache) Line(filename string, line int) ([]byte, error)

Line returns the source code line for the given file and line number. If the file is not already cached, reads it, inserts it into the cache, and removes the least recently used file if necessary. If the file is in cache, it is moved to the front of the list.

type FormalParamEntry

type FormalParamEntry struct {
	Entry *dwarf.Entry
	Type  *dwarf.Type
	Data  *dwarf.Data
}

func ParseFormalParameter

func ParseFormalParameter(d *dwarf.Data, entry *dwarf.Entry) FormalParamEntry

Populate a formal parameter

type FunctionEntry

type FunctionEntry struct {
	Entry              *dwarf.Entry
	Type               *dwarf.Type
	Params             []FormalParamEntry
	Data               *dwarf.Data
	FormalParamsLookup map[dwarf.Offset]*dwarf.Entry
}

Types that we need to parse

func (*FunctionEntry) GetComponents

func (f *FunctionEntry) GetComponents() []Component

Function components are the associated fields

func (*FunctionEntry) GetData

func (f *FunctionEntry) GetData() *dwarf.Data

Expose data and type

func (*FunctionEntry) GetEntry

func (f *FunctionEntry) GetEntry() *dwarf.Entry

func (*FunctionEntry) GetType

func (f *FunctionEntry) GetType() *dwarf.Type

func (*FunctionEntry) Name

func (f *FunctionEntry) Name() string

Get the name of the entry or formal param

type GNUAssembly

type GNUAssembly struct {
	SymbolName   string
	File         string
	PCLine       uint64
	SrcLine      string
	Instructions []Instruction
}

type GNUAssemblyLookup

type GNUAssemblyLookup map[string]GNUAssembly

type Instruction

type Instruction struct {
	Text     string
	Source   string
	Assembly string
	PCLine   uint64
	Size     uint64
}

GNUAssembly holds parsed assembly for symbols

type Liner

type Liner interface {
	// Given a pc, returns the corresponding file, line, and function data.
	// If unknown, returns "",0,nil.
	PCToLine(uint64) (string, int, *gosym.Func)
}

type RelocStringer

type RelocStringer interface {
	// insnOffset is the offset of the instruction containing the relocation
	// from the start of the symbol containing the relocation.
	String(insnOffset uint64) string
}

type Relocation

type Relocation struct {
	Address  uint64 // Address of first byte that reloc applies to.
	Size     uint64 // Number of bytes
	Stringer RelocStringer

	// Added to suppored retriving raw
	SymbolName   string
	Offset       uint64
	SymbolValue  uint64
	RelocType    string // can be parse from into
	Info         uint64
	SectionIndex int
}

https://cs.opensource.google/go/go/+/master:src/debug/elf/elf.go;l=3108

type SortByAddress

type SortByAddress []Symbol

SortByAddress

func (SortByAddress) Len

func (x SortByAddress) Len() int

Length returns the number of symbols in the sorter

func (SortByAddress) Less

func (x SortByAddress) Less(i, j int) bool

func (SortByAddress) Swap

func (x SortByAddress) Swap(i, j int)

Swap swips two symbols

type Symbol

type Symbol interface {
	GetName() string    // symbol name
	GetAddress() uint64 // virtual address of symbol
	GetSize() int64     // size in bytes
	GetCode() rune      // nm code (T for text, D for data, and so on)
	GetType() string    // string of type calculated from s.Info
	GetLibrary() string
	GetVersion() string
	GetBinding() string // binding calculated from s.Info
	GetRelocations() []Relocation
	GetOriginal() interface{}
	GetDirection() string // import or export based on symbol definition
	GetIntArch() int
}

A raw symbol provides extra functions for interaction

type VariableEntry

type VariableEntry struct {
	Entry *dwarf.Entry
	Type  *dwarf.Type
	Data  *dwarf.Data
}

Types that we need to parse

func (*VariableEntry) GetComponents

func (v *VariableEntry) GetComponents() []Component

Variable components is just one for the variable

func (*VariableEntry) GetData

func (v *VariableEntry) GetData() *dwarf.Data

func (*VariableEntry) GetEntry

func (v *VariableEntry) GetEntry() *dwarf.Entry

func (*VariableEntry) GetType

func (v *VariableEntry) GetType() *dwarf.Type

func (*VariableEntry) Name

func (v *VariableEntry) Name() string

Get the name of the entry or formal param

Jump to

Keyboard shortcuts

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