/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)main.c 1.7 (Berkeley) %G%";
#define isterm(file) (interactive or isatty(fileno(file)))
typedef struct sgttyb Ttyinfo
;
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 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 traceblocks
; /* trace blocks while reading symbols */
public File corefile
; /* File id of core dump */
#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) */
extern integer versionNumber
;
printf("dbx version %d of %s.\nType 'help' for help.\n",
if (setjmp(env
) == FIRST_TIME
) {
for (i
= firstarg
; i
< argc
; i
++) {
if (setjmp(env
) != FIRST_TIME
) {
restoretty(stdout
, &ttyinfo
);
signal(SIGINT
, catchintr
);
* Initialize the world, including setting initial input file
savetty(stdout
, &ttyinfo
);
if (not coredump
and not runfirst
) {
printf("reading symbolic information ...");
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("/tmp/dbxXXXX");
for (i
= 1; argv
[i
] != nil
; i
++) {
printf(" > %s", outfile
);
* After a non-fatal error we jump back to command parsing.
* This routine is called when an interrupt occurs.
* Scan the argument list.
private scanargs(argc
, argv
)
register Boolean foundfile
;
sourcepath
= list_alloc();
list_append(list_item("."), nil
, sourcepath
);
while (i
< argc
and (not foundfile
or corefile
== nil
)) {
if (streq(argv
[i
], "-I")) {
fatal("missing directory for -I");
list_append(list_item(argv
[i
]), nil
, sourcepath
);
for (j
= 1; argv
[i
][j
] != '\0'; j
++) {
} else if (not foundfile
) {
} else if (coredump
and corefile
== nil
) {
corefile
= fopen(argv
[i
], "r");
if (i
< argc
and not runfirst
) {
fatal("extraneous argument %s", argv
[i
]);
if (not foundfile
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("core", "r");
* Take appropriate action for recognized command argument.
case 'r': /* run program before accepting commands */
fatal("\"-l\" only applicable when compiled with LEXDEBUG");
fatal("unknown option '%c'", c
);
* Save/restore the state of a tty.