Support setting sysctls from the debugger

This commit is contained in:
Ali Mashtizadeh 2015-11-13 14:43:29 -08:00
parent 069e7b44b7
commit ae809dd23a

View File

@ -71,6 +71,11 @@ Debug_SysCtl(int argc, const char *argv[])
return;
}
if (argc != 2 && argc != 3) {
kprintf("Usage: sysctl NODE [VALUE]\n");
return;
}
i = SysCtl_Lookup(argv[1]);
if (i == -1) {
kprintf("Unknown sysctl node!\n");
@ -98,6 +103,37 @@ Debug_SysCtl(int argc, const char *argv[])
return;
}
if (argc == 3) {
if (SYSCTLTable[i].flags == SYSCTL_FLAG_RO) {
kprintf("Sysctl node is read-only!\n");
return;
}
switch (SYSCTLTable[i].type) {
case SYSCTL_TYPE_STR: {
SysCtlString *val = (SysCtlString *)SYSCTLTable[i].node;
strncpy(&val->value[0], argv[2], SYSCTL_STR_MAXLENGTH);
break;
}
case SYSCTL_TYPE_INT: {
SysCtlInt *val = (SysCtlInt *)SYSCTLTable[i].node;
val->value = Debug_StrToInt(argv[2]);
break;
}
case SYSCTL_TYPE_BOOL: {
SysCtlBool *val = (SysCtlBool *)SYSCTLTable[i].node;
if (strcmp(argv[2], "0") == 0) {
val->value = false;
} else if (strcmp(argv[2], "1") == 0) {
val->value = true;
} else {
kprintf("Invalid value!\n");
}
break;
}
}
}
}
REGISTER_DBGCMD(sysctl, "SYSCTL", Debug_SysCtl);