8000 minix/commands/mdb/mdb.c at R3.1.0 · ygx2011/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1028 lines (953 loc) · 22.4 KB

mdb.c

File metadata and controls

1028 lines (953 loc) · 22.4 KB
case 'v': /* toggle debug */
debug = !debug;
if (debug) Printf("Debug flag ON\n");
break;
#endif
case 'e': /* list symbols */
listsym(cmd);
break;
case 'y': /* print mapping */
prtmap();
break;
case '?': /* print help */
help_page();
break;
case 'V': /* print version info */
version_info();
break;
case '@': /* command file */
cmd = skip(cmd);
openin(cmd);
*cmd = '\n';
return;
case '#': /* set register or variable */
cmd = skip(cmd + 1);
if (*cmd == '$') {
cmd++;
i = reg_addr(cmd);
set_reg(curpid, i, strtol(cmd+2, &cmd, 0) );
update();
break;
}
cmd = getexp(cmd, &exp, &seg);
fill(exp, T_GETDATA);
break;
default:
help_page();
break;
}
while (*cmd != '\n' && *cmd != ';') ++cmd;
if (*cmd == ';') cmd = skip(cmd + 1);
}
PUBLIC void mdb_error(s)
char *s;
{
Printf("%s",s);
longjmp(mainlp, 0);
}
PUBLIC void main(argc, argv)
int argc;
char *argv[];
{
int i, c;
char *p, *q, *r;
int opt_c = FALSE; /* load core file */
int opt_f = FALSE; /* load object file */
int opt_l = FALSE; /* log to file */
int opt_L = FALSE; /* log to file and screen */
prc = (struct proc *) lbuf;
strcpy(sbuf, "\n");
corepid = -1; /* set to indicate none */
prog = p = q = r = NULL;
if ( argc == 1 )
{
help_page();
exit(0);
}
/* Possible combinations of arguments:
* A single file name:
* If the name is 'core', the coreonly flag is set.
* The -c flag: examine a core file.
* One filename is required with this flag.
* The -f flag: examine an object file.
* One file name is required with this flag.
* The -L or -l flag: write to a log file.
* One file name is required with these flags.
* The -x flag: turn on debugging.
* Used for debugging, and followed by an integer
* argument which is the debugging level.
*
* If any files remain on the argument list, the first
* file is an executable, and the second a core file.
* If any filename starts with '@' it is assumed to
* to be a command file. Only one command file is
* loaded.
*/
/* check for default file name and fake out getopt */
if (strcmp(argv[1], "core") == 0) {
for (i = argc ; i > 1 ; i--)
argv[i] = argv[i - 1];
argv[i] = "-c";
argc++;
}
/* parse options */
opterr = 0;
while ((i = getopt(argc, argv, "c:f:L:l:x:")) != EOF) {
switch (i & 0377) {
case 'c': /* examine a core file */
if (opt_c == TRUE || opt_f == TRUE) {
help_page();
exit(1);
}
p = optarg;
opt_c = TRUE;
break;
case 'f': /* examine an object file */
if (opt_c == TRUE || opt_f == TRUE) {
help_page();
exit(1);
}
p = optarg;
opt_f = TRUE;
break;
case 'l': /* start logging */
if (opt_l == TRUE || opt_L == TRUE) {
help_page();
exit(1);
}
opt_l = TRUE;
logging(i, optarg);
break;
case 'L': /* start logging */
if (opt_l == TRUE || opt_L == TRUE) {
help_page();
exit(1);
}
opt_L = TRUE;
logging(i, optarg);
break;
#ifdef DEBUG
case 'x': /* set debug level */
debug = atoi(optarg);
break;
#endif
case '?': /* default arguments arrive here */
default:
help_page();
exit(1);
}
}
/* can't cope without filenames */
if (!opt_c && !opt_f && optind >= argc) {
help_page();
exit(1);
}
/* any remaining arguments are (optional) file names */
for (i = optind ; i < argc ; i++) {
if (*argv[i] == '@') { /* command file */
if (r == NULL) r = argv[i] + 1;
}
/* you can't combine a -c or -f object file and a core file */
else if (!opt_c && !opt_f && p == NULL) p = argv[i];
else if (q == NULL) q = argv[i]; /* core file */
}
/* initialise stuff - fairly tricky logic */
coreonly = opt_c;
fileonly = opt_f;
/* when examining files, prog == NULL */
if (!opt_c && !opt_f) {
prog = p;
syminit(prog);
}
/* file_init is called for non-core files.
* It is very similar to core_init. It opens the file and set
* various pointers so that we can read it using the same routines
* as a core file.
* NB: Currently there is no special provision to handle object files.
*/
/* A comment from Will Rose:
* It would be nice to have
* symbol tables available when reading a core
* or a.out, either as part of the executable or
* as a separate file.
0