我想打印调用实例函数的结果std::path::Path。
我正在使用 Rust 1.43 和 GDB 9.1
主程序.rs
use std::path::Path;
fn main() {
let path = Path::new("/home/sweet/home");
println!("The path: {}", path.display());
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 rust-gdb 调试它时,我得到以下信息:
$ rust-gdb target/debug/poc-gdb-pathbuf
...
>>> start
>>> n
>>> print path
$1 = (*mut std::path::Path) 0x55555557c000
>>> print &path
$2 = (*mut *mut std::path::Path) 0x7fffffffe0c0
>>> print *path
$3 = std::path::Path {
inner: std::ffi::os_str::OsStr {
inner: std::sys_common::os_str_bytes::Slice {
inner: 0x55555557c000
}
}
}
>>> print *path.is_absolute()
Could not find function named 'std::path::Path::is_absolute'
>>> print path.is_absolute()
Could not find function named 'std::path::Path::is_absolute'
>>> print path.display()
Function 'std::path::Path::display' takes no arguments
>>> print *path.display()
Function 'std::path::Path::display' takes no arguments
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我无法正确调用单个Path实例函数,它要么告诉我该函数不存在(它确实存在),要么它不接受任何参数(我没有传递任何参数)。
我对简单、最小的结构函数调用没有任何问题,这是一个有效的示例。
主程序.rs
$ rust-gdb target/debug/poc-gdb-pathbuf
...
>>> start
>>> n
>>> print path
$1 = (*mut std::path::Path) 0x55555557c000
>>> print &path
$2 = (*mut *mut std::path::Path) 0x7fffffffe0c0
>>> print *path
$3 = std::path::Path {
inner: std::ffi::os_str::OsStr {
inner: std::sys_common::os_str_bytes::Slice {
inner: 0x55555557c000
}
}
}
>>> print *path.is_absolute()
Could not find function named 'std::path::Path::is_absolute'
>>> print path.is_absolute()
Could not find function named 'std::path::Path::is_absolute'
>>> print path.display()
Function 'std::path::Path::display' takes no arguments
>>> print *path.display()
Function 'std::path::Path::display' takes no arguments
Run Code Online (Sandbox Code Playgroud)
rust-gdb 会话:
$ rust-gdb target/debug/poc-gdb-something
...
>>> start
>>> n
>>> print something
$1 = poc_gdb_pathbuf::Something {
x: 10
}
>>> print something.show()
$2 = 10
Run Code Online (Sandbox Code Playgroud)
我怀疑这可能与Path实例是指针有关,但取消引用它并没有帮助......
为什么Path通话打不通?我缺少什么?