gdb 带参数调试可执行文件程序

1、在 gdb 里带参数运行可执行文件程序

使用如下命令

gdb --args ./my_program 参数1 参数1

此时终端会进入 gdb 界面,如下

GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.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 "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 Mono...(no debugging symbols found)...done.
(gdb)

在 gdb 界面输入 run 然后回车,程序开始运行。

2、调试

假设程序此时已经出错自动暂停,界面仍然是 gdb 界面,使用 bt 命令即可开始 backtrace 程序出错的地方。示例输出如下:

(gdb) bt
#0  0x00007ffff37ecfd0 in __GI___pthread_mutex_lock (mutex=0x707070707070957) at ../nptl/pthread_mutex_lock.c:67
#1  0x00007ffff668580d in void std::lock<std::unique_lock<std::mutex>, std::unique_lock<std::mutex>>(std::unique_lock<std::mutex>&, std::unique_lock<std::mutex>&) ()
    at /home/nav/catkin_ws/src/orbslam3/orbslam3/../lib/libORB_SLAM3.so
#2  0x00007ffff668174f in ORB_SLAM3::MapPoint::isBad() () at /home/nav/catkin_ws/src/orbslam3/orbslam3/../lib/libORB_SLAM3.so
#3  0x00007ffff6697f5f in ORB_SLAM3::Map::PreSave(std::set<ORB_SLAM3::GeometricCamera*, std::less<ORB_SLAM3::GeometricCamera*>, std::allocator<ORB_SLAM3::GeometricCamera*> >&) () at /home/nav/catkin_ws/src/orbslam3/orbslam3/../lib/libORB_SLAM3.so
#4  0x00007ffff66951f5 in ORB_SLAM3::Atlas::PreSave() () at /home/nav/catkin_ws/src/orbslam3/orbslam3/../lib/libORB_SLAM3.so
#5  0x00007ffff65f54f2 in ORB_SLAM3::System::SaveAtlas(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) ()
    at /home/nav/catkin_ws/src/orbslam3/orbslam3/../lib/libORB_SLAM3.so
#6  0x0000555555567ebf in main ()

其中每行开头数字越大表示越外层,越小表示越接近出错的具体代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值