How to Debug C++ with Script Side-by-side Simultaneously¶
Before Cocos Code IDE 1.0.0-RC1, many users suffered from being unable to debug C++with script simultaneously, because Cocos Code IDE supports Lua / JavaScipt only and controls the launching and terminating of runtime.
Debug framework cpp is an advanced feature, and I'm assuming you have mastered the basics. If not, please refer to How to Debug Cocos2d-x Lua Game Using Code IDE and How to Debug Cocos2d-x JS Game Using Code IDE
The basic principle is: We are using Cocos Code IDE to debug scripting logic, and XCode / Visual Studio to debug C++ code, here is the key steps:
- Begin with XCode / Visual Studio to debug runtime project
- Runtime enter
waiting for debugging connectpage with blue background
- Use Cocos Code IDE to connect to the runtime and notify runtime to start the game
- Then C++ breakpoints will be triggered in XCode / Visual Studio and scripts breakpoints will be triggered in Cocos Code IDE.
Debug Mac OSX runtime¶
This is a step-by-step guide for debugging Mac OSX lua runtime; other platforms and JavaScipt are similar, and I will only point out the differences.
- If you haven't added C++ code for this project, you need: right click on project, Cocos Tools->Add Native Codes Support...
- Open project with XCode by double clicking
- Add C++ breakpoint at
Texture2D * TextureCache::addImage(const std::string &path)
- Switch the target to
- Click Run button to debug runtime.
- It would probably take several minutes to build project. Then you'll see the waiting connect page with a blue background.
- Go back to Cocos Code IDE, open “Debug Configurations” page by clicking Debug Configurations button on toolbars
- Check Remote Debug radio button
- Select "Mac" platfrom
- Enter "127.0.0.1" into the Target IP and select "127.0.0.1" on the Host IP
- Then click the Debug button
Debug iOS runtime¶
The differences between iOS and Mac OSX are:
- Switch the target to
CocosLuaGame iOS; if you want to debug on iOS device, please have your Developer Certificate ready.
- Select "iOS" platform
Debug Win32 runtime¶
The differences between Win32 and Mac OSX are:
- Open project with Visual Studio by double clicking
F5to debug runtime directly
- Select "Win32" platfrom
Debug Android runtime¶
In principle, you can also debug java and cpp in ADT Bundle, but the process is more complex and any document sharing is welcome!
The only difference in Cocos Code IDE is: Select "Android" platform