通过函数指针定义,调用时加上参数
struct Command {
const char *name;
const char *desc;
// return -1 to force monitor to exit
int (*func)(int argc, char** argv, struct Trapframe* tf);
};
static struct Command commands[] = {
{ "help", "Display this list of commands", mon_help },
{ "kerninfo", "Display information about the kernel", mon_kerninfo },
{ "backtrace", "Display the current stack trace", mon_backtrace },
};
if (strcmp(argv[0], commands[i].name) == 0)
return commands[i].func(argc, argv, tf);