In my code, I have
mov x21, 0
str x21, [x29, 16]
and then later on in the code,
ldr x22, [x29, 16]
which stores 0 into x22. And then, even later in the code, I have
ldr x23, [x29, 16]
which ends up storing 214748364800 into x23 even though there is no str
command between the two ldr
commands.
My question is how do i set a watchpoint for the [x29, 16]
location on the stack so I can see when it is written to?
I am using gdb for debugging.
EDIT: This is a portion of the gdb output when I set a watch on the x29+16 location
Breakpoint 2, 0x0000000000400668 in inittest ()
1: x/i $pc
=> 0x400668 <inittest+8>: mov x21, #0x0 // #0
(gdb) ni
0x000000000040066c in inittest ()
1: x/i $pc
=> 0x40066c <inittest+12>: str x21, [x29,#16]
(gdb) p/x $x29+16
$1 = 0x3fffffff340
(gdb) x/x $x29+16
0x3fffffff340: 0xb8002d40
(gdb) watch *(int*)0x3fffffff340
Hardware watchpoint 5: *(int*)0x3fffffff340
(gdb) c
Continuing.
Hardware watchpoint 5: *(int*)0x3fffffff340
Old value = -1207947968
New value = 0
0x0000000000400670 in inittest ()
1: x/i $pc
=> 0x400670 <inittest+16>: b 0x4006d8 <testOut>
later on in the gdb output:
(gdb) p $x24
$4 = 103
(gdb) x/x $x29+24
0x3fffffff348: 0x00000000
(gdb) ni
0x00000000004006b4 in testIn ()
1: x/i $pc
=> 0x4006b4 <testIn+16>: ldr x24, [x29,#16]
(gdb) x/x $x29+16
0x3fffffff340: 0x00000000
(gdb) ni
if i were to type p$x24
here, it displays 214748364800
even though it loads from [x29,#16]
which is holding 0
0x00000000004006b8 in testIn ()
1: x/i $pc
=> 0x4006b8 <testIn+20>: ldr w23, [x19,x21,lsl #2]
(gdb) ni
0x00000000004006bc in testIn ()
1: x/i $pc
=> 0x4006bc <testIn+24>: str w23, [x29,#28]
(gdb)
0x00000000004006c0 in testIn ()
1: x/i $pc
=> 0x4006c0 <testIn+28>: ldr w23, [x19,x24,lsl #2]
(gdb)
Program received signal SIGSEGV, Segmentation fault.
0x00000000004006c0 in testIn ()
1: x/i $pc
=> 0x4006c0 <testIn+28>: ldr w23, [x19,x24,lsl #2]
Error arises because x24
can only be max of about 54
due to memory allocation