嗯,有一阵子没写日志了。
曾经有很长一段时间,其实也就是今天之前啦,在用gdb调试core文件时,仅限于通过bt查看下崩溃时的堆栈。这两天,服务常常挂掉,查看堆栈发现是rapidjson在解析时断言失败导致的。于是想要查看接收到消息,以前的做法是,把消息记录到日志中,之后再根据崩溃的时间点去日志中找(掩面)。之前也有想过,既然core文件中记录了调用堆栈,那么记录调用时参数的值,也是合情合理的啊。
今天在网上找了些资料,算是大概弄明白了~过程大致如下:
[user@xxxxxxx bin]$ gdb mybin core.25756
打印调用堆栈
(gdb) bt
#0 0x0000003ddae32885 in raise () from /lib64/libc.so.6
#1 0x0000003ddae34065 in abort () from /lib64/libc.so.6
#2 0x0000003ddae2b9fe in __assert_fail_base () from /lib64/libc.so.6
#3 0x0000003ddae2bac0 in __assert_fail () from /lib64/libc.so.6
#4 0x0000000000419aa4 in FindMember (this=0x7fbdcc329378, request=0x7fbdcc327980, root=...) at ../../rapidjson/include/rapidjson/document.h:620
#5 operator[] (this=0x7fbdcc329378, request=0x7fbdcc327980, root=...) at ../../rapidjson/include/rapidjson/document.h:233
#6 Head::parse_head (this=0x7fbdcc329378, request=0x7fbdcc327980, root=...) at Head.cpp:51
#7 0x000000000041009f in Request::parse_msg (this=0x7fbdcc329370, request=0x7fbdcc327980, num_record=@0x7fbddbbb2b68) at Request.cpp:41
#8 0x000000000041baf8 in HttpHandler::handle (request=0x7fbdcc327980, a=<value optimized out>) at HttpHandler.cpp:114
#9 0x000000000042b010 in _evhtp_request_parser_fini ()
#10 0x000000000043010b in htparser_run ()
#11 0x000000000042bdb1 in _evhtp_connection_readcb ()
#12 0x00007fbddefe1ee5 in bufferevent_readcb (fd=<value optimized out>, event=<value optimized out>, arg=0x7fbdcc0d47a0) at bufferevent_sock.c:186
#13 0x00007fbddefd9e0c in event_process_active_single_queue (base=0x7fbdcc0008f0, flags=0) at event.c:1350
#14 event_process_active (base=0x7fbdcc0008f0, flags=0) at event.c:1420
#15 event_base_loop (base=0x7fbdcc0008f0, flags=0) at event.c:1621
#16 0x0000000000431152 in _evthr_loop ()
#17 0x0000003ddb6077f1 in start_thread () from /lib64/libpthread.so.0
#18 0x0000003ddaee5ccd in clone () from /lib64/libc.so.6
跳到堆栈中某一层,这里是第7层
(gdb) f 7
#7 0x000000000041009f in Request::parse_msg (this=0x7fbdcc329370, request=0x7fbdcc327980, num_record=@0x7fbddbbb2b68) at Request.cpp:41
41 Request.cpp: 没有那个文件或目录.
in Request.cpp
打印变量值str_msg
(gdb) p str_msg
$8 =
"{\"ex\":[],\"pr\":[{\"e\":1394130724051,\"s\":1394130632364,\"c\":1,\"i\":1394130724052,\"p\":[{\"n\":\"desktopspeedup.DesktopSpeedUpAnimationActivity\",\"d\":8116,\"ps\":1},{\"n\":\"manage.AccelerateActivity\",\"d\":24918,\"ps\":"...
如果字符串太长,结尾以
...
表示,可以通过set print elements 0
调整
2014-03-10@迈科龙
评论