int dwarfunwind(Dwarf *d, ulong pc, DwarfExpr *cfa, DwarfExpr *ra, DwarfExpr *r, int nr) { int i, ret; DwarfBuf fde, b; DwarfExpr *initr; State s; initr = mallocz(nr*sizeof(initr[0]), 1); if(initr == 0) return -1; memset(&s, 0, sizeof s); s.loc = 0; s.cfa = cfa; s.ra = ra; s.r = r; s.nr = nr; if(findfde(d, pc, &s, &fde) < 0){ free(initr); return -1; } memset(r, 0, nr*sizeof(r[0])); for(i=0; i<nr; i++) r[i].type = RuleSame; if(trace) werrstr("s.init %p-%p, fde %p-%p\n", s.init.p, s.init.ep, fde.p, fde.ep); b = s.init; if(dexec(&b, &s, 0) < 0) goto err; s.initr = initr; memmove(initr, r, nr*sizeof(initr[0])); if(trace) werrstr("s.loc 0x%lux pc 0x%lux\n", s.loc, pc); while(s.loc < pc){ if(trace) werrstr("s.loc 0x%lux pc 0x%lux\n", s.loc, pc); if(dexec(&fde, &s, 1) < 0) goto err; } *ra = s.r[s.rareg]; ret = 0; goto out; err: ret = -1; out: free(initr); for(i=0; i<s.nstack; i++) free(s.stack[i]); free(s.stack); return ret; }
int main(int argc, char *argv[]) { int i; common_options(&argc, &argv); if (argc < 3) { die_usage("missing requried parameters!"); } char *message = ARGV_SHIFT; char *failmsg = ARGV_SHIFT; if (strlen(failmsg) < 1) { failmsg = message; } return dexec(message, failmsg, argc, argv);; }