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
 42
 43
 44
 45
 46
 47
 48
 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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
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)

    if _GDB_MI_NOTIFY_RE.match(gdb_mi_text):
        token, message, payload = _get_notify_msg_and_payload(gdb_mi_text, stream)
        return {
            "type": "notify",
            "message": message,
            "payload": payload,
            "token": token,
        }

    elif _GDB_MI_RESULT_RE.match(gdb_mi_text):
        token, message, payload = _get_result_msg_and_payload(gdb_mi_text, stream)
        return {
            "type": "result",
            "message": message,
            "payload": payload,
            "token": token,
        }

    elif _GDB_MI_CONSOLE_RE.match(gdb_mi_text):
        match = _GDB_MI_CONSOLE_RE.match(gdb_mi_text)
        if match:
            payload = unescape(match.groups()[0])
        else:
            payload = None
        return {
            "type": "console",
            "message": None,
            "payload": payload,
        }

    elif _GDB_MI_LOG_RE.match(gdb_mi_text):
        match = _GDB_MI_LOG_RE.match(gdb_mi_text)
        if match:
            payload = unescape(match.groups()[0])
        else:
            payload = None
        return {"type": "log", "message": None, "payload": payload}

    elif _GDB_MI_TARGET_OUTPUT_RE.match(gdb_mi_text):
        match = _GDB_MI_TARGET_OUTPUT_RE.match(gdb_mi_text)
        if match:
            payload = unescape(match.groups()[0])
        else:
            payload = None
        return {"type": "target", "message": None, "payload": payload}

    elif response_is_finished(gdb_mi_text):
        return {"type": "done", "message": None, "payload": None}

    else:
        # 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
    """
    if _GDB_MI_RESPONSE_FINISHED_RE.match(gdb_mi_text):
        return True

    else:
        return False