Pass array length to getcallerpcs

上级 96068001
...@@ -182,7 +182,7 @@ kerneltrap(struct trapframe *tf) ...@@ -182,7 +182,7 @@ kerneltrap(struct trapframe *tf)
tf->trapno, mycpu()->id, tf->trapno, mycpu()->id,
tf->rip, tf->rsp, rcr2(), tf->rip, tf->rsp, rcr2(),
name, pid, kstack); name, pid, kstack);
getcallerpcs((void*)tf->rbp, pc); getcallerpcs((void*)tf->rbp, pc, NELEM(pc));
for (i = 0; i < NELEM(pc) && pc[i] != 0; i++) for (i = 0; i < NELEM(pc) && pc[i] != 0; i++)
__cprintf(" %p\n", pc[i]); __cprintf(" %p\n", pc[i]);
......
...@@ -299,7 +299,7 @@ void swtch(struct context**, struct context*); ...@@ -299,7 +299,7 @@ void swtch(struct context**, struct context*);
extern struct segdesc bootgdt[NSEGS]; extern struct segdesc bootgdt[NSEGS];
void pushcli(void); void pushcli(void);
void popcli(void); void popcli(void);
void getcallerpcs(void*, uptr*); void getcallerpcs(void*, uptr*, int);
// uart.c // uart.c
void uartputc(char c); void uartputc(char c);
......
...@@ -507,6 +507,7 @@ void *procdump(void *vk, void *v, void *arg) ...@@ -507,6 +507,7 @@ void *procdump(void *vk, void *v, void *arg)
struct proc *p = (struct proc *) v; struct proc *p = (struct proc *) v;
const char *name = "(no name)"; const char *name = "(no name)";
const char *state; const char *state;
uptr pc[10];
if(p->state >= 0 && p->state < NELEM(states) && states[p->state]) if(p->state >= 0 && p->state < NELEM(states) && states[p->state])
state = states[p->state]; state = states[p->state];
...@@ -518,9 +519,8 @@ void *procdump(void *vk, void *v, void *arg) ...@@ -518,9 +519,8 @@ void *procdump(void *vk, void *v, void *arg)
cprintf("\n%-3d %-10s %8s %2u %lu\n", p->pid, name, state, p->cpuid, p->tsc); cprintf("\n%-3d %-10s %8s %2u %lu\n", p->pid, name, state, p->cpuid, p->tsc);
uptr pc[10];
if(p->state == SLEEPING){ if(p->state == SLEEPING){
getcallerpcs((void*)p->context->rbp, pc); getcallerpcs((void*)p->context->rbp, pc, NELEM(pc));
for(int i=0; i<10 && pc[i] != 0; i++) for(int i=0; i<10 && pc[i] != 0; i++)
cprintf(" %lx\n", pc[i]); cprintf(" %lx\n", pc[i]);
} }
......
...@@ -40,7 +40,7 @@ tryacquire(struct spinlock *lk) ...@@ -40,7 +40,7 @@ tryacquire(struct spinlock *lk)
#if SPINLOCK_DEBUG #if SPINLOCK_DEBUG
// Record info about lock acquisition for debugging. // Record info about lock acquisition for debugging.
lk->cpu = mycpu(); lk->cpu = mycpu();
getcallerpcs(&lk, lk->pcs); getcallerpcs(&lk, lk->pcs, NELEM(lk->pcs));
#endif #endif
return 1; return 1;
} }
...@@ -72,7 +72,7 @@ acquire(struct spinlock *lk) ...@@ -72,7 +72,7 @@ acquire(struct spinlock *lk)
#if SPINLOCK_DEBUG #if SPINLOCK_DEBUG
// Record info about lock acquisition for debugging. // Record info about lock acquisition for debugging.
lk->cpu = mycpu(); lk->cpu = mycpu();
getcallerpcs(&lk, lk->pcs); getcallerpcs(&lk, lk->pcs, NELEM(lk->pcs));
#endif #endif
} }
......
...@@ -234,18 +234,18 @@ popcli(void) ...@@ -234,18 +234,18 @@ popcli(void)
// Record the current call stack in pcs[] by following the %rbp chain. // Record the current call stack in pcs[] by following the %rbp chain.
void void
getcallerpcs(void *v, uptr pcs[]) getcallerpcs(void *v, uptr pcs[], int n)
{ {
uptr *rbp; uptr *rbp;
int i; int i;
rbp = (uptr*)v; rbp = (uptr*)v;
for(i = 0; i < 10; i++){ for(i = 0; i < n; i++){
if(rbp == 0 || rbp < (uptr*)KBASE || rbp == (uptr*)(~0UL)) if(rbp == 0 || rbp < (uptr*)KBASE || rbp == (uptr*)(~0UL))
break; break;
pcs[i] = rbp[1]; // saved %rip pcs[i] = rbp[1]; // saved %rip
rbp = (uptr*)rbp[0]; // saved %rbp rbp = (uptr*)rbp[0]; // saved %rbp
} }
for(; i < 10; i++) for(; i < n; i++)
pcs[i] = 0; pcs[i] = 0;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论