Monday, 14 March 2016

Debug Core Dump Cross Platform



1. Enable core dump in target board (embdedded linux 2.6.35)

#ulimit -c unlimited

2. Then run the target program to wait for a crash, a file called "core" will be generated on crash happened.


3. Copy the core file to PC through scp, ftp, http....
    You need the elf file as well, in this case, it is called main.



4. Debug in PC (Ubuntu linux)

sudo apt-get install gdb-multiarch

gdb-multiarch

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

(gdb) set gnutarget elf32-littlearm
or
(gdb) set gnutarget auto

(gdb) file main
Reading symbols from main...(no debugging symbols found)...done.
(gdb) target core core
[New LWP 7150]
warning: Could not load shared library symbols for 8 libraries, e.g. /lib/libdl.so.2.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Core was generated by `/minesite/prog/app/main'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0001b848 in Crc_CalcCrc32(unsigned int, unsigned char const*, unsigned int) ()
(gdb) bt

#0  0x0001b848 in Crc_CalcCrc32(unsigned int, unsigned char const*, unsigned int) ()
#1  0x0002050c in GetFwSizeCrc(char const*, unsigned int*, unsigned int*) ()
#2  0x00020780 in App_StartReflash(ConfigSpiDeviceType_T, unsigned char, FwUpdate*, SpiMessage_T*) ()
#3  0x00015c1c in FwUpSm::send_spi_msg_to_reflash_dev() ()
#4  0x00018758 in FwUpSm::event_handler(Msg const&) ()
#5  0x0003011c in Msg::handle() const ()
#6  0x0003019c in MsgQueue_Fd::send_msg(int, MsgHandler*, void*) ()
#7  0x00010e28 in MainSm::event_handler(Msg const&) ()
#8  0x0003011c in Msg::handle() const ()
#9  0x0003019c in MsgQueue_Fd::send_msg(int, MsgHandler*, void*) ()
#10 0x0000cd74 in SpiReadSm::send_msg_api_data_to_main(SpiMessage_T*) ()
#11 0x0000d318 in SpiReadSm::event_handler(Msg const&) ()
#12 0x0003011c in Msg::handle() const ()
#13 0x0003019c in MsgQueue_Fd::send_msg(int, MsgHandler*, void*) ()
#14 0x0000d368 in SpiReadSm::event_handler(Msg const&) ()
#15 0x0003011c in Msg::handle() const ()
#16 0x0003019c in MsgQueue_Fd::send_msg(int, MsgHandler*, void*) ()
#17 0x0000b8c8 in SPI_DEVICE::on_event() ()
#18 0x0002fcc0 in FileDescCommuSelector::run() ()
#19 0x0000b07c in main ()
(gdb)