From: bjarne@hsr.no (Bjarne Steinsbo)
Newsgroups: comp.sys.hp
Subject: Examine core files
Keywords: core
Date: 9 Apr 92 12:22:59 GMT
Organization: Rogaland University Centre

Since HP's "file" command neither recognizes core files nor tells which
program the core is from, I wrote a quick and dirty C program to examine
core files.  It's written for a 720 running HP-UX 8.07, and probably doesn't
work on anything but HP-PA 1.1 and HP-UX 8.0[57].

No copyright, no guarantees!

Compile by saving to file and type "cc -o core core.c".  Install the
program in some publicly available directory like /usr/local/bin.

Bjarne

-- Cut here! --
/* Quick and dirty program to examine core files.
 * Probably works on HP9000/7xx running HPUX 8.0[57] and nothing else.
 * Written by B. Steinsbo (bjarne@hsr.no) April 9th,1992.
 */

#include <sys/core.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

struct corehead chead;
struct proc_exec pexec;
struct proc_info pinfo;

char *signames[] = {
  "", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "IOT", "EMT", "FPE",
  "KILL", "SEGV", "SYS", "PIPE", "ALRM", "TERM", "USR1", "USR2", "CHLD",
  "CLD", "PWR", "VTALRM", "PROF", "IO", "POLL", "WINCH", "STOP", "TSTP",
  "CONT", "TTIN", "TTOU", "URG", "LOST", "" "DIL"
};

char dummy[BUFSIZ];

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))

main(argc, argv)
  int argc;
  char **argv;
{
  char *file;
  int fd;
  int len;

  if (argc < 2)
	file = "core";
  else
	file = argv[1];
  if ((fd = open(file, O_RDONLY)) < 0) {
	fprintf(stderr, "Cant't open core file.\n");
	fprintf(stderr, "Usage: core [core_file]\n");
	exit(1);
  }

  while(read(fd, &chead, sizeof(struct corehead))) {
	switch(chead.type) {
	  case CORE_DATA:
		len = chead.len;
		printf("Core data length: %d\n", len);
		while (len > 0) {
			read(fd, dummy, min(len, BUFSIZ));
			len -= min(len, BUFSIZ);
		}
		break;
	  case CORE_EXEC:
		read(fd, &pexec, sizeof(struct proc_exec));
		printf("Command:  %s\n", pexec.cmd);
		break;
	  case CORE_FORMAT:
		read(fd, &len, sizeof(int));
		printf("Format version: %d\n", len);
		break;
	  case CORE_KERNEL:
		read(fd, dummy, chead.len);
		printf("Kernel: %s\n", dummy);
		break;
	  case CORE_PROC:
		len = chead.len;
		read(fd, &pinfo, sizeof(struct proc_info));
		printf("Died from signal %d (SIG%s), type %d\n",
			pinfo.sig, signames[pinfo.sig], pinfo.trap_type);
		break;
	  case CORE_STACK:
		len = chead.len;
		printf("Core stack length: %d\n", len);
		while (len > 0) {
			read(fd, dummy, min(len, BUFSIZ));
			len -= min(len, BUFSIZ);
		}
		break;
	  default:
		fprintf(stderr, "Unknown data object in core file!\n");
		fprintf(stderr,
			"Type = %d, Space = %d, Addr = %d, Length = %d\n",
			chead.type, chead.space, chead.addr, chead.len);
		exit(1);
	}
  }
  exit(0);
}
                              --------------------
Bjarne Steinsbo (bjarne@hsr.no)    |     There is no such thing as "luck";
Rogaland University Center         |  only "rotten luck" and "cool planning".
From: bturner@hpcvlx.cv.hp.com (Bill Turner)
Date: Wed, 8 Apr 1992 17:13:54 GMT
Subject: Re: XtDestroyWidget ?'s on HP-UX
Organization: A Maze of Twisty Little Passages