cannot access memory at address 0x10084 when trying to set breakpoint via gdb

1

I wrote this simple assembly-program (based on a tutorial, only slightly changed.)

@ p = q + r + s
@ let q=2, r=4, s=5
@ this version of the simple-equation stores in memory

p:      .space  4       @reserve 4 bytes in memory for variable p
q:      .word   2       @create 32-bit variable q with initial value of 2
r:      .word   4   
s:      .word   5

        .global _start

_start:

        ldr     r1,q    @load r1 with q
        ldr     r2,r    @load r2 with r
        ldr     r3,s    @load r3 with s

        add     r0,r1,r2
        add     r0,r0,r3

        mov     r7,#1   @syscall to terminate the program
        svc     0

        .end

I assemble the program using as -g -o main.o main.s Then i link the object-file usind ld main.o -o main Then i execute gdb main Now, when trying to insert a breakpoint at any line-number, i get the error that is the title of this post (cannot access memory at address 0x10084). As this program's code is based off of a tutorial, and the teacher in the tutorial uses a codeblocks-project and

    .global main
main:

instead of

    .global _start
_start:

i assume that this is where my error might come from (although not understanding how this results in not being able to set a breakpoint via gdb, while not getting any error while assembling and linking). I would be very greatful if anyone could shed some light on this for me. Thanks in advance! edit: having been asked what the output of objdump -d main might look like, i add the output of the command here:

main:     file format elf32-littlearm


Disassembly of section .text:

00010054 <p>:
   10054:       00000000        .word   0x00000000

00010058 <q>:
   10058:       00000002        .word   0x00000002

0001005c <r>:
   1005c:       00000004        .word   0x00000004

00010060 <s>:
   10060:       00000005        .word   0x00000005

00010064 <_start>:
   10064:       e51f1014        ldr     r1, [pc, #-20]  ; 10058 <q>
   10068:       e51f2014        ldr     r2, [pc, #-20]  ; 1005c <r>
   1006c:       e51f3014        ldr     r3, [pc, #-20]  ; 10060 <s>
   10070:       e0810002        add     r0, r1, r2
   10074:       e0800003        add     r0, r0, r3
   10078:       e3a07001        mov     r7, #1
   1007c:       ef000000        svc     0x00000000

readelf -a main told me (among other things), that my entry point is 0x10064.

I already tried to use main instead of _start, however then during disassembling and linking i get an error telling me that no entry point has been found.

edit: Given the address of the entry-point, i ran the program again using gdb, then set a breakpoint to the specified address. It did so without complaining, and when running, execution indeed stops at the breakpoint. So the issue seems to be that the address 0x10084 that gdb wants to use for my breakpoint linenum command just doesn't correspond to the addresses that the instructions at the corresponding lines really have.

Using the gdb command info line 'linenumber' just confirms my assumption. It prints out memory addresses and i can indeed set breakpoints to the printed addresses, but when i try to set a breakpoint specifying the line-number, gdb always wants to use 0x10084 and fails.

Does anybody have an idea, how this behaviour comes about, and what might be ways to fix it?

debugging
assembly
memory
arm
gdb
asked on Stack Overflow Dec 10, 2018 by LeonTheProfessional • edited Dec 22, 2018 by LeonTheProfessional

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0