@@ -29,6 +29,7 @@ def __init__(self, program=None, log_file=None, load_gnatdbg=True):
29
29
os .environ ['TERM' ] = 'dumb'
30
30
31
31
self .proc = ExpectProcess (argv , save_input = True , save_output = True )
32
+ self .alive = True
32
33
_ = self ._read_to_next_prompt ()
33
34
34
35
# 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):
38
39
rcfile = os .environ ['COVERAGE_RCFILE' ]
39
40
self .import_coverage ()
40
41
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)
42
45
_cov.start()
43
46
end''' .format (
44
47
data_file = datafile ,
@@ -96,6 +99,7 @@ def _read_to_next_prompt(self):
96
99
97
100
:rtype: str
98
101
"""
102
+ assert self .alive
99
103
status = self .proc .expect ([self .PROMPT_RE ], self .TIMEOUT )
100
104
if status is EXPECT_DIED :
101
105
raise RuntimeError ('GDB died' )
@@ -121,6 +125,7 @@ def test(self, command, expected_output):
121
125
output. Otherwise, it must be a quotemeta expression that must
122
126
match the output.
123
127
"""
128
+ assert self .alive
124
129
assert self .proc .send (command )
125
130
output = self ._read_to_next_prompt ().strip ().replace ('\r ' , '' )
126
131
matcher = convert_expression (expected_output )
@@ -175,10 +180,24 @@ def run_to(self, location):
175
180
self .execute ('tbreak {}' .format (location ))
176
181
self .execute ('run' )
177
182
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
+
179
192
if self .coverage_enabled :
180
193
self .execute ('python _cov.stop(); _cov.save()' )
194
+ self .alive = False
195
+
181
196
# No matter what, write the session logs to make post-mortem debugging
182
197
# possible.
183
198
with open (self .log_file , 'w' ) as f :
184
199
f .write (self .proc .get_session_logs ())
200
+
201
+ def __del__ (self ):
202
+ if self .alive :
203
+ self .stop ()
0 commit comments