• 嵌入式linux下core文件分析


    配置core文件生成

    # ulimit -c unlimited
    # echo "/var/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
    # cat /proc/sys/kernel/core_pattern
    /var/core-%e-%p-%t
    

    生成的core

    # ls /var/core-dump-1063-991181935 
    

    使用API导致的崩溃

    # arm-none-linux-gnueabi-gdb a.out
    GNU gdb (Sourcery G++ Lite 2011.03-41) 7.2.50.20100908-cvs
    Copyright (C) 2010 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 "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi".
    For bug reporting instructions, please see:
    <https://support.codesourcery.com/GNUToolchain/>...
    Reading symbols from /mnt/hgfs/build/a.out...done.
    (gdb) 
    (gdb) set solib-search-path /home/rootfs/lib
    (gdb) info sharedlibrary 
    From        To          Syms Read   Shared Object Library
    0x401d501c  0x401e6f64  Yes (*)     /home/rootfs/lib/libgcc_s.so.1
    0x40206c00  0x402ffb5c  Yes (*)     /home/rootfs/lib/libc.so.6
    0x4007e7d0  0x40098f58  Yes (*)     /home/rootfs/lib/ld-linux.so.3
    (*): Shared library is missing debugging information.
    (gdb) core-file /home/core-dump-1063-991181935 
    warning: exec file is newer than core file.
    [New LWP 1063]
    Reading symbols from /home/rootfs/lib/libgcc_s.so.1...(no debugging symbols found)...done.
    Loaded symbols for /home/rootfs/lib/libgcc_s.so.1
    Reading symbols from /home/rootfs/lib/libc.so.6...(no debugging symbols found)...done.
    Loaded symbols for /home/rootfs/lib/libc.so.6
    Reading symbols from /home/rootfs/lib/ld-linux.so.3...(no debugging symbols found)...done.
    Loaded symbols for /home/rootfs/lib/ld-linux.so.3
    Core was generated by `./dump'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x4026e854 in memcpy () from /home/rootfs/lib/libc.so.6
    (gdb) 
    

    堆栈信息

    (gdb) bt
    #0  0x40309eb8 in memmove () from /lib/libc.so.6
    #1  0x0007b644 in std::__copy_move<false, true, std::random_access_iterator_tag>::__copy_m<char> (__first=0xaa <error: Cannot access memory at address 0xaa>, __last=0x0, 
        __result=0x169fa0 "\034\230<@\034\230<@\230\237\026")
        at /home/zyyt/worker/toolchain/arm-2011.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/include/c++/4.5.2/bits/stl_algobase.h:386
    #2  0x0007b5ec in std::__copy_move_a<false, char*, char*> (__first=0xaa <error: Cannot access memory at address 0xaa>, __last=0x0, __result=0x169fa0 "\034\230<@\034\230<@\230\237\026")
        at /home/zyyt/worker/toolchain/arm-2011.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/include/c++/4.5.2/bits/stl_algobase.h:404
    #3  0x0007b53c in std::__copy_move_a2<false, char*, char*> (__first=0xaa <error: Cannot access memory at address 0xaa>, __last=0x0, __result=0x169fa0 "\034\230<@\034\230<@\230\237\026")
        at /home/zyyt/worker/toolchain/arm-2011.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/include/c++/4.5.2/bits/stl_algobase.h:442
    #4  0x0007b40c in std::copy<char*, char*> (__first=0xaa <error: Cannot access memory at address 0xaa>, __last=0x0, __result=0x169fa0 "\034\230<@\034\230<@\230\237\026")
        at /home/zyyt/worker/toolchain/arm-2011.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/include/c++/4.5.2/bits/stl_algobase.h:474
    #5  0x0007af50 in Smart::Buffer::expand (this=0x44e00510, len=170) at src/7_freamwork/_net/_buffer.cpp:17
    #6  0x0007ae88 in Smart::Buffer::makeRoom (this=0x44e00510, len=170) at src/7_freamwork/_net/_buffer.cpp:9
    #7  0x0007b2ec in Smart::Buffer::allocRoom (this=0x44e00510, len=170) at ./inc/_buffer.h:24
    #8  0x0007b334 in Smart::Buffer::append (this=0x44e00510, p=0x17b5f4 "\246\241\066\001\241", len=170) at ./inc/_buffer.h:25
    #9  0x000f446c in Smart::Buffer::append (this=0x44e00510, slice=...) at ./inc/_buffer.h:26
    #10 0x000f4254 in Smart::MsgCodec::encode (this=0x44e00678, msg=..., buf=...) at src/7_freamwork/_net/_codec.cpp:56
    #11 0x0008f724 in Smart::TcpConn::sendMsg (this=0x44e004e8, msg=...) at src/7_freamwork/_net/_tcp.cpp:374
    #12 0x000e86b0 in Communication::TcpServerLtdHandle::sendDataToTcp (this=0xbefcf7f0, con=..., data=...) at src/2_communication/_tcp/ltd/_tcpserver_ltdhandle.cpp:1788
    #13 0x000e83f4 in Communication::TcpServerLtdHandle::sendData (this=0xbefcf7f0, con=..., type=54 '6', state=161 '\241', data=...)
        at src/2_communication/_tcp/ltd/_tcpserver_ltdhandle.cpp:1751
    #14 0x000e14dc in Communication::TcpServerLtdHandle::getElectricityLTD_new (this=0xbefcf7f0, con=..., Pos=0) at src/2_communication/_tcp/ltd/_tcpserver_ltdhandle.cpp:983
    #15 0x00077954 in Communication::TcpServerHandle::handleTcpCommFromLtd (this=0xbefcf7bc, con=..., str=...) at src/2_communication/_tcp/_tcpserverhandle.cpp:124
    #16 0x00076fc8 in Communication::TcpServerHandle::handleTcpComm (this=0xbefcf7bc, con=..., str=...) at src/2_communication/_tcp/_tcpserverhandle.cpp:34
    #17 0x000e8e04 in operator() (this=0x44e00900, con=..., input=...) at src/2_communication/_tcp/_tcpservercontrol.cpp:18
    #18 0x000e9538 in std::_Function_handler<std::basic_string<char, std::char_traits<char>, std::allocator<char> >(const std::shared_ptr<Smart::TcpConn>&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&), Communication::TcpServerControl::Run()::<lambda(const Smart::TcpConnPtr&, const std::string&)> >::_M_invoke(const std::_Any_data &, const std::shared_ptr<Smart::TcpConn> &, const std::basic_string<char, std::char_traits<char>, std::allocator<char> > &) (__functor=..., __args#0=..., __args#1=...)
        at /home/zyyt/worker/toolchain/arm-2011.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/include/c++/4.5.2/functional:1699
    #19 0x00095900 in std::function<std::string (std::shared_ptr<Smart::TcpConn> const&, std::string const&)>::operator()(std::shared_ptr<Smart::TcpConn> const&, std::string const&) const (
        this=0x44e008d8, __args#0=..., __args#1=...)
        at /home/zyyt/worker/toolchain/arm-2011.03/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.2/../../../../arm-none-linux-gnueabi/include/c++/4.5.2/functional:2116
    #20 0x00090b3c in operator() (this=0x44e008d8) at src/7_freamwork/_net/_tcp.cpp:489
    #21 0x0009253c in std::_Function_handler<void(), Smart::HSHA::onMsg(Smart::CodecBase*, const Smart::RetMsgCallBack&)::<lambda(const Smart::TcpConnPtr&, Smart::Slice)>::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...)
    

    代码引起的段错误

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <signal.h>
    
    void dump_backtrace(int signum){
    	signal(signum,SIG_DFL);
    
    	int j, nptrs;
    #define SIZE 100
    	void *buffer[100];
    	char **strings;
    
    	nptrs = backtrace(buffer, SIZE);
    	printf("backtrace() returned %d addresses\n", nptrs);
    
    	/* The call backtrace_symbols_fd(buffer, nptrs,
    	 * STDOUT_FILENO)
    	 *        would produce similar output to the
    	 *        following: */
    
    	strings = backtrace_symbols(buffer, nptrs);
    	if (strings == NULL) {
    		perror("backtrace_symbols");
    		exit(EXIT_FAILURE);
    	}
    
    	for (j = 0; j < nptrs; j++){
    		printf("%s\n", strings[j]);
    	}
    
    	free(strings);
    }
    
    int main()
    {
    	char *str = NULL;
    
    	signal(SIGSEGV, dump_backtrace); 
    
    	*str = 'a';
    
    	return 0;
    }
    
    $ arm-none-linux-gnueabi-gdb dump
    GNU gdb (Sourcery G++ Lite 2011.03-41) 7.2.50.20100908-cvs
    Copyright (C) 2010 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 "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi".
    For bug reporting instructions, please see:
    <https://support.codesourcery.com/GNUToolchain/>...
    Reading symbols from /home/dump...done.
    (gdb) core-file core-dump-2255-88331 
    warning: exec file is newer than core file.
    [New LWP 2255]
    warning: Could not load shared library symbols for 3 libraries, e.g. /lib/libgcc_s.so.1.
    Use the "info sharedlibrary" command to see the complete listing.
    Do you need "set solib-search-path" or "set sysroot"?
    warning: Unable to find dynamic linker.
    GDB will be unable to debug shared library initializers
    and track explicitly loaded dynamic code.
    Core was generated by `./dump'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x00008684 in main () at dump.c:41
    41		*str = 'a';
    (gdb) 
    
    $ arm-none-linux-gnueabi-addr2line -e dump 0x00008684 -f
    main
    /home/dump.c:41
    
  • 相关阅读:
    2017-2018-1 20179226 《文献管理与信息分析》第1讲学习总结
    2017-2018-1 20179226《Linux内核原理与分析》第十一周作业
    2017-2018-1 20179226《Linux内核原理与分析》第十周作业
    2017-2018-1 20179226 《从问题到程序》第2周学习总结
    2017-2018-1 20179226 《构建之法》第1周学习总结
    掌握一种编辑器-Vim
    2017-2018-1 20179226 《深入理解计算机系统》第1周学习总结
    2017-2018-1 20179209《Linux内核原理与分析》第二周作业
    20179209《Linux内核原理与分析》第一周作业
    linux_cpu信息查询
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/15562117.html
Copyright © 2020-2023  润新知