顯示具有 core dump 標籤的文章。 顯示所有文章
顯示具有 core dump 標籤的文章。 顯示所有文章

2015年2月7日 星期六

[Embedded] GDB script -- generate a basic report per core file

wikibook 針對 core dump 使用,提供了幾個有用的 script,其中有個自動產生報表的方式對我幫助很大。摘錄如下:


#!/bin/bash

#
# A script to extract core-file informations
#


if [ $# -ne 1 ]
then
echo "Usage: `basename $0` "
exit -1
else
binimg=$1
fi


# Today and yesterdays cores
cores=`find . -name '*.core' -mtime -1`

#cores=`find . -name '*.core'`


for core in $cores
do
gdblogfile="$core-gdb.log"
rm $gdblogfile

bininfo=`ls -l $binimg`
coreinfo=`ls -l $core`

gdb -batch \
-ex "set logging file $gdblogfile" \
-ex "set logging on" \
-ex "set pagination off" \
-ex "printf \"**\n** Process info for $binimg - $core \n** Generated `date`\n\"" \
-ex "printf \"**\n** $bininfo \n** $coreinfo\n**\n\"" \
-ex "file $binimg" \
-ex "core-file $core" \
-ex "bt" \
-ex "info proc" \
-ex "printf \"*\n* Libraries \n*\n\"" \
-ex "info sharedlib" \
-ex "printf \"*\n* Memory map \n*\n\"" \
-ex "info target" \
-ex "printf \"*\n* Registers \n*\n\"" \
-ex "info registers" \
-ex "printf \"*\n* Current instructions \n*\n\"" -ex "x/16i \$pc" \
-ex "printf \"*\n* Threads (full) \n*\n\"" \
-ex "info threads" \
-ex "bt" \
-ex "thread apply all bt full" \
-ex "printf \"*\n* Threads (basic) \n*\n\"" \
-ex "info threads" \
-ex "thread apply all bt" \
-ex "printf \"*\n* Done \n*\n\"" \
-ex "quit"
done

Reference:
http://en.m.wikibooks.org/wiki/Linux_Applications_Debugging_Techniques/Core_files

2015年1月24日 星期六

[Embedded] Why no core dump after segmentation fault?

1. Follow below command to set core dump generated in embedded Linux.
$ ulimit -c 1024
$ echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern

2. Why no core dump?
  • no write access to the directory 
  • use "ls" to check
  • the program changes the working directory 
  • how to check??
  • look for the core in other places too 
  • use "sysctl -a | grep core_pattern" to check
  • disk is full 
  • use "df ." to check
  • most Unix systems do not allow a setuid process to dump core 
  • use "cat /proc/sys/fs/suid_dumpable" to check,  
  • use "echo 1 > /proc/sys/fs/suid_dumpable" to change setting 
  • ulimit is set in one shell and the program is started in a different shell or environment
  • check /proc/pid/environ for current shell
  • note that only the program executed after "ulimit -c 1024" can generate core

3. We can use "kill -ABRT  pid_of_process" to generate core manually.

4. Check /proc/pid/limits for system limit
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytesMax resident set          unlimited            unlimited            bytes
Max processes             748                  748                  processes
Max open files            1024                 1024                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       748                  748                  signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Reference:
  1. http://stackoverflow.com/questions/15272817/segmentation-fault-no-core-dump
  2. http://www.idimmu.net/2013/06/21/enable-linux-core-dump/
  3. http://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
  4. http://blog.csdn.net/pro_or_gram/article/details/15813879
  5. http://linuxxperts.com/enabling-core-dumps-in-embedded-systems/
  6. http://tieba.baidu.com/p/2365639005

2012年2月29日 星期三

[轉] 使用 Core Dump 找出問題


原文出處: http://blogger.org.cn/blog/more.asp?name=yach&id=22810

====
先看看我用的是什麼機器:

$ uname -a
Linux dev 2.4.21-9.30AXsmp #1 SMP Wed May 26 23:37:09 EDT 2004 i686 i686 i386 GNU/Linux

再看看預設的一些參數,注意core file size若是0,程序出錯?不會產生core文件了。

$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 2048
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 7168
virtual memory (kbytes, -v) unlimited

寫個簡單的程序,看看core文件是不是會被產生。