Skip to content

Commit 07ddc51

Browse files
authored
Rollup merge of rust-lang#66576 - pnkfelix:more-robust-gdb-vec-printer, 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
2 parents e3590d5 + 9b40e0b commit 07ddc51

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/etc/gdb_rust_pretty_printing.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,20 @@ def to_string(self):
284284
("(len: %i, cap: %i)" % (length, cap)))
285285

286286
def children(self):
287+
saw_inaccessible = False
287288
(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(self.__val)
288289
gdb_ptr = data_ptr.get_wrapped_value()
289290
for index in xrange(0, length):
290-
yield (str(index), (gdb_ptr + index).dereference())
291+
if saw_inaccessible:
292+
return
293+
try:
294+
# rust-lang/rust#64343: passing deref expr to `str` allows
295+
# catching exception on garbage pointer
296+
str((gdb_ptr + index).dereference())
297+
yield (str(index), (gdb_ptr + index).dereference())
298+
except RuntimeError:
299+
saw_inaccessible = True
300+
yield (str(index), "inaccessible")
291301

292302

293303
class RustStdVecDequePrinter(object):

0 commit comments

Comments
 (0)