about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNathan Henrie <nate@n8henrie.com>2024-02-01 09:08:52 -0700
committerNathan Henrie <nate@n8henrie.com>2024-03-29 18:02:26 -0600
commit41e97a0a3f5c60c24547c849cee03681983b8471 (patch)
tree275b367492a1a1444e2ad2ea35d8d3d31f088100
parent45796d1c24445b298567752519471cef2cff3298 (diff)
downloadrust-41e97a0a3f5c60c24547c849cee03681983b8471.tar.gz
rust-41e97a0a3f5c60c24547c849cee03681983b8471.zip
Add rust-lldb pretty printing for Path and PathBuf
Fixes https://github.com/rust-lang/rust/issues/120553
Fixes https://github.com/rust-lang/rust/issues/48462
-rw-r--r--src/etc/lldb_commands3
-rw-r--r--src/etc/lldb_lookup.py5
-rw-r--r--src/etc/lldb_providers.py29
-rw-r--r--src/etc/rust_types.py6
-rw-r--r--tests/debuginfo/path.rs29
5 files changed, 72 insertions, 0 deletions
diff --git a/src/etc/lldb_commands b/src/etc/lldb_commands
index 615d13ccd0f..4be2dba34f6 100644
--- a/src/etc/lldb_commands
+++ b/src/etc/lldb_commands
@@ -16,4 +16,7 @@ type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)R
 type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
 type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
 type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust
+type summary add -F lldb_lookup.summary_lookup  -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
+type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::([a-z_]+::)+)PathBuf$" --category Rust
+type summary add -F lldb_lookup.summary_lookup  -e -x -h "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
 type category enable Rust
diff --git a/src/etc/lldb_lookup.py b/src/etc/lldb_lookup.py
index 36c7d82b34a..a93b42e1cc4 100644
--- a/src/etc/lldb_lookup.py
+++ b/src/etc/lldb_lookup.py
@@ -58,6 +58,11 @@ def summary_lookup(valobj, dict):
     if rust_type == RustType.STD_NONZERO_NUMBER:
         return StdNonZeroNumberSummaryProvider(valobj, dict)
 
+    if rust_type == RustType.STD_PATHBUF:
+        return StdPathBufSummaryProvider(valobj, dict)
+    if rust_type == RustType.STD_PATH:
+        return StdPathSummaryProvider(valobj, dict)
+
     return ""
 
 
diff --git a/src/etc/lldb_providers.py b/src/etc/lldb_providers.py
index 5d2b6fd525c..1c43977a501 100644
--- a/src/etc/lldb_providers.py
+++ b/src/etc/lldb_providers.py
@@ -173,6 +173,35 @@ def StdStrSummaryProvider(valobj, dict):
     return '"%s"' % data
 
 
+def StdPathBufSummaryProvider(valobj, dict):
+    # type: (SBValue, dict) -> str
+    # logger = Logger.Logger()
+    # logger >> "[StdPathBufSummaryProvider] for " + str(valobj.GetName())
+    return StdOsStringSummaryProvider(valobj.GetChildMemberWithName("inner"), dict)
+
+
+def StdPathSummaryProvider(valobj, dict):
+    # type: (SBValue, dict) -> str
+    # logger = Logger.Logger()
+    # logger >> "[StdPathSummaryProvider] for " + str(valobj.GetName())
+    length = valobj.GetChildMemberWithName("length").GetValueAsUnsigned()
+    if length == 0:
+        return '""'
+
+    data_ptr = valobj.GetChildMemberWithName("data_ptr")
+
+    start = data_ptr.GetValueAsUnsigned()
+    error = SBError()
+    process = data_ptr.GetProcess()
+    data = process.ReadMemory(start, length, error)
+    if PY3:
+        try:
+            data = data.decode(encoding='UTF-8')
+        except UnicodeDecodeError:
+            return '%r' % data
+    return '"%s"' % data
+
+
 class StructSyntheticProvider:
     """Pretty-printer for structs and struct enum variants"""
 
diff --git a/src/etc/rust_types.py b/src/etc/rust_types.py
index 2b06683ef93..c0415a3cdcf 100644
--- a/src/etc/rust_types.py
+++ b/src/etc/rust_types.py
@@ -32,6 +32,8 @@ class RustType(object):
     STD_REF_MUT = "StdRefMut"
     STD_REF_CELL = "StdRefCell"
     STD_NONZERO_NUMBER = "StdNonZeroNumber"
+    STD_PATH = "StdPath"
+    STD_PATHBUF = "StdPathBuf"
 
 
 STD_STRING_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)String$")
@@ -51,6 +53,8 @@ STD_REF_REGEX = re.compile(r"^(core::([a-z_]+::)+)Ref<.+>$")
 STD_REF_MUT_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefMut<.+>$")
 STD_REF_CELL_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefCell<.+>$")
 STD_NONZERO_NUMBER_REGEX = re.compile(r"^(core::([a-z_]+::)+)NonZero<.+>$")
+STD_PATHBUF_REGEX = re.compile(r"^(std::([a-z_]+::)+)PathBuf$")
+STD_PATH_REGEX =  re.compile(r"^&(mut )?(std::([a-z_]+::)+)Path$")
 
 TUPLE_ITEM_REGEX = re.compile(r"__\d+$")
 
@@ -75,6 +79,8 @@ STD_TYPE_TO_REGEX = {
     RustType.STD_REF_CELL: STD_REF_CELL_REGEX,
     RustType.STD_CELL: STD_CELL_REGEX,
     RustType.STD_NONZERO_NUMBER: STD_NONZERO_NUMBER_REGEX,
+    RustType.STD_PATHBUF: STD_PATHBUF_REGEX,
+    RustType.STD_PATH: STD_PATH_REGEX,
 }
 
 def is_tuple_fields(fields):
diff --git a/tests/debuginfo/path.rs b/tests/debuginfo/path.rs
new file mode 100644
index 00000000000..42bbacc3a91
--- /dev/null
+++ b/tests/debuginfo/path.rs
@@ -0,0 +1,29 @@
+//@ ignore-gdb
+
+//@ compile-flags:-g
+
+// === LLDB TESTS =================================================================================
+
+// lldb-command:run
+
+// lldb-command:print pathbuf
+// lldb-check:[...] "/some/path" { inner = "/some/path" { inner = { inner = size=10 { [0] = '/' [1] = 's' [2] = 'o' [3] = 'm' [4] = 'e' [5] = '/' [6] = 'p' [7] = 'a' [8] = 't' [9] = 'h' } } } }
+// lldb-command:po pathbuf
+// lldb-check:"/some/path"
+// lldb-command:print path
+// lldb-check:[...] "/some/path" { data_ptr = [...] length = 10 }
+// lldb-command:po path
+// lldb-check:"/some/path"
+
+use std::path::Path;
+
+fn main() {
+    let path = Path::new("/some/path");
+    let pathbuf = path.to_path_buf();
+
+    zzz(); // #break
+}
+
+fn zzz() {
+    ()
+}