1. 程式人生 > 其它 >GDB除錯實戰三完整的資料流程

GDB除錯實戰三完整的資料流程

技術標籤:C++gdb

一、基本流程介紹

經過了前面的各種準備,再結合學習過的GDB的各種除錯方法和技巧,下面進行一次完整的資料除錯流程。整個程式的流程基本是模擬網路和網口通訊,區別在於完整包的大小不同,網口是100個位元組而串列埠是60個位元組。程式在啟動時,啟動了兩個執行緒,生產者直接從一個固定的字串陣列取大小不同的陣列來送到資料處理的兩個std::vector 中。消費執行緒從這兩個向量中不斷的取出資料並根據包大小對其進行處理,一旦處理成功就通過回撥函式顯示並列印到螢幕上。這裡需要注意的是,如果不除錯了,要馬上停止這個程序,否則會產生大量的垃圾日誌。

二、啟動除錯

按照上面兩篇檔案的方法啟動啟動程序:“nohup ./gdbTest >1.log 2>&1 &”。

1、檢視訊息

tail-f-n201.log

2、attach程序並停止程序

ps-ef|grepgdbTest
gdbattach5057
(gdb)stop

三、除錯過程和方法

1、在資料輸入和輸出下斷點

(gdb)dir../inet
Sourcedirectoriessearched:/root/projects/gdbTest/build/../inet:$cdir:$cwd
(gdb)dir../data:../data/comdata:../data/netdata
Sourcedirectoriessearched:/root/projects/gdbTest/build/../data:/root/projects/gdbTest/build/../data/comdata:/root/projects/gdbTest/build/../data/netdata:/root/projects/gdbTest/build/../inet:$cdir:$cwd
(gdb)bServer.cpp:36
Breakpoint1at0x417ece:file/root/projects/gdbTest/inet/Server.cpp,line36.
(gdb)bServer.cpp:55
Breakpoint2at0x418066:file/root/projects/gdbTest/inet/Server.cpp,line55.
(gdb)bNetData.cpp:31
Breakpoint3at0x41bbdb:file/root/projects/gdbTest/data/netdata/NetData.cpp,line31.
(gdb)bIData.cpp:21
Breakpoint4at0x414b4f:file/root/projects/gdbTest/data/IData.cpp,line21.
(gdb)bIData.cpp:70
Breakpoint5at0x414e36:file/root/projects/gdbTest/data/IData.cpp,line70.
(gdb)infob
NumTypeDispEnbAddressWhat
1breakpointkeepy0x0000000000417eceininet::Server::__lambda0::operator()()constat/root/projects/gdbTest/inet/Server.cpp:36
2breakpointkeepy0x0000000000418066ininet::Server::__lambda1::operator()()constat/root/projects/gdbTest/inet/Server.cpp:55
3breakpointkeepy0x000000000041bbdbinnetdata::NetData::ParseData(char*,int)at/root/projects/gdbTest/data/netdata/NetData.cpp:31
4breakpointkeepy0x0000000000414b4findata::IData::__lambda0::operator()(std::shared_ptr<global::__MemData>,int)constat/root/projects/gdbTest/data/IData.cpp:21
5breakpointkeepy0x0000000000414e36indata::IData::GetMemData(int,int)at/root/projects/gdbTest/data/IData.cpp:70
(gdb)

2、鎖定輸入程序檢視資料輸入

(gdb)infothread
IdTargetIdFrame
3Thread0x7f2717ffa700(LWP5058)"gdbTest"0x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
2Thread0x7f27177f9700(LWP5059)"gdbTest"0x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
*1Thread0x7f2719011740(LWP5057)"gdbTest"0x00007f27183d0f47inpthread_join()from/lib64/libpthread.so.0
(gdb)threadapplyallbt

