Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

[ANN] Debug .NETMF native code using VS Code #520

Open
josesimoes opened this issue Oct 20, 2016 · 6 comments
Open

[ANN] Debug .NETMF native code using VS Code #520

josesimoes opened this issue Oct 20, 2016 · 6 comments

Comments

@josesimoes
Copy link
Contributor

josesimoes commented Oct 20, 2016

This is a guide to use VS Code as a debugging environment for NETMF native code.
Not a competition or wanting to pick on @cw2 ;) !
The motivation behind it is that I’ve been using VS Code for native code development for quite some time now, and felt that being able to debug it right there would be a nice improvement and would boost productivity.
Anyways, it’s another option for the community members interested in this side of the development.

netmf-core-vscode-debug-1

Requirements:

  • VS Code installed
  • C/C++ VS Code extension
  • OpenOCD installed (pretty much any working distribution will work)
  • ST-LINK (either the device or the equivalent circuit in the development board)

Add the following file (launch.json) in the .vscode directory at the root folder of the NETMF repository .

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NETMF core debug (Windows)",
            "type": "cppdbg",
            "request": "launch",
            "miDebuggerPath": "E:/GNU_Tools_ARM_Embedded/5_4_2016q2/bin/arm-none-eabi-gdb.exe",
            "targetArchitecture": "ARM",
            "program": "E:/GitHub/netmf-interpreter/BuildOutput/THUMB2FP/GCC5.4/le/FLASH/release/STM32F4DISCOVERY/bin/tinyclr.axf",
            "setupCommands": [
                {"text": "target extended-remote localhost:3333"},
                {"text": "file E:/GitHub/netmf-interpreter/BuildOutput/THUMB2FP/GCC5.4/le/FLASH/release/STM32F4DISCOVERY/bin/tinyclr.axf"},
                {"text": "monitor reset halt"}
            ],
            "customLaunchSetupCommands": [
                {"text": "monitor reset init"}
            ],
            "launchCompleteCommand": "exec-continue",
            "debugServerPath": "C:/Program Files (x86)/openocd-0.10.0/bin/openocd.exe",
            "debugServerArgs": "-s \"C:/Program Files (x86)/openocd-0.10.0/bin/scripts/\" -f interface/stlink-v2-1.cfg -f board/stm32f4discovery.cfg",
            "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
            "filterStderr": true,
            "externalConsole": true,
            "cwd": "${cwd}"
        }
    ]
}

A few explanations on what you need to tweak there.
miDebuggerPath: full path to the gdb executable.
program: full path to the .axf output file that results from a successful NETMF build.
setupCommands (the second ‘text’ entry): the same as the previous one.
debugServerPath: full path to the OpenOCD executable.
debugServerArgs: full path to the scripts directory on the OpenOCD installation AND the appropriate .cfg files for the interface and the board. In this example I’m using the STM32F4DISCOVERY board, so I add there the ‘stlink-v2-1.cfg’ for the interface and ‘stm32f4discovery.cfg’ for the board support configuration.
(note the slash on all the paths there)

And that’s it!
Assuming that you have successfully build a NETMF image, have loaded it on the board and that you’ve open the root folder of the NETMF repository with VS Code, you can navigate to the View – Debug menu. You’ll see there the debug interface and the familiar green play button (or F5, if you prefer). Hit that one and the magic will happen.
You can set breakpoints, add watch variables, navigate up and down the call stack and use the toolbar or the familiar keyboard shortcuts to debug the code.
Final note: to have enough info in the compiled output for a decent debug session make sure you set the appropriate flavour to the build command. As an alternative you can always tweak the Microsoft.Spot.system.gcc.targets file. I’ve changed mine in these two lines:

<CC_CPP_TARGETTYPE_FLAGS Condition="'$(FLAVOR)'=='Release'" >$(CC_CPP_TARGETTYPE_FLAGS) -Os -g3 -ggdb</CC_CPP_TARGETTYPE_FLAGS></code>

<ARCH_TARGETTYPE_FLAGS Condition="'$(FLAVOR)'=='Release'" >-Os -g3 -ggdb</ARCH_TARGETTYPE_FLAGS></code>

@piwi1263
Copy link

Nice work, I'll definately try this one. Launch time of the full VS is so .....

@maiorfi
Copy link

maiorfi commented Oct 21, 2016

👍

@techcap
Copy link
Contributor

techcap commented Oct 23, 2016

Very nice!!! Do you know how to integrate with compile key(Ctrl+Shift+B)?

@josesimoes
Copy link
Contributor Author

josesimoes commented Oct 26, 2016

@techcap yes now I do! 😛
Check #524.

@Glober777
Copy link

@josesimoes, I'm a bit new to NETMF, and I'm wondering if the following could also be used to manage Netduino board, any idea?

@techcap
Copy link
Contributor

techcap commented Mar 17, 2017

@josesimoes I was suffered because of debugger disconnection after starting debug mode. I found it was because of power mode which you included in your PR #524.
I really appriciate for your help. Thank you very very much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants