windows vscode 调试 linux 内核

当前环境

windows A : vscode
centos    : linux code & toolchain
windows B : openocd
开发板	  : riscv

用 vscode 调试 riscv开发板(运行linux)

配置

  • 提前 需要在windows A安装的插件remote-ssh,必须
  • 提前需要在centos 安装的插件 clangd,非必须

launch.json 创建与修改

  • launch.json 文件的创建
注意: 这个文件是在本机中的,而不是远端主机
点击 左侧 debug 图标,点击 "创建 launch.json 文件" . 会在本机新建一个模板文件,待用户修改内容
注意: 这个文件的存在和 C/C++插件 没有关系
  • launch.json 的修改
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "linux kernel debug",
            
            // 注意: 如果不装 C/C++ 插件,会提示 cppdbg 找不到
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/vmlinux",
            "cwd": "${workspaceFolder}",
            "MIMode": "gdb",
            // 注意 : miDebuggerPath 必须是绝对路径
            "miDebuggerPath":"/path/to/bin/riscv64-unknown-linux-gdb",
            "miDebuggerServerAddress": "10.37.30.85:1111"
        }
    ]
}

在centos安装 C/C++ 插件

// 虽然是在 centos 安装  C/C++ 插件, 但还是  在 windows A 的 vscode 操作!!!
// 注意 : 要保持remote ssh 连接的情况下 安装 C/C++ 插件,才会安装到 centos
在 本机安装完 remote ssh 并配置,运行OK之后
在 remote主机 安装 clangd 并配置,运行OK之后
    
需要在 remote 主机 增加 C/C++ 插件
	提供 一个 debug type : cppdbg 
        // 等会在 本机 launch.json 中有体现
        // 注意 : vscode 本身就支持debug前端,但是需要具体的后端实现( debug type)
        // 在这里, 后端为 C/C++ 插件
        // launch.json 本身就被 vscode 支持, 与  C/C++ 无关
  • clangd 与 C/C++ 的兼容问题
安装完之后,clangd 会 提示不兼容,需要做一个动作。我们点击之后,
vscode 会自动修改 本地扩展配置 增加如下:
"C_Cpp.intelliSenseEngine": "disabled",

运行

运行步骤

1. 开启开发板并运行openocd服务器
2. vscode 中
    2.1 点击 "左侧debug按钮"
    2.2 切换 "RUN AND DEBUG" 配置到 "linux kernel debug"
    2.3 点击 "RUN AND DEBUG" 右侧 绿三角
3. 此时就开启了 gdb
    // 注意 : "linux kernel debug" 的内容相当于 在 命令行中 ${workspaceFolder} 目录 执行 如下命令
    // /path/to/bin/riscv64-unknown-linux-gdb vmlinux  -ex 'target remote 10.37.30.85:1111' -ex 'c'
    // 注意 : 他并没有停下来,而是在全速运行

运行信息

  • debug console 信息
=thread-group-added,id="i1"
GNU gdb (2022-05-03_riscv64-linux-85ba823a400) 8.2.50.20190522-git
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-pc-linux-gnu --target=riscv64-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
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".
[info] Loading .Andesgdbinit.
=cmd-param-changed,param="remotetimeout",value="60"
[info] .Andesgdbinit loaded.
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
=cmd-param-changed,param="print frame-arguments",value="none"
0x0000000020003738 in ?? ()
=cmd-param-changed,param="print frame-arguments",value="scalars"

Program received signal SIGTRAP, Trace/breakpoint trap. // 我在内核中加了一条内嵌汇编,他就停下来了,这是停下来的第一句打印
0xffffffff8000180a in start_kernel () at init/main.c:581
581		asm("c.ebreak");
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)

-exec info registers // 这是我键入的一条命令
ra             0xffffffff80001094	0xffffffff80001094 <_start_kernel+148>
sp             0xffffffff8079bfd0	0xffffffff8079bfd0
gp             0xffffffff807e6640	0xffffffff807e6640 <tcp6_seq_afinfo>
tp             0xffffffff807a1b00	0xffffffff807a1b00 <init_task>
t0             0xffffffff807f6670	-2139134352
t1             0x159c	5532
t2             0xffffffffb35db666	-1285704090
fp             0xffffffff8079c000	0xffffffff8079c000 <vdso_data_store>
s1             0xc00000	12582912
a0             0x1	1
a1             0x15a0	5536
a2             0x0	0
a3             0x1500	5376
a4             0xffffffffffffffff	-1
a5             0xffffffffffffffff	-1
a6             0x0	0
a7             0xa4	164
s2             0x200000	2097152
s3             0xc00000	12582912
s4             0x0	0
s5             0x0	0
s6             0x8000000a00006800	-9223371993905076224
s7             0x140c0	82112
s8             0x7f	127
s9             0x13010	77840
s10            0x0	0
s11            0x0	0
t3             0x7	7
t4             0x0	0
t5             0xffffffff807e6c20	-2139198432
t6             0xffffffff807f666d	-2139134355
pc             0xffffffff8000180a	0xffffffff8000180a <start_kernel+10>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值