* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)coredump.c 5.2 (Berkeley) %G%";
static char rcsid
[] = "$Header: coredump.c,v 1.5 84/12/26 10:38:56 linton Exp $";
* Deal with the core dump anachronism.
#define coredump_readin(m, r, s) coredump_xreadin(&(m), r, &(s))
private Map datamap
, stkmap
;
public coredump_getkerinfo ()
s
= lookup(identname("Sysmap", true));
panic("can't find 'Sysmap'");
sbr
= (struct pte
*) (s
->symvalue
.offset
);
s
= lookup(identname("Syssize", true));
panic("can't find 'Syssize'");
slr
= (integer
) (s
->symvalue
.offset
);
printf("sbr %lx slr %lx\n", sbr
, slr
);
s
= lookup(identname("masterpaddr", true));
panic("can't find 'masterpaddr'");
datamap
.seekaddr
+ physaddr(s
->symvalue
.offset
) - datamap
.begin
, 0);
get(corefile
, masterpcbb
);
masterpcbb
= (masterpcbb
&PG_PFNUM
)*NBPG
;
* Read the user area information from the core dump.
public coredump_xreadin(mask
, reg
, signo
)
register struct user
*up
;
char dummy
[ctob(UPAGES
)];
objfile
= fopen(objname
, "r");
fatal("can't read \"%s\"", objname
);
datamap
.end
= 0xffffffff;
stkmap
.begin
= 0xffffffff;
fread(up
, ctob(UPAGES
), 1, corefile
);
savreg
= (Word
*) &(ustruct
.dummy
[ctob(UPAGES
)]);
datamap
.seekaddr
= ctob(UPAGES
);
stkmap
.begin
= USRSTACK
- ctob(up
->u_ssize
);
stkmap
.seekaddr
= datamap
.seekaddr
+ ctob(up
->u_dsize
);
datamap
.end
= ctob(up
->u_tsize
) + ctob(up
->u_dsize
);
datamap
.begin
= (Address
) ptob(btop(ctob(up
->u_tsize
) - 1) + 1);
datamap
.end
= datamap
.begin
+ ctob(up
->u_dsize
);
fatal("bad magic number 0x%x", hdr
.a_magic
);
* Core dump not from this object file?
if (hdr
.a_magic
!= 0 and up
->u_exdata
.ux_mag
!= 0 and
hdr
.a_magic
!= up
->u_exdata
.ux_mag
) {
warning("core dump ignored");
public coredump_readtext(buff
, addr
, nbytes
)
if (hdr
.a_magic
== OMAGIC
or vaddrs
) {
coredump_readdata(buff
, addr
, nbytes
);
fseek(objfile
, N_TXTOFF(hdr
) + addr
, 0);
fread(buff
, nbytes
, sizeof(Byte
), objfile
);
public coredump_readdata(buff
, addr
, nbytes
)
if (hdr
.a_magic
== OMAGIC
) {
error("[data address 0x%x too low (lb = 0x%x)]", a
, datamap
.begin
);
coredump_readtext(buff
, a
, nbytes
);
} else if (a
> stkmap
.end
) {
error("data address 0x%x too high (ub = 0x%x)", a
, stkmap
.end
);
vreadfromfile(corefile
, a
, buff
, nbytes
);
readfromfile(corefile
, a
, buff
, nbytes
);
* Read a block of data from a memory image, mapping virtual addresses.
* Have to watch out for page boundaries.
private vreadfromfile (corefile
, v
, buff
, nbytes
)
integer i
, remainder
, pagesize
;
pagesize
= (integer
) ptob(1);
remainder
= pagesize
- (a mod pagesize
);
if (remainder
>= nbytes
) {
readfromfile(corefile
, vmap(a
), buff
, nbytes
);
readfromfile(corefile
, vmap(a
), buff
, remainder
);
readfromfile(corefile
, vmap(a
), bufp
, pagesize
);
readfromfile(corefile
, vmap(a
), bufp
, i
);
private readfromfile (f
, a
, buff
, nbytes
)
fileaddr
= datamap
.seekaddr
+ a
- datamap
.begin
;
fileaddr
= stkmap
.seekaddr
+ a
- stkmap
.begin
;
fread(buff
, nbytes
, sizeof(Byte
), f
);