Pass array length to getcallerpcs

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