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