Thread3(Thread0x7f2717ffa700(LWP5058)):
#00x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
#10x00007f27180bfcc4insleep()from/lib64/libc.so.6
#20x0000000000417fcbininet::Server::__lambda0::operator()(__closure=0xb6f3c0)at/root/projects/gdbTest/inet/Server.cpp:42
#30x0000000000419f26instd::_Bind_simple<inet::Server::Start()::__lambda0()>::_M_invoke<>(std::_Index_tuple<>)(this=0xb6f3c0)at/usr/include/c++/4.8.2/functional:1732
#40x0000000000419dd5instd::_Bind_simple<inet::Server::Start()::__lambda0()>::operator()(void)(this=0xb6f3c0)at/usr/include/c++/4.8.2/functional:1720
#50x0000000000419d06instd::thread::_Impl<std::_Bind_simple<inet::Server::Start()::__lambda0()>>::_M_run(void)(this=0xb6f3a8)at/usr/include/c++/4.8.2/thread:115
#60x00007f2718bb1070in??()from/lib64/libstdc++.so.6
#70x00007f27183cfdd5instart_thread()from/lib64/libpthread.so.0
#80x00007f27180f8eadinclone()from/lib64/libc.so.6

Thread2(Thread0x7f27177f9700(LWP5059)):
#00x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
#10x00007f27180bfcc4insleep()from/lib64/libc.so.6
#20x00000000004181b2ininet::Server::__lambda1::operator()(__closure=0xb6f660)at/root/projects/gdbTest/inet/Server.cpp:77
#30x0000000000419ec8instd::_Bind_simple<inet::Server::RunWork()::__lambda1()>::_M_invoke<>(std::_Index_tuple<>)(this=0xb6f660)at/usr/include/c++/4.8.2/functional:1732
#40x0000000000419db7instd::_Bind_simple<inet::Server::RunWork()::__lambda1()>::operator()(void)(this=0xb6f660)at/usr/include/c++/4.8.2/functional:1720
#50x0000000000419ce8instd::thread::_Impl<std::_Bind_simple<inet::Server::RunWork()::__lambda1()>>::_M_run(void)(this=0xb6f648)at/usr/include/c++/4.8.2/thread:115
#60x00007f2718bb1070in??()from/lib64/libstdc++.so.6
#70x00007f27183cfdd5instart_thread()from/lib64/libpthread.so.0
#80x00007f27180f8eadinclone()from/lib64/libc.so.6

Thread1(Thread0x7f2719011740(LWP5057)):
#00x00007f27183d0f47inpthread_join()from/lib64/libpthread.so.0
#10x00007f2718bb0e37instd::thread::join()()from/lib64/libstdc++.so.6
#20x0000000000417dc6ininet::Server::~Server(this=0xb6d058,__in_chrg=<optimizedout>)at/root/projects/gdbTest/inet/Server.cpp:15
#30x000000000041ca34in__gnu_cxx::new_allocator<inet::Server>::destroy<inet::Server>(this=0xb6d050,__p=0xb6d058)at/usr/include/c++/4.8.2/ext/new_allocator.h:124
#40x000000000041c9f1instd::allocator_traits<std::allocator<inet::Server>>::_S_destroy<inet::Server>(__a=...,__p=0xb6d058)at/usr/include/c++/4.8.2/bits/alloc_traits.h:281
#50x000000000041c9a7instd::allocator_traits<std::allocator<inet::Server>>::destroy<inet::Server>(__a=...,__p=0xb6d058)at/usr/include/c++/4.8.2/bits/alloc_traits.h:405
#60x000000000041c8efinstd::_Sp_counted_ptr_inplace<inet::Server,std::allocator<inet::Server>,(__gnu_cxx::_Lock_policy)2>::_M_dispose(this=0xb6d040)
at/usr/include/c++/4.8.2/bits/shared_ptr_base.h:407
#70x0000000000415b7ainstd::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release(this=0xb6d040)at/usr/include/c++/4.8.2/bits/shared_ptr_base.h:144
#80x00000000004156c9instd::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count(this=0x7ffe36ed4a88,__in_chrg=<optimizedout>)at/usr/include/c++/4.8.2/bits/shared_ptr_base.h:546
#90x000000000041bfb4instd::__shared_ptr<inet::Server,(__gnu_cxx::_Lock_policy)2>::~__shared_ptr(this=0x804136ed4a80,__in_chrg=<optimizedout>)at/usr/include/c++/4.8.2/bits/shared_ptr_base.h:781
#100x000000000041bff2instd::shared_ptr<inet::Server>::~shared_ptr(this=0x7ffe36ed4a80,__in_chrg=<optimizedout>)at/usr/include/c++/4.8.2/bits/shared_ptr.h:93
#110x000000000041beb8inModuleNet::~ModuleNet(this=0x7ffe36ed4a80,__in_chrg=<optimizedout>)at/root/projects/gdbTest/ModuleNet.cpp:8
#120x000000000041bda1inmain()at/root/projects/gdbTest/main.cpp:12
(gdb)thread3
[Switchingtothread3(Thread0x7f2717ffa700(LWP5058))]
#00x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
(gdb)bt
#00x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
#10x00007f27180bfcc4insleep()from/lib64/libc.so.6
#20x0000000000417fcbininet::Server::__lambda0::operator()(__closure=0xb6f3c0)at/root/projects/gdbTest/inet/Server.cpp:42
#30x0000000000419f26instd::_Bind_simple<inet::Server::Start()::__lambda0()>::_M_invoke<>(std::_Index_tuple<>)(this=0xb6f3c0)at/usr/include/c++/4.8.2/functional:1732
#40x0000000000419dd5instd::_Bind_simple<inet::Server::Start()::__lambda0()>::operator()(void)(this=0xb6f3c0)at/usr/include/c++/4.8.2/functional:1720
#50x0000000000419d06instd::thread::_Impl<std::_Bind_simple<inet::Server::Start()::__lambda0()>>::_M_run(void)(this=0xb6f3a8)at/usr/include/c++/4.8.2/thread:115
#60x00007f2718bb1070in??()from/lib64/libstdc++.so.6
#70x00007f27183cfdd5instart_thread()from/lib64/libpthread.so.0
#80x00007f27180f8eadinclone()from/lib64/libc.so.6
(gdb)showshceduler-locking
Undefinedshowcommand:"shceduler-locking".Try"helpshow".
(gdb)showscheduler-locking
Modeforlockingschedulerduringexecutionis"step".
(gdb)setscheduler-lockingon

