ARM - Assembly GNU Debugger Output Help

Thread Starter

Ab Abrams

Joined Apr 27, 2017
25
Hi guys, I was wondering, I am running a simple Assembly example with GNU Debbuger (GDB) on a RPI (ARM architecture). When I execute the command "info registers" I take the following output.

(gdb) info registers
r0 0x1 1
r1 0x7efff7b4 2130704308
r2 0x7efff7bc 2130704316
r3 0x10408 66568
r4 0x1042c 66604
r5 0x0 0
r6 0x102e0 66272
r7 0x0 0
r8 0x0 0
r9 0x0 0
r10 0x76fff000 1996484608
r11 0x0 0
r12 0x7efff6e0 2130704096
sp 0x7efff660 0x7efff660
lr 0x76e8f678 1994978936
pc 0x10408 0x10408 <main>
cpsr 0x60000010 1610612752


From the output I can see that some register's values are memory addresses. Am I correct?
If I type then the following command I take this output:

(gdb) x $r3
0x10408 <main>: 0xe3a00000
(gdb) x $r1
0x7efff7b4: 0x7efff8d3
(gdb) x $r2
0x7efff7bc: 0x7efff8e3


This means that the value of the R3 for example points to another memory address location?

I am confused, the value of a register is the address that shows at the info field or the address that points to?

Any help to understand this?
Also, Is any general rule that declares which values of which registers are addresses or actual values like 3,4 and so on?
 

tribbles

Joined Jun 19, 2015
31
ARM registers are basically universal, so you don't really know if they're pointing to an address or not. PC is the only one which will practically always be pointing to an address, but SP and LR will pretty much all of the time be pointing to an address (SP being the Stack Pointer, and LR being the Link Register - i.e. where to call back to when you return).

So when you list the registers, it's just the value of the registers that is being shown, and not what the registers are pointing at. GDB doesn't know if they're being used as a pointer, or basic arithmetic - and it could try to read some invalid memory addresses if it made the assumption that it was the pointer.

Since your PC is 0x10408, then I would hazard a guess that R3, R4 and R6 are pointers to areas in your program. R1, R2, R10, R12, SP and LR are also likely to be pointers. But this was only because they're in the same range.

The upshot is that only the PC is guaranteed to be a pointer - all other registers can be used for other purposes (I've used R0-R14 for general number storage in programs before).
 

MrChips

Joined Oct 2, 2009
30,795
Why should you be concerned if a register holds an address?
This is normal practice when working with pointers.
 
Top