无法访问内存 - gdb [英] Cannot access memory - gdb

查看:613
本文介绍了无法访问内存 - gdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的disas代码:

 函数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

$ b

启动程序:/root/print.out
警告:
不能插入断点4.
无法访问地址0x6b4处的内存

但是当我用 b 4 完成并运行代码时,它正常工作。所以我在第一种情况下做错了什么。

解决方案


转储:
0x00000000000006b0< + 0> ;: push%rbp
0x00000000000006b1< + 1> ;: mov%rsp,%rbp


您正在查看独立于位置的可执行文件(一种特殊的共享库)。当可执行文件开始运行时, main 的代码将重定位到另一个地址。



因为一旦可执行文件被重新定位,在 0x6b4 处没有代码,GDB抱怨它不能在那里设置断点。


但是当我用b 4执行并运行代码时,它正常工作。


在这种情况下,GDB知道您要在第4行设置断点,并在之后插入适当的断点 >可执行文件已被重新定位。



使用 info break 查看重新定位的地址是什么。


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.

解决方案

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.

这篇关于无法访问内存 - gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