GDB命令

参考上位: http://blog.csdn.net/liigo/archive/2006/01/17/582231.aspx

GDB是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。

GDB中的命令固然很多,但我们只需掌握其中十个左右的命令,就大致可以完成日常的基本的程序调试工作。

命令具体解释

file <文件名>

加载被调试的可执行程序文件。
因为一般都在被调试程序所在目录下执行GDB,因而文本名不需要带路径。

(gdb) file TestExe

r

Run的简写,运行被调试的程序。
如果此前没有下过断点,则执行完整个程序;如果有断点,则程序暂停在第一个可用断点处。

(gdb) r

c

Continue的简写,继续执行被调试程序,直至下一个断点或程序结束。

(gdb) c

b

Breakpoint的简写,设置断点。两可以使用“行号”“函数名称”“执行地址”等方式指定断点位置。

b <行号>
b <函数名称>
b <代码地址> 

(gdb) b 8
(gdb) b main
(gdb) b *0x804835c 

(gdb)b router_policy.c:flux_build_msg
(gdb)b router_policy.c:行号


(gdb) info b

注意:b函数名称时C++要注意命名空间,所以b 行号是最好用的, b函数名称时

d

Delete breakpoint的简写,删除指定编号的某个断点,或删除所有断点。断点编号从1开始递增。

d [编号]

s

step缩写, 执行一行源程序代码,如果此行代码中有函数调用,则进入该函数

(gdb) s

注意: 必须在有源代码调试信息的情况下才可以使用(GCC编译时使用“-g”参数)

n

next缩写, 执行一行源程序代码,此行代码中的函数调用也一并执行

(gdb) n

注意: 必须在有源代码调试信息的情况下才可以使用(GCC编译时使用“-g”参数)

si

si命令类似于s命令, 所不同的是,这两个命令(si/ni)所针对的是汇编指令,而s/n针对的是源代码。

(gdb) si

ni

ni命令类似于n命令, 所不同的是,这两个命令(si/ni)所针对的是汇编指令,而s/n针对的是源代码。

(gdb) ni

p <变量名称>

Print的简写,显示指定变量(临时变量或全局变量)的值。

(gdb) p i
(gdb) p nGlobalVar

display

display,设置程序中断后欲显示的数据及其格式。
例如,如果希望每次程序中断后可以看到即将被执行的下一条汇编指令,可以使用命令

display  /i  $pc

其中 $pc 代表当前汇编指令,/i 表示以十六进行显示。当需要关心汇编代码时,此命令相当有用。

undisplay <编号>

undispaly,取消先前的display设置,编号从1开始递增。

(gdb) undisplay 1

help [命令名称]

GDB帮助命令,提供对GDB名种命令的解释说明。
如果指定了“命令名称”参数,则显示该命令的详细说明;如果没有指定参数,则分类显示所有GDB命令,供用户进一步浏览和查询。

(gdb) help display

i

Info的简写,用于显示各类信息,详情请查阅“help i”。

(gdb) i r
(gdb) info b

q

Quit的简写,退出GDB调试环境。

(gdb) q

工作中用到的

Gdb   attach   进程号
(gdb)p /x  *指针@长度                      //(“打印指针里面的内容按照指定长度且打印的是16进制”)
(gdb)info b //查看断点信息
(gdb)clear  //清空断点
(gdb)set print pretty on   //打开开关  打印数组
(gdb)where 						//查看堆栈信息
(gdb)bt							//查看堆栈信息
(gdb)bt  full
(gdb)thread apply all bt		//查看所有线程的堆栈信息
gdb -c core  程序

thread apply all bt 示例:

(gdb) thread apply all bt

