1

我正在尝试调试一个核心转储(主要使用 gdb),到目前为止我发现的只是有一个正好 124 字节的结构,这会导致问题。鉴于该程序的所有来源,有没有办法找到该结构?(我的意思是有办法找到结构,其大小为 124 字节)

  • PS。我知道这个结构在记忆中的确切位置,但如果我看它,就无法知道它的用途。它也是常见的结构,所以我可以根据需要制作尽可能多的核心转储。

  • PS2。到目前为止,我尝试过:

    1. 要使用正则表达式grep '^ *[a-zA-Z][^ ;,."()]* [a-zA-Z][^ ;,."()]*' * | grep -v 'return' | sed 's/[^:]*: *\([^ ]*\).*/\1/' | sort | uniq > tmp.txt,添加p sizeof(x) 到每个找到的行并输入到 gdb。
    2. info variables在 gdb 中使用,记录输出,提取变量类型并将 sizeof(x) 添加到每种类型并输出到 gdb。
4

2 回答 2

2

尝试使用这个:

objdump -W <elf-name> | grep -B 2 "DW_AT_byte_size   : 124"

此命令转储 ELF 文件中的所有调试符号,并发现这些大小为 124。

于 2012-07-16T09:47:57.630 回答
2

在所有源文件包含的头文件中,定义一个宏,

#define malloc(size) my_malloc(size, __FILE__, __LINE__)

然后在实现中:

#undef malloc
void * my_malloc(size_t size, const char* file, int line)
{
    //if the size equal to 124 bytes, log it, then you will have a chance know where this kind of allocation happens, so you know the struct.
    if(124==size) printf(...);

    return malloc(size);
}
于 2012-07-16T10:03:52.770 回答