Editing UsingVSCode

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
= Source level debugging OOT C++ modules with Visual Studio Code =
+
= Building and source level debugging OOT C++ modules with Visual Studio Code =
  
 
The following instructions were created using VSCode v1.33.1 on Ubuntu 18.04
 
The following instructions were created using VSCode v1.33.1 on Ubuntu 18.04
Line 5: Line 5:
 
== Prerequisites ==
 
== Prerequisites ==
  
'''In some versions, VSCode must be run as sudo to debug using GDB.  Try without sudo first'''
+
'''VSCode must be run as sudo to debug using GDB.  Haven't found a way around this yet.'''
  
 
  <nowiki>
 
  <nowiki>
Line 13: Line 13:
  
 
NOTE: Using . as the user-data-dir will litter the current directory with files and folder.
 
NOTE: Using . as the user-data-dir will litter the current directory with files and folder.
 
NOTE: The most recent versions of vscode do not appear to require code to be run as sudo, so try without first
 
 
  
 
== Instructions ==
 
== Instructions ==
Line 24: Line 21:
 
2) Build the target OOT module and install into the pybombs prefix (or whatever other install method was used for GNU Radio)
 
2) Build the target OOT module and install into the pybombs prefix (or whatever other install method was used for GNU Radio)
  
* '''Be sure when building the OOT module, use -DCMAKE_BUILD_TYPE=Debug as one of the cmake flags''', e.g:
+
* Be sure when building the OOT module, use -DCMAKE_BUILD_TYPE=Debug as one of the cmake flags, e.g:
  
 
  <nowiki>
 
  <nowiki>
Line 33: Line 30:
 
* In GRC, it is helpful to spool a temporary .py by changing the ID in options, generating the flowgraph, then changing the id back, so that direct changes to the python are not overwritten when the flowgraph is run from GRC
 
* In GRC, it is helpful to spool a temporary .py by changing the ID in options, generating the flowgraph, then changing the id back, so that direct changes to the python are not overwritten when the flowgraph is run from GRC
  
 
+
4) Add a sleep into the python file
=== Launching from VsCode ===
 
 
 
The simplest way to achieve source level debugging is to launch the top level flowgraph (python file) from VsCode.
 
 
 
a) Set breakpoints in VSCode that you want to hit
 
* Like any other IDE with source level debugging, these can also be set while the code is free running
 
 
 
b) In VSCode, Debug --> Open Configurations brings up a "Set Environment" selection
 
* Choose GDB
 
* This brings up launch.json
 
 
 
c) Add Launch type of configuration
 
* Debug --> Add Configuration
 
* Select C/C++ (gdb) Launch
 
* This inserts some code
 
 
 
d) Modify the configuration so that the program to debug is python (either python2 or python3 depending gnuradio branch)
 
* The launch.json should look like this:
 
<nowiki>
 
{
 
    "version": "0.2.0",
 
    "configurations": [
 
       
 
        {
 
            "name": "(gdb) Launch",
 
            "type": "cppdbg",
 
            "request": "launch",
 
            "program": "/usr/bin/python3",
 
            "args": ["-u","/path/to/flowgraph.py"],
 
            "stopAtEntry": false,
 
            "cwd": "${workspaceFolder}",
 
            "environment": [],
 
            "externalConsole": false,
 
            "MIMode": "gdb",
 
            "setupCommands": [
 
                {
 
                    "description": "Enable pretty-printing for gdb",
 
                    "text": "-enable-pretty-printing",
 
                    "ignoreFailures": true
 
                }
 
            ]
 
        },
 
 
 
}</nowiki>
 
 
 
 
 
e) From the menu Debug:Start Debugging (F5) will start the python and land on your breakpoints!
 
 
 
=== Attaching to Process ===
 
 
 
Another alternative is to attach to already running process.  This is useful for more complicated systems and flowgraphs
 
 
 
a) (optional) Add a sleep into the python file
 
  
 
* Place after the import statement for your module
 
* Place after the import statement for your module
Line 95: Line 39:
 
import time; time.sleep(15)</nowiki>
 
import time; time.sleep(15)</nowiki>
  
b) Set breakpoints in VSCode that you want to hit
+
5) Set breakpoints in VSCode that you want to hit
 
* Like any other IDE with source level debugging, these can also be set while the code is free running
 
* Like any other IDE with source level debugging, these can also be set while the code is free running
  
c) In VSCode, Debug --> Open Configurations brings up a "Set Environment" selection
+
6) In VSCode, Debug --> Open Configurations brings up a "Set Environment" selection
 
* Choose GDB
 
* Choose GDB
 
* This brings up launch.json
 
* This brings up launch.json
  
d) Add Attach type of configuration
+
7) Add Attach type of configuration
 
* Debug --> Add Configuration
 
* Debug --> Add Configuration
 
* Select C/C++ (gdb) Attach
 
* Select C/C++ (gdb) Attach
 
* This inserts some code
 
* This inserts some code
  
e) Modify the configuration so that the program to debug is python (either python2 or python3 depending gnuradio branch)
+
8) Modify the configuration so that the program to debug is python (either python2 or python3 depending gnuradio branch)
 
* The launch.json should look like this:
 
* The launch.json should look like this:
 
  <nowiki>
 
  <nowiki>
Line 137: Line 81:
  
  
f) From a terminal, launch the python script which uses your module in a flowgraph
+
9) From a terminal, launch the python script which uses your module in a flowgraph
  
g) From VSCode, Start Debugging (F5), and you will be prompted to select the process to attach to
+
10) From VSCode, Start Debugging (F5), and you will be prompted to select the process to attach to
  
h) Start typing python, and then choose the python instance which is running your flowgraph
+
11) Start typing python, and then choose the python instance which is running your flowgraph
  
i) At this point (or after the script passes time.sleep) GDB should attach and breakpoints will be active
+
12) At this point (or after the script passes time.sleep) GDB should attach and breakpoints will be active

Please note that all contributions to GNU Radio are considered to be released under the Creative Commons Attribution-ShareAlike (see GNU Radio:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)