Thread 4 (LWP 4873):
#0  0x0000ffff9115a344 in __lll_lock_wait () from /lib64/libpthread.so.0
#1  0x0000ffff91153650 in pthread_mutex_lock () from /lib64/libpthread.so.0
#2  0x0000000000b34eb0 in SmartMutexGuard::lock (guard=0x34b4720)
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/assist/../navicore-lib/include/assist/smart_mutex.h:30
#3  SmartMutexGuardAutoRelease::SmartMutexGuardAutoRelease (guard=0x34b4720, this=<synthetic pointer>)
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/assist/../navicore-lib/include/assist/smart_mutex.h:60
#4  SmartLogImpl::get (moduleName=0x13821f8 "navicore") at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/assist/src/smart_log_impl.cpp:837
#5  0x0000000000b2d220 in Mapbar_trace (text=0xffff8e6a8ad0 "src/platform_posix/timer_posix.cpp(84): einfo:[Mapdal] [FoxTimer]MapbarPosixFoxTimer_init end.")
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/mapdal/src/platform_posix/other_posix.cpp:100
#6  0x0000000000c4c258 in NcLog::writeVaList(MapbarLogLevel, char const*, int, char const*, char const*, char const*, std::__va_list) ()
#7  0x0000000000c4c704 in cq_log ()
#8  0x0000000000b29adc in MapbarPosixFoxTimer_init ()
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/mapdal/src/platform_posix/timer_posix.cpp:84
#9  0x0000000000b1e14c in Mapbar_mapdal_init ()
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/mapdal/src/platform_posix/mapdal_common_posix.cpp:438
#10 0x0000000000b687a8 in App_init ()
#11 0x0000000000aa4204 in MbApi::AppService::init (this=0x1817bf0 <MbApi::AppService::getInstance()::instance>)
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/mbapi/src/mbapi_app_service.cpp:103
#12 0x000000000087a60c in mapbar_client_main (argc=<optimized out>, argv=<optimized out>) at /root/21mm/Code/mbdrive/src/appmain/main.cpp:46
#13 0x0000000000b13d6c in ServiceManager::ServiceManagerStart_21MM::RunningMainThread (this=0x34b6260)
    at /root/21mm/Code/service_manager/sm/adaptor/wrapper/StartUp/21mm/serviceManagerNaviStartup_21MM.cpp:337
#14 0x0000000000b14798 in ServiceManager::ServiceManagerStart_21MM::OnPasStartUp (data=<optimized out>)
    at /root/21mm/Code/service_manager/sm/adaptor/wrapper/StartUp/21mm/serviceManagerNaviStartup_21MM.cpp:153
#15 0x0000ffff91150f78 in start_thread () from /lib64/libpthread.so.0
#16 0x0000ffff9045ad5c in thread_start () from /lib64/libc.so.6

Thread 3 (LWP 3952):
#0  0x0000ffff9045ae74 in epoll_pwait () from /lib64/libc.so.6
#1  0x0000ffff90d5da0c in pasFdHandler (hApp=hApp@entry=0xffff80000b20, efd=29) at NS_FrameworkCore/src/pas_dispatcher.cpp:1673
#2  0x0000ffff90d76894 in RunChildDispatcher (hChildApp=0xffff80000b20) at NS_FrameworkCore/src/pas_multithreading.cpp:524
#3  0x0000ffff90d76e00 in child_thread_proc (args=<optimized out>) at NS_FrameworkCore/src/pas_multithreading.cpp:199
#4  0x0000ffff91150f78 in start_thread () from /lib64/libpthread.so.0
#5  0x0000ffff9045ad5c in thread_start () from /lib64/libc.so.6

Thread 2 (LWP 3334):
#0  0x0000ffff9045ae74 in epoll_pwait () from /lib64/libc.so.6
#1  0x0000ffff90d5da0c in pasFdHandler (hApp=hApp@entry=0xffff88000b20, efd=17) at NS_FrameworkCore/src/pas_dispatcher.cpp:1673
#2  0x0000ffff90d76894 in RunChildDispatcher (hChildApp=0xffff88000b20) at NS_FrameworkCore/src/pas_multithreading.cpp:524
#3  0x0000ffff90d76e00 in child_thread_proc (args=<optimized out>) at NS_FrameworkCore/src/pas_multithreading.cpp:199
#4  0x0000ffff91150f78 in start_thread () from /lib64/libpthread.so.0
#5  0x0000ffff9045ad5c in thread_start () from /lib64/libc.so.6

Thread 1 (LWP 3279):
#0  0x0000000000b34e8c in SmartLogImpl::get (moduleName=0x1379f38 "servicemanager")
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/assist/src/smart_log_impl.cpp:843
#1  0x0000000000af063c in SMARTLOG_WRAPPER (levelString=levelString@entry=0x136e608 "INFO", moduleName=moduleName@entry=0x1379fb8 "NVSM", 
    fmt=fmt@entry=0x1379fc0 "Level[%s] Line[%d] Func[%s] %s") at /root/21mm/Code/service_manager/sm/cmn/serviceManagerOutPutLog.cpp:547
#2  0x0000000000af5ed0 in Navi_PAS_LOG_Start (logLevel=logLevel@entry=0x136e608 "INFO", line=line@entry=58, 
---Type <return> to continue, or q <return> to quit---
    funcname=funcname@entry=0x1417340 <ServiceManager::onUSBStatusChange(void*)::__FUNCTION__> "onUSBStatusChange", 
    fmt=fmt@entry=0x1417af0 "[UsbMediaManager] PasGetMsgDataOfSize stat[%d]") at /root/21mm/Code/service_manager/sm/cmn/serviceManagerOutPutLog.cpp:501
