Skip to content

Commit eee99b2

Browse files
paolopasgrafikrobot
authored andcommitted
more on debugger-mi.py (and TestCmd.py)
+ direct definition of pattern in split_stdin_stdout was a good idea + minor outside_pattern adjustment + escape_line now escapes prompt only, for more readability of diff output in case of error + simplified BoostBuild.Tester init + escape added on test data where needed + better regexps hardcoded in test data, mainly .* -> .+ + optimized TestCmd.match_re, use of re.match instead of forcing regex compilation, since Python re.match use a cache to remember already compiled expressions do not need to recompile "\(gdb\) $" any time fixes #585
1 parent d3cf312 commit eee99b2

2 files changed

Lines changed: 72 additions & 71 deletions

File tree

test/TestCmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def match_re(lines=None, res=None):
217217
if not type(res) is list:
218218
res = res.split("\n")
219219
for i in range(min(len(lines), len(res))):
220-
if not re.compile("^" + res[i] + "$").search(lines[i]):
220+
if not re.match(res[i] + "$", lines[i]):
221221
return MatchError("Mismatch at line %d\n- %s\n+ %s\n" %
222222
(i+1, res[i], lines[i]))
223223
if len(lines) < len(res):

test/debugger-mi.py

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
#!/usr/bin/env python3
22

33
# Copyright 2016 Steven Watanabe
4+
# Copyright 2026 Paolo Pastori
45
# Distributed under the Boost Software License, Version 1.0.
56
# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
67

7-
# Test the mi interface for the debugger
8+
"""
9+
Test the mi interface for the debugger
10+
"""
811

912
import BoostBuild
1013
import TestCmd
1114
import re
1215

1316
def split_stdin_stdout(text):
14-
"""stdin is all text after the prompt up to and including
15-
the next newline. Everything else is stdout. stdout
16-
may contain regular expressions enclosed in {{}}."""
17-
prompt = re.escape('(gdb) \n')
18-
pattern = re.compile('(?<=%s)((?:\\d*-.*)\n)' % prompt)
17+
# stdin is all text after the prompt up to and including
18+
# the next newline. Everything else is stdout. stdout
19+
# may contain regular expressions enclosed in {{}}.
20+
pattern = re.compile(r'(?<=\(gdb\) \n)((?:\d*-.*)\n)')
1921
stdin = ''.join(re.findall(pattern, text))
2022
stdout = re.sub(pattern, '', text)
21-
outside_pattern = re.compile(r'(?:\A|(?<=\}\}))(?:[^\{]|(?:\{(?!\{)))*(?:(?=\{\{)|\Z)')
23+
outside_pattern = re.compile(r'(?:\A|(?<=\}\}))(?:[^{]|(?:\{(?!\{)))*(?:(?=\{\{)|\Z)')
2224

2325
def escape_line(line):
24-
line = re.sub(outside_pattern, lambda m: re.escape(m.group(0)), line)
26+
if line == '(gdb) ': return r'\(gdb\) '
27+
line = re.sub(outside_pattern, lambda m: m.group(0), line)
2528
return re.sub(r'\{\{|\}\}', '', line)
2629

2730
stdout = '\n'.join([escape_line(line) for line in stdout.split('\n')])
28-
return (stdin,stdout)
31+
return (stdin, stdout)
2932

3033
def run(tester, io):
31-
(input,output) = split_stdin_stdout(io)
34+
(input, output) = split_stdin_stdout(io)
3235
tester.run_build_system(stdin=input, stdout=output, match=TestCmd.match_re)
3336

3437
def make_tester():
35-
return BoostBuild.Tester(["-dmi"], pass_toolset=False, pass_d0=False,
36-
use_test_config=False, ignore_toolset_requirements=False, match=TestCmd.match_re)
38+
return BoostBuild.Tester(["-dmi"], pass_toolset=False)
39+
3740

3841
def test_exec_run():
3942
t = make_tester()
4043
t.write("test.jam", """\
4144
UPDATE ;
4245
""")
43-
4446
run(t, """\
4547
=thread-group-added,id="i1"
4648
(gdb)
4749
72-exec-run -ftest.jam
4850
=thread-created,id="1",group-id="i1"
49-
72^running
51+
72\\^running
5052
(gdb)
51-
*stopped,reason="exited-normally"
53+
\\*stopped,reason="exited-normally"
5254
(gdb)
5355
73-gdb-exit
54-
73^exit
56+
73\\^exit
5557
""")
56-
5758
t.cleanup()
5859

