3 # Copyright (C) 2003, 2005 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301, USA.
22 # Script to generate a core file of a running program.
23 # It starts up gdb, attaches to the given PID and invokes the gcore command.
28 echo "usage: gcore [-o filename] pid"
32 # Need to check for -o option, but set default basename to "core".
39 # Not enough arguments.
40 echo "usage: gcore [-o filename] pid"
45 # Shift over to start of pid list
49 # Create a temporary file. Use mktemp if available, but cope if it is not.
50 tmpfile=`mktemp ${name}.XXXXXX 2>/dev/null` || {
52 if test -e $tmpfile; then
53 echo "Could not create temporary file $tmpfile"
58 trap "rm -f $tmpfile" EXIT
60 # Initialise return code.
66 # Write gdb script for pid $pid.
74 gdb -x $tmpfile -batch
76 if [ -r $name.$pid ] ; then
79 echo gcore: failed to create $name.$pid