Annotation of 43BSDReno/pgrm/dbx/coredump.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted provided
        !             6:  * that: (1) source distributions retain this entire copyright notice and
        !             7:  * comment, and (2) distributions including binaries display the following
        !             8:  * acknowledgement:  ``This product includes software developed by the
        !             9:  * University of California, Berkeley and its contributors'' in the
        !            10:  * documentation or other materials provided with the distribution and in
        !            11:  * all advertising materials mentioning features or use of this software.
        !            12:  * Neither the name of the University nor the names of its contributors may
        !            13:  * be used to endorse or promote products derived from this software without
        !            14:  * specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)coredump.c 5.6 (Berkeley) 6/29/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: /*
        !            25:  * Deal with the core dump anachronism.
        !            26:  */
        !            27: 
        !            28: #include "defs.h"
        !            29: #include "coredump.h"
        !            30: #include "machine.h"
        !            31: #include "object.h"
        !            32: #include "main.h"
        !            33: #include <a.out.h>
        !            34: 
        !            35: #ifndef public
        !            36: #define coredump_readin(m, r, s) coredump_xreadin(&(m), r, &(s))
        !            37: 
        !            38: #include "machine.h"
        !            39: #endif
        !            40: 
        !            41: typedef struct {
        !            42:     Address begin;
        !            43:     Address end;
        !            44:     Address seekaddr;
        !            45: } Map;
        !            46: 
        !            47: private Map datamap, stkmap;
        !            48: private File objfile;
        !            49: private struct exec hdr;
        !            50: 
        !            51: public coredump_getkerinfo ()
        !            52: {
        !            53:     Symbol s;
        !            54: 
        !            55:     s = lookup(identname("Sysmap", true));
        !            56:     if (s == nil) {
        !            57:        panic("can't find 'Sysmap'");
        !            58:     }
        !            59:     sbr = (struct pte *) (s->symvalue.offset);
        !            60:     s = lookup(identname("Syssize", true));
        !            61:     if (s == nil) {
        !            62:        panic("can't find 'Syssize'");
        !            63:     }
        !            64:     slr = (integer) (s->symvalue.offset);
        !            65:     printf("sbr %lx slr %lx\n", sbr, slr);
        !            66:     s = lookup(identname("masterpaddr", true));
        !            67:     if (s == nil) {
        !            68:        panic("can't find 'masterpaddr'");
        !            69:     }
        !            70:     fseek(
        !            71:        corefile,
        !            72:        datamap.seekaddr + s->symvalue.offset&0x7fffffff - datamap.begin,
        !            73:        0
        !            74:     );
        !            75:     get(corefile, masterpcbb);
        !            76:     masterpcbb = (masterpcbb&PG_PFNUM)*NBPG;
        !            77:     getpcb();
        !            78: }
        !            79: 
        !            80: /*
        !            81:  * Read the user area information from the core dump.
        !            82:  */
        !            83: 
        !            84: public coredump_xreadin(mask, reg, signo)
        !            85: int *mask;
        !            86: Word reg[];
        !            87: short *signo;
        !            88: {
        !            89:     register struct user *up;
        !            90:     register Word *savreg;
        !            91:     union {
        !            92:        struct user u;
        !            93:        char dummy[ctob(UPAGES)];
        !            94:     } ustruct;
        !            95:     Symbol s;
        !            96: 
        !            97:     objfile = fopen(objname, "r");
        !            98:     if (objfile == nil) {
        !            99:        fatal("can't read \"%s\"", objname);
        !           100:     }
        !           101:     get(objfile, hdr);
        !           102:     if (vaddrs) {
        !           103:        datamap.begin = 0;
        !           104:        datamap.end = 0xffffffff;
        !           105:        stkmap.begin = 0xffffffff;
        !           106:        stkmap.end = 0xffffffff;
        !           107:     } else {
        !           108:        up = &(ustruct.u);
        !           109:        fread(up, ctob(UPAGES), 1, corefile);
        !           110: #      if vax || tahoe
        !           111:            savreg = (Word *) &(ustruct.dummy[ctob(UPAGES)]);
        !           112: #      else ifdef mc68000
        !           113:            savreg = (Word *) (
        !           114:                &ustruct.dummy[ctob(UPAGES) - 10] - (NREG * sizeof(Word))
        !           115:            );
        !           116: #      endif
        !           117: #       ifdef IRIS
        !           118:            *mask = savreg[RPS];
        !           119: #       else
        !           120:            *mask = savreg[PS];
        !           121: #       endif
        !           122:        copyregs(savreg, reg);
        !           123:        *signo = up->u_sig;
        !           124:        datamap.seekaddr = ctob(UPAGES);
        !           125:        stkmap.begin = USRSTACK - ctob(up->u_ssize);
        !           126:        stkmap.end = USRSTACK;
        !           127:        stkmap.seekaddr = datamap.seekaddr + ctob(up->u_dsize);
        !           128:        switch (hdr.a_magic) {
        !           129:            case OMAGIC:
        !           130:                datamap.begin = CODESTART;
        !           131:                datamap.end = CODESTART + ctob(up->u_tsize) + ctob(up->u_dsize);
        !           132:                break;
        !           133: 
        !           134:            case NMAGIC:
        !           135:            case ZMAGIC:
        !           136:                datamap.begin = (Address)
        !           137:                    ptob(btop(ctob(up->u_tsize) - 1) + 1) + CODESTART;
        !           138:                datamap.end = datamap.begin + ctob(up->u_dsize);
        !           139:                break;
        !           140: 
        !           141:            default:
        !           142:                fatal("bad magic number 0x%x", hdr.a_magic);
        !           143:        }
        !           144: #ifdef UXMAG
        !           145:        /*
        !           146:         * Core dump not from this object file?
        !           147:         */
        !           148:        if (hdr.a_magic != 0 and up->u_exdata.ux_mag  != 0 and
        !           149:          hdr.a_magic != up->u_exdata.ux_mag) {
        !           150:            warning("core dump ignored");
        !           151:            coredump = false;
        !           152:            fclose(corefile);
        !           153:            fclose(objfile);
        !           154:            start(nil, nil, nil);
        !           155:        }
        !           156: #endif
        !           157:     }
        !           158: }
        !           159: 
        !           160: public coredump_close()
        !           161: {
        !           162:     fclose(objfile);
        !           163: }
        !           164: 
        !           165: public coredump_readtext(buff, addr, nbytes)
        !           166: char *buff;
        !           167: Address addr;
        !           168: int nbytes;
        !           169: {
        !           170:     if (hdr.a_magic == OMAGIC or vaddrs) {
        !           171:        coredump_readdata(buff, addr, nbytes);
        !           172:     } else {
        !           173:        fseek(objfile, N_TXTOFF(hdr) + addr - CODESTART, 0);
        !           174:        fread(buff, nbytes, sizeof(Byte), objfile);
        !           175:     }
        !           176: }
        !           177: 
        !           178: public coredump_readdata(buff, addr, nbytes)
        !           179: char *buff;
        !           180: Address addr;
        !           181: int nbytes;
        !           182: {
        !           183:     Address a;
        !           184: 
        !           185:     a = addr;
        !           186:     if (a < datamap.begin) {
        !           187:        if (hdr.a_magic == OMAGIC) {
        !           188:            error("[data address 0x%x too low (lb = 0x%x)]", a, datamap.begin);
        !           189:        } else {
        !           190:            coredump_readtext(buff, a, nbytes);
        !           191:        }
        !           192:     } else if (a > stkmap.end) {
        !           193:        error("data address 0x%x too high (ub = 0x%x)", a, stkmap.end);
        !           194:     } else {
        !           195:        if (vaddrs) {
        !           196:            vreadfromfile(corefile, a, buff, nbytes);
        !           197:        } else {
        !           198:            readfromfile(corefile, a, buff, nbytes);
        !           199:        }
        !           200:     }
        !           201: }
        !           202: 
        !           203: /*
        !           204:  * Read a block of data from a memory image, mapping virtual addresses.
        !           205:  * Have to watch out for page boundaries.
        !           206:  */
        !           207: 
        !           208: private vreadfromfile (corefile, v, buff, nbytes)
        !           209: File corefile;
        !           210: Address v;
        !           211: char *buff;
        !           212: integer nbytes;
        !           213: {
        !           214:     Address a;
        !           215:     integer i, remainder, pagesize;
        !           216:     char *bufp;
        !           217: 
        !           218:     a = v;
        !           219:     pagesize = (integer) ptob(1);
        !           220:     remainder = pagesize - (a mod pagesize);
        !           221:     if (remainder >= nbytes) {
        !           222:        readfromfile(corefile, vmap(a), buff, nbytes);
        !           223:     } else {
        !           224:        readfromfile(corefile, vmap(a), buff, remainder);
        !           225:        a += remainder;
        !           226:        i = nbytes - remainder;
        !           227:        bufp = buff + remainder;
        !           228:        while (i > pagesize) {
        !           229:            readfromfile(corefile, vmap(a), bufp, pagesize);
        !           230:            a += pagesize;
        !           231:            bufp += pagesize;
        !           232:            i -= pagesize;
        !           233:        }
        !           234:        readfromfile(corefile, vmap(a), bufp, i);
        !           235:     }
        !           236: }
        !           237: 
        !           238: private readfromfile (f, a, buff, nbytes)
        !           239: File f;
        !           240: Address a;
        !           241: char *buff;
        !           242: integer nbytes;
        !           243: {
        !           244:     integer fileaddr;
        !           245: 
        !           246:     if (a < stkmap.begin) {
        !           247:        fileaddr = datamap.seekaddr + a - datamap.begin;
        !           248:     } else {
        !           249:        fileaddr = stkmap.seekaddr + a - stkmap.begin;
        !           250:     }
        !           251:     fseek(f, fileaddr, 0);
        !           252:     fread(buff, nbytes, sizeof(Byte), f);
        !           253: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.