1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 static char sccsid[] = "@(#)start.c 5.2 (Berkeley) 04/07/87"; 9 #endif not lint 10 11 /* 12 * Begin execution. 13 * 14 * For px, pstart does a traced exec to read in px and then stop. But we 15 * want control after px has read in the obj file and before it starts 16 * executing. The zeroth argument to px tells it to give us control 17 * by sending itself a signal just prior to interpreting. 18 * 19 * We set a "END_BP" breakpoint at the end of the code so that the 20 * process data doesn't disappear after the program terminates. 21 */ 22 23 #include "defs.h" 24 #include <signal.h> 25 #include "process.h" 26 #include "machine.h" 27 #include "main.h" 28 #include "breakpoint.h" 29 #include "source.h" 30 #include "object.h" 31 #include "mappings.h" 32 #include "sym.h" 33 #include "process.rep" 34 35 #include "pxinfo.h" 36 37 start(argv, infile, outfile) 38 char **argv; 39 char *infile, *outfile; 40 { 41 char *cmd; 42 43 setsigtrace(); 44 cmd = "/usr/ucb/px"; 45 pstart(process, cmd, argv, infile, outfile); 46 if (process->status == STOPPED) { 47 TRAPARGS *ap, t; 48 49 pcont(process); 50 if (process->status != STOPPED) { 51 if (option('t')) { 52 quit(process->exitval); 53 } else { 54 panic("px exited with %d", process->exitval); 55 } 56 } 57 #ifdef tahoe 58 dread(&ap, process->fp, sizeof(ap)); 59 ap = (TRAPARGS *)((unsigned)ap - 4); 60 dread(&RETLOC, process->fp - 8, sizeof(RETLOC)); 61 #else 62 dread(&ap, process->fp + 2*sizeof(int), sizeof(ap)); 63 #endif 64 dread(&t, ap, sizeof(TRAPARGS)); 65 66 #define NARGS 5 67 #ifdef tahoe 68 # define STKNARGS (sizeof(int)*(NARGS+1)) 69 # define NARGLOC t.trp_removed 70 #else 71 # define STKNARGS (NARGS) 72 # define NARGLOC t.nargs 73 #endif 74 if (NARGLOC != STKNARGS) { 75 if (option('t')) { 76 unsetsigtraces(process); 77 pcont(process); 78 quit(process->exitval); 79 } else { 80 panic("start: args out of sync"); 81 } 82 } 83 DISPLAY = t.disp; 84 DP = t.dp; 85 ENDOFF = t.objstart; 86 PCADDRP = t.pcaddrp; 87 LOOPADDR = t.loopaddr; 88 pc = 0; 89 curfunc = program; 90 if (objsize != 0) { 91 addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0); 92 } 93 } 94 } 95 96 /* 97 * Note the termination of the program. We do this so as to avoid 98 * having the process exit, which would make the values of variables 99 * inaccessible. 100 * 101 * Although the END_BP should really be deleted, it is taken 102 * care of by fixbps the next time the program runs. 103 */ 104 105 endprogram() 106 { 107 if (ss_variables) { 108 prvarnews(); 109 } 110 printf("\nexecution completed\n"); 111 curfunc = program; 112 skimsource(srcfilename(pc)); 113 curline = lastlinenum; 114 erecover(); 115 } 116 117 /* 118 * set up what signals we want to trace 119 */ 120 121 LOCAL setsigtrace() 122 { 123 register PROCESS *p; 124 125 p = process; 126 psigtrace(p, SIGINT, TRUE); 127 psigtrace(p, SIGTRAP, TRUE); 128 psigtrace(p, SIGIOT, TRUE); 129 psigtrace(p, SIGILL, TRUE); 130 psigtrace(p, SIGBUS, TRUE); 131 } 132