how to debug cocos2d-x(c++) in eclipse

how to debug cocos2d-x(c++) in eclipse i have add pointbreak but can’t run

1 Like

You need to be in Debug Perspective and click the Debug button instead of the Run button.

c++ can’t…java can

Actually it is possible.

You need to install NVidia debug manager for Android NDK (https://developer.nvidia.com/tegra-resources). But it also requires a lot of configuration and headache. Finally I managed to successful debug and hit breakpoints, but it was sooooo slow, and it is completely unuseful.

I use Eclipse as my primary IDE for cocos2d-x development. So I ended up developing in eclipse and debugging in visual studio for win32.

It is also possible just using the ADT. It takes quite a few changes but its possible to use breakpoints and step as well as inspect variables. Its not as clean and fast as using XCode but its not too bad.

Maybe we can come up with a minimal set of steps to make debugging in eclipse (ADT) work correctly and have the project template changed to reflect these changes.

I am running the following:
I am using Mac OS X
Android Developer Tools Build: v22.2.0-822323
Android NDK r9
cocos2d-x 3.0 alpha0

I will try to document a few things I believe were necessary in getting debugging working.
In a number of places I will reference /full/path/to/ please change those accordingly.

In Android.mk:
I added two import-add-path lines between the BUILD_SHARED_LIBRARY line and the import-module line:

    include $(BUILD_SHARED_LIBRARY)

    $(call import-add-path,/full/path/to/cocos2d-x/)
    $(call import-add-path,/full/path/to/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt)

    $(call import-module,cocos2dx)

This is the contents of my Application.mk file:

    APP_STL := gnustl_static
    APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1 -std=c++11 -Wno-literal-suffix -O0 -gstabs+
    APP_ABI := armeabi
    APP_OPTIM := debug
    NDK_APP_OPTIM := debug
    NDK_DEBUG := 1
    APP_PLATFORM := android-14

The -O0 and -gstabs+ were required to make variable inspection work, i could not make it work without those at all.

In the project properties:
C/C++ Build -> Build Command:

    bash ${ProjDirPath}/build_native.sh NDK_DEBUG=1 V=1

C/C++ Build -> Environment:
I have two added environment variables:

NDK_MODULE_PATH
$COCOS2DX_ROOT:$COCOS2DX_ROOT/cocos2dx/platform/third_party/android/prebuilt

NDK_ROOT
/full/path/to/android-ndk-r9

I created a debug configuration of type: Android Native Application
For that configuration, on the debugger tab, under Shared Libraries I added:

    /full/path/to/proj.android/obj/local/armeabi
    /full/path/to/proj.android/obj/local/armeabi/objs-debug

I hope I have not missed anything.

Lets try to figure out which parts are just my superstition and which are actually needed to debug. Its working quite well now and I am happy with it. I have issues from time to time that I believe are eclipse. For instance hovering to inspect variables just stopped working, but the Expressions tab in the debugger still shows them fine and I can view them using the GDB window as well.

  • Jerry
2 Likes