Add GDB pretty-printer for OsString
This commit is contained in:
parent
c7ef85ca0e
commit
c1f687b73f
3 changed files with 37 additions and 2 deletions
|
@ -46,6 +46,7 @@ TYPE_KIND_CSTYLE_ENUM = 14
|
|||
TYPE_KIND_PTR = 15
|
||||
TYPE_KIND_FIXED_SIZE_VEC = 16
|
||||
TYPE_KIND_REGULAR_UNION = 17
|
||||
TYPE_KIND_OS_STRING = 18
|
||||
|
||||
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
|
||||
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
|
||||
|
@ -64,6 +65,9 @@ STD_VEC_FIELD_NAMES = [STD_VEC_FIELD_NAME_BUF,
|
|||
# std::String related constants
|
||||
STD_STRING_FIELD_NAMES = ["vec"]
|
||||
|
||||
# std::ffi::OsString related constants
|
||||
OS_STRING_FIELD_NAMES = ["inner"]
|
||||
|
||||
|
||||
class Type(object):
|
||||
"""
|
||||
|
@ -162,6 +166,11 @@ class Type(object):
|
|||
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
|
||||
return TYPE_KIND_STD_STRING
|
||||
|
||||
# OS STRING
|
||||
if (unqualified_type_name == "OsString" and
|
||||
self.__conforms_to_field_layout(OS_STRING_FIELD_NAMES)):
|
||||
return TYPE_KIND_OS_STRING
|
||||
|
||||
# ENUM VARIANTS
|
||||
if fields[0].name == ENUM_DISR_FIELD_NAME:
|
||||
if field_count == 1:
|
||||
|
|
|
@ -125,6 +125,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
|
|||
if type_kind == rustpp.TYPE_KIND_STD_STRING:
|
||||
return RustStdStringPrinter(val)
|
||||
|
||||
if type_kind == rustpp.TYPE_KIND_OS_STRING:
|
||||
return RustOsStringPrinter(val)
|
||||
|
||||
if type_kind == rustpp.TYPE_KIND_TUPLE:
|
||||
return RustStructPrinter(val,
|
||||
omit_first_field = False,
|
||||
|
@ -269,6 +272,21 @@ class RustStdStringPrinter(object):
|
|||
length=length)
|
||||
|
||||
|
||||
class RustOsStringPrinter(object):
|
||||
def __init__(self, val):
|
||||
self.__val = val
|
||||
|
||||
def to_string(self):
|
||||
buf = self.__val.get_child_at_index(0)
|
||||
vec = buf.get_child_at_index(0)
|
||||
if vec.type.get_unqualified_type_name() == "Wtf8Buf":
|
||||
vec = vec.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(length=length)
|
||||
|
||||
|
||||
class RustCStyleVariantPrinter(object):
|
||||
def __init__(self, val):
|
||||
assert val.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_ENUM
|
||||
|
|
|
@ -38,8 +38,11 @@
|
|||
// gdbg-check:$6 = None
|
||||
// gdbr-check:$6 = core::option::Option::None
|
||||
|
||||
// gdb-command: print some_string
|
||||
// gdbr-check:$7 = Some = {"IAMA optional string!"}
|
||||
// gdbr-command: print os_string
|
||||
// gdbr-check:$7 = "IAMA OS string 😃"
|
||||
|
||||
// gdbr-command: print some_string
|
||||
// gdbr-check:$8 = Some = {"IAMA optional string!"}
|
||||
|
||||
|
||||
// === LLDB TESTS ==================================================================================
|
||||
|
@ -66,6 +69,8 @@
|
|||
|
||||
|
||||
#![allow(unused_variables)]
|
||||
use std::ffi::OsString;
|
||||
|
||||
|
||||
fn main() {
|
||||
|
||||
|
@ -81,6 +86,9 @@ fn main() {
|
|||
// String
|
||||
let string = "IAMA string!".to_string();
|
||||
|
||||
// OsString
|
||||
let os_string = OsString::from("IAMA OS string \u{1F603}");
|
||||
|
||||
// Option
|
||||
let some = Some(8i16);
|
||||
let none: Option<i64> = None;
|
||||
|
|
Loading…
Add table
Reference in a new issue