GDB调试实战三完整的数据流程

 

一、基本流程介绍

经过了前面的各种准备,再结合学习过的GDB的各种调试方法和技巧,下面进行一次完整的数据调试流程。整个程序的流程基本是模拟网络和网口通信,区别在于完整包的大小不同,网口是100个字节而串口是60个字节。程序在启动时,启动了两个线程,生产者直接从一个固定的字符串数组取大小不同的数组来送到数据处理的两个std::vector 中。消费线程从这两个向量中不断的取出数据并根据包大小对其进行处理,一旦处理成功就通过回调函数显示并打印到屏幕上。这里需要注意的是,如果不调试了,要马上停止这个进程,否则会产生大量的垃圾日志。

二、启动调试

按照上面两篇文件的方法启动启动进程:“nohup ./gdbTest >1.log 2>&1 &”。
1、查看消息

tail -f -n 20 1.log

2、attach进程并停止进程

ps -ef|grep gdbTest
gdb attach 5057
(gdb) stop

三、调试过程和方法

1、在数据输入和输出下断点

(gdb) dir ../inet
Source directories searched: /root/projects/gdbTest/build/../inet:$cdir:$cwd
(gdb) dir ../data:../data/comdata:../data/netdata
Source directories searched: /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) b Server.cpp:36
Breakpoint 1 at 0x417ece: file /root/projects/gdbTest/inet/Server.cpp, line 36.
(gdb) b Server.cpp:55
Breakpoint 2 at 0x418066: file /root/projects/gdbTest/inet/Server.cpp, line 55.
(gdb) b NetData.cpp:31
Breakpoint 3 at 0x41bbdb: file /root/projects/gdbTest/data/netdata/NetData.cpp, line 31.
(gdb) b IData.cpp:21
Breakpoint 4 at 0x414b4f: file /root/projects/gdbTest/data/IData.cpp, line 21.
(gdb) b IData.cpp:70
Breakpoint 5 at 0x414e36: file /root/projects/gdbTest/data/IData.cpp, line 70.
(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000417ece in inet::Server::__lambda0::operator()() const at /root/projects/gdbTest/inet/Server.cpp:36
2       breakpoint     keep y   0x0000000000418066 in inet::Server::__lambda1::operator()() const at /root/projects/gdbTest/inet/Server.cpp:55
3       breakpoint     keep y   0x000000000041bbdb in netdata::NetData::ParseData(char*, int) at /root/projects/gdbTest/data/netdata/NetData.cpp:31
4       breakpoint     keep y   0x0000000000414b4f in data::IData::__lambda0::operator()(std::shared_ptr<global::__MemData>, int) const at /root/projects/gdbTest/data/IData.cpp:21
5       breakpoint     keep y   0x0000000000414e36 in data::IData::GetMemData(int, int) at /root/projects/gdbTest/data/IData.cpp:70
(gdb)  

2、锁定输入进程查看数据输入

(gdb) info thread
  Id   Target Id         Frame
  3    Thread 0x7f2717ffa700 (LWP 5058) "gdbTest" 0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
  2    Thread 0x7f27177f9700 (LWP 5059) "gdbTest" 0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
* 1    Thread 0x7f2719011740 (LWP 5057) "gdbTest" 0x00007f27183d0f47 in pthread_join () from /lib64/libpthread.so.0
(gdb) thread apply all bt

Thread 3 (Thread 0x7f2717ffa700 (LWP 5058)):
#0  0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
#1  0x00007f27180bfcc4 in sleep () from /lib64/libc.so.6
#2  0x0000000000417fcb in inet::Server::__lambda0::operator() (__closure=0xb6f3c0) at /root/projects/gdbTest/inet/Server.cpp:42
#3  0x0000000000419f26 in std::_Bind_simple<inet::Server::Start()::__lambda0()>::_M_invoke<>(std::_Index_tuple<>) (this=0xb6f3c0) at /usr/include/c++/4.8.2/functional:1732
#4  0x0000000000419dd5 in std::_Bind_simple<inet::Server::Start()::__lambda0()>::operator()(void) (this=0xb6f3c0) at /usr/include/c++/4.8.2/functional:1720
#5  0x0000000000419d06 in std::thread::_Impl<std::_Bind_simple<inet::Server::Start()::__lambda0()> >::_M_run(void) (this=0xb6f3a8) at /usr/include/c++/4.8.2/thread:115
#6  0x00007f2718bb1070 in ?? () from /lib64/libstdc++.so.6
#7  0x00007f27183cfdd5 in start_thread () from /lib64/libpthread.so.0
#8  0x00007f27180f8ead in clone () from /lib64/libc.so.6

Thread 2 (Thread 0x7f27177f9700 (LWP 5059)):
#0  0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
#1  0x00007f27180bfcc4 in sleep () from /lib64/libc.so.6
#2  0x00000000004181b2 in inet::Server::__lambda1::operator() (__closure=0xb6f660) at /root/projects/gdbTest/inet/Server.cpp:77
#3  0x0000000000419ec8 in std::_Bind_simple<inet::Server::RunWork()::__lambda1()>::_M_invoke<>(std::_Index_tuple<>) (this=0xb6f660) at /usr/include/c++/4.8.2/functional:1732
#4  0x0000000000419db7 in std::_Bind_simple<inet::Server::RunWork()::__lambda1()>::operator()(void) (this=0xb6f660) at /usr/include/c++/4.8.2/functional:1720
#5  0x0000000000419ce8 in std::thread::_Impl<std::_Bind_simple<inet::Server::RunWork()::__lambda1()> >::_M_run(void) (this=0xb6f648) at /usr/include/c++/4.8.2/thread:115
#6  0x00007f2718bb1070 in ?? () from /lib64/libstdc++.so.6
#7  0x00007f27183cfdd5 in start_thread () from /lib64/libpthread.so.0
#8  0x00007f27180f8ead in clone () from /lib64/libc.so.6

Thread 1 (Thread 0x7f2719011740 (LWP 5057)):
#0  0x00007f27183d0f47 in pthread_join () from /lib64/libpthread.so.0
#1  0x00007f2718bb0e37 in std::thread::join() () from /lib64/libstdc++.so.6
#2  0x0000000000417dc6 in inet::Server::~Server (this=0xb6d058, __in_chrg=<optimized out>) at /root/projects/gdbTest/inet/Server.cpp:15
#3  0x000000000041ca34 in __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
#4  0x000000000041c9f1 in std::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
#5  0x000000000041c9a7 in std::allocator_traits<std::allocator<inet::Server> >::destroy<inet::Server> (__a=..., __p=0xb6d058) at /usr/include/c++/4.8.2/bits/alloc_traits.h:405
#6  0x000000000041c8ef in std::_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
#7  0x0000000000415b7a in std::_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
#8  0x00000000004156c9 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x7ffe36ed4a88, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/shared_ptr_base.h:546
#9  0x000000000041bfb4 in std::__shared_ptr<inet::Server, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x804136ed4a80, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/shared_ptr_base.h:781
#10 0x000000000041bff2 in std::shared_ptr<inet::Server>::~shared_ptr (this=0x7ffe36ed4a80, __in_chrg=<optimized out>) at /usr/include/c++/4.8.2/bits/shared_ptr.h:93
#11 0x000000000041beb8 in ModuleNet::~ModuleNet (this=0x7ffe36ed4a80, __in_chrg=<optimized out>) at /root/projects/gdbTest/ModuleNet.cpp:8
#12 0x000000000041bda1 in main () at /root/projects/gdbTest/main.cpp:12
(gdb) thread 3
[Switching to thread 3 (Thread 0x7f2717ffa700 (LWP 5058))]
#0  0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
(gdb) bt
#0  0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
#1  0x00007f27180bfcc4 in sleep () from /lib64/libc.so.6
#2  0x0000000000417fcb in inet::Server::__lambda0::operator() (__closure=0xb6f3c0) at /root/projects/gdbTest/inet/Server.cpp:42
#3  0x0000000000419f26 in std::_Bind_simple<inet::Server::Start()::__lambda0()>::_M_invoke<>(std::_Index_tuple<>) (this=0xb6f3c0) at /usr/include/c++/4.8.2/functional:1732
#4  0x0000000000419dd5 in std::_Bind_simple<inet::Server::Start()::__lambda0()>::operator()(void) (this=0xb6f3c0) at /usr/include/c++/4.8.2/functional:1720
#5  0x0000000000419d06 in std::thread::_Impl<std::_Bind_simple<inet::Server::Start()::__lambda0()> >::_M_run(void) (this=0xb6f3a8) at /usr/include/c++/4.8.2/thread:115
#6  0x00007f2718bb1070 in ?? () from /lib64/libstdc++.so.6
#7  0x00007f27183cfdd5 in start_thread () from /lib64/libpthread.so.0
#8  0x00007f27180f8ead in clone () from /lib64/libc.so.6
(gdb) show shceduler-locking
Undefined show command: "shceduler-locking".  Try "help show".
(gdb) show scheduler-locking
Mode for locking scheduler during execution is "step".
(gdb) set scheduler-locking on

3、锁定输出进程查看数据输出

(gdb) c
Continuing.

Breakpoint 1, inet::Server::__lambda0::operator() (__closure=0xb6f3c0) at /root/projects/gdbTest/inet/Server.cpp:36
36                                      int len = strlen(barr[num % 10]);
(gdb) p len
$1 = 18
(gdb) p /x  barr
$2 = {0x41ce63, 0x41ce75, 0x41ce84, 0x41ce97, 0x41cea9, 0x41ceba, 0x41ced0, 0x41cee2, 0x41ceed, 0x41cf09}
(gdb) p /s  barr
$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
915             return _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
25                      if ( nullptr == buf || len == 0)
(gdb) n
30                      memmove(data + count_,buf,len);
(gdb)

通过对s和n命令的操作进入下一级函数,同时,在上面也打了断点,直接c命令也可以跳到当前断点中去。

(gdb) n
30                      memmove(data + count_,buf,len);
(gdb) p data
$4 = 0xb6d2e0 "abce4YT%$#dghhfgdh88980<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rrtththTryretjjkkIO"
(gdb) p /s data
$5 = 0xb6d2e0 "abce4YT%$#dghhfgdh88980<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rrtththTryretjjkkIO"
(gdb) x /60tb buf
0xb6d080:       00100011        00100011        00100100        01100111        01110010        01111001        01110010        01111001
0xb6d088:       01100101        01101010        01101000        01100101        01110100        01110010        01101010        01110010
0xb6d090:       01101010        00110000        01000111        00100100        00100011        00100011        01000000        01111001
0xb6d098:       01110010        01100101        01110100        00000000        00000000        00000000        00000000        00000000
0xb6d0a0:       00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0xb6d0a8:       00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0xb6d0b0:       00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0xb6d0b8:       00000000        00000000        00000000        00000000
(gdb) x /60ub buf
0xb6d080:       35      35      36      103     114     121     114     121
0xb6d088:       101     106     104     101     116     114     106     114
0xb6d090:       106     48      71      36      35      35      64      121
0xb6d098:       114     101     116     0       0       0       0       0
0xb6d0a0:       0       0       0       0       0       0       0       0
0xb6d0a8:       0       0       0       0       0       0       0       0
0xb6d0b0:       0       0       0       0       0       0       0       0
0xb6d0b8:       0       0       0       0
(gdb) x /60ab buf
0xb6d080:       0x23    0x23    0x24    0x67    0x72    0x79    0x72    0x79
0xb6d088:       0x65    0x6a    0x68    0x65    0x74    0x72    0x6a    0x72
0xb6d090:       0x6a    0x30    0x47    0x24    0x23    0x23    0x40    0x79
0xb6d098:       0x72    0x65    0x74    0x0     0x0     0x0     0x0     0x0
0xb6d0a0:       0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0xb6d0a8:       0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0xb6d0b0:       0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0xb6d0b8:       0x0     0x0     0x0     0x0
(gdb) p /s buf
$6 = 0xb6d080 "##$gryryejhetrjrj0G$##@yret"

看数据“35 35 36”正好是“##$”,说明内存的数据对上了。

(gdb) p mem->buf
$12 = '\000' <repeats 99 times>
(gdb) p /s mem->buf
$13 = '\000' <repeats 99 times>
(gdb) n
40                                      mem->len = 100;
1: count_ = 111
(gdb) p /s mem->buf
$14 = "whe##$gryryejhetrjrjwhethtwrh8967777346346546*&****jjkkIOJL)(567568jgjhjgkghjgktytuk45747476466&&***"
(gdb) p /s dataa
No symbol "dataa" in current context.
(gdb)
(gdb) n
42                                      this->count_ = this->count_ - 100;
1: count_ = 111
(gdb) n
44                                      this->cb_(mem,1);
1: count_ = 11
(gdb) s

再看一下输出数据,先解锁输入线程,再锁定输出线程:

(gdb) show scheduler-locking
Mode for locking scheduler during execution is "on".
(gdb) set scheduler-locking step
(gdb) info thread
  Id   Target Id         Frame
* 3    Thread 0x7f2717ffa700 (LWP 5058) "gdbTest" data::IData::__lambda0::operator() (__closure=0xb6f370, mem=std::shared_ptr (count 2, weak 0) 0x7f2710002328, type=1)
    at /root/projects/gdbTest/data/IData.cpp:21
  2    Thread 0x7f27177f9700 (LWP 5059) "gdbTest" 0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
  1    Thread 0x7f2719011740 (LWP 5057) "gdbTest" 0x00007f27183d0f47 in pthread_join () from /lib64/libpthread.so.0
(gdb) thread 2
[Switching to thread 2 (Thread 0x7f27177f9700 (LWP 5059))]
#0  0x00007f27180bfe2d in nanosleep () from /lib64/libc.so.6
(gdb) set scheduler-locking on
(gdb) c
Continuing.

Breakpoint 2, inet::Server::__lambda1::operator() (__closure=0xb6f660) at /root/projects/gdbTest/inet/Server.cpp:55
55                                      int len = 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
915             return _M_ptr;
(gdb) n
916           }
(gdb) s
data::IData::GetMemCount (this=0xb6d1d8, type=0) at /root/projects/gdbTest/data/IData.cpp:116
116                     if (type == 0)
(gdb) n
118                             return this->vecCom_.size();
(gdb)

