Skip to content
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

Enhance .vscode folder for complete configuration to develop and debug the extension #50

Closed
ozzr opened this issue Mar 19, 2023 · 13 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request feature-request Feature Request for the GDExtension

Comments

@ozzr
Copy link
Contributor

ozzr commented Mar 19, 2023

To debug the extension either from the godot editor or launching the demo project, it is important to

  1. Create a debug build of the extension by creating at least one dev_build library to test with this can be done just by adding the code below to the task.json:
{
            "label": "build-extension [dev build]",
            "type": "shell",
            "command": "scons target=template_debug dev_build=yes",
            "presentation": {
                "echo": true,
                "revealProblems": "onProblem",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": "$msCompile"
}
  1. Add the below code in a launch.json file in the .vscode folder in the root folder
{
    "version": "0.2.0",
    "configurations": [
        {
			"name": "Run Demo Project in Editor",
			"type": "cppvsdbg",
			"request": "launch",
			"program": "C:/godot.exe",  // Your absolute path to the godot executable
			"args": [
				"--editor",
				"--path",
				"${workspaceFolder}/demo",
				"--verbose",
				"--debug",
				"--stdout"
			],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"console": "internalConsole",
			//"preLaunchTask": "build godot editor in debug mode"
		},
        {
			"name": "Run Demo Project in Game",
			"type": "cppvsdbg",
			"request": "launch",
			"program": "C:/godot.exe",  // Your absolute path to the godot executable
			"args": [
				"--path",
				"${workspaceFolder}/demo",
				"--verbose",
				"--debug",
				"--stdout"
			],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"console": "internalConsole",
			//"preLaunchTask": "build godot editor in debug mode"
		},
    ]
}
  1. slightly modify the .gdextension file to find the dev library while developing it. The code below is an example of how I do it for my upcoming terrain extension:
    windows.debug.x86_64 = "bin/libgd.landscape.windows.template_debug.dev.x86_64.dll"

With this we get to properly test and debug the code

@paddy-exe
Copy link
Owner

paddy-exe commented Mar 20, 2023

@ozzr Hey, thanks for giving out this info. Do you want to open a PR? Also, do you think the debugging functionality could be added without changing the .gdextension file?

@paddy-exe paddy-exe added documentation Improvements or additions to documentation feature-request Feature Request for the GDExtension enhancement New feature or request labels Mar 20, 2023
@ozzr
Copy link
Contributor Author

ozzr commented Mar 22, 2023

Hi, sorry for the delayed response.
OK, I will open a PR later today

The only way to debug the extension code is by forcing the engine to load a debug build of the extension by modifing temporarily the path to the "template_debug" library. What is needed is de .pdb file generated with the dev_build flag so the vscode debugger can find the code in our extension. The other builds do not inlcude it and I havent find a way to explicitly tell the engine to load de dev_build version of the engine

Also it could be nice to modify the c_cpp_proprtirs.json like this so the editor can properly load the include files:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/godot-cpp/gen/include",
                "${workspaceFolder}/etxtension/src"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

@ozzr
Copy link
Contributor Author

ozzr commented Mar 22, 2023

Maybe we could write the .gdextension file on every build so the user dont have to do it manually. Maybe doing it from the same SCons script? and create a task like "Generate Poduction Builds" and "Create DEV build"

@paddy-exe
Copy link
Owner

paddy-exe commented Mar 24, 2023

Hey, sorry @ozzr for the late answer as well. Your proposal sounds very interesting. However, does this mean that the changes will be only compatible with Windows or also with the other desktop platforms?

About the different tasks for production and dev builds: Yes👍🏻 sounds good. Not sure though if we should meddle with the generation of the .gdextension file... this would mostly confuse users since it's more complicated to change the system to their needs then.

@ozzr
Copy link
Contributor Author

ozzr commented Mar 24, 2023

the changes should be compatible with other platforms too. It would only requires to update the corresponding paths to follow specific OS notation.

In the case of the .gdextension file we could just tell about it in the main page README so the user knows that it can be done, but then it has to be done manually

@paddy-exe
Copy link
Owner

the changes should be compatible with other platforms too. It would only requires to update the corresponding paths to follow specific OS notation.

In the case of the .gdextension file we could just tell about it in the main page README so the user knows that it can be done, but then it has to be done manually

Okay, sounds good to me 👍🏻

@paddy-exe
Copy link
Owner

paddy-exe commented Apr 6, 2023

Bump :) @ozzr Would you still like to add a PR for this? I'd appreciate it immensely since I won't have that much time to work on this

@ozzr
Copy link
Contributor Author

ozzr commented Apr 7, 2023

Sorry, I will do it today

@ozzr
Copy link
Contributor Author

ozzr commented Apr 7, 2023

Done, please check the pull request.
I will properly update the README tomorrow once I have some time, to point to how to properly modify the .gdextension file when debugging or simply you can point in the main page to this issue.
The configuration was done in Windows but it should work as long as the user replaces with their global path to godot executable

@ozzr ozzr closed this as completed Apr 7, 2023
@paddy-exe
Copy link
Owner

@ozzr I think it's important that the information is on the README. There is no hurry with it so take your time if you need👍🏻 I appreciate your contribution

@ozzr
Copy link
Contributor Author

ozzr commented Apr 9, 2023

Ok, I will update the readme and restart the pull request

@zhangjt93
Copy link

zhangjt93 commented Sep 15, 2023

I'm using a macbook now. vscode reports an error:
process exited with status -1 (Error 1)

console infomation:
Console is in 'commands' mode, prefix expressions with '?'.
Launching: /Applications/Godot.app/Contents/MacOS/Godot --editor --path /Users/Desktop/godot-rpgbuilder/plugin --verbose --debug --stdout

How should I deal with it, thank you

my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Demo Project in Editor",
"type": "lldb",
"request": "launch",
"program": "/Applications/Godot.app/Contents/MacOS/Godot", // Your absolute path to the godot executable
"args": [
"--editor",
"--path",
"${workspaceFolder}/plugin",
"--verbose",
"--debug",
"--stdout"
],
"cwd": "${workspaceFolder}",
//"preLaunchTask": "build godot editor in debug mode"
},
]
}

@ozzr
Copy link
Contributor Author

ozzr commented Sep 15, 2023

Hi, try creating a task using the VScode command and see how it is organized, maybe, the task should look different in MacOs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request feature-request Feature Request for the GDExtension
Projects
None yet
Development

No branches or pull requests

3 participants