Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Step Into C++ Code? (Read 3249 times)
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Step Into C++ Code?
Feb 3rd, 2022 at 8:12pm
Print Post  
Hi! I just started using VisualMicro.  I'm an experienced developer and have used Visual Studio A LOT over the years.

I have an Adafruit Feather M0 Bluefruit LE I'm using VisualMicro with to run some BLE examples from Adafruit.

Adafruit provides this Arduino library with examples.  It works great.  It's in C++.  What I'd *REALLY* like to do though is step through the code and I'm having a problem getting to the C++ code.

I have VisualMicro installed in Visual Studio 2022 Community Edition.  I'm able to load an Adafruit BLE example using it.  It builds, flashes it to my Adafruit board and runs fine.  I'm even able to set breakpoints in the INO code of the example and when debugging these breakpoints get hit.

The one problem is that when hitting F11 it's not stepping into the Adafruit C++ code as one might expect, but instead it will just jump to the next INO breakpoint.

I've tried to load the C++ code into Visual Studio and add breakpoints to it as well, but they don't get hit.

So, I'm wondering if VisualMicro is only meant to allow stepping through INO code or if I'm doing something wrong?  Anyone?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2145
Joined: Feb 13th, 2019
Re: Step Into C++ Code?
Reply #1 - Feb 3rd, 2022 at 9:57pm
Print Post  
It depends which debugging configuration you are using on the vMicro > Debugger > Debug option?

Debug:Serial
Does not currently allow stepping through code, however a vast amount of conditional breaks can be set, and conditions to trigger them added (as well as variable watches etc), as well as needing no additional hardware besides the board itself and the normal USB-Serial connection to your PC.

Debug: Hardware
Often requires an external debug probe to allow GDB debugging, which does allow the step action. The Adafruit Feather M0 Bluefruit LE is running the ATSAMD21G18 processor which should work as shown on the below page:
https://www.visualmicro.com/page/SAMD-Debugging.aspx

For this board I believe you need an external debugger e.g. JLink, BlackMagic, AtmelICE, etc...  and will also require some soldering onto the  SWCLK and SWDIO pads on the bottom of the board, example from Adafruit below:
https://learn.adafruit.com/make-a-simple-debugging-featherwing-for-the-m0/overvi...
  
Back to top
 
IP Logged
 
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Re: Step Into C++ Code?
Reply #2 - Feb 3rd, 2022 at 11:51pm
Print Post  
Hi Simon - Thanks for the quick reply.  As luck would have it, I do have a Segger J-Link debugger like the one shown in your link.  I've successfully used it with the Adafruit board in Microchip Studio too!

However, I'm having problems using it with VisualMicro.

One problem I seem to be having properly configuring it with VisualMicro is COM ports are the only things that show in the window third from the left as circled in my screenshot below.



Notice how this differs from your image:



Despite having selected hardware debugging it seems something is still not right since COM ports are still showing up as shown below:



But it seems I have everything configured correctly in my first screen so I'm not sure what the problem is.

Any thoughts?
  
Back to top
 
IP Logged
 
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Re: Step Into C++ Code?
Reply #3 - Feb 4th, 2022 at 12:16am
Print Post  
I got a little farther.  I see I can add more settings to the Toolbar and have them set as shown below:



However, when trying to debug I get the following:



The debug output window in Visual Studio shows this:

Code
Select All
Starting: "C:\ProgramData\vmicro\tools\openocd-0.10.0.20200213\bin/openocd.exe" -d2 -l feather_m0\Debug/bleuart_cmdmode.ino_DebugOpenOCD.log}" -s "C:\ProgramData\vmicro\tools\openocd-0.10.0.20200213/scripts/" -f "interface/jlink.cfg" -c "transport select swd" -f ariants/feather_m0/openocd_scripts/feather_m0.cfg" -c "init; reset halt"
Starting: cc\9-2019q4/bin\arm-none-eabi-gdb.exe" --interpreter=mi
"C:\ProgramData\vmicro\tools\openocd-0.10.0.20200213\bin/openocd.exe" exited with code 1 (0x1).
 



Those paths for both arm-none-eabi-gdb.exe and openocd.exe are good.  I verified them.

Any idea what the problem is?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2145
Joined: Feb 13th, 2019
Re: Step Into C++ Code?
Reply #4 - Feb 4th, 2022 at 10:12am
Print Post  
Thanks for the detail on where you have got to.

Can you enable the below options:
vMicro > Compiler > Verbose
vMicro > Compiler > Show Build Properties
vMicro > Uploader > Verbose

And then perform a build, and then try Debug > Attach to Process.

Please then attach the full output from the Output > Micro Build screen as a text file, and also attach the below log file which is created by OpenOCD:
Code
Select All
ather_m0\Debug/bleuart_cmdmode.ino_DebugOpenOCD.log 

  
Back to top
 
IP Logged
 
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Re: Step Into C++ Code?
Reply #5 - Feb 5th, 2022 at 2:27pm
Print Post  
Sorry for the late reply, I was very busy yesterday with work (this is a hobby project).

Okay, the bleuart_cmdmode.ino_DebugOpenOCD.log is very small and simple:

Code
Select All
swd
Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
Error: No J-Link device found. 



I made sure I had everything hooked up correctly with the debugger by starting Microchip Studio and verifying I could step through code using it.

It sounds like I might need to install the Zadig USB driver.  Is that right?  ...If so, I don't understand why I need to install it when Microchip Studio does not need any additional drivers.  Any idea why?

  
Back to top
 
IP Logged
 
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Re: Step Into C++ Code?
Reply #6 - Feb 6th, 2022 at 6:23pm
Print Post  
Hmmmmmm....  I went ahead and installed the Zadig driver as shown:



