Slight cleanup to ELF core file handing, and add support for
NetBSD-style ELF core files.
This commit is contained in:
parent
91c4b48914
commit
a4ea757e28
|
@ -44,8 +44,6 @@
|
|||
# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
|
||||
# corrections by Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
|
||||
>>16 leshort 4 core file
|
||||
>>>(0x38+0xcc) string >\0 of '%s'
|
||||
>>>(0x38+0x10) lelong >0 (signal %d),
|
||||
>>16 leshort &0xff00 processor-specific,
|
||||
>>18 leshort 0 no machine,
|
||||
>>18 leshort 1 AT&T WE32100 - invalid byte order,
|
||||
|
@ -115,8 +113,6 @@
|
|||
>>16 beshort 2 executable,
|
||||
>>16 beshort 3 shared object,
|
||||
>>16 beshort 4 core file,
|
||||
>>>(0x38+0xcc) string >\0 of '%s'
|
||||
>>>(0x38+0x10) belong >0 (signal %d),
|
||||
>>16 beshort &0xff00 processor-specific,
|
||||
>>18 beshort 0 no machine,
|
||||
>>18 beshort 1 AT&T WE32100,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: readelf.c,v 1.9 2000/11/23 23:21:15 pooka Exp $ */
|
||||
/* $NetBSD: readelf.c,v 1.10 2001/12/09 23:21:07 thorpej Exp $ */
|
||||
|
||||
#include "file.h"
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
|||
#if 0
|
||||
FILE_RCSID("@(#)Id: readelf.c,v 1.17 2000/08/05 19:00:12 christos Exp ")
|
||||
#else
|
||||
__RCSID("$NetBSD: readelf.c,v 1.9 2000/11/23 23:21:15 pooka Exp $");
|
||||
__RCSID("$NetBSD: readelf.c,v 1.10 2001/12/09 23:21:07 thorpej Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -237,6 +237,17 @@ size_t prpsoffsets64[] = {
|
|||
* *do* have that binary, the debugger will probably tell you what
|
||||
* signal it was.)
|
||||
*/
|
||||
|
||||
#define OS_STYLE_SVR4 0
|
||||
#define OS_STYLE_FREEBSD 1
|
||||
#define OS_STYLE_NETBSD 2
|
||||
|
||||
static const char *os_style_names[] = {
|
||||
"SVR4",
|
||||
"FreeBSD",
|
||||
"NetBSD",
|
||||
};
|
||||
|
||||
static void
|
||||
dophn_core(class, swap, fd, off, num, size)
|
||||
int class;
|
||||
|
@ -255,7 +266,7 @@ dophn_core(class, swap, fd, off, num, size)
|
|||
int i, j;
|
||||
char nbuf[BUFSIZ];
|
||||
int bufsize;
|
||||
int is_freebsd;
|
||||
int os_style = -1;
|
||||
|
||||
/*
|
||||
* Loop through all the program headers.
|
||||
|
@ -288,21 +299,9 @@ dophn_core(class, swap, fd, off, num, size)
|
|||
nh64 = (Elf64_Nhdr *)&nbuf[offset];
|
||||
offset += nh_size;
|
||||
|
||||
/*
|
||||
* If this note isn't an NT_PRPSINFO note, it's
|
||||
* not what we're looking for.
|
||||
*/
|
||||
if (nh_type != NT_PRPSINFO) {
|
||||
offset += nh_namesz;
|
||||
offset = ((offset + 3)/4)*4;
|
||||
offset += nh_descsz;
|
||||
offset = ((offset + 3)/4)*4;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether this note has the name "CORE" or
|
||||
* "FreeBSD".
|
||||
* "FreeBSD", or "NetBSD-CORE".
|
||||
*/
|
||||
if (offset + nh_namesz >= bufsize) {
|
||||
/*
|
||||
|
@ -329,17 +328,50 @@ dophn_core(class, swap, fd, off, num, size)
|
|||
* doesn't include the terminating null in the
|
||||
* name....
|
||||
*/
|
||||
if ((nh_namesz == 4 &&
|
||||
strncmp(&nbuf[nameoffset], "CORE", 4) == 0) ||
|
||||
(nh_namesz == 5 &&
|
||||
strcmp(&nbuf[nameoffset], "CORE") == 0))
|
||||
is_freebsd = 0;
|
||||
else if ((nh_namesz == 8 &&
|
||||
strcmp(&nbuf[nameoffset], "FreeBSD") == 0))
|
||||
is_freebsd = 1;
|
||||
else
|
||||
continue;
|
||||
if (nh_type == NT_PRPSINFO) {
|
||||
if (os_style == -1) {
|
||||
if ((nh_namesz == 4 &&
|
||||
strncmp(&nbuf[nameoffset],
|
||||
"CORE", 4) == 0) ||
|
||||
(nh_namesz == 5 &&
|
||||
strcmp(&nbuf[nameoffset],
|
||||
"CORE") == 0)) {
|
||||
os_style = OS_STYLE_SVR4;
|
||||
} else
|
||||
if ((nh_namesz == 8 &&
|
||||
strcmp(&nbuf[nameoffset],
|
||||
"FreeBSD") == 0)) {
|
||||
os_style = OS_STYLE_FREEBSD;
|
||||
} else
|
||||
if ((nh_namesz >= 11 &&
|
||||
strncmp(&nbuf[nameoffset],
|
||||
"NetBSD-CORE", 11) == 0)) {
|
||||
os_style = OS_STYLE_NETBSD;
|
||||
} else
|
||||
continue;
|
||||
printf(", %s-style", os_style_names[os_style]);
|
||||
}
|
||||
|
||||
if (os_style == OS_STYLE_NETBSD &&
|
||||
nh_type == NT_NETBSD_CORE_PROCINFO) {
|
||||
uint32_t signo;
|
||||
|
||||
/*
|
||||
* Extract the program name. It is at
|
||||
* offset 0x7c, and is up to 32-bytes,
|
||||
* including the terminating NUL.
|
||||
*/
|
||||
printf(", from '%.31s'", &nbuf[offset + 0x7c]);
|
||||
|
||||
/*
|
||||
* Extract the signal number. It is at
|
||||
* offset 0x08.
|
||||
*/
|
||||
memcpy(&signo, &nbuf[offset + 0x08],
|
||||
sizeof(signo));
|
||||
printf(" (signal %u)", getu32(swap, signo));
|
||||
} else
|
||||
if (os_style != OS_STYLE_NETBSD &&
|
||||
nh_type == NT_PRPSINFO) {
|
||||
/*
|
||||
* Extract the program name. We assume
|
||||
* it to be 16 characters (that's what it
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: readelf.h,v 1.5 1999/11/01 17:39:27 christos Exp $ */
|
||||
/* $NetBSD: readelf.h,v 1.6 2001/12/09 23:21:07 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* readelf.h
|
||||
|
@ -168,6 +168,8 @@ typedef struct {
|
|||
#define NT_PRPSINFO 3
|
||||
#define NT_TASKSTRUCT 4
|
||||
|
||||
#define NT_NETBSD_CORE_PROCINFO 1
|
||||
|
||||
/* Note header in a PT_NOTE section */
|
||||
typedef struct elf_note {
|
||||
Elf32_Word n_namesz; /* Name size */
|
||||
|
|
Loading…
Reference in New Issue