file reorg, pathnames.h, paths.h
[unix-history] / usr / src / old / dbx / main.c
index 698032b..10c40e4 100644 (file)
@@ -1,8 +1,20 @@
-/* Copyright (c) 1982 Regents of the University of California */
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
 
 
-static char sccsid[] = "@(#)main.c     1.11 (Berkeley) %G%";
+#ifndef lint
+static char sccsid[] = "@(#)main.c     5.5 (Berkeley) %G%";
+#endif not lint
 
 
-static char rcsid[] = "$Header: main.c,v 1.5 84/12/26 10:40:16 linton Exp $";
+static char rcsid[] = "$Header: main.c,v 1.4 87/07/08 21:31:27 donn Exp $";
 
 /*
  * Debugger main routine.
 
 /*
  * Debugger main routine.
@@ -13,6 +25,7 @@ static char rcsid[] = "$Header: main.c,v 1.5 84/12/26 10:40:16 linton Exp $";
 #include <signal.h>
 #include <errno.h>
 #include "main.h"
 #include <signal.h>
 #include <errno.h>
 #include "main.h"
+#include "tree.h"
 #include "eval.h"
 #include "debug.h"
 #include "symbols.h"
 #include "eval.h"
 #include "debug.h"
 #include "symbols.h"
@@ -24,22 +37,29 @@ static char rcsid[] = "$Header: main.c,v 1.5 84/12/26 10:40:16 linton Exp $";
 #include "object.h"
 #include "mappings.h"
 #include "coredump.h"
 #include "object.h"
 #include "mappings.h"
 #include "coredump.h"
+#include "pathnames.h"
 
 #ifndef public
 
 #define isterm(file)   (interactive or isatty(fileno(file)))
 
 
 #ifndef public
 
 #define isterm(file)   (interactive or isatty(fileno(file)))
 
-#include <sgtty.h>
-#include <fcntl.h>
-
-typedef struct {
-    struct sgttyb sg;          /* standard sgttyb structure */
-    struct tchars tc;          /* terminal characters */
-    struct ltchars ltc;                /* local special characters */
-    integer ldisc;             /* line discipline */
-    integer local;             /* TIOCLGET */
-    integer fcflags;           /* fcntl(2) F_GETFL, F_SETFL */
-} Ttyinfo;
+#ifdef IRIS
+#   include <termio.h>
+
+    typedef struct termio Ttyinfo;
+#else
+#   include <sgtty.h>
+#   include <fcntl.h>
+
+    typedef struct {
+       struct sgttyb sg;               /* standard sgttyb structure */
+       struct tchars tc;               /* terminal characters */
+       struct ltchars ltc;             /* local special characters */
+       integer ldisc;                  /* line discipline */
+       integer local;                  /* TIOCLGET */
+       integer fcflags;                /* fcntl(2) F_GETFL, F_SETFL */
+    } Ttyinfo;
+#endif
 
 #endif
 
 
 #endif
 
@@ -52,21 +72,25 @@ public boolean traceexec;           /* trace execution */
 public boolean tracesyms;              /* print symbols are they are read */
 public boolean traceblocks;            /* trace blocks while reading symbols */
 public boolean vaddrs;                 /* map addresses through page tables */
 public boolean tracesyms;              /* print symbols are they are read */
 public boolean traceblocks;            /* trace blocks while reading symbols */
 public boolean vaddrs;                 /* map addresses through page tables */
+public boolean quiet;                  /* don't print heading */
+public boolean autostrip;              /* strip C++ prefixes */
 
 public File corefile;                  /* File id of core dump */
 
 
 public File corefile;                  /* File id of core dump */
 
+public integer versionNumber = 4;
+
 #define FIRST_TIME 0                   /* initial value setjmp returns */
 
 private Boolean initdone = false;      /* true if initialization done */
 private jmp_buf env;                   /* setjmp/longjmp data */
 private char outbuf[BUFSIZ];           /* standard output buffer */
 private char namebuf[512];             /* possible name of object file */
 #define FIRST_TIME 0                   /* initial value setjmp returns */
 
 private Boolean initdone = false;      /* true if initialization done */
 private jmp_buf env;                   /* setjmp/longjmp data */
 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 Ttyinfo ttyinfo;
 private String corename;               /* name of core file */
 
 private catchintr();
 
 private Ttyinfo ttyinfo;
 private String corename;               /* name of core file */
 
 private catchintr();
