GDB出现value has been optimized out这个错误,gcc编译选项已经更改为O0仍同样错误

zaixiankaifa 2019-03-04 08:15:52
#include <stdio.h>

int i=0;

int main(void)
{
i=3;
printf("i is %d.\n",i);

i=5;

printf("i is %d.\n",i);
return 0;
}

[GDB]gcc -g -Wall -O0 watch.c -o watch
[GDB]
[GDB] gdb watch
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/thomas/Linux_Pra_Fast/GDB/watch...done.
(gdb) break main
Breakpoint 1 at 0x4004e6: file watch.c, line 7.
(gdb) watch i > 4
Hardware watchpoint 2: i > 4
(gdb) run
Starting program: /home/thomas/Linux_Pra_Fast/GDB/watch
Error in re-setting breakpoint 2: value has been optimized out
value has been optimized out
dl_main (phdr=<optimized out>, phdr@entry=0x400040, phnum=<optimized out>,
phnum@entry=9, user_entry=user_entry@entry=0x7fffffffdc88,
auxv=<optimized out>) at rtld.c:2286
2286 _dl_unload_cache ();
(gdb)



在CentOS 7 使用gdb调试程序的时候,发现老是出现value has been optimized out这个错误无法设置监视点,gdb版本为:
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7

[GDB] gdb -v
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.


[GDB] gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
Thread model: posix
gcc version 8.1.0 (GCC)


在网上查找到的解决办法说是gcc编译的时候默认选择O2选项,已经更改为O0选项还是报同样错误。
麻烦大神指点。。。。。
[/color]
...全文
1724 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,118

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