But still got the same results in bleuart_cmdmode.ino_DebugOpenOCD.log when trying to debug:

Code
Select All
swd
Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
Error: No J-Link device found. 



One thing I noticed is the Zadig window doesn't seem quite right:



My Segger J-Link debugger is indeed plugged in and turned on.  I'd expect that to show up as a device in Zadig, right?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2145
Joined: Feb 13th, 2019
Re: Step Into C++ Code?
Reply #7 - Feb 7th, 2022 at 2:05pm
Print Post  
Thanks for the detail.

Visual Micro uses OpenOCD to communicate with the debugger, and this tool requires the WinUSB Driver installed by Zadig to communicate with the JLink.  Microchip studio uses a different system directly through the JLink default drivers.

To install the driver with Zadig, you will need to click the Options > List all devices to get the JLink to show up.  Then you can select it to install the WinUSB Driver:
https://www.visualmicro.com/page/Zadig-Driver-Installation-Guide.aspx
  
Back to top
 
IP Logged
 
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Re: Step Into C++ Code?
Reply #8 - Feb 8th, 2022 at 2:23am
Print Post  
Thank you, Simon.  I believe I now have the Zadig driver properly installed.

I've reopened the Arduino project and set a breakpoint in setup() and start debugging as shown below:



After the program compiles and is flashed to the Adafruit Feather M0 I don't really get into any sort of expected interactive debug mode.  The Debug window in Visual Studio shows this:

Code
Select All
For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
0x00000288 in ?? ()
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at res\arduino\main.cpp:35
35	  init(); 



And the bleuart_cmdmode.ino_DebugOpenOCD.log has this in it:
Code
Select All
swd
Info : J-Link V10 compiled Oct  8 2019 14:57:57
Info : Hardware version: 10.10
Info : VTarget = 3.303 V
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : at91samd21g18.cpu: external reset detected
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x41000000 pc: 0x00000288 msp: 0x20002dd8
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'gdb' connection on tcp/3333
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0x3776bffa
Info : SWD DPIDR 0x0bc11477
Error: Failed to read memory at 0x3776bffa
 



It seems like I'm really close, it's just that the IDE is not in any sort of interactive mode.  It doesn't show that it's at any breakpoint nor does it allow me to step into code, "continue", etc...

Any thoughts?

  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2145
Joined: Feb 13th, 2019
Re: Step Into C++ Code?
Reply #9 - Feb 8th, 2022 at 10:32am
Print Post  
Thanks for the detail, and it appears to have connected to the JLink probe correctly, and found the board.

Your code appears to be waiting infinitely for the serial port to connect before it can reach that breakpoint, however the output shown shows it has stopped at the init() function in the core.

So we can see all environmental settings, if you enable the below options:
vMicro > Compiler > Verbose
vMicro > Compiler > Show Build Properties
vMicro > Uploader > Verbose

Then perform a Build > Clean Solution.
Then build the project, upload it and attach the debugger.

Please attach in a text file, all output from the Output Window > Micro Build, and from Debug as well.

  
Back to top
 
IP Logged
 
Terence D
Newbies
*
Offline


Posts: 7
Joined: Feb 3rd, 2022
Re: Step Into C++ Code?
Reply #10 - Feb 9th, 2022 at 2:49am
Print Post  
Hi Simon - Sounds good.  I just followed your instructions and have attached the output from building, uploading and debugging.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2145
Joined: Feb 13th, 2019
Re: Step Into C++ Code?
Reply #11 - Feb 23rd, 2022 at 6:11pm
Print Post  
Sorry for the delayed response.

If you go to this project, and use the vMicro > Add Code > Add Custom GDB Debugger button, this will add two files to the project.

If you then open the SAMD_ZERO.Debug.debugger_launch.json file, and paste in the JSON from your logs (Its below, but can also be obtained by running Debug > Attach to Process, and scrolling to the end of the Output Window). The only edit I have made is to remove the "reset halt" from the end of the debugServerArgs command:
Code
Select All
{
  "serverLaunchTimeout": 5000,
  "filterStdout": false,
  "filterStderr": true,
  "targetArchitecture": "arm",
  "stopAtEntry": false,
  "externalConsole": false,
  "MIMode": "gdb",
  "MIDebuggerServerAddress": "localhost:3333",
  "cwd": afruit_feather_m0\\Debug",
  "MIDebuggerPath": ne-eabi-gcc\\9-2019q4/bin\\arm-none-eabi-gdb.exe",
  "MIDebuggerArgs": "",
  "debugServerPath": "C:\\ProgramData\\vmicro\\tools\\openocd-0.10.0.20200213\\bin/openocd.exe",
  "debugServerArgs": "-d2 -l adafruit_feather_m0\\Debug/bleuart_cmdmode.ino_DebugOpenOCD.log}\" -s \"C:\\ProgramData\\vmicro\\tools\\openocd-0.10.0.20200213/scripts/\" -f \"interface/jlink.cfg\" -c \"transport select swd\" -f md\\1.7.8/variants/feather_m0/openocd_scripts/feather_m0.cfg\" -c \"init\"",
  "setupCommands": [],
  "program": eather_m0/Debug/bleuart_cmdmode.ino.elf",
  "logging": {
    "moduleLoad": false,
    "trace": false,
    "engineLogging": false,
    "programOutput": false,
    "exceptions": false,
    "traceResponse": false
  },
  "visualizerFile": afruit_feather_m0\\Debug\\debugger_tmp.natvis",
  "showDisplayString": true
} 



Then change the Debugger selection from "Segger Jlink (SWD)" and change it to Manual/Custom.

Hopefully it won't reset in the core init() code, and will start the debugging session fully next time you try the Debug > Attach to Process option.

If there is still an issue with Debug > Start Debugging, there could be a timing issue at play as well.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint