"next" 后 gdb 结构值全部变为 0

Gdb struct values all become 0 after "next"

因此,在 gdb 中执行 "next" 命令后,我的结构值变为 0,这应该没有任何效果。

166     RawElfSymbol *currSymb = symbolTabSec;   
(gdb) p *currSymb
 = {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
 = {name = 0, addr = 0, size = 0, type_and_bind = 0 '[=11=]0', ignored = 0 '[=11=]0', 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;
166     RawElfSymbol *currSymb = symbolTabSec;   
(gdb) p *currSymb
 = {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
 = {name = 0, addr = 0, size = 0, type_and_bind = 0 '[=11=]0', ignored = 0 '[=11=]0', section_tag = 0} 

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