1*48096Sbostic /*- 2*48096Sbostic * Copyright (c) 1980 The Regents of the University of California. 3*48096Sbostic * All rights reserved. 4*48096Sbostic * 5*48096Sbostic * %sccs.include.redist.c% 622514Sdist */ 75510Slinton 822514Sdist #ifndef lint 9*48096Sbostic static char sccsid[] = "@(#)start.c 5.4 (Berkeley) 04/16/91"; 10*48096Sbostic #endif /* not lint */ 1130848Smckusick 125510Slinton /* 135510Slinton * Begin execution. 145510Slinton * 155510Slinton * For px, pstart does a traced exec to read in px and then stop. But we 165510Slinton * want control after px has read in the obj file and before it starts 175653Slinton * executing. The zeroth argument to px tells it to give us control 185510Slinton * by sending itself a signal just prior to interpreting. 195510Slinton * 205510Slinton * We set a "END_BP" breakpoint at the end of the code so that the 215510Slinton * process data doesn't disappear after the program terminates. 225510Slinton */ 235510Slinton 245510Slinton #include "defs.h" 255510Slinton #include <signal.h> 265510Slinton #include "process.h" 275510Slinton #include "machine.h" 285653Slinton #include "main.h" 295510Slinton #include "breakpoint.h" 305510Slinton #include "source.h" 315510Slinton #include "object.h" 325510Slinton #include "mappings.h" 335510Slinton #include "sym.h" 345510Slinton #include "process.rep" 355510Slinton 3630848Smckusick #include "pxinfo.h" 375510Slinton 385510Slinton start(argv, infile, outfile) 395510Slinton char **argv; 405510Slinton char *infile, *outfile; 415510Slinton { 425714Slinton char *cmd; 435510Slinton 445714Slinton setsigtrace(); 4536538Smckusick cmd = "px"; 465714Slinton pstart(process, cmd, argv, infile, outfile); 475714Slinton if (process->status == STOPPED) { 4830848Smckusick TRAPARGS *ap, t; 495653Slinton 5030848Smckusick pcont(process); 5130848Smckusick if (process->status != STOPPED) { 5230848Smckusick if (option('t')) { 5330848Smckusick quit(process->exitval); 5430848Smckusick } else { 5530848Smckusick panic("px exited with %d", process->exitval); 565714Slinton } 5730848Smckusick } 5830848Smckusick #ifdef tahoe 5930848Smckusick dread(&ap, process->fp, sizeof(ap)); 6030848Smckusick ap = (TRAPARGS *)((unsigned)ap - 4); 6130848Smckusick dread(&RETLOC, process->fp - 8, sizeof(RETLOC)); 6230848Smckusick #else 6330848Smckusick dread(&ap, process->fp + 2*sizeof(int), sizeof(ap)); 6430848Smckusick #endif 6530848Smckusick dread(&t, ap, sizeof(TRAPARGS)); 6630848Smckusick 6730848Smckusick #define NARGS 5 6830848Smckusick #ifdef tahoe 6930848Smckusick # define STKNARGS (sizeof(int)*(NARGS+1)) 7030848Smckusick # define NARGLOC t.trp_removed 7130848Smckusick #else 7230848Smckusick # define STKNARGS (NARGS) 7330848Smckusick # define NARGLOC t.nargs 7430848Smckusick #endif 7530848Smckusick if (NARGLOC != STKNARGS) { 7630848Smckusick if (option('t')) { 7730848Smckusick unsetsigtraces(process); 7830848Smckusick pcont(process); 7930848Smckusick quit(process->exitval); 8030848Smckusick } else { 8130848Smckusick panic("start: args out of sync"); 825714Slinton } 8330848Smckusick } 8430848Smckusick DISPLAY = t.disp; 8530848Smckusick DP = t.dp; 8630848Smckusick ENDOFF = t.objstart; 8736538Smckusick PCADDR = t.pcaddr; 8830848Smckusick LOOPADDR = t.loopaddr; 895714Slinton pc = 0; 905714Slinton curfunc = program; 915714Slinton if (objsize != 0) { 925714Slinton addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0); 935510Slinton } 945714Slinton } 955510Slinton } 965510Slinton 975510Slinton /* 985510Slinton * Note the termination of the program. We do this so as to avoid 995510Slinton * having the process exit, which would make the values of variables 1005510Slinton * inaccessible. 1015510Slinton * 1025510Slinton * Although the END_BP should really be deleted, it is taken 1035510Slinton * care of by fixbps the next time the program runs. 1045510Slinton */ 1055510Slinton 1065510Slinton endprogram() 1075510Slinton { 1085714Slinton if (ss_variables) { 1095714Slinton prvarnews(); 1105714Slinton } 1115714Slinton printf("\nexecution completed\n"); 1125714Slinton curfunc = program; 1135761Slinton skimsource(srcfilename(pc)); 1145714Slinton curline = lastlinenum; 1155714Slinton erecover(); 1165510Slinton } 1175510Slinton 1185510Slinton /* 1195510Slinton * set up what signals we want to trace 1205510Slinton */ 1215510Slinton 1225510Slinton LOCAL setsigtrace() 1235510Slinton { 1245714Slinton register PROCESS *p; 1255510Slinton 1265714Slinton p = process; 1275714Slinton psigtrace(p, SIGINT, TRUE); 1285714Slinton psigtrace(p, SIGTRAP, TRUE); 1295714Slinton psigtrace(p, SIGIOT, TRUE); 1305739Slinton psigtrace(p, SIGILL, TRUE); 1315761Slinton psigtrace(p, SIGBUS, TRUE); 1325510Slinton } 133