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,32 +519,24 @@ procdump(u32 pid, proc *p) ...@@ -516,32 +519,24 @@ procdump(u32 pid, proc *p)
const char *state; const char *state;
uptr pc[10]; uptr pc[10];
if(p->state >= 0 && p->state < NELEM(states) && states[p->state]) for (proc *p : xnspid) {
state = states[p->state]; if(p->state >= 0 && p->state < NELEM(states) && states[p->state])
else state = states[p->state];
state = "???"; else
state = "???";
if (p->name && p->name[0] != 0)
name = p->name; if (p->name && p->name[0] != 0)
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",
if(p->state == SLEEPING){ p->pid, name, state, p->cpuid, p->tsc);
getcallerpcs((void*)p->context->rbp, pc, NELEM(pc));
for(int i=0; i<10 && pc[i] != 0; i++) if(p->state == SLEEPING){
cprintf(" %lx\n", pc[i]); getcallerpcs((void*)p->context->rbp, pc, NELEM(pc));
for(int i=0; i<10 && pc[i] != 0; 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论