1

I am trying to understand how to read memory address and find out its value using GDB.

In code, I assigned a value:

xyz->a = -1;

In GDB I see this:

(gdb) p xyz->a  
$1 = 65535  
(gdb) p/x xyz->a    
$2 = 0xffff  
(gdb) p &(xyz->a)  
$3 = (some_type *) 0x172e750  

(gdb) x/40xb 0x172e750  
0x172e750:      0xff    0xff    0x00    0x00    0x00    0x00    0x00    0x00  
0x172e758:      0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00  
0x172e760:      0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00  
0x172e768:      0xc0    0xe0    0x5b    0x01    0x00    0x00    0x00    0x00  
0x172e770:      0xd8    0x00    0x00    0x00    0x29    0x00    0x00    0x00  

Firstly, how do I read the memory addresses and their values to determine xyz->a value?
Second, looks like there is an Endian issue going on? How do I confirm that?

adizone
  • 203
  • 1
  • 5
  • 13
  • Is `a` declared as `unsigned short` or `uint16`? If so, then everything looks OK. The integer -1 is almost always represented as a bit pattern of all 1's. – Mark Plotnick Aug 21 '14 at 14:25
  • @MarkPlotnick yes, `a` is declared as `uint16`. Maybe I dont see it correctly, how can a -ve number be represented in unsigned format? – adizone Aug 21 '14 at 17:01
  • See [What happens if I assign a negative value to an unsigned variable](http://stackoverflow.com/questions/2711522/what-happens-if-i-assign-a-negative-value-to-an-unsigned-variable). – Mark Plotnick Aug 21 '14 at 17:08

1 Answers1

1

In memory, they are complements. To confirm endian, you can try to give xyz->a a value such like 0x55aa.

adol
  • 21
  • 1