+private char **scanargs();
 
 /*
  * Main program.
 
 /*
  * Main program.
@@ -76,27 +100,33 @@ main(argc, argv)
 int argc;
 String argv[];
 {
 int argc;
 String argv[];
 {
-    register integer i;
-    extern String date;
     extern integer versionNumber;
     extern integer versionNumber;
+    char **scanargs();
+
+    if (!(cmdname = rindex(*argv, '/')))
+       cmdname = *argv;
+    else
+       ++cmdname;
 
 
-    cmdname = argv[0];
     catcherrs();
     onsyserr(EINTR, nil);
     catcherrs();
     onsyserr(EINTR, nil);
+    onsyserr(EADDRINUSE, nil);
+    onsyserr(ENXIO, nil);
     setbuf(stdout, outbuf);
     setbuf(stdout, outbuf);
-    printf("dbx version 3.%d of %s.\nType 'help' for help.\n",
-       versionNumber, date);
-    fflush(stdout);
-    scanargs(argc, argv);
+    argv = scanargs(argc, argv);
+    if (not runfirst and not quiet) {
+       printheading();
+    }
+    openfiles();
     language_init();
     symbols_init();
     process_init();
     language_init();
     symbols_init();
     process_init();
+    optab_init();
     if (runfirst) {
        if (setjmp(env) == FIRST_TIME) {
            arginit();
     if (runfirst) {
        if (setjmp(env) == FIRST_TIME) {
            arginit();
-           for (i = firstarg; i < argc; i++) {
-               newarg(argv[i]);
-           }
+           while (*argv)
+               newarg(*argv++);
            run();
            /* NOTREACHED */
        } else {
            run();
            /* NOTREACHED */
        } else {
@@ -114,6 +144,16 @@ String argv[];
     quit(0);
 }
 
     quit(0);
 }
 
+public printheading ()
+{
+    extern String date;
+
+    printf("dbx version 3.%d of %s.\nType 'help' for help.\n",
+       versionNumber, date
+    );
+    fflush(stdout);
+}
+
 /*
  * Initialize the world, including setting initial input file
  * if the file exists.
 /*
  * Initialize the world, including setting initial input file
  * if the file exists.
@@ -142,6 +182,7 @@ public init()
        if (vaddrs) {
            coredump_getkerinfo();
        }
        if (vaddrs) {
            coredump_getkerinfo();
        }
+       getsrcpos();
        setcurfunc(whatblock(pc));
     } else {
        setcurfunc(program);
        setcurfunc(whatblock(pc));
     } else {
        setcurfunc(program);
@@ -192,7 +233,7 @@ String outfile;
     String tmpfile;
     extern String mktemp();
 
     String tmpfile;
     extern String mktemp();
 
-    tmpfile = mktemp("/tmp/dbxXXXX");
+    tmpfile = mktemp(_PATH_TMP);
     setout(tmpfile);
     status();
     alias(nil, nil, nil);
     setout(tmpfile);
     status();
     alias(nil, nil, nil);
@@ -258,14 +299,13 @@ private catchintr()
  * Scan the argument list.
  */
 
  * Scan the argument list.
  */
 
