Changes

Jump to: navigation, search

BELK-AN-009: Using Visual Studio Code for remote debugging

1,588 bytes added, 08:48, 19 February 2020
no edit summary
{{Applies To Bora}}
{{Applies To BoraX}}
{{AppliesToVisualStudioCode}}
{{InfoBoxBottom}}
 
{{WarningMessage|text=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.}}
!Notes
|-
|4.0.0/21.0.0
|June 2019
|[[BELK/BXELK_software_components#BELK_4.0.0_.2F_BXELK_2.0.0|4.0.0 / 2.0.0]]
== Introduction ==
[https://code.visualstudio.com/ Visual Studio Code] (VSC VSCode for short) is a powerful integrated development environment (IDE). In the last years, it has gotten growing grown in 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 development specifically, 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 is assumed that the reader is familiar with at least one of [[Bora_Embedded_Linux_Kit_(BELK/)|Bora Embedded Linux Kit]] (BELK for short) or [[BoraX_Embedded_Linux_Kit_(BXELK)|BoraX Embedded Linux Kit]] (BXELK kit for short), and with VSCVSCode.
==Host configuration==
[[FileThe procedure described in this document was tested specifically with the following version of VSCode:BELK<pre>Version: 1.35.0Commit: 553cfb2c2205db5f15f3ee8395bbd5cf066d357dDate: 2019-AN06-04T01:13:26.790ZElectron: 3.1.8Chrome: 66.0.3359.181Node.js: 10.2.0V8: 6.6.346.32OS: Linux x64 3.13.0-009170-workspace.png|thumb|center|600px|VSC workspace]]generic</pre>
==Target configuration==
The target has to be configured to mount the root file system over NFS. Please refer to [https://wiki.dave.eu/index.php/BELK/BXELK_Quick_Start_Guide#Target_configuration_for_the_development_stage_.28net_nfs.29|this link] for more details.
The example project associated with this application note should be located copied in this directory of the host machine: <code>/bora/rfs/belk-4.0.0/home/root/hello</code>. This directory is seen by the target machine as <code>/home/root/hello</code>.
Please note that you need to change the permissions of the directory <code>/bora/rfs/belk-4.0.0/home/root/hello</code> in order to allow the user <code>dvdk</code> to access it without any restrictions:
drwxr-xrwx 4 root root 4096 Jun 12 14:55 hello/
</pre>
 
 
After completing this step, you should see these files:
[[File:BELK-AN-009-tree.png|center|thumb|600px|Files of the example project]]
==The example project==
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 VSCVSCode-controlled debugging session. The following image shows the files that the VSCode workspace consists of.[[File:BELK-AN-009-workspace.png|thumb|center|600px|VSCode workspace]] 
The following image shows the files that the VSC workspace consists of. The most relevant are:
*<code>hello.c</code>
**The source file of the program
*<code>Makefile</code>
**This file allows building the program manually from the command line. It is also used by VSC VSCode to build the program before starting a debug session.
*<code>remote-debugging.sh</code>
**This script is invoked by VSC VSCode to
***Build the program for the embedded target
***Start a remote debug session.Kill the gdbserver instance running on the target
*<code>cross-build.sh</code>
**This script is invoked in turn by <code>remote-debugging.sh</code> to run the cross build process. The final command that triggers the actual building process is <code>make hello</code>, that is the same command used to build the program manually.*<code>start-gdbserver-loop.sh</code>**This script is invoked by <code>remote-debugging.sh</code> to start only once on the target side; it guarantees that there is always a <code>running instance of the gdbserver</code> instance on the target.
*<code>.gdbinit</code>
**In includes initialization 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].
****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, 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.
==Starting a debug session==
In practice, once the target is up and running and the example project is copied onto the host machine as stated previously, follow these steps to start a cross-debugging session.
*Open the VSCode workspace
*Go to the ''Terminal'' panel and open an ssh connection to the target machine
**Once logged, execute the <code>start-gdbserver-loop.sh</code> script as shown in the following image. '''This operation has to be carried out only once, at the beginning of the first debug session'''.
 
 
[[File:BELK-AN-009-gdbserver.png|center|thumb|600px|Starting the <code>gdbserver</code> on the target machine]]
 
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'' icon 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|800px|Cross-debugging session]]
[[File:BELK-AN-009-cross-debug.png|thumb|center|600px|Cross debugging session]]
[[File:BELK-AN-009-native-debug.png|thumb|center|600px|Native debugging session]]
==Download==
The source file associated with this application note can be downloaded [https://cloud.dave.eu/ws-reserved-area-belk/AN/009 here]. For accessing the <b><i>BELK Reserved area</i></b>, please contact our [mailto:sales@dave.eu sales department].
4,650
edits

Navigation menu