(gdb)
inet::Server::__lambda1::operator() (__closure=0xb6f660) at /root/projects/gdbTest/inet/Server.cpp:61
61                                                      std::cout << "dataparse tmp comData:" << tmp->len << std::endl;
(gdb) p tmp->buf
$15 = "abce459v,$#truytritrkmb<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rr", '\000' <repeats 39 times>
(gdb) p /s tmp->buf
$16 = "abce459v,$#truytritrkmb<>NNHGG$##@abce459v,$#@!`pitNBG^*(_rr", '\000' <repeats 39 times>
(gdb) x /100tb
0x7f2710000a9c: 00111100        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0x7f2710000aa4: 00000000        00000000        00000000        00000000        00110101        00000000        00000000        00000000
0x7f2710000aac: 00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0x7f2710000ab4: 00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0x7f2710000abc: 00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0x7f2710000ac4: 00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0x7f2710000acc: 00000000        00000000        00000000        00000000        00000000        00000000        00000000        00000000
0x7f2710000ad4: 00000000        00000000        00000000        00000000        10010101        00000000        00000000        00000000
0x7f2710000adc: 00000000        00000000        00000000        00000000        00110000        11010100        01000001        00000000
0x7f2710000ae4: 00000000        00000000        00000000        00000000        00000001        00000000        00000000        00000000
0x7f2710000aec: 00000001        00000000        00000000        00000000        11111000        00001010        00000000        00010000
0x7f2710000af4: 00100111        01111111        00000000        00000000        01100001        01100010        01100011        01100101
0x7f2710000afc: 00110100        01011001        01010100        00100101
(gdb) x /100ub
0x7f2710000b00: 36      35      100     103     104     104     102     103
0x7f2710000b08: 100     104     56      56      57      56      48      35
0x7f2710000b10: 35      36      103     114     121     114     121     101
0x7f2710000b18: 106     104     101     116     114     106     114     106
0x7f2710000b20: 119     104     101     116     104     116     119     114
0x7f2710000b28: 104     56      57      54      55      55      55      55
0x7f2710000b30: 51      52      54      51      0       0       0       0
0x7f2710000b38: 0       0       0       0       0       0       0       0
0x7f2710000b40: 0       0       0       0       0       0       0       0
0x7f2710000b48: 0       0       0       0       0       0       0       0
0x7f2710000b50: 0       0       0       0       0       0       0       0
0x7f2710000b58: 0       0       0       0       60      0       0       0
0x7f2710000b60: 0       0       0       0
(gdb) x /100ab
0x7f2710000b64: 0x0     0x0     0x0     0x0     0x55    0x0     0x0     0x0
0x7f2710000b6c: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000b74: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000b7c: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000b84: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000b8c: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000b94: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000b9c: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000ba4: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000bac: 0x0     0x0     0x0     0x0     0x0     0x0     0x0     0x0
0x7f2710000bb4: 0x0     0x0     0x0     0x0     0xffffffffffffff95      0x0     0x0     0x0
0x7f2710000bbc: 0x0     0x0     0x0     0x0     0x30    0xffffffffffffffd4      0x41    0x0
0x7f2710000bc4: 0x0     0x0     0x0     0x0
(gdb)

