diff options
author | rsc <devnull@localhost> | 2005-01-18 20:26:26 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-01-18 20:26:26 +0000 |
commit | 20173464d2169892bde1a91bbfd1c2a811a79ace (patch) | |
tree | 34fa5370e0a961affdc8ce8f7bd677572e736848 /src/libmach | |
parent | 170d47ee1fe2e59a37344025de696bc0d57989bb (diff) | |
download | plan9port-20173464d2169892bde1a91bbfd1c2a811a79ace.tar.gz plan9port-20173464d2169892bde1a91bbfd1c2a811a79ace.tar.bz2 plan9port-20173464d2169892bde1a91bbfd1c2a811a79ace.zip |
add core cmd
Diffstat (limited to 'src/libmach')
-rw-r--r-- | src/libmach/cmdline.c | 1 | ||||
-rw-r--r-- | src/libmach/crackelf.c | 62 | ||||
-rw-r--r-- | src/libmach/elf.h | 1 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/libmach/cmdline.c b/src/libmach/cmdline.c index d06f139e..4da38d9e 100644 --- a/src/libmach/cmdline.c +++ b/src/libmach/cmdline.c @@ -58,6 +58,7 @@ attachargs(int argc, char **argv, int omode) } fprint(2, "%s: %s %s %s\n", argv[i], hdr->aname, hdr->mname, hdr->fname); if(hdr->ftype == FCORE){ + fprint(2, "core cmd: %s\n", hdr->cmd); if(corpid){ fprint(2, "already have corpid %d; ignoring core %s\n", corpid, argv[i]); uncrackhdr(hdr); diff --git a/src/libmach/crackelf.c b/src/libmach/crackelf.c index f0f84230..6ed3ee51 100644 --- a/src/libmach/crackelf.c +++ b/src/libmach/crackelf.c @@ -6,6 +6,7 @@ static int mapelf(Fhdr *fp, ulong base, Map *map, Regs**); static int mapcoreregs(Fhdr *fp, Map *map, Regs**); +static char *getcorecmd(Fhdr *fp, Map *map); static struct { @@ -137,6 +138,7 @@ crackelf(int fd, Fhdr *fp) || ctab[i].mtype != fp->mtype) continue; elf->coreregs = ctab[i].coreregs; + elf->corecmd = ctab[i].corecmd; break; } return 0; @@ -257,6 +259,8 @@ mapelf(Fhdr *fp, ulong base, Map *map, Regs **regs) if(fp->ftype == FCORE){ if(mapcoreregs(fp, map, regs) < 0) fprint(2, "warning: reading core regs: %r"); + if((fp->cmd = getcorecmd(fp, map)) == nil) + fprint(2, "warning: reading core command: %r"); } return 0; @@ -347,3 +351,61 @@ mapcoreregs(Fhdr *fp, Map *map, Regs **rp) return -1; } +static char* +getcorecmd(Fhdr *fp, Map *map) +{ + int i; + uchar *a, *sa, *ea; + char *cmd; + uint n; + ElfNote note; + ElfProg *p; + Elf *elf; + + elf = fp->elf; + if(elf->corecmd == 0){ + werrstr("cannot parse %s %s cores", fp->mname, fp->aname); + return nil; + } + + for(i=0; i<elf->nprog; i++){ + p = &elf->prog[i]; + if(p->type != ElfProgNote) + continue; + n = p->filesz; + a = malloc(n); + if(a == nil) + return nil; + if(seek(fp->fd, p->offset, 0) < 0 || readn(fp->fd, a, n) != n){ + free(a); + continue; + } + sa = a; + ea = a+n; + while(a < ea){ + note.offset = (a-sa) + p->offset; + if(unpacknote(elf, a, ea, ¬e, &a) < 0) + break; + switch(note.type){ + case ElfNotePrPsinfo: + if((n = elf->corecmd(elf, ¬e, &cmd)) < 0){ + free(sa); + return nil; + } + free(sa); + return cmd; + case ElfNotePrStatus: + case ElfNotePrFpreg: + case ElfNotePrTaskstruct: + case ElfNotePrAuxv: + case ElfNotePrXfpreg: + break; + } + // fprint(2, "0x%lux note %s/%lud %p\n", note.offset, note.name, note.type, note.desc); + } + free(sa); + } + fprint(2, "could not find registers in core file\n"); + return nil; +} + diff --git a/src/libmach/elf.h b/src/libmach/elf.h index 02fb5851..6b65cfc8 100644 --- a/src/libmach/elf.h +++ b/src/libmach/elf.h @@ -221,6 +221,7 @@ struct Elf ulong dynamic; /* offset to elf dynamic crap */ int (*coreregs)(Elf*, ElfNote*, uchar**); + int (*corecmd)(Elf*, ElfNote*, char**); }; Elf* elfopen(char*); |