...

Package disasm

import "cmd/internal/disasm"
Overview
Index

Overview ▾

Package disasm provides disassembly routines.

It is broken out from cmd/internal/objfile so tools that don't need disassembling don't need to depend on x/arch disassembler code.

type CachedFile

CachedFile contains the content of a file split into lines.

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

type Disasm

Disasm is a disassembler for a given File.

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

func DisasmForFile

func DisasmForFile(f *objfile.File) (*Disasm, error)

DisasmForFile returns a disassembler for the file f.

func (*Disasm) Decode

func (d *Disasm) Decode(start, end uint64, relocs []objfile.Reloc, 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) 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 includes corresponding source lines. The disassembly only includes functions that overlap the range [start, end).

type FileCache

FileCache is a simple LRU cache of file contents.

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

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.