GDB machine for interacting with the GNU debugger.

GDB Machine

class tbot_contrib.gdb.GDB(host: H, *args: str | Path[H], gdb: str | Path[H] | None = None)[source]

Bases: Connector, GDBShell

GDB Machine.

This machine can be used to invoke GDB on a LinuxShell and interact with it. The machine will live in a context like any other:

from tbot_contrib import gdb

with tbot.acquire_lab() as lh:
    with gdb.GDB(lh, "/usr/bin/echo") as g:
        # GDB active here

You can then send commands to gdb using gdb.exec() or drop the user into an interactive GDB session with gdb.interactive():

with gdb.GDB(lh, "/usr/bin/echo", "hello", "world") as g:
    # Break on the first getenv
    g.exec("break", "getenv")

    # Not let the user take over and interact with GDB

New in version 0.9.3.

exec(*args: str) str

Run a GDB command (and wait for it to finish).


gdb.exec("break", "main")
# Returns once the program hits a breakpoint
interactive() None

Drop into an interactive GDB session.

escape(*args: str) str

Escape a string so it can be used safely on the GDB command-line.


At the moment, this is a noop because GDB escaping is very different from traditional escaping … Use with care.


class tbot_contrib.gdb.GDBShell[source]

Bases: Shell

Shell implementation for GDB.

This class implements CLI interaction with GDB. You will most likely not use it directly but instead use a gdb.GDB() machine instead.

New in version 0.9.3.