* Copyright (c) 1983 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.7 (Berkeley) %G%";
#define isterm(file) (interactive or isatty(fileno(file)))
typedef struct termio Ttyinfo
;
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 */
public boolean coredump
; /* true if using a core dump */
public boolean runfirst
; /* run program immediately */
public boolean interactive
; /* standard input IS a terminal */
public boolean lexdebug
; /* trace scanner return values */
public boolean tracebpts
; /* trace create/delete breakpoints */
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 quiet
; /* don't print heading */
public boolean autostrip
; /* strip C++ prefixes */
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 */
private String corename
; /* name of core file */
private char **scanargs();
extern integer versionNumber
;
if (!(cmdname
= rindex(*argv
, '/')))
onsyserr(EADDRINUSE
, nil
);
argv
= scanargs(argc
, argv
);
if (not runfirst
and not quiet
) {
if (setjmp(env
) == FIRST_TIME
) {
if (setjmp(env
) != FIRST_TIME
) {
restoretty(stdout
, &ttyinfo
);
signal(SIGINT
, catchintr
);
printf("dbx version 3.%d of %s.\nType 'help' for help.\n",
* Initialize the world, including setting initial input file
savetty(stdout
, &ttyinfo
);
if (not coredump
and not runfirst
) {
printf("reading symbolic information ...");
printf("[using memory image in %s]\n", corename
);
setcurfunc(whatblock(pc
));
f
= fopen(initfile
, "r");
sprintf(buf
, "%s/%s", home
, initfile
);
* Re-initialize the world, first de-allocating all storage.
* This is necessary when the symbol information must be re-read
* from the object file when it has changed.
* Before "forgetting" things, we save the current tracing/breakpoint
* information to a temp file. Then after re-creating the world,
* we read the temp file as commands. This isn't always the right thing;
* if a procedure that was being traced is deleted, an error message
* If the argument vector is not nil, then this is re-initialize is being
* done in preparation for running the program. Since we want to process
* the commands in the temp file before running the program, we add the
* run command at the end of the temp file. In this case, reinit longjmps
* back to parsing rather than returning.
public reinit(argv
, infile
, outfile
)
tmpfile
= mktemp(_PATH_TMP
);
for (i
= 1; argv
[i
] != nil
; i
++) {
printf(" > %s", outfile
);
* After a non-fatal error we skip the rest of the current input line, and
* jump back to command parsing.
* This routine is called when an interrupt occurs.
* Scan the argument list.
private char **scanargs (argc
, argv
)
sourcepath
= list_alloc();
list_append(list_item("."), nil
, sourcepath
);
while ((ch
= getopt(argc
, argv
, "I:abc:eiklnqrs")) != EOF
)
list_append(list_item(optarg
), nil
, sourcepath
);
fatal("\"-l\" only applicable when compiled with LEXDEBUG");
case 'r': /* run program before accepting commands */
if (*++argv
&& coredump
) {
corefile
= fopen(*argv
, "r");
if (*argv
and not runfirst
) {
fatal("extraneous argument %s", *argv
);
if (objname
== nil
and isatty(0)) {
printf("enter object file name (default is `%s'): ", objname
);
if (namebuf
[0] != '\0') {
fatal("can't read %s", objname
);
if (rindex(objname
, '/') != nil
) {
*(rindex(tmp
, '/')) = '\0';
list_append(list_item(tmp
), nil
, sourcepath
);
if (coredump
and corefile
== nil
) {
corefile
= fopen(corename
, "r");
panic("can't open %s", _PATH_MEM
);
corefile
= fopen(corename
, "r");
* Save/restore the state of a tty.
ioctl(fileno(f
), TCGETA
, 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);
if ((t
->fcflags
&FASYNC
) != 0) {
/* fprintf(stderr, "[async i/o found set -- reset]\n"); */
ioctl(fileno(f
), TCSETA
, 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
));
if ((t
->fcflags
&FASYNC
) != 0) {
/* fprintf(stderr, "[async i/o not set]\n"); */
(void) fcntl(fileno(f
), F_SETFL
, t
->fcflags
);