Write Mimi's name in ASCII.
[deliverable/binutils-gdb.git] / bfd / rs6000-core.c
CommitLineData
252b5132 1/* IBM RS/6000 "XCOFF" back-end for BFD.
7898deda 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3db64b00 3 2001, 2002, 2004, 2006, 2007
252b5132 4 Free Software Foundation, Inc.
2ce18a16 5 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
252b5132
RH
6 Archive support from Damon A. Permezel.
7 Contributed by IBM Corporation and Cygnus Support.
8
eb1e0e80 9 This file is part of BFD, the Binary File Descriptor library.
252b5132 10
eb1e0e80
NC
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
252b5132 15
eb1e0e80
NC
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
252b5132 20
eb1e0e80
NC
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
3e110533 23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
24
25/* This port currently only handles reading object files, except when
26 compiled on an RS/6000 host. -- no archive support, no core files.
27 In all cases, it does not support writing.
28
252b5132 29 This is in a separate file from coff-rs6000.c, because it includes
6a125b16 30 system include files that conflict with coff/rs6000.h. */
252b5132
RH
31
32/* Internalcoff.h and coffcode.h modify themselves based on this flag. */
33#define RS6000COFF_C 1
34
35/* The AIX 4.1 kernel is obviously compiled with -D_LONG_LONG, so
36 we have to define _LONG_LONG for older versions of gcc to get the
37 proper alignments in the user structure. */
38#if defined(_AIX41) && !defined(_LONG_LONG)
39#define _LONG_LONG
40#endif
41
252b5132 42#include "sysdep.h"
3db64b00 43#include "bfd.h"
252b5132
RH
44#include "libbfd.h"
45
46#ifdef AIX_CORE
47
48/* AOUTHDR is defined by the above. We need another defn of it, from the
49 system include files. Punt the old one and get us a new name for the
50 typedef in the system include files. */
51#ifdef AOUTHDR
52#undef AOUTHDR
53#endif
54#define AOUTHDR second_AOUTHDR
55
56#undef SCNHDR
57
252b5132 58/* ------------------------------------------------------------------------ */
59d9f049 59/* Support for core file stuff.. */
252b5132
RH
60/* ------------------------------------------------------------------------ */
61
62#include <sys/user.h>
59d9f049
ND
63#define __LDINFO_PTRACE32__ /* for __ld_info32 */
64#define __LDINFO_PTRACE64__ /* for __ld_info64 */
252b5132
RH
65#include <sys/ldr.h>
66#include <sys/core.h>
59d9f049
ND
67#include <sys/systemcfg.h>
68
cc429f57
JB
69/* Borrowed from <sys/inttypes.h> on recent AIX versions. */
70typedef unsigned long ptr_to_uint;
71
59d9f049
ND
72#define core_hdr(bfd) ((CoreHdr *) bfd->tdata.any)
73
74/* AIX 4.1 changed the names and locations of a few items in the core file.
75 AIX 4.3 defined an entirely new structure, core_dumpx, but kept support for
76 the previous 4.1 structure, core_dump.
77
78 AIX_CORE_DUMPX_CORE is defined (by configure) on AIX 4.3+, and
79 CORE_VERSION_1 is defined (by AIX core.h) as 2 on AIX 4.3+ and as 1 on AIX
80 4.1 and 4.2. AIX pre-4.1 (aka 3.x) either doesn't define CORE_VERSION_1
3d855632 81 or else defines it as 0. */
59d9f049
ND
82
83#if defined(CORE_VERSION_1) && !CORE_VERSION_1
84# undef CORE_VERSION_1
85#endif
86
87/* The following union and macros allow this module to compile on all AIX
88 versions and to handle both core_dumpx and core_dump on 4.3+. CNEW_*()
89 and COLD_*() macros respectively retrieve core_dumpx and core_dump
3d855632 90 values. */
59d9f049 91
3d855632 92/* Union of 32-bit and 64-bit versions of ld_info. */
59d9f049
ND
93
94typedef union {
95#ifdef __ld_info32
96 struct __ld_info32 l32;
97 struct __ld_info64 l64;
98#else
99 struct ld_info l32;
100 struct ld_info l64;
101#endif
102} LdInfo;
103
3d855632 104/* Union of old and new core dump structures. */
59d9f049
ND
105
106typedef union {
107#ifdef AIX_CORE_DUMPX_CORE
6a125b16 108 struct core_dumpx new; /* new AIX 4.3+ core dump */
59d9f049 109#else
6a125b16 110 struct core_dump new; /* for simpler coding */
59d9f049 111#endif
6a125b16 112 struct core_dump old; /* old AIX 4.2- core dump, still used on
59d9f049
ND
113 4.3+ with appropriate SMIT config */
114} CoreHdr;
115
3d855632 116/* Union of old and new vm_info structures. */
59d9f049 117
1605fc4f 118#ifdef CORE_VERSION_1
59d9f049
ND
119typedef union {
120#ifdef AIX_CORE_DUMPX_CORE
6a125b16 121 struct vm_infox new;
59d9f049 122#else
6a125b16 123 struct vm_info new;
59d9f049 124#endif
6a125b16 125 struct vm_info old;
59d9f049 126} VmInfo;
1605fc4f 127#endif
59d9f049 128
3d855632 129/* Return whether CoreHdr C is in new or old format. */
59d9f049
ND
130
131#ifdef AIX_CORE_DUMPX_CORE
132# define CORE_NEW(c) (!(c).old.c_entries)
133#else
134# define CORE_NEW(c) 0
135#endif
136
3d855632 137/* Return the c_stackorg field from struct core_dumpx C. */
59d9f049
ND
138
139#ifdef AIX_CORE_DUMPX_CORE
140# define CNEW_STACKORG(c) (c).c_stackorg
141#else
142# define CNEW_STACKORG(c) 0
143#endif
144
3d855632 145/* Return the offset to the loader region from struct core_dump C. */
59d9f049
ND
146
147#ifdef AIX_CORE_DUMPX_CORE
148# define CNEW_LOADER(c) (c).c_loader
149#else
150# define CNEW_LOADER(c) 0
151#endif
152
3d855632 153/* Return the offset to the loader region from struct core_dump C. */
59d9f049
ND
154
155#define COLD_LOADER(c) (c).c_tab
156
3d855632 157/* Return the c_lsize field from struct core_dumpx C. */
59d9f049
ND
158
159#ifdef AIX_CORE_DUMPX_CORE
160# define CNEW_LSIZE(c) (c).c_lsize
161#else
162# define CNEW_LSIZE(c) 0
163#endif
164
3d855632 165/* Return the c_dataorg field from struct core_dumpx C. */
252b5132 166
59d9f049
ND
167#ifdef AIX_CORE_DUMPX_CORE
168# define CNEW_DATAORG(c) (c).c_dataorg
169#else
170# define CNEW_DATAORG(c) 0
171#endif
252b5132 172
3d855632 173/* Return the c_datasize field from struct core_dumpx C. */
252b5132 174
59d9f049
ND
175#ifdef AIX_CORE_DUMPX_CORE
176# define CNEW_DATASIZE(c) (c).c_datasize
177#else
178# define CNEW_DATASIZE(c) 0
179#endif
180
3d855632 181/* Return the c_impl field from struct core_dumpx C. */
59d9f049 182
83954261 183#if defined (HAVE_ST_C_IMPL) || defined (AIX_5_CORE)
59d9f049
ND
184# define CNEW_IMPL(c) (c).c_impl
185#else
186# define CNEW_IMPL(c) 0
187#endif
188
3d855632 189/* Return the command string from struct core_dumpx C. */
59d9f049
ND
190
191#ifdef AIX_CORE_DUMPX_CORE
192# define CNEW_COMM(c) (c).c_u.U_proc.pi_comm
193#else
194# define CNEW_COMM(c) 0
195#endif
196
3d855632 197/* Return the command string from struct core_dump C. */
59d9f049
ND
198
199#ifdef CORE_VERSION_1
200# define COLD_COMM(c) (c).c_u.U_comm
201#else
202# define COLD_COMM(c) (c).c_u.u_comm
203#endif
252b5132 204
3d855632 205/* Return the struct __context64 pointer from struct core_dumpx C. */
252b5132 206
59d9f049
ND
207#ifdef AIX_CORE_DUMPX_CORE
208# define CNEW_CONTEXT64(c) (c).c_flt.hctx.r64
209#else
210# define CNEW_CONTEXT64(c) c
211#endif
252b5132 212
3d855632 213/* Return the struct mstsave pointer from struct core_dumpx C. */
6ad49cca
KB
214
215#ifdef AIX_CORE_DUMPX_CORE
59d9f049 216# define CNEW_MSTSAVE(c) (c).c_flt.hctx.r32
6ad49cca 217#else
59d9f049
ND
218# define CNEW_MSTSAVE(c) c
219#endif
220
3d855632 221/* Return the struct mstsave pointer from struct core_dump C. */
59d9f049 222
252b5132 223#ifdef CORE_VERSION_1
59d9f049 224# define COLD_MSTSAVE(c) (c).c_mst
252b5132 225#else
59d9f049 226# define COLD_MSTSAVE(c) (c).c_u.u_save
6ad49cca 227#endif
59d9f049 228
3d855632 229/* Return whether struct core_dumpx is from a 64-bit process. */
59d9f049
ND
230
231#ifdef AIX_CORE_DUMPX_CORE
232# define CNEW_PROC64(c) IS_PROC64(&(c).c_u.U_proc)
233#else
234# define CNEW_PROC64(c) 0
235#endif
236
237/* Magic end-of-stack addresses for old core dumps. This is _very_ fragile,
3d855632 238 but I don't see any easy way to get that info right now. */
59d9f049
ND
239
240#ifdef CORE_VERSION_1
241# define COLD_STACKEND 0x2ff23000
242#else
243# define COLD_STACKEND 0x2ff80000
252b5132
RH
244#endif
245
59d9f049 246/* Size of the leading portion that old and new core dump structures have in
3d855632 247 common. */
6a125b16
KH
248#define CORE_COMMONSZ ((int) &((struct core_dump *) 0)->c_entries \
249 + sizeof (((struct core_dump *) 0)->c_entries))
252b5132 250
cc429f57
JB
251/* Define prototypes for certain functions, to avoid a compiler warning
252 saying that they are missing. */
253
254const bfd_target * rs6000coff_core_p (bfd *abfd);
255bfd_boolean rs6000coff_core_file_matches_executable_p (bfd *core_bfd,
256 bfd *exec_bfd);
257char * rs6000coff_core_file_failing_command (bfd *abfd);
258int rs6000coff_core_file_failing_signal (bfd *abfd);
259
3d855632
KH
260/* Try to read into CORE the header from the core file associated with ABFD.
261 Return success. */
59d9f049 262
b34976b6 263static bfd_boolean
59d9f049
ND
264read_hdr (bfd *abfd, CoreHdr *core)
265{
266 bfd_size_type size;
267
dc810e39 268 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
b34976b6 269 return FALSE;
59d9f049
ND
270
271 /* Read the leading portion that old and new core dump structures have in
3d855632 272 common. */
dc810e39
AM
273 size = CORE_COMMONSZ;
274 if (bfd_bread (core, size, abfd) != size)
b34976b6 275 return FALSE;
59d9f049 276
3d855632 277 /* Read the trailing portion of the structure. */
dc810e39
AM
278 if (CORE_NEW (*core))
279 size = sizeof (core->new);
280 else
281 size = sizeof (core->old);
282 size -= CORE_COMMONSZ;
283 return bfd_bread ((char *) core + CORE_COMMONSZ, size, abfd) == size;
59d9f049 284}
252b5132
RH
285
286static asection *
cc429f57
JB
287make_bfd_asection (bfd *abfd, const char *name, flagword flags,
288 bfd_size_type size, bfd_vma vma, file_ptr filepos)
252b5132
RH
289{
290 asection *asect;
291
117ed4f8 292 asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
252b5132
RH
293 if (!asect)
294 return NULL;
295
eea6121a 296 asect->size = size;
252b5132
RH
297 asect->vma = vma;
298 asect->filepos = filepos;
299 asect->alignment_power = 8;
300
301 return asect;
302}
303
304/* Decide if a given bfd represents a `core' file or not. There really is no
3d855632 305 magic number or anything like, in rs6000coff. */
252b5132
RH
306
307const bfd_target *
cc429f57 308rs6000coff_core_p (bfd *abfd)
252b5132 309{
59d9f049 310 CoreHdr core;
252b5132 311 struct stat statbuf;
59d9f049 312 bfd_size_type size;
252b5132
RH
313 char *tmpptr;
314
3d855632 315 /* Values from new and old core structures. */
59d9f049
ND
316 int c_flag;
317 file_ptr c_stack, c_regoff, c_loader;
318 bfd_size_type c_size, c_regsize, c_lsize;
319 bfd_vma c_stackend;
320 void *c_regptr;
321 int proc64;
252b5132 322
59d9f049 323 if (!read_hdr (abfd, &core))
252b5132
RH
324 {
325 if (bfd_get_error () != bfd_error_system_call)
326 bfd_set_error (bfd_error_wrong_format);
327 return NULL;
328 }
329
3d855632 330 /* Copy fields from new or old core structure. */
59d9f049
ND
331 if (CORE_NEW (core))
332 {
333 c_flag = core.new.c_flag;
334 c_stack = (file_ptr) core.new.c_stack;
335 c_size = core.new.c_size;
336 c_stackend = CNEW_STACKORG (core.new) + c_size;
337 c_lsize = CNEW_LSIZE (core.new);
338 c_loader = CNEW_LOADER (core.new);
339 proc64 = CNEW_PROC64 (core.new);
340 }
341 else
342 {
343 c_flag = core.old.c_flag;
cc429f57 344 c_stack = (file_ptr) (ptr_to_uint) core.old.c_stack;
59d9f049
ND
345 c_size = core.old.c_size;
346 c_stackend = COLD_STACKEND;
347 c_lsize = 0x7ffffff;
cc429f57 348 c_loader = (file_ptr) (ptr_to_uint) COLD_LOADER (core.old);
59d9f049
ND
349 proc64 = 0;
350 }
351
352 if (proc64)
353 {
354 c_regsize = sizeof (CNEW_CONTEXT64 (core.new));
355 c_regptr = &CNEW_CONTEXT64 (core.new);
356 }
357 else if (CORE_NEW (core))
358 {
359 c_regsize = sizeof (CNEW_MSTSAVE (core.new));
360 c_regptr = &CNEW_MSTSAVE (core.new);
361 }
362 else
363 {
364 c_regsize = sizeof (COLD_MSTSAVE (core.old));
365 c_regptr = &COLD_MSTSAVE (core.old);
366 }
6a125b16 367 c_regoff = (char *) c_regptr - (char *) &core;
59d9f049 368
252b5132
RH
369 if (bfd_stat (abfd, &statbuf) < 0)
370 {
371 bfd_set_error (bfd_error_system_call);
372 return NULL;
373 }
374
375 /* If the core file ulimit is too small, the system will first
376 omit the data segment, then omit the stack, then decline to
377 dump core altogether (as far as I know UBLOCK_VALID and LE_VALID
378 are always set) (this is based on experimentation on AIX 3.2).
379 Now, the thing is that GDB users will be surprised
380 if segments just silently don't appear (well, maybe they would
381 think to check "info files", I don't know).
382
383 For the data segment, we have no choice but to keep going if it's
384 not there, since the default behavior is not to dump it (regardless
6a125b16 385 of the ulimit, it's based on SA_FULLDUMP). But for the stack segment,
252b5132
RH
386 if it's not there, we refuse to have anything to do with this core
387 file. The usefulness of a core dump without a stack segment is pretty
388 limited anyway. */
59d9f049
ND
389
390 if (!(c_flag & UBLOCK_VALID)
391 || !(c_flag & LE_VALID))
252b5132
RH
392 {
393 bfd_set_error (bfd_error_wrong_format);
394 return NULL;
395 }
396
59d9f049 397 if (!(c_flag & USTACK_VALID))
252b5132
RH
398 {
399 bfd_set_error (bfd_error_file_truncated);
400 return NULL;
401 }
402
403 /* Don't check the core file size for a full core, AIX 4.1 includes
6a125b16 404 additional shared library sections in a full core. */
59d9f049 405 if (!(c_flag & (FULL_CORE | CORE_TRUNC)))
252b5132 406 {
3d855632 407 /* If the size is wrong, it means we're misinterpreting something. */
59d9f049
ND
408 if (c_stack + (file_ptr) c_size != statbuf.st_size)
409 {
410 bfd_set_error (bfd_error_wrong_format);
411 return NULL;
412 }
252b5132
RH
413 }
414
415 /* Sanity check on the c_tab field. */
59d9f049
ND
416 if (!CORE_NEW (core) && (c_loader < (file_ptr) sizeof core.old ||
417 c_loader >= statbuf.st_size ||
418 c_loader >= c_stack))
252b5132
RH
419 {
420 bfd_set_error (bfd_error_wrong_format);
421 return NULL;
422 }
423
424 /* Issue warning if the core file was truncated during writing. */
59d9f049 425 if (c_flag & CORE_TRUNC)
252b5132
RH
426 (*_bfd_error_handler) (_("%s: warning core file truncated"),
427 bfd_get_filename (abfd));
428
6a125b16 429 /* Allocate core file header. */
59d9f049 430 size = CORE_NEW (core) ? sizeof (core.new) : sizeof (core.old);
dc810e39 431 tmpptr = (char *) bfd_zalloc (abfd, (bfd_size_type) size);
252b5132
RH
432 if (!tmpptr)
433 return NULL;
252b5132
RH
434
435 /* Copy core file header. */
59d9f049
ND
436 memcpy (tmpptr, &core, size);
437 set_tdata (abfd, tmpptr);
438
3d855632 439 /* Set architecture. */
59d9f049
ND
440 if (CORE_NEW (core))
441 {
442 enum bfd_architecture arch;
443 unsigned long mach;
444
445 switch (CNEW_IMPL (core.new))
446 {
447 case POWER_RS1:
448 case POWER_RSC:
449 case POWER_RS2:
450 arch = bfd_arch_rs6000;
451 mach = bfd_mach_rs6k;
452 break;
453 default:
454 arch = bfd_arch_powerpc;
455 mach = bfd_mach_ppc;
456 break;
6a125b16 457 }
59d9f049
ND
458 bfd_default_set_arch_mach (abfd, arch, mach);
459 }
252b5132 460
3d855632 461 /* .stack section. */
252b5132 462 if (!make_bfd_asection (abfd, ".stack",
59d9f049
ND
463 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
464 c_size, c_stackend - c_size, c_stack))
9e7b37b3 465 goto fail;
252b5132 466
3d855632 467 /* .reg section for all registers. */
252b5132 468 if (!make_bfd_asection (abfd, ".reg",
59d9f049
ND
469 SEC_HAS_CONTENTS,
470 c_regsize, (bfd_vma) 0, c_regoff))
9e7b37b3 471 goto fail;
252b5132
RH
472
473 /* .ldinfo section.
474 To actually find out how long this section is in this particular
475 core dump would require going down the whole list of struct ld_info's.
476 See if we can just fake it. */
477 if (!make_bfd_asection (abfd, ".ldinfo",
59d9f049
ND
478 SEC_HAS_CONTENTS,
479 c_lsize, (bfd_vma) 0, c_loader))
9e7b37b3 480 goto fail;
252b5132
RH
481
482#ifndef CORE_VERSION_1
483 /* .data section if present.
484 AIX 3 dumps the complete data section and sets FULL_CORE if the
485 ulimit is large enough, otherwise the data section is omitted.
486 AIX 4 sets FULL_CORE even if the core file is truncated, we have
59d9f049 487 to examine core.c_datasize below to find out the actual size of
6a125b16 488 the .data section. */
59d9f049 489 if (c_flag & FULL_CORE)
252b5132
RH
490 {
491 if (!make_bfd_asection (abfd, ".data",
492 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
59d9f049 493 (bfd_size_type) core.old.c_u.u_dsize,
252b5132 494 (bfd_vma)
59d9f049
ND
495 CDATA_ADDR (core.old.c_u.u_dsize),
496 c_stack + c_size))
9e7b37b3 497 goto fail;
252b5132
RH
498 }
499#endif
500
501#ifdef CORE_VERSION_1
502 /* AIX 4 adds data sections from loaded objects to the core file,
503 which can be found by examining ldinfo, and anonymously mmapped
504 regions. */
505 {
59d9f049
ND
506 LdInfo ldinfo;
507 bfd_size_type ldi_datasize;
508 file_ptr ldi_core;
509 uint ldi_next;
510 bfd_vma ldi_dataorg;
511
3d855632 512 /* Fields from new and old core structures. */
59d9f049
ND
513 bfd_size_type c_datasize, c_vmregions;
514 file_ptr c_data, c_vmm;
515
516 if (CORE_NEW (core))
517 {
518 c_datasize = CNEW_DATASIZE (core.new);
519 c_data = (file_ptr) core.new.c_data;
520 c_vmregions = core.new.c_vmregions;
521 c_vmm = (file_ptr) core.new.c_vmm;
522 }
523 else
524 {
525 c_datasize = core.old.c_datasize;
cc429f57 526 c_data = (file_ptr) (ptr_to_uint) core.old.c_data;
59d9f049 527 c_vmregions = core.old.c_vmregions;
cc429f57 528 c_vmm = (file_ptr) (ptr_to_uint) core.old.c_vmm;
59d9f049 529 }
252b5132
RH
530
531 /* .data section from executable. */
59d9f049 532 if (c_datasize)
252b5132
RH
533 {
534 if (!make_bfd_asection (abfd, ".data",
535 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
59d9f049
ND
536 c_datasize,
537 (bfd_vma) CDATA_ADDR (c_datasize),
538 c_data))
9e7b37b3 539 goto fail;
252b5132
RH
540 }
541
542 /* .data sections from loaded objects. */
59d9f049 543 if (proc64)
6a125b16 544 size = (int) ((LdInfo *) 0)->l64.ldinfo_filename;
59d9f049 545 else
6a125b16 546 size = (int) ((LdInfo *) 0)->l32.ldinfo_filename;
59d9f049 547
252b5132
RH
548 while (1)
549 {
59d9f049 550 if (bfd_seek (abfd, c_loader, SEEK_SET) != 0)
9e7b37b3 551 goto fail;
dc810e39 552 if (bfd_bread (&ldinfo, size, abfd) != size)
9e7b37b3 553 goto fail;
59d9f049
ND
554
555 if (proc64)
252b5132 556 {
59d9f049
ND
557 ldi_core = ldinfo.l64.ldinfo_core;
558 ldi_datasize = ldinfo.l64.ldinfo_datasize;
559 ldi_dataorg = (bfd_vma) ldinfo.l64.ldinfo_dataorg;
560 ldi_next = ldinfo.l64.ldinfo_next;
561 }
562 else
563 {
564 ldi_core = ldinfo.l32.ldinfo_core;
565 ldi_datasize = ldinfo.l32.ldinfo_datasize;
3d855632 566 ldi_dataorg = (bfd_vma) (long) ldinfo.l32.ldinfo_dataorg;
59d9f049 567 ldi_next = ldinfo.l32.ldinfo_next;
252b5132 568 }
59d9f049
ND
569
570 if (ldi_core)
571 if (!make_bfd_asection (abfd, ".data",
572 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
573 ldi_datasize, ldi_dataorg, ldi_core))
9e7b37b3 574 goto fail;
59d9f049
ND
575
576 if (ldi_next == 0)
252b5132 577 break;
59d9f049 578 c_loader += ldi_next;
252b5132
RH
579 }
580
581 /* .vmdata sections from anonymously mmapped regions. */
59d9f049 582 if (c_vmregions)
252b5132 583 {
59d9f049 584 bfd_size_type i;
252b5132 585
59d9f049 586 if (bfd_seek (abfd, c_vmm, SEEK_SET) != 0)
9e7b37b3 587 goto fail;
252b5132 588
59d9f049 589 for (i = 0; i < c_vmregions; i++)
252b5132 590 {
59d9f049
ND
591 VmInfo vminfo;
592 bfd_size_type vminfo_size;
593 file_ptr vminfo_offset;
594 bfd_vma vminfo_addr;
252b5132 595
59d9f049 596 size = CORE_NEW (core) ? sizeof (vminfo.new) : sizeof (vminfo.old);
dc810e39 597 if (bfd_bread (&vminfo, size, abfd) != size)
9e7b37b3 598 goto fail;
59d9f049
ND
599
600 if (CORE_NEW (core))
252b5132 601 {
59d9f049
ND
602 vminfo_addr = (bfd_vma) vminfo.new.vminfo_addr;
603 vminfo_size = vminfo.new.vminfo_size;
604 vminfo_offset = vminfo.new.vminfo_offset;
252b5132 605 }
59d9f049
ND
606 else
607 {
3d855632 608 vminfo_addr = (bfd_vma) (long) vminfo.old.vminfo_addr;
59d9f049
ND
609 vminfo_size = vminfo.old.vminfo_size;
610 vminfo_offset = vminfo.old.vminfo_offset;
611 }
612
613 if (vminfo_offset)
614 if (!make_bfd_asection (abfd, ".vmdata",
615 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
616 vminfo_size, vminfo_addr,
617 vminfo_offset))
9e7b37b3 618 goto fail;
252b5132
RH
619 }
620 }
621 }
622#endif
623
6a125b16 624 return abfd->xvec; /* This is garbage for now. */
9e7b37b3
AM
625
626 fail:
627 bfd_release (abfd, abfd->tdata.any);
628 abfd->tdata.any = NULL;
629 bfd_section_list_clear (abfd);
630 return NULL;
252b5132
RH
631}
632
b34976b6 633/* Return `TRUE' if given core is from the given executable. */
6a125b16 634
b34976b6 635bfd_boolean
cc429f57 636rs6000coff_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
252b5132 637{
59d9f049 638 CoreHdr core;
252b5132
RH
639 bfd_size_type size;
640 char *path, *s;
641 size_t alloc;
642 const char *str1, *str2;
b34976b6 643 bfd_boolean ret;
59d9f049 644 file_ptr c_loader;
252b5132 645
59d9f049 646 if (!read_hdr (core_bfd, &core))
b34976b6 647 return FALSE;
252b5132 648
59d9f049
ND
649 if (CORE_NEW (core))
650 c_loader = CNEW_LOADER (core.new);
651 else
cc429f57 652 c_loader = (file_ptr) (ptr_to_uint) COLD_LOADER (core.old);
252b5132 653
59d9f049 654 if (CORE_NEW (core) && CNEW_PROC64 (core.new))
6a125b16 655 size = (int) ((LdInfo *) 0)->l64.ldinfo_filename;
59d9f049 656 else
6a125b16 657 size = (int) ((LdInfo *) 0)->l32.ldinfo_filename;
59d9f049
ND
658
659 if (bfd_seek (core_bfd, c_loader + size, SEEK_SET) != 0)
b34976b6 660 return FALSE;
252b5132
RH
661
662 alloc = 100;
dc810e39 663 path = bfd_malloc ((bfd_size_type) alloc);
252b5132 664 if (path == NULL)
b34976b6 665 return FALSE;
252b5132
RH
666 s = path;
667
668 while (1)
669 {
dc810e39 670 if (bfd_bread (s, (bfd_size_type) 1, core_bfd) != 1)
252b5132
RH
671 {
672 free (path);
b34976b6 673 return FALSE;
252b5132
RH
674 }
675 if (*s == '\0')
676 break;
677 ++s;
678 if (s == path + alloc)
679 {
680 char *n;
681
682 alloc *= 2;
dc810e39 683 n = bfd_realloc (path, (bfd_size_type) alloc);
252b5132
RH
684 if (n == NULL)
685 {
686 free (path);
b34976b6 687 return FALSE;
252b5132
RH
688 }
689 s = n + (path - s);
690 path = n;
691 }
692 }
59d9f049 693
252b5132
RH
694 str1 = strrchr (path, '/');
695 str2 = strrchr (exec_bfd->filename, '/');
696
697 /* step over character '/' */
698 str1 = str1 != NULL ? str1 + 1 : path;
699 str2 = str2 != NULL ? str2 + 1 : exec_bfd->filename;
700
701 if (strcmp (str1, str2) == 0)
b34976b6 702 ret = TRUE;
252b5132 703 else
b34976b6 704 ret = FALSE;
252b5132
RH
705
706 free (path);
707
708 return ret;
709}
710
711char *
cc429f57 712rs6000coff_core_file_failing_command (bfd *abfd)
252b5132 713{
59d9f049
ND
714 CoreHdr *core = core_hdr (abfd);
715 char *com = CORE_NEW (*core) ?
716 CNEW_COMM (core->new) : COLD_COMM (core->old);
717
252b5132
RH
718 if (*com)
719 return com;
720 else
721 return 0;
722}
723
724int
cc429f57 725rs6000coff_core_file_failing_signal (bfd *abfd)
252b5132 726{
59d9f049
ND
727 CoreHdr *core = core_hdr (abfd);
728 return CORE_NEW (*core) ? core->new.c_signo : core->old.c_signo;
252b5132
RH
729}
730
731#endif /* AIX_CORE */
This page took 0.43327 seconds and 4 git commands to generate.