Debug

Runtime, launch, connection

Copy the right runtime, align ports, start the editor debugger first.

Where runtime files come from

The extension’s luadebug folder contains the runtime files. After updating the extension, copy them again and confirm the runtime actually loads this copy (especially Unity — avoid running an old AssetBundle).

Setting luadebug.automaticDownloadingDebugFile is deprecated: the extension no longer prompts to download debug files.

Connection order

  1. Start the editor debug session (listens on the launch port).
  2. Start the game / client and run StartDebug(host, port).
  3. Ports must match; on a device, host is the PC’s LAN IP.

How to add launch configs

  1. Open the Run and Debug panel.
  2. No launch.json: Create launch.json → pick LuaDebug.
  3. Existing launch.json: Add Configuration… → pick a LuaDebug: … snippet.
  4. Adjust fields per engine; port must match StartDebug.
If multiple Lua debug extensions are installed, keep only LuaDebug — otherwise type=lua may be claimed by another extension.
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Unity-xlua",
      "type": "lua",
      "request": "attach",
      "runtimeType": "Unity",
      "localRoot": "${workspaceFolder}",
      "port": 7003,
      "fileExtNames": [".lua", ".txt", ".lua.txt", ".bytes"],
      "printType": 1
    }
  ]
}

Common launch fields

FieldDescription
nameLabel shown in the debug dropdown
typeAlways lua (UI shows LuaDebug)
requestlaunch starts a process from the editor; attach waits for a connection
runtimeTypeCocos2 / Cocos3 / Unity / OpenResty / LuaTest, etc.
localRootLocal script root for stack path mapping; wrong values cause wrong files / jumps
portDebug port (default 7003); must match StartDebug
exePathExecutable path in launch mode (simulator / player)
commandLineArgs passed to the simulator (common for Cocos)
mainFileEntry script name in some configs
fileExtNamesSuffixes the engine may use for Lua
printType1 console+system; 2 console only; 3 system only

Full engine samples: Frameworks.

LuaTest

Pick LuaTest in launch to debug the current / a given Lua file without starting the full game.

{
  "name": "LuaTest",
  "type": "lua",
  "request": "launch",
  "runtimeType": "LuaTest",
  "mainFile": "${fileBasenameNoExtension}",
  "localRoot": "${fileDirname}",
  "curFileExtname": "${fileExtname}",
  "fileExtNames": [".lua", ".txt", ".lua.txt", ".bytes"],
  "port": 7003,
  "printType": 1
}

On macOS, if you see Permission denied, check execute permission on the extension folder and temp scripts, or allow the program under Privacy & Security.

Multiple game folders

With several similar directories, the debugger may guess the wrong file from package.path / chunkname. Use a separate config per game and set localRoot precisely:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug src1",
      "type": "lua",
      "request": "attach",
      "runtimeType": "Cocos2",
      "localRoot": "${workspaceFolder}/src1",
      "port": 7003,
      "fileExtNames": [".lua", ".txt", ".lua.txt", ".bytes"],
      "printType": 1
    },
    {
      "name": "Debug src2",
      "type": "lua",
      "request": "attach",
      "runtimeType": "Cocos2",
      "localRoot": "${workspaceFolder}/src2",
      "port": 7003,
      "fileExtNames": [".lua", ".txt", ".lua.txt", ".bytes"],
      "printType": 1
    }
  ]
}

Pick the matching config in the debug panel, then F5. Non-Cocos projects likewise only need a correct localRoot.