/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)@(#)coredump.c 1.1 %G%";
* Deal with the core dump anachronism.
* If I understood this code, I'd try to make it readable.
#define coredump_readin(m, r, s) coredump_xreadin(&(m), r, &(s))
#define MAXSTKADDR (0x80000000 - ctob(UPAGES)) /* highest stack address */
private Map datamap
, stkmap
;
* 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
);
fread(up
, ctob(UPAGES
), 1, corefile
);
savreg
= (Word
*) &(ustruct
.dummy
[ctob(UPAGES
)]);
reg
[PROGCTR
] = savreg
[PC
];
datamap
.seekaddr
= ctob(UPAGES
);
stkmap
.begin
= MAXSTKADDR
- 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
) {
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 (addr
< datamap
.begin
) {
error("data address 0x%x too low (lb = 0x%x)", addr
, datamap
.begin
);
} else if (addr
> stkmap
.end
) {
error("data address 0x%x too high (ub = 0x%x)", addr
, stkmap
.end
);
} else if (addr
< stkmap
.begin
) {
fseek(corefile
, datamap
.seekaddr
+ addr
- datamap
.begin
, 0);
fread(buff
, nbytes
, sizeof(Byte
), corefile
);
fseek(corefile
, stkmap
.seekaddr
+ addr
- stkmap
.begin
, 0);
fread(buff
, nbytes
, sizeof(Byte
), corefile
);