当存在多个相同名称的类型时,在gdb中通过名称指定正确的类型
Specifying correct type by name in gdb when multiple types of same name exist
我发现在检查一个变量时得到两个不同的结果,这取决于我是隐式地还是显式地使用GDB理解该变量的类型:
导航到我的堆栈框架
(gdb) frame 2
#2 0x00007f6a4277e87d in PyCheckFile (fname=0x7f6a338704b8 "/usr/lib/debug/sbin", ctx=0x7f6a3803ddf8)
at python-fd.c:2054
2054 pFunc = PyDict_GetItemString(p_ctx->pDict, "check_file"); /* Borrowed reference */
输出p_ctx
指向什么,GDB理解它,隐式地使用GDB所知道的关于它的类型。
(gdb) print *p_ctx
$26 = {backup_level = 0, python_loaded = false, plugin_options = 0x0, module_path = 0x0, module_name = 0x0,
fname = 0x0, link = 0x0, object_name = 0x0, object = 0x0, interpreter = 0x7f6a3802bb10, pModule = 0x0,
pDict = 0x0, bpContext = 0x0}
向GDB询问类型
的名称(gdb) whatis p_ctx
type = plugin_ctx *
在打印p_ctx
时显式指定类型名称,我们得到一个非常不同的输出。
(gdb) print * ( (plugin_ctx *) p_ctx )
$27 = {offset = 0, pfd = 0x0, plugin_options = 0x0, fname = 0x0, reader = 0x0, writer = 0x0,
where = ' 00' <repeats 16 times>, " 20273 02 70j177", ' 00' <repeats 26 times>, "225 31327Mj177 00 00240 00 00 00 00 00 00 00% 01 00 00 00 00 00 00@e317Mj177 00 00370&322Mj177 00 00375377377377377377377377260234337Mj177 00 00 01 00 00 00 00 00 00 00@ntBj177 00 00 60 00 00 00 00 00 00 00* 00 00 00 00 00 00 00177 00 00 00 00 00 00 00@322 00 70j177 00 00PaCBj177 00 00Ȋ260270i225fbЉ342Mj177 00 00 00 35c 01 00 00 00 00َ372<375364343372300237342Mj177 00 00 00337325"..., replace = 0}
让GDB告诉我们关于plugin_ctx的类型:
(gdb) info types ^plugin_ctx$
All types matching regular expression "^plugin_ctx$":
File bpipe-fd.c:
plugin_ctx;
File python-fd.c:
plugin_ctx;
这就是我们的问题;我们在python-fd中,当我们显式指定类型名称时,我们得到的是bpipe-fd的类型!
作为证据:
(gdb) ptype p_ctx
type = struct plugin_ctx {
int32_t backup_level;
bool python_loaded;
char *plugin_options;
char *module_path;
char *module_name;
char *fname;
char *link;
char *object_name;
char *object;
PyThreadState *interpreter;
PyObject *pModule;
PyObject *pDict;
PyObject *bpContext;
} *
:相比(gdb) ptype plugin_ctx
type = struct plugin_ctx {
boffset_t offset;
BPIPE *pfd;
char *plugin_options;
char *fname;
char *reader;
char *writer;
char where[512];
int replace;
}
那么,当出现多个名为plugin_ctx
的类型时,我如何告诉gdb使用哪一个?我试过:
(gdb) print * ( ('python-fd.c'::plugin_ctx *) p_ctx )
A syntax error in expression, near `*) p_ctx )'.
显然不起作用。我没有在GDB的手册中找到任何关于如何在应用于类型时解决这种消歧的内容。那么在这种情况下,首选的方法是什么?
我将用示例充实这个答案,因为我让它工作,但基于@n。M对核心帖子的反馈讨论和在另一个线程中发现的信息,这是一个解决方案:
用您想要的类型创建一个object文件,并使用一个明确的名称。
#include <Python.h>
struct plugin_ctx2 {
int32_t backup_level;
bool python_loaded;
char *plugin_options;
char *module_path;
char *module_name;
char *fname;
char *link;
char *object_name;
char *object;
PyThreadState *interpreter;
PyObject *pModule;
PyObject *pDict;
PyObject *bpContext;
} ;
- 使用
gcc
的add-symbol-file
命令,将目标文件拉入正在运行的进程。 - 你现在应该可以使用新类型了。
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- GDB 不完整类型前向枚举:int 声明
- 在非本机类型上具有多个条件的 GDB 断点
- GDB 无法访问值类型变量的内存
- 为什么我在 gdb 中收到 ifstream 对象的<不完整类型>消息?
- 如何捕获除使用 GDB 的异常类型之外的所有异常类型
- GDB有没有办法在不省略模板参数的情况下打印类型
- 将地址转换为Python GDB中的特定类型
- 使用 python 扩展在 gdb 中打印特征类型时出现问题
- GDB:请参阅未使用的结构类型定义
- 具有非类型参数的类模板的静态成员的 gdb "static field value has been optimized out"
- 漂亮的打印提升::MPL::字符串<...> GDB 中的类型
- GDB:显示某些数据的类型信息
- 当存在多个相同名称的类型时,在gdb中通过名称指定正确的类型
- STL类型/函数在gdb中使用条件断行,会使程序崩溃
- 我如何得到值和类型的当前异常在c++中使用gdb
- 在GDB中抛出特定异常类型时如何中断