package disasm

import "cmd/internal/disasm"

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.

Index

Types

type CachedFile

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

CachedFile contains the content of a file split into lines.

type Disasm

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

Disasm is a disassembler for a given File.

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

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.

Source Files

disasm.go

Version
v1.24.0 (latest)
Published
Feb 10, 2025
Platform
linux/amd64
Imports
21 packages
Last checked
4 minutes ago

Tools for package owners.