1*7777Srrh static char sccsid[] = "@(#)xeq.c 4.3 08/17/82";
21355Sbill #include "head.h"
31355Sbill #include <a.out.h>
41355Sbill #include <stab.h>
51355Sbill struct user u;
61355Sbill #include <stdio.h>
71355Sbill INT signo;
81355Sbill INT adrflg;
91355Sbill INT pid;
101355Sbill ADDR userpc;
111355Sbill L_INT cntval;
121355Sbill
131355Sbill
141355Sbill /* service routines for sub process control */
151355Sbill
161355Sbill
171355Sbill /*
181355Sbill * single step until loc with descriptor format d is modified
191355Sbill * return its new value.
201355Sbill */
monex(loc,d)211355Sbill monex(loc, d)
221355Sbill ADDR loc; char d; {
231355Sbill register ADDR oldval;
241355Sbill
251355Sbill oldval = getval(loc, d, DSP);
261355Sbill do {
271355Sbill subpcs('s');
281355Sbill } while (oldval == getval(loc, d, DSP));
291355Sbill return(getval(loc, d, DSP));
301355Sbill }
311355Sbill
321355Sbill /* single step count source stmts */
singstep(count,cmd)331355Sbill singstep(count, cmd)
341355Sbill char cmd; {
351355Sbill register int thisline, curline;
361355Sbill register struct proct *thisproc;
371355Sbill
381355Sbill if (sdbttym.sg_flags != userttym.sg_flags)
391355Sbill stty(2, &userttym);
401355Sbill dot = *(ADDR *) (((ADDR) &u) + PC);
411355Sbill thisproc = adrtoprocp(dot);
421355Sbill thisline = adrtolineno(dot);
431355Sbill if (count == 0) count = 1;
441355Sbill for(; count; count--) {
451355Sbill do {
461355Sbill if (cmd == 'S') { /* MACHINE DEPENDENT */
471355Sbill dot = *(ADDR *) (((ADDR) &u) + PC);
481355Sbill if ((get(dot,ISP) & 0xff) == 0xfb){ /* calls */
491355Sbill int retaddr;
501355Sbill subpcs('s');
511355Sbill retaddr =
521355Sbill *(ADDR *) (((ADDR) &u) + USP) + 16;
531355Sbill retaddr = dot = get(retaddr, DSP);
541355Sbill subpcs('b');
551355Sbill subpcs('c');
561355Sbill dot = retaddr;
571355Sbill subpcs('d');
581355Sbill dot = *(ADDR *) (((ADDR) &u) + PC);
591355Sbill if (retaddr != dot && signo == 0) {
601355Sbill gtty(2, &userttym);
611355Sbill if (sdbttym.sg_flags !=
621355Sbill userttym.sg_flags)
631355Sbill stty(2, &sdbttym);
641355Sbill printf("Breakpoint at \n");
651355Sbill return;
661355Sbill }
671355Sbill continue;
681355Sbill }
691355Sbill }
701355Sbill
711355Sbill subpcs('s');
721355Sbill dot = *(ADDR *) (((ADDR) &u) + PC);
731355Sbill curline = adrtolineno(dot);
741355Sbill } while (!signo &&
751355Sbill ((thisproc == adrtoprocp(dot) && thisline == curline) ||
761355Sbill curline == -1));
771355Sbill gtty(2, &userttym);
781355Sbill if (sdbttym.sg_flags != userttym.sg_flags)
791355Sbill stty(2, &sdbttym);
801355Sbill if (signo) return;
811355Sbill }
821355Sbill }
831355Sbill
doscall()841355Sbill doscall() {
851355Sbill int subargs[NUMARGS];
861355Sbill /* subargs[0] = address,
871355Sbill * subargs[1] = number of arguments
881355Sbill * subargs[2:NUMARGS] = actual arguments
891355Sbill */
901355Sbill union {
911355Sbill int w[128-NUMARGS];
921355Sbill char c[4*(128-NUMARGS)];
931355Sbill }substr;
941355Sbill
951355Sbill register int i, numchars, *subargp;
961355Sbill register char ch;
971355Sbill ADDR straddr, adr, praddr;
981355Sbill ADDR j;
991355Sbill
1001355Sbill praddr = extaddr(proc);
1011355Sbill if (praddr == -1) {
1021355Sbill printf("Cannot find %s\n", proc);
1031355Sbill return;
1041355Sbill }
1051355Sbill straddr = extaddr("_dbargs");
1061355Sbill if (straddr == -1) {
1071355Sbill error("Program not loaded with -lg");
1081355Sbill return;
1091355Sbill }
1101355Sbill
1111355Sbill numchars = 0;
1121355Sbill subargp = subargs;
1131355Sbill argsp++;
1141355Sbill *subargp++ = praddr;
1151355Sbill subargp++;
1161355Sbill
1171355Sbill for (i=0; i<NUMARGS - 2; i++) { /* process an argument */
1181355Sbill ch = *argsp;
1191355Sbill if (ch == '\'') {
1201355Sbill *subargp++ = *(argsp+1);
1211355Sbill argsp += 2;
1221355Sbill } else if (ch == '"') {
1231355Sbill *subargp++ = straddr + sizeof subargs + numchars;
1241355Sbill argsp++;
1251355Sbill for (;;) {
1261355Sbill ch = *argsp++;
1271355Sbill if (ch == '\\') {
1281355Sbill switch(ch = *argsp++) {
1291355Sbill case 'r':
1301355Sbill ch = '\015';
1311355Sbill break;
1321355Sbill case 'n':
1331355Sbill ch = '\012';
1341355Sbill break;
1351355Sbill case '\\':
1361355Sbill ch = '\\';
1371355Sbill break;
1381355Sbill }
1391355Sbill }
1401355Sbill substr.c[numchars++] = ch;
1411355Sbill if (ch == '"') {
1421355Sbill substr.c[numchars-1] = '\0';
1431355Sbill break;
1441355Sbill }
1451355Sbill if (ch == '\0') {
1461355Sbill error("Unterminated string constant");
1471355Sbill return;
1481355Sbill }
1491355Sbill if (numchars > sizeof substr.c) {
1501355Sbill error("Too many string constants");
1511355Sbill return;
1521355Sbill }
1531355Sbill }
1541355Sbill } else if ((ch >= '0' && ch <= '9') || ch == '-') {
1551355Sbill *subargp++ = readint(&argsp);
1561355Sbill } else if ((ch >= 'a' && ch <= 'z') ||
1571355Sbill (ch >= 'A' && ch <= 'Z') || ch == '_') {
1581355Sbill cpname(var, argsp);
1591355Sbill j = varaddr(curproc()->pname, var);
1601355Sbill if (j == -1) {
1611355Sbill return;
1621355Sbill }
1631355Sbill *subargp++ =
1641355Sbill sl_class == N_RSYM ?
1651355Sbill *(ADDR *)(((ADDR) &u) + R0 + (WORDSIZE)*j) :
1661355Sbill getval(j, typetodesc(sl_type, 0)[0], DSP);
1671355Sbill do {
1681355Sbill argsp++;
1691355Sbill } while (varchar(*argsp) || number(*argsp));
1701355Sbill } else if (ch != ')') {
1711355Sbill printf("Unexpected character %c\n", ch);
1721355Sbill return;
1731355Sbill }
1741355Sbill
1751355Sbill do {
1761355Sbill ch = *argsp++;
1771355Sbill } while(ch == ' ');
1781355Sbill if (ch == ')') {
1791355Sbill if (scallx == 0) {
1801355Sbill scallx = 1;
1811355Sbill pcs = *(ADDR *)(((ADDR)&u)+PC);
1821355Sbill fps = *(ADDR *)(((ADDR)&u)+FP);
1831355Sbill aps = *(ADDR *)(((ADDR)&u)+AP);
1841355Sbill if (bkpts = scanbkpt(userpc)) {
1851355Sbill if (flagss = bkpts->flag) {
1861355Sbill bkpts->flag = BKPTSET;
1871355Sbill }
1881355Sbill }
1891355Sbill }
1901355Sbill dot = *(ADDR *)(((ADDR)&u)+PC) = extaddr("_dbsubc");
1911355Sbill if (dot == -1) {
1921355Sbill error("Internal error - cannot find _dbsubc");
1931355Sbill return;
1941355Sbill }
1951355Sbill adrflg = 1;
1961355Sbill cntval = 1;
1971355Sbill if (pid == 0 || signo) subpcs('r');
1981355Sbill subargs[1] = (subargp - subargs) - 2;
1991355Sbill adr = straddr;
2001355Sbill for (j=0; j<=(subargp-subargs); j++) {
2011355Sbill put(adr, DSP, subargs[j]);
2021355Sbill adr += WORDSIZE;
2031355Sbill }
2041355Sbill adr = straddr + sizeof subargs;
2051355Sbill for (j=0; j<(numchars+WORDSIZE-1)/WORDSIZE; j++) {
2061355Sbill put(adr, DSP, substr.w[j]);
2071355Sbill adr += WORDSIZE;
2081355Sbill }
2091355Sbill dschar = *argsp++;
2101355Sbill errflg = 0;
2111355Sbill dopcs('c');
2121355Sbill if (!signo) printf("Breakpoint");
2131355Sbill printf(" at\n");
2141355Sbill return;
2151355Sbill }
2161355Sbill while (*argsp == ' ' || *argsp == ',')
2171355Sbill argsp++;
2181355Sbill }
2191355Sbill
2201355Sbill error ("Too many arguments");
2211355Sbill
2221355Sbill }
2231355Sbill
2241355Sbill
2251355Sbill /* get arguments from core file, place them in args */
getargs()2261355Sbill getargs() {
2271355Sbill struct proct *procp;
2281355Sbill ADDR p, av;
2291355Sbill int ac, i;
2301355Sbill char *argsp = args;
2311355Sbill union {
2321355Sbill char c[WORDSIZE];
2331355Sbill int w;
2341355Sbill float f;
2351355Sbill } word;
2361355Sbill
2371355Sbill if ((procp = initframe()) == badproc) goto old1;
2381355Sbill do {
2391355Sbill if (eqstr("main", procp->pname))
2401355Sbill goto fnd;
2411355Sbill } while ((procp = nextframe()) != badproc);
2421355Sbill
2431355Sbill old1: cpstr(args, oldargs);
2441355Sbill printf("%s %s\n", symfil, args);
2451355Sbill return;
2461355Sbill
2471355Sbill fnd: ac = get(argp, DSP);
2481355Sbill if ((ac == 0) || (ac & 0xff)) goto old1;
2491355Sbill ac = get(argp+4, DSP);
2501355Sbill av = (ADDR) get(argp+8, DSP);
2511355Sbill
2521355Sbill av += WORDSIZE;
2531355Sbill ac--;
2541355Sbill
2551355Sbill for (; ac; ac--) {
2561355Sbill p = (ADDR) get(av, DSP);
2571355Sbill av += WORDSIZE;
2581355Sbill for (;;) {
2591355Sbill word.w = get(p, DSP);
2601355Sbill for (i=0; i<WORDSIZE; i++) {
2611355Sbill if (word.c[i] == '\0') goto l1;
2621355Sbill *argsp++ = word.c[i];
2631355Sbill }
2641355Sbill p += WORDSIZE;
2651355Sbill }
2661355Sbill l1: *argsp++ = ' ';
2671355Sbill }
2681355Sbill *argsp == '\0';
2691355Sbill printf("%s %s\n", symfil, args);
2701355Sbill return;
2711355Sbill
2721355Sbill
2731355Sbill }
2741355Sbill
dopcs(c)2751355Sbill dopcs(c)
2761355Sbill char c; {
2771355Sbill if (c != 'r' && c != 'R' && sdbttym.sg_flags != userttym.sg_flags)
2781355Sbill stty(2, &userttym);
2791355Sbill subpcs(c);
2801355Sbill gtty(2, &userttym);
2811355Sbill if (sdbttym.sg_flags != userttym.sg_flags)
2821355Sbill stty(2, &sdbttym);
2831355Sbill
2841355Sbill if (eqany(c, "cCsS") &&
2851355Sbill *(ADDR *)(((ADDR)&u)+PC) == extaddr("_dbsubn")) {
2861355Sbill if (dschar == '/') {
2871355Sbill dispf((ADDR) 0, *argsp ? argsp : "d", N_RSYM, 0, 0, DSP);
2881355Sbill }
2891355Sbill else
2901355Sbill printf("Procedure returned normally\n");
2911355Sbill userpc = dot = *(ADDR *)(((ADDR)&u)+PC) = pcs;
2921355Sbill *(ADDR *)(((ADDR)&u)+FP) = fps;
2931355Sbill *(ADDR *)(((ADDR)&u)+AP) = aps;
2941355Sbill if (bkpts)
2951355Sbill bkpts->flag = flagss;
2961355Sbill scallx = 0;
2971355Sbill longjmp(env, 0);
2981355Sbill }
2991355Sbill }
3001355Sbill
3011355Sbill /* execute commands from a breakpoint */
acommand(cmds)3021355Sbill acommand(cmds)
3031355Sbill char *cmds; {
3041355Sbill char *p = cmds;
3051355Sbill int endflg = 0;
3061355Sbill
3071355Sbill setcur(0);
3081355Sbill do { /* process a command */
3091355Sbill for (;;) {
3101355Sbill if (*p == ';') {
3111355Sbill *p = '\n';
3121355Sbill break;
3131355Sbill }
3141355Sbill if (*p == '\n') {
3151355Sbill endflg++;
3161355Sbill break;
3171355Sbill }
3181355Sbill p++;
3191355Sbill }
3201355Sbill if (decode(cmds) == 1) {
3211355Sbill printf("Bad command: ");
3221355Sbill do {
3231355Sbill printf("%c", *cmds);
3241355Sbill } while (*cmds++ != '\n');
3251355Sbill return;
3261355Sbill }
3271355Sbill docommand();
3283947Sroot if (!endflg)
3293947Sroot *p = ';';
3301355Sbill p = cmds = p + 1;
3311355Sbill } while (!endflg);
3321355Sbill }
333