merge from gcc
[deliverable/binutils-gdb.git] / gdb / gdb_gcore.sh
CommitLineData
627bf7c1
EZ
1#!/bin/sh
2
dfb893af 3# Copyright 2003, 2005 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
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
627bf7c1
EZ
19#
20# gcore.sh
21# Script to generate a core file of a running program.
22# It starts up gdb, attaches to the given PID and invokes the gcore command.
23#
24
25if [ "$#" -eq "0" ]
26then
27 echo "usage: gcore [-o filename] pid"
28 exit 2
29fi
30
31# Need to check for -o option, but set default basename to "core".
32name=core
33
34if [ "$1" = "-o" ]
35then
36 if [ "$#" -lt "3" ]
37 then
38 # Not enough arguments.
39 echo "usage: gcore [-o filename] pid"
40 exit 2
41 fi
42 name=$2
43
44 # Shift over to start of pid list
45 shift; shift
46fi
47
dfb893af
DJ
48# Create a temporary file. Use mktemp if available, but cope if it is not.
49tmpfile=`mktemp ${name}.XXXXXX 2>/dev/null` || {
50 tmpfile=${name}.$$
51 if test -e $tmpfile; then
52 echo "Could not create temporary file $tmpfile"
53 exit 1
54 fi
55 touch $tmpfile
56}
57trap "rm -f $tmpfile" EXIT
58
627bf7c1
EZ
59# Initialise return code.
60rc=0
61
62# Loop through pids
63for pid in $*
64do
65 # Write gdb script for pid $pid.
dfb893af
DJ
66 cat >>$tmpfile <<EOF
67attach $pid
68gcore $name.$pid
69detach
70quit
627bf7c1
EZ
71EOF
72
dfb893af
DJ
73 gdb -x $tmpfile -batch
74
627bf7c1
EZ
75 if [ -r $name.$pid ] ; then
76 rc=0
77 else
78 echo gcore: failed to create $name.$pid
79 rc=1
80 break
81 fi
82
83
84done
85
86exit $rc
This page took 0.239282 seconds and 4 git commands to generate.