5960
def test_exit_status():
@@ -66,13 +67,13 @@ def test_exit_status():
6667
(gdb)
6768
72-exec-run -ftest.jam
6869
=thread-created,id="1",group-id="i1"
69-
72^running
70+
72\\^running
7071
(gdb)
7172
72-
*stopped,reason="exited",exit-code="1"
73+
\\*stopped,reason="exited",exit-code="1"
7374
(gdb)
7475
73-gdb-exit
75-
73^exit
76+
73\\^exit
7677
""")
7778
t.cleanup()
7879

@@ -95,31 +96,31 @@ def test_exec_step():
9596
=thread-group-added,id="i1"
9697
(gdb)
9798
-break-insert f
98-
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
99+
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
99100
(gdb)
100101
72-exec-run -ftest.jam
101102
=thread-created,id="1",group-id="i1"
102-
72^running
103+
72\\^running
103104
(gdb)
104-
*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1",stopped-threads="all"
105+
\\*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="8"},thread-id="1",stopped-threads="all"
105106
(gdb)
106107
1-exec-step
107-
1^running
108+
1\\^running
108109
(gdb)
109-
*stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="3"},thread-id="1"
110+
\\*stopped,reason="end-stepping-range",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="3"},thread-id="1"
110111
(gdb)
111112
2-exec-step
112-
2^running
113+
2\\^running
113114
(gdb)
114-
*stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="4"},thread-id="1"
115+
\\*stopped,reason="end-stepping-range",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="4"},thread-id="1"
115116
(gdb)
116117
3-exec-step
117-
3^running
118+
3\\^running
118119
(gdb)
119-
*stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="9"},thread-id="1"
120+
\\*stopped,reason="end-stepping-range",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="9"},thread-id="1"
120121
(gdb)
121122
73-gdb-exit
122-
73^exit
123+
73\\^exit
123124
""")
124125
t.cleanup()
125126

@@ -148,36 +149,36 @@ def test_exec_next():
148149
=thread-group-added,id="i1"
149150
(gdb)
150151
-break-insert f
151-
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
152+
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
152153
(gdb)
153154
72-exec-run -ftest.jam
154155
=thread-created,id="1",group-id="i1"
155-
72^running
156+
72\\^running
156157
(gdb)
157-
*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="7"},thread-id="1",stopped-threads="all"
158+
\\*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="7"},thread-id="1",stopped-threads="all"
158159
(gdb)
159160
1-exec-next
160-
1^running
161+
1\\^running
161162
(gdb)
162-
*stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1"
163+
\\*stopped,reason="end-stepping-range",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="8"},thread-id="1"
163164
(gdb)
164165
2-exec-next
165-
2^running
166+
2\\^running
166167
(gdb)
167-
*stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="9"},thread-id="1"
168+
\\*stopped,reason="end-stepping-range",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="9"},thread-id="1"
168169
(gdb)
169170
3-exec-next
170-
3^running
171+
3\\^running
171172
(gdb)
172-
*stopped,reason="end-stepping-range",frame={func="h",args=[],file="test.jam",fullname="{{.*}}test.jam",line="14"},thread-id="1"
173+
\\*stopped,reason="end-stepping-range",frame={func="h",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="14"},thread-id="1"
173174
(gdb)
174175
4-exec-next
175-
4^running
176+
4\\^running
176177
(gdb)
177-
*stopped,reason="end-stepping-range",frame={func="module scope",args=[],file="test.jam",fullname="{{.*}}test.jam",line="17"},thread-id="1"
178+
\\*stopped,reason="end-stepping-range",frame={func="module scope",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="17"},thread-id="1"
178179
(gdb)
179180
73-gdb-exit
180-
73^exit
181+
73\\^exit
181182
""")
182183
t.cleanup()
183184

@@ -210,35 +211,34 @@ def test_exec_finish():
210211
=thread-group-added,id="i1"
211212
(gdb)
212213
-break-insert f
213-
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
214+
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
214215
(gdb)
215216
72-exec-run -ftest.jam
216217
=thread-created,id="1",group-id="i1"
217-
72^running
218+
72\\^running
218219
(gdb)
219-
*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="3"},thread-id="1",stopped-threads="all"
220+
\\*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="3"},thread-id="1",stopped-threads="all"
220221
(gdb)
221222
1-exec-finish
222-
1^running
223+
1\\^running
223224
(gdb)
224-
*stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1"
225+
\\*stopped,reason="end-stepping-range",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="8"},thread-id="1"
225226
(gdb)
226227
2-exec-finish
227-
2^running
228+
2\\^running
228229
(gdb)
229-
*stopped,reason="end-stepping-range",frame={func="h",args=[],file="test.jam",fullname="{{.*}}test.jam",line="14"},thread-id="1"
230+
\\*stopped,reason="end-stepping-range",frame={func="h",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="14"},thread-id="1"
230231
(gdb)
231232
3-exec-finish
232-
3^running
233+
3\\^running
233234
(gdb)
234-
*stopped,reason="end-stepping-range",frame={func="module scope",args=[],file="test.jam",fullname="{{.*}}test.jam",line="21"},thread-id="1"
235+
\\*stopped,reason="end-stepping-range",frame={func="module scope",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="21"},thread-id="1"
235236
(gdb)
236237
73-gdb-exit
237-
73^exit
238+
73\\^exit
238239
""")
239240
t.cleanup()
240241

