Skip to content

Commit 41e97a0

Browse files
committed
Add rust-lldb pretty printing for Path and PathBuf
Fixes #120553 Fixes #48462
1 parent 45796d1 commit 41e97a0

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

src/etc/lldb_commands

+3
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)R
1616
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
1717
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
1818
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust
19+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
20+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::([a-z_]+::)+)PathBuf$" --category Rust
21+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
1922
type category enable Rust

src/etc/lldb_lookup.py

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def summary_lookup(valobj, dict):
5858
if rust_type == RustType.STD_NONZERO_NUMBER:
5959
return StdNonZeroNumberSummaryProvider(valobj, dict)
6060

61+
if rust_type == RustType.STD_PATHBUF:
62+
return StdPathBufSummaryProvider(valobj, dict)
63+
if rust_type == RustType.STD_PATH:
64+
return StdPathSummaryProvider(valobj, dict)
65+
6166
return ""
6267

6368

src/etc/lldb_providers.py

+29
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,35 @@ def StdStrSummaryProvider(valobj, dict):
173173
return '"%s"' % data
174174

175175

176+
def StdPathBufSummaryProvider(valobj, dict):
177+
# type: (SBValue, dict) -> str
178+
# logger = Logger.Logger()
179+
# logger >> "[StdPathBufSummaryProvider] for " + str(valobj.GetName())
180+
return StdOsStringSummaryProvider(valobj.GetChildMemberWithName("inner"), dict)
181+
182+
183+
def StdPathSummaryProvider(valobj, dict):
184+
# type: (SBValue, dict) -> str
185+
# logger = Logger.Logger()
186+
# logger >> "[StdPathSummaryProvider] for " + str(valobj.GetName())
187+
length = valobj.GetChildMemberWithName("length").GetValueAsUnsigned()
188+
if length == 0:
189+
return '""'
190+
191+
data_ptr = valobj.GetChildMemberWithName("data_ptr")
192+
193+
start = data_ptr.GetValueAsUnsigned()
194+
error = SBError()
195+
process = data_ptr.GetProcess()
196+
data = process.ReadMemory(start, length, error)
197+
if PY3:
198+
try:
199+
data = data.decode(encoding='UTF-8')
200+
except UnicodeDecodeError:
201+
return '%r' % data
202+
return '"%s"' % data
203+
204+
176205
class StructSyntheticProvider:
177206
"""Pretty-printer for structs and struct enum variants"""
178207

src/etc/rust_types.py

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class RustType(object):
3232
STD_REF_MUT = "StdRefMut"
3333
STD_REF_CELL = "StdRefCell"
3434
STD_NONZERO_NUMBER = "StdNonZeroNumber"
35+
STD_PATH = "StdPath"
36+
STD_PATHBUF = "StdPathBuf"
3537

3638

3739
STD_STRING_REGEX = re.compile(r"^(alloc::([a-z_]+::)+)String$")
@@ -51,6 +53,8 @@ class RustType(object):
5153
STD_REF_MUT_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefMut<.+>$")
5254
STD_REF_CELL_REGEX = re.compile(r"^(core::([a-z_]+::)+)RefCell<.+>$")
5355
STD_NONZERO_NUMBER_REGEX = re.compile(r"^(core::([a-z_]+::)+)NonZero<.+>$")
56+
STD_PATHBUF_REGEX = re.compile(r"^(std::([a-z_]+::)+)PathBuf$")
57+
STD_PATH_REGEX = re.compile(r"^&(mut )?(std::([a-z_]+::)+)Path$")
5458

5559
TUPLE_ITEM_REGEX = re.compile(r"__\d+$")
5660

@@ -75,6 +79,8 @@ class RustType(object):
7579
RustType.STD_REF_CELL: STD_REF_CELL_REGEX,
7680
RustType.STD_CELL: STD_CELL_REGEX,
7781
RustType.STD_NONZERO_NUMBER: STD_NONZERO_NUMBER_REGEX,
82+
RustType.STD_PATHBUF: STD_PATHBUF_REGEX,
83+
RustType.STD_PATH: STD_PATH_REGEX,
7884
}
7985

8086
def is_tuple_fields(fields):

tests/debuginfo/path.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ ignore-gdb
2+
3+
//@ compile-flags:-g
4+
5+
// === LLDB TESTS =================================================================================
6+
7+
// lldb-command:run
8+
9+
// lldb-command:print pathbuf
10+
// 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' } } } }
11+
// lldb-command:po pathbuf
12+
// lldb-check:"/some/path"
13+
// lldb-command:print path
14+
// lldb-check:[...] "/some/path" { data_ptr = [...] length = 10 }
15+
// lldb-command:po path
16+
// lldb-check:"/some/path"
17+
18+
use std::path::Path;
19+
20+
fn main() {
21+
let path = Path::new("/some/path");
22+
let pathbuf = path.to_path_buf();
23+
24+
zzz(); // #break
25+
}
26+
27+
fn zzz() {
28+
()
29+
}

0 commit comments

Comments
 (0)