Add support to GDB for the Renesas rl78 architecture.
[external/binutils.git] / gdb / gdb_gcore.sh
1 #!/bin/sh
2
3 #   Copyright (C) 2003, 2005, 2007-2012 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
17
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
24 if [ "$#" -eq "0" ]
25 then
26     echo "usage:  gcore [-o filename] pid"
27     exit 2
28 fi
29
30 # Need to check for -o option, but set default basename to "core".
31 name=core
32
33 if [ "$1" = "-o" ]
34 then
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
45 fi
46
47 # Initialise return code.
48 rc=0
49
50 # Loop through pids
51 for pid in $*
52 do
53         # `</dev/null' to avoid touching interactive terminal if it is
54         # available but not accessible as GDB would get stopped on SIGTTIN.
55         gdb </dev/null --nx --batch \
56             -ex "set pagination off" -ex "set height 0" -ex "set width 0" \
57             -ex "attach $pid" -ex "gcore $name.$pid" -ex detach -ex quit
58
59         if [ -r $name.$pid ] ; then 
60             rc=0
61         else
62             echo gcore: failed to create $name.$pid
63             rc=1
64             break
65         fi
66
67
68 done
69
70 exit $rc