Prithvi Raj
Prithvi Raj

Reputation: 1961

Cannot access memory - gdb

Here is my disas code:

Dump of assembler code for function main:
0x00000000000006b0 <+0>:    push   %rbp
0x00000000000006b1 <+1>:    mov    %rsp,%rbp
0x00000000000006b4 <+4>:    sub    $0x10,%rsp
0x00000000000006b8 <+8>:    movl   $0xa,-0xc(%rbp)
0x00000000000006bf <+15>:   lea    -0xc(%rbp),%rax
0x00000000000006c3 <+19>:   mov    %rax,-0x8(%rbp)
0x00000000000006c7 <+23>:   lea    0x96(%rip),%rdi        # 0x764
0x00000000000006ce <+30>:   mov    $0x0,%eax
0x00000000000006d3 <+35>:   callq  0x560 <printf@plt>
0x00000000000006d8 <+40>:   mov    $0x0,%eax
0x00000000000006dd <+45>:   leaveq 
0x00000000000006de <+46>:   retq 

when I set the breakpoint at 0x06b4 by b *0x00000000000006b4 and run the code it is giving an error Starting program: /root/print.out Warning: Cannot insert breakpoint 4. Cannot access memory at address 0x6b4 but when I do it with b 4 and run the code ,it is working normal. so what am I doing wrong in the first case.

Upvotes: 0

Views: 5233

Answers (1)

Employed Russian
Employed Russian

Reputation: 213375

Dump of assembler code for function main: 0x00000000000006b0 <+0>: push %rbp 0x00000000000006b1 <+1>: mov %rsp,%rbp

You are looking at position-independent executable (a special kind of shared library). The code for main gets relocated to a different address when the executable starts running.

Because there is no code at 0x6b4 once the executable is relocated, GDB complains that it can't set a breakpoint there.

but when I do it with b 4 and run the code ,it is working normal.

In this case, GDB understands that you want to set breakpoint on line 4, and inserts appropriate breakpoint after the executable has been relocated.

Use info break to see what the relocated address is.

Upvotes: 2

Related Questions