如果想要同时看输入和输出的强一致性,可以断点停住后,单步前进。也可以直接在两个关键的地方下好断点,让他们自动跳转,但前提是要把线程锁定去掉。下面看一下:

(gdb) c
Continuing.

Breakpoint 2, data::IData::__lambda0::operator() (__closure=0x183f2f0, mem=std::shared_ptr (count 2, weak 0) 0x7f29e0000c68, type=0) at /root/projects/gdbTest/data/IData.cpp:23
23                                              vecCom_.emplace_back(mem);
(gdb) n
29                              };
(gdb) p mem->buf
[Switching to Thread 0x7f29e6558700 (LWP 6041)]

Breakpoint 1, inet::Server::__lambda1::operator() (__closure=0x1840660) at /root/projects/gdbTest/inet/Server.cpp:60
60                                                      std::shared_ptr<global::MemData> tmp = pData_->GetMemData(num, 0);
The program stopped in another thread while making a function call from GDB.
Evaluation of the expression containing the function
(std::__shared_ptr<global::__MemData, (__gnu_cxx::_Lock_policy)2>::operator->() const) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) n
[Switching to Thread 0x7f29e6d59700 (LWP 6040)]
(gdb) p mem->buf
$1 = "abce459ghjgktytuk45747476466&&***HJJKKTryrettruytritrkmb<>NN", '\000' <repeats 39 times>
(gdb) n                                   this->cb_(mem,0);

