disasm

Imports

Imports #

"bufio"
"bytes"
"container/list"
"encoding/binary"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"text/tabwriter"
"cmd/internal/objfile"
"cmd/internal/src"
"golang.org/x/arch/arm/armasm"
"golang.org/x/arch/arm64/arm64asm"
"golang.org/x/arch/loong64/loong64asm"
"golang.org/x/arch/ppc64/ppc64asm"
"golang.org/x/arch/riscv64/riscv64asm"
"golang.org/x/arch/s390x/s390xasm"
"golang.org/x/arch/x86/x86asm"

Constants & Variables

byteOrders var #

var byteOrders = map[string]binary.ByteOrder{...}

disasms var #

var disasms = map[string]disasmFunc{...}

Type Aliases

disasmFunc type #

type disasmFunc func(code []byte, pc uint64, lookup lookupFunc, ord binary.ByteOrder, _ bool) (text string, size int)

lookupFunc type #

type lookupFunc func(addr uint64) (sym string, base uint64)

Structs

CachedFile struct #

CachedFile contains the content of a file split into lines.

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

Disasm struct #

Disasm is a disassembler for a given File.

type Disasm struct {
syms []objfile.Sym
pcln objfile.Liner
text []byte
textStart uint64
textEnd uint64
goarch string
disasm disasmFunc
byteOrder binary.ByteOrder
}

FileCache struct #

FileCache is a simple LRU cache of file contents.

type FileCache struct {
files *list.List
maxLen int
}

textReader struct #

type textReader struct {
code []byte
pc uint64
}

Functions

Decode method #

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

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

DisasmForFile function #

DisasmForFile returns a disassembler for the file f.

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

Line method #

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.

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

NewFileCache function #

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

func NewFileCache(maxLen int) *FileCache

Print method #

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).

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

ReadAt method #

func (r textReader) ReadAt(data []byte, off int64) (n int, err error)

base function #

base returns the final element in the path. It works on both Windows and Unix paths, regardless of host operating system.

func base(path string) string

disasmForEntry function #

func disasmForEntry(e *objfile.Entry) (*Disasm, error)

disasm_386 function #

func disasm_386(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder, gnuAsm bool) (string, int)

disasm_amd64 function #

func disasm_amd64(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder, gnuAsm bool) (string, int)

disasm_arm function #

func disasm_arm(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder, gnuAsm bool) (string, int)

disasm_arm64 function #

func disasm_arm64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder, gnuAsm bool) (string, int)

disasm_loong64 function #

func disasm_loong64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder, gnuAsm bool) (string, int)

disasm_ppc64 function #

func disasm_ppc64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder, gnuAsm bool) (string, int)

disasm_riscv64 function #

func disasm_riscv64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder, gnuAsm bool) (string, int)

disasm_s390x function #

func disasm_s390x(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder, gnuAsm bool) (string, int)

disasm_x86 function #

func disasm_x86(code []byte, pc uint64, lookup lookupFunc, arch int, gnuAsm bool) (string, int)

lookup method #

lookup finds the symbol name containing addr.

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

Generated with Arrow