Skip to content

Godbg

debug_color = theme.add_color_param('go-dump-debug', 'blue', "color for 'go-dump' command's debug info when --debug is specified") module-attribute

hex_digits = set('0123456789abcdefABCDEFxX') module-attribute

indent_amount = pwndbg.config.add_param('go-dump-indent-amount', 4, 'the indent amount for go-dump pretty printing') module-attribute

line_width = pwndbg.config.add_param('go-dump-line-width', 80, 'the soft line width for go-dump pretty printing') module-attribute

ArrayType dataclass

Bases: Type

An array type in Go, notated as [count]inner.

Arrays are laid out as contiguous data.

count: int instance-attribute

inner: Type instance-attribute

__init__(meta, inner, count)

additional_metadata()

dump(addr, fmt=FormatOpts())

get_typename()

size()

BackrefType dataclass

Bases: Type

A temporary placeholder type used when dumping recursive types, e.g. type a []a

key: int instance-attribute

__init__(meta, key)

dump(addr, fmt=FormatOpts())

get_typename()

size()

BasicType dataclass

Bases: Type

A primitive Go type.

Complex numbers are laid out as a real and imaginary part (both floats). Strings are laid out as a pointer and a length.

Methodless interfaces (the interface{} type) are denoted as any, and interfaces with methods are denoted as interface.

Function pointers are denoted as funcptr.

extra_meta: List[str] = dataclasses.field(default_factory=list) class-attribute instance-attribute

name: str instance-attribute

sz: int = dataclasses.field(init=False) class-attribute instance-attribute

__init__(meta, name, extra_meta=list())

__post_init__()

additional_metadata()

dump(addr, fmt=FormatOpts())

get_typename()

size()

FormatOpts dataclass

debug: bool = False class-attribute instance-attribute

float_decimals: int | None = None class-attribute instance-attribute

int_hex: bool = False class-attribute instance-attribute

pretty: bool = False class-attribute instance-attribute

__init__(int_hex=False, debug=False, pretty=False, float_decimals=None)

fmt_bytes(val)

fmt_debug(val, default='')

fmt_elems(elems)

fmt_float(val)

fmt_int(val)

fmt_ptr(val)

fmt_str(val)

GoTypeKind

Bases: IntEnum

ARRAY = 17 class-attribute instance-attribute

BOOL = 1 class-attribute instance-attribute

CHAN = 18 class-attribute instance-attribute

COMPLEX128 = 16 class-attribute instance-attribute

COMPLEX64 = 15 class-attribute instance-attribute

FLOAT32 = 13 class-attribute instance-attribute

FLOAT64 = 14 class-attribute instance-attribute

FUNC = 19 class-attribute instance-attribute

INT = 2 class-attribute instance-attribute

INT16 = 4 class-attribute instance-attribute

INT32 = 5 class-attribute instance-attribute

INT64 = 6 class-attribute instance-attribute

INT8 = 3 class-attribute instance-attribute

INTERFACE = 20 class-attribute instance-attribute

INVALID = 0 class-attribute instance-attribute

MAP = 21 class-attribute instance-attribute

POINTER = 22 class-attribute instance-attribute

SLICE = 23 class-attribute instance-attribute

STRING = 24 class-attribute instance-attribute

STRUCT = 25 class-attribute instance-attribute

UINT = 7 class-attribute instance-attribute

UINT16 = 9 class-attribute instance-attribute

UINT32 = 10 class-attribute instance-attribute

UINT64 = 11 class-attribute instance-attribute

UINT8 = 8 class-attribute instance-attribute

UINTPTR = 12 class-attribute instance-attribute

UNSAFEPOINTER = 26 class-attribute instance-attribute

get_simple_name()

GoTypeMeta dataclass

addr: int instance-attribute

align: int = 1 class-attribute instance-attribute

direct_iface: bool = False class-attribute instance-attribute

kind: GoTypeKind instance-attribute

name: str instance-attribute

size: int = 0 class-attribute instance-attribute

__init__(name, kind, addr, size=0, align=1, direct_iface=False)

MapType dataclass

Bases: Type

A map type in Go, notated as map[key]val.

Note that maps in Go are actually pointers to the inner map, but the map type printer here directly prints the inner map.

Maps don't have a simple layout, and may reasonably change, but the last change was in 2017, so it probably won't.

The layout assumed is as follows (taken from src/runtime/map.go commit 1b4f1dc):

type hmap struct { count int flags uint8 B uint8 noverflow uint16 hash0 uint32 buckets unsafe.Pointer oldbuckets unsafe.Pointer nevacuate uintptr extra *mapextra }

