Install pygdbmi via pip
masterInstall the pygdbmi package using pip to get access to the GDB machine interface parser and the GDB subprocess controller.
pip install pygdbmirepository·master·Indexed 42 days ago
https://github.com/cs01/pygdbmiA Python library that provides structured, JSON-serializable output from the GDB Machine Interface (GDB/MI). It includes a parser to convert raw GDB/MI strings into Python dictionaries and a GdbController class to manage GDB as a subprocess, supporting GDB 7.6+ on Linux, macOS, and Windows.
Install the pygdbmi package using pip to get access to the GDB machine interface parser and the GDB subprocess controller.
pip install pygdbmiUse pygdbmi.gdbmiparser.parse_response to convert raw GDB/MI string output into structured, JSON-serializable Python dictionaries. This is useful when you are capturing output from a GDB process manually and need to process it programmatically.
from pygdbmi import gdbmiparser
from pprint import pprint
response = gdbmiparser.parse_response('^done,bkpt={number="1",type="breakpoint",disp="keep", enabled="y",addr="0x08048564",func="main",file="myprog.c",fullname="/home/myprog.c",line="68",thread-groups=["i1"],times="0"')
pprint(response)The GdbController provides several methods to interact with the running GDB process:
write(command, timeout_sec=1, raise_error_on_timeout=True): Sends a command (MI or standard GDB) to GDB. Use MI commands (starting with -) for better structured output.send_signal_to_gdb(signal): Sends a signal to GDB. signal can be the name (e.g., 'SIGKILL') or the integer value.interrupt_gdb(): Sends SIGINT to GDB to interrupt execution.exit(): Exits the GDB process.# Examples of various interaction methods
gdbmi.write('-break-insert main')
gdbmi.write('break main')
gdbmi.send_signal_to_gdb('SIGKILL')
gdbmi.interrupt_gdb()
gdbmi.exit()The GdbController class allows you to manage a GDB instance as a subprocess. You can write both standard GDB commands and GDB Machine Interface (MI) commands (which start with a -) and receive structured responses.
from pygdbmi.gdbcontroller import GdbController
from pprint import pprint
# Start gdb process
gdbmi = GdbController()
# Load binary a.out and get structured response
response = gdbmi.write('-file-exec-file a.out')
pprint(response)
# Example of sending an MI command with a custom timeout
response = gdbmi.write('-exec-next', timeout_sec=0.1)please check gdb is codesigned - see taskgated(8), you must follow macOS codesigning instructions.Every parsed response from pygdbmi is a list of dictionaries. Each dictionary contains the following keys:
message: A textual message from GDB (can be None).payload: The structured content of the output (can be a dictionary, list, string, or None).token: If the input command had a token, this field contains it. Present only for notify and result types.type: The category of the record, based on GDB/MI output types. Possible values include:result: The result of a command (e.g., done, running, error).notify: Asynchronous changes (e.g., breakpoint modified).console: Textual responses to CLI commands.log: Internal GDB debugging messages.output: Output from the target.target: Output from a remote target.done: Indicates GDB has finished outputting.