1

So my struct values are becoming 0 after a "next" command in gdb, which should have no effect.

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} 

Any possible explanations for why this is happening? I can't figure it out:/

if this helps, this is the RawElfSymbol struct:

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;
Fran C
  • 13
  • 3
  • Is symbolTabSec being processed by any other thread? Most likely, by the time you go to line 167, your memory chunk pointed by currSymb is already wiped out by the "other" thread. – sanjayk79 Mar 01 '15 at 10:22

1 Answers1

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}

At this point in gdb session line 166 was not executed yet. What you see is random garbage values stored at some uninitialized currSymb address.

(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} 

Now line 166 was executed and you see real valid values of struct. To confirm this they must be the same as at symbolTabSec address.

ks1322
  • 33,961
  • 14
  • 109
  • 164