hashmap - 如何在 GDB 中漂亮地打印 Rust HashMap?
问题描述
这是一个简单的 Rust 示例,其中包含我在 GDB 中运行的Vec
和:HashMap
use std::collections::HashMap;
fn main() {
let v = vec!["Mon", "Tue", "Wed"];
println!("{:?}", v);
let mut h = HashMap::new();
h.insert(1,"Jan");
h.insert(2,"Feb");
h.insert(3,"Mar");
h.insert(4,"Apr");
println!("{:?}", h);
}
当我查看Vec
它时,它打印得很漂亮,而HashMap
不是:
bash$ rust-gdb target/debug/test_hashmap
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from target/debug/test_hashmap...done.
(gdb) b 12
Breakpoint 1 at 0xa056: file src/main.rs, line 12.
(gdb) r
Starting program: /home/john/proj/test_hashmap/target/debug/test_hashmap
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
["Mon", "Tue", "Wed"]
Breakpoint 1, test_hashmap::main () at src/main.rs:12
12 println!("{:?}", h);
(gdb) p v
$1 = Vec<&str>(len: 3, cap: 3) = {"Mon", "Tue", "Wed"}
(gdb) p h
$2 = HashMap<i32, &str, std::collections::hash::map::RandomState> = {hash_builder = RandomState = {k0 = 12919411587537124140,
k1 = 836420561220520453}, table = RawTable<i32, &str> = {capacity_mask = 31, size = 4, hashes = TaggedHashUintPtr = {
Unique<usize> = {pointer = NonZero<*const usize> = {0x7ffff6c1c400}, _marker = PhantomData<usize>}},
marker = PhantomData<(i32, &str)>}, resize_policy = DefaultResizePolicy}
(gdb) info pretty-printer
global pretty-printers:
builtin
mpx_bound128
objfile /home/john/proj/test_hashmap/target/debug/test_hashmap pretty-printers:
rust_pretty_printer_lookup_function
(gdb) n
{1: "Jan", 4: "Apr", 3: "Mar", 2: "Feb"}
13 }
(gdb)
该程序可以看到HashMap
(并打印出它的值),但我在 GDB 中看不到那些。Rust 漂亮的打印机似乎已启用,因为Vec
它打印得很好。
如何获取HashMap
常规 GDB 中的键和值?
解决方案
目前无法为HashMap
.
推荐阅读
- python - 用户定义函数在 Python 中不起作用
- python - 如何在 Python 中将输入数据动态共享到并行进程
- javascript - 在 oracle apex 中每隔几分钟执行一次 plsql 代码
- sharepoint - 503 响应错误代码 - 使用 Graph API 针对 Microsoft 搜索索引数据
- laravel - 生产中的 Laravel config/app.php 未更新
- c# - 根据条件防止数组重复
- python - 如何在python脚本中使用进程名杀死一个进程
- java - Maven中2个不同项目中的循环依赖
- scrapy - 亚马逊立即检测到scrapy。如何防止验证码?
- r - R中组的滞后差异