|
1 | 1 | # VSCode IoT.js Debug
|
2 | 2 | IoT.js and JerryScript debug adapter for Visual Studio Code.
|
| 3 | + |
| 4 | +- [Introduction](#introduction) |
| 5 | +- [Features](#features) |
| 6 | +- [Requirements](#requirements) |
| 7 | +- [How to start](#how-to-start) |
| 8 | +- [How to use](#how-to-use) |
| 9 | +- [License](#license) |
| 10 | + |
| 11 | +# Introduction |
| 12 | +`IoT.js Debug` is a debugger extension for [Visual Studio Code](https://code.visualstudio.com/) that lets you debug the code which is running on a device and lets you upload your code to the device, directly from the VSCode over websocket communication. |
| 13 | + |
| 14 | +# Features |
| 15 | +Available Control commands: |
| 16 | +- Continue command |
| 17 | +- Pause command |
| 18 | +- Step-over command |
| 19 | +- Step-in command |
| 20 | +- Step-out command |
| 21 | +- Disconnect command |
| 22 | + |
| 23 | +Available features: |
| 24 | +- Call stack display |
| 25 | +- Handle source receive from the engine |
| 26 | + |
| 27 | +Currently in Progress features or commands: |
| 28 | +- Set/Remove breakpoint |
| 29 | +- Source sending to the engine |
| 30 | +- Watch (evaluate expression) |
| 31 | + |
| 32 | +# Requirements |
| 33 | +- The latest Vscode which is available [here](https://code.visualstudio.com/Download). |
| 34 | +- An [IoT.js](https://github.com/Samsung/iotjs) or a [JerryScript](https://github.com/jerryscript-project/jerryscript) as an engine to run your code. |
| 35 | + |
| 36 | +- (For development) Requires [node.js](https://nodejs.org/en/) v8.x.x or higher (latest one is recommended) and [npm](https://www.npmjs.com) 5.x.x or higher to be able to work properly. |
| 37 | + |
| 38 | +# How to start |
| 39 | +Getting the sources: |
| 40 | + |
| 41 | +```sh |
| 42 | +# Clone the repository to your local drive: |
| 43 | +$ git clone https://github.com/knightburton/vscode-iotjs-debug |
| 44 | + |
| 45 | +# Move into the directory |
| 46 | +$ cd vscode-iotjs-debug |
| 47 | +``` |
| 48 | + |
| 49 | +The project requires node.js to build, the best way to install the node and the npm is the nvm (Node Version Manager): |
| 50 | + |
| 51 | +```sh |
| 52 | +# Install the latest nvm with the following command |
| 53 | +$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash |
| 54 | + |
| 55 | +# Reload your .bashrc |
| 56 | +$ source ~/.bashrc |
| 57 | +``` |
| 58 | + |
| 59 | +Use the proper node.js and node package manager version: |
| 60 | +```sh |
| 61 | +# Install the latest node.js and npm with the nvm tool |
| 62 | +$ nvm install 9 |
| 63 | + |
| 64 | +# If you have already installed the node.js and npm then make sure you are using the right version in the project folder |
| 65 | +$ nvm use 9 |
| 66 | +``` |
| 67 | + |
| 68 | +Install the project dependencies: |
| 69 | +```sh |
| 70 | +npm install |
| 71 | +``` |
| 72 | + |
| 73 | +For the first time you have to build the project to be able to start the extension host, this will build the project into the `out` folder: |
| 74 | +```sh |
| 75 | +npm run compile |
| 76 | +``` |
| 77 | + |
| 78 | +To start the extension you have to open the project in VSCode and you have to navigate to the Debug view (Ctrl+Shift+D). |
| 79 | +At the top of the debug panel you have to select the `Extension` option from the dropdown menu if you want to run the extension (or you have to select the `Extension Test` if you want to run the unit tests). |
| 80 | +After you selected the `Extension` option you can start the debug session by pressing the `F5` key or click on the green triangle shaped button next to the dropdown menu. |
| 81 | +This debug session will open up a new VSCode (Extension host) where our extension is installed and available. |
| 82 | + |
| 83 | +**Note:** When the extension host window is opened you do not have to rebuild the project if you make any changes on the code because vscode will automatically do that, the only thing you have to do is restart the main debug session in the main vscode window by hit the restart button in the debug action bar or press the Ctrl+Shift+F5 key combination. |
| 84 | + |
| 85 | +# How to use |
| 86 | +After the extension is running in the extension host window you have to open (or create a new) project folder where you have to define a `launch.json` configuration file inside the `.vscode` folder. In case of IoT.js Debug this configuration looks like this: |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "version": "0.2.0", |
| 91 | + "configurations": [ |
| 92 | + { |
| 93 | + "name": "IoT.js: Attach", |
| 94 | + "type": "iotjs", |
| 95 | + "request": "attach", |
| 96 | + "address": "localhost", |
| 97 | + "port": 5001, |
| 98 | + "localRoot": "${workspaceRoot}", |
| 99 | + "stopOnEntry": false, |
| 100 | + "debugLog": true |
| 101 | + }, |
| 102 | + ] |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +Now you can connect to a running engine. |
| 107 | +If you are using IoT.js you have to do the following: |
| 108 | + |
| 109 | +```sh |
| 110 | +# Open up a new terminal window and navigate into the IoT.js root folder |
| 111 | +$ cd path/to/the/iotjs |
| 112 | + |
| 113 | +# Build the IoT.js with the following switches |
| 114 | +$ ./tools/build.py --buildtype=debug --jerry-debugger |
| 115 | + |
| 116 | +# If you want to debug the IoT.js javascript modules |
| 117 | +# then you have to turn off the snapshot in the IoT.js build |
| 118 | +$ ./tools/build.py --buildtype=debug --jerry-debugger --no-snapshot |
| 119 | + |
| 120 | +# Run the IoT.js with the following switches |
| 121 | +$ ./build/x86_64-linux/debug/bin/iotjs --start-debug-server {file} |
| 122 | + |
| 123 | +# To run with diferent port (the default is 5001) |
| 124 | +$ ./build/x86_64-linux/debug/bin/iotjs --start-debug-server --jerry-debugger-port={number} {file} |
| 125 | + |
| 126 | +# To run with show opcodes |
| 127 | +$ ./build/x86_64-linux/debug/bin/iotjs --start-debug-server --show-opcodes {file} |
| 128 | + |
| 129 | +# To run with source waiting mode (allows the on-the-fly source code sending) |
| 130 | +# NOTE: This is not fully supported for now |
| 131 | +$ ./build/x86_64-linux/debug/bin/iotjs --start-debug-server --debugger-wait-source |
| 132 | +``` |
| 133 | + |
| 134 | +If you are using only JerryScript you have to do the following: |
| 135 | + |
| 136 | +```sh |
| 137 | +# Open up a new terminal window and navigate into the JerryScript root folder |
| 138 | +$ cd path/to/the/jerryscript |
| 139 | + |
| 140 | +# Build the JerryScript with the following command |
| 141 | +$ ./tools/build.py --jerry-debugger ON --jerry-libc OFF |
| 142 | + |
| 143 | +# To build without default port. |
| 144 | +$ ./tools/build.py --jerry-debugger ON --jerry-libc OFF --jerry-port-default OFF |
| 145 | + |
| 146 | +# Run JerryScript with the following switches |
| 147 | +# The --log-level 3 is strongly recommended to see what is happening on server side |
| 148 | +$ ./build/bin/jerry --start-debug-server --log-level 3 {files} |
| 149 | + |
| 150 | +# To run with diferent port |
| 151 | +$ ./build/bin/jerry --start-debug-server --debug-port {number} {file} |
| 152 | + |
| 153 | +# To run with source waiting mode (allows on-the-fly source code sending) |
| 154 | +# NOTE: This is not fully supported for now |
| 155 | +$ ./build/bin/jerry --start-debug-server --debugger-wait-source |
| 156 | +``` |
| 157 | + |
| 158 | +After the engine is running you can start the debug session inside the extension host by pressing the `F5` key or click on the green triangle in the debug panel. |
| 159 | +If the client (VSCode extension) is connected then you have to see that file which is running inside the engine in the vscode editor and you have to see where the execution is stopped. Now you can use the VSCode debug action bar to control the debug session. |
| 160 | + |
| 161 | +# License |
| 162 | +IoT.js Code is Open Source software under the [Apache 2.0 license](LICENSE). Complete license and copyright information can be found within the code. |
0 commit comments