找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1120|回复: 0
打印 上一主题 下一主题
收起左侧

HC32L110(五) Ubuntu20.04 VSCode的Debug环境配置

[复制链接]
跳转到指定楼层
楼主
ID:912806 发表于 2022-9-3 22:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本文介绍在Ubuntu20.04下, VSCode中如何设置对 HC32L110 进行 debug

原文: https://www.cnblogs.com/milton/p/16653827.html
仓库地址: https://github.com/IOsetting/hc32l110-template

如果转载, 请注明出处.

环境说明

本文使用的软硬件环境已经在前面介绍

硬件
基于 HC32L110 系列MCU的开发板
JLink OB
软件
Ubuntu20.04
VSCode

配置步骤

安装配置 Cortex-Debug

在VSCode的插件中, 搜索安装Cortex-Debug

在VSCode中, 切换到Run And Debug, 点击上方的 Add Configuration, 会在 .vscode 目录下的 launch.json (如果没有会自动创建)中添加配置, 需要增加对应的配置信息
  1. "configurations": [
  2.         {
  3.             "name": "Cortex Debug",
  4.             "cwd": "${workspaceFolder}",
  5.             "executable": "${workspaceFolder}/Build/app.elf",
  6.             "request": "launch",        // 可以是launch或attach, 后者表示运行中接入, 前者会执行前置任务并重启
  7.             "type": "cortex-debug",
  8.             "runToEntryPoint": "main",
  9.             "servertype": "jlink",
  10.             "device": "HC32L110X4",     // 如果是32K的版本, 需要修改为 HC32L110X6
  11.             "interface": "swd",
  12.             "runToMain": true,          // false则从 reset handler 开始停留
  13.             "preLaunchTask": "build",   // 根据 tasks.json 中配置的任务填写,
  14.             // "preLaunchCommands": ["Build all"], // 如果不使用 preLaunchTask, 可以用这个参数指定命令行命令
  15.             "svdFile": "",              // svd 用于观察外设
  16.             "showDevDebugOutput": "vscode", // 输出的日志级别, parsed:解析后的内容, raw:直接输出, vscode:包含scode调用和raw
  17.             "swoConfig":
  18.             {
  19.                 "enabled": true,
  20.                 "cpuFrequency": 24000000,
  21.                 "swoFrequency":  4000000,
  22.                 "source": "probe",
  23.                 "decoders":
  24.                 [
  25.                     {
  26.                         "label": "ITM port 0 output",
  27.                         "type": "console",
  28.                         "port": 0,
  29.                         "showOnStartup": true,
  30.                         "encoding": "ascii"
  31.                     }
  32.                 ]
  33.             }
  34.         }
  35.     ]
复制代码

具体的配置项含义, 可以参考 Debug Attributes

同时在 .vscode/settings.json 中增加以下配置, 如果文件不存在则创建. 路径根据自己的环境修改
  1. {
  2.     "cortex-debug.gdbPath": "/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb",
  3.     "cortex-debug.JLinkGDBServerPath": "/opt/SEGGER/JLink/JLinkGDBServerCLExe",
  4. }
复制代码


修改 rules.mk

在rules.mk中开启debug, 涉及到两处, OPT要使用-O0, 表示不执行任何优化. 使用优化后代码中的部分变量在编译后会被丢弃无法跟踪

OPT         ?= -O0

在CFLAGS中增加gdb输出

CFLAGS      += -g -gdwarf-2 # original: -g

这样编译后, 尺寸会比原先大不少

Ubuntu20.04下遇到的问题

以上配置后, 点击 Run And Debug 中的绿色运行图标应该就能启动Debug, 但是可能在看到以下输出后就没有反应了
  1. Reading symbols from /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-objdump --syms -C -h -w /home/milton/Stm32Projects/hc32_workspace/hc32l110-template/Build/app.elf
  2. Reading symbols from /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/milton/Stm32Projects/hc32_workspace/hc32l110-template/Build/app.elf
  3. Launching GDB: /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb -q --interpreter=mi2
  4. 1-gdb-version
复制代码


这时候到命令行执行一下命令/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb -q --interpreter=mi2就能看到问题

1. libncursesw.so.5: cannot open shared object file
首先是会有这样的错误输出

/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb -q --interpreter=mi2
/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory
观察ldd可以看到缺少两个so: libncursesw.so.5, libpython3.6m.so.1.0

ldd /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb
    linux-vdso.so.1 (0x00007ffc82998000)
    libncursesw.so.5 => not found
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f326ba1e000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f326ba18000)
    libpython3.6m.so.1.0 => not found
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f326b9f5000)
    libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f326b9f0000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f326b89f000)
    libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f326b871000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f326b68f000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f326b674000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f326b482000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f326ba6e000)

libncursesw.so.5可以通过安装 libncursesw5 可以解决

sudo apt install libncursesw5

2. libpython3.6m.so.1.0: cannot open shared object file

这样就剩下另一个动态连接库无法找到

/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb -q --interpreter=mi2
/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

但是 Ubuntu20.04 自带的 Python3.8, 无法安装 Python3.6

~$ sudo apt-get install libpython3.6
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Note, selecting 'libpython3.6-stdlib' for regex 'libpython3.6'
0 upgraded, 0 newly installed, 0 to remove and 29 not upgraded.

简单粗暴的解决方法就是直接用3.8的代替

cd /usr/lib/x86_64-linux-gnu/
$ ll libpython*
lrwxrwxrwx 1 root root      19 Jul  1 20:27 libpython2.7.so.1 -> libpython2.7.so.1.0
-rw-r--r-- 1 root root 3455600 Jul  1 20:27 libpython2.7.so.1.0
lrwxrwxrwx 1 root root      55 Jun 23 04:18 libpython3.8.a -> ../python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a
lrwxrwxrwx 1 root root      17 Jun 23 04:18 libpython3.8.so -> libpython3.8.so.1
lrwxrwxrwx 1 root root      19 Jun 23 04:18 libpython3.8.so.1 -> libpython3.8.so.1.0
-rw-r--r-- 1 root root 5449112 Jun 23 04:18 libpython3.8.so.1.0
$ sudo ln -s libpython3.8.so.1.0 libpython3.6m.so.1.0

这时候再运行就可以启动了

$ /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb -q --interpreter=mi2
/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb: Symbol `PyBool_Type' has different size in shared object, consider re-linking
/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb: Symbol `PySlice_Type' has different size in shared object, consider re-linking
/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb: Symbol `PyFloat_Type' has different size in shared object, consider re-linking
=thread-group-added,id="i1"
(gdb)

使用

点击 Run And Debug 中的绿色运行图标启动Debug, F10 下一步, F11 进入, Shift + F11 跳出. 左侧能观察到变量值和寄存器值. 操作方法和其它IDE基本一致.


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表