• Stars
    star
    359
  • Rank 118,537 (Top 3 %)
  • Language
    TypeScript
  • License
    The Unlicense
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Native debugging for VSCode

Debug

VS Marketplace Open VSX Registry GitHub CI Status Coverage Status

Native VSCode debugger. Supports both GDB and LLDB.

Installation

Press ctrl-p (cmd+p on OS X) and run ext install webfreak.debug in visual studio code and install GDB/LLDB. See Usage for details on how to set it up.

Preview

Usage

Image with red circle around a gear and a red arrow pointing at GDB and LLDB

Or if you already have an existing debugger in your project setup you can click "Create Configuration" or use the auto completion instead:

Visual studio code debugger launch.json auto completion showing alternative way to create debuggers

Open your project and click the debug button in your sidebar. At the top right press the little gear icon and select GDB or LLDB. It will automatically generate the configuration you need.

Note: for LLDB you need to have lldb-mi in your PATH

If you are on OS X you can add lldb-mi to your path using ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi /usr/local/bin/lldb-mi if you have Xcode.

Default config with a red circle around the target

Now you need to change target to the application you want to debug relative to the cwd. (Which is the workspace root by default)

Additionally you can set terminal if you want to run the program in a separate terminal with support for input. On Windows set it to an empty string ("") to enable this feature. On linux set it to an empty string ("") to use the default terminal emulator specified with x-terminal-emulator or specify a custom one. Note that it must support the -e argument.

Before debugging you need to compile your application first, then you can run it using the green start button in the debug sidebar. For this you could use the preLaunchTask argument vscode allows you to do. Adding breakpoints while the program runs will not interrupt it immediately. For that you need to pause & resume the program once first. However adding breakpoints while its paused works as expected.

Extending variables is very limited as it does not support child values of variables. Watching expressions works partially but the result does not get properly parsed and it shows the raw output of the command. It will run data-evaluate-expression to check for variables.

While running you will get a console where you can manually type GDB/LLDB commands or MI commands prepended with a hyphen -. The console shows all output separated in stdout for the application, stderr for errors and log for log messages.

Some exceptions/signals like segmentation faults will be caught and displayed but it does not support for example most D exceptions.

Support exists for stopping at the entry point of the application. This is controlled through the stopAtEntry setting. This value may be either a boolean or a string. In the case of a boolean value of false (the default), this setting is disabled. In the case of a boolean value of true, if this is a launch configuration and the debugger supports the start (or exec-run --start MI feature, more specifically), than this will be used to run to the entry point of the application. Note that this appears to work fine for GDB, but LLDB doesn't necessarily seem to adhere to this, even though it may indicate that it supports this feature. The alternative configuration option for the stopAtEntry setting is to specify a string where the string represents the entry point itself. In this situation a temporary breakpoint will be set at the specified entry point and a normal run will occur for a launch configuration. This (setting a temporary breakpoint) is also the behavior that occurs when the debugger does not support the start feature and the stopAtEntry was set to true. In that case the entry point will default to "main". Thus, the most portable way to use this configuration is to explicitly specify the entry point of the application. In the case of an attach configuration, similar behavior will occur, however since there is no equivalent of the start command for attaching, a boolean value of true for the stopAtEntry setting in a launch configuration will automatically default to an entry point of "main", while a string value for this setting will be interpreted as the entry point, causing a temporary breakpoint to be set at that location prior to continuing execution. Note that stopping at the entry point for the attach configuration assumes that the entry point has not yet been entered at the time of attach, otherwise this will have no affect.

Attaching to existing processes

Attaching to existing processes currently only works by specifying the PID in the launch.json and setting request to "attach". You also need to specify the executable path for the debugger to find the debug symbols.

"request": "attach",
"executable": "./bin/executable",
"target": "4285"

This will attach to PID 4285 which should already run. GDB will pause the program on entering and LLDB will keep it running.

Using gdbserver for remote debugging (GDB only)

You can also connect to a gdbserver instance and debug using that. For that modify the launch.json by setting request to "attach" and remote to true and specifying the port and optionally hostname in target.

"request": "attach",
"executable": "./bin/executable",
"target": ":2345",
"cwd": "${workspaceRoot}",
"remote": true

This will attach to the running process managed by gdbserver on localhost:2345. You might need to hit the start button in the debug bar at the top first to start the program.

Control over whether the debugger should continue executing on connect can be configured by setting stopAtConnect. The default value is false so that execution will continue after connecting.

Using ssh for debugging on remote

Debugging using ssh automatically converts all paths between client & server and also optionally redirects X11 output from the server to the client.
Simply add a ssh object in your launch request.

"request": "launch",
"target": "./executable",
"cwd": "${workspaceRoot}",
"ssh": {
	"forwardX11": true,
	"host": "192.168.178.57",
	"cwd": "/home/remoteUser/project/",
	"keyfile": "/path/to/.ssh/key", // OR
	"password": "password123",
	"user": "remoteUser",
	"x11host": "localhost",
	// x11port may also be specified as string containing only numbers (useful to use configuration variables)
	"x11port": 6000,
	// Optional, content will be executed on the SSH host before the debugger call.
	"bootstrap": "source /home/remoteUser/some-env"
}

