static char sccsid
[] = "@(#)main.c 5.1 (Berkeley) %G%";
* adb - main command loop and error/interrupt handling
extern char NOEOR
[]; /* "newline expected" */
* executing is set by command.c whenever we are running a subprocess.
char *Ipath
= "/usr/lib/adb";/* XXX */
static int xargc
; /* remembers argc for getfile() */
static int reading
; /* set whenever reading input */
static jmp_buf mainloop
; /* label for error jumps */
radix
= 16; /* default radix is hex */
* Set up machine dependent code (e.g., instruction decoding tables),
* then look at arguments, and open the object and core files;
* finally, set up signal handlers. Alas, cannot really use getopt.
while (argc
> 1 && argv
[1][0] == '-') {
register char *p
= argv
[1] + 1;
if (*p
== 'w' && p
[1] == 0) {
wtflag
= 2; /* suitable for open() */
} else if (*p
== 'k' && p
[1] == 0) {
xargc
= argc
; /* remember for getfile() */
if ((sigint
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
) {
(void) signal(SIGINT
, fault
);
sigquit
= signal(SIGQUIT
, SIG_IGN
);
* Errors jump back to the main loop here.
* If the error occurred while the process was running,
* we need to remove any breakpoints.
* flush pending output, and print any error message(s);
* read a line; if end of file, close current input and
* continue, unless input == stdin; otherwise, perform
* the command(s) on the line and make sure that that
* consumed the whole line.
adbprintf("%s\n", errflag
);
if (readline(line
, sizeof line
)) {
if (/* lp && */ lastc
!= '\n')
* Exit with optional error status.
* Open the a.out (1) or core (2) file. If the name was given,
* rather than defaulted, and we were asked to open for writing,
* create the file if necessary.
if (fname
[0] == '-' && fname
[1] == 0)
if ((flags
= wtflag
) != 0 && xargc
> which
)
if ((fd
= open(fname
, flags
, 0666)) < 0 && flags
& O_CREAT
)
adbprintf("cannot open `%s'\n", fname
);
* Read a character, skipping white space.
while (*lp
== ' ' || *lp
== '\t')
* Read a character, incrementing the pointer if not at end.
* Read a line. Return -1 at end of file.
* Alas, cannot read more than one character at a time here (except
* possibly on tty devices; must think about that later).
if (read(infile
, p
, 1) != 1)
*p
= 0; /* can we perhaps eliminate this? */
* Return the next non-white non-end-of-line character.
* If there has been an error or a fault, take the error.
* An error occurred. Save the message for later printing,
* close open files, and reset to main command loop.
* An interrupt occurred. Seek to the end of the current input file.
* If we were reading commands, jump back to the main loop.
/* (void) signal(sig, fault); */ /* unnecessary */
(void) lseek(infile
, 0L, 2);
* Panic announces an internally detected error.
static char p
[] = "panic: \n";
static struct iovec iov
[3] = { { p
, 7 }, { 0 }, { p
+ 7, 1 } };
iov
[1].iov_len
= strlen(s
);
(void) writev(2, iov
, 3);
abort(); /* beware, overwrites current core file! */