Skip to content

Add debug configuration for VSCode #2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions premake-core.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"folders": [
{
"name": "root",
"path": ".",
}
],
"settings": {
"files.exclude": {
"build": true,
"bin": true,
"MyLocation": true,
}
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "bootstrap",
"type": "shell",
"windows": {
"command": "Bootstrap.bat",
},
"linux": {
"command": "make",
"args": [
"-f",
"Bootstrap.mak",
"linux",
"PLATFORM=x64",
"CONFIG=release",
]
},
"osx": {
"command": "make",
"args": [
"-f",
"Bootstrap.mak",
"macosx",
"PLATFORM=x64",
"CONFIG=release",
]
},
"group": {
"kind": "build",
},
"problemMatcher": []
},
{
"label": "open",
"type": "shell",
"windows": {
"command": "C:/Program Files (x86)/Common Files/Microsoft Shared/MSEnv/VSLauncher.exe",
"args": [
"build/bootstrap/Premake5.sln",
]
},
"problemMatcher": []
}
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "test",
"type": "lua-local",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": {
"command": "bin/release/premake5",
},
"args": [
"test",
]
},
{
"name": "test-all",
"type": "lua-local",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": {
"command": "bin/release/premake5",
},
"args": [
"test",
"--test-all",
]
},
{
"name": "test-only",
"type": "lua-local",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": {
"command": "bin/release/premake5",
},
"args": [
"test",
"--test-only=${input:test_suite_name}",
]
}
],
"inputs": [
{
"type": "promptString",
"id": "test_suite_name",
"description": "test suite name",
}
]
},
"extensions": {
"recommendations": [
"tomblind.local-lua-debugger-vscode",
"editorconfig.editorconfig",
]
},
}
5 changes: 5 additions & 0 deletions tests/test_premake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
-- Copyright (c) 2008-2015 Jason Perkins and the Premake project
--

-- Start local lua debugger
-- https://marketplace.visualstudio.com/items?itemName=tomblind.local-lua-debugger-vscode
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
require("lldebugger").start()
end

local suite = test.declare("premake")

Expand Down
40 changes: 40 additions & 0 deletions website/docs/Debugging-Scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,43 @@ Since Premake's update to 5.3, the only debugger that seems to be able to debug
* There's also a Project tab. Right-click the root folder and select **Project Directory > Choose...** to select the root of the premake repository. Open the lua file you want to debug (you can start with _premake_init.lua) and set a breakpoint.
* Run premake with your desired command line and append `--scripts=path_to_premake --debugger` path_to_premake is the root of the repository where src lives. This isn't necessary if you run premake in the same directory as the src folder. If all goes well premake should think for a moment and the debugger should flash indicating that it has broken execution.
* An example command line would be `C:/my_project_folder/premake5.exe vs2015 --scripts=C:/premake_repo/ --debugger`

## Visual Studio Code

* [Download Visual Studio Code](https://code.visualstudio.com/) and install it
* Install [Local Lua Debugger](https://marketplace.visualstudio.com/items?itemName=tomblind.local-lua-debugger-vscode) plugin
* Add the following text to the top of the premake5.lua file in your project.
```lua
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
require("lldebugger").start()
end
```
* Create `launch.json` according to the [debugger settings](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) and modify it as follows.
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "premake_debug",
"type": "lua-local",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": {
// path to premake5.exe
// If you want to debug including premake5.exe internals, use debug build premake5.exe
"command": "C:/my_project_folder/premake5.exe",
},
"args": [
"vs2022",
"--verbose",
// path to root script file
"--file=${workspaceFolder}/premake5.lua"
],
},
]
}
```
* Open the lua file you want to debug and [set a breakpoint](https://code.visualstudio.com/docs/editor/debugging#_breakpoints).
* Open Debug Console (Press Ctrl+Shift+Y)
* Press F5 key to start debugging.