#3  0x0000000000ef9fe4 in ServiceManager::onUSBStatusChange (hApp=<optimized out>)
    at /root/21mm/Code/service_manager/sm/adaptor/wrapper/Addition/serviceManagerWrapper_usbMediaManager.cpp:58
#4  0x0000ffff90d56bf8 in boost::function1<ePasStatus, void*>::operator() (this=<optimized out>, a0=<optimized out>)
    at /usr/include/boost/function/function_template.hpp:769
#5  0x0000ffff90d57098 in PasProcessServiceProtocolCallback (hApp=0x34bcd40, pRequester=<optimized out>) at NS_FrameworkCore/src/pas_dispatcher.cpp:331
#6  0x0000ffff90d5712c in PasProcessServiceProtocol (hApp=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:355
#7  0x0000ffff90d5bc40 in PasDispatchProcess (hApp=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:783
#8  0x0000ffff90d5dcb8 in ProcessMq (hApp=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:1795
#9  pasFdHandler (hApp=hApp@entry=0x34bcd40, efd=<optimized out>) at NS_FrameworkCore/src/pas_dispatcher.cpp:1700
#10 0x0000ffff90d5e3e4 in RunDispatcher (hApp=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:1245
#11 0x0000ffff90d5e4f8 in PasDispatcherMain (hApp=hApp@entry=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:1271
#12 0x0000ffff90d5ff70 in PasDispatcherWithArguments (cAppName=cAppName@entry=0x13821f8 "navicore", argc=argc@entry=0, argv=argv@entry=0x0, 
    CbHandler=CbHandler@entry=0x19176b0 <ServiceManager::gPasCallBack>, cmdLineOptions=cmdLineOptions@entry=0x0) at NS_FrameworkCore/src/pas_dispatcher.cpp:998
#13 0x0000ffff90d60108 in PasDispatcher (cAppName=cAppName@entry=0x13821f8 "navicore", CbHandler=CbHandler@entry=0x19176b0 <ServiceManager::gPasCallBack>)
    at NS_FrameworkCore/src/pas_dispatcher.cpp:957
#14 0x0000000000870cd0 in main (argc=<optimized out>, argv=<optimized out>)
    at /root/21mm/Code/service_manager/sm/adaptor/wrapper/StartUp/21mm/serviceManagerNaviStartup_21MM.cpp:530
(gdb) 
(gdb) 
(gdb) 
(gdb) 
(gdb) bt full
#0  0x0000000000b34e8c in SmartLogImpl::get (moduleName=0x1379f38 "servicemanager")
    at /mapbar/data/jenkins/workspace/dalian-1-TOYOTA_21MM_ReleaseLinux/navicore_dl/assist/src/smart_log_impl.cpp:843
        iter = {_M_current = 0xffff84006fc0}
        ret = 0x0
#1  0x0000000000af063c in SMARTLOG_WRAPPER (levelString=levelString@entry=0x136e608 "INFO", moduleName=moduleName@entry=0x1379fb8 "NVSM", 
    fmt=fmt@entry=0x1379fc0 "Level[%s] Line[%d] Func[%s] %s") at /root/21mm/Code/service_manager/sm/cmn/serviceManagerOutPutLog.cpp:547
        __logger = <optimized out>
        valist = {__stack = 0xffffe9f70970, __gr_top = 0xffffe9f70970, __vr_top = 0xffffe9f70940, __gr_offs = -40, __vr_offs = -128}
        logbuf = "Level[INFO] Line[58] Func[onUSBStatusChange] [UsbMediaManager] PasGetMsgDataOfSize stat[0]", '\000' <repeats 1957 times>
        __FUNCTION__ = "SMARTLOG_WRAPPER"
#2  0x0000000000af5ed0 in Navi_PAS_LOG_Start (logLevel=logLevel@entry=0x136e608 "INFO", line=line@entry=58, 
    funcname=funcname@entry=0x1417340 <ServiceManager::onUSBStatusChange(void*)::__FUNCTION__> "onUSBStatusChange", 
    fmt=fmt@entry=0x1417af0 "[UsbMediaManager] PasGetMsgDataOfSize stat[%d]") at /root/21mm/Code/service_manager/sm/cmn/serviceManagerOutPutLog.cpp:501
        valist = {__stack = 0xffffe9f712b0, __gr_top = 0xffffe9f712b0, __vr_top = 0xffffe9f71290, __gr_offs = -32, __vr_offs = -128}
        logbuf = "[UsbMediaManager] PasGetMsgDataOfSize stat[0]", '\000' <repeats 2002 times>
        tp = {tv_sec = 21066360, tv_nsec = 84}
