Skip to content

Commit

Permalink
Rollup merge of rust-lang#66576 - pnkfelix:more-robust-gdb-vec-printe…
Browse files Browse the repository at this point in the history
…r, r=alexcrichton

made gdb pretty-printing more robust when printing uninitialized vec

made gdb pretty-printing 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 rust-lang#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 rust-lang#60826 and rust-lang#65564.

Fix rust-lang#64343
  • Loading branch information
pietroalbini authored Nov 22, 2019
2 parents e3590d5 + 9b40e0b commit 07ddc51
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 07ddc51

Please sign in to comment.