merge linton branch delta trail
[unix-history] / usr / src / old / dbx / main.c
index 41ac5ee..f9e6bab 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1982 Regents of the University of California */
 
 /* Copyright (c) 1982 Regents of the University of California */
 
-static char sccsid[] = "@(#)main.c 1.2 %G%";
+static char sccsid[] = "@(#)main.c     1.7 (Berkeley) %G%";
 
 /*
  * Debugger main routine.
 
 /*
  * Debugger main routine.
@@ -11,15 +11,22 @@ static char sccsid[] = "@(#)main.c 1.2 %G%";
 #include <signal.h>
 #include <errno.h>
 #include "main.h"
 #include <signal.h>
 #include <errno.h>
 #include "main.h"
+#include "symbols.h"
 #include "scanner.h"
 #include "process.h"
 #include "scanner.h"
 #include "process.h"
+#include "runtime.h"
 #include "source.h"
 #include "object.h"
 #include "source.h"
 #include "object.h"
+#include "mappings.h"
 
 #ifndef public
 
 #define isterm(file)   (interactive or isatty(fileno(file)))
 
 
 #ifndef public
 
 #define isterm(file)   (interactive or isatty(fileno(file)))
 
+#include <sgtty.h>
+
+typedef struct sgttyb Ttyinfo;
+
 #endif
 
 public Boolean coredump;               /* true if using a core dump */
 #endif
 
 public Boolean coredump;               /* true if using a core dump */
@@ -29,6 +36,7 @@ public Boolean lexdebug;              /* trace yylex return values */
 public Boolean tracebpts;              /* trace create/delete breakpoints */
 public Boolean traceexec;              /* trace process execution */
 public Boolean tracesyms;              /* print symbols as their read */
 public Boolean tracebpts;              /* trace create/delete breakpoints */
 public Boolean traceexec;              /* trace process execution */
 public Boolean tracesyms;              /* print symbols as their read */
+public Boolean traceblocks;            /* trace blocks while reading symbols */
 
 public File corefile;                  /* File id of core dump */
 
 
 public File corefile;                  /* File id of core dump */
 
@@ -40,6 +48,8 @@ private char outbuf[BUFSIZ];          /* standard output buffer */
 private char namebuf[512];             /* possible name of object file */
 private int firstarg;                  /* first program argument (for -r) */
 
 private char namebuf[512];             /* possible name of object file */
 private int firstarg;                  /* first program argument (for -r) */
 
+private Ttyinfo ttyinfo;
+
 private catchintr();
 
 /*
 private catchintr();
 
 /*
@@ -50,12 +60,17 @@ main(argc, argv)
 int argc;
 String argv[];
 {
 int argc;
 String argv[];
 {
-    register Integer i;
+    register integer i;
+    extern String date;
+    extern integer versionNumber;
 
     cmdname = argv[0];
     catcherrs();
     onsyserr(EINTR, nil);
     setbuf(stdout, outbuf);
 
     cmdname = argv[0];
     catcherrs();
     onsyserr(EINTR, nil);
     setbuf(stdout, outbuf);
+    printf("dbx version %d of %s.\nType 'help' for help.\n",
+       versionNumber, date);
+    fflush(stdout);
     scanargs(argc, argv);
     language_init();
     process_init();
     scanargs(argc, argv);
     language_init();
     process_init();
@@ -73,7 +88,9 @@ String argv[];
     } else {
        init();
     }
     } else {
        init();
     }
-    setjmp(env);
+    if (setjmp(env) != FIRST_TIME) {
+       restoretty(stdout, &ttyinfo);
+    }
     signal(SIGINT, catchintr);
     yyparse();
     putchar('\n');
     signal(SIGINT, catchintr);
     yyparse();
     putchar('\n');
@@ -92,13 +109,22 @@ public init()
     char buf[100];
     extern String getenv();
 
     char buf[100];
     extern String getenv();
 
+    savetty(stdout, &ttyinfo);
     enterkeywords();
     scanner_init();
     if (not coredump and not runfirst) {
        start(nil, nil, nil);
     }
     enterkeywords();
     scanner_init();
     if (not coredump and not runfirst) {
        start(nil, nil, nil);
     }
+    printf("reading symbolic information ...");
+    fflush(stdout);
     readobj(objname);
     readobj(objname);
-    curfunc = program;
+    printf("\n");
+    fflush(stdout);
+    if (coredump) {
+       setcurfunc(whatblock(pc));
+    } else {
+       setcurfunc(program);
+    }
     bpinit();
     f = fopen(initfile, "r");
     if (f != nil) {
     bpinit();
     f = fopen(initfile, "r");
     if (f != nil) {
@@ -220,13 +246,14 @@ String argv[];
     tracebpts = false;
     traceexec = false;
     tracesyms = false;
     tracebpts = false;
     traceexec = false;
     tracesyms = false;
+    traceblocks = false;
     foundfile = false;
     corefile = nil;
     coredump = true;
     sourcepath = list_alloc();
     list_append(list_item("."), nil, sourcepath);
     i = 1;
     foundfile = false;
     corefile = nil;
     coredump = true;
     sourcepath = list_alloc();
     list_append(list_item("."), nil, sourcepath);
     i = 1;
-    while (i < argc and not foundfile and corefile == nil) {
+    while (i < argc and (not foundfile or corefile == nil)) {
        if (argv[i][0] == '-') {
            if (streq(argv[i], "-I")) {
                ++i;
        if (argv[i][0] == '-') {
            if (streq(argv[i], "-I")) {
                ++i;
@@ -310,6 +337,10 @@ char c;
            tracesyms = true;
            break;
 
            tracesyms = true;
            break;
 
+       case 'n':
+           traceblocks = true;
+           break;
+
        case 'l':
 #          ifdef LEXDEBUG
                lexdebug = true;
        case 'l':
 #          ifdef LEXDEBUG
                lexdebug = true;
@@ -323,6 +354,24 @@ char c;
     }
 }
 
     }
 }
 
+/*
+ * Save/restore the state of a tty.
+ */
+
+public savetty(f, t)
+File f;
+Ttyinfo *t;
+{
+    gtty(fileno(f), t);
+}
+
+public restoretty(f, t)
+File f;
+Ttyinfo *t;
+{
+    stty(fileno(f), t);
+}
+
 /*
  * Exit gracefully.
  */
 /*
  * Exit gracefully.
  */
@@ -330,5 +379,6 @@ char c;
 public quit(r)
 Integer r;
 {
 public quit(r)
 Integer r;
 {
+    pterm(process);
     exit(r);
 }
     exit(r);
 }