daily update
[deliverable/binutils-gdb.git] / bfd / corefile.c
CommitLineData
252b5132 1/* Core file generic interface routines for BFD.
3db64b00
AM
2 Copyright 1990, 1991, 1992, 1993, 1994, 2000, 2001, 2002, 2003, 2005,
3 2007 Free Software Foundation, Inc.
252b5132
RH
4 Written by Cygnus Support.
5
cd123cb7
NC
6 This file is part of BFD, the Binary File Descriptor library.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132
RH
22
23/*
24SECTION
25 Core files
26
1b74d094
BW
27SUBSECTION
28 Core file functions
29
252b5132
RH
30DESCRIPTION
31 These are functions pertaining to core files.
32*/
33
252b5132 34#include "sysdep.h"
3db64b00 35#include "bfd.h"
252b5132
RH
36#include "libbfd.h"
37
252b5132
RH
38/*
39FUNCTION
40 bfd_core_file_failing_command
41
42SYNOPSIS
c58b9523 43 const char *bfd_core_file_failing_command (bfd *abfd);
252b5132
RH
44
45DESCRIPTION
46 Return a read-only string explaining which program was running
47 when it failed and produced the core file @var{abfd}.
48
49*/
50
3f9c735e 51const char *
c58b9523 52bfd_core_file_failing_command (bfd *abfd)
252b5132 53{
c58b9523
AM
54 if (abfd->format != bfd_core)
55 {
56 bfd_set_error (bfd_error_invalid_operation);
57 return NULL;
58 }
252b5132
RH
59 return BFD_SEND (abfd, _core_file_failing_command, (abfd));
60}
61
62/*
63FUNCTION
64 bfd_core_file_failing_signal
65
66SYNOPSIS
c58b9523 67 int bfd_core_file_failing_signal (bfd *abfd);
252b5132
RH
68
69DESCRIPTION
70 Returns the signal number which caused the core dump which
71 generated the file the BFD @var{abfd} is attached to.
72*/
73
74int
c58b9523 75bfd_core_file_failing_signal (bfd *abfd)
252b5132 76{
c58b9523
AM
77 if (abfd->format != bfd_core)
78 {
79 bfd_set_error (bfd_error_invalid_operation);
80 return 0;
81 }
252b5132
RH
82 return BFD_SEND (abfd, _core_file_failing_signal, (abfd));
83}
84
261b8d08
PA
85/*
86FUNCTION
87 bfd_core_file_pid
88
89SYNOPSIS
90 int bfd_core_file_pid (bfd *abfd);
91
92DESCRIPTION
93
94 Returns the PID of the process the core dump the BFD
95 @var{abfd} is attached to was generated from.
96*/
97
98int
99bfd_core_file_pid (bfd *abfd)
100{
101 if (abfd->format != bfd_core)
102 {
103 bfd_set_error (bfd_error_invalid_operation);
104 return 0;
105 }
106 return BFD_SEND (abfd, _core_file_pid, (abfd));
107}
108
109
252b5132
RH
110/*
111FUNCTION
112 core_file_matches_executable_p
113
114SYNOPSIS
b34976b6 115 bfd_boolean core_file_matches_executable_p
c58b9523 116 (bfd *core_bfd, bfd *exec_bfd);
252b5132
RH
117
118DESCRIPTION
b34976b6 119 Return <<TRUE>> if the core file attached to @var{core_bfd}
252b5132 120 was generated by a run of the executable file attached to
b34976b6 121 @var{exec_bfd}, <<FALSE>> otherwise.
252b5132 122*/
c58b9523 123
b34976b6 124bfd_boolean
c58b9523 125core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
252b5132 126{
c58b9523
AM
127 if (core_bfd->format != bfd_core || exec_bfd->format != bfd_object)
128 {
129 bfd_set_error (bfd_error_wrong_format);
130 return FALSE;
131 }
132
133 return BFD_SEND (core_bfd, _core_file_matches_executable_p,
134 (core_bfd, exec_bfd));
252b5132 135}
69d246d9
JB
136
137/*
138FUNCTION
139 generic_core_file_matches_executable_p
140
141SYNOPSIS
142 bfd_boolean generic_core_file_matches_executable_p
9bf46c00 143 (bfd *core_bfd, bfd *exec_bfd);
69d246d9
JB
144
145DESCRIPTION
146 Return TRUE if the core file attached to @var{core_bfd}
147 was generated by a run of the executable file attached
148 to @var{exec_bfd}. The match is based on executable
149 basenames only.
150
151 Note: When not able to determine the core file failing
152 command or the executable name, we still return TRUE even
153 though we're not sure that core file and executable match.
154 This is to avoid generating a false warning in situations
155 where we really don't know whether they match or not.
156*/
157
158bfd_boolean
159generic_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
160{
161 char *exec;
162 char *core;
163 char *last_slash;
164
165 if (exec_bfd == NULL || core_bfd == NULL)
166 return TRUE;
167
168 /* The cast below is to avoid a compiler warning due to the assignment
169 of the const char * returned by bfd_core_file_failing_command to a
170 non-const char *. In this case, the assignement does not lead to
171 breaking the const, as we're only reading the string. */
172
173 core = (char *) bfd_core_file_failing_command (core_bfd);
174 if (core == NULL)
175 return TRUE;
176
177 exec = bfd_get_filename (exec_bfd);
178 if (exec == NULL)
179 return TRUE;
180
181 last_slash = strrchr (core, '/');
182 if (last_slash != NULL)
183 core = last_slash + 1;
184
185 last_slash = strrchr (exec, '/');
186 if (last_slash != NULL)
187 exec = last_slash + 1;
188
007d6189 189 return filename_cmp (exec, core) == 0;
69d246d9
JB
190}
191
This page took 0.580378 seconds and 4 git commands to generate.