ssh.sourceFileMap will be used to trim off local paths and map them to the server. This is required for basically everything except watched variables or user commands to work.

For backward compatibility you can also use cwd and ssh.cwd for the mapping, this is only used if the newer ssh.sourceFileMap is not configured.

For X11 forwarding to work you first need to enable it in your Display Manager and allow the connections. To allow connections you can either add an entry for applications or run xhost + in the console while you are debugging and turn it off again when you are done using xhost -.

Because some builds requires one or more environment files to be sourced before running any command, you can use the ssh.bootstrap option to add some extra commands which will be prepended to the debugger call (using && to join both).

Debugging a process from a different user (especially root/system processes)

To debug a program that needs additional privileges you may use one of the two approaches:

  1. start vscode with the necessary rights (so both the program and the started debugger instance will have root rights) - sudo code / sudo codium or "start as admin".
    Note that this has a lot of security implications and will have the user settings of vscode for this user.
  2. preferred: use a small wrapper script that calls sudo gdb $* / runas /profile /user:admin-user (or the debugger of your choice) and configure this extension to use it (for example with gdbpath)

Extra Debugger Arguments

Additional arguments can be supplied to the debugger if needed. These will be added when the debugger executable (e.g., gdb, lldb-mi, etc.) is launched. Extra debugger arguments are supplied via the debugger_args setting. Note that the behavior of escaping these options depends on the environment in which the debugger is started. For non-SSH debugging, the options are passed directly to the application and therefore no escaping is necessary (other than what is necessary for the JSON configuration). However, as a result of the options being passed directly to the application, care must be taken to place switches and switch values as separate entities in debugger_args, if they would normally be separated by a space. For example, supplying the option and value -iex "set $foo = \"bar\"" would consist of the following debugger_args:

"debugger_args" : ["-iex", "set $foo = \"bar\""]

If = is used to associate switches with their values, than the switch and value should be placed together instead. In fact, the following example shows 4 different ways in which to specify the same switch and value, using both short and long format, as well as switch values supplied as a separate parameter or supplied via the =:

  • "debugger_args" : ["-iex", "set $foo = \"bar\""]
  • "debugger_args" : ["-iex=set $foo = \"bar\""]
  • "debugger_args" : ["--init-eval-command", "set $foo = \"bar\""]
  • "debugger_args" : ["--init-eval-command=set $foo = \"bar\""]

Where escaping is really necessary is when running the debugger over SSH. In this case, the options are not passed directly to the application, but are instead combined with the application name, joined together with any other options, and sent to the remote system to be parsed and executed. Thus, depending on the remote system, different escaping may be necessary. The following shows how the same command as above needs to be escaped differently based on whether the remote system is a POSIX or a Windows system.

  • SSH to Linux machine:
    "debugger_args": ["-iex", "'set $foo = \"bar\"'"]
  • SSH to Windows machine:
    "debugger_args": ["-iex", "\"set $foo = \\\"bar\\\"\""]

You may need to experiment to find the correct escaping necessary for the command to be sent to the debugger as you intended.

Issues

More Repositories

1

FSWatch

A cross-platform folder & file watching library using win32, inotify or std.file
D
29
star
2

DWin-Bar

A taskbar for linux with DWin in mind
D
20
star
3

DWinProgramming

Fork because original project doesn't exist anymore
D
19
star
4

avrd

Embedded Systems in D - Port of avr-libc headers and most avr-gcc processor defines
C
19
star
5

Programmers-Cookbook

Literally a public cookbook for programmers
17
star
6

deploy-nightly

Deploy an asset to a GitHub release with date and commit hash and delete old assets.
JavaScript
17
star
7

hack.chat.js

*No longer maintained* API wrapper for hack.chat using ws package
JavaScript
16
star
8

D2DGame

2D Game Engine for Ludum Dare written in D
D
16
star
9

WurgerKing

max1220's slurger web frontend - mirror of https://sr.ht/~webfreak/WurgerKing/
JavaScript
13
star
10

WantsPet

Petting website generator, originally made for SimplyNick on Twitch - https://dman.wants.pet - https://foxgirl.wants.pet - https://marisa.wants.pet - https://nick.pet
D
11
star
11

dwinrt

cppwinrt just in D
D
10
star
12

WebConfig

HTML settings generator & server side validator from any struct
D
9
star
13

MongoSchemaD

Support for more structured MongoDB databases
D
9
star
14

EventSystem

Tiny event system in D using delegates
D
7
star
15

SimpleImageConvert

Simple image conversion gui using ImageMagick
D
7
star
16

SpaceD

D Game for a Game Jam https://itch.io/jam/linux-jam-2017
D
6
star
17

ShareX-Lite

Cross Platform ShareX clone - currently on hold
D
6
star
18

bmfont-d

BMFont parser & encoder
D
6
star
19

ldap

