gdb

Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6_6.9.x86_64 libgcc-4.4.7-11.el6.x86_64 libstdc++-4.4.7-11.el6.x86_64 zlib-1.2.3-29.el6.x86_64
(gdb) bt
#0  0x00007f5de36f6625 in raise () from /lib64/libc.so.6
#1  0x00007f5de36f7e05 in abort () from /lib64/libc.so.6
#2  0x00007f5de4834a7d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6
#3  0x00007f5de4832bd6 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00007f5de4832c03 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5  0x00007f5de4832c86 in __cxa_rethrow () from /usr/lib64/libstdc++.so.6
#6  0x000000000041817c in SharedPtr<TeacherObj, ReferenceCounter, ReleasePolicy<TeacherObj> >::deref (this=0x7f5ddabfcad0)
    at /home/diego/work/branch0901_shengwang/rtqa_center/source/..//source/tmbase/utils/include/SharedPtr.h:356
#7  0x00000000004177c0 in SharedPtr<TeacherObj, ReferenceCounter, ReleasePolicy<TeacherObj> >::operator-> (this=0x7f5ddabfcad0)
    at /home/diego/work/branch0901_shengwang/rtqa_center/source/..//source/tmbase/utils/include/SharedPtr.h:209
#8  0x000000000041e7f6 in CmdTcGetMsp::OnCallBack (this=0x7f5db8000cb0, msg=0x7f5db8002b70) at CmdTeacher.cpp:208
#9  0x000000000040d40a in CommonHandler::OnResponse (this=0x7f5db80043e0, response=...) at BaseMsg.cpp:77
#10 0x000000000040e672 in client::replyhandle (req=0x7f5db8001400, arg=0x7f5db80043e0) at client.cpp:42
#11 0x00007f5de4ec4b41 in evhttp_connection_done (evcon=0x7f5db8000f00) at http.c:817
#12 0x00007f5de4ec5158 in evhttp_read_body (evcon=0x7f5db8000f00, req=0x7f5db8001400) at http.c:964
#13 0x00007f5de4ec5858 in evhttp_get_body (evcon=0x7f5db8000f00, req=0x7f5db8001400) at http.c:1969
#14 0x00007f5de4eb4ee5 in bufferevent_readcb (fd=<value optimized out>, event=<value optimized out>, arg=0x7f5db8001090) at bufferevent_sock.c:186
#15 0x00007f5de4eace0c in event_process_active_single_queue (base=0x1b281a0, flags=0) at event.c:1350
#16 event_process_active (base=0x1b281a0, flags=0) at event.c:1420
#17 event_base_loop (base=0x1b281a0, flags=0) at event.c:1621
#18 0x000000000040e817 in client::httpclient::runeventloop (arg=0x1b281a0) at client.cpp:65
#19 0x00007f5de4a839d1 in start_thread () from /lib64/libpthread.so.0
#20 0x00007f5de37ac8fd in clone () from /lib64/libc.so.6
(gdb) f 8
#8  0x000000000041e7f6 in CmdTcGetMsp::OnCallBack (this=0x7f5db8000cb0, msg=0x7f5db8002b70) at CmdTeacher.cpp:208
208     CmdTeacher.cpp: No such file or directory.
        in CmdTeacher.cpp
(gdb) 
(gdb) p httpRes
$1 = (OrderGetMspRes *) 0x7f5db8002b70
(gdb) p *httpRes
$2 = {<HttpRespMsg> = {<BaseMsg> = {_vptr.BaseMsg = 0x51e790, msgType = BaseMsg::OR_GET_MSP, errNo = 0, errMsg = ""}, <No data fields>}, errorMsg = "", statuscode = 1, msp = 4, operId = 
    "shengwang"}
(gdb) p st
$3 = {_pCounter = 0x7f5db4002b10, _ptr = 0x7f5db4001940}
(gdb) p *st
Could not find operator*.
(gdb) p tc
$4 = {_pCounter = 0x7f5dcc0017c0, _ptr = 0x0}
(gdb) 

 

我们可以通过  1)  gdb prog_name -> r               用在逐步调试自己的程序时

                    2)  gdb -> attach process_id       正在运行中的后台程序突然卡在了某个地方,先ps再gdb/attach

                    3)  gdb prog_name core              程序core掉了

