Use new core file format in cpu_coredump()

This commit is contained in:
gwr 1995-04-03 22:06:11 +00:00
parent 69aa4da3cf
commit aa197980e8
1 changed files with 74 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vm_machdep.c,v 1.24 1995/02/13 22:24:27 gwr Exp $ */
/* $NetBSD: vm_machdep.c,v 1.25 1995/04/03 22:06:11 gwr Exp $ */
/*
* Copyright (c) 1994 Gordon W. Ross
@ -41,25 +41,29 @@
*
* from: Utah $Hdr: vm_machdep.c 1.21 91/04/06$
* from: @(#)vm_machdep.c 7.10 (Berkeley) 5/7/91
* vm_machdep.c,v 1.3 1993/07/07 07:09:32 cgd Exp
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/buf.h>
#include <sys/user.h>
#include <sys/vnode.h>
#include <sys/core.h>
#include <sys/exec.h>
#include <vm/vm.h>
#include <vm/vm_kern.h>
#include <vm/vm_map.h>
#include <machine/cpu.h>
#include <machine/reg.h>
#include <machine/pte.h>
#include <machine/pmap.h>
extern int fpu_type;
/*
* Finish a fork operation, with process p2 nearly set up.
* Copy and update the kernel stack and pcb, making the child
@ -161,25 +165,79 @@ cpu_exit(p)
/* NOTREACHED */
}
/*
* Dump the machine specific segment at the start of a core dump.
* This means the CPU and FPU registers. The format used here is
* the same one ptrace uses, so gdb can be machine independent.
*
* XXX - Generate Sun format core dumps for Sun executables?
*/
struct md_core {
struct reg intreg;
struct fpreg freg;
};
int
cpu_coredump(p, vp, cred)
cpu_coredump(p, vp, cred, chdr)
struct proc *p;
struct vnode *vp;
struct ucred *cred;
struct core *chdr;
{
int error;
struct md_core md_core;
struct coreseg cseg;
register struct user *up = p->p_addr;
register i;
#ifdef COMPAT_HPUX
/*
* If we loaded from an HP-UX format binary file we dump enough
* of an HP-UX style user struct so that the HP-UX debuggers can
* grok it.
*/
if (p->p_emul == EMUL_HPUX)
return (hpux_dumpu(vp, cred));
#endif
return (vn_rdwr(UIO_WRITE, vp, (caddr_t) p->p_addr, ctob(UPAGES),
(off_t)0, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, (int *)NULL,
p));
CORE_SETMAGIC(*chdr, COREMAGIC, MID_M68K, 0);
chdr->c_hdrsize = ALIGN(sizeof(*chdr));
chdr->c_seghdrsize = ALIGN(sizeof(cseg));
chdr->c_cpusize = sizeof(md_core);
/* Save integer registers. */
{
register struct frame *f;
f = (struct frame*) p->p_md.md_regs;
for (i = 0; i < 16; i++) {
md_core.intreg.r_regs[i] = f->f_regs[i];
}
md_core.intreg.r_sr = f->f_sr;
md_core.intreg.r_pc = f->f_pc;
}
if (fpu_type) {
register struct fpframe *f;
f = &up->u_pcb.pcb_fpregs;
m68881_save(f);
for (i = 0; i < (8*3); i++) {
md_core.freg.r_regs[i] = f->fpf_regs[i];
}
md_core.freg.r_fpcr = f->fpf_fpcr;
md_core.freg.r_fpsr = f->fpf_fpsr;
md_core.freg.r_fpiar = f->fpf_fpiar;
} else {
bzero((caddr_t)&md_core.freg, sizeof(md_core.freg));
}
CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_M68K, CORE_CPU);
cseg.c_addr = 0;
cseg.c_size = chdr->c_cpusize;
error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&cseg, chdr->c_seghdrsize,
(off_t)chdr->c_hdrsize, UIO_SYSSPACE,
IO_NODELOCKED|IO_UNIT, cred, (int *)NULL, p);
if (error)
return error;
error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&md_core, sizeof(md_core),
(off_t)(chdr->c_hdrsize + chdr->c_seghdrsize), UIO_SYSSPACE,
IO_NODELOCKED|IO_UNIT, cred, (int *)NULL, p);
if (!error)
chdr->c_nseg++;
return error;
}