Annotation of 42BSD/ucb/dbx/coredump.c, revision 1.1

1.1     ! root        1: /* Copyright (c) 1982 Regents of the University of California */
        !             2: 
        !             3: static char sccsid[] = "@(#)coredump.c 1.4 1/25/83";
        !             4: 
        !             5: /*
        !             6:  * Deal with the core dump anachronism.
        !             7:  *
        !             8:  * If I understood this code, I'd try to make it readable.
        !             9:  */
        !            10: 
        !            11: #include "defs.h"
        !            12: #include "coredump.h"
        !            13: #include "machine.h"
        !            14: #include "object.h"
        !            15: #include "main.h"
        !            16: #include <sys/param.h>
        !            17: #include <sys/dir.h>
        !            18: #include <machine/psl.h>
        !            19: #include <machine/pte.h>
        !            20: #include <sys/user.h>
        !            21: #include <sys/vm.h>
        !            22: #include <machine/reg.h>
        !            23: #include <a.out.h>
        !            24: 
        !            25: #ifndef public
        !            26: #define coredump_readin(m, r, s) coredump_xreadin(&(m), r, &(s))
        !            27: 
        !            28: #include "machine.h"
        !            29: #endif
        !            30: 
        !            31: #define MAXSTKADDR (0x80000000 - ctob(UPAGES)) /* highest stack address */
        !            32: 
        !            33: typedef struct {
        !            34:     Address begin;
        !            35:     Address end;
        !            36:     Address seekaddr;
        !            37: } Map;
        !            38: 
        !            39: private Map datamap, stkmap;
        !            40: private File objfile;
        !            41: private struct exec hdr;
        !            42: 
        !            43: /*
        !            44:  * Read the user area information from the core dump.
        !            45:  */
        !            46: 
        !            47: public coredump_xreadin(mask, reg, signo)
        !            48: int *mask;
        !            49: Word reg[];
        !            50: int *signo;
        !            51: {
        !            52:     register struct user *up;
        !            53:     register Word *savreg;
        !            54:     union {
        !            55:        struct user u;
        !            56:        char dummy[ctob(UPAGES)];
        !            57:     } ustruct;
        !            58: 
        !            59:     objfile = fopen(objname, "r");
        !            60:     if (objfile == nil) {
        !            61:        fatal("can't read \"%s\"", objname);
        !            62:     }
        !            63:     get(objfile, hdr);
        !            64:     up = &(ustruct.u);
        !            65:     fread(up, ctob(UPAGES), 1, corefile);
        !            66:     savreg = (Word *) &(ustruct.dummy[ctob(UPAGES)]);
        !            67:     *mask = savreg[PS];
        !            68:     reg[0] = savreg[R0];
        !            69:     reg[1] = savreg[R1];
        !            70:     reg[2] = savreg[R2];
        !            71:     reg[3] = savreg[R3];
        !            72:     reg[4] = savreg[R4];
        !            73:     reg[5] = savreg[R5];
        !            74:     reg[6] = savreg[R6];
        !            75:     reg[7] = savreg[R7];
        !            76:     reg[8] = savreg[R8];
        !            77:     reg[9] = savreg[R9];
        !            78:     reg[10] = savreg[R10];
        !            79:     reg[11] = savreg[R11];
        !            80:     reg[ARGP] = savreg[AP];
        !            81:     reg[FRP] = savreg[FP];
        !            82:     reg[STKP] = savreg[SP];
        !            83:     reg[PROGCTR] = savreg[PC];
        !            84:     *signo = up->u_arg[0];
        !            85:     datamap.seekaddr = ctob(UPAGES);
        !            86:     stkmap.begin = MAXSTKADDR - ctob(up->u_ssize);
        !            87:     stkmap.end = MAXSTKADDR;
        !            88:     stkmap.seekaddr = datamap.seekaddr + ctob(up->u_dsize);
        !            89:     switch (hdr.a_magic) {
        !            90:        case OMAGIC:
        !            91:            datamap.begin = 0;
        !            92:            datamap.end = ctob(up->u_tsize) + ctob(up->u_dsize);
        !            93:            break;
        !            94: 
        !            95:        case NMAGIC:
        !            96:        case ZMAGIC:
        !            97:            datamap.begin = (Address) ptob(btop(ctob(up->u_tsize) - 1) + 1);
        !            98:            datamap.end = datamap.begin + ctob(up->u_dsize);
        !            99:            break;
        !           100: 
        !           101:        default:
        !           102:            fatal("bad magic number 0x%x", hdr.a_magic);
        !           103:     }
        !           104:     /*
        !           105:      * Core dump not from this object file?
        !           106:      */
        !           107:     if (hdr.a_magic != 0 and up->u_exdata.ux_mag  != 0 and
        !           108:       hdr.a_magic != up->u_exdata.ux_mag) {
        !           109:        warning("core dump ignored");
        !           110:        coredump = false;
        !           111:        fclose(corefile);
        !           112:        fclose(objfile);
        !           113:        start(nil, nil, nil);
        !           114:     }
        !           115: }
        !           116: 
        !           117: public coredump_close()
        !           118: {
        !           119:     fclose(objfile);
        !           120: }
        !           121: 
        !           122: public coredump_readtext(buff, addr, nbytes)
        !           123: char *buff;
        !           124: Address addr;
        !           125: int nbytes;
        !           126: {
        !           127:     if (hdr.a_magic == OMAGIC) {
        !           128:        coredump_readdata(buff, addr, nbytes);
        !           129:     } else {
        !           130:        fseek(objfile, N_TXTOFF(hdr) + addr, 0);
        !           131:        fread(buff, nbytes, sizeof(Byte), objfile);
        !           132:     }
        !           133: }
        !           134: 
        !           135: public coredump_readdata(buff, addr, nbytes)
        !           136: char *buff;
        !           137: Address addr;
        !           138: int nbytes;
        !           139: {
        !           140:     if (addr < datamap.begin) {
        !           141:        error("data address 0x%x too low (lb = 0x%x)", addr, datamap.begin);
        !           142:     } else if (addr > stkmap.end) {
        !           143:        error("data address 0x%x too high (ub = 0x%x)", addr, stkmap.end);
        !           144:     } else if (addr < stkmap.begin) {
        !           145:        fseek(corefile, datamap.seekaddr + addr - datamap.begin, 0);
        !           146:        fread(buff, nbytes, sizeof(Byte), corefile);
        !           147:     } else {
        !           148:        fseek(corefile, stkmap.seekaddr + addr - stkmap.begin, 0);
        !           149:        fread(buff, nbytes, sizeof(Byte), corefile);
        !           150:     }
        !           151: }

unix.superglobalmegacorp.com

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