一,win10版本的openocd+stlink调试环境搭建
1,在官网下载openocd的win10版本解压即可,arm-none-eabi的win10版本解压即可,然后添加到环境变量。
2,stlink连接开发板,且插入stlink。
3,打开一个cmd输入命令,然后可以看到正常识别到stlink,且等待gdb的3333端口。
openocd -f D:\program\OpenOCD-20231002-0.12.0\share\openocd\scripts\interface\stlink.cfg -f D:\program\OpenOCD-20231002-0.12.0\share\openocd\scripts\target\stm32f4x.cfg
4,再在带有elf的路径下,打开一个cmd,作为客户端。
arm-none-eabi-gdb -ex "target remote localhost:3333" led.elf
连接成功后
load led.elf
然后就可以输入gdb常用命令调试了
遇到问题:连接成功后,启动不了,一开始的PC是0x1FFF3da0,非预期。
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x1fff3da0 msp: 0x20001d80
强制设置PC值也没用,后来网上查了其它人操作的命令发现,需要先load elf,命令参考如下。
G:\keil\LED_small_3\Release>arm-none-eabi-gdb -ex "target remote localhost:3333" LED.elf
D:\program\gcc-arm-none-eabi-9-2019-q4-major-win32\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 8.3.0.20190709-git
Copyright (C) 2019 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=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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"...
Reading symbols from LED.elf...
Remote debugging using localhost:3333
0x1fff3834 in ?? ()
(gdb) c
Continuing.
Program received signal SIGINT, Interrupt.
0x1fff36aa in ?? ()
(gdb) load LED.elf
Loading section .isr_vector, size 0x188 lma 0x8000000
Loading section .text, size 0xf1c lma 0x8000188
Loading section .rodata, size 0x10 lma 0x80010a4
Loading section .ARM, size 0x8 lma 0x80010b4
Loading section .init_array, size 0x4 lma 0x80010bc
Loading section .fini_array, size 0x4 lma 0x80010c0
Loading section .data, size 0x54 lma 0x80010c4
Loading section .mysec, size 0x4 lma 0x8001118
Start address 0x8000fc4, load size 4380
Transfer rate: 6 KB/sec, 547 bytes/write.
(gdb) b main
Breakpoint 1 at 0x80005e6: file Src/Core/Src/main.c, line 77.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 1, main () at Src/Core/Src/main.c:77
77 HAL_Init();
(gdb) c
Continuing.
halted: PC: 0x08000f44
Program received signal SIGINT, Interrupt.
0x08000fba in HAL_Delay (Delay=Delay@entry=500) at Src/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:402
402 }
仔细想了下,之前没板子单独的app只要file xx.elf就可以了。但是这是有板子的,所以elf需要下载到板子中才可以调试,光gdb还没连接target时候的file命令只能导入symbol表,连接了target后,需要用load命令把代码下载到目标板,才能正常调试,哈哈~
二,启动openocd的远程gdb连接ubuntu
我想在虚拟机直接用vscode的远程gdb调试脚本不通过,连接后断点不会停。命令输入也无效。
于是直接远程命令窗口gdb调试
arm-none-eabi-gdb -ex "target remote 192.168.112.10:3333" led.elf
远程连接不上3333
Type "apropos word" to search for commands related to "word"...
Reading symbols from LED.elf...
192.168.112.10:3333: 连接超时.
网上搜索了下要加-c "bindto 0.0.0.0",原因并不清楚,但是可以解决问题
openocd -f D:\program\OpenOCD-20231002-0.12.0\share\openocd\scripts\interface\stlink.cfg -f D:\program\OpenOCD-20231002-0.12.0\share\openocd\scripts\target\stm32f4x.cfg -c "bindto 0.0.0.0"
于是在ubuntu中可以正常调试了。
Reading symbols from LED.elf...
Remote debugging using 192.168.112.10:3333
0x1fff37b8 in ?? ()
(gdb) load LED.elf
Loading section .isr_vector, size 0x188 lma 0x8000000
Loading section .text, size 0xf1c lma 0x8000188
Loading section .rodata, size 0x10 lma 0x80010a4
Loading section .ARM, size 0x8 lma 0x80010b4
Loading section .init_array, size 0x4 lma 0x80010bc
Loading section .fini_array, size 0x4 lma 0x80010c0
Loading section .data, size 0x54 lma 0x80010c4
Loading section .mysec, size 0x4 lma 0x8001118
Start address 0x8000fc4, load size 4380
Transfer rate: 6 KB/sec, 547 bytes/write.
(gdb) b main
Breakpoint 1 at 0x80005e6: file Src/Core/Src/main.c, line 77.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 1, main () at Src/Core/Src/main.c:77
77 Src/Core/Src/main.c: 没有那个文件或目录.
(gdb) c
Continuing.
halted: PC: 0x08000f44
^C
Program received signal SIGINT, Interrupt.
0x08000f94 in HAL_GetTick ()
at Src/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:325
325 Src/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c: 没有那个文件或目录.
直接用gdb可以调试,但是用ssh连接出来的PC端的vscode中用gdb就无法调试了,那么我考虑ubuntu中安装一个vscode来调试吧!总比gdb调试方便!
我暂时验证环境,所以elf是一个之前本地PC编译的,也不带源码,所以list看不到c代码信息的。
三,小结
我为什么愿意花那么多时间在调试环境的建立上,是因为大部分自己写的code基本不用调试,若要快速了解其他人写的code,光看代码怕理解错误,要形成闭环验证,就要靠调试,所以掌握各种调试方法是有必要的。工欲善其事必先利其器,磨刀不误砍柴工。
标签:openocd,Loading,Apple,Src,--,section,gdb,lma,size From: https://blog.51cto.com/AppleCai/8079048