BSD 3 development
[unix-history] / usr / src / cmd / sdb / runpcs.c
index 7b26505..70c1a13 100644 (file)
@@ -80,9 +80,6 @@ runpcs(runmode,execsig)
 {
        REG BKPTR       bkpt;
        IF adrflg THEN userpc=dot; FI
 {
        REG BKPTR       bkpt;
        IF adrflg THEN userpc=dot; FI
-/*
-       printf("%s: running\n", symfil);
-*/
        WHILE --loopcnt>=0
        DO
                if (debug) printf("\ncontinue %x %d\n",userpc,execsig);
        WHILE --loopcnt>=0
        DO
                if (debug) printf("\ncontinue %x %d\n",userpc,execsig);
@@ -97,19 +94,23 @@ runpcs(runmode,execsig)
                ptrace(runmode,pid,userpc,execsig);
                bpwait(); chkerr(); execsig=0; delbp(); readregs();
 
                ptrace(runmode,pid,userpc,execsig);
                bpwait(); chkerr(); execsig=0; delbp(); readregs();
 
-               IF (signo==0) ANDF (bkpt=scanbkpt(userpc))
+       loop1:  IF (signo==0) ANDF (bkpt=scanbkpt(userpc))
                THEN /* stopped by BPT instruction */
                        if (debug) printf("\n BPT code; '%s'%o'%o'%d",
                                bkpt->comm,bkpt->comm[0],EOR,bkpt->flag);
                        dot=bkpt->loc;
                THEN /* stopped by BPT instruction */
                        if (debug) printf("\n BPT code; '%s'%o'%o'%d",
                                bkpt->comm,bkpt->comm[0],EOR,bkpt->flag);
                        dot=bkpt->loc;
+                       IF bkpt->comm[0] != EOR
+                       THEN acommand(bkpt->comm);
+                       FI
                        IF bkpt->flag==BKPTEXEC
                        ORF ((bkpt->flag=BKPTEXEC)
                        IF bkpt->flag==BKPTEXEC
                        ORF ((bkpt->flag=BKPTEXEC)
-                               ANDF bkpt->comm[0]!=EOR
-                               ANDF --bkpt->count)
+                               ANDF bkpt->comm[0]!=EOR)
                        THEN execbkpt(bkpt,execsig); execsig=0; loopcnt++;
                        THEN execbkpt(bkpt,execsig); execsig=0; loopcnt++;
+                            goto loop1;
                        ELSE bkpt->count=bkpt->initcnt;
                        FI
                ELSE execsig=signo;
                        ELSE bkpt->count=bkpt->initcnt;
                        FI
                ELSE execsig=signo;
+                    if (execsig) break;
                FI
        OD
                if (debug) printf("Returning from runpcs\n");
                FI
        OD
                if (debug) printf("Returning from runpcs\n");
@@ -134,17 +135,35 @@ endpcs()
        bpstate=BPOUT;
 }
 
        bpstate=BPOUT;
 }
 
