gdb:是否可以根据调试符号中不存在的用户定义结构来转换/重新解释序列
以下是问题陈述。如果您最终只是浏览问题陈述,那么底部是我的实际问题。
编辑
我忘了提及:我正在链接--no-strip-discarded --discard-none
。当我搜索有问题的类型时,其中一个目标文件(预链接)与 grep 匹配,但在使用 nm 从目标文件转储信息后找不到该字符串、objdump
和 readelf
。
我正在查看一些使用以下惯用法的 C 代码:
// somecode.h
typedef struct {
// ...
volatile unsigned char *member1;
} Type1_t;
typedef struct {
unsigned int member1:16;
unsigned int member2:32;
unsigned int member3:16;
} Type2_t;
// somecode.c
// ...
void someFunction( Type1_t *type1Ptr ) {
// ...
doSomething( ((Type2_t*)type1Ptr->member1)->accessType2Member );
}
请忽略您可能对编码风格的任何反对意见,这不是我的问题。
在这种情况下,Type2_t
的实例不会被实例化,因此我可以告诉编译器确定没有必要发出有关该类型的调试信息。
我正在尝试使用此转换数据来监视代码的行为来追踪问题,但我所能做的最好的事情就是让 gdb 将有问题的数组打印为字节数组。我可以使用以下方法在数组上设置监视:
watch {char[12]}type1Ptr->member1
... 但除了实际不显示 member1、member2 和 & member3,字符数组的漂亮打印机将其打印为 \000\032\021
... 形式的序列(对此的说明:我在Solaris ,并且 Solaris 中的 gdb 7.2 存在 libiconv 问题,gdb 使用它来进行代码页转换,我现在不确定这是否是这样。为什么它不只是将其打印为十六进制字符序列),所以我最终要么必须使用 display
或其他某种机制打印内容,然后在我的脑海中解释内容。
我正在寻找什么:
- 有没有办法让 gcc 发出所有调试符号,即使有问题的类型仅在进行强制转换时出现?
- ...或者如果实际代码中根本没有使用该类型
- 我可以以某种方式在
gdb
中包含一个标头,以便定义类型吗? - 这可能有点牵强,但是:除了转换为当前定义的类型之外,gdb 是否有任何工具可以进行更复杂的转换?举个例子,有没有办法做类似下面的事情
(gdb) print {struct { unsigned int:16 member1; unsigned int:32 member2;
unsigned int:16 member3;} }( type1Ptr->member1 )
Below is the problem statement. At the bottom is my actual question if you end up just skimming the problem statement.
edit
I forgot to mention: I'm linking with --no-strip-discarded --discard-none
. One of the object files (pre-link) gets matched by grep
when I search for the type in question, but I'm not finding that string after dumping info from the object file with nm
, objdump
, and readelf
.
I'm looking at some C code that uses an idiom along the lines of:
// somecode.h
typedef struct {
// ...
volatile unsigned char *member1;
} Type1_t;
typedef struct {
unsigned int member1:16;
unsigned int member2:32;
unsigned int member3:16;
} Type2_t;
// somecode.c
// ...
void someFunction( Type1_t *type1Ptr ) {
// ...
doSomething( ((Type2_t*)type1Ptr->member1)->accessType2Member );
}
Please ignore any objections you might have to the coding style, that isn't my question.
In this case, no instance of Type2_t
is ever instantiated, so as best I can tell the compiler determined it wasn't necessary to emit debugging information about the type.
I'm attempting to monitor the behavior of code using this casted data to track down a problem, but the best I've managed to do is get gdb to print the array in question as an array of bytes. I can set a watch on the array with:
watch {char[12]}type1Ptr->member1
... but in addition to not actually displaying member1, member2, & member3
, the pretty-printer for char arrays prints it out as a sequence of the form \000\032\021
... etc (a note on this: I'm in solaris, and gdb 7.2 in Solaris has issues with libiconv, which gdb uses for code page translations. I'm stuck with ISO-8859-1 for now. I'm unsure if that's why it doesn't just print it as a sequence of hex characters), so I end up either having to print the contents with display
or some other mechanism, then interpret the contents in my head.
What I'm looking for:
- Is there a way to make
gcc
emit all debug symbols, even if the type in question only shows up when doing a cast?- ... or if the type isn't used at all in actual code
- Can I just include a header in
gdb
somehow so the type is defined? - This one is probably far fetched, but: does
gdb
have any facility for doing more complex casts than just casting to currently defined types? As an example, is there a way to do something like the following
(gdb) print {struct { unsigned int:16 member1; unsigned int:32 member2;
unsigned int:16 member3;} }( type1Ptr->member1 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来像这个问题/答案 解决了第二个问题,并在某种程度上减轻了对第三个问题的需求。
It looks like this question/answer takes care of the 2nd question, and sort of alleviates the need for #3.
我对类型信息不可用的问题有一个答案。我将
-gstabs+
添加到我的 CFLAGS:... 现在 gdb 可以告诉我有关相关类型的有用信息。
不过,如果有人想尝试一下的话,我仍然对其他两个问题的答案感兴趣。
I have an answer to the problem of type information not being available. I added
-gstabs+
to my CFLAGS:... and now gdb can tell me useful stuff about the type in question.
I'm still interested in answers to the other two questions, though, if anyone wants to take a shot at those.