3 # Copyright 2016 Steven Watanabe
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7 # Test the mi interface for the debugger
13 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
)
19 stdin
= ''.join(re
.findall(pattern
, text
))
20 stdout
= re
.sub(pattern
, '', text
)
21 outside_pattern
= re
.compile(r
'(?:\A|(?<=\}\}))(?:[^\{]|(?:\{(?!\{)))*(?:(?=\{\{)|\Z)')
23 def escape_line(line
):
24 line
= re
.sub(outside_pattern
, lambda m
: re
.escape(m
.group(0)), line
)
25 return re
.sub(r
'\{\{|\}\}', '', line
)
27 stdout
= '\n'.join([escape_line(line
) for line
in stdout
.split('\n')])
31 (input,output
) = split_stdin_stdout(io
)
32 tester
.run_build_system(stdin
=input, stdout
=output
, match
=TestCmd
.match_re
)
35 return BoostBuild
.Tester(["-dmi"], pass_toolset
=False, pass_d0
=False,
36 use_test_config
=False, ignore_toolset_requirements
=False, match
=TestCmd
.match_re
)
40 t
.write("test.jam", """\
45 =thread-group-added,id="i1"
47 72-exec-run -ftest.jam
48 =thread-created,id="1",group-id="i1"
51 *stopped,reason="exited-normally"
59 def test_exit_status():
61 t
.write("test.jam", """\
65 =thread-group-added,id="i1"
67 72-exec-run -ftest.jam
68 =thread-created,id="1",group-id="i1"
72 *stopped,reason="exited",exit-code="1"
81 t
.write("test.jam", """\
95 =thread-group-added,id="i1"
98 ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
100 72-exec-run -ftest.jam
101 =thread-created,id="1",group-id="i1"
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"
109 *stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="3"},thread-id="1"
114 *stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="4"},thread-id="1"
119 *stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="9"},thread-id="1"
126 def test_exec_next():
128 t
.write("test.jam", """\
148 =thread-group-added,id="i1"
151 ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
153 72-exec-run -ftest.jam
154 =thread-created,id="1",group-id="i1"
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"
162 *stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1"
167 *stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="9"},thread-id="1"
172 *stopped,reason="end-stepping-range",frame={func="h",args=[],file="test.jam",fullname="{{.*}}test.jam",line="14"},thread-id="1"
177 *stopped,reason="end-stepping-range",frame={func="module scope",args=[],file="test.jam",fullname="{{.*}}test.jam",line="17"},thread-id="1"
184 def test_exec_finish():
186 t
.write("test.jam", """\
210 =thread-group-added,id="i1"
213 ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
215 72-exec-run -ftest.jam
216 =thread-created,id="1",group-id="i1"
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"
224 *stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1"
229 *stopped,reason="end-stepping-range",frame={func="h",args=[],file="test.jam",fullname="{{.*}}test.jam",line="14"},thread-id="1"
234 *stopped,reason="end-stepping-range",frame={func="module scope",args=[],file="test.jam",fullname="{{.*}}test.jam",line="21"},thread-id="1"
242 def test_breakpoints():
243 """Tests the interaction between the following commands:
244 break, clear, delete, disable, enable"""
246 t
.write("test.jam", """\
266 =thread-group-added,id="i1"
269 ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
271 72-exec-run -ftest.jam
272 =thread-created,id="1",group-id="i1"
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"
277 -interpreter-exec console kill
281 ^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",func="g"}
286 73-exec-run -ftest.jam
287 =thread-created,id="1",group-id="i1"
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"
292 -interpreter-exec console kill
298 74-exec-run -ftest.jam
299 =thread-created,id="1",group-id="i1"
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"
304 -interpreter-exec console kill
310 75-exec-run -ftest.jam
311 =thread-created,id="1",group-id="i1"
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"