Skip to content

Commit 9b7c74c

Browse files
Marcel Plchvstinner
authored andcommitted
bpo-32962: Fix test_gdb failure in debug build with -mcet -fcf-protection -O0 (#6754)
When Python is built with the intel control-flow protection flags, -mcet -fcf-protection, gdb is not able to read the stack without actually jumping inside the function. This means an extra 'next' command is required to make the $pc (program counter) enter the function and make the stack of the function exposed to gdb.
1 parent c1897ed commit 9b7c74c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Lib/test/test_gdb.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def get_stack_trace(self, source=None, script=None,
162162
commands += ['set print entry-values no']
163163

164164
if cmds_after_breakpoint:
165-
commands += cmds_after_breakpoint
165+
# bpo-32962: When Python is compiled with -mcet -fcf-protection,
166+
# arguments are unusable before running the first instruction
167+
# of the function entry point. The 'next' command makes the
168+
# required first step.
169+
commands += ['next'] + cmds_after_breakpoint
166170
else:
167171
commands += ['backtrace']
168172

@@ -847,9 +851,12 @@ def __init__(self):
847851
id("first break point")
848852
l = MyList()
849853
''')
854+
# bpo-32962: same case as in get_stack_trace():
855+
# we need an additional 'next' command in order to read
856+
# arguments of the innermost function of the call stack.
850857
# Verify with "py-bt":
851858
gdb_output = self.get_stack_trace(cmd,
852-
cmds_after_breakpoint=['break wrapper_call', 'continue', 'py-bt'])
859+
cmds_after_breakpoint=['break wrapper_call', 'continue', 'next', 'py-bt'])
853860
self.assertRegex(gdb_output,
854861
r"<method-wrapper u?'__init__' of MyList object at ")
855862

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed test_gdb when Python is compiled with flags -mcet -fcf-protection -O0.

0 commit comments

Comments
 (0)