Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/TestCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def match_re(lines=None, res=None):
if not type(res) is list:
res = res.split("\n")
for i in range(min(len(lines), len(res))):
if not re.compile("^" + res[i] + "$").search(lines[i]):
if not re.match(res[i] + "$", lines[i]):
return MatchError("Mismatch at line %d\n- %s\n+ %s\n" %
(i+1, res[i], lines[i]))
if len(lines) < len(res):
Expand Down
141 changes: 71 additions & 70 deletions test/debugger-mi.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
#!/usr/bin/env python3

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

# Test the mi interface for the debugger
"""
Test the mi interface for the debugger
"""

import BoostBuild
import TestCmd
import re

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

def escape_line(line):
line = re.sub(outside_pattern, lambda m: re.escape(m.group(0)), line)
if line == '(gdb) ': return r'\(gdb\) '
line = re.sub(outside_pattern, lambda m: m.group(0), line)
return re.sub(r'\{\{|\}\}', '', line)

stdout = '\n'.join([escape_line(line) for line in stdout.split('\n')])
return (stdin,stdout)
return (stdin, stdout)

def run(tester, io):
(input,output) = split_stdin_stdout(io)
(input, output) = split_stdin_stdout(io)
tester.run_build_system(stdin=input, stdout=output, match=TestCmd.match_re)

def make_tester():
return BoostBuild.Tester(["-dmi"], pass_toolset=False, pass_d0=False,
use_test_config=False, ignore_toolset_requirements=False, match=TestCmd.match_re)
return BoostBuild.Tester(["-dmi"], pass_toolset=False)


def test_exec_run():
t = make_tester()
t.write("test.jam", """\
UPDATE ;
""")

run(t, """\
=thread-group-added,id="i1"
(gdb)
72-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
72^running
72\\^running
(gdb)
*stopped,reason="exited-normally"
\\*stopped,reason="exited-normally"
(gdb)
73-gdb-exit
73^exit
73\\^exit
""")

t.cleanup()

def test_exit_status():
Expand All @@ -66,13 +67,13 @@ def test_exit_status():
(gdb)
72-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
72^running
72\\^running
(gdb)

*stopped,reason="exited",exit-code="1"
\\*stopped,reason="exited",exit-code="1"
(gdb)
73-gdb-exit
73^exit
73\\^exit
""")
t.cleanup()

Expand All @@ -95,31 +96,31 @@ def test_exec_step():
=thread-group-added,id="i1"
(gdb)
-break-insert f
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
(gdb)
72-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
72^running
72\\^running
(gdb)
*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"
\\*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"
(gdb)
1-exec-step
1^running
1\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="3"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="3"},thread-id="1"
(gdb)
2-exec-step
2^running
2\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="4"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="4"},thread-id="1"
(gdb)
3-exec-step
3^running
3\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="9"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="9"},thread-id="1"
(gdb)
73-gdb-exit
73^exit
73\\^exit
""")
t.cleanup()

Expand Down Expand Up @@ -148,36 +149,36 @@ def test_exec_next():
=thread-group-added,id="i1"
(gdb)
-break-insert f
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
(gdb)
72-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
72^running
72\\^running
(gdb)
*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"
\\*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"
(gdb)
1-exec-next
1^running
1\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="8"},thread-id="1"
(gdb)
2-exec-next
2^running
2\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="f",args=[],file="test.jam",fullname="{{.*}}test.jam",line="9"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="f",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="9"},thread-id="1"
(gdb)
3-exec-next
3^running
3\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="h",args=[],file="test.jam",fullname="{{.*}}test.jam",line="14"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="h",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="14"},thread-id="1"
(gdb)
4-exec-next
4^running
4\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="module scope",args=[],file="test.jam",fullname="{{.*}}test.jam",line="17"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="module scope",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="17"},thread-id="1"
(gdb)
73-gdb-exit
73^exit
73\\^exit
""")
t.cleanup()

Expand Down Expand Up @@ -210,35 +211,34 @@ def test_exec_finish():
=thread-group-added,id="i1"
(gdb)
-break-insert f
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
(gdb)
72-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
72^running
72\\^running
(gdb)
*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"
\\*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"
(gdb)
1-exec-finish
1^running
1\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="g",args=[],file="test.jam",fullname="{{.*}}test.jam",line="8"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="g",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="8"},thread-id="1"
(gdb)
2-exec-finish
2^running
2\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="h",args=[],file="test.jam",fullname="{{.*}}test.jam",line="14"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="h",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="14"},thread-id="1"
(gdb)
3-exec-finish
3^running
3\\^running
(gdb)
*stopped,reason="end-stepping-range",frame={func="module scope",args=[],file="test.jam",fullname="{{.*}}test.jam",line="21"},thread-id="1"
\\*stopped,reason="end-stepping-range",frame={func="module scope",args=\\[\\],file="test.jam",fullname="{{.+}}test.jam",line="21"},thread-id="1"
(gdb)
73-gdb-exit
73^exit
73\\^exit
""")
t.cleanup()


def test_breakpoints():
"""Tests the interaction between the following commands:
break, clear, delete, disable, enable"""
Expand Down Expand Up @@ -266,58 +266,59 @@ def test_breakpoints():
=thread-group-added,id="i1"
(gdb)
-break-insert f
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
\\^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",func="f"}
(gdb)
72-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
72^running
72\\^running
(gdb)
*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"
\\*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"
(gdb)
-interpreter-exec console kill
^done
\\^done
(gdb)
-break-insert g
^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",func="g"}
\\^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",func="g"}
(gdb)
-break-disable 1
^done
\\^done
(gdb)
73-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
73^running
73\\^running
(gdb)
*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"
\\*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"
(gdb)
-interpreter-exec console kill
^done
\\^done
(gdb)
-break-enable 1
^done
\\^done
(gdb)
74-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
74^running
74\\^running
(gdb)
*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"
\\*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"
(gdb)
-interpreter-exec console kill
^done
\\^done
(gdb)
-break-delete 1
^done
\\^done
(gdb)
75-exec-run -ftest.jam
=thread-created,id="1",group-id="i1"
75^running
75\\^running
(gdb)
*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"
\\*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"
(gdb)
76-gdb-exit
76^exit
76\\^exit
""")
t.cleanup()


test_exec_run()
test_exit_status()
test_exec_step()
Expand Down
Loading