{"id":4190,"library":"pygdbmi","title":"pygdbmi","description":"pygdbmi is a Python library that parses GDB's machine interface (MI) output into structured data (Python dictionaries) that are JSON serializable. It also provides a class, `GdbController`, to control GDB as a subprocess, allowing programmatic interaction for backend development of GDB frontends. It supports cross-platform debugging on Linux, macOS, and Windows. The current stable version is 0.11.0.0, with releases occurring periodically to introduce new features, fix bugs, and address breaking changes.","status":"active","version":"0.11.0.0","language":"en","source_language":"en","source_url":"https://github.com/cs01/pygdbmi","tags":["GDB","debugger","MI interface","parsing","subprocesses"],"install":[{"cmd":"pip install pygdbmi","lang":"bash"}],"dependencies":[],"imports":[{"symbol":"GdbController","correct":"from pygdbmi.gdbcontroller import GdbController"},{"symbol":"parse_response","correct":"from pygdbmi.gdbmiparser import parse_response"},{"note":"`NoGdbProcessError` was removed as part of the `GdbController` API changes in v0.10.0.0. Handlers for GDB process issues should now rely on `subprocess.CalledProcessError` or similar standard Python exceptions for subprocess management.","wrong":"from pygdbmi.constants import NoGdbProcessError","symbol":"NoGdbProcessError","correct":"Removed in v0.10.0.0"}],"quickstart":{"code":"from pygdbmi.gdbcontroller import GdbController\nfrom pprint import pprint\nimport os\nimport subprocess\nimport shutil\n\n# NOTE: This example assumes 'make' and 'gdb' are available in your PATH.\n# Create a dummy C program for debugging\nif not os.path.exists('sample_app'):\n    os.makedirs('sample_app')\nwith open('sample_app/main.c', 'w') as f:\n    f.write('int main() { int x = 1; x++; return 0; }')\n\nif shutil.which('gcc') and shutil.which('make'):\n    subprocess.run(['gcc', 'main.c', '-o', 'pygdbmiapp', '-g'], cwd='sample_app', check=True)\n    binary_path = os.path.abspath('sample_app/pygdbmiapp')\nelse:\n    print(\"Warning: 'gcc' or 'make' not found. Quickstart will only demonstrate parsing.\")\n    binary_path = None\n\ngdbmi = GdbController()\n\ntry:\n    if binary_path:\n        print(f\"\\nDebugging: {binary_path}\")\n        # Load the binary\n        responses = gdbmi.write(f\"-file-exec-and-symbols {binary_path}\")\n        print(\"Load binary response:\")\n        pprint(responses)\n\n        # Set a breakpoint at main\n        responses = gdbmi.write(\"-break-insert main\")\n        print(\"Breakpoint response:\")\n        pprint(responses)\n\n        # Run the program\n        responses = gdbmi.write(\"-exec-run\")\n        print(\"Run response:\")\n        pprint(responses)\n\n        # Continue to finish\n        responses = gdbmi.write(\"-exec-continue\")\n        print(\"Continue response:\")\n        pprint(responses)\n\n    # Example of parsing raw MI output\n    print(\"\\nParsing raw GDB MI output:\")\n    raw_mi_output = '^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\"}'\n    parsed_response = gdbmi.gdbmiparser.parse_response(raw_mi_output)\n    pprint(parsed_response)\n\nfinally:\n    # Ensure gdb process is terminated\n    gdbmi.exit()\n    print(\"\\nGDB process exited.\")\n    # Clean up dummy app\n    shutil.rmtree('sample_app', ignore_errors=True)","lang":"python","description":"This quickstart demonstrates how to use `GdbController` to interact with a GDB subprocess programmatically, including loading a binary, setting a breakpoint, running, and continuing execution. It also shows how to directly parse a raw GDB MI output string using `gdbmiparser.parse_response`. A simple C program is compiled and used as the debug target for the demonstration."},"warnings":[{"fix":"Review your `GdbController` instantiation and method calls. Update to the new constructor signature and remove calls to deprecated methods and exception handling for `NoGdbProcessError`. For Python 3.5, upgrade your Python version as support was dropped.","message":"The `GdbController` class API changed significantly in version 0.10.0.0. The constructor now expects `command: Optional[List[str]]` and `time_to_check_for_additional_output_sec: Optional[int]]`. Several methods like `GdbController.verify_valid_gdb_subprocess()` were removed, and the `NoGdbProcessError` exception was also removed.","severity":"breaking","affected_versions":"0.10.0.0+"},{"fix":"Ensure your project is running on Python 3.7 or newer to use `pygdbmi` versions 0.10.0.2 and above. Python 3.9 and 3.10 are explicitly supported from v0.10.0.2.","message":"Support for Python 3.5 was dropped in `pygdbmi` v0.10.0.0, and support for Python 3.6 was dropped in v0.10.0.2.","severity":"breaking","affected_versions":"0.10.0.0+"},{"fix":"Remove any direct calls to `pygdbmi.IoManager.make_non_blocking` from your code. This function was an internal detail and should not have been used directly.","message":"The `pygdbmi.IoManager.make_non_blocking` function was removed from the public API in version 0.11.0.0 as it was considered an internal utility not meant for public consumption.","severity":"breaking","affected_versions":"0.11.0.0+"},{"fix":"Be aware of GDB's output behavior with newer versions. If encountering timeouts after a `run` command, you may need to adjust `time_to_check_for_additional_output_sec` in `GdbController` or implement more robust polling for `get_gdb_response()` to ensure all output is consumed.","message":"When using GDB versions 8.1 and newer, the output from the `run` command might be split into multiple parts. This can cause `pygdbmi` to only catch the initial part, leading to `GdbTimeOutError` if subsequent calls to `get_gdb_response()` are not handled correctly to fetch all parts of the response.","severity":"gotcha","affected_versions":"All versions, with GDB 8.1+"},{"fix":"Always pass `--interpreter=mi2` as part of the GDB command list when initializing `GdbController`, e.g., `GdbController(command=['gdb', '--interpreter=mi2'])`.","message":"To ensure GDB outputs machine-readable interface (MI) format, it must be launched with the `--interpreter=mi2` flag. If this flag is omitted, `pygdbmi` will receive standard console output which it cannot reliably parse into structured data.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}