Skip to content

Commit 451b2d6

Browse files
committed
Testsuite: allow multiple GDB sessions in the same testcase
Change-Id: I789520511bfcaa5d094c90d376539887b29a154e TN: RC14-025
1 parent f0c2c1e commit 451b2d6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

testsuite/support/gdb.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, program=None, log_file=None, load_gnatdbg=True):
2929
os.environ['TERM'] = 'dumb'
3030

3131
self.proc = ExpectProcess(argv, save_input=True, save_output=True)
32+
self.alive = True
3233
_ = self._read_to_next_prompt()
3334

3435
# If code coverage is enabled, start it before loading gnatdbg
@@ -38,7 +39,9 @@ def __init__(self, program=None, log_file=None, load_gnatdbg=True):
3839
rcfile = os.environ['COVERAGE_RCFILE']
3940
self.import_coverage()
4041
self.execute('''python
41-
_cov = coverage.Coverage(data_file={data_file!r}, config_file={config_file!r})
42+
_cov = coverage.Coverage(data_file={data_file!r},
43+
config_file={config_file!r},
44+
auto_data=True)
4245
_cov.start()
4346
end'''.format(
4447
data_file=datafile,
@@ -96,6 +99,7 @@ def _read_to_next_prompt(self):
9699
97100
:rtype: str
98101
"""
102+
assert self.alive
99103
status = self.proc.expect([self.PROMPT_RE], self.TIMEOUT)
100104
if status is EXPECT_DIED:
101105
raise RuntimeError('GDB died')
@@ -121,6 +125,7 @@ def test(self, command, expected_output):
121125
output. Otherwise, it must be a quotemeta expression that must
122126
match the output.
123127
"""
128+
assert self.alive
124129
assert self.proc.send(command)
125130
output = self._read_to_next_prompt().strip().replace('\r', '')
126131
matcher = convert_expression(expected_output)
@@ -175,10 +180,24 @@ def run_to(self, location):
175180
self.execute('tbreak {}'.format(location))
176181
self.execute('run')
177182

178-
def __del__(self):
183+
def stop(self):
184+
"""
185+
Stop GDB.
186+
187+
This writes session logs to make post-mortem debugging.
188+
"""
189+
if not self.alive:
190+
return
191+
179192
if self.coverage_enabled:
180193
self.execute('python _cov.stop(); _cov.save()')
194+
self.alive = False
195+
181196
# No matter what, write the session logs to make post-mortem debugging
182197
# possible.
183198
with open(self.log_file, 'w') as f:
184199
f.write(self.proc.get_session_logs())
200+
201+
def __del__(self):
202+
if self.alive:
203+
self.stop()

0 commit comments

Comments
 (0)