任务2
cd pintos/src/threads
cd build
pintos --bochs --gdb -- run loader.S
换一个命令行
cd pintos/src/threads
cd build
pintos-gdb kernel.o
target remote localhost:1234
break *0x7c00
开始执行代码,直到断点处停止:
c
一旦程序停在断点处,你可以使用 x/i
命令来反汇编当前指令:
x/i $pc
连续查看3条
x/3i 0xffff0 + 1
练习4
cd pintos/src/threads
cd build
pintos --bochs --gdb -- run start.S
换一个命令行
pintos-gdb kernel.o
target remote localhost:1234
//打断点
break pintos_init
//运行
c
//查看init_page_dir[pd_no(ptov(0))]的值:
print/x init_page_dir[pd_no(ptov(0))]
break palloc_get_page
c
backtrace
print/x init_page_dir[pd_no(ptov(0))]
练习5
修改init.c
记得修改自己的学号姓名
if (*argv != NULL) run_actions(argv);
else{
// TODO: no command line passed to kernel. Run interactively;
console_init();
while (true){
char buffer[1024];
int index = 0;
printf("OS2021> ");
while (true){
char c = input_getc();
if (c == '\r' || c == '\n'){
buffer[index] = '\0';
if (strcmp(buffer, "msk") == 0)
printf("\nYour Name: [msk]\nYour ID: [202110120428]\n");
else if (strcmp(buffer, "exit") == 0)
shutdown_power_off();
else
printf("\nInvalid command\n");
memset(buffer, 0, sizeof(buffer));
index = 0;
break;
}
else if (c > ' ' && c < '~'){
printf("%c",c);
buffer[index++] = c;
}
}
}
}
每次修改完都要 make all 进行编译,形成 .o 文件
cd pintos/src/threads
cd build
make all
pintos --