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