#3  0x0000000000ef9fe4 in ServiceManager::onUSBStatusChange (hApp=<optimized out>)
    at /root/21mm/Code/service_manager/sm/adaptor/wrapper/Addition/serviceManagerWrapper_usbMediaManager.cpp:58
        sts = ePasStatusOK
        devinfo = {dev_type = eUSB, bIsDeviceAvailable = 1, dev_info = {usb_info = {bus_no = 5 '\005', dev_no = 4 '\004', idVendor = 1921, idProduct = 21911, 
              reserved = "\000", manufacturerName = '\000' <repeats 255 times>, productName = '\000' <repeats 255 times>, serial_no = '\000' <repeats 255 times>, 
              deviceFile = "/dev/bus/usb/005/004", '\000' <repeats 235 times>}, sd_info = {cid = {manufacturerID = 5 '\005', applicationID = 1921, revision = 151 '\227', 
                serialNumber = 0, productName = "\000\000\000\000\000", reserve = "\000", manufactureDate = 0}, csd = {csd_structure = 0 '\000', taac = 0 '\000', 
                nsac = 0 '\000', tran_speed = 0 '\000', ccc = 0, read_bl_len = 0 '\000', read_bl_partial = 0 '\000', write_blk_misalign = 0 '\000', 
                read_blk_misalign = 0 '\000', dsr_imp = 0 '\000', reserve1 = 0 '\000', c_size = 0, vdd_r_curr_min = 0 '\000', vdd_r_curr_max = 0 '\000', 
                vdd_w_curr_min = 0 '\000', vdd_w_curr_max = 0 '\000', c_size_mult = 0 '\000', erase_blk_en = 0 '\000', sector_size = 0 '\000', wp_grp_size = 0 '\000', 
                wp_grp_enable = 0 '\000', r2w_factor = 0 '\000', write_bl_len = 0 '\000', write_bl_partial = 0 '\000', file_format_grp = 0 '\000', copy = 0 '\000', 
                perm_write_protect = 0 '\000', tmp_write_protect = 0 '\000', file_format = 0 '\000', reserve2 = "\000\000"}, deviceFile = '\000' <repeats 255 times>, 
              part_num = 0, nparts = 0}, disc_info = {deviceFile = "\005\004\201\a\227U", '\000' <repeats 249 times>, disc_type = eCD}, fusedav_info = {
              url = "\005\004\201\a\227U", '\000' <repeats 249 times>}}, deviceMountpath = "/nv/export/USB0", '\000' <repeats 240 times>, 
          filepathName = '\000' <repeats 255 times>, bIsFuseDav = 0, err_code = SS_DEV_OK, volume_info = {volume_label_availability = 1, 
            volume_label = "\313\316\323\361\267\345", '\000' <repeats 249 times>}}
        __FUNCTION__ = "onUSBStatusChange"
#4  0x0000ffff90d56bf8 in boost::function1<ePasStatus, void*>::operator() (this=<optimized out>, a0=<optimized out>)
    at /usr/include/boost/function/function_template.hpp:769
No locals.
#5  0x0000ffff90d57098 in PasProcessServiceProtocolCallback (hApp=0x34bcd40, pRequester=<optimized out>) at NS_FrameworkCore/src/pas_dispatcher.cpp:331
        spt_iterator = {_M_node = 0x34e2da0}
        session_iterator = <optimized out>
        pApp = 0x34bcd40
        s_iterator = <optimized out>
        eStatus = ePasStatusOK
#6  0x0000ffff90d5712c in PasProcessServiceProtocol (hApp=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:355
        pApp = 0x34bcd40
        eStatus = ePasStatusOK
#7  0x0000ffff90d5bc40 in PasDispatchProcess (hApp=0x34bcd40) at NS_FrameworkCore/src/pas_dispatcher.cpp:783
        pApp = 0x34bcd40
        start = {ru_utime = {tv_sec = 281474607033696, tv_usec = 281474607033696}, ru_stime = {tv_sec = 281474607033767, tv_usec = 281474607035743}, {
            ru_maxrss = 281474607033696, __ru_maxrss_word = 281474607033696}, {ru_ixrss = 281474607035743, __ru_ixrss_word = 281474607035743}, {ru_idrss = 0, 
            __ru_idrss_word = 0}, {ru_isrss = 0, __ru_isrss_word = 0}, {ru_minflt = 0, __ru_minflt_word = 0}, {ru_majflt = 0, __ru_majflt_word = 0}, {ru_nswap = 0, 
---Type <return> to continue, or q <return> to quit---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值