D LDAP client library using winldap on windows and openldap on other platforms
D
6
star
20

setup-dmd

[OBSOLETE] install dmd in a github actions environment
JavaScript
6
star
21

OpenVR-D

D bindings for Valve's C++ OpenVR library
C++
5
star
22

Spamguard2

Twitch chat bot written in D
CSS
5
star
23

opengl-d

dynamic & static generated OpenGL bindings for D using ogl_gen
D
5
star
24

XKeyBinD

Interface for global keyboard shortcuts on X11 in D applications.
D
5
star
25

discord-w

outdated vibe.d based discord client library
D
5
star
26

sfml-ui

*No longer maintained* Simple and lightweight ui library for SFML.Net
C#
4
star
27

Cheating-Site

*No longer maintained* Website with integrated chat and file upload for cheating at school exams
JavaScript
4
star
28

BananaBot

Bot for hack.chat posting random facts about bananas
TypeScript
4
star
29

LD34

Ludum Dare 34 Jam with Wild
D
3
star
30

MongoStore

vibe.d component for storing sessions in MongoDB
D
3
star
31

dsoundio

D binding for libsoundio 1.1.0 and 2.0.0
C++
3
star
32

LD-31

Ludum Dare 31
D
3
star
33

URITemplate

RFC 6570 URI Template expansion implementation for the D programming language
D
3
star
34

PixelGUI

GUI framework in D rendering into a memory buffer with no required dependencies for maximum portability
D
3
star
35

DOpenLocationCode

D port of google's open-location-code (also known as Plus+Codes)
D
3
star
36

dmc

D
3
star
37

EasyEnum

Easily handle long enum names for operations. Written in 20 lines (including unittests)
D
3
star
38

webfreak.org-v3

my new website with state of the art design and functionality
CSS
2
star
39

rm-rf

Delete folders recursively on windows with read-only content such as a .git folder
D
2
star
40

dub-docs-v2

WIP, new dub documentation
HTML
2
star
41

sat-gl3n

A Separating Axis theorem implementation based on gl3n
D
2
star
42

http-here

Super Basic http server creation by right-clicking folders in windows -> "Simple HTTP Server here"
D
2
star
43

sizes

Basically core.time.Duration, but for byte sizes (file size)
D
2
star
44

LD35

D
2
star
45

FoodInventory

D
2
star
46

LD32

D
2
star
47

Tetris

Win32 Console Tetris game - working on this when bored in school
D
2
star
48

hasdata

Cross platform check if a file or stdin has data available for read
D
2
star
49

mir-toml

Custom mir-ion (de)serializer for the TOML format
D
2
star
50

wagomu

Chinese and Japanese Handwriting recognition in D
D
2
star
51

ImageUploader

Image uploader written in D
CSS
1
star
52

ld28-one-bullet

C#
1
star
53

dub-upgrade

Run `dub upgrade` trying to repeat on network failure and using package cache on GitHub Actions
JavaScript
1
star
54

ics_parse

RFC 5545 iCal / iCalendar event parser (.ics files)
D
1
star
55

MaterialColor

Material Design named color palletes for GIMP and Inkscape.
D
1
star
56

fontconfig-d

fontconfig bindings for D
C
1
star
57

sha1ct

sha1 hashing & uuid algorithm that works at compile time
D
1
star
58

linux-screenshot-utils

Mirror of https://gitlab.com/WebFreak001/linux-screenshot-utils
D
1
star
59

LD-30

C#
1
star
60

MaterialDoc

very simple documentation generator. Obsolete now, I recommend using adrdox for more features instead and style it.
D
1
star
61

OmniLauncherMC

WIP
JavaScript
1
star
62

nbtD

A lightweight NBT decoding/encoding library
D
1
star
63

LGJ2019

Linux Game Jam 2019 entry
D
1
star
64

CheatingSite2

Better version of https://github.com/WebFreak001/Cheating-Site
D
1
star
65

LGJ2018

Linux Game Jam 2018
D
1
star
66

RemoteShutdown

Control and shutdown your PC from your Bed. On Linux I would recommend you KDE Connect instead
D
1
star
67

OsuAutoHost

Moved
D
1
star
68

lxcd

Deimos Bindings for lxc
C
1
star
69

FoodInventory-react

React native app for FoodInventory
JavaScript
1
star
70

NaroncoGame

An Open Source Game by Naronco
C++
1
star
71

Butter

JS Game Engine
JavaScript
1
star
72

multicast-delegate

C-Sharp style MulticastDelegate, allows combining and calling multiple delegates into one
D
1
star
73

StampGen

Generate hundreds of different stickers with QR-codes and labels for printing quickly
D
1
star
74

McRcD

A tiny Minecraft Rcon library for D
D
1
star
75

WhyLinux

D
1
star
76

NaroncoChangelogLoader

Load your Changelogs and todolists in PHP with the Naronco Changelog Loader
PHP
1
star
77

FuzzyMatch

Dead-simple, efficient string and array fuzzy matching library (string.contains, but better)
D
1
star