PARAMS ((void));
static asection *
-make_bfd_asection (abfd, name, flags, _raw_size, vma, alignment_power)
+make_bfd_asection (abfd, name, flags, size, vma, alignment_power)
bfd *abfd;
const char *name;
flagword flags;
- bfd_size_type _raw_size;
+ bfd_size_type size;
bfd_vma vma;
unsigned int alignment_power;
{
return NULL;
asect->flags = flags;
- asect->_raw_size = _raw_size;
+ asect->size = size;
asect->vma = vma;
asect->filepos = bfd_tell (abfd);
asect->alignment_power = alignment_power;
return asect;
}
+/* Return true if the given core file section corresponds to a thread,
+ based on its name. */
+
+static int
+thread_section_p (bfd *abfd ATTRIBUTE_UNUSED,
+ asection *sect,
+ void *obj ATTRIBUTE_UNUSED)
+{
+ return (strncmp (bfd_section_name (abfd, sect), ".reg/", 5) == 0);
+}
+
/* this function builds a bfd target if the file is a corefile.
It returns null or 0 if it finds out thaat it is not a core file.
The way it checks this is by looking for allowed 'type' field values.
/* However, we also want to create those sections with the
file positioned at the start of the record, it seems. */
- if (bfd_seek (abfd, (file_ptr) -core_header.len, SEEK_CUR) != 0)
+ if (bfd_seek (abfd, -((file_ptr) core_header.len), SEEK_CUR) != 0)
break;
#if defined(PROC_INFO_HAS_THREAD_ID)
if (core_kernel_thread_id (abfd) == 0)
{
if (!make_bfd_asection (abfd, ".reg",
- SEC_HAS_CONTENTS,
- core_header.len,
- (int) &proc_info - (int) & proc_info.hw_regs,
- 2))
+ SEC_HAS_CONTENTS,
+ core_header.len,
+ (bfd_vma) offsetof (struct proc_info,
+ hw_regs),
+ 2))
goto fail;
}
else
if (!make_bfd_asection (abfd, ".reg",
SEC_HAS_CONTENTS,
core_header.len,
- (int) &proc_info - (int) & proc_info.hw_regs,
+ (bfd_vma)offsetof (struct proc_info,
+ hw_regs),
2))
goto fail;
}
/* We always make one of these sections, for every thread. */
sprintf (secname, ".reg/%d", core_kernel_thread_id (abfd));
if (!make_bfd_asection (abfd, secname,
- SEC_HAS_CONTENTS,
- core_header.len,
- (int) &proc_info - (int) & proc_info.hw_regs,
- 2))
+ SEC_HAS_CONTENTS,
+ core_header.len,
+ (bfd_vma) offsetof (struct proc_info,
+ hw_regs),
+ 2))
goto fail;
}
core_signal (abfd) = proc_info.sig;
/* OK, we believe you. You're a core file (sure, sure). */
+ /* On HP/UX, we sometimes encounter core files where none of the threads
+ was found to be the running thread (ie the signal was set to -1 for
+ all threads). This happens when the program was aborted externally
+ via a TT_CORE ttrace system call. In that case, we just pick one
+ thread at random to be the active thread. */
+ if (core_kernel_thread_id (abfd) != 0
+ && bfd_get_section_by_name (abfd, ".reg") == NULL)
+ {
+ asection *asect = bfd_sections_find_if (abfd, thread_section_p, NULL);
+ asection *reg_sect;
+
+ if (asect != NULL)
+ {
+ reg_sect = make_bfd_asection (abfd, ".reg", asect->flags,
+ asect->size, asect->vma,
+ asect->alignment_power);
+ if (reg_sect == NULL)
+ goto fail;
+
+ reg_sect->filepos = asect->filepos;
+ }
+ }
+
/* Were there sections of unknown type? If so, yet there were
at least some complete sections of known type, then, issue
a warning. Possibly the core file was generated on a version