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