From d4ab05479c9c956b10d7ef5ad113181f04a96495 Mon Sep 17 00:00:00 2001 From: Marcel Plch Date: Thu, 10 May 2018 17:03:42 +0200 Subject: [PATCH 1/3] bpo-32962: Fix test_gdb when built with gcc 8 new protection flags. (GH-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. --- Lib/test/test_gdb.py | 6 ++++-- .../next/Tests/2018-05-10-16-59-15.bpo-32962.S-rcIN.rst | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2018-05-10-16-59-15.bpo-32962.S-rcIN.rst diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index 9e0eaea8c8f692..37978531ed338e 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -162,7 +162,7 @@ def get_stack_trace(self, source=None, script=None, commands += ['set print entry-values no'] if cmds_after_breakpoint: - commands += cmds_after_breakpoint + commands += ['next'] + cmds_after_breakpoint else: commands += ['backtrace'] @@ -202,6 +202,8 @@ def get_stack_trace(self, source=None, script=None, 'BFD: ', # ignore all warnings 'warning: ', + # See #32962 + 'Python Exception', ) for line in errlines: if not line: @@ -849,7 +851,7 @@ def __init__(self): ''') # Verify with "py-bt": gdb_output = self.get_stack_trace(cmd, - cmds_after_breakpoint=['break wrapper_call', 'continue', 'py-bt']) + cmds_after_breakpoint=['break wrapper_call', 'continue', 'next', 'py-bt']) self.assertRegex(gdb_output, r" Date: Fri, 15 Jun 2018 14:36:09 +0200 Subject: [PATCH 2/3] Add comments and revert exception ignore in test_gdb. --- Lib/test/test_gdb.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index 37978531ed338e..19e1954b7cc15d 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -161,6 +161,9 @@ def get_stack_trace(self, source=None, script=None, if (gdb_major_version, gdb_minor_version) >= (7, 4): commands += ['set print entry-values no'] + # bpo-32962: When Python is compiled with -mcet -fcf-protection, + # arguments are unusable before running the first instruction + # of the function entry point. Next makes the required first step. if cmds_after_breakpoint: commands += ['next'] + cmds_after_breakpoint else: @@ -202,8 +205,6 @@ def get_stack_trace(self, source=None, script=None, 'BFD: ', # ignore all warnings 'warning: ', - # See #32962 - 'Python Exception', ) for line in errlines: if not line: @@ -849,6 +850,9 @@ def __init__(self): id("first break point") l = MyList() ''') + # bpo-32962: same case as in get_stack_trace(): + # we need one extra step in order to read arguments + # of the innermost function of the call stack. # Verify with "py-bt": gdb_output = self.get_stack_trace(cmd, cmds_after_breakpoint=['break wrapper_call', 'continue', 'next', 'py-bt']) From 6266c3413d0699615328fc94a2904333a3e38379 Mon Sep 17 00:00:00 2001 From: Marcel Plch Date: Fri, 15 Jun 2018 16:45:13 +0200 Subject: [PATCH 3/3] Improve clarity of new comments --- Lib/test/test_gdb.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index 19e1954b7cc15d..d341a17f1fec80 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -161,10 +161,11 @@ def get_stack_trace(self, source=None, script=None, if (gdb_major_version, gdb_minor_version) >= (7, 4): commands += ['set print entry-values no'] - # bpo-32962: When Python is compiled with -mcet -fcf-protection, - # arguments are unusable before running the first instruction - # of the function entry point. Next makes the required first step. if cmds_after_breakpoint: + # bpo-32962: When Python is compiled with -mcet -fcf-protection, + # arguments are unusable before running the first instruction + # of the function entry point. The 'next' command makes the + # required first step. commands += ['next'] + cmds_after_breakpoint else: commands += ['backtrace'] @@ -851,8 +852,8 @@ def __init__(self): l = MyList() ''') # bpo-32962: same case as in get_stack_trace(): - # we need one extra step in order to read arguments - # of the innermost function of the call stack. + # we need an additional 'next' command in order to read + # arguments of the innermost function of the call stack. # Verify with "py-bt": gdb_output = self.get_stack_trace(cmd, cmds_after_breakpoint=['break wrapper_call', 'continue', 'next', 'py-bt'])