三种方式对一个程序进行调试;

 

1. thread——gdb 多线程调试命令:

 

     info threads:           显示当前进程中的线程;

     thread thread_no:  进入线程xx,通常紧接而来的是 bt/f 命令;

 

(gdb) info threads
  19 Thread 0x7f9024dfa700 (LWP 26847)  0x00007f9038295ef3 in epoll_wait () from /lib64/libc.so.6
  18 Thread 0x7f901e1fc700 (LWP 26851)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  17 Thread 0x7f901ffff700 (LWP 26848)  0x00007f9038295ef3 in epoll_wait () from /lib64/libc.so.6
  16 Thread 0x7f9035792700 (LWP 26840)  0x00007f9038295ef3 in epoll_wait () from /lib64/libc.so.6
  15 Thread 0x7f90261fc700 (LWP 26845)  0x00007f903828c0d3 in poll () from /lib64/libc.so.6
  14 Thread 0x7f901f5fe700 (LWP 26849)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  13 Thread 0x7f9027fff700 (LWP 26842)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  12 Thread 0x7f90257fb700 (LWP 26846)  0x00007f90395705bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  11 Thread 0x7f9026bfd700 (LWP 26844)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  10 Thread 0x7f9036b94700 (LWP 26838)  0x00007f903828e373 in select () from /lib64/libc.so.6
  9 Thread 0x7f901cdfa700 (LWP 26853)  0x00007f90395705bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  8 Thread 0x7f90275fe700 (LWP 26843)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  7 Thread 0x7f9034d91700 (LWP 26841)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  6 Thread 0x7f9036193700 (LWP 26839)  0x00007f903828e373 in select () from /lib64/libc.so.6
  5 Thread 0x7f903a0ec720 (LWP 26827)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  4 Thread 0x7f9037595700 (LWP 26837)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
  3 Thread 0x7f901d7fb700 (LWP 26852)  0x00007f903828c0d3 in poll () from /lib64/libc.so.6
  2 Thread 0x7f9037f96700 (LWP 26835)  0x00007f9038259a3d in nanosleep () from /lib64/libc.so.6
* 1 Thread 0x7f901ebfd700 (LWP 26850)  0x00007f900c129300 in ?? ()

 

查看所有线程的调用栈信息 

(gdb) thread apply all bt

