danielga / vscode-gmrdb

Garry's Mod Lua debugger for Visual Studio Code
https://github.com/danielga/vscode-gmrdb
Boost Software License 1.0
35 stars 2 forks source link
debugger debugging vscode vscode-extension

Garry's Mod Remote DeBugger for Visual Studio Code

Introduction

This extension allows debugging Lua code and using the Source engine console of Garry's Mod clients or SRCDS (SouRCe Dedicated Server) instances, through Visual Studio Code.

This works by running a remote debugging server on SRCDS listening on a port. The VSCode extension is then used to attach a debugger to provide breakpoints.

This fork works only with the Garry's Mod module danielga/gm_rdb.

Based on the work from satoren/vscode-lrdb and kapecp/vscode-lrdb.

Garry's Mod debug

Features

Requirements

Usage

Be sure to use 64-bit or 32-bit modules on the respective platforms, otherwise the modules will not be loaded.

Server-side debugging

For this example, we're using SRCDS from the x86-64 beta branch on Windows.

The server will freeze until we attach the debugger through VSCode and resume.

  1. Place the gmsv_rdb_win64.dll binary module in garrysmod/lua/bin - guide
  2. (Optional) Add the following snippet wherever we want to start the server
-- Fetch the remote debugging server binary module
require("rdb")

-- Start a debugging server
-- This will pause the server until we attach a debugger
-- Listens on port 21111 by default, use the first argument to change it
rdb.activate()

Extension settings

Feel free to use variables like workspaceFolder to specify paths as a shortcut.

launch.json example:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "gmrdb",
      "request": "attach",
      "host": "127.0.0.1",
      "port": 21111,
      "name": "Attach to Garry's Mod",
      "sourceRoot": "C:/example-srcds/garrysmod",
      // Important to map Lua source code to breakpoints
      // (otherwise we'll see missing file errors on VSCode)
      "sourceFileMap": {
        // Local absolute path: remote path
        "C:/example-srcds/garrysmod/addons/exampleaddon": "addons/exampleaddon",
        "C:/example-srcds/garrysmod/gamemode/examplerp": "gamemodes/examplerp"
      },
      "stopOnEntry": true
    },
    {
      "type": "gmrdb",
      "request": "launch",
      "name": "Launch Garry's Mod",
      "program": "C:/example-srcds/srcds_win64.exe",
      "cwd": "C:/example-srcds",
      "args": [
        "-console",
        "-game",
        "garrysmod",
        "-ip",
        "127.0.0.1",
        "-port",
        "27015",
        "+map",
        "gm_construct",
        "+maxplayers",
        "2"
      ],
      "sourceRoot": "C:/example-srcds/garrysmod",
      "port": 21111,
      "sourceFileMap": {
        "C:/example-srcds/garrysmod/addons/test2": "addons/test2",
        "C:/example-srcds/garrysmod/gamemode/examplerp": "gamemodes/examplerp"
      },
      "stopOnEntry": true
    }
  ]
}

Client-side debugging

This follows similar steps to server-side debugging on Windows 64-bit.

The client will freeze until we attach the debugger through VSCode and resume.

It is possible to join a server that will load the module on your client. Just be wary if this is what you want, since ANY server can do this. The only effect of this should be your game freezing until you attach a debugger on it. Someone else remotely debugging your game should be considered a bug!

  1. Place the gmcl_rdb_win64.dll binary module in garrysmod/lua/bin in our local Garry's Mod installation - guide
  2. (Optional) Add the following snippet wherever we want to start the debugging server
-- Fetch the remote debugging server binary module
require("rdb")

-- Start a debugging server
-- This will pause the server until we attach a debugger
-- Listens on port 21111 by default, use the first argument to change it
rdb.activate()

Extension settings

Feel free to use variables like workspaceFolder to specify paths as a shortcut.

launch.json example:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "gmrdb",
      "request": "attach",
      "host": "127.0.0.1",
      "port": 21111,
      "name": "Attach to Garry's Mod",
      "sourceRoot": "C:/steamapps/common/garrysmod",
      // Important to map Lua source code to breakpoints
      // (otherwise we'll see missing file errors on VSCode)
      "sourceFileMap": {
        // Local absolute path: remote path
        "C:/steamapps/common/garrysmod/addons/exampleaddon": "addons/exampleaddon",
        "C:/steamapps/common/garrysmod/gamemode/examplerp": "gamemodes/examplerp"
      },
      "stopOnEntry": true
    }
  ]
}

Icon licensing

Lua icon

Search for virus (modified)