3、鎖定輸出程序檢視資料輸出

(gdb)c
Continuing.

Breakpoint1,inet::Server::__lambda0::operator()(__closure=0xb6f3c0)at/root/projects/gdbTest/inet/Server.cpp:36
36intlen=strlen(barr[num%10]);
(gdb)plen
$1=18
(gdb)p/xbarr
$2={0x41ce63,0x41ce75,0x41ce84,0x41ce97,0x41cea9,0x41ceba,0x41ced0,0x41cee2,0x41ceed,0x41cf09}
(gdb)p/sbarr
$3={0x41ce63"abce459v,$#@!`pit",0x41ce75"NBG^*(_rrtthth",0x41ce84"YT%$#dghhfgdh88980",0x41ce97"##$gryryejhetrjrj",0x41cea9"whethtwrh8967777",0x41ceba"346346546*&****jjkkIO",
0x41ced0"JL)(567568jgjhjgk",0x41cee2"ghjgktytuk",0x41ceed"45747476466&&***HJJKKTryret",0x41cf09"truytritrkmb<>NNHGG$##@"}
(gdb)

(gdb)s
std::__shared_ptr<comdata::ComData,(__gnu_cxx::_Lock_policy)2>::operator->(this=0xb6d1d8)at/usr/include/c++/4.8.2/bits/shared_ptr_base.h:915
915return_M_ptr;
(gdb)n
916}
(gdb)s
comdata::ComData::ParseData(this=0xb6d288,buf=0xb6d080"##$gryryejhetrjrj0G$##@yret",len=17)at/root/projects/gdbTest/data/comdata/ComData.cpp:25
25if(nullptr==buf||len==0)
(gdb)n
30memmove(data+count_,buf,len);
(gdb)

通過對s和n命令的操作進入下一級函式,同時,在上面也打了斷點,直接c命令也可以跳到當前斷點中去。

