From af0244b81f8956bce167b9e558ea62c376c7625e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 14 Jun 2018 16:28:07 +0200 Subject: [PATCH 1/3] bpo-32962: python-gdb catchs ValueError on read_var() (GH-7692) python-gdb now catchs ValueError on read_var(): when Python has no debug symbols for example. (cherry picked from commit 019d33b7a447e78057842332fb5d3bad01922122) --- .../2018-06-14-16-16-53.bpo-32962.2YfdwI.rst | 2 ++ Tools/gdb/libpython.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-16-53.bpo-32962.2YfdwI.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-16-53.bpo-32962.2YfdwI.rst b/Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-16-53.bpo-32962.2YfdwI.rst new file mode 100644 index 000000000000000..de40070795e9531 --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-16-53.bpo-32962.2YfdwI.rst @@ -0,0 +1,2 @@ +python-gdb now catchs ValueError on read_var(): when Python has no debug +symbols for example. diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 7df7c9bd541672f..41cbba2f10f351c 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1552,15 +1552,22 @@ def is_other_python_frame(self): # Use the prettyprinter for the func: func = frame.read_var(arg_name) return str(func) + except ValueError: + return ('PyCFunction invocation (unable to read %s: ' + 'missing debuginfos?)' % arg_name) except RuntimeError: return 'PyCFunction invocation (unable to read %s)' % arg_name if caller == 'wrapper_call': + arg_name = 'wp' try: - func = frame.read_var('wp') + func = frame.read_var(arg_name) return str(func) + except ValueError: + return ('' % arg_name) except RuntimeError: - return '' + return '' % arg_name # This frame isn't worth reporting: return False From f34bce8ee655c3b68d0520d62e6b1df991598ac6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 14 Jun 2018 22:34:52 +0200 Subject: [PATCH 2/3] bpo-32962: python-gdb catchs UnicodeDecodeError (GH-7693) python-gdb now catchs UnicodeDecodeError exceptions when calling string(). (cherry picked from commit d22fc0bc7de7882da204abe50884bbde2da4f9e7) --- .../2018-06-14-16-23-07.bpo-32962.Q3Dwns.rst | 2 ++ Tools/gdb/libpython.py | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-23-07.bpo-32962.Q3Dwns.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-23-07.bpo-32962.Q3Dwns.rst b/Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-23-07.bpo-32962.Q3Dwns.rst new file mode 100644 index 000000000000000..fc14261019a03fb --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2018-06-14-16-23-07.bpo-32962.Q3Dwns.rst @@ -0,0 +1,2 @@ +python-gdb now catchs ``UnicodeDecodeError`` exceptions when calling +``string()``. diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 41cbba2f10f351c..27eabcb0d3d0916 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -270,12 +270,13 @@ def is_optimized_out(self): def safe_tp_name(self): try: - return self.type().field('tp_name').string() - except NullPyObjectPtr: - # NULL tp_name? - return 'unknown' - except RuntimeError: - # Can't even read the object at all? + ob_type = self.type() + tp_name = ob_type.field('tp_name') + return tp_name.string() + # NullPyObjectPtr: NULL tp_name? + # RuntimeError: Can't even read the object at all? + # UnicodeDecodeError: Failed to decode tp_name bytestring + except (NullPyObjectPtr, RuntimeError, UnicodeDecodeError): return 'unknown' def proxyval(self, visited): @@ -349,7 +350,9 @@ def subclass_from_type(cls, t): try: tp_name = t.field('tp_name').string() tp_flags = int(t.field('tp_flags')) - except RuntimeError: + # RuntimeError: NULL pointers + # UnicodeDecodeError: string() fails to decode the bytestring + except (RuntimeError, UnicodeDecodeError): # Handle any kind of error e.g. NULL ptrs by simply using the base # class return cls @@ -617,7 +620,10 @@ class PyCFunctionObjectPtr(PyObjectPtr): def proxyval(self, visited): m_ml = self.field('m_ml') # m_ml is a (PyMethodDef*) - ml_name = m_ml['ml_name'].string() + try: + ml_name = m_ml['ml_name'].string() + except UnicodeDecodeError: + ml_name = '' pyop_m_self = self.pyop_field('m_self') if pyop_m_self.is_null(): @@ -1340,13 +1346,13 @@ def safe_name(self): try: name = self.field('descr')['d_base']['name'].string() return repr(name) - except (NullPyObjectPtr, RuntimeError): + except (NullPyObjectPtr, RuntimeError, UnicodeDecodeError): return '' def safe_tp_name(self): try: return self.field('self')['ob_type']['tp_name'].string() - except (NullPyObjectPtr, RuntimeError): + except (NullPyObjectPtr, RuntimeError, UnicodeDecodeError): return '' def safe_self_addresss(self): From a872f41af4a6e8de0d5041fa5e3f3798d0ea26d3 Mon Sep 17 00:00:00 2001 From: Marcel Plch Date: Fri, 15 Jun 2018 17:56:24 +0200 Subject: [PATCH 3/3] 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. (cherry picked from commit 9b7c74ca32d1bec7128d550a9ab1b2ddc7046287) --- Lib/test/test_gdb.py | 11 +++++++++-- .../Tests/2018-05-10-16-59-15.bpo-32962.S-rcIN.rst | 1 + 2 files changed, 10 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 9e0eaea8c8f6921..d341a17f1fec80f 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -162,7 +162,11 @@ def get_stack_trace(self, source=None, script=None, commands += ['set print entry-values no'] if cmds_after_breakpoint: - commands += 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'] @@ -847,9 +851,12 @@ def __init__(self): id("first break point") l = MyList() ''') + # bpo-32962: same case as in get_stack_trace(): + # 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', 'py-bt']) + cmds_after_breakpoint=['break wrapper_call', 'continue', 'next', 'py-bt']) self.assertRegex(gdb_output, r"