gdb optimized out错误解决

本文介绍在使用GDB进行Linux程序调试时遇到的问题及解决办法。当使用较高优化等级(如-O2、-O3等)编译程序时,可能会导致GDB无法正确显示变量值或误导源代码行。解决此问题的最佳方式是将编译选项改为-O0,即禁用所有优化,以确保调试信息的准确性。

 转自:http://blog.youkuaiyun.com/cws1214/article/details/12023093

 

when linux gdb debug, print a variable, such as i,  by command p i;

 

The gdb output  value optimized out.

 

The solution for the problem is off the compile optimation option -Ox,  x note digital, such 2, 3, 4 etc

 

The better way is that changing -Ox to -O0.

The -O0 denotes there is no optimization. It will avoid gdb mislead source code line issue.

转载于:https://www.cnblogs.com/x_wukong/p/5711287.html

277 CMenu::~CMenu() (gdb) s 279 } (gdb) s 277 CMenu::~CMenu() (gdb) s std::vector<CMenu::Item, std::allocator<CMenu::Item> >::~vector (this=0x7fff91c2aa00, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:414 414 ~vector() _GLIBCXX_NOEXCEPT (gdb) s 415 { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, (gdb) s _Destroy<CMenu::Item*, CMenu::Item> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:415 415 { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, (gdb) s _Destroy<CMenu::Item*> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_construct.h:126 126 std::_Destroy_aux<__has_trivial_destructor(_Value_type)>:: (gdb) finish Run till exit from #0 _Destroy<CMenu::Item*> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_construct.h:126 std::vector<CMenu::Item, std::allocator<CMenu::Item> >::~vector (this=0x7fff91c2aa00, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:414 414 ~vector() _GLIBCXX_NOEXCEPT (gdb) s 415 { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, (gdb) s _Destroy<CMenu::Item*, CMenu::Item> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:415 415 { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, (gdb) s _Destroy<CMenu::Item*> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_construct.h:126 126 std::_Destroy_aux<__has_trivial_destructor(_Value_type)>:: (gdb) finish Run till exit from #0 _Destroy<CMenu::Item*> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_construct.h:126 std::vector<CMenu::Item, std::allocator<CMenu::Item> >::~vector (this=0x7fff91c2aa00, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:416 416 _M_get_Tp_allocator()); } (gdb) s ~_Vector_base (this=0x7fff91c2aa00, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:161 161 - this->_M_impl._M_start); } (gdb) s 160 { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage (gdb) s _M_deallocate (this=<optimized out>, __n=4, __p=0x10e3a250) at /usr/include/c++/4.8.2/bits/stl_vector.h:173 173 if (__p) (gdb) s 174 _M_impl.deallocate(__p, __n); (gdb) s deallocate (this=<optimized out>, __p=0x10e3a250) at /usr/include/c++/4.8.2/ext/new_allocator.h:110 110 { ::operator delete(__p); } (gdb) s std::vector<CMenu::Item, std::allocator<CMenu::Item> >::~vector (this=0x7fff91c2aa00, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:416 416 _M_get_Tp_allocator()); } (gdb) s ~_Vector_base (this=<optimized out>, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/stl_vector.h:416 416 _M_get_Tp_allocator()); } (gdb) s _M_deallocate (this=<optimized out>, __n=<optimized out>, __p=0x10e3a250) at /usr/include/c++/4.8.2/bits/stl_vector.h:416 416 _M_get_Tp_allocator()); } (gdb) s deallocate (this=<optimized out>, __p=0x10e3a250) at /usr/include/c++/4.8.2/ext/new_allocator.h:110 110 { ::operator delete(__p); } (gdb) s 0x00007f336d1d62e0 in operator delete(void*) () from /lib64/libstdc++.so.6 (gdb) finish Run till exit from #0 0x00007f336d1d62e0 in operator delete(void*) () from /lib64/libstdc++.so.6 main (argc=<optimized out>, argv=<optimized out>) at Src/mkconfig.cpp:2161 2161 } (gdb) s 0x00007f336c8b5555 in __libc_start_main () from /lib64/libc.so.6 (gdb) s Single stepping until exit from function __libc_start_main, which has no line number information. pure virtual method called terminate called without an active exception Program received signal SIGABRT, Aborted. 0x00007f336c8c9387 in raise () from /lib64/libc.so.6
08-31
sunhaoming@ubuntu:~/nvr_re/nvr_2025$ sstar931/toolchain/bin/arm-sigmastar-linux-uclibcgnueabihf-gdb torchlight/build_dir/target-arm-openwrt-linux-uclibcgnueabihf/nvr_work/nvr_work /home/sunhaoming/nvr_re/nvr_work.1237.11.1757330061.core GNU gdb (crosstool-NG 1.24.0) 8.2.1 Copyright (C) 2018 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 "--host=x86_64-build_pc-linux-gnu --target=arm-sigmastar-linux-uclibcgnueabihf". 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 torchlight/build_dir/target-arm-openwrt-linux-uclibcgnueabihf/nvr_work/nvr_work...done. [New LWP 1237] warning: Could not load shared library symbols for 9 libraries, e.g. /usr/lib/libtrace_alloc.so. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? Core was generated by `nvr_work'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0001081c in ubus_nvr_work_null_ptr_cb (context=<optimized out>, obj=<optimized out>, req=<optimized out>, method=<optimized out>, msg=0x2207c) at nvr_work_ubus.c:69 69 printf("%d\n", (*ptr)); /*解引用空指针发生段错误*/ (gdb) bt #0 0x0001081c in ubus_nvr_work_null_ptr_cb (context=<optimized out>, obj=<optimized out>, req=<optimized out>, method=<optimized out>, msg=0x2207c) at nvr_work_ubus.c:69 #1 0xb6ee39c4 in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?)
最新发布
09-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值