Skip to content

Commit c1f687b

Browse files
committed
Add GDB pretty-printer for OsString
1 parent c7ef85c commit c1f687b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/etc/debugger_pretty_printers_common.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
TYPE_KIND_PTR = 15
4747
TYPE_KIND_FIXED_SIZE_VEC = 16
4848
TYPE_KIND_REGULAR_UNION = 17
49+
TYPE_KIND_OS_STRING = 18
4950

5051
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
5152
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
@@ -64,6 +65,9 @@
6465
# std::String related constants
6566
STD_STRING_FIELD_NAMES = ["vec"]
6667

68+
# std::ffi::OsString related constants
69+
OS_STRING_FIELD_NAMES = ["inner"]
70+
6771

6872
class Type(object):
6973
"""
@@ -162,6 +166,11 @@ def __classify_struct(self):
162166
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
163167
return TYPE_KIND_STD_STRING
164168

169+
# OS STRING
170+
if (unqualified_type_name == "OsString" and
171+
self.__conforms_to_field_layout(OS_STRING_FIELD_NAMES)):
172+
return TYPE_KIND_OS_STRING
173+
165174
# ENUM VARIANTS
166175
if fields[0].name == ENUM_DISR_FIELD_NAME:
167176
if field_count == 1:

src/etc/gdb_rust_pretty_printing.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
125125
if type_kind == rustpp.TYPE_KIND_STD_STRING:
126126
return RustStdStringPrinter(val)
127127

128+
if type_kind == rustpp.TYPE_KIND_OS_STRING:
129+
return RustOsStringPrinter(val)
130+
128131
if type_kind == rustpp.TYPE_KIND_TUPLE:
129132
return RustStructPrinter(val,
130133
omit_first_field = False,
@@ -269,6 +272,21 @@ def to_string(self):
269272
length=length)
270273

271274

275+
class RustOsStringPrinter(object):
276+
def __init__(self, val):
277+
self.__val = val
278+
279+
def to_string(self):
280+
buf = self.__val.get_child_at_index(0)
281+
vec = buf.get_child_at_index(0)
282+
if vec.type.get_unqualified_type_name() == "Wtf8Buf":
283+
vec = vec.get_child_at_index(0)
284+
285+
(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(
286+
vec)
287+
return '"%s"' % data_ptr.get_wrapped_value().string(length=length)
288+
289+
272290
class RustCStyleVariantPrinter(object):
273291
def __init__(self, val):
274292
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_ENUM

src/test/debuginfo/pretty-std.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
// gdbg-check:$6 = None
3939
// gdbr-check:$6 = core::option::Option::None
4040

41-
// gdb-command: print some_string
42-
// gdbr-check:$7 = Some = {"IAMA optional string!"}
41+
// gdbr-command: print os_string
42+
// gdbr-check:$7 = "IAMA OS string 😃"
43+
44+
// gdbr-command: print some_string
45+
// gdbr-check:$8 = Some = {"IAMA optional string!"}
4346

4447

4548
// === LLDB TESTS ==================================================================================
@@ -66,6 +69,8 @@
6669

6770

6871
#![allow(unused_variables)]
72+
use std::ffi::OsString;
73+
6974

7075
fn main() {
7176

@@ -81,6 +86,9 @@ fn main() {
8186
// String
8287
let string = "IAMA string!".to_string();
8388

89+
// OsString
90+
let os_string = OsString::from("IAMA OS string \u{1F603}");
91+
8492
// Option
8593
let some = Some(8i16);
8694
let none: Option<i64> = None;

0 commit comments

Comments
 (0)