+#ifdef VFORK
+nullsig()
+{
+
+}
+#endif
+
 setup()
 {
        close(fsym); fsym = -1;
 setup()
 {
        close(fsym); fsym = -1;
+#ifdef VFORK
+       IF (pid = vfork()) == 0
+#else
        IF (pid = fork()) == 0
        IF (pid = fork()) == 0
+#endif
        THEN ptrace(SETTRC,0,0,0);
             signal(SIGINT,sigint); signal(SIGQUIT,sigqit);
        THEN ptrace(SETTRC,0,0,0);
             signal(SIGINT,sigint); signal(SIGQUIT,sigqit);
+#ifdef VFORK
+            signal(SIGTRC,nullsig);
+#endif
                if (debug) printf("About to doexec  pid=%d\n",pid);
                if (debug) printf("About to doexec  pid=%d\n",pid);
+#ifdef UCBVAX
+            doexec(); _exit(0);
+#else
             doexec(); exit(0);
             doexec(); exit(0);
+#endif
        ELIF pid == -1
        THEN error(NOFORK);
        ELIF pid == -1
        THEN error(NOFORK);
-       ELSE bpwait(); readregs(); /******** lp[0]=EOR; lp[1]=0; */
+       ELSE bpwait(); readregs();
        if (debug) printf("About to open symfil = %s\n", symfil);
             fsym=open(symfil,wtflag);
             IF errflg
        if (debug) printf("About to open symfil = %s\n", symfil);
             fsym=open(symfil,wtflag);
             IF errflg
@@ -170,30 +189,67 @@ extern STRING environ;
 
 doexec()
 {
 
 doexec()
 {
-       STRING          argl[MAXARG];
-       CHAR            args[LINSIZ];
-       STRING          p, *ap, filnam;
-       ap=argl; p=args;
-       *ap++=symfil;
-       REP     IF rdc()==EOR THEN break; FI
-               *ap = p;
-               WHILE lastc!=EOR ANDF lastc!=SP ANDF lastc!=TB DO *p++=lastc; readchar(); OD
-               *p++=0; filnam = *ap+1;
-               IF **ap=='<'
-               THEN    close(0);
-                       IF open(filnam,0)<0
-                       THEN    printf("%s: cannot open\n",filnam); exit(0);
-                       FI
-               ELIF **ap=='>'
-               THEN    close(1);
-                       IF creat(filnam,0666)<0
-                       THEN    printf("%s: cannot create\n",filnam); exit(0);
-                       FI
-               ELSE    ap++;
-               FI
-       PER lastc!=EOR DONE
-       *ap++=0;
-       if (debug) printf("About to exect(%s, %d, %d)\n",symfil,argl,environ);
+       char *argl[MAXARG], args[LINSIZ];
+       register char c, redchar, *argsp, **arglp, *filnam;
+
+       arglp = argl;
+       argsp = args;
+       *arglp++ = symfil;
+       c = ' ';
+
+       do {
+               while (eqany(c, " \t")) {
+                       c = rdc();
+               } 
+               if (eqany(c, "<>")) {
+                       redchar = c;
+                       do {
+                               c = rdc();
+                       } while (eqany(c, " \t"));
+                       filnam = argsp;
+                       do {
+                               *argsp++ = c;
+                               c = rdc();
+                       } while (!eqany(c, " <>\t\n"));
+                       *argsp++ = '\0';
+                       if (redchar == '<') {
+                               close(0);
+                               if (open(filnam,0) < 0) {
+                                       printf("%s: cannot open\n",filnam);
+#ifdef UCBVAX
+                                        _exit(0);
+#else
+                                        exit(0);
+#endif
+                               }
+                       } else {
+                               close(1);
+                               if (creat(filnam,0666) < 0) {
+                                       printf("%s: cannot create\n",filnam);
+#ifdef UCBVAX
+                                        _exit(0);
+#else
+                                        exit(0);
+#endif
+                               }
+                       }
+               } else if (c != '\n') {
+                       *arglp++ = argsp;
+                       do {
+                               *argsp++ = c;
+                               c = rdc();
+                       } while(!eqany(c, " <>\t\n"));
+                       *argsp++ = '\0';
+               }
+       } while (c != '\n');
+       *arglp = (char *) 0;
+       if (debug) {
+               char **dap;
+               printf("About to exect(%s, %d, %d)\n",symfil,argl,environ);
+               for (dap = argl; *dap; dap++) {
+                       printf("%s, ", *dap);
+               }
+       }
        exect(symfil, argl, environ);
        perror("Returned from exect");
 }
        exect(symfil, argl, environ);
        perror("Returned from exect");
 }
@@ -243,9 +299,6 @@ setbp()
                        THEN error("cannot set breakpoint: ");
                             printf("%s:%d @ %d\n", adrtoprocp(dot)->pname,
                                adrtolineno(dot), dot);
                        THEN error("cannot set breakpoint: ");
                             printf("%s:%d @ %d\n", adrtoprocp(dot)->pname,
                                adrtolineno(dot), dot);
-/********
-                            psymoff(bkptr->loc,ISYM,"\n");
-*/
                        FI
                   FI
                OD
                        FI
                   FI
                OD
@@ -300,14 +353,18 @@ readregs()
        userpc= *(ADDR *)(((ADDR)&u)+PC);
 }
 
        userpc= *(ADDR *)(((ADDR)&u)+PC);
 }
 
-rdc()
-{      REP     readchar();
-       PER     lastc==SP ORF lastc==TB
-       DONE
-       return(lastc);
-}
-
+char 
 readchar() {
        lastc = *argsp++;
        if (lastc == '\0') lastc = '\n';
 readchar() {
        lastc = *argsp++;
        if (lastc == '\0') lastc = '\n';
+       return(lastc);
+}
+
+char
+rdc()
+{
+       register char c;
+
+       c = *argsp++;
+       return(c == '\0' ? '\n' : c);
 }
 }