再看一下对应的数据:

 61                                                      std::cout << "dataparse tmp comData:" << tmp->len << std::endl;
 2: x/s tmp->buf  0x7f29e00008d8:        "abce459v,$#@!`pit45747476466&&***HJJKKTryrettruytritrkmb<>NN"
 1: tmp->buf = "abce459v,$#@!`pit45747476466&&***HJJKKTryrettruytritrkmb<>NN", '\000' <repeats 39 times>
 (gdb)

会发现输入数据对应着相应的缓冲区内的数据,其实如果想更好的匹配,可以把大小改成动态的,每个不同;或者将数据从向量改成队列,这样保证一一对应,就更清楚的可以看清楚目标。但是这是模拟的实际工程,所以就不能按照理想的状态来修改程序了。

四、崩溃调试

在前面调试的过程时,程序崩溃了两次,正好看一下原因,调试一下core文件:

debuginfo-install libgcc-4.8.5-11.el7.x86_64 libstdc++-4.8.5-11.el7.x86_64

[root@socket-server build]# gdb gdbTest core.9453
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/projects/gdbTest/build/gdbTest...done.
[New LWP 9454]
[New LWP 9455]
[New LWP 9453]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./gdbTest'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007fdd8a43a901 in __strlen_sse2_pminub () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7_6.5.x86_64 libgcc-4.8.5-36.el7_6.2.x86_64 libstdc++-4.8.5-36.el7_6.2.x86_64
(gdb) bt
#0  0x00007fdd8a43a901 in __strlen_sse2_pminub () from /lib64/libc.so.6
#1  0x0000000000417f11 in inet::Server::__lambda0::operator() (__closure=0x11903c0) at /root/projects/gdbTest/inet/Server.cpp:36
#2  0x0000000000419f32 in std::_Bind_simple<inet::Server::Start()::__lambda0()>::_M_invoke<>(std::_Index_tuple<>) (this=0x11903c0) at /usr/include/c++/4.8.2/functional:1732
#3  0x0000000000419de1 in std::_Bind_simple<inet::Server::Start()::__lambda0()>::operator()(void) (this=0x11903c0) at /usr/include/c++/4.8.2/functional:1720
#4  0x0000000000419d12 in std::thread::_Impl<std::_Bind_simple<inet::Server::Start()::__lambda0()> >::_M_run(void) (this=0x11903a8) at /usr/include/c++/4.8.2/thread:115
#5  0x00007fdd8ae82070 in ?? () from /lib64/libstdc++.so.6
#6  0x00007fdd8a6a0dd5 in start_thread () from /lib64/libpthread.so.0
#7  0x00007fdd8a3c9ead in clone () from /lib64/libc.so.6

(gdb) frame
#0  0x00007fdd8a43a901 in __strlen_sse2_pminub () from /lib64/libc.so.6
(gdb) frame 1
#1  0x0000000000417f11 in inet::Server::__lambda0::operator() (__closure=0x11903c0) at /root/projects/gdbTest/inet/Server.cpp:36
36                                      int len = strlen(barr[num % 30]);
(gdb)

定位到了代码中数组越界,直接就看明白了。

四、总结

工程应用中会结合到很多的知识,不同的场景也有不同的细节要求,比如对程序编辑工具的使用,对不同OS的Shell命令的使用等等,这些都往往融合在一起,有一个应用不太熟悉就可能造成调试上的不方便,所以还是要多熟悉,多练习,在实践中不断的成长,自然在以后的应用中,驾轻就熟,顺手拈来。
《卖油翁》中说过:“无它,惟手熟尔!”,调试确实如此。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值