Use a range-based for-loop in procdumpall

上级 ed955be3
...@@ -501,8 +501,11 @@ kill(int pid) ...@@ -501,8 +501,11 @@ kill(int pid)
return 0; return 0;
} }
bool // Print a process listing to console. For debugging.
procdump(u32 pid, proc *p) // Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
void
procdumpall(void)
{ {
static const char *states[] = { static const char *states[] = {
/* [UNUSED] = */ "unused", /* [UNUSED] = */ "unused",
...@@ -516,6 +519,7 @@ procdump(u32 pid, proc *p) ...@@ -516,6 +519,7 @@ procdump(u32 pid, proc *p)
const char *state; const char *state;
uptr pc[10]; uptr pc[10];
for (proc *p : xnspid) {
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];
else else
...@@ -524,24 +528,15 @@ procdump(u32 pid, proc *p) ...@@ -524,24 +528,15 @@ procdump(u32 pid, proc *p)
if (p->name && p->name[0] != 0) if (p->name && p->name[0] != 0)
name = p->name; name = p->name;
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);
if(p->state == SLEEPING){ if(p->state == SLEEPING){
getcallerpcs((void*)p->context->rbp, pc, NELEM(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]);
} }
}
return false;
}
// Print a process listing to console. For debugging.
// Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
void
procdumpall(void)
{
xnspid->enumerate(procdump);
} }
// Create a new process copying p as the parent. // Create a new process copying p as the parent.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论