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