Difference between revisions of "BELK-AN-009: Using Visual Studio Code for remote debugging"

From DAVE Developer's Wiki
Jump to: navigation, search
(Host configuration)
(One intermediate revision by the same user not shown)
Line 35: Line 35:
 
*<code>gdb</code> (<code>sudo apt install gdb</code>).
 
*<code>gdb</code> (<code>sudo apt install gdb</code>).
 
[[File:BELK-AN-009-extensions.png|thumb|center|600px|The two VSC extensions required.]]
 
[[File:BELK-AN-009-extensions.png|thumb|center|600px|The two VSC extensions required.]]
 +
[[File:BELK-AN-009-workspace.png|thumb|center|600px|VSC workspace]]
  
 
==Target configuration==
 
==Target configuration==

Revision as of 14:44, 12 June 2019

Info Box
Bora5-small.jpg Applies to Bora
BORA Xpress.png Applies to BORA Xpress
Warning-icon.png This application note was validated against specific versions of the kit only. It may not work with other versions. Supported versions are listed in the History section. Warning-icon.png

History

Version Date BELK/BXELK version Notes
4.0.0/2.0.0 June 2019 4.0.0 / 2.0.0 First release

Introduction

Visual Studio Code (VSC for short) is a powerful integrated development environment (IDE). In the last years, it has gotten growing popularity among software developers of any kind, thanks to its excellent flexibility. Numerous extensions, native git support, availability for all of the most common platforms are some of the features that have made it so successful.

Even though it was not designed for embedded software development, it is so versatile that it can be used for this purpose as well. This application note shows, for instance, how to configure it in order to remotely debug an application running on the Bora/BoraX platform. As host machine, the Virtual Machine released along with the BELK/BXELK kit was used.

It assumed that the reader is familiar with BELK/BXELK kit and with VSC.

Host configuration

The example here described allows compiling and debugging the application for the host machine too. For this reason, the procedure indicates to install the native gdb debugger as well.

In essence, the followings are the packages that have to be installed:

The two VSC extensions required.
VSC workspace

Target configuration

The target has to be configured to mount the root file system over NFS. Please refer to link for more details.

The example project associated with this application note should be located in this directory of the host machine: /bora/rfs/belk-4.0.0/home/root/hello. This directory is seen by the target machine as /home/root/hello.

Please note that you need to change the permissions of the directory /bora/rfs/belk-4.0.0/home/root/hello in order to allow the user dvdk to access it without any restrictions:

dvdk@vagrant-ubuntu-trusty-64:~/bora/rfs/belk-4.0.0/home/root$ ll
total 16
drwxr-xr-x 3 root root 4096 Jun 12 16:27 ./
drwxr-xr-x 3 root root 4096 Jul 10  2017 ../
-rw------- 1 root root 1102 Jun 12 10:41 .bash_history
drwxr-xrwx 4 root root 4096 Jun 12 14:55 hello/

The example project

The example project is the umpteenth flavor of the world-famous "Hello, world!" program. Source code is available [ here] for download.

The following image shows the files the workspace consists of. The most relevant are:

  • hello.c
    • The source file of the program
  • Makefile
    • This file allows building the program manually from the command line. It is also used by VSC to build the program before starting a debug session.
  • remote-debugging.sh
    • This script is invoked by VSC to
      • Build the program for the embedded target
      • Start a remote debug session.
  • cross-build.sh
    • This script is invoked in turn by remote-debugging.sh to run the actual cross build process. The final commands that triggers the actual building process is make hello, tha tis the same command used to build the program manually.
  • start-gdbserver.sh
    • This script is invoked by remote-debugging.sh to start a gdbserver instance on the target.
  • .gdbinit
    • In includes initialization scipts that are run by . For more details, please see this page.
  • launch.json
    • In this file two configurations are defined:
      • (gdb) Native launch
        • This is used to build and debug the application on the host machine
      • (gdb) Cross launch
        • This is used to build the application on the host machine and to debug it on the target machine
  • tasks.json
    • In this file two tasks are defined:
      • native build
        • This is used to build the program for the host target. In this case, the explicit command is run (gcc -g -o hello.x86 hello.c)
      • build and start remote debugging
        • As stated before, this task invokes the remote-debugging.sh script. Please note