]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/postmortem/elf-core/gcore/make-core.sh
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / postmortem / elf-core / gcore / make-core.sh
1 #! /bin/sh
2
3 linux_check_ptrace_scope()
4 {
5     if grep -q '1' </proc/sys/kernel/yama/ptrace_scope; then
6         cat <<EOF
7 Your system prevents the use of PTRACE to attach to non-child processes. The core file
8 cannot be generated.  Please reset /proc/sys/kernel/yama/ptrace_scope to 0 (requires root
9 privileges) to enable core generation via gcore.
10 EOF
11         exit 1
12     fi
13 }
14
15 set -e -x
16
17 OS=$(uname -s)
18 if [ "$OS" = Linux ]; then
19     linux_check_ptrace_scope
20 fi
21
22 rm -f a.out
23 make -f main.mk
24
25 cat <<EOF
26 Executable file is in a.out.
27 Core file will be saved as core.<pid>.
28 EOF
29
30 stack_size=`ulimit -s`
31
32 # Decrease stack size to 16k => smaller core files.
33 # gcore won't run with the smaller stack
34 ulimit -Ss 16
35
36 core_dump_filter=`cat /proc/self/coredump_filter`
37 echo 0 > /proc/self/coredump_filter
38
39 ./a.out &
40
41 pid=$!
42
43 echo $core_dump_filter > /proc/self/coredump_filter
44
45 # Reset stack size as so there's enough space to run gcore.
46 ulimit -s $stack_size
47
48 echo "Sleeping for 5 seconds to wait for $pid"
49
50 sleep 5
51 echo "Taking core from process $pid"
52
53 gcore -o core $pid
54
55 echo "Killing process $pid"
56 kill -9 $pid