简体   繁体   English

无法访问内存 - gdb

[英]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.当我通过 b *0x00000000000006b4 在 0x06b4 设置断点并运行代码时,它给出了错误Starting program: /root/print.out Warning: Cannot insert breakpoint 4. Cannot access memory at address 0x6b4但是当我使用b 4执行此操作时并运行代码,它工作正常。 so what am I doing wrong in the first case.那么在第一种情况下我做错了什么。

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.当可执行文件开始运行时, main的代码被重定位到不同的地址。

Because there is no code at 0x6b4 once the executable is relocated, GDB complains that it can't set a breakpoint there.因为一旦可执行文件被重新定位, 0x6b4处就没有代码,GDB 抱怨它无法在那里设置断点。

but when I do it with b 4 and run the code ,it is working normal.但是当我用 b 4 做它并运行代码时,它工作正常。

In this case, GDB understands that you want to set breakpoint on line 4, and inserts appropriate breakpoint after the executable has been relocated.在这种情况下,GDB 知道您要在第 4 行设置断点,并在可执行文件重新定位插入适当的断点。

Use info break to see what the relocated address is.使用info break来查看重定位的地址是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM