Skip to content

init

GDB_BUILTIN_COMMANDS = pwndbg.dbg.commands() module-attribute

P = ParamSpec('P') module-attribute

T = TypeVar('T') module-attribute

command_names: Set[str] = set() module-attribute

commands: List[Command] = [] module-attribute

log = logging.getLogger(__name__) module-attribute

pwndbg_is_reloading = False module-attribute

ArgparsedCommand

Adds documentation and offloads parsing for a Command via argparse

aliases = aliases instance-attribute

category = category instance-attribute

parser = argparse.ArgumentParser(description=parser_or_desc) instance-attribute

__call__(function)

__init__(parser_or_desc, aliases=[], command_name=None, category=CommandCategory.MISC)

:param parser_or_desc: argparse.ArgumentParser instance or str

Command

Generic command wrapper

__name__ = command_name instance-attribute

aliases = aliases instance-attribute

builtin_override_whitelist: Set[str] = {'up', 'down', 'search', 'pwd', 'start', 'ignore'} class-attribute instance-attribute

category = category instance-attribute

doc = doc instance-attribute

function = function instance-attribute

handle = pwndbg.dbg.add_command(command_name, _handler, doc) instance-attribute

history: Dict[int, str] = {} class-attribute instance-attribute

is_alias = is_alias instance-attribute

repeat = False instance-attribute

shell = shell instance-attribute

__call__(*args, **kwargs)

__init__(function, prefix=False, command_name=None, shell=False, is_alias=False, aliases=[], category=CommandCategory.MISC, doc=None)

check_repeated(argument, from_tty)

Keep a record of all commands which come from the TTY.

Returns:

Type Description
bool

True if this command was executed by the user just hitting "enter".

invoke(argument, from_tty)

Invoke the command with an argument string

split_args(argument)

Split a command-line string from the user into arguments.

Returns:

Type Description
List[str]

A (tuple, dict), in the form of *args, **kwargs.

Dict[Any, Any]

The contents of the tuple/dict are undefined.

CommandCategory

Bases: str, Enum

BREAKPOINT = 'Breakpoint' class-attribute instance-attribute

CONTEXT = 'Context' class-attribute instance-attribute

DEV = 'Developer' class-attribute instance-attribute

DISASS = 'Disassemble' class-attribute instance-attribute

INTEGRATIONS = 'Integrations' class-attribute instance-attribute

JEMALLOC = 'jemalloc Heap' class-attribute instance-attribute

KERNEL = 'Kernel' class-attribute instance-attribute

LINUX = 'Linux/libc/ELF' class-attribute instance-attribute

MEMORY = 'Memory' class-attribute instance-attribute

MISC = 'Misc' class-attribute instance-attribute

NEXT = 'Step/Next/Continue' class-attribute instance-attribute

PROCESS = 'Process' class-attribute instance-attribute

PTMALLOC2 = 'GLibc ptmalloc2 Heap' class-attribute instance-attribute

PWNDBG = 'pwndbg' class-attribute instance-attribute

REGISTER = 'Register' class-attribute instance-attribute

SHELL = 'Shell' class-attribute instance-attribute

STACK = 'Stack' class-attribute instance-attribute

START = 'Start' class-attribute instance-attribute

WINDBG = 'WinDbg' class-attribute instance-attribute

AddressExpr(s)

Parses an address expression. Returns an int.

HexOrAddressExpr(s)

Parses string as hexadecimal int or an address expression. Returns an int. (e.g. '1234' will return 0x1234)

OnlyWhenHeapIsInitialized(function)

OnlyWhenLocal(function)

OnlyWhenPagingEnabled(function)

OnlyWhenQemuKernel(function)

OnlyWhenRunning(function)

OnlyWhenUserspace(function)

OnlyWithArch(arch_names)

Decorates function to work only with the specified archictectures.

OnlyWithDbg(*dbg_names)

Decorates function to work only with the specified debugger.

OnlyWithFile(function)

OnlyWithKernelDebugSyms(function)

OnlyWithResolvedHeapSyms(function)

OnlyWithTcache(function)

fix(arg, sloppy=False, quiet=True, reraise=False)

Fix a single command-line argument coming from the CLI.

Parameters:

Name Type Description Default
arg(str)

Original string representation (e.g. '0', '\(rax', '\)rax+44')

required
sloppy(bool)

If arg cannot be evaluated, return arg. (default: False)

required
quiet(bool)

If an error occurs, suppress it. (default: True)

required
reraise(bool)

If an error occurs, raise the exception. (default: False)

required

Returns:

Type Description
str | Value | None

Ideally a Value object. May return a str if sloppy==True.

str | Value | None

May return None if sloppy == False and reraise == False.

fix_int(*a, **kw)

fix_int_reraise(*a, **kw)

fix_reraise(*a, **kw)

load_commands()

sloppy_gdb_parse(s)

This function should be used as argparse.ArgumentParser .add_argument method's type helper.

This makes the type being parsed as gdb value and if that parsing fails, a string is returned.

:param s: String. :return: Whatever gdb.parse_and_eval returns or string.