aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/db
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-23 22:48:54 +0000
committerrsc <devnull@localhost>2005-01-23 22:48:54 +0000
commitb030a6c390428033300e4b6df2a97065059d7a48 (patch)
treeecc3b38b2535c9a17afac17c337d220c7e3c074c /src/cmd/db
parent4f2ac1b76b04df503944e86c2e7f152c2ff53f0e (diff)
downloadplan9port-b030a6c390428033300e4b6df2a97065059d7a48.tar.gz
plan9port-b030a6c390428033300e4b6df2a97065059d7a48.tar.bz2
plan9port-b030a6c390428033300e4b6df2a97065059d7a48.zip
change to use attach functions.
$a means switch thread in core dumps. (maybe that should be $A now?).
Diffstat (limited to 'src/cmd/db')
-rw-r--r--src/cmd/db/defs.h4
-rw-r--r--src/cmd/db/main.c90
-rw-r--r--src/cmd/db/mkfile2
-rw-r--r--src/cmd/db/print.c5
-rw-r--r--src/cmd/db/setup.c31
5 files changed, 35 insertions, 97 deletions
diff --git a/src/cmd/db/defs.h b/src/cmd/db/defs.h
index 02ef0854..63fde3ba 100644
--- a/src/cmd/db/defs.h
+++ b/src/cmd/db/defs.h
@@ -102,9 +102,7 @@ extern int nnote;
extern char note[NNOTE][ERRMAX];
extern int ending;
-extern Fhdr *corhdr, *symhdr;
-extern Map *cormap, *symmap, *dotmap;
-extern Regs *correg;
+extern Map *dotmap;
extern BKPT *bkpthead;
extern int kflag;
diff --git a/src/cmd/db/main.c b/src/cmd/db/main.c
index 8e574037..3fadcc32 100644
--- a/src/cmd/db/main.c
+++ b/src/cmd/db/main.c
@@ -24,8 +24,6 @@ extern char *Ipath;
jmp_buf env;
static char *errmsg;
-Fhdr *symhdr, *corhdr;
-
void
usage(void)
{
@@ -36,11 +34,11 @@ usage(void)
void
main(int argc, char **argv)
{
- int i, omode;
+ int omode, quiet;
char *s;
char *name;
- Fhdr *hdr;
+ quiet = 0;
name = 0;
outputinit();
maxoff = MAXOFF;
@@ -68,86 +66,12 @@ main(int argc, char **argv)
if(name == 0)
dprint("missing -m argument\n");
break;
+ case 'q':
+ quiet = 1;
+ break;
}ARGEND
- /*
- * 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);
- }
+ attachargs(argc, argv, omode, !quiet);
dotmap = dumbmap(-1);
@@ -159,7 +83,7 @@ main(int argc, char **argv)
if(setjmp(env) == 0){
if (pid || corhdr)
setcor(); /* could get error */
- if (correg) {
+ if (correg && !quiet) {
dprint("%s\n", mach->exc(cormap, correg));
printpc();
}
diff --git a/src/cmd/db/mkfile b/src/cmd/db/mkfile
index 00e7a753..9ed0c028 100644
--- a/src/cmd/db/mkfile
+++ b/src/cmd/db/mkfile
@@ -17,7 +17,7 @@ OFILES=\
HFILES=defs.h\
fns.h\
-
+ $PLAN9/include/mach.h\
<$PLAN9/src/mkone
diff --git a/src/cmd/db/print.c b/src/cmd/db/print.c
index 41eb98c6..05096a76 100644
--- a/src/cmd/db/print.c
+++ b/src/cmd/db/print.c
@@ -125,6 +125,11 @@ printdollar(int modif)
attachprocess();
break;
+/* maybe use this for lwpids?
+ case 'A':
+ attachpthread();
+ break;
+*/
case 'k':
kmsys();
break;
diff --git a/src/cmd/db/setup.c b/src/cmd/db/setup.c
index e2488b61..7fec6437 100644
--- a/src/cmd/db/setup.c
+++ b/src/cmd/db/setup.c
@@ -27,18 +27,29 @@ setsym(void)
void
setcor(void)
{
- unmapproc(cormap);
- unmapfile(corhdr, cormap);
- free(correg);
- correg = nil;
+ static int mapped;
- if (pid > 0) {
- if (mapproc(pid, cormap, &correg) < 0)
- dprint("mapproc %d: %r\n", pid);
- } else {
- if (corhdr) {
+ if (corhdr) {
+ if (!mapped) {
if (mapfile(corhdr, 0, cormap, &correg) < 0)
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
dprint("no core image\n");
}
@@ -137,7 +148,7 @@ void
attachprocess(void)
{
if (!adrflg) {
- dprint("used pid$a\n");
+ dprint("usage: pid$a\n");
return;
}
pid = adrval;