Edit online

GDB 调试

3 Mar 2025
Read time: 6 minute(s)
GDB 调试的主要配置步骤如下所示:
  1. 安装 T-HEADDebugServer。

  2. 配置主控调试引脚功能为 JTAG。

  3. 关闭主控 JTAG 引脚其他复用功能及断开对应物理连接(如有)。

  4. 编译、烧录。

  5. 使用 T-HEADDebugServer 连接主控。

  6. 进行调试。

GDB 工具介绍

GDB 调试工具及其功能描述如下:

1. GDB 调试工具

工具

说明

T-HeadDebugServer

运行 GDB Server

AiBurn

镜像烧写工具

AIC-JTAG

AIC 调试器

JTAG - SDMC 转接线

仅用于调试器连接 SDMC 接口使用

riscv64-unknown-elf-gdb.exe

调试工具,位于 $(SDK)tool/riscv64-gdb/bin/

d21x.elf

Eclipse 工程目录下生成的符号链接表

Tabby

用于控制调试串口、发送指令

准备工作

执行 GDB 调试前,需要按照以下步骤准备相关软件环境:

  1. 安装 T-HeadDebugServer(以下简称 DebugServer)

    下列过程中会自动安装自带的 AIC-JTAG 驱动。

    1. 解压,运行 setup.exe
    2. 在弹出页面中,点击 Next
      install_1

    3. 在用户协议界面点击 Yes
      install_2

    4. 在安装路径页面,按照实际需求,修改路径:
      install_4

    5. 在安装组件页面,建议全选,继续点 Next
      install_5


      install_6

      等待完成安装后,桌面会自动创建一个 DebugServer 的图标:
      install_7

  2. 将 AIC 调试器通过 USB-TypeC 连接 PC。

    成功识别后,AIC 调试器绿灯会亮起。
    run_1


    cklink_detected

SDK 配置

Baremetal SDK 支持使用 JTAG硬件接口进行调试。 为避免 GPIO 冲突,需要配置 ddr_init.jsonxxx_defconfig
注:

配置前,确保已经加载目标工程。

使用 JTAG 口 进行连接和配置的详细操作流程:
  1. target/<CPU>/<board>/pinmux.c 中,找到 aic_pinmux_config 数组,添加代码如下:
    struct aic_pinmux aic_pinmux_config[] = {
    ...
        {6, PIN_PULL_DIS, 3, "PA.8"},       // 以 D21x 为例,查询引脚复用表,结合电路图,设置四个引脚的功能为 JTAG
        {6, PIN_PULL_DIS, 3, "PA.9"},
        {6, PIN_PULL_DIS, 3, "PA.10"},
        {6, PIN_PULL_DIS, 3, "PA.11"},
    ...
    };
  2. 运行下列命令:

    scons --menuconfig
  3. 关闭 I2C 以及 Touch Panel

    Board options  --->
        [ ] Using I2C3
    Drivers options  --->
        Peripheral  --->
            [ ] Touch Panel Support
    注: 由于开发板的 I2C3 与 JTAG 引脚共用,此处关闭 CTP 是为了避免软件干扰;同时硬件上需断开 CTP 触屏排线。

    CTP_disconnected

连接开发板

  1. 编译 SDK。

  2. 使用 AiBurn 烧录编译生成的镜像,详见配置烧录镜像

  3. 开发板连接串口、AIC-JTAG 和电源线。


    debug_jtag

    1. 开发板连接 JTAG 接口
  4. 使用 Tabby,打开调试串口。
    1. 打开选择页面。

      tabby_open_serial-1

    2. 选择串口 COM 口。

      tabby_open_serial-2

    3. 设置波特率,默认 115200。

      tabby_open_serial-3


      tabby_open_serial-4

      2. 打开成功
  5. 将系统句柄放置在调试串口窗口,点击一下调试串口所在窗口。

  6. 在键盘上按住 Ctrl + C,同时给开发板上电,串口打印如下:
    Pre-Boot Program ... (2023-08-08 11:29:35 13a563f)
    No DDR info
    Going to init DDR2. freq: 504MHz
    DDR2 initialized
    120186 134875 162258
    PBP done
    
    tinySPL [Built on Aug 21 2023 17:12:58]
    Boot device = 5(BD_SPINAND)
    nand read speed: 1346320 byte, 76998 us -> 17075 KB/s
    aic@tinySPL #
    aic@tinySPL #
  7. 运行 DebugServer,首次运行会有安全警告,点击允许访问


    run_0

  8. 配置 DebugServer Setting > Setting > Target Setting


    run_2

  9. 配置 DebugServer 的端口号,例如 3333。


    debug_server1

  10. 启动仿真器连接,显示本地 IP 及已配置的端口(3333),则表示连接成功:

    connected

  11. 连接成功后,即可通过 IDE 或命令行进行调试。

Linux 下使用 GDB 调试

注:

在 Linux 下进行调试操作前,需确保与 DebugServer 所在的 Windows 系统可以 ping 通。

  1. 在 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
  2. 在 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 调试模式。