]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdb_gcore.sh
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / gdb_gcore.sh
CommitLineData
627bf7c1
EZ
1#!/bin/sh
2
6aba47ca 3# Copyright (C) 2003, 2005, 2007 Free Software Foundation, Inc.
627bf7c1
EZ
4
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.
9#
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.
14#
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
197e01b6
EZ
17# Foundation, Inc., 51 Franklin Street, Fifth Floor,
18# Boston, MA 02110-1301, USA.
627bf7c1 19
627bf7c1
EZ
20#
21# gcore.sh
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.
24#
25
26if [ "$#" -eq "0" ]
27then
28 echo "usage: gcore [-o filename] pid"
29 exit 2
30fi
31
32# Need to check for -o option, but set default basename to "core".
33name=core
34
35if [ "$1" = "-o" ]
36then
37 if [ "$#" -lt "3" ]
38 then
39 # Not enough arguments.
40 echo "usage: gcore [-o filename] pid"
41 exit 2
42 fi
43 name=$2
44
45 # Shift over to start of pid list
46 shift; shift
47fi
48
dfb893af
DJ
49# Create a temporary file. Use mktemp if available, but cope if it is not.
50tmpfile=`mktemp ${name}.XXXXXX 2>/dev/null` || {
51 tmpfile=${name}.$$
52 if test -e $tmpfile; then
53 echo "Could not create temporary file $tmpfile"
54 exit 1
55 fi
56 touch $tmpfile
57}
58trap "rm -f $tmpfile" EXIT
59
627bf7c1
EZ
60# Initialise return code.
61rc=0
62
63# Loop through pids
64for pid in $*
65do
66 # Write gdb script for pid $pid.
dfb893af
DJ
67 cat >>$tmpfile <<EOF
68attach $pid
69gcore $name.$pid
70detach
71quit
627bf7c1
EZ
72EOF
73
dfb893af
DJ
74 gdb -x $tmpfile -batch
75
627bf7c1
EZ
76 if [ -r $name.$pid ] ; then
77 rc=0
78 else
79 echo gcore: failed to create $name.$pid
80 rc=1
81 break
82 fi
83
84
85done
86
87exit $rc