mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
add core cmd
This commit is contained in:
parent
170d47ee1f
commit
20173464d2
4 changed files with 65 additions and 0 deletions
|
@ -259,6 +259,7 @@ struct Fhdr
|
|||
void *dwarf; /* handle to dwarf image */
|
||||
void *macho; /* handle to mach-o image */
|
||||
struct Stab stabs;
|
||||
char *cmd; /* command-line that produced core */
|
||||
|
||||
/* private */
|
||||
Symbol *sym; /* cached list of symbols */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Reference in a new issue