godbg ¤
Classes:
-
FormatOpts
– -
Type
– -
GoTypeKind
– -
GoTypeMeta
– -
BackrefType
–A temporary placeholder type used when dumping recursive types, e.g. type a []a
-
BasicType
–A primitive Go type.
-
SliceType
–A slice type in Go, notated as []inner.
-
PointerType
–A pointer type in Go, notated as *inner.
-
ArrayType
–An array type in Go, notated as [count]inner.
-
MapType
–A map type in Go, notated as map[key]val.
-
StructType
–A struct type in Go, notated as struct(SIZE){FIELDS},
-
RuntimeType
–A value of a runtime reflection type in Go, notated as runtime(SIZE)ADDRESS,
Functions:
-
word_size
–Gets the Go word size for the current architecture.
-
compute_offsets
–Given a list of (size, alignment) for struct field types,
-
compute_named_offsets
–Like compute_offsets, but takes in field names and returns a dictionary
-
load_uint
– -
load_int
– -
load_float
– -
emit_warning
– -
get_elf
– -
read_buildversion
–Reads a Go runtime.buildVersion string to extract the version.
-
get_go_version
–Try to determine the Go version used to compile the binary.
-
get_type_start
–Given the address to a type, try to find the moduledata types section containing it.
-
read_varint_str
–Read a length-prefix string encoded with Go's variable length encoding.
-
read_type_name
–Reads a Go type name given the address to the name.
-
decode_runtime_type
–Decodes a runtime reflection type from memory, returning a (meta, type) tuplee.
-
parse_type
–
Attributes:
-
line_width
– -
indent_amount
– -
debug_color
– -
hex_digits
–
line_width module-attribute
¤
line_width = add_param(
"go-dump-line-width", 80, "the soft line width for go-dump pretty printing"
)
indent_amount module-attribute
¤
indent_amount = add_param(
"go-dump-indent-amount", 4, "the indent amount for go-dump pretty printing"
)
debug_color module-attribute
¤
debug_color = add_color_param(
"go-dump-debug",
"blue",
"color for 'go-dump' command's debug info when --debug is specified",
)
FormatOpts dataclass
¤
FormatOpts(
int_hex: bool = False,
debug: bool = False,
pretty: bool = False,
float_decimals: int | None = None,
)
Type dataclass
¤
Type(meta: GoTypeMeta | None)
Bases: ABC
Methods:
-
dump
–Dump a type from memory given an address and format.
-
size
–Returns the size of a type in bytes.
-
get_typename
–Returns the typename of a type. Should be reparsable via _parse_ty.
-
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
additional_metadata
–Returns a list of lines of additional metadata to dump from the
go-type
command. -
__str__
–
Attributes:
-
meta
(GoTypeMeta | None
) –
dump abstractmethod
¤
dump(addr: int, fmt: FormatOpts = FormatOpts()) -> str
Dump a type from memory given an address and format.
size abstractmethod
¤
Returns the size of a type in bytes.
Used for computing array and struct layouts.
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
additional_metadata ¤
Returns a list of lines of additional metadata to dump from the go-type
command.
GoTypeKind ¤
GoTypeMeta dataclass
¤
GoTypeMeta(
name: str,
kind: GoTypeKind,
addr: int,
size: int = 0,
align: int = 1,
direct_iface: bool = False,
)
Attributes:
-
name
(str
) – -
kind
(GoTypeKind
) – -
addr
(int
) – -
size
(int
) – -
align
(int
) – -
direct_iface
(bool
) –
BackrefType dataclass
¤
BackrefType(meta: GoTypeMeta | None, key: int)
Bases: Type
A temporary placeholder type used when dumping recursive types, e.g. type a []a
Methods:
-
dump
– -
size
– -
get_typename
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
additional_metadata
–Returns a list of lines of additional metadata to dump from the
go-type
command. -
__str__
–
Attributes:
-
key
(int
) – -
meta
(GoTypeMeta | None
) –
BasicType dataclass
¤
BasicType(meta: GoTypeMeta | None, name: str, extra_meta: list[str] = list())
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.
Methods:
-
dump
– -
size
– -
get_typename
– -
additional_metadata
– -
__post_init__
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
__str__
–
Attributes:
-
name
(str
) – -
sz
(int
) – -
extra_meta
(list[str]
) – -
meta
(GoTypeMeta | None
) –
is_cyclic ¤
Checks if a type is cyclic (contains references to itself), e.g. type a []a
SliceType dataclass
¤
SliceType(meta: GoTypeMeta | None, inner: Type)
Bases: Type
A slice type in Go, notated as []inner.
Slices are laid out as a pointer, length, and capacity.
Methods:
-
dump
– -
size
– -
get_typename
– -
additional_metadata
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
__str__
–
Attributes:
-
inner
(Type
) – -
meta
(GoTypeMeta | None
) –
is_cyclic ¤
Checks if a type is cyclic (contains references to itself), e.g. type a []a
PointerType dataclass
¤
PointerType(meta: GoTypeMeta | None, inner: Type)
Bases: Type
A pointer type in Go, notated as *inner.
Methods:
-
dump
– -
size
– -
get_typename
– -
additional_metadata
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
__str__
–
Attributes:
-
inner
(Type
) – -
meta
(GoTypeMeta | None
) –
is_cyclic ¤
Checks if a type is cyclic (contains references to itself), e.g. type a []a
ArrayType dataclass
¤
ArrayType(meta: GoTypeMeta | None, inner: Type, count: int)
Bases: Type
An array type in Go, notated as [count]inner.
Arrays are laid out as contiguous data.
Methods:
-
dump
– -
size
– -
get_typename
– -
additional_metadata
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
__str__
–
Attributes:
-
inner
(Type
) – -
count
(int
) – -
meta
(GoTypeMeta | None
) –
is_cyclic ¤
Checks if a type is cyclic (contains references to itself), e.g. type a []a
MapType dataclass
¤
MapType(meta: GoTypeMeta | None, key: Type, val: Type)
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 }
Methods:
-
field_offsets
– -
dump
– -
size
– -
get_typename
– -
additional_metadata
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
__str__
–
Attributes:
is_cyclic ¤
Checks if a type is cyclic (contains references to itself), e.g. type a []a
StructType dataclass
¤
StructType(
meta: GoTypeMeta | None,
fields: list[tuple[str, str | Type, int]],
sz: int,
name: str | None = None,
)
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.
Methods:
-
dump
– -
size
– -
get_typename
– -
additional_metadata
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
__str__
–
Attributes:
-
fields
(list[tuple[str, str | Type, int]]
) – -
sz
(int
) – -
name
(str | None
) – -
meta
(GoTypeMeta | None
) –
is_cyclic ¤
Checks if a type is cyclic (contains references to itself), e.g. type a []a
RuntimeType dataclass
¤
RuntimeType(meta: GoTypeMeta | None, sz: int, addr: int)
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.
Methods:
-
dump
– -
size
– -
get_typename
– -
is_cyclic
–Checks if a type is cyclic (contains references to itself), e.g. type a []a
-
additional_metadata
–Returns a list of lines of additional metadata to dump from the
go-type
command. -
__str__
–
Attributes:
-
sz
(int
) – -
addr
(int
) – -
meta
(GoTypeMeta | None
) –
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
compute_offsets ¤
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
compute_named_offsets ¤
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.
read_buildversion ¤
Reads a Go runtime.buildVersion string to extract the version.
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 ¤
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.
read_varint_str ¤
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
read_type_name ¤
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.
decode_runtime_type ¤
decode_runtime_type(
addr: int, keep_backrefs: bool = False
) -> tuple[GoTypeMeta, Type | None]
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 }