Changes

Jump to: navigation, search
The example project
[https://code.visualstudio.com/ 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. [https://marketplace.visualstudio.com/VSCode 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 developmentspecifically, 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.
In essence, the followings are the packages that have to be installed:
*[Visual Studio Code https://code.visualstudio.com/DownloadVisual Studio Code] with these extensions
**C/C++
**Native Debug
*<code>sshpass</code> (<code>sudo apt install sshpass</code>)
*<code>gdb</code> (<code>sudo apt install gdb</code>).
  [[File:BELK-AN-009-extensions.png|thumb|center|600px|The two VSC required extensions required.]][[File:BELK-AN-009-workspace.png|thumb|center|600px|VSC workspace]]
==Target configuration==
The example project is the umpteenth flavor of the world-famous [https://en.wikipedia.org/wiki/%22Hello,_World!%22_program "Hello, world!" program]. Source code is available [ here] for download.
The example makes use of a simple <code>Makefile</code> for cross-building. This <code>Makefile</code> can be used either to build the application manually or to build it automatically as part of a VSC-controlled debugging session. The following image shows the files that the VSC workspace consists of.   [[File:BELK-AN-009-workspace.png|thumb|center|600px|VSC workspace]]  The most relevant are:
*<code>hello.c</code>
**The source file of the program
***Start a remote debug session.
*<code>cross-build.sh</code>
**This script is invoked in turn by <code>remote-debugging.sh</code> to run the actual cross build process. The final commands command that triggers the actual building process is <code>make hello</code>, tha tis that is the same command used to build the program manually.
*<code>start-gdbserver.sh</code>
**This script is invoked by <code>remote-debugging.sh</code> to start a <code>gdbserver</code> instance on the target.
*<code>.gdbinit</code>
**In includes initialization scipts scripts that are run by <code>/home/dvdk/bora/sdk/belk-4.0.0/sysroots/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-gnueabi/arm-xilinx-linux-gnueabi-gdb</code> upon startup. For more details, please see [http://man7.org/linux/man-pages/man5/gdbinit.5.html this page].
*<code>launch.json</code>
**In this file two configurations are defined:
****This is used to build and debug the application on the host machine
***<code>(gdb) Cross launch</code>
****This is used to cross build the application on the host machine and to debug it on the target machine
*<code>tasks.json</code>
**In this file two tasks are defined:
***<code>native build</code>
****This is used to build the program for the host target. In this case, the an explicit command is run (<code>gcc -g -o hello.x86 hello.c</code>)
***<code>build and start remote debugging</code>
****As stated before, this task invokes the <code>remote-debugging.sh</code> script. Please note In practice, once the target is up and running and the example project was copied onto the host machine, follow these steps to start a cross-debugging session:*Open the VSC workspace*Select the <code>(gdb) Cross launch</code> configuration*Click on the green ''Start Debugging'' or select the ''Debug->Start Debugging'' menu item. Alternatively, press F5. You should see something like the following picture. It is worth remembering that the scripts take care of killing any <code>gdbserver</code> instance running on the target before starting a new debugging session. This allows starting it with just one click.  [[File:BELK-AN-009-cross-debug.png|thumb|center|600px|Cross debugging session]]
[[File:BELK-AN-009-For the sake of completeness, the native-debug.png|thumb|center|600px|Native debugging session]]is illustrated as well.
[[File:BELK-AN-009-crossnative-debug.png|thumb|center|600px|Cross Native debugging session]]
4,650
edits

Navigation menu