1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

docs: add info on how to setup VSCode for debugging V code (#10329)

This commit is contained in:
Andreas Heissenberger 2021-06-04 16:55:22 +02:00 committed by GitHub
parent 89aab95177
commit 18bebcc3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 115 additions and 3 deletions

View File

@ -129,7 +129,7 @@ For more details and troubleshooting, please visit the [vab GitHub repository](h
* [Structs with reference fields](#structs-with-reference-fields)
* [sizeof and __offsetof](#sizeof-and-__offsetof)
* [Calling C from V](#calling-c-from-v)
* [Debugging generated C code](#debugging-generated-c-code)
* [Debugging](#debugging)
* [Conditional compilation](#conditional-compilation)
* [Compile time pseudo variables](#compile-time-pseudo-variables)
* [Compile-time reflection](#compile-time-reflection)
@ -3825,9 +3825,11 @@ re-creating the original structure exactly.
Alternatively, you may [embed](#embedded-structs) the sub-data-structures to maintain
a parallel code structure.
## Debugging generated C code
## Debugging
To debug issues in the generated C code, you can pass these flags:
### C Backend binaries (Default)
To debug issues in the generated binary (flag: `-b c`), you can pass these flags:
- `-g` - produces a less optimized executable with more debug information in it.
V will enforce line numbers from the .v files in the stacktraces, that the
@ -3860,6 +3862,26 @@ for example `main`, you can use: `-printfn main -o file.c`.
To see a detailed list of all flags that V supports,
use `v help`, `v help build` and `v help build-c`.
**Commandline Debugging**
1. compile your binary with debugging info `v -g hello.v`
2. debug with [lldb](https://lldb.llvm.org) or [GDB](https://www.gnu.org/software/gdb/) e.g. `lldb hello`
Troubleshooting (debugging) executables [created with V in GDB](https://github.com/vlang/v/wiki/Troubleshooting-(debugging)-executables-created-with-V-in-GDB)
**Visual debugging Setup:**
* [Visual Studio Code](vscode.md)
### Native Backend binaries
Currently there is no debugging support for binaries created by the native backend (flag: `-b native`).
### Javascript Backend
There is currently no support for source maps for Javascript output create by the JS Backend (flag: `-b js`).
## Conditional compilation
### Compile time code

BIN
doc/img/vscode-debugger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

90
doc/vscode.md Normal file
View File

@ -0,0 +1,90 @@
# Visual Studio Code Setup
## Table of Contents
* [V language support](#v-language-support)
* [Visual Debugging](#visual-debugging)
## V language support
The [V VS Code Extention](https://marketplace.visualstudio.com/items?itemName=vlanguage.vscode-vlang) provides V language support for Visual Studio Code.
![Screenshot Code with activated extention](https://github.com/vlang/vscode-vlang/raw/HEAD/images/demo.png)
**Features:**
* Syntax Highlighting.
* Code Snippets for quick coding.
* Format code on file save as well as format manually (using v fmt).
* Linter (Workspace files only).
[more](https://marketplace.visualstudio.com/items?itemName=vlanguage.vscode-vlang)
**Hint:** This extention will not add the V compiler! Information on how to [install V compiler](https://github.com/vlang/v/blob/master/doc/docs.md#install-from-source) on your operating system.
### Setup
Install [V VS Code Extention](https://marketplace.visualstudio.com/items?itemName=vlanguage.vscode-vlang).
## Visual Debugging
![screenshot visual debugger](https://github.com/vlang/v/blob/master/doc/img/vscode-debugger.png?raw=true)
The [C/C++ Extention](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) for Visual Studio Code provides visual conditional debugging.
**Features:**
* Conditional breakpoints
* Function breakpoints
* Expression evaluation
* Change Values
[more Features & Documentation](https://code.visualstudio.com/docs/cpp/cpp-debug)
**Hint:** Not all types (e.g. Array) in V currently create the required [DWARF](https://en.wikipedia.org/wiki/DWARF) information to show and edit the variable.
### Setup
1. Install the [C/C++ Extention](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
2. Open `RUN AND DEBUG` panel (Debug Icon in left panel).
3. Click on `Show` all automatic debug configurations.
4. Select `Add config`.
5. Select environment `C++ (GDB/LLDB)`.
6. Change the line `"program": "Programmnamen eingeben, z. B. \"${workspaceFolder}/a.out\"",` to point to your compiled application e.g. `"program": "${workspaceFolder}/hello",`.
This will add a block to your `.workspace` file or creates the file `.vscode/launch.json`:
```json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Starten",
"type": "cppdbg",
"request": "launch",
"program": "Programmnamen eingeben, z. B. \"${workspaceFolder}/a.out\"",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
```
### Usage
To allow your compiled application to be debugged. The application needs to include additional debugging information ([DWARF](https://en.wikipedia.org/wiki/DWARF)).
**1. Compile with debugging information:**
`v -b c -g hello.v -o hello` or short `v -g hello.v`
The `-g` option will add the needed debugging informations. More Options are explained in the [docs](docs.md#debugging).
**2. Start Debugging**
1. Open your source code and set the required break points
2. Click on the Debug Icon in the left Icon panel and klick `> (lldb) Start` or use `F5` to launch your application in debug mode.
For all options look at the official [C/C++ Extention documentation](https://code.visualstudio.com/docs/cpp/cpp-debug).