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