Skip to content

Commit

Permalink
made gdb pretty-printing script more robust when printing uninitializ…
Browse files Browse the repository at this point in the history
…ed 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.
  • Loading branch information
pnkfelix committed Nov 20, 2019
1 parent 76ade3e commit 9b40e0b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9b40e0b

Please sign in to comment.