Marus / cortex-debug

Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
MIT License
1.01k stars 238 forks source link

BlackMagic Probe, can't pause connected target after run. #865

Closed wmaxfield closed 1 year ago

wmaxfield commented 1 year ago

Congratulations on such a good extension. However, there is an issue which may/may not be your issue.

I created a BlackMagic probe and tested it on an STM32F103T6 clone. I can load a program and run. When it hits the 'main' breakpoint, then it pauses, and I can set another breakpoint, run, and it will break. I can see variables, single step, step into and out of functions, etc. With all debugger probes so far, pause execution works.

But, if I have BlackMagic run the target again without breakpoints in the execution path, pressing Pause does nothing. I can quit the session, restart it and reload and restart the processor, and set a new breakpoint and have it hit that breakpoint. If I connect to the GDB Server on the serial port via a terminal program, I can stop it; so it could come down to the right commands. I don't know GDB command, so I really don't know how to go from that point on. This may be a BlackMagic probe problem, I am just letting you know.

Thanks for such a good product! I have used it minimally JLink, STLink. I use it almost every day with OpenOCD (psoc5lp DAPLink). It works very well in that configuration.

haneefdm commented 1 year ago

Unfortunately, I don't have a blackmagic probe. Can you enable Debug ("showDevDebugOutput": "raw") and attach the output of the Debug Console? This way we can see ALL the commands being sent to gdb. We never talk to the gdb-server directly.

A second run with "showDevDebugOutput": "vscode" is also helpful. This may tell us why the Pause button is not sending the command to our debugger ... if that is the case.

May I ask why you prefer BlackMagic Probe?

wmaxfield commented 1 year ago

It appears that when I click on the "pause" button, nothing is sent at all, from observation. The button appears to be ignored. I created my BlackMagic probe from a pair of cheap stlink/blue-pill boards from amazon. I documented that on my blog (see following)

Answer to your question: I do not prefer BlackMagic Probe. I have a blog ( socmaker . com ) where I discuss PSOC family, and other things. I was trying to work with a Quicklogic QuickFeather and bricked it. That lead me on a chase for cheap debug probes that could possibly work and I stumbled across several options. I saw where your extension indicated support for BlackMagic, and tested it, just to see. That is where I ran across this issue.

I prefer whatever probe will work, but for my readers, I wanted to point them to the least expensive probes possible.

BlackMagic is just one of them, but is contractually ok for many processors. JLink-OB's (On-Board) are contractually tied to a processor family, as are STLink OB's. J-Links that are not tied are over 500usd.

BlackMagic was a possibility of one not contractually tied to any processor family. That is the only reason for looking at it.

Thanks!

Output:

Note: the showDevDebugOutput is not shown in the intellisense suggestions:

showDevDebugOutput:raw

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-apple-darwin10 --target=arm-none-eabi". 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". =cmd-param-changed,param="pagination",value="off" 0x08000362 in ?? () 1: (859) <-1015-thread-info 1: (860) ->1015^done,threads=[{id="1",target-id="Thread 1",frame={level="0",addr="0x08000c94",func="Reset_Handler",args=[],file="startup_stm32f103x6.s",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/startup_stm32f103x6.s",line="65",arch="armv7"},state="stopped"}],current-thread-id="1" 1: (860) ->(gdb) 1: (861) 1015: elapsed time 1 1: (868) <-1016-stack-list-frames 0 1000 1: (868) ->1016^done,stack=[frame={level="0",addr="0x08000c94",func="Reset_Handler",file="startup_stm32f103x6.s",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/startup_stm32f103x6.s",line="65",arch="armv7"}] 1: (868) ->(gdb) 1: (870) 1016: elapsed time 1 1: (872) Send Event AD7ProcessInfoUpdatedEvent 1: (878) Send Event AD7ThreadCreateEvent 1: (885) <--exec-continue 1: (885) ->^running 1: (885) ->*running,thread-id="all" 1: (887) ->(gdb) 1: (889) ->=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0800022e",func="main",file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",thread-groups=["i1"],times="1",original-location="main"} 1: (892) ->~"\n" 1: (892) ->~"Breakpoint 1, main () at Core/Src/main.c:74\n" 1: (892) ->~"74\t HAL_Init();\n"

Breakpoint 1, main () at Core/Src/main.c:74 1: (892) ->stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x0800022e",func="main",args=[],file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",arch="armv7"},thread-id="1",stopped-threads="all" 74 HAL_Init(); 1: (892) <-1017-stack-list-frames 0 1000 1: (893) ->1017^done,stack=[frame={level="0",addr="0x0800022e",func="main",file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",arch="armv7"}] 1: (893) ->(gdb) 1: (893) 1017: elapsed time 0 1: (896) Send Event AD7ExceptionEvent Execute debugger commands using "-exec ", for example "-exec info registers" will list registers in use (when GDB is the debugger) 1: (952) <-1018-stack-list-arguments 0 0 0 1: (952) ->1018^done,stack-args=[frame={level="0",args=[]}] 1: (952) ->(gdb) 1: (953) 1018: elapsed time 1 1: (1131) <-1019-var-create - "counter" 1: (1132) ->1019^done,name="var1",numchild="0",value="0",type="int16_t",has_more="0" 1: (1132) ->(gdb) 1: (1132) 1019: elapsed time 1 1: (1417) <-1020-stack-list-variables 0 1: (1417) ->1020^done,variables=[] 1: (1418) ->(gdb) 1: (1418) 1020: elapsed time 1 1: (15020) <--exec-continue 1: (15020) ->^running 1: (15020) ->*running,thread-id="all" 1: (15020) ->(gdb)

———————

showDevDebugOutput:vscode

1: (80) LaunchOptions{"name":"Black Magic Probe","type":"cppdbg","request":"launch","preLaunchTask":"Build STM","cwd":"/Users/maxfield/Desktop/STM32_Projects/blink2","MIMode":"gdb","targetArchitecture":"arm","logging":{"engineLogging":true},"program":"/Users/maxfield/Desktop/STM32_Projects/blink2/build/blink2.elf","miDebuggerPath":"arm-none-eabi-gdb","showDevDebugOutput":"vscode","customLaunchSetupCommands":[{"text":"cd /Users/maxfield/Desktop/STM32_Projects/blink2"},{"text":"target extended-remote /dev/cu.usbmodem4C99B0AB1"},{"text":"monitor swdp_scan"},{"text":"attach 1"},{"text":"file ./build/blink2.elf"},{"text":"load"},{"text":"cd /Users/maxfield/Desktop/STM32_Projects/blink2"},{"text":"set mem inaccessible-by-default off"},{"text":"break main"}],"serverLaunchTimeout":10000,"configurationTarget":6,"configSource":"workspaceFolder","debugType":"debug","sessionId":"6ca85b9e-5c26-45a2-b60e-5d5181c79f3e"} 1: (144) codeSign-stderr: Executable=/Applications/VSCode_OnethinxPack_macOS/gcc-arm-none-eabi-10-2021-q1-update/bin/arm-none-eabi-gdb 1: (148) Starting: "/Applications/VSCode_OnethinxPack_macOS/gcc-arm-none-eabi-10-2021-q1-update/bin/arm-none-eabi-gdb" --interpreter=mi 1: (154) DebuggerPid=19882 1: (167) ->=thread-group-added,id="i1" 1: (168) ->~"GNU gdb (GNU Arm Embedded Toolchain 10.3-2021.10) 10.2.90.20210621-git\n" 1: (168) ->~"Copyright (C) 2021 Free Software Foundation, Inc.\n" 1: (168) ->~"License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law." 1: (168) ->~"\nType \"show copying\" and \"show warranty\" for details.\n" 1: (168) ->~"This GDB was configured as \"--host=x86_64-apple-darwin10 --target=arm-none-eabi\".\n" 1: (168) ->~"Type \"show configuration\" for configuration details.\n" 1: (168) ->~"For bug reporting instructions, please see:\n" 1: (168) ->~"https://www.gnu.org/software/gdb/bugs/.\n" 1: (168) ->~"Find the GDB manual and other documentation resources online at:\n http://www.gnu.org/software/gdb/documentation/." 1: (168) ->~"\n\n" 1: (168) ->~"For help, type \"help\".\n" 1: (168) ->~"Type \"apropos word\" to search for commands related to \"word\".\n" 1: (168) ->(gdb) 1: (174) <-1001-gdb-set mi-async on 1: (174) ->1001^done 1: (174) ->(gdb) 1: (177) 1001: elapsed time 4 1: (186) <-1002-interpreter-exec console "set pagination off" 1: (187) ->=cmd-param-changed,param="pagination",value="off" 1: (187) ->1002^done 1: (187) ->(gdb) 1: (187) 1002: elapsed time 0 1: (187) <-1003-gdb-set auto-solib-add on 1: (187) ->1003^done 1: (187) ->(gdb) 1: (187) 1003: elapsed time 0 1: (187) <-1004-gdb-set solib-search-path /Users/maxfield/Desktop/STM32_Projects/blink2/build: 1: (187) ->1004^done 1: (187) ->(gdb) 1: (187) 1004: elapsed time 0 1: (189) <-1005-interpreter-exec console "cd /Users/maxfield/Desktop/STM32_Projects/blink2" 1: (189) ->~"Working directory /Users/maxfield/Desktop/STM32_Projects/blink2.\n" 1: (189) ->1005^done 1: (189) ->(gdb) 1: (189) 1005: elapsed time 0 1: (190) <-1006-interpreter-exec console "target extended-remote /dev/cu.usbmodem4C99B0AB1" 1: (193) ->~"Remote debugging using /dev/cu.usbmodem4C99B0AB1\n" 1: (206) ->1006^done 1: (207) ->(gdb) 1: (207) 1006: elapsed time 17 1: (207) <-1007-interpreter-exec console "monitor swdp_scan" 1: (208) ->@"Target voltage: 3.26V\n" 1: (424) ->@"Available Targets:\n" 1: (424) ->@"No. Att Driver\n" 1: (424) ->@" 1 STM32F1 medium density M3\n" 1: (425) ->1007^done 1: (425) ->(gdb) 1: (425) 1007: elapsed time 217 1: (425) <-1008-interpreter-exec console "attach 1" 1: (425) ->~"Attaching to Remote target\n" 1: (427) ->=thread-group-started,id="i1",pid="1" 1: (428) ->=thread-created,id="1",group-id="i1" 1: (442) ->1008^done 1: (442) ->&"warning: No executable has been specified and target does not support\ndetermining executable automatically. Try using the \"file\" command." 1: (442) 1008: elapsed time 17 1: (442) ->&"\n" 1: (442) <-1009-thread-info 1 1: (445) ->~"0x08000382 in ?? ()\n" 1: (445) ->*stopped,frame={addr="0x08000382",func="??",args=[],arch="arm"},thread-id="1",stopped-threads="all" 1: (446) ->1009^done,threads=[{id="1",target-id="Thread 1",frame={level="0",addr="0x08000382",func="??",args=[],arch="arm"},state="stopped"}] 1: (446) ->(gdb) 1: (451) 1009: elapsed time 9 1: (451) <-1010-interpreter-exec console "file ./build/blink2.elf" 1: (451) ->~"A program is being debugged already.\nAre you sure you want to change the file? " 1: (452) ->~"(y or n) [answered Y; input not from terminal]\n" 1: (452) ->~"Reading symbols from ./build/blink2.elf...\n" 1: (455) ->1010^done 1: (455) ->(gdb) 1: (455) 1010: elapsed time 3 1: (455) <-1011-interpreter-exec console "load" 1: (578) ->~"Loading section .isr_vector, size 0x10c lma 0x8000000\n" 1: (579) ->1011+download,{section=".isr_vector",section-size="268",total-size="44673"} 1: (579) ->1011+download,{section=".isr_vector",section-sent="268",section-size="268",total-sent="268",total-size="44673"} 1: (579) ->~"Loading section .text, size 0xc44 lma 0x800010c\n" 1: (609) ->1011+download,{section=".text",section-size="3140",total-size="44673"} 1: (670) ->~"Loading section .rodata, size 0x24 lma 0x8000d50\n" 1: (671) ->1011+download,{section=".rodata",section-size="36",total-size="44673"} 1: (671) ->~"Loading section .init_array, size 0x4 lma 0x8000d74\n" 1: (671) ->1011+download,{section=".init_array",section-size="4",total-size="44673"} 1: (671) ->~"Loading section .fini_array, size 0x4 lma 0x8000d78\n" 1: (671) ->1011+download,{section=".fini_array",section-size="4",total-size="44673"} 1: (672) ->~"Loading section .data, size 0xc lma 0x8000d7c\n" 1: (672) ->1011+download,{section=".data",section-size="12",total-size="44673"} 1: (736) ->~"Start address 0x08000c94, load size 3464\n" 1: (737) ->~"Transfer rate: 12 KB/sec, 384 bytes/write.\n" 1: (737) ->1011^done 1: (737) ->(gdb) 1: (737) 1011: elapsed time 281 1: (737) <-1012-interpreter-exec console "cd /Users/maxfield/Desktop/STM32_Projects/blink2" 1: (737) ->~"Working directory /Users/maxfield/Desktop/STM32_Projects/blink2.\n" 1: (737) ->1012^done 1: (737) ->(gdb) 1: (737) 1012: elapsed time 0 1: (737) <-1013-interpreter-exec console "set mem inaccessible-by-default off" 1: (738) ->=cmd-param-changed,param="mem inaccessible-by-default",value="off" 1: (738) ->1013^done 1: (738) ->(gdb) 1: (738) 1013: elapsed time 0 1: (738) <-1014-interpreter-exec console "break main" 1: (741) ->~"Breakpoint 1 at 0x800022e: file Core/Src/main.c, line 74.\n" 1: (741) ->=breakpoint-created,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0800022e",func="main",file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",thread-groups=["i1"],times="0",original-location="main"} 1: (741) ->~"Note: automatically using hardware breakpoints for read-only addresses.\n" 1: (741) ->1014^done 1: (741) ->(gdb) 1: (741) 1014: elapsed time 3 1: (745) Send Event AD7EngineCreateEvent 1: (747) Send Event AD7ProgramCreateEvent 1: (804) Send Event AD7LoadCompleteEvent =thread-group-added,id="i1" GNU gdb (GNU Arm Embedded Toolchain 10.3-2021.10) 10.2.90.20210621-git Copyright (C) 2021 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-apple-darwin10 --target=arm-none-eabi". 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". =cmd-param-changed,param="pagination",value="off" 0x08000382 in ?? () 1: (834) <-1015-thread-info 1: (835) ->1015^done,threads=[{id="1",target-id="Thread 1",frame={level="0",addr="0x08000c94",func="Reset_Handler",args=[],file="startup_stm32f103x6.s",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/startup_stm32f103x6.s",line="65",arch="armv7"},state="stopped"}],current-thread-id="1" 1: (835) ->(gdb) 1: (836) 1015: elapsed time 1 1: (843) <-1016-stack-list-frames 0 1000 1: (843) ->1016^done,stack=[frame={level="0",addr="0x08000c94",func="Reset_Handler",file="startup_stm32f103x6.s",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/startup_stm32f103x6.s",line="65",arch="armv7"}] 1: (843) ->(gdb) 1: (845) 1016: elapsed time 1 1: (847) Send Event AD7ProcessInfoUpdatedEvent 1: (853) Send Event AD7ThreadCreateEvent 1: (860) <--exec-continue 1: (860) ->^running 1: (860) ->*running,thread-id="all" 1: (861) ->(gdb) 1: (864) ->=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0800022e",func="main",file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",thread-groups=["i1"],times="1",original-location="main"} 1: (867) ->~"\n" 1: (867) ->~"Breakpoint 1, main () at Core/Src/main.c:74\n"

Breakpoint 1, main () at Core/Src/main.c:74 1: (867) ->~"74\t HAL_Init();\n" 74 HAL_Init(); 1: (867) ->stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x0800022e",func="main",args=[],file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",arch="armv7"},thread-id="1",stopped-threads="all" 1: (867) <-1017-stack-list-frames 0 1000 1: (867) ->1017^done,stack=[frame={level="0",addr="0x0800022e",func="main",file="Core/Src/main.c",fullname="/Users/maxfield/Desktop/STM32_Projects/blink2/Core/Src/main.c",line="74",arch="armv7"}] 1: (867) ->(gdb) 1: (867) 1017: elapsed time 0 1: (871) Send Event AD7ExceptionEvent Execute debugger commands using "-exec ", for example "-exec info registers" will list registers in use (when GDB is the debugger) 1: (928) <-1018-stack-list-arguments 0 0 0 1: (929) ->1018^done,stack-args=[frame={level="0",args=[]}] 1: (929) ->(gdb) 1: (929) 1018: elapsed time 1 1: (1049) <-1019-var-create - "counter" 1: (1050) ->1019^done,name="var1",numchild="0",value="0",type="int16_t",has_more="0" 1: (1050) ->(gdb) 1: (1050) 1019: elapsed time 0 1: (1403) <-1020-stack-list-variables 0 1: (1403) ->1020^done,variables=[] 1: (1403) ->(gdb) 1: (1404) 1020: elapsed time 1 1: (4330) <--exec-continue 1: (4331) ->^running 1: (4331) ->*running,thread-id="all" 1: (4331) ->(gdb)

haneefdm commented 1 year ago

Note: the showDevDebugOutput is not shown in the intellisense suggestions:

Not sure why. The best way to know the left over attributes is to just type two double quotes and the Intellisense will pop up but you may have to scroll. I am not sure why whey are not sorted.

image

Everything is also documented in https://github.com/Marus/cortex-debug/blob/master/debug_attributes.md

haneefdm commented 1 year ago

Could we try this. While we are in a state that the pause button has no effect, enter the following in the Debug Console

-exec-interrupt

It should pause the debugger almost immediately. I want to know this part actually works. I dont know why VSCode is not sending us a request to actually pause - perhaps it thinks that the session hasn't even started yet.

haneefdm commented 1 year ago

Oh wait. You are not using our debugger at all. You are using Microsofts debugger. Our debugger type is cortex-debug. You probably have cppdbg. No wonder II was all confused. Our setup is TOTALLY different.

https://github.com/Marus/cortex-debug/wiki/Black-Magic-Probe-Specific-Configuration

wmaxfield commented 1 year ago

I APOLOGIZE!!!!!

I TRULY thought I was using BMP!!! I don't understand the launch.json and the script I was given is wrong. I replaced it with yours AND IT WORKS!

I apologize Again. I WAS WRONG!

Yours works well!

haneefdm commented 1 year ago

You may be using BMP more than likely but you were using microsoft's debugger. Not ours.

haneefdm commented 1 year ago

I am closing this as there is not much more to do..

Btw, I had a long relationship with PSoC5 (I was one of the architects).