From: Nathaniel Wesley Filardo Date: Sat, 24 Oct 2015 04:34:33 +0000 (-0400) Subject: Make getcallerpcs size parametric X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=803d73842629a73b3770b486de12dacba5e8b571;p=xv6-public Make getcallerpcs size parametric --- diff --git a/console.c b/console.c index ed0b73b..c2319be 100644 --- a/console.c +++ b/console.c @@ -113,7 +113,7 @@ panic(char *s) cprintf("cpu%d: panic: ", cpu->id); cprintf(s); cprintf("\n"); - getcallerpcs(&s, pcs); + getcallerpcs(&s, NELEM(pcs), pcs); for(i=0; i<10; i++) cprintf(" %p", pcs[i]); panicked = 1; // freeze other CPU diff --git a/defs.h b/defs.h index 8c3568c..b0406df 100644 --- a/defs.h +++ b/defs.h @@ -127,7 +127,7 @@ void swtch(struct context**, struct context*); // spinlock.c void acquire(struct spinlock*); -void getcallerpcs(void*, uint*); +void getcallerpcs(void*, uint, uint*); int holding(struct spinlock*); void initlock(struct spinlock*, char*); void release(struct spinlock*); diff --git a/proc.c b/proc.c index f60d6dd..758ab6d 100644 --- a/proc.c +++ b/proc.c @@ -456,7 +456,7 @@ procdump(void) state = "???"; cprintf("%d %s %s", p->pid, state, p->name); if(p->state == SLEEPING){ - getcallerpcs((uint*)p->context->ebp+2, pc); + getcallerpcs((uint*)p->context->ebp+2, NELEM(pc), pc); for(i=0; i<10 && pc[i] != 0; i++) cprintf(" %p", pc[i]); } diff --git a/spinlock.c b/spinlock.c index a16621c..bcb5378 100644 --- a/spinlock.c +++ b/spinlock.c @@ -36,7 +36,7 @@ acquire(struct spinlock *lk) // Record info about lock acquisition for debugging. lk->cpu = cpu; - getcallerpcs(&lk, lk->pcs); + getcallerpcs(&lk, NELEM(lk->pcs), lk->pcs); } // Release the lock. @@ -65,19 +65,19 @@ release(struct spinlock *lk) // Record the current call stack in pcs[] by following the %ebp chain. void -getcallerpcs(void *v, uint pcs[]) +getcallerpcs(void *v, uint n, uint pcs[]) { uint *ebp; int i; ebp = (uint*)v - 2; - for(i = 0; i < 10; i++){ + for(i = 0; i < n; i++){ if(ebp == 0 || ebp < (uint*)KERNBASE || ebp == (uint*)0xffffffff) break; pcs[i] = ebp[1]; // saved %eip ebp = (uint*)ebp[0]; // saved %ebp } - for(; i < 10; i++) + for(; i < n; i++) pcs[i] = 0; }