(gdb)n
30memmove(data+count_,buf,len);
(gdb)pdata
$4=0xb6d2e0"abce4YT%$#dghhfgdh88980<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rrtththTryretjjkkIO"
(gdb)p/sdata
$5=0xb6d2e0"abce4YT%$#dghhfgdh88980<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rrtththTryretjjkkIO"
(gdb)x/60tbbuf
0xb6d080:0010001100100011001001000110011101110010011110010111001001111001
0xb6d088:0110010101101010011010000110010101110100011100100110101001110010
0xb6d090:0110101000110000010001110010010000100011001000110100000001111001
0xb6d098:0111001001100101011101000000000000000000000000000000000000000000
0xb6d0a0:0000000000000000000000000000000000000000000000000000000000000000
0xb6d0a8:0000000000000000000000000000000000000000000000000000000000000000
0xb6d0b0:0000000000000000000000000000000000000000000000000000000000000000
0xb6d0b8:00000000000000000000000000000000
(gdb)x/60ubbuf
0xb6d080:353536103114121114121
0xb6d088:101106104101116114106114
0xb6d090:106487136353564121
0xb6d098:11410111600000
0xb6d0a0:00000000
0xb6d0a8:00000000
0xb6d0b0:00000000
0xb6d0b8:0000
(gdb)x/60abbuf
0xb6d080:0x230x230x240x670x720x790x720x79
0xb6d088:0x650x6a0x680x650x740x720x6a0x72
0xb6d090:0x6a0x300x470x240x230x230x400x79
0xb6d098:0x720x650x740x00x00x00x00x0
0xb6d0a0:0x00x00x00x00x00x00x00x0
0xb6d0a8:0x00x00x00x00x00x00x00x0
0xb6d0b0:0x00x00x00x00x00x00x00x0
0xb6d0b8:0x00x00x00x0
(gdb)p/sbuf
$6=0xb6d080"##$gryryejhetrjrj0G$##@yret"

看資料“35 35 36”正好是“##$”,說明記憶體的資料對上了。

(gdb)pmem->buf
$12='\000'<repeats99times>
(gdb)p/smem->buf
$13='\000'<repeats99times>
(gdb)n
40mem->len=100;
1:count_=111
(gdb)p/smem->buf
$14="whe##$gryryejhetrjrjwhethtwrh8967777346346546*&****jjkkIOJL)(567568jgjhjgkghjgktytuk45747476466&&***"
(gdb)p/sdataa
Nosymbol"dataa"incurrentcontext.
(gdb)
(gdb)n
42this->count_=this->count_-100;
1:count_=111
(gdb)n
44this->cb_(mem,1);
1:count_=11
(gdb)s

再看一下輸出資料,先解鎖輸入執行緒,再鎖定輸出執行緒:

(gdb)showscheduler-locking
Modeforlockingschedulerduringexecutionis"on".
(gdb)setscheduler-lockingstep
(gdb)infothread
IdTargetIdFrame
*3Thread0x7f2717ffa700(LWP5058)"gdbTest"data::IData::__lambda0::operator()(__closure=0xb6f370,mem=std::shared_ptr(count2,weak0)0x7f2710002328,type=1)
at/root/projects/gdbTest/data/IData.cpp:21
2Thread0x7f27177f9700(LWP5059)"gdbTest"0x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
1Thread0x7f2719011740(LWP5057)"gdbTest"0x00007f27183d0f47inpthread_join()from/lib64/libpthread.so.0
(gdb)thread2
[Switchingtothread2(Thread0x7f27177f9700(LWP5059))]
#00x00007f27180bfe2dinnanosleep()from/lib64/libc.so.6
(gdb)setscheduler-lockingon
(gdb)c
Continuing.

Breakpoint2,inet::Server::__lambda1::operator()(__closure=0xb6f660)at/root/projects/gdbTest/inet/Server.cpp:55
55intlen=pData_->GetMemCount(0);
(gdb)s
std::__shared_ptr<data::IData,(__gnu_cxx::_Lock_policy)2>::operator->(this=0xb6d058)at/usr/include/c++/4.8.2/bits/shared_ptr_base.h:915
915return_M_ptr;
(gdb)n
916}
(gdb)s
data::IData::GetMemCount(this=0xb6d1d8,type=0)at/root/projects/gdbTest/data/IData.cpp:116
116if(type==0)
(gdb)n
118returnthis->vecCom_.size();
(gdb)

