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