Skip to content

Commit e63e5fc

Browse files
authored
Recognize notifications without payload
1 parent ae2a5d2 commit e63e5fc

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# pygdbmi release history
22

3+
## 0.10.0.3
4+
* Fixed a bug where notifications without a payload were not recognized as such
5+
36
## 0.10.0.2
47
* Strings containing escapes are now unescaped, both for messages in error records, which were previously mangled (#57), and textual records, which were previously left escaped (#58)
58
* Dropped support for Python 3.6 and added explicit support for Python 3.9 and 3.10.

pygdbmi/gdbmiparser.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ def assert_match(actual_char_or_str, expected_char_or_str):
149149
# In addition to a number of out-of-band notifications,
150150
# the response to a gdb/mi command includes one of the following result indications:
151151
# done, running, connected, error, exit
152-
_GDB_MI_RESULT_RE = re.compile(r"^(\d*)\^(\S+?)(,(.*))?$")
152+
_GDB_MI_RESULT_RE = re.compile(r"^(\d*)\^(\S+?)(,.*)?$")
153153

154154
# https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Async-Records.html#GDB_002fMI-Async-Records
155155
# Async records are used to notify the gdb/mi client of additional
156156
# changes that have occurred. Those changes can either be a consequence
157157
# of gdb/mi commands (e.g., a breakpoint modified) or a result of target activity
158158
# (e.g., target stopped).
159-
_GDB_MI_NOTIFY_RE = re.compile(r"^(\d*)[*=](\S+?),(.*)$")
159+
_GDB_MI_NOTIFY_RE = re.compile(r"^(\d*)[*=](\S+?)(,.*)*$")
160160

161161
# https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Stream-Records.html#GDB_002fMI-Stream-Records
162162
# "~" string-output
@@ -193,23 +193,29 @@ def assert_match(actual_char_or_str, expected_char_or_str):
193193

194194
def _get_notify_msg_and_payload(result, stream: StringStream):
195195
"""Get notify message and payload dict"""
196-
token = stream.advance_past_chars(["=", "*"])
197-
token = int(token) if token != "" else None
198-
logger.debug("%s", fmt_green("parsing message"))
199-
message = stream.advance_past_chars([","])
196+
match = _GDB_MI_NOTIFY_RE.match(result)
197+
assert match is not None
198+
groups = match.groups()
199+
token = int(groups[0]) if groups[0] != "" else None
200+
message = groups[1]
200201

201202
logger.debug("parsed message")
202203
logger.debug("%s", fmt_green(message))
203204

204-
payload = _parse_dict(stream)
205+
if groups[2] is None:
206+
payload = None
207+
else:
208+
stream.advance_past_chars([","])
209+
payload = _parse_dict(stream)
210+
205211
return token, message.strip(), payload
206212

207213

208214
def _get_result_msg_and_payload(result, stream: StringStream):
209215
"""Get result message and payload dict"""
210-
211216
match = _GDB_MI_RESULT_RE.match(result)
212-
groups = match.groups() if match else [""]
217+
assert match is not None
218+
groups = match.groups()
213219
token = int(groups[0]) if groups[0] != "" else None
214220
message = groups[1]
215221

tests/test_pygdbmi.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,27 @@ def test_parser(self):
194194
},
195195
)
196196

197+
# Test async records status changes
198+
assert_match(
199+
parse_response('*running,thread-id="all"'),
200+
{
201+
"type": "notify",
202+
"payload": {"thread-id": "all"},
203+
"message": "running",
204+
"token": None,
205+
},
206+
)
207+
208+
assert_match(
209+
parse_response("*stopped"),
210+
{
211+
"type": "notify",
212+
"payload": None,
213+
"message": "stopped",
214+
"token": None,
215+
},
216+
)
217+
197218
def _get_c_program(self, makefile_target_name, binary_name):
198219
"""build c program and return path to binary"""
199220
find_executable(MAKE_CMD)

0 commit comments

Comments
 (0)