四.使用vscode调试xv6内核

资料来源:

1.南京大学操作系统课程第18课:https://www.bilibili.com/medialist/play/202224425?from=space&business=space_collection&business_id=192498&desc=0
下方的评论:
  https://zhuanlan.zhihu.com/p/501901665
  https://www.bilibili.com/video/BV1Lv411g7EV/?spm_id_from=333.824.b_636f6d6d656e74.32

一.相关插件

1.vscode远程连接到自己xv6目录

2.下载相关扩展

3.创建launch.json和task.json文件

(1)launch.json 

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "debug xv6",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/kernel/kernel",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "miDebuggerServerAddress": "localhost:25000",
            "miDebuggerPath": "/usr/bin/gdb-multiarch",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "pretty printing",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "logging": {
                 "engineLogging": true,
                 "programOutput": true,
            },
            "preLaunchTask": "xv6build",
        }
    ]
}

(2)task.json

// xv6-riscv/.vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
      {
          "label": "xv6build",
          "type": "shell",
          "isBackground": true,
          "command": "make qemu-gdb",
          "problemMatcher": [
              {
                  "pattern": [
                      {
                          "regexp": ".",
                          "file": 1,
                          "location": 2,
                          "message": 3
                      }
                  ],
                  "background": {
                      "beginsPattern": ".*Now run 'gdb' in another window.",
                      // 要对应编译成功后,一句echo的内容. 此处对应 Makefile Line:170
                      "endsPattern": "."
                  }
              }
          ]
      }
  ]
}

(3)在命令行中执行make qemu-gdb查看端口

 

(4).gdbinit文件相关行注释

(5)launch.json文件相关行修改

 

(6)关闭所有终端,新建一个新的终端,在main中添加断点,按F5开始调试

 

posted @ 2022-09-10 19:08  All_just_for_fun  阅读(838)  评论(0编辑  收藏  举报