Thread 19 (Thread 0x7f45f72a2700 (LWP 27863)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x00000000005035f8 in TTLogEx::WriteLogThread (ptr=0x0) at TTLogEx.cpp:61
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b82d00) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 18 (Thread 0x7f45f68a1700 (LWP 27865)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x00000000005048e0 in TTLogOp::WriteLogThread (ptr=0x0) at TTLogOp.cpp:62
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b8ac70) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 17 (Thread 0x7f45f5ea0700 (LWP 27866)):
#0  0x00007f45f759a373 in select () from /lib64/libc.so.6
#1  0x00007f45f7cf5fbc in SU_sleep (seconds=1, micro_seconds=0) at ../platform/linux/platform.cpp:369
#2  0x00007f45f7cf53c0 in SchedManager::run (this=0x1b88410) at su_sched_manager.cpp:177
#3  0x00007f45f7cf4e6a in run_func (args=0x1b88410) at su_sched_manager.cpp:50
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 16 (Thread 0x7f45f549f700 (LWP 27867)):
#0  0x00007f45f759a373 in select () from /lib64/libc.so.6
#1  0x00007f45f7cf5e7f in SU_recvfrom (fd=5, addr=0x7f45f549ee30, buf=0x7f45f00008c0, len=1376, ms=5) at ../platform/linux/platform.cpp:340
#2  0x00007f45f7cf26d4 in SchedRPC::run (this=0x1b8a280) at su_sched.cpp:328
#3  0x00007f45f7cf1a27 in rpc_func (args=0x1b8a280) at su_sched.cpp:47
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 15 (Thread 0x7f45effff700 (LWP 27868)):
#0  0x00007f45f75a1ef3 in epoll_wait () from /lib64/libc.so.6
#1  0x00007f45f8cb5326 in epoll_dispatch (base=0x1b851c0, tv=<value optimized out>) at epoll.c:407
#2  0x00007f45f8ca3ac6 in event_base_loop (base=0x1b851c0, flags=0) at event.c:1607
#3  0x000000000040e9a7 in client::httpclient::runeventloop (arg=0x1b851c0) at client.cpp:65
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
---Type <return> to continue, or q <return> to quit---  
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 14 (Thread 0x7f45ef5fe700 (LWP 27869)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x000000000042d944 in ThreadDistribute (para=0x0) at OrderManager.cpp:1054
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b868d0) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 13 (Thread 0x7f45eebfd700 (LWP 27870)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x000000000042d987 in ThreadTimer (para=0x0) at OrderManager.cpp:1067
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b84b80) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 12 (Thread 0x7f45ee1fc700 (LWP 27871)):
#0  0x00007f45f75980d3 in poll () from /lib64/libc.so.6
#1  0x000000000052f6c2 in do_io (v=0x7f45e80018d0) at src/mt_adaptor.c:387
#2  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#3  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 11 (Thread 0x7f45ed7fb700 (LWP 27872)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x00000000004908a7 in ThreadStudentDelayDel (para=0x0) at StudentManager.cpp:30
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b86e80) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 10 (Thread 0x7f45ecdfa700 (LWP 27873)):
#0  0x00007f45f887e5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x000000000052f4ab in do_completion (v=0x7f45e80018d0) at src/mt_adaptor.c:463
#2  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#3  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 9 (Thread 0x7f45dbfff700 (LWP 27874)):
---Type <return> to continue, or q <return> to quit---
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x00000000004e3b81 in ThreadTeacher (para=0x0) at TeacherManager.cpp:29
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b8e390) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 8 (Thread 0x7f45db5fe700 (LWP 27875)):
#0  0x00007f45f75a1ef3 in epoll_wait () from /lib64/libc.so.6
#1  0x00007f45f8cb5326 in epoll_dispatch (base=0x1b85820, tv=<value optimized out>) at epoll.c:407
#2  0x00007f45f8ca3ac6 in event_base_loop (base=0x1b85820, flags=0) at event.c:1607
#3  0x000000000051012a in TTLibEvent::RunEventLoop (ptr=0x1b85820) at TTLibEvent.cpp:49
#4  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b857f0) at thread.cpp:125
#5  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#6  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 7 (Thread 0x7f45dabfd700 (LWP 27876)):
#0  0x00007f45f75a1ef3 in epoll_wait () from /lib64/libc.so.6
#1  0x00007f45f8cb5326 in epoll_dispatch (base=0x1b8ca30, tv=<value optimized out>) at epoll.c:407
#2  0x00007f45f8ca3ac6 in event_base_loop (base=0x1b8ca30, flags=0) at event.c:1607
#3  0x000000000051012a in TTLibEvent::RunEventLoop (ptr=0x1b8ca30) at TTLibEvent.cpp:49
#4  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b88ac0) at thread.cpp:125
#5  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#6  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 6 (Thread 0x7f45da1fc700 (LWP 27877)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f759abe4 in usleep () from /lib64/libc.so.6
#2  0x0000000000505c2f in TTWorkThread::run (this=0x1b83cc0) at TTServiceManager.cpp:52
#3  0x0000000000513b12 in Thread::runnable_entry (pThread=0x1b83cc0) at thread.cpp:99
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 5 (Thread 0x7f45d97fb700 (LWP 27878)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f759abe4 in usleep () from /lib64/libc.so.6
#2  0x0000000000505c2f in TTWorkThread::run (this=0x1b8f5e0) at TTServiceManager.cpp:52
#3  0x0000000000513b12 in Thread::runnable_entry (pThread=0x1b8f5e0) at thread.cpp:99
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
---Type <return> to continue, or q <return> to quit---
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 4 (Thread 0x7f45d8dfa700 (LWP 27879)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f759abe4 in usleep () from /lib64/libc.so.6
#2  0x0000000000505dff in TTServiceManager::RunEventThread (ptr=0x0) at TTServiceManager.cpp:100
#3  0x0000000000513bbc in Thread::callable_entry (pThread=0x1b8f750) at thread.cpp:125
#4  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#5  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 3 (Thread 0x7f45c3fff700 (LWP 27880)):
#0  0x00007f45f75980d3 in poll () from /lib64/libc.so.6
#1  0x000000000052f6c2 in do_io (v=0x1ba0410) at src/mt_adaptor.c:387
#2  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#3  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 2 (Thread 0x7f45c35fe700 (LWP 27881)):
#0  0x00007f45f887e5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x000000000052f4ab in do_completion (v=0x1ba0410) at src/mt_adaptor.c:463
#2  0x00007f45f887a9d1 in start_thread () from /lib64/libpthread.so.0
#3  0x00007f45f75a18fd in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7f45f93fa720 (LWP 27852)):
#0  0x00007f45f7565a3d in nanosleep () from /lib64/libc.so.6
#1  0x00007f45f75658b0 in sleep () from /lib64/libc.so.6
#2  0x0000000000424952 in main (argc=2, argv=0x7fffb45355c8) at main.cpp:166

 

一、多线程调试
1. 多线程调试,最重要的几个命令:
info threads                        查看当前进程的线程。
                                          GDB会为每个线程分配一个ID, 后面操作线程的时候会用到这个ID.
                                          前面有*的是当前调试的线程.
thread                      切换调试的线程为指定ID的线程。
break file.c:100 thread all    在file.c文件第100行处为所有经过这里的线程设置断点。
set scheduler-locking off|on|step    
      在使用step或者continue命令调试当前被调试线程的时候,其他线程也是同时执行的,
      怎么只让被调试程序执行呢?
      通过这个命令就可以实现这个需求。
         off      不锁定任何线程,也就是所有线程都执行,这是默认值。
         on       只有当前被调试程序会执行。
         step     在单步的时候,除了next过一个函数的情况
                  (熟悉情况的人可能知道,这其实是一个设置断点然后continue的行为)以外,
                  只有当前线程会执行。
thread apply ID1 ID2 command        让一个或者多个线程执行GDB命令command
thread apply all command            让所有被调试线程执行GDB命令command。

2. 使用示例:
线程产生通知:在产生新的线程时, gdb会给出提示信息
(gdb) r
Starting program: /root/thread 
[New Thread 1073951360 (LWP 12900)] 
[New Thread 1082342592 (LWP 12907)]---以下三个为新产生的线程
[New Thread 1090731072 (LWP 12908)]
[New Thread 1099119552 (LWP 12909)]

查看线程:使用info threads可以查看运行的线程。
(gdb) info threads
  4 Thread 1099119552 (LWP 12940)   0xffffe002 in ?? ()
  3 Thread 1090731072 (LWP 12939)   0xffffe002 in ?? ()
  2 Thread 1082342592 (LWP 12938)   0xffffe002 in ?? ()
* 1 Thread 1073951360 (LWP 12931)   main (argc=1, argv=0xbfffda04) at thread.c:21
(gdb)
注意,行首为gdb分配的线程ID号,对线程进行切换时,使用该ID号码。
另外,行首的星号标识了当前活动的线程
切换线程:
使用 thread THREADNUMBER 进行切换,THREADNUMBER 为上文提到的线程ID号。
下例显示将活动线程从 1 切换至 4。
(gdb) info threads
   4 Thread 1099119552 (LWP 12940)   0xffffe002 in ?? ()
   3 Thread 1090731072 (LWP 12939)   0xffffe002 in ?? ()
   2 Thread 1082342592 (LWP 12938)   0xffffe002 in ?? ()
* 1 Thread 1073951360 (LWP 12931)   main (argc=1, argv=0xbfffda04) at thread.c:21
(gdb) thread 4
[Switching to thread 4 (Thread 1099119552 (LWP 12940))]#0   0xffffe002 in ?? ()
(gdb) info threads
* 4 Thread 1099119552 (LWP 12940)   0xffffe002 in ?? ()
   3 Thread 1090731072 (LWP 12939)   0xffffe002 in ?? ()
   2 Thread 1082342592 (LWP 12938)   0xffffe002 in ?? ()
   1 Thread 1073951360 (LWP 12931)   main (argc=1, argv=0xbfffda04) at thread.c:21
(gdb)
以上即为使用gdb提供的对多线程进行调试的一些基本命令。
另外,gdb也提供对线程的断点设置以及对指定或所有线程发布命令的命令

二、调试宏
在GDB下, 我们无法print宏定义,因为宏是预编译的。
但是我们还是有办法来调试宏,这个需要GCC的配合。
在GCC编译程序的时候,加上
  -ggdb3   参数,这样,你就可以调试宏了。

另外,你可以使用下述的GDB的宏调试命令 来查看相关的宏。
info macro   查看这个宏在哪些文件里被引用了,以及宏定义是什么样的。
macro         查看宏展开的样子。

三、源文件
GDB时,提示找不到源文件。
需要做下面的检查:
编译程序员是否加上了 -g参数 以包含debug信息。
路径是否设置正确了。
使用GDB的directory命令来设置源文件的目录。

下面给一个调试/bin/ls的示例(ubuntu下)
$ apt-get source coreutils
$ sudo apt-get install coreutils-dbgsym
$ gdb /bin/ls
GNU gdb (GDB) 7.1-ubuntu
(gdb) list main
1192    ls.c: No such file or directory.
in ls.c
(gdb) directory ~/src/coreutils-7.4/src/
Source directories searched: /home/hchen/src/coreutils-7.4:$cdir:$cwd
(gdb) list main
1192        }
1193    }
1194
1195    int
1196    main (int argc, char **argv)
1197    {
1198      int i;
1199      struct pending *thispend;
1200      int n_files;
1201

四、条件断点
条件断点是语法是:
  break  [where] if [condition]
这种断点真是非常管用。
尤其是在一个循环或递归中,或是要监视某个变量。
注意,这个设置是在GDB中的,只不过每经过那个断点时GDB会帮你检查一下条件是否满足。

五、命令行参数
有时候,我们需要调试的程序需要有命令行参数, 有三种方法:
gdb命令行的 -args 参数
gdb环境中   set args命令。
gdb环境中   run 参数

六、gdb的变量
有时候,在调试程序时,我们不单单只是查看运行时的变量,
我们还可以直接设置程序中的变量,以模拟一些很难在测试中出现的情况,比较一些出错,
或是switch的分支语句。使用set命令可以修改程序中的变量。
另外,你知道gdb中也可以有变量吗?
就像shell一样,gdb中的变量以$开头,比如你想打印一个数组中的个个元素,你可以这样:
(gdb) set $i = 0
(gdb) p a[$i++]
...  #然后就一路回车下去了
当然,这里只是给一个示例,表示程序的变量和gdb的变量是可以交互的。

七、x命令
也许,你很喜欢用p命令。
所以,当你不知道变量名的时候,你可能会手足无措,因为p命令总是需要一个变量名的。
x命令是用来查看内存的,在gdb中 “help x” 你可以查看其帮助。
x/x 以十六进制输出
x/d 以十进制输出
x/c 以单字符输出
x/i  反汇编 – 通常,我们会使用 x/10i $ip-20 来查看当前的汇编($ip是指令寄存器)
x/s 以字符串输出

八、command命令
如何自动化调试。
这里向大家介绍command命令,简单的理解一下,其就是把一组gdb的命令打包,有点像字处理软件的“宏”。
下面是一个示例:
(gdb) break func
Breakpoint 1 at 0x3475678: file test.c, line 12.
(gdb) command 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>print arg1
>print arg2
>print arg3
>end
(gdb)
当我们的断点到达时,自动执行command中的三个命令,把func的三个参数值打出来。

 

 

使用gdb ctrl 是有时候会报错,找不到相应的so文件,这个时候可以这样做

1 编辑/etc/ld.so.conf 文件,将so所在的位置加到/etc/ld.so.conf文件中。

2 ldconfig ,使之生效。

 

 ldconfig是一个动态链接库管理命令

  为了让动态链接库为系统所共享,还需运行动态链接库的管理命令--ldconfig

  ldconfig  命令的用途,主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态 链接库(格式如前介绍,lib*.so*),进而创建出动态装入程序(ld.so)所需的连接和缓存文件.缓存文件默认为  /etc/ld.so.cache,此文件保存已排好序的动态链接库名字列表.

  ldconfig通常在系统启动时运行,而当用户安装了一个新的动态链接库时,就需要手工运行这个命令.

posted @ 2015-09-08 20:14  穆穆兔兔  阅读(1284)  评论(0编辑  收藏  举报