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
912import BoostBuild
1013import TestCmd
1114import re
1215
1316def 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
3033def 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
3437def 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
3841def 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)
474972-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)
535573-gdb-exit
54- 73^exit
56+ 73\\ ^exit
5557""" )
56-
5758 t .cleanup ()
5859
5960def test_exit_status ():
@@ -66,13 +67,13 @@ def test_exit_status():
6667(gdb)
676872-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)
747573-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)
10010172-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)
1061071-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)
1111122-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)
1161173-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)
12112273-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)
15315472-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)
1591601-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)
1641652-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)
1691703-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)
1741754-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)
17918073-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)
21521672-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)
2212221-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)
2262272-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)
2312323-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)
23623773-gdb-exit
237- 73^exit
238+ 73\\ ^exit
238239""" )
239240 t .cleanup ()
240241
241-
242242def 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)
27127172-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)
28628673-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)
29829874-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)
31031075-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)
31631676-gdb-exit
317- 76^exit
317+ 76\\ ^exit
318318""" )
319319 t .cleanup ()
320320
321+
321322test_exec_run ()
322323test_exit_status ()
323324test_exec_step ()
0 commit comments