When i was debugging an issue using GDB, i came across this weird behavior. For which i could not convince myself with any logical answer.
Below is the snapshot of the call stack obtained because of the breakpoint at the beginning of the function (I am restricting the stack frame to 3 level for simplicity).
(gdb)
#0 hashset_get (hashset=<value optimized out>, item_key=0x7fffd7e4f5b8)
at /xxx/yyy/zzz/hashset.c:123
#1 0x00007fffed855d00 in hashmap_get (hashmap=<value optimized out>, key=0x7fffd7e4f648)
at /xxx/yyy/zzz/hashmap.c:789
#2 0x00007ffa589d8eeb in hashmap_get_value (hashmap=0x7ff9d82d1b78, key=0x7fffd7e4f648)
at /xxx/yyy/zzz/hashmap.c:456
After this there is one single-step execution. Later to which stack frame looked as below-
(gdb) bt
#0 hashset_get (hashset=0xf8f8f8f8f8f8f8f8, item_key=0x7fffd7e4f5b8)
at /xxx/yyy/zzz/hashset.c:125
#1 0x00007fffed855d00 in hashmap_get (hashmap=<value optimized out>, key=0x7fffd7e4f648)
at /xxx/yyy/zzz/hashmap.c:789
#2 0x00007ffa589d8eeb in hashmap_get_value (hashmap=0x7ff9d82d1b78, key=0x7fffd7e4f648)
at /xxx/yyy/zzz/hashmap.c:456
I know that when the GDB shows any variable as "value optimized out", it indicates that its value is stored in register instead of storing on the stack frame.
However, in this case, the arg hashset which was initially shown as "value optimized out" is later changed to some address location - 0xf8f8f8f8f8f8f8f8. So does that mean initially it has stored the hashset in register then created a space on the stack frame?
And this address doesn't looks like any other memory location address. You could see some pattern in the address (like f8f8...)
To add more confusion to the fact, if I try to print the data at that location, GDB outputs as below-
(gdb) p *hashset
Cannot access memory at address 0xf8f8f8f8f8f8f8f8
Some more things i tried in a hope that it could help in understand this behavior.
I assigned a valid address 0x7fffd7e4f5b8 - which is held by the arg item_key, to hashset
(gdb) s hashset=0x7fffd7e4f5b8
(gdb) p *hashset
Cannot access memory at address 0xb8b8b8b8b8b8b8b8
(gdb) p hashset
$6 = (hashset) 0xb8b8b8b8b8b8b8b8
But to my surprise, when I print the value of hashset, it is showing the address as 0xb8b8b8b8b8b8b8b8 instead of 0x7fffd7e4f5b8!!
Could someone please explain what is happening here?
[Edit: There is NO crash/hang. System is operational, normally]