Skip to content

Commit a764a1c

Browse files
bpo-40019: Skip test_gdb if Python was optimized (GH-19081)
test_gdb now skips tests if it detects that gdb failed to read debug information because the Python binary is optimized. (cherry picked from commit 7bf069b) Co-authored-by: Victor Stinner <[email protected]>
1 parent 9073f92 commit a764a1c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Lib/test/test_gdb.py

+9
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ def get_stack_trace(self, source=None, script=None,
227227
" because the Program Counter is"
228228
" not present")
229229

230+
# bpo-40019: Skip the test if gdb failed to read debug information
231+
# because the Python binary is optimized.
232+
for pattern in (
233+
'(frame information optimized out)',
234+
'Unable to read information on python frame',
235+
):
236+
if pattern in out:
237+
raise unittest.SkipTest(f"{pattern!r} found in gdb output")
238+
230239
return out
231240

232241
def get_gdb_repr(self, source,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test_gdb now skips tests if it detects that gdb failed to read debug
2+
information because the Python binary is optimized.

Tools/gdb/libpython.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def _sizeof_void_p():
9999

100100
ENCODING = locale.getpreferredencoding()
101101

102+
FRAME_INFO_OPTIMIZED_OUT = '(frame information optimized out)'
103+
UNABLE_READ_INFO_PYTHON_FRAME = 'Unable to read information on python frame'
102104
EVALFRAME = '_PyEval_EvalFrameDefault'
103105

104106
class NullPyObjectPtr(RuntimeError):
@@ -918,7 +920,7 @@ def get_var_by_name(self, name):
918920
def filename(self):
919921
'''Get the path of the current Python source file, as a string'''
920922
if self.is_optimized_out():
921-
return '(frame information optimized out)'
923+
return FRAME_INFO_OPTIMIZED_OUT
922924
return self.co_filename.proxyval(set())
923925

924926
def current_line_num(self):
@@ -949,7 +951,7 @@ def current_line(self):
949951
'''Get the text of the current source line as a string, with a trailing
950952
newline character'''
951953
if self.is_optimized_out():
952-
return '(frame information optimized out)'
954+
return FRAME_INFO_OPTIMIZED_OUT
953955

954956
lineno = self.current_line_num()
955957
if lineno is None:
@@ -970,7 +972,7 @@ def current_line(self):
970972

971973
def write_repr(self, out, visited):
972974
if self.is_optimized_out():
973-
out.write('(frame information optimized out)')
975+
out.write(FRAME_INFO_OPTIMIZED_OUT)
974976
return
975977
lineno = self.current_line_num()
976978
lineno = str(lineno) if lineno is not None else "?"
@@ -993,7 +995,7 @@ def write_repr(self, out, visited):
993995

994996
def print_traceback(self):
995997
if self.is_optimized_out():
996-
sys.stdout.write(' (frame information optimized out)\n')
998+
sys.stdout.write(' %s\n' % FRAME_INFO_OPTIMIZED_OUT)
997999
return
9981000
visited = set()
9991001
lineno = self.current_line_num()
@@ -1744,7 +1746,7 @@ def invoke(self, args, from_tty):
17441746

17451747
pyop = frame.get_pyop()
17461748
if not pyop or pyop.is_optimized_out():
1747-
print('Unable to read information on python frame')
1749+
print(UNABLE_READ_INFO_PYTHON_FRAME)
17481750
return
17491751

17501752
filename = pyop.filename()
@@ -1904,7 +1906,7 @@ def invoke(self, args, from_tty):
19041906

19051907
pyop_frame = frame.get_pyop()
19061908
if not pyop_frame:
1907-
print('Unable to read information on python frame')
1909+
print(UNABLE_READ_INFO_PYTHON_FRAME)
19081910
return
19091911

19101912
pyop_var, scope = pyop_frame.get_var_by_name(name)
@@ -1938,7 +1940,7 @@ def invoke(self, args, from_tty):
19381940

19391941
pyop_frame = frame.get_pyop()
19401942
if not pyop_frame:
1941-
print('Unable to read information on python frame')
1943+
print(UNABLE_READ_INFO_PYTHON_FRAME)
19421944
return
19431945

19441946
for pyop_name, pyop_value in pyop_frame.iter_locals():

0 commit comments

Comments
 (0)