00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "bfd.h"
00029
00030 #ifdef AIX_5_CORE
00031
00032 #include "sysdep.h"
00033 #include "libbfd.h"
00034
00035 const bfd_target *xcoff64_core_p
00036 PARAMS ((bfd *));
00037 bfd_boolean xcoff64_core_file_matches_executable_p
00038 PARAMS ((bfd *, bfd *));
00039 char *xcoff64_core_file_failing_command
00040 PARAMS ((bfd *));
00041 int xcoff64_core_file_failing_signal
00042 PARAMS ((bfd *));
00043
00044
00045
00046
00047 #define __LDINFO_PTRACE64__
00048 #include <sys/ldr.h>
00049 #include <core.h>
00050
00051 #define core_hdr(abfd) ((struct core_dumpxx *) abfd->tdata.any)
00052
00053 #define CHECK_FILE_OFFSET(s, v) \
00054 ((bfd_signed_vma)(v) < 0 || (bfd_signed_vma)(v) > (bfd_signed_vma)(s).st_size)
00055
00056 const bfd_target *
00057 xcoff64_core_p (abfd)
00058 bfd *abfd;
00059 {
00060 struct core_dumpxx core, *new_core_hdr;
00061 struct stat statbuf;
00062 asection *sec;
00063 struct __ld_info64 ldinfo;
00064 bfd_vma ld_offset;
00065 bfd_size_type i;
00066 struct vm_infox vminfo;
00067 bfd_target *return_value = NULL;
00068
00069
00070 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
00071 goto xcoff64_core_p_error;
00072
00073 if (sizeof (struct core_dumpxx)
00074 != bfd_bread (&core, sizeof (struct core_dumpxx), abfd))
00075 goto xcoff64_core_p_error;
00076
00077 if (bfd_stat (abfd, &statbuf) < 0)
00078 goto xcoff64_core_p_error;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 if ((CORE_VERSION_1 != (core.c_flag & CORE_VERSION_1))
00094 || (0 != core.c_entries)
00095 || (! (IS_PROC64 (&core.c_u.U_proc)))
00096 || ((CHECK_FILE_OFFSET (statbuf, core.c_fdsinfox)))
00097 || ((CHECK_FILE_OFFSET (statbuf, core.c_loader)))
00098 || ((CHECK_FILE_OFFSET (statbuf, core.c_loader + core.c_lsize)))
00099 || ((CHECK_FILE_OFFSET (statbuf, core.c_thr)))
00100 || ((CHECK_FILE_OFFSET (statbuf, core.c_segregion)))
00101 || ((CHECK_FILE_OFFSET (statbuf, core.c_stack)))
00102 || ((CHECK_FILE_OFFSET (statbuf, core.c_stack + core.c_size)))
00103 || ((CHECK_FILE_OFFSET (statbuf, core.c_data)))
00104 || ((CHECK_FILE_OFFSET (statbuf, core.c_data + core.c_datasize)))
00105 || (! (core.c_flag & UBLOCK_VALID))
00106 || (! (core.c_flag & LE_VALID)))
00107 goto xcoff64_core_p_error;
00108
00109
00110 if ((! (core.c_flag & USTACK_VALID))
00111 || (core.c_flag & CORE_TRUNC))
00112 {
00113 bfd_set_error (bfd_error_file_truncated);
00114
00115 return return_value;
00116 }
00117
00118 new_core_hdr = (struct core_dumpxx *)
00119 bfd_zalloc (abfd, sizeof (struct core_dumpxx));
00120 if (NULL == new_core_hdr)
00121 return return_value;
00122
00123 memcpy (new_core_hdr, &core, sizeof (struct core_dumpxx));
00124 core_hdr(abfd) = (char *)new_core_hdr;
00125
00126
00127 sec = bfd_make_section_anyway (abfd, ".stack");
00128 if (NULL == sec)
00129 return return_value;
00130
00131 sec->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
00132 sec->size = core.c_size;
00133 sec->vma = core.c_stackorg;
00134 sec->filepos = core.c_stack;
00135
00136
00137 sec = bfd_make_section_anyway (abfd, ".reg");
00138 if (NULL == sec)
00139 return return_value;
00140
00141 sec->flags = SEC_HAS_CONTENTS | SEC_IN_MEMORY;
00142 sec->size = sizeof (struct __context64);
00143 sec->vma = 0;
00144 sec->filepos = 0;
00145 sec->contents = (bfd_byte *)&new_core_hdr->c_flt.r64;
00146
00147
00148
00149
00150
00151 sec = bfd_make_section_anyway (abfd, ".ldinfo");
00152 if (NULL == sec)
00153 return return_value;
00154
00155 sec->flags = SEC_HAS_CONTENTS;
00156 sec->size = core.c_lsize;
00157 sec->vma = 0;
00158 sec->filepos = core.c_loader;
00159
00160
00161
00162
00163
00164
00165 sec = bfd_make_section_anyway (abfd, ".data");
00166 if (NULL == sec)
00167 return return_value;
00168
00169 sec->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
00170 sec->size = core.c_datasize;
00171 sec->vma = core.c_dataorg;
00172 sec->filepos = core.c_data;
00173
00174
00175 ld_offset = core.c_loader;
00176
00177 while (1)
00178 {
00179 if (bfd_seek (abfd, ld_offset, SEEK_SET) != 0)
00180 return return_value;
00181
00182 if (sizeof (struct __ld_info64) !=
00183 bfd_bread (&ldinfo, sizeof (struct __ld_info64), abfd))
00184 return return_value;
00185
00186 if (ldinfo.ldinfo_core)
00187 {
00188 sec = bfd_make_section_anyway (abfd, ".data");
00189 if (NULL == sec)
00190 return return_value;
00191
00192 sec->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
00193 sec->size = ldinfo.ldinfo_datasize;
00194 sec->vma = ldinfo.ldinfo_dataorg;
00195 sec->filepos = ldinfo.ldinfo_core;
00196 }
00197
00198 if (0 == ldinfo.ldinfo_next)
00199 break;
00200 ld_offset += ldinfo.ldinfo_next;
00201 }
00202
00203
00204 if (core.c_vmregions)
00205 {
00206 if (bfd_seek (abfd, core.c_vmm, SEEK_SET) != 0)
00207 return return_value;
00208
00209 for (i = 0; i < core.c_vmregions; i++)
00210 if (sizeof (struct vm_infox) !=
00211 bfd_bread (&vminfo, sizeof (struct vm_infox), abfd))
00212 return return_value;
00213
00214 if (vminfo.vminfo_offset)
00215 {
00216 sec = bfd_make_section_anyway (abfd, ".vmdata");
00217 if (NULL == sec)
00218 return return_value;
00219
00220 sec->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
00221 sec->size = vminfo.vminfo_size;
00222 sec->vma = vminfo.vminfo_addr;
00223 sec->filepos = vminfo.vminfo_offset;
00224 }
00225 }
00226
00227 return_value = abfd->xvec;
00228
00229 xcoff64_core_p_error:
00230 if (bfd_get_error () != bfd_error_system_call)
00231 bfd_set_error (bfd_error_wrong_format);
00232
00233 return return_value;
00234 }
00235
00236
00237
00238 bfd_boolean
00239 xcoff64_core_file_matches_executable_p (core_bfd, exec_bfd)
00240 bfd *core_bfd;
00241 bfd *exec_bfd;
00242 {
00243 struct core_dumpxx core;
00244 char *path, *s;
00245 size_t alloc;
00246 const char *str1, *str2;
00247 bfd_boolean return_value = FALSE;
00248
00249
00250 if (bfd_seek (core_bfd, 0, SEEK_SET) != 0)
00251 return return_value;
00252
00253 if (sizeof (struct core_dumpxx) !=
00254 bfd_bread (&core, sizeof (struct core_dumpxx), core_bfd))
00255 return return_value;
00256
00257 if (bfd_seek (core_bfd, core.c_loader, SEEK_SET) != 0)
00258 return return_value;
00259
00260 alloc = 100;
00261 path = bfd_malloc (alloc);
00262 if (path == NULL)
00263 return return_value;
00264
00265 s = path;
00266
00267 while (1)
00268 {
00269 if (bfd_bread (s, 1, core_bfd) != 1)
00270 goto xcoff64_core_file_matches_executable_p_end_1;
00271
00272 if (*s == '\0')
00273 break;
00274 ++s;
00275 if (s == path + alloc)
00276 {
00277 char *n;
00278
00279 alloc *= 2;
00280 n = bfd_realloc (path, alloc);
00281 if (n == NULL)
00282 goto xcoff64_core_file_matches_executable_p_end_1;
00283
00284 s = n + (path - s);
00285 path = n;
00286 }
00287 }
00288
00289 str1 = strrchr (path, '/');
00290 str2 = strrchr (exec_bfd->filename, '/');
00291
00292
00293 str1 = str1 != NULL ? str1 + 1 : path;
00294 str2 = str2 != NULL ? str2 + 1 : exec_bfd->filename;
00295
00296 if (strcmp (str1, str2) == 0)
00297 return_value = TRUE;
00298
00299 xcoff64_core_file_matches_executable_p_end_1:
00300 free (path);
00301 return return_value;
00302 }
00303
00304 char *
00305 xcoff64_core_file_failing_command (abfd)
00306 bfd *abfd;
00307 {
00308 struct core_dumpxx *c = core_hdr (abfd);
00309 char *return_value = 0;
00310
00311 if (NULL != c)
00312 return_value = c->c_u.U_proc.pi_comm;
00313
00314 return return_value;
00315 }
00316
00317 int
00318 xcoff64_core_file_failing_signal (abfd)
00319 bfd *abfd;
00320 {
00321 struct core_dumpxx *c = core_hdr (abfd);
00322 int return_value = 0;
00323
00324 if (NULL != c)
00325 return_value = c->c_signo;
00326
00327 return return_value;
00328 }
00329
00330 #else
00331
00332 const bfd_target *xcoff64_core_p
00333 PARAMS ((bfd *));
00334 bfd_boolean xcoff64_core_file_matches_executable_p
00335 PARAMS ((bfd *, bfd *));
00336 char *xcoff64_core_file_failing_command
00337 PARAMS ((bfd *));
00338 int xcoff64_core_file_failing_signal
00339 PARAMS ((bfd *));
00340
00341 const bfd_target *
00342 xcoff64_core_p (abfd)
00343 bfd *abfd ATTRIBUTE_UNUSED;
00344 {
00345 bfd_set_error (bfd_error_wrong_format);
00346 return 0;
00347 }
00348
00349 bfd_boolean
00350 xcoff64_core_file_matches_executable_p (core_bfd, exec_bfd)
00351 bfd *core_bfd ATTRIBUTE_UNUSED;
00352 bfd *exec_bfd ATTRIBUTE_UNUSED;
00353 {
00354 return FALSE;
00355 }
00356
00357 char *
00358 xcoff64_core_file_failing_command (abfd)
00359 bfd *abfd ATTRIBUTE_UNUSED;
00360 {
00361 return 0;
00362 }
00363
00364 int
00365 xcoff64_core_file_failing_signal (abfd)
00366 bfd *abfd ATTRIBUTE_UNUSED;
00367 {
00368 return 0;
00369 }
00370
00371 #endif