多程序 多執行緒除錯

2021-08-02 16:19:10 字數 4127 閱讀 7082

//啟動gdb除錯

#gdb ./jccc 

//設定預設跟蹤子程序

(gdb) set follow-fork-mode child

//設定當程式在gdb中停止,只有當前的執行緒會被停止,而其他的執行緒將會繼續執行(gdb預設程序的所有執行緒都會停止)

(gdb) set non-stop on

//接下來設定斷點

(gdb) b processcore.cpp:454

//執行jccc程式

(gdb) r -c /home/xiongli/workspace/paas/jchang/jc.conf

starting program: /home/xiongli/workspace/paas/jchang/jccc -c /home/xiongli/workspace/paas/jchang/jc.conf

[thread debugging using libthread_db enabled]

using host libthread_db library "/lib64/libthread_db.so.1".

setrlimit 500000 ok

[new process 989]

[thread debugging using libthread_db enabled]

using host libthread_db library "/lib64/libthread_db.so.1".

[new thread 0x7ffff7aef700 (lwp 990)]

[thread 0x7ffff7aef700 (lwp 990) exited]

[tcsetpgrp failed in terminal_inferior: no such process]

[new thread 0x7ffff7aef700 (lwp 991)]

[new thread 0x7ffff6ed0700 (lwp 992)]

[new thread 0x7ffff64cf700 (lwp 994)]

[new thread 0x7ffff5ace700 (lwp 995)]

[new thread 0x7ffff50cd700 (lwp 996)]

[new thread 0x7fffeffff700 (lwp 997)]

[new thread 0x7fffef5fe700 (lwp 998)]

[new thread 0x7fffeebfd700 (lwp 999)]

(這裡我們看到4個執行緒因為斷點停住了,其他執行緒如期執行)

thread 2.8 "jccc" hit breakpoint 1, thread_processor (lpvoid=0x70f5e0) at processcore.cpp:454

warning: source file is more recent than executable.

454                             if(!g_processcore.m_mobilelist.isvalid(fd))

(gdb) 

(gdb) 

(gdb) 

thread 2.9 "jccc" hit breakpoint 1, thread_processor (lpvoid=0x70fbb0) at processcore.cpp:454

454                             if(!g_processcore.m_mobilelist.isvalid(fd))

thread 2.10 "jccc" hit breakpoint 1, thread_processor (lpvoid=0x710190) at processcore.cpp:454

454                             if(!g_processcore.m_mobilelist.isvalid(fd))

thread 2.7 "jccc" hit breakpoint 1, thread_processor (lpvoid=0x70edb0) at processcore.cpp:454

454 

//檢視一下所有執行緒資訊

(gdb) info threads

id   target id         frame 

2.1  thread 0x7ffff7af17e0 (lwp 989) "jccc" (running)

2.3  thread 0x7ffff7aef700 (lwp 991) "jccc" (running)

2.4  thread 0x7ffff6ed0700 (lwp 992) "jccc" (running)

2.5  thread 0x7ffff64cf700 (lwp 994) "jccc" (running)

2.6  thread 0x7ffff5ace700 (lwp 995) "jccc" (running)

2.7  thread 0x7ffff50cd700 (lwp 996) "jccc" thread_processor (lpvoid=0x70edb0) at processcore.cpp:454

2.8  thread 0x7fffeffff700 (lwp 997) "jccc" thread_processor (lpvoid=0x70f5e0) at processcore.cpp:454

2.9  thread 0x7fffef5fe700 (lwp 998) "jccc" thread_processor (lpvoid=0x70fbb0) at processcore.cpp:454

2.10 thread 0x7fffeebfd700 (lwp 999) "jccc" thread_processor (lpvoid=0x710190) at processcore.cpp:454

//指定id可以切換到任何執行緒,這裡切換到要除錯的執行緒

(gdb) thread 2.7

[switching to thread 2.7 (thread 0x7ffff50cd700 (lwp 996))]

#0  thread_processor (lpvoid=0x70edb0) at processcore.cpp:454

454                             if(!g_processcore.m_mobilelist.isvalid(fd))

//接下來,單步除錯當前執行緒

(gdb) p g_processcore.m_mobilelist.isvalid(fd)

$2 = true

(gdb) n

395             while(!g_bwantexit)

(gdb) 

397                     if(0!=pthread_mutex_lock(&(process->m_mutex_mobiletcptask)))

(gdb) 

404                     while(process->m_mobiletcptaskqueue.empty())

(gdb) 

414                     if(g_bwantexit)

(gdb) 

421                     fd = process->m_mobiletcptaskqueue.front();

(gdb) 

422                     process->m_mobiletcptaskqueue.pop();

(gdb) 

423                     int nqueuesize=process->m_mobiletcptaskqueue.size();

(gdb) 

425                     write_log(debug, "fd=%d,qsize=%d",nthreadindex,fd,nqueuesize); 

(gdb) 

427                     if(0!=pthread_mutex_unlock(&(process->m_mutex_mobiletcptask)))

(gdb) 

434                     memset(slinedata,0,sizeof(slinedata));

多程序 多執行緒除錯

一 執行緒除錯 程序啟動執行緒,是可以使用od除錯到執行緒中去的 是在waitforsingleobject這裡,之後就是cpu調到執行緒中去了,我們只需要在createthread 中的執行緒函式中下斷點就能斷下來 二 程序除錯 2.1 od除錯時,是不會調到新程序中 關鍵函式 createpro...

gdb除錯多程序多執行緒

1.除錯多程序預設設定下,在除錯多程序程式時gdb只會除錯主程序。但是gdb v7.0 支援多程序的 分別以及同時 除錯,換句話說,gdb可以同時除錯多個程式。只需要設定follow fork mode 預設值 parent 和detach on fork 預設值 on 即可。接下來,首先介紹一下f...

gdb除錯多程序多執行緒

gdb是非常強大的unix及unix like下的程式除錯工具 gdb的使用 r或run 執行程式。list l 行號 顯示檔案源 接著上次的位置往下列,每次列10行。list l 函式名 列出某個函式的源 s或step 進入函式呼叫 breaktrace 或bt 檢視各級函式調 用及引數 info...