Linux App Visual Studio Code¶
Objective¶
This wiki page will describe how to setup Visual Studio Code so it can be used to build and debug an ARM Linux user-level program on the AM62x.
References¶
- https://code.visualstudio.com/docs/cpp/cmake-quickstart
- https://stackoverflow.com/questions/76203791/automating-yocto-sdk-environment-variable-setup-in-vscode-for-cross-compile-with/76355581#76355581
- https://code.visualstudio.com/docs/cpp/cmake-linux
General setup¶
- Install and setup visual studio code. See vscode_setup
- Make target name. See ssh_target_naming_and_port_forwarding
- Information on VSCode tasks and launch files. See vscode_tasks_and_launch
- Download and install CL's processor SDK toolchain. See CL_SDK_download_and_installation
Vscode CMake Hello World Example¶
- Create a project directory
mkdir helloworld cd helloworld code .
- Open the Command Palette
Ctrl Shift P
and run theCMake: Quick Start
command:- Enter name: "Hello_World"
- Language: C
- Project Type: Executable
- Additional Options: CTest
- CMake: Edit User-Local CMake Kits
- Add the following code to the end of
cmake-tools-kits.json
Replace <CRITICAL_LINK_PROCESSOR_SDK> with location of toolchain installed in General Setup
Example:/home/<yourhome>/arago-2023.10-aarch64-linux-tisdk-mitysom-am62x-SDK10.01.10_43
{ "name": "CL SDK 10.01 am62x", "compilers": { "C": "<CRITICAL_LINK_PROCESSOR_SDK>/sysroots/x86_64-arago-linux/usr/bin/aarch64-oe-linux/aarch64-oe-linux-gcc", "CXX": "<CRITICAL_LINK_PROCESSOR_SDK>/sysroots/x86_64-arago-linux/usr/bin/aarch64-oe-linux/aarch64-oe-linux-g " }, "environmentSetupScript": "<CRITICAL_LINK_PROCESSOR_SDK>/environment-setup", "toolchainFile": "<CRITICAL_LINK_PROCESSOR_SDK>/sysroots/x86_64-arago-linux/usr/share/cmake/OEToolchainConfig.cmake" }
- Add the following code to the end of
- Open the Command Palette
Ctrl Shift P
and run theCMake: Select a kit
command:- Select kit for helloworld: CL SDK 10.01 am62x
- Open the Command Palette
Ctrl Shift P
and run theCMake: Configure
command - Open the Command Palette
Ctrl Shift P
and run theCMake: Build
command or press F7 (default hotkey) - Copy the Hello_World binary to your target
scp build/Hello_World target_62x:
- Run the program
ssh target_62x ./Hello_World
Additional CMake Commands¶
- CMake: Clean - Cleans the build environment
- CMake: Clean Rebuild - Cleans the build environment and then rebuilds
- CMake: Select Variant - Easily change from debug build to release, and others
Debugging¶
- Create a launch.json file
- In the "Run and Debug" tab on the left side of the vscode window select "create a launch.json file"
- Copy the following into the launch.json file
{ "version": "0.2.0", "configurations": [ { "type": "cppdbg", "request": "launch", "name": "Attach to target_62x", "program": "${workspaceFolder}/build/Hello_World", "miDebuggerServerAddress": "localhost:10000", "stopAtEntry": true, "externalConsole": false, "MIMode": "gdb", "cwd": "${workspaceRoot}", "valuesFormatting": "prettyPrinters", "miDebuggerPath": "/usr/bin/gdb-multiarch" }, ] }
- Debug the program
- start gdbserver on target
ssh target_62x gdbserver :10000 ./Hello_World
- start debug session
- In the "Run and Debug" tab select Attach to target_62x
- Should stop with arrow at the std::cout
- Select "continue" in the debug toolbar or press F5
- Should see "Hello, from Hello_World!" in ssh console
- Click the disconnect icon or shift F5
- start gdbserver on target
- VSCode debugger quirks
- Only plant or remove breakpoints when the target is stopped, not when the target is running.
- Only disconnect a debug session when the target is stopped.
- Doing these operations while the target is running will cause confusion. You may have to kill the gdbserver manually on the target and you will have to start a new debug session.
Summary¶
A sample debug session with a simple hello world project has been demonstrated.
Go to top