change to use attach functions.

$a means switch thread in core dumps.
(maybe that should be $A now?).
This commit is contained in:
rsc 2005-01-23 22:48:54 +00:00
parent 4f2ac1b76b
commit b030a6c390
5 changed files with 35 additions and 97 deletions

View file

@ -102,9 +102,7 @@ extern int nnote;
extern char note[NNOTE][ERRMAX]; extern char note[NNOTE][ERRMAX];
extern int ending; extern int ending;
extern Fhdr *corhdr, *symhdr; extern Map *dotmap;
extern Map *cormap, *symmap, *dotmap;
extern Regs *correg;
extern BKPT *bkpthead; extern BKPT *bkpthead;
extern int kflag; extern int kflag;

View file

@ -24,8 +24,6 @@ extern char *Ipath;
jmp_buf env; jmp_buf env;
static char *errmsg; static char *errmsg;
Fhdr *symhdr, *corhdr;
void void
usage(void) usage(void)
{ {
@ -36,11 +34,11 @@ usage(void)
void void
main(int argc, char **argv) main(int argc, char **argv)
{ {
int i, omode; int omode, quiet;
char *s; char *s;
char *name; char *name;
Fhdr *hdr;
quiet = 0;
name = 0; name = 0;
outputinit(); outputinit();
maxoff = MAXOFF; maxoff = MAXOFF;
@ -68,86 +66,12 @@ main(int argc, char **argv)
if(name == 0) if(name == 0)
dprint("missing -m argument\n"); dprint("missing -m argument\n");
break; break;
case 'q':
quiet = 1;
break;
}ARGEND }ARGEND
/* attachargs(argc, argv, omode, !quiet);
* Unix and Plan 9 differ on what the right order of pid, text, and core is.
* I never remember anyway. Let's just accept them in any order.
*/
for(i=0; i<argc; i++){
if(alldigs(argv[i])){
if(pid){
dprint("already have pid %d; ignoring pid %d\n", pid, argv[i]);
continue;
}
if(corhdr){
dprint("already have core %s; ignoring pid %d\n", corfil, pid);
continue;
}
pid = atoi(argv[i]);
continue;
}
if((hdr = crackhdr(argv[i], omode)) == nil){
dprint("crackhdr %s: %r\n", argv[i]);
continue;
}
dprint("%s: %s %s %s\n", argv[i], hdr->aname, hdr->mname, hdr->fname);
if(hdr->ftype == FCORE){
if(pid){
dprint("already have pid %d; ignoring core %s\n", pid, argv[i]);
uncrackhdr(hdr);
continue;
}
if(corhdr){
dprint("already have core %s; ignoring core %s\n", corfil, argv[i]);
uncrackhdr(hdr);
continue;
}
corhdr = hdr;
corfil = argv[i];
}else{
if(symhdr){
dprint("already have text %s; ignoring text %s\n", symfil, argv[i]);
uncrackhdr(hdr);
continue;
}
symhdr = hdr;
symfil = argv[i];
}
}
if(symhdr==nil){
symfil = "a.out";
if(pid){
if((s = proctextfile(pid)) != nil){
dprint("pid %d: text %s\n", pid, s);
symfil = s;
}
}
/* XXX pull command from core */
if((symhdr = crackhdr(symfil, omode)) == nil){
dprint("crackhdr %s: %r\n", symfil);
symfil = nil;
}
}
if(!mach)
mach = machcpu;
/*
* Set up maps.
*/
symmap = allocmap();
cormap = allocmap();
if(symmap == nil || cormap == nil)
sysfatal("allocating maps: %r");
if(symhdr){
if(mapfile(symhdr, 0, symmap, nil) < 0)
dprint("mapping %s: %r\n", symfil);
mapfile(symhdr, 0, cormap, nil);
}
dotmap = dumbmap(-1); dotmap = dumbmap(-1);
@ -159,7 +83,7 @@ main(int argc, char **argv)
if(setjmp(env) == 0){ if(setjmp(env) == 0){
if (pid || corhdr) if (pid || corhdr)
setcor(); /* could get error */ setcor(); /* could get error */
if (correg) { if (correg && !quiet) {
dprint("%s\n", mach->exc(cormap, correg)); dprint("%s\n", mach->exc(cormap, correg));
printpc(); printpc();
} }

View file

@ -17,7 +17,7 @@ OFILES=\
HFILES=defs.h\ HFILES=defs.h\
fns.h\ fns.h\
$PLAN9/include/mach.h\
<$PLAN9/src/mkone <$PLAN9/src/mkone

View file

@ -125,6 +125,11 @@ printdollar(int modif)
attachprocess(); attachprocess();
break; break;
/* maybe use this for lwpids?
case 'A':
attachpthread();
break;
*/
case 'k': case 'k':
kmsys(); kmsys();
break; break;

View file

@ -27,18 +27,29 @@ setsym(void)
void void
setcor(void) setcor(void)
{ {
unmapproc(cormap); static int mapped;
unmapfile(corhdr, cormap);
free(correg);
correg = nil;
if (pid > 0) { if (corhdr) {
if (mapproc(pid, cormap, &correg) < 0) if (!mapped) {
dprint("mapproc %d: %r\n", pid);
} else {
if (corhdr) {
if (mapfile(corhdr, 0, cormap, &correg) < 0) if (mapfile(corhdr, 0, cormap, &correg) < 0)
dprint("mapfile %s: %r\n", corfil); dprint("mapfile %s: %r\n", corfil);
mapped = 1;
}
free(correg);
if (pid == 0 && corhdr->nthread > 0)
pid = corhdr->thread[0].id;
correg = coreregs(corhdr, pid);
if(correg == nil)
dprint("no such pid in core dump\n");
} else {
unmapproc(cormap);
unmapfile(corhdr, cormap);
free(correg);
correg = nil;
if (pid > 0) {
if (mapproc(pid, cormap, &correg) < 0)
dprint("mapproc %d: %r\n", pid);
} else } else
dprint("no core image\n"); dprint("no core image\n");
} }
@ -137,7 +148,7 @@ void
attachprocess(void) attachprocess(void)
{ {
if (!adrflg) { if (!adrflg) {
dprint("used pid$a\n"); dprint("usage: pid$a\n");
return; return;
} }
pid = adrval; pid = adrval;