Hi guys, i have finished writing a debugger for VSCode to debug cocos2d-x JSB
programs. It is availabe since Cocos2d-x v3.11.
The debugger supports:
- set breakpoints
- step over, step in, step out
- show context variables
- show stack frames
- evaluate expression in the
Debug Console
Please refer to VSCode debugging documentation for more detail information and usage.
Environment setup
- Install VSCode,
v.0.10.8+
is required. - Download cocos-debug.zip, and upzip it to:
-
Windows
%USERPROFILE%\.vscode\extensions
-
Mac
$HOME/.vscode/extensions
-
Linux
$HOME/.vscode/extensions
-
Windows
- cocos2d-x(
latest codes from cocos2d-x repo is commended
)- If your cocos2d-x version is v3.10 or lower, you should:
- replace
cocos/scripting/js-bindings/script/debugger
with corresponding contents from cocos2d-x github - replace
cocos/scripting/js-bindings/script/jsb_debugger.js
with corresponding file from cocos2d-x github - change
cocos/scripting/js-bindings/manual/ScriptingCore.cpp
as did in this commit did - change
templates/cocos2dx_files.json
as this commit did
- replace
- If you use cocos2d-x git repo, then you should synchronize to latest codes.
- You need to create a new project to test, or you should do changes for
cocos/scripting/js-bindings/script/debugger
,cocos/scripting/js-bindings/script/jsb_debugger.js
,cocos/scripting/js-bindings/manual/ScriptingCore.cpp
as mentioned above in yourproject_root/frameworks/cocos2d-x
.
- If your cocos2d-x version is v3.10 or lower, you should:
You should re-launch VSCode after upzip cocos-debug.zip.
I only tried on Mac now, other platforms can work in theory because VSCode is cross-platform.
Limitations
Currently VSCode can only attach to cocos2d-x JSB
program to debug. Which means it can not pause on entry. We will improve it in future.
Usage
First you should run cocos2d-x JSB
program, then use VSCode to attach it to the debugger.
Run cocos2dx JSB programs
If you don’t know how to run cocos2d-x JSB
program, you can refer to this document.
VSCode attach to cocos2d-x JSB
program
- lauch VSCode and open the folder of your project(for example
cocos2d-x/tests/js-tests
)
- click on the Debugging icon in the View Bar on the side of VSCode
-
set up launch configuration
- If you want to debug on iOS devices, you should:
- connect iOS device to Mac via USB cable
- run cocos2d-x JSB program on iOS devices
- use ip address the iOS device to fill the
address
section in launch.json
- If you want to debug on Android devices, you should:
- connect Android devices with PC via USB cable
- run cocos2d-x JSB program on Android devices
- use adb to forward tcp
adb forward tcp:5086 tcp:5086
- If you want to debug on iOS devices, you should:
-
start debugging
For more detailed information please refer to VSCode debugging documentation.
I appreciate if you can try it and give some feedback.
Thanks.