Skip to content

Commit

Permalink
Implement display_hint in gdb pretty printers
Browse files Browse the repository at this point in the history
A few pretty-printers were returning a quoted string from their
to_string method.  It's preferable in gdb to return a lazy string and to
let gdb handle the display by having a "display_hint" method that
returns "string" -- it lets gdb settings (like "set print ...") work, it
handles corrupted strings a bit better, and it passes the information
along to IDEs.
  • Loading branch information
tromey committed Oct 6, 2017
1 parent a8feaee commit c3c1df5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ def __init__(self, val):
def to_string(self):
(length, data_ptr) = rustpp.extract_length_and_ptr_from_slice(self.__val)
raw_ptr = data_ptr.get_wrapped_value()
return '"%s"' % raw_ptr.string(encoding="utf-8", length=length)
return raw_ptr.lazy_string(encoding="utf-8", length=length)

def display_hint(self):
return "string"


class RustStdVecPrinter(object):
Expand Down Expand Up @@ -278,9 +281,11 @@ def __init__(self, val):
def to_string(self):
vec = self.__val.get_child_at_index(0)
(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(vec)
return '"%s"' % data_ptr.get_wrapped_value().string(encoding="utf-8",
length=length)
return data_ptr.get_wrapped_value().lazy_string(encoding="utf-8",
length=length)

def display_hint(self):
return "string"

class RustOsStringPrinter(object):
def __init__(self, val):
Expand All @@ -294,8 +299,10 @@ def to_string(self):

(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(
vec)
return '"%s"' % data_ptr.get_wrapped_value().string(length=length)
return data_ptr.get_wrapped_value().lazy_string(length=length)

def display_hint(self):
return "string"

class RustCStyleVariantPrinter(object):
def __init__(self, val):
Expand Down
4 changes: 4 additions & 0 deletions src/test/debuginfo/pretty-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
// gdb-command: print some_string
// gdb-check:$8 = Some = {"IAMA optional string!"}

// gdb-command: set print length 5
// gdb-command: print some_string
// gdb-check:$8 = Some = {"IAMA "...}


// === LLDB TESTS ==================================================================================

Expand Down

0 comments on commit c3c1df5

Please sign in to comment.