key: Type instance-attribute

val: Type instance-attribute

__init__(meta, key, val)

additional_metadata()

dump(addr, fmt=FormatOpts())

field_offsets() staticmethod

get_typename()

size()

PointerType dataclass

Bases: Type

A pointer type in Go, notated as *inner.

inner: Type instance-attribute

__init__(meta, inner)

additional_metadata()

dump(addr, fmt=FormatOpts())

get_typename()

size()

RuntimeType dataclass

Bases: Type

A value of a runtime reflection type in Go, notated as runtime(SIZE)ADDRESS, where SIZE is the size of the type's value in bytes, and ADDRESS is the address of the type.

This type is useful for serializing cyclic types.

addr: int instance-attribute

sz: int instance-attribute

__init__(meta, sz, addr)

dump(addr, fmt=FormatOpts())

get_typename()

size()

SliceType dataclass

Bases: Type

A slice type in Go, notated as []inner.

Slices are laid out as a pointer, length, and capacity.

inner: Type instance-attribute

__init__(meta, inner)

additional_metadata()

dump(addr, fmt=FormatOpts())

get_typename()

size()

StructType dataclass

Bases: Type

A struct type in Go, notated as struct(SIZE){FIELDS}, where SIZE is the size of the struct in bytes, and FIELDS is a semicolon-separated list of OFFSET:NAME:TYPE fields.

fields: List[Tuple[str, Type | str, int]] instance-attribute

name: str | None = None class-attribute instance-attribute

sz: int instance-attribute

__init__(meta, fields, sz, name=None)

additional_metadata()

dump(addr, fmt=FormatOpts())

get_typename()

size()

Type dataclass

Bases: ABC

meta: GoTypeMeta | None instance-attribute

__init__(meta)

__str__()

additional_metadata()

Returns a list of lines of additional metadata to dump from the go-type command.

dump(addr, fmt=FormatOpts()) abstractmethod

Dump a type from memory given an address and format.

get_typename() abstractmethod

Returns the typename of a type. Should be reparsable via _parse_ty.

Also used to get the string representation.

is_cyclic()

Checks if a type is cyclic (contains references to itself), e.g. type a []a

size() abstractmethod

Returns the size of a type in bytes.

Used for computing array and struct layouts.

compute_named_offsets(fields)

Like compute_offsets, but takes in field names and returns a dictionary mapping field name to offset instead.

Also maps in a special $size field with the size of the struct.

compute_offsets(fields)

Given a list of (size, alignment) for struct field types, returns a list of field offsets for the struct. The last element will be the offset of the struct's end (the struct size).

Layout computation taken from src/go/types/sizes.go commit 1b4f1dc

decode_runtime_type(addr, keep_backrefs=False)

Decodes a runtime reflection type from memory, returning a (meta, type) tuplee.

The layout assumed is as follows (taken from src/internal/abi/type.go commit 1b4f1dc):

type Type struct { Size_ uintptr PtrBytes uintptr Hash uint32 TFlag TFlag Align_ uint8 FieldAlign_ uint8 Kind_ Kind Equal func(unsafe.Pointer, unsafe.Pointer) bool GCData *byte Str NameOff PtrToThis TypeOff }

emit_warning(msg)

get_elf()

get_go_version()

Try to determine the Go version used to compile the binary.

None can be returned if the version couldn't be inferred, at which point it's probably best to assume latest version.

get_type_start(addr=None)

Given the address to a type, try to find the moduledata types section containing it.

Necessary to determine the base address that the type name is offset by.

load_float(data)

load_int(data)

load_uint(data, endian=None)

parse_type(ty)

read_buildversion(addr)

Reads a Go runtime.buildVersion string to extract the version.

read_type_name(addr)

Reads a Go type name given the address to the name.

Go type names are stored as a 1 byte bitfield followed by a varint length prefixed string after 1.17.

Prior to 1.17, they were stored as a 1 byte bitfield followed by a 2 byte length prefixed string.

read_varint_str(addr)

Read a length-prefix string encoded with Go's variable length encoding.

Implementation taken from https://github.com/golang/go/blob/9d33956503c0d96c0c5666d374173f7ac9756d98/src/internal/abi/type.go#L640-L649

word_size()

Gets the Go word size for the current architecture.

Values taken from https://github.com/golang/go/blob/20b79fd5775c39061d949569743912ad5e58b0e7/src/go/types/sizes.go#L233-L252