Skip to content

gdbmiparser

Python parser for gdb's machine interface interpreter.

Parses string output from gdb with the --interpreter=mi2 flag into structured objects.

See more at https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html#GDB_002fMI

parse_response(gdb_mi_text)

Parse gdb mi text and turn it into a dictionary.

See https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Stream-Records.html#GDB_002fMI-Stream-Records for details on types of gdb mi output.

Parameters:

Name Type Description Default
gdb_mi_text str

String output from gdb

required

Returns:

Type Description
Dict

dictionary with keys "type", "message", "payload", "token"

Source code in pygdbmi/gdbmiparser.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def parse_response(gdb_mi_text: str) -> Dict:
    """Parse gdb mi text and turn it into a dictionary.

    See https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Stream-Records.html#GDB_002fMI-Stream-Records
    for details on types of gdb mi output.

    Args:
        gdb_mi_text: String output from gdb

    Returns:
        dictionary with keys "type", "message", "payload", "token"
    """
    stream = StringStream(gdb_mi_text, debug=_DEBUG)

    for pattern, parser in _GDB_MI_PATTERNS_AND_PARSERS:
        match = pattern.match(gdb_mi_text)
        if match is not None:
            return parser(match, stream)

    # This was not gdb mi output, so it must have just been printed by
    # the inferior program that's being debugged
    return {
        "type": "output",
        "message": None,
        "payload": gdb_mi_text,
    }

response_is_finished(gdb_mi_text)

Return true if the gdb mi response is ending

Parameters:

Name Type Description Default
gdb_mi_text str

String output from gdb

required

Returns:

Type Description
bool

True if gdb response is finished

Source code in pygdbmi/gdbmiparser.py
77
78
79
80
81
82
83
84
85
86
def response_is_finished(gdb_mi_text: str) -> bool:
    """Return true if the gdb mi response is ending

    Args:
        gdb_mi_text: String output from gdb

    Returns:
        True if gdb response is finished
    """
    return _GDB_MI_RESPONSE_FINISHED_RE.match(gdb_mi_text) is not None