-private scanargs(argc, argv)
+private char **scanargs (argc, argv)
 int argc;
 String argv[];
 {
 int argc;
 String argv[];
 {
-    register int i, j;
-    register Boolean foundfile;
-    register File f;
-    char *tmp;
+    extern char *optarg;
+    extern integer optind;
+    integer ch;
 
     runfirst = false;
     interactive = false;
 
     runfirst = false;
     interactive = false;
@@ -275,48 +315,83 @@ String argv[];
     tracesyms = false;
     traceblocks = false;
     vaddrs = false;
     tracesyms = false;
     traceblocks = false;
     vaddrs = false;
-    foundfile = false;
+    quiet = false;
+    autostrip = true;
     corefile = nil;
     coredump = true;
     sourcepath = list_alloc();
     list_append(list_item("."), nil, sourcepath);
     corefile = nil;
     coredump = true;
     sourcepath = list_alloc();
     list_append(list_item("."), nil, sourcepath);
-    i = 1;
-    while (i < argc and (not foundfile or (coredump and corefile == nil))) {
-       if (argv[i][0] == '-') {
-           if (streq(argv[i], "-I")) {
-               ++i;
-               if (i >= argc) {
-                   fatal("missing directory for -I");
-               }
-               list_append(list_item(argv[i]), nil, sourcepath);
-           } else if (streq(argv[i], "-c")) {
-               ++i;
-               if (i >= argc) {
-                   fatal("missing command file name for -c");
-               }
-               initfile = argv[i];
-           } else {
-               for (j = 1; argv[i][j] != '\0'; j++) {
-                   setoption(argv[i][j]);
-               }
-           }
-       } else if (not foundfile) {
-           objname = argv[i];
-           foundfile = true;
-       } else if (coredump and corefile == nil) {
-           corefile = fopen(argv[i], "r");
-           corename = argv[i];
-           if (corefile == nil) {
+
+    while ((ch = getopt(argc, argv, "I:abc:eiklnqrs")) != EOF)
+    switch((char)ch) {
+       case 'I':
+               list_append(list_item(optarg), nil, sourcepath);
+               break;
+       case 'a':
+               autostrip = false;
+               break;
+       case 'b':
+               tracebpts = true;
+               break;
+       case 'c':
+               initfile = optarg;
+               break;
+       case 'e':
+               traceexec = true;
+               break;
+       case 'i':
+               interactive = true;
+               break;
+       case 'k':
+               vaddrs = true;
+               break;
+       case 'l':
+#ifdef LEXDEBUG
+               lexdebug = true;
+#else
+               fatal("\"-l\" only applicable when compiled with LEXDEBUG");
+#endif
+               break;
+       case 'n':
+               traceblocks = true;
+               break;
+       case 'q':
+               quiet = true;
+               break;
+       case 'r':       /* run program before accepting commands */
+               runfirst = true;
                coredump = false;
                coredump = false;
-           }
+               break;
+       case 's':
+               tracesyms = true;
+               break;
+       case '?':
+       default:
+               fatal("unknown option");
+    }
+    argv += optind;
+    if (*argv) {
+       objname = *argv;
+       if (*++argv && coredump) {
+               corename = *argv;
+               corefile = fopen(*argv, "r");
+               if (corefile == nil)
+                       coredump = false;
+               ++argv;
        }
        }
-       ++i;
     }
     }
-    if (i < argc and not runfirst) {
-       fatal("extraneous argument %s", argv[i]);
+    if (*argv and not runfirst) {
+       fatal("extraneous argument %s", *argv);
     }
     }
-    firstarg = i;
-    if (not foundfile and isatty(0)) {
+    return argv;
+}
+
+private openfiles ()
+{
+    File f;
+    char *tmp;
+
+    if (objname == nil and isatty(0)) {
        printf("enter object file name (default is `%s'): ", objname);
        fflush(stdout);
        gets(namebuf);
        printf("enter object file name (default is `%s'): ", objname);
        fflush(stdout);
        gets(namebuf);
@@ -337,14 +412,14 @@ String argv[];
     }
     if (coredump and corefile == nil) {
        if (vaddrs) {
     }
     if (coredump and corefile == nil) {
        if (vaddrs) {
-           corefile = fopen("/dev/mem", "r");
-           corename = "/dev/mem";
+           corename = _PATH_MEM;
+           corefile = fopen(corename, "r");
            if (corefile == nil) {
            if (corefile == nil) {
-               panic("can't open /dev/mem");
+               panic("can't open %s", _PATH_MEM);
            }
        } else {
            }
        } else {
-           corefile = fopen("core", "r");
            corename = "core";
            corename = "core";
+           corefile = fopen(corename, "r");
            if (corefile == nil) {
                coredump = false;
            }
            if (corefile == nil) {
                coredump = false;
            }
@@ -352,56 +427,6 @@ String argv[];
     }
 }
 
     }
 }
 
-/*
- * Take appropriate action for recognized command argument.
- */
-
-private setoption(c)
-char c;
-{
-    switch (c) {
-       case 'r':   /* run program before accepting commands */
-           runfirst = true;
-           coredump = false;
-           break;
-
-       case 'i':
-           interactive = true;
-           break;
-
-       case 'b':
-           tracebpts = true;
-           break;
-
-       case 'e':
-           traceexec = true;
-           break;
-
-       case 's':
-           tracesyms = true;
-           break;
-
-       case 'n':
-           traceblocks = true;
-           break;
-
-       case 'k':
-           vaddrs = true;
-           break;
-
-       case 'l':
-#          ifdef LEXDEBUG
-               lexdebug = true;
-#          else
-               fatal("\"-l\" only applicable when compiled with LEXDEBUG");
-#          endif
-           break;
-
-       default:
-           fatal("unknown option '%c'", c);
-    }
-}
-
 /*
  * Save/restore the state of a tty.
  */
 /*
  * Save/restore the state of a tty.
  */
@@ -410,24 +435,40 @@ public savetty(f, t)
 File f;
 Ttyinfo *t;
 {
 File f;
 Ttyinfo *t;
 {
-    ioctl(fileno(f), TIOCGETP, &(t->sg));
-    ioctl(fileno(f), TIOCGETC, &(t->tc));
-    ioctl(fileno(f), TIOCGLTC, &(t->ltc));
-    ioctl(fileno(f), TIOCGETD, &(t->ldisc));
-    ioctl(fileno(f), TIOCLGET, &(t->local));
-    t->fcflags = fcntl(fileno(f), F_GETFL, 0);
+#   ifdef IRIS
+       ioctl(fileno(f), TCGETA, t);
+#   else
+       ioctl(fileno(f), TIOCGETP, &(t->sg));
+       ioctl(fileno(f), TIOCGETC, &(t->tc));
+       ioctl(fileno(f), TIOCGLTC, &(t->ltc));
+       ioctl(fileno(f), TIOCGETD, &(t->ldisc));
+       ioctl(fileno(f), TIOCLGET, &(t->local));
+       t->fcflags = fcntl(fileno(f), F_GETFL, 0);
+       if ((t->fcflags&FASYNC) != 0) {
+           /* fprintf(stderr, "[async i/o found set -- reset]\n"); */
+           t->fcflags &= ~FASYNC;
+       }
+#   endif
 }
 
 public restoretty(f, t)
 File f;
 Ttyinfo *t;
 {
 }
 
 public restoretty(f, t)
 File f;
 Ttyinfo *t;
 {
-    ioctl(fileno(f), TIOCSETN, &(t->sg));
-    ioctl(fileno(f), TIOCSETC, &(t->tc));
-    ioctl(fileno(f), TIOCSLTC, &(t->ltc));
-    ioctl(fileno(f), TIOCSETD, &(t->ldisc));
-    ioctl(fileno(f), TIOCLSET, &(t->local));
-    (void) fcntl(fileno(f), F_SETFL, t->fcflags);
+#   ifdef IRIS
+       ioctl(fileno(f), TCSETA, t);
+#   else
+       ioctl(fileno(f), TIOCSETN, &(t->sg));
+       ioctl(fileno(f), TIOCSETC, &(t->tc));
+       ioctl(fileno(f), TIOCSLTC, &(t->ltc));
+       ioctl(fileno(f), TIOCSETD, &(t->ldisc));
+       ioctl(fileno(f), TIOCLSET, &(t->local));
+       if ((t->fcflags&FASYNC) != 0) {
+           /* fprintf(stderr, "[async i/o not set]\n"); */
+           t->fcflags &= ~FASYNC;
+       }
+       (void) fcntl(fileno(f), F_SETFL, t->fcflags);
+#   endif
 }
 
 /*
 }
 
 /*