#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]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/154892.html
標籤:應用程序開發區
上一篇:虛擬機作業
下一篇:linux
