调试
Windows 下使用 Eclipse 调试
采用 Eclipse 配合 GDB 的调试方案,方便用户上手
使用 Eclipse 调试前,需先按照 Eclipse IDE 调试 的步骤,完成 Eclipse 工程导入及编译。
配置 Debug Configurations - Main
配置 Debug Configurations - Debugger
Eclipse 进入 Debug 模式
Eclipse 调试常用快捷键
-
F5:单步进入,进入函数内部
-
F6:下一行代码,逐行执行
-
F7:返回值调用处的下一行代码
-
F8:继续运行,跳过当前中断点
-
F11:调试并启动程序
Linux 下使用 GDB 调试
在 Linux 下调试前,需确保与 DebugServer 所在的 Windows 系统可以 ping 通。
-
在 SDK 根目录编写
jtag-debug.sh
脚本:$cat jtag-debug.sh target remote 172.16.31.141:3333 #此处 IP 为 DebugServer 运行 PC 的 IP,端口为 DebugServer 配置的端口 load ./output/d13x_demo88-nor_rt-thread_helloworld/images/d13x.elf # 对应项目的 elf 文件 file ./output/d13x_demo88-nor_rt-thread_helloworld/images/d13x.elf
-
在 SDK 根目录下运行 GDB :
$ ./toolchain/bin/riscv64-unknown-elf-gdb -x ./jtag-debug.sh GNU gdb (Xuantie-900 elf newlib gcc Toolchain V2.6.1 B-20220906)10.0.50.20200724-git Copyright (C)2020 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-unknown-elf". Type "show configuration"for configuration details. For bug reporting instructions, please see: <https://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". warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x0000000000106b3a in ?? () Loading section .text, size 0xa4780 lma 0x40000100 sectio--Type <RET> for more, q to quit, c to continue without paging-- --Type <RET> for more, q to quit, c to continue without paging-- section progress: 41.5%, total progress: inf% section progress: 46.2%, total progress: inf% section progress: 50.4%, total progress: inf% section progress: 53.9%, total progress: inf% section progress: 63.3%, total--Type <RET> for more, q to quit, c to continue without paging-- section progress: 93.5%, total progress: inf%--Type <RET> for more, q to quit, c to continue without paging-- section progress: 100.0%, total progress: inf% Loading section .rodata, size 0x843b8 lma 0x400a4880 section progress: 27.7%, total progress: i--Type <RET> for more, q to quit, c to continue without paging-- sect--Type <RET> for more, q to quit, c to continue without paging-- section progress: 100.0%, total progress: inf% Loading section .data, size 0x32e0 lma 0x40128c40 --Type <RET> for more, q to quit, c to continue without paging-- section progress: 100.0%, total progress: inf% Start address 0x0000000040000100, load size 1228312 Transfer rate: 107 KB/sec, 3988 bytes/write.
显示以上信息,表示已经进入 GDB 调试模式。