bpo-32962: Fix test_gdb failure in debug build with -mcet -fcf-protec… · python/cpython@79d2133 (original) (raw)
`@@ -54,6 +54,23 @@ def get_gdb_version():
`
54
54
``
55
55
`PYTHONHASHSEED = '123'
`
56
56
``
``
57
+
``
58
`+
def cet_protection():
`
``
59
`+
cflags = sysconfig.get_config_var('CFLAGS')
`
``
60
`+
if not cflags:
`
``
61
`+
return False
`
``
62
`+
flags = cflags.split()
`
``
63
`+
True if "-mcet -fcf-protection" options are found, but false
`
``
64
`+
if "-fcf-protection=none" or "-fcf-protection=return" is found.
`
``
65
`+
return (('-mcet' in flags)
`
``
66
`+
and any((flag.startswith('-fcf-protection')
`
``
67
`+
and not flag.endswith(("=none", "=return")))
`
``
68
`+
for flag in flags))
`
``
69
+
``
70
`+
Control-flow enforcement technology
`
``
71
`+
CET_PROTECTION = cet_protection()
`
``
72
+
``
73
+
57
74
`def run_gdb(*args, **env_vars):
`
58
75
`"""Runs gdb in --batch mode with the additional arguments given by *args.
`
59
76
``
`@@ -162,6 +179,12 @@ def get_stack_trace(self, source=None, script=None,
`
162
179
`commands += ['set print entry-values no']
`
163
180
``
164
181
`if cmds_after_breakpoint:
`
``
182
`+
if CET_PROTECTION:
`
``
183
`+
bpo-32962: When Python is compiled with -mcet
`
``
184
`+
-fcf-protection, function arguments are unusable before
`
``
185
`+
running the first instruction of the function entry point.
`
``
186
`+
The 'next' command makes the required first step.
`
``
187
`+
commands += ['next']
`
165
188
`commands += cmds_after_breakpoint
`
166
189
`else:
`
167
190
`commands += ['backtrace']
`
`@@ -869,9 +892,17 @@ def init(self):
`
869
892
` id("first break point")
`
870
893
` l = MyList()
`
871
894
` ''')
`
``
895
`+
cmds_after_breakpoint = ['break wrapper_call', 'continue']
`
``
896
`+
if CET_PROTECTION:
`
``
897
`+
bpo-32962: same case as in get_stack_trace():
`
``
898
`+
we need an additional 'next' command in order to read
`
``
899
`+
arguments of the innermost function of the call stack.
`
``
900
`+
cmds_after_breakpoint.append('next')
`
``
901
`+
cmds_after_breakpoint.append('py-bt')
`
``
902
+
872
903
`# Verify with "py-bt":
`
873
904
`gdb_output = self.get_stack_trace(cmd,
`
874
``
`-
cmds_after_breakpoint=['break wrapper_call', 'continue', 'py-bt'])
`
``
905
`+
cmds_after_breakpoint=cmds_after_breakpoint)
`
875
906
`self.assertRegex(gdb_output,
`
876
907
`r"<method-wrapper u?'init' of MyList object at ")
`
877
908
``