From 9b40e0bb9af6641a23586fd5999430e4c7622636 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 20 Nov 2019 16:37:17 +0100 Subject: [PATCH] made gdb pretty-printing script more robust when printing uninitialized vec. I based this solution on my reading of: https://rethinkdb.com/blog/make-debugging-easier-with-custom-pretty-printers#what-is-still-to-be-done That post claims that there is no clean way to check for garbage pointers, and so this PR adopts the same solution of tentatively attempting to convert a dererence to a string, which throws a clean exception on garbage that we can catch and recover from. I only made the change to vec and not the other pretty printers because I wanted to focus my effort on the simplest thing that would resolve issue #64343. In particular, I *considered* generalizing this fix to work on the other datatypes in the pretty-printing support library, but I don't want to invest effort in that until after we resolve our overall debugging support strategy; see also issues #60826 and #65564. --- src/etc/gdb_rust_pretty_printing.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index a6b09722e1c94..5da01b96fa5e3 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -284,10 +284,20 @@ def to_string(self): ("(len: %i, cap: %i)" % (length, cap))) def children(self): + saw_inaccessible = False (length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(self.__val) gdb_ptr = data_ptr.get_wrapped_value() for index in xrange(0, length): - yield (str(index), (gdb_ptr + index).dereference()) + if saw_inaccessible: + return + try: + # rust-lang/rust#64343: passing deref expr to `str` allows + # catching exception on garbage pointer + str((gdb_ptr + index).dereference()) + yield (str(index), (gdb_ptr + index).dereference()) + except RuntimeError: + saw_inaccessible = True + yield (str(index), "inaccessible") class RustStdVecDequePrinter(object):