我有一个程序的调试版本(V8 JavaScript VM),我想了解某些类的实例是如何在内存中布局的.我可以漂亮地打印这样的结构:
(gdb) print thread_local
$6 = {
blocks_ = {
data_ = 0x868ceb0,
capacity_ = 7,
length_ = 1
},
entered_contexts_ = {
data_ = 0x868d828,
capacity_ = 1,
length_ = 1
},
saved_contexts_ = {
data_ = 0x868d838,
capacity_ = 1,
length_ = 1
},
spare_ = 0x0,
ignore_out_of_memory_ = false,
call_depth_ = 1,
handle_scope_data_ = {
next = 0x0,
limit = 0x0,
level = 0
}
}
Run Code Online (Sandbox Code Playgroud)
但我想知道相对于对象的开始,那些不同的成员(块,entered_contexts等)在物理上的位置.在基于Solaris的系统上,mdb可以为C结构执行此操作,如下所示:
> ::print -at port_event_t
0 port_event_t {
0 int portev_events
4 ushort_t portev_source
6 ushort_t portev_pad
8 uintptr_t portev_object
10 void *portev_user
}
Run Code Online (Sandbox Code Playgroud)
在该示例中,每个字段以其从结构的开始处的偏移为前缀.我想为C++类做同样的事情.gdb必须有这些信息才能打印出struct成员,但是有什么方法可以查看它吗?
或者,还有其他方法可以为正在运行的程序执行此操作吗?