汇编报错:Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x1135 解决办法(先不打断点run一遍)

470 篇文章 72 订阅
6 篇文章 1 订阅

在linux下用gdb打断点调试发现报错了:

(gdb) run
Starting program: /home/dontla/桌面/test/test 
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x1135

解决办法:

先退出GDB

(gdb) quit
A debugging session is active.

	Inferior 1 [process 32756] will be killed.

Quit anyway? (y or n) 
dontla@dontla-virtual-machine:~/桌面/test$ c

然后用gdb打开程序先run一遍再打断点调试:

dontla@dontla-virtual-machine:~/桌面/test$ gdb ./test
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
(No debugging symbols found in ./test)
(gdb) run
Starting program: /home/dontla/桌面/test/test 
[Inferior 1 (process 32770) exited with code 03]
(gdb) disas main
Dump of assembler code for function main:
   0x0000555555555130 <+0>:	mov    $0x1,%eax
   0x0000555555555135 <+5>:	mov    $0x2,%ebx
   0x000055555555513a <+10>:	add    %ebx,%eax
   0x000055555555513c <+12>:	retq   
   0x000055555555513d <+13>:	nopl   (%rax)
End of assembler dump.
(gdb) break *0x0000555555555135
Breakpoint 1 at 0x555555555135
(gdb) run
Starting program: /home/dontla/桌面/test/test 

Breakpoint 1, 0x0000555555555135 in main ()
(gdb) 

这是因为:

原因在于数据断点的设置有误。在没有用gdb运行(run)过可执行程序之前,使用disasemble指令反汇编出来的汇编语言的左边的地址偏移地址,不是逻辑地址。所以,即使break指令能够设置断点,当GDB运行时也不可能访问到这个地址。也就会出现上面的错误。
数据断点:给某个内存地址设置断点,改变该地址所装内容时会触发断点,运行到该地址时会触发断点。(从网上看的,参考)
而学过操作系统或者微机原理就该知道,程序给出来的只是逻辑地址,不可能直接给物理地址的,物理地址都是由系统将其映射成了逻辑地址。

参考文章:GDB数据数据断(内存断点)报错:Warning: Cannot insert breakpoint

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dontla

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值