给定一个指针,gdb 如何获取它的类型?
gdb 如何知道指针指向 int
或 struct
或任何其他数据类型?
How does gdb know the pointer points to a int
or struct
or any other data types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自:检查符号表
两个命令给出以下输出:
from: Examining the Symbol Table
the two commands give this output:
gdb 无法知道,除非指针来自可以确定其类型的变量或表达式。
如果 gdb 被赋予 0x4567789,它不知道这可能指向什么。但如果 int *p 具有该值,gdb 可以遵循该值并给出该地址包含的内容。
gdb can't know, unless the pointer came from a variable or expression for which the type can be determined.
If gdb is given 0x4567789, it has no idea what that might point to. But if an int *p has that value, gdb can deference that and give you what that address contains.
当您使用调试选项 (
-g
) 进行编译时,gdb
通过读取嵌入在可执行文件中的调试信息(也称为符号表)来了解代码中指针变量的类型)。gdb
knows the type of a pointer variable in your code by reading the debugging information (a.k.a. symbol table) that's embedded in your executable when you compile with the debug option (-g
).