首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

u-boot-搭建gdb调试环境

GDB是Linux下非常好用且功能强大的调试工具,使用gdb调试u-boot,能加快分析u-boot代码过程,使我们更加清晰的掌握u-boot运行过程。本文介绍使用qemu模拟运行u-boot时,用gdb调试u-

测试环境:

虚拟机:ubuntu18.04 LTS

qemu 版本:version 2.11.1

u-boot版本:u-boot-2017.05-rc2

gdb-multiarch版本:8.1.1

编译生成u-boot

u-boot编译过程可以参考之前的文章,这里就不做详细介绍。

安装gdb-multiarch

apt-get install gdb-multiarch

gdb-multiarch 是一个经过交叉编译后的、支持多架构版本的 gdb。

运行u-boot

使用如下命令运行u-boot

qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot -s -S

-s 选项告诉 qemu-system-arm 启动内置的 gdb-server, 监听在 TCP 端口 1234 上

-S 选项告诉 qemu-system-arm 不要启动程序执行,等待 gdb 的指令

目前程序 u-boot 处于停止状态

qemu-system-arm 等待 gdb 客户端连接它,发送进一步的指令。

u-boot运行界面如下:

启动gdb

另外打开一个终端。

输入

gdb-multiarch u-boot

在gdb下输入:

target remote :1234

如下所示:

root@ubuntu:/home/ubuntu/Desktop/u-boot-2017.05-rc2# gdb-multiarch u-boot

GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1

Copyright (C) 2018 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later

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 "x86_64-linux-gnu".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

.

Find the GDB manual and other documentation resources online at:

.

For help, type "help".

Type "apropos word" to search for commands related to "word"...

Reading symbols from u-boot...done.

(gdb) target remote :1234

Remote debugging using :1234

_start () at arch/arm/lib/vectors.S:54

54breset

使用gdb下的快捷键ctrl+x然后再摁下a,可以看到gdb的图形化界面。图下图所示:

在当前页面下可以使用gdb命令进行调试,也可以单独运行,查看u-boot代码的运行过程。

u-boot代码重定向的问题

u-boot代码在运行过程中会将自身程序拷贝到内存中,然后跳转到相应的地方继续执行,跳转之后,gdb就不能找到相应的描述符了,此时,无法查看具体的代码。因此需要根据内存地址设置新的描述符表。

其具体过程如下:

获取重定位之后uboot在内存中的地址,先跳到relocate_code,查看r0 的值,就知道从定位后地址,然后从新设置符号表,设置之后的断点b board_init_r

(gdb) b relocate_code #设置断点

Breakpoint 1 at 0x60800b34: file arch/arm/lib/relocate.S, line 81.

(gdb) c #继续执行

Continuing.

Breakpoint 1, relocate_code () at arch/arm/lib/relocate.S:81

81ldrr1, =__image_copy_start/* r1

(gdb) info register r0 #查看r0信息

r0 0x6ff7d0001878511616

(gdb) symbol-file #删除符号表

Discard symbol table from `/home/ubuntu/Desktop/u-boot-2017.05-rc2/u-boot'? (y or n) y

Error in re-setting breakpoint 1: No symbol table is loaded. Use the "file" command.

No symbol file now.

(gdb) add-symbol-file u-boot 0x6ff7d000 #重新添加符号表

add symbol table from file "u-boot" at

.text_addr = 0x6ff7d000

(y or n) y

Reading symbols from u-boot...done.

此时u-boot符号表已重新定位。此时增加一个断点。

重新切换为gdb的代码页面,可以正常使用gdb进行调试了。

此时也可以看到qemu已经运行了一部分u-boot了

总结

使用gdb调试也可以在vscode 或着eclispe下进行设置,可以看到可视化的代码界面,这里就不详细介绍了。另外,如果有开发板,也可以搭建远程的gdb调试环境。这里使用了qemu工具模拟启动u-boot,并且使用gdb进行调试,对了解u-boot的运行流程有很大的帮助。

  • 发表于:
  • 原文链接https://page.om.qq.com/page/OYQfmUZ4xOIYHIACg2YQk4PQ0
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券