🐳
uCore OS(on RISC-V64)实验指导书
  • Introduction
  • LAB0:ready~go!
    • 实验目的
    • 实验内容
    • 前导知识
      • 了解uCore
      • 了解RISC-V
      • 了解OS实验
      • 了解实验环境
      • 了解开发调试基本工具
      • 了解硬件模拟器
    • 配置环境
      • 安装虚拟环境
      • 安装开发工具
      • 安装硬件模拟器
      • 安装调试工具
  • LAB0.5:最小可执行内核
    • 实验目的
    • 实验内容
    • 练习
    • 内存布局
    • 链接脚本
    • 真正的入口点
    • 从SBI到stdio
    • 编译运行
    • 项目组成与执行流
  • LAB1:中断机制
    • 实验目的
    • 实验内容
    • 练习
    • RISC-V中断相关
    • 上下文处理
    • 中断处理程序
    • 时钟中断
    • 项目组成与执行流
  • LAB2:物理内存管理
    • 实验目的
    • 实验内容
    • 练习
    • 地址与页表
    • 物理内存探测
    • 以页为单位管理物理内存
    • 页面分配算法
    • 项目组成与执行流
  • LAB3:虚拟内存管理
    • 实验目的
    • 实验内容
    • 练习
    • 页面置换
    • PageFault
    • 使用多级页表
    • 页面置换机制
    • FIFO置换算法
    • 项目组成与执行流
  • LAB4:进程管理
    • 实验目的
    • 实验内容
    • 练习
    • 进程与线程
    • 相关结构体
    • 进程模块初始化
    • 进程切换
    • 项目组成与执行流
  • LAB5:用户程序
    • 实验目的
    • 实验内容
    • 练习
    • 用户进程
    • 用户程序
    • 创建并执行用户进程
    • 系统调用
    • 用户进程的退出和等待
    • 项目组成与执行流
  • LAB6:进程调度
    • 实验目的
    • 实验内容
    • 练习
    • 进程状态
    • 再次认识进程切换
    • 调度算法框架
    • 项目组成与执行流
  • LAB7:同步互斥
    • 实验目的
    • 实验内容
    • 练习
    • 同步互斥的基本概念
    • 信号量
    • 条件变量与管程
    • 项目组成与执行流
  • LAB8:文件系统
    • 实验目的
    • 实验内容
    • 练习
    • 文件系统介绍
    • 文件系统抽象层VFS
    • 硬盘文件系统SFS
    • 设备即文件
    • 从中断到终端
    • 项目组成与执行流
由 GitBook 提供支持
在本页
  • 编译
  • 修改脚本
  • 使用GDB进行调试

这有帮助吗?

  1. LAB0:ready~go!
  2. 配置环境

安装调试工具

编译

其实说安装有点不准确,因为之前已经把GDB已经悄悄的装进了环境变量里。其实就是在我们安装编译器的时候我们只需要打开lab0的文件夹,然后打开终端,输入make,就可以进行编译了

$ make
+ cc kern/init/entry.S
+ cc kern/init/init.c
+ cc kern/libs/stdio.c
+ cc kern/driver/console.c
+ cc libs/string.c
+ cc libs/printfmt.c
+ cc libs/readline.c
+ cc libs/sbi.c
+ ld bin/kernel
riscv64-unknown-elf-objcopy bin/kernel --strip-all -O binary bin/ucore.img

可以看到多了几个文件夹,我们之后再来介绍这些。

修改脚本

工具链(之前下载的编译器里面的工具)里提供了相应的gdb工具,要使用gdb,就需要对脚本进行修改。在源代码的文件夹中,找到lab0中的Makefile文件然后找到CC := $(GCCPREFIX)gcc在后面添加-g。

使用GDB进行调试

因为gdb和qemu是两个应用不能直接交流,比较常用的方法是以tcp进行通讯,也就是让qemu在localhost::1234端口上等待。

在lab0文件夹下打开终端,运行

$ qemu-system-riscv64 -S -s -hda ./bin/ucore.img 
WARNING: Image format was not specified for './bin/ucore.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
VNC server running on 127.0.0.1:5900xxxxxxxxxx qemu-system-riscv64 -S -s -hda ./bin/ucore.img$ qemu-system-riscv64 -S -s -hda ./bin/ucore.img WARNING: Image format was not specified for './bin/ucore.img' and probing guessed raw.         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.         Specify the 'raw' format explicitly to remove the restrictions.VNC server running on 127.0.0.1:5900

然后在该文件夹下重新打开一个终端,运行

$ riscv64-unknown-elf-gdb ./bin/kernel
GNU gdb (SiFive GDB 8.3.0-2020.04.0) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=riscv64-unknown-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://github.com/sifive/freedom-tools/issues>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./bin/kernel...
(gdb)

接着连接qemu:

(gdb) target remote :1234
Remote debugging using :1234
0x0000000000001000 in ?? ()

连接成功输入si就可以进行运行下一条指令,

(gdb) si
0x0000000000001004 in ?? ()

这样就代表可以正常运行了噢,具体调试步骤与方法,看一下前面哈。

上一页安装硬件模拟器下一页LAB0.5:最小可执行内核

最后更新于4年前

这有帮助吗?