(gdb)
inet::Server::__lambda1::operator()(__closure=0xb6f660)at/root/projects/gdbTest/inet/Server.cpp:61
61std::cout<<"dataparsetmpcomData:"<<tmp->len<<std::endl;
(gdb)ptmp->buf
$15="abce459v,$#truytritrkmb<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rr",'\000'<repeats39times>
(gdb)p/stmp->buf
$16="abce459v,$#truytritrkmb<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rr",'\000'<repeats39times>
(gdb)x/100tb
0x7f2710000a9c:0011110000000000000000000000000000000000000000000000000000000000
0x7f2710000aa4:0000000000000000000000000000000000110101000000000000000000000000
0x7f2710000aac:0000000000000000000000000000000000000000000000000000000000000000
0x7f2710000ab4:0000000000000000000000000000000000000000000000000000000000000000
0x7f2710000abc:0000000000000000000000000000000000000000000000000000000000000000
0x7f2710000ac4:0000000000000000000000000000000000000000000000000000000000000000
0x7f2710000acc:0000000000000000000000000000000000000000000000000000000000000000
0x7f2710000ad4:0000000000000000000000000000000010010101000000000000000000000000
0x7f2710000adc:0000000000000000000000000000000000110000110101000100000100000000
0x7f2710000ae4:0000000000000000000000000000000000000001000000000000000000000000
0x7f2710000aec:0000000100000000000000000000000011111000000010100000000000010000
0x7f2710000af4:0010011101111111000000000000000001100001011000100110001101100101
0x7f2710000afc:00110100010110010101010000100101
(gdb)x/100ub
0x7f2710000b00:3635100103104104102103
0x7f2710000b08:100104565657564835
0x7f2710000b10:3536103114121114121101
0x7f2710000b18:106104101116114106114106
0x7f2710000b20:119104101116104116119114
0x7f2710000b28:10456575455555555
0x7f2710000b30:515254510000
0x7f2710000b38:00000000
0x7f2710000b40:00000000
0x7f2710000b48:00000000
0x7f2710000b50:00000000
0x7f2710000b58:000060000
0x7f2710000b60:0000
(gdb)x/100ab
0x7f2710000b64:0x00x00x00x00x550x00x00x0
0x7f2710000b6c:0x00x00x00x00x00x00x00x0
0x7f2710000b74:0x00x00x00x00x00x00x00x0
0x7f2710000b7c:0x00x00x00x00x00x00x00x0
0x7f2710000b84:0x00x00x00x00x00x00x00x0
0x7f2710000b8c:0x00x00x00x00x00x00x00x0
0x7f2710000b94:0x00x00x00x00x00x00x00x0
0x7f2710000b9c:0x00x00x00x00x00x00x00x0
0x7f2710000ba4:0x00x00x00x00x00x00x00x0
0x7f2710000bac:0x00x00x00x00x00x00x00x0
0x7f2710000bb4:0x00x00x00x00xffffffffffffff950x00x00x0
0x7f2710000bbc:0x00x00x00x00x300xffffffffffffffd40x410x0
0x7f2710000bc4:0x00x00x00x0
(gdb)

如果想要同時看輸入和輸出的強一致性,可以斷點停住後,單步前進。也可以直接在兩個關鍵的地方下好斷點,讓他們自動跳轉,但前提是要把執行緒鎖定去掉。下面看一下:

(gdb)c
Continuing.

Breakpoint2,data::IData::__lambda0::operator()(__closure=0x183f2f0,mem=std::shared_ptr(count2,weak0)0x7f29e0000c68,type=0)at/root/projects/gdbTest/data/IData.cpp:23
23vecCom_.emplace_back(mem);
(gdb)n
29};
(gdb)pmem->buf
[SwitchingtoThread0x7f29e6558700(LWP6041)]

Breakpoint1,inet::Server::__lambda1::operator()(__closure=0x1840660)at/root/projects/gdbTest/inet/Server.cpp:60
60std::shared_ptr<global::MemData>tmp=pData_->GetMemData(num,0);
TheprogramstoppedinanotherthreadwhilemakingafunctioncallfromGDB.
Evaluationoftheexpressioncontainingthefunction
(std::__shared_ptr<global::__MemData,(__gnu_cxx::_Lock_policy)2>::operator->()const)willbeabandoned.
Whenthefunctionisdoneexecuting,GDBwillsilentlystop.
(gdb)n
[SwitchingtoThread0x7f29e6d59700(LWP6040)]
(gdb)pmem->buf
$1="abce459ghjgktytuk45747476466&&***HJJKKTryrettruytritrkmb<>NN",'\000'<repeats39times>
(gdb)nthis->cb_(mem,0);

再看一下對應的資料:

