嵌入式linux之yocto

嵌入式linux之yocto,第1张

1. 添加gdbserver软件包
~/yocto$ source poky/oe-init-build-env qemux86-64-build/
~/yocto/qemux86-64-build$ devtool edit-recipe myimage
require recipes-core/images/core-image-minimal.bb
IMAGE_INSTALL += "sqlite3 gdb gdbserver"
~/yocto/qemux86-64-build$ bitbake myimage
~/yocto/qemux86-64-build$ bitbake myimage -c populate_sdk
~/yocto/qemux86-64-build$ runqemu qemux86-64
~/yocto/qemux86-64-build$ ifconfig 
2. 编写测试程序
/* app/gdb_test.c */
#include 
#include 

int main(void)
{
	int i = 0;
	while (1)
	{
		i++;
		printf("%d\r\n", i);
		sleep(1);
	}
	return 0;
}

app$ x86_64-poky-linux-gcc --sysroot=/opt/poky/3.4.2/sysroots/core2-64-poky-linux gdb_test.c -o gdb_test -g
app$ cp gdb_test ~/nfs_rootfs/mnt/
3. vscode设置

安装Remote Developmen插件,C/C++插件,点击运行和调试->创建launch.json文件。

/* 配置launch.json */
{
        "version": "0.2.0",
        "configurations": [
                {
                        "name": "gdb_test",
                        "type": "cppdbg",
                        "request": "launch",
                        "program": "${workspaceFolder}/gdb_test",
                        "args": [],
                        "stopAtEntry": false,
                        "cwd": "${workspaceFolder}",
                        "environment": [],
                        "externalConsole": false,
                        "MIMode": "gdb",
                        "setupCommands": [
                            {
                                "description": "Enable pretty-printing for gdb",
                                "text": "-enable-pretty-printing",
                                "ignoreFailures": true
                            }
                        ],
                        "miDebuggerPath": "/opt/poky/3.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/x86_64-poky-linux/x86_64-poky-linux-gdb",
                        "miDebuggerServerAddress": "xxx.xxx.xxx.xxx:2021"
                    }
            
        ]
}
name: 调试的文件名,例如"gdb_test"
program: 需要调试的应用程序可执行文件路径
cwd: 需要调试的应用程序源码路径
miDebuggerPath: 交叉编译器gdb路径
miDebuggerServerAddress: 开发板ip:port
4. 开始调试
~/yocto/qemux86-64-build$ runqemu qemux86-64 
root@qemux86-64$ mount -t nfs -o nolock,vers=3 ###.###.###.###:/home/ubuntu18/nfs_rootfs/mnt /mnt
root@qemux86-64:/mnt$ gdbserver xxx.xxx.xxx.xxx:2021 gdb_test

xxx.xxx.xxx.xxx为服务器IP。对口与launch.json的端口对应。然后打开vsode ,按F5快捷键开始调试。


qemux86-64调试结果:

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/707207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-24
下一篇 2022-04-24

发表评论

登录后才能评论

评论列表(0条)

保存