Closed
Description
The &str
type is not available in rust-gdb
.
When debugging using rust-gdb
, local variables with &str
type are pretty printed.
(gdb) p my_string_local
$6 = "my string"
(gdb) ptype my_string_local
type = struct &str {
data_ptr: *mut u8,
length: usize,
}
I expect that a raw pointer referring to the same memory location on the stack can be casted to &str
and printed. However, gdb throws an exception:
(gdb) p *(($rsp + 168) as *mut &[u8])
$15 = &[*gdb*](len: 14) = {109, 121, 32, 115, 116, 114, 105, 110, 103}
(gdb) p *(($rsp + 168) as *mut &str)
No typed name 'str' in current context
rust/src/etc/debugger_pretty_printers_common.py
Lines 149 to 151 in 8ee24f6
Workaround
You can use a helper function to cast and dereference the pointer:
unsafe fn print_str(ptr: *const &str) -> &str {
return *ptr;
}
(gdb) p my_lib::print_str($rsp + 168)
$15 = "my string"
Meta
rustc --version --verbose
rustc 1.38.0 (625451e37 2019-09-23)
binary: rustc
commit-hash: 625451e376bb2e5283fc4741caa0a3e8a2ca4d54
commit-date: 2019-09-23
host: x86_64-unknown-linux-gnu
release: 1.38.0
LLVM version: 9.0