]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/make-core.sh
Vendor import of lldb release_39 branch r287912:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / postmortem / elf-core / make-core.sh
1 #! /bin/sh
2
3 linux_check_core_pattern()
4 {
5     if grep -q '^|' </proc/sys/kernel/core_pattern; then
6         cat <<EOF
7 Your system uses a crash report tool ($(cat /proc/sys/kernel/core_pattern)). Core files
8 will not be generated.  Please reset /proc/sys/kernel/core_pattern (requires root
9 privileges) to enable core generation.
10 EOF
11         exit 1
12     fi
13 }
14
15 OS=$(uname -s)
16 case "$OS" in
17 FreeBSD)
18     core_pattern=$(sysctl -n kern.corefile)
19     ;;
20 Linux)
21     core_pattern=$(cat /proc/sys/kernel/core_pattern)
22     ;;
23 *)
24     echo "OS $OS not supported" >&2
25     exit 1
26     ;;
27 esac
28
29 set -e -x
30
31 file=$1
32 if [ -z "$file" ]; then
33     cat <<EOF
34 Please supply the main source file as the first argument.
35 EOF
36     exit 1
37 fi
38
39 if [ "$OS" = Linux ]; then
40     linux_check_core_pattern
41 fi
42
43 ulimit -c 1000
44 real_limit=$(ulimit -c)
45 if [ $real_limit -lt 100 ]; then
46     cat <<EOF
47 Unable to increase the core file limit. Core file may be truncated!
48 To fix this, increase HARD core file limit (ulimit -H -c 1000). This may require root
49 privileges.
50 EOF
51 fi
52
53 ${CC:-cc} -nostdlib -static -g $CFLAGS "$file" -o a.out
54
55 cat <<EOF
56 Executable file is in a.out.
57 Core file will be saved according to pattern $core_pattern.
58 EOF
59
60 ulimit -s 8 # Decrease stack size to 8k => smaller core files.
61 exec ./a.out