1 Star 5 Fork 8

Open-SkyEye / wiki

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
text.md 6.26 KB
一键复制 编辑 原始数据 按行查看 历史

基于vscode和WSL2的SkyEye调试环境

一、介绍

上一篇文章我们讲了如何搭建wsl2的skyeye开发环境,这一节我们来尝试使用vscode图形化界面方式调试skyeye的目标机程序以及skyeye自身的代码。

二、调试skyeye目标机程序

(一)安装vscode插件

在vscode的扩展里搜索Remote Development, 安装两个插件Remote WSL和Remote Container。

(二)连接开发容器

安装好Remote WSL和Remote Container后,先运行wsl的ubuntu开发机,在vscode左下角有个绿色图标打开远程连接。

点击后弹出对话框,选择New wsl window后连接wsl2。

连接上wsl2后,选择打开远程目录 /home/xxx/skyeye-workspace

再次点击左下角图标,选择Attach To running Container,选中开发容器名称连接到容器。

(三)安装arm编译器和调试器

在容器内安装arm开发环境

apt install gcc-arm-none-eabi gcc-arm-linux-gnueabi gdb-arm-none-eabi

三、调试helloworld程序

(一)编写helloworld

参照《一步一步编写嵌入式操作系统》2.1节的helloworld。

#define UFCON0	((volatile unsigned int *)(0x50000020))

void helloworld(void)
{
	const char *p="hello skyeye\n";
	while(*p){
		*UFCON0=*p++;
	};
	while(1); 
}

由于arm下默认从0x0地址启动程序,因此我们编译链接helloworld到0地址,并转换为bin文件。

arm-none-eabi-gcc -nostdlib -O2 -g -c helloworld.c
arm-none-eabi-ld -e helloworld -Ttext 0x0 helloworld.o -o helloworld.elf
arm-none-eabi-objcopy -O binary helloworld.elf helloworld.bin

(二)配置vscode调试环境

vscode的调试环境是在.vscode目录下新建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": "helloworld", // launch名称
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/skyeye-workspace/leeos-book/2.1_使用c语言写第一段程序/helloworld.elf",        // 调试的程序位置,是你实际makefile生成的程序
            "args": [],
            "stopAtEntry": true,                                                                          // 默认在入口暂停
            "cwd": "/home/skyeye-workspace/leeos-book/2.1_使用c语言写第一段程序",                           // 当前项目的路径,即用vscode打开文件夹时的位置,需要注意。
            "environment": [],
            "externalConsole": false,     
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "", // 第一次开始调试的任务,见task.json
            "miDebuggerPath": "/usr/bin/arm-none-eabi-gdb",                                               //arm的调试器
            "miDebuggerServerAddress": "127.0.0.1:12345"                                                  //连接的skeye启动的gdbserver
        }
    ]
}

(三)配置skyeye

我们使用s3c2410x1运行hellworld,需要修改load_addr, memory_space_0的ram0地址为0x0

修改s3c2410x1.json配置

{
	"s3c2410x1_0":{
		"base":"mach",
		"class":"s3c2410x1",
		"s3c2410x1_core_0":{
			"base":"cpu",
			"class":"arm920t_core",
			"load_mask":["uinteger", "0xFFFFFF"],
			"load_addr":["uinteger", "0x00000000"],
			"memory_space":["iface", "memory_space_0"]
		},
		"memory_space_0":{
			"base":"device",
			"class":"memory_space",
			"memory_space":[
				[1,"iface", "ram0", "0x00000000", "0x02000000"],
				[2,"iface", "core_0_uart_0", "0x50000000", "0x4000"]
			]
		},
		"image0": {
			"base": "device",
			"class": "image",
			"size": ["uinteger", "0x02000000"]
		},
		"ram0": {
			"base": "device",
			"class": "ram",
			"memory_space": ["iface", "image0"]
		},
		"core_0_uart_0": {
			"base": "device",
			"class": "s3c2410x_uart",
			"rfifo": ["uinteger", "256"],
			"skyeye_uart_intf":["iface", "uart_term0"]
		},
		"uart_term0": {
			"base": "device",
			"class": "uart_term"
		}
	}
}

修改s3c2410x1.skyeye,配置加载helloworld.bin到0地址,并启动gdbserver

define-conf skyeye.json
load-file  s3c2410x1_core_0 helloworld.bin 0x00000000
init-ok
remote_gdb s3c2410x1_core_0 12345

(三)运行skyeye并调试helloworld

启动skyeye,

root@2be3571dae17:/home/skyeye-workspace/leeos-book/2.1_使用c语言写第一段程序# skyeye
Open-SkyEye  <build  Linux> Copyright 2010-2022 Digiproto Corporation

(skyeye) run-script s3c2410x.skyeye
[ERROR] Remote Gdb Start error, Target Cpu Name: s3c2410x1_core_0, Ip: 0.0.0.0, Port: 12345
(skyeye) 

在vscode中运行调试helloword

自动打开源代码并将断点停止在helloworld函数入口,可以愉快的调试目标机程序啦。

小结

vscode的tasks.json可用于配置编译任务,launch.json可以配置调试任务,有兴趣的同学可以尝试配置调试skyeye的源代码,下面给了一个参考的配置。 后续打算用新版的skyeye完成《一步一步编写嵌入式操作系统》中的各个实验。

 {
    "name": "skyeye debug", // launch名称
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/opt/skyeye/bin/skyeye", // 调试的程序位置,是你实际makefile生成的程序
    "args": [-s /home/skyeye-workspace/boards/core-boards/arm/s3c2410x/s3c2410x.skyeye],
    "stopAtEntry": true,
    "cwd": "${workspaceFolder}/code", // 当前项目的路径,即用vscode打开文件夹时的位置,需要注意。
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
    ],
    "preLaunchTask": "", // 第一次开始调试的任务,见task.json
    "miDebuggerPath": "/usr/bin/gdb"
},
1
https://gitee.com/open-skyeye/wiki.git
git@gitee.com:open-skyeye/wiki.git
open-skyeye
wiki
wiki
master

搜索帮助