]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdb_gcore.sh
* win32-low.c (win32_add_one_solib): If the dll name is
[thirdparty/binutils-gdb.git] / gdb / gdb_gcore.sh
CommitLineData
627bf7c1
EZ
1#!/bin/sh
2
0fb0cc75 3# Copyright (C) 2003, 2005, 2007, 2008, 2009 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
50efebf8 7# the Free Software Foundation; either version 3 of the License, or
627bf7c1 8# (at your option) any later version.
50efebf8 9#
627bf7c1
EZ
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.
50efebf8 14#
627bf7c1 15# You should have received a copy of the GNU General Public License
50efebf8 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
627bf7c1 17
627bf7c1
EZ
18#
19# gcore.sh
20# Script to generate a core file of a running program.
21# It starts up gdb, attaches to the given PID and invokes the gcore command.
22#
23
24if [ "$#" -eq "0" ]
25then
26 echo "usage: gcore [-o filename] pid"
27 exit 2
28fi
29
30# Need to check for -o option, but set default basename to "core".
31name=core
32
33if [ "$1" = "-o" ]
34then
35 if [ "$#" -lt "3" ]
36 then
37 # Not enough arguments.
38 echo "usage: gcore [-o filename] pid"
39 exit 2
40 fi
41 name=$2
42
43 # Shift over to start of pid list
44 shift; shift
45fi
46
dfb893af
DJ
47# Create a temporary file. Use mktemp if available, but cope if it is not.
48tmpfile=`mktemp ${name}.XXXXXX 2>/dev/null` || {
49 tmpfile=${name}.$$
50 if test -e $tmpfile; then
51 echo "Could not create temporary file $tmpfile"
52 exit 1
53 fi
54 touch $tmpfile
55}
56trap "rm -f $tmpfile" EXIT
57
627bf7c1
EZ
58# Initialise return code.
59rc=0
60
61# Loop through pids
62for pid in $*
63do
64 # Write gdb script for pid $pid.
dfb893af
DJ
65 cat >>$tmpfile <<EOF
66attach $pid
67gcore $name.$pid
68detach
69quit
627bf7c1
EZ
70EOF
71
dfb893af
DJ
72 gdb -x $tmpfile -batch
73
627bf7c1
EZ
74 if [ -r $name.$pid ] ; then
75 rc=0
76 else
77 echo gcore: failed to create $name.$pid
78 rc=1
79 break
80 fi
81
82
83done
84
85exit $rc