Gdb结构值在" next"之后变为0

时间:2015-03-01 09:53:07

标签: c struct gdb elf

所以我的struct值在gdb中的“next”命令之后变为0,这应该没有效果。

166     RawElfSymbol *currSymb = symbolTabSec;   
(gdb) p *currSymb
$8 = {name = 623313010, addr = 540682099, size = 1931505518, type_and_bind = 117 'u', ignored = 99 'c', section_tag = 8296}
(gdb) next
167     int sizeOfSymb = currSymb->size;    
(gdb) p *currSymb
$9 = {name = 0, addr = 0, size = 0, type_and_bind = 0 '\000', ignored = 0 '\000', section_tag = 0} 

对于为什么会发生这种情况的任何可能的解释?我无法弄清楚:/

如果这有帮助,这是RawElfSymbol结构:

typedef struct {
    unsigned int name;  // offset in bytes from start of string table to symbol name
    uintptr_t  addr;   // symbol address
    unsigned int size;    // symbol size in bytes
    unsigned char type_and_bind;   // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
                                // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
    unsigned char  ignored;
    unsigned short section_tag;     // will be SHN_UNDEF if symbol is undefined
} RawElfSymbol;

1 个答案:

答案 0 :(得分:5)

166     RawElfSymbol *currSymb = symbolTabSec;   
(gdb) p *currSymb
$8 = {name = 623313010, addr = 540682099, size = 1931505518, type_and_bind = 117 'u', ignored = 99 'c', section_tag = 8296}

此时gdb会话线166尚未执行。您看到的是存储在某些未初始化的currSymb地址的随机垃圾值。

(gdb) next
167     int sizeOfSymb = currSymb->size;    
(gdb) p *currSymb
$9 = {name = 0, addr = 0, size = 0, type_and_bind = 0 '\000', ignored = 0 '\000', section_tag = 0} 

现在执行第166行,您会看到struct的实际有效值。要确认这一点,它们必须与symbolTabSec地址相同。