61std::cout<<"dataparsetmpcomData:"<<tmp->len<<std::endl;
2:x/stmp->buf0x7f29e00008d8:"abce459v,$#@!`pit45747476466&&***HJJKKTryrettruytritrkmb<>NN"
1:tmp->buf="abce459v,$#@!`pit45747476466&&***HJJKKTryrettruytritrkmb<>NN",'\000'<repeats39times>
(gdb)

會發現輸入資料對應著相應的緩衝區內的資料,其實如果想更好的匹配,可以把大小改成動態的,每個不同;或者將資料從向量改成佇列,這樣保證一一對應,就更清楚的可以看清楚目標。但是這是模擬的實際工程,所以就不能按照理想的狀態來修改程式了。

四、崩潰除錯

在前面除錯的過程時,程式崩潰了兩次,正好看一下原因,除錯一下core檔案:

debuginfo-installlibgcc-4.8.5-11.el7.x86_64libstdc++-4.8.5-11.el7.x86_64

[[email protected]build]#gdbgdbTestcore.9453
GNUgdb(GDB)RedHatEnterpriseLinux7.6.1-114.el7
Copyright(C)2013FreeSoftwareFoundation,Inc.
LicenseGPLv3+:GNUGPLversion3orlater<http://gnu.org/licenses/gpl.html>
Thisisfreesoftware:youarefreetochangeandredistributeit.
ThereisNOWARRANTY,totheextentpermittedbylaw.Type"showcopying"
and"showwarranty"fordetails.
ThisGDBwasconfiguredas"x86_64-redhat-linux-gnu".
Forbugreportinginstructions,pleasesee:
<http://www.gnu.org/software/gdb/bugs/>...
Readingsymbolsfrom/root/projects/gdbTest/build/gdbTest...done.
[NewLWP9454]
[NewLWP9455]
[NewLWP9453]
[Threaddebuggingusinglibthread_dbenabled]
Usinghostlibthread_dblibrary"/lib64/libthread_db.so.1".
Corewasgeneratedby`./gdbTest'.
Programterminatedwithsignal11,Segmentationfault.
#00x00007fdd8a43a901in__strlen_sse2_pminub()from/lib64/libc.so.6
Missingseparatedebuginfos,use:debuginfo-installglibc-2.17-260.el7_6.5.x86_64libgcc-4.8.5-36.el7_6.2.x86_64libstdc++-4.8.5-36.el7_6.2.x86_64
(gdb)bt
#00x00007fdd8a43a901in__strlen_sse2_pminub()from/lib64/libc.so.6
#10x0000000000417f11ininet::Server::__lambda0::operator()(__closure=0x11903c0)at/root/projects/gdbTest/inet/Server.cpp:36
#20x0000000000419f32instd::_Bind_simple<inet::Server::Start()::__lambda0()>::_M_invoke<>(std::_Index_tuple<>)(this=0x11903c0)at/usr/include/c++/4.8.2/functional:1732
#30x0000000000419de1instd::_Bind_simple<inet::Server::Start()::__lambda0()>::operator()(void)(this=0x11903c0)at/usr/include/c++/4.8.2/functional:1720
#40x0000000000419d12instd::thread::_Impl<std::_Bind_simple<inet::Server::Start()::__lambda0()>>::_M_run(void)(this=0x11903a8)at/usr/include/c++/4.8.2/thread:115
#50x00007fdd8ae82070in??()from/lib64/libstdc++.so.6
#60x00007fdd8a6a0dd5instart_thread()from/lib64/libpthread.so.0
#70x00007fdd8a3c9eadinclone()from/lib64/libc.so.6

(gdb)frame
#00x00007fdd8a43a901in__strlen_sse2_pminub()from/lib64/libc.so.6
(gdb)frame1
#10x0000000000417f11ininet::Server::__lambda0::operator()(__closure=0x11903c0)at/root/projects/gdbTest/inet/Server.cpp:36
36intlen=strlen(barr[num%30]);
(gdb)

定位到了程式碼中陣列越界,直接就看明白了。

四、總結

工程應用中會結合到很多的知識,不同的場景也有不同的細節要求,比如對程式編輯工具的使用,對不同OS的Shell命令的使用等等,這些都往往融合在一起,有一個應用不太熟悉就可能造成除錯上的不方便,所以還是要多熟悉,多練習,在實踐中不斷的成長,自然在以後的應用中,駕輕就熟,順手拈來。
《賣油翁》中說過:“無它,惟手熟爾!”,除錯確實如此。