241-
242242
def test_breakpoints():
243243
"""Tests the interaction between the following commands:
244244
break, clear, delete, disable, enable"""
@@ -266,58 +266,59 @@ def test_breakpoints():
266266
=thread-group-added,id="i1"
267267
(gdb)
268268
-break-insert f
269-
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
269+
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
270270
(gdb)
271271
72-exec-run -ftest.jam
272272
=thread-created,id="1",group-id="i1"
273-
72^running
273+
72\\^running
274274
(gdb)
275-
*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="3"},thread-id="1",stopped-threads="all"
275+
\\*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="3"},thread-id="1",stopped-threads="all"
276276
(gdb)
277277
-interpreter-exec console kill
278-
^done
278+
\\^done
279279
(gdb)
280280
-break-insert g
281-
^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",func="g"}
281+
\\^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",func="g"}
282282
(gdb)
283283
-break-disable 1
284-
^done
284+
\\^done
285285
(gdb)
286286
73-exec-run -ftest.jam
287287
=thread-created,id="1",group-id="i1"
288-
73^running
288+
73\\^running
289289
(gdb)
290-
*stopped,reason="breakpoint-hit",bkptno="2",disp="keep",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="7"},thread-id="1",stopped-threads="all"
290+
\\*stopped,reason="breakpoint-hit",bkptno="2",disp="keep",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="7"},thread-id="1",stopped-threads="all"
291291
(gdb)
292292
-interpreter-exec console kill
293-
^done
293+
\\^done
294294
(gdb)
295295
-break-enable 1
296-
^done
296+
\\^done
297297
(gdb)
298298
74-exec-run -ftest.jam
299299
=thread-created,id="1",group-id="i1"
300-
74^running
300+
74\\^running
301301
(gdb)
302-
*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="3"},thread-id="1",stopped-threads="all"
302+
\\*stopped,reason="breakpoint-hit",bkptno="1",disp="keep",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="3"},thread-id="1",stopped-threads="all"
303303
(gdb)
304304
-interpreter-exec console kill
305-
^done
305+
\\^done
306306
(gdb)
307307
-break-delete 1
308-
^done
308+
\\^done
309309
(gdb)
310310
75-exec-run -ftest.jam
311311
=thread-created,id="1",group-id="i1"
312-
75^running
312+
75\\^running
313313
(gdb)
314-
*stopped,reason="breakpoint-hit",bkptno="2",disp="keep",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="7"},thread-id="1",stopped-threads="all"
314+
\\*stopped,reason="breakpoint-hit",bkptno="2",disp="keep",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="7"},thread-id="1",stopped-threads="all"
315315
(gdb)
316316
76-gdb-exit
317-
76^exit
317+
76\\^exit
318318
""")
319319
t.cleanup()
320320

321+
321322
test_exec_run()
322323
test_exit_status()
323324
test_exec_step()

0 commit comments

Comments
 (0)