Debugging static libraries in shared object of project.

3,304 views
Skip to first unread message

mpel...@istucf.org

unread,
Jun 7, 2013, 10:46:16 AM6/7/13
to andro...@googlegroups.com
Hello,

I'm trying to debug native code in a shared library but I am having some issues with 'No source available for "class::function() at 0x00000000" ' errors, and I can not get a stack trace when using bt in the gdb console. I'm using ADT v22 and the NDK plugin. For my setup I have a C++ Project projA which contains a set of static libraries, my main project projB, and a native C++ project libA. Now, libA adds the static libraries from projA into it's .so with an Android.mk\ like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libA

PROJECT_ROOT := $(LOCAL_PATH)/../../../projA
PROJECT_INCLUDES := $(PROJECT_ROOT)/build/include
LOCAL_CFLAGS += -I$(PROJECT_INCLUDES)
         
LOCAL_LDLIBS += -L$(PROJECT_ROOT)/build/libs
LOCAL_LDLIBS += -lstaticLibA -lstaticLibB

include $(BUILD_SHARED_LIBRARY)

And projB adds the libA.so with an Android/.mk like this:

include $(CLEAR_VARS)

LOCAL_MODULE := STEP_Wrapper-prebuilt
LOCAL_SRC_FILES := ../libA/obj/local/armeabi/libstepwrapper.so

include $(PREBUILT_SHARED_LIBRARY)


I ran the nm command on the .o's contained in projA's static libraries and it looks like the debugging symbols are present. I also ran file on libA.so and it says it's non-stripped. Is there something else I'm missing so I can properly debug my native code?

mpel...@istucf.org

unread,
Jun 7, 2013, 10:56:59 AM6/7/13
to andro...@googlegroups.com
I meant that I ran the nm command on the static libraries and it looks like the debugging symbols are present. And I also ran file on the .o's from the static libraries and libA.so and it says it's non-stripped.
Message has been deleted
Message has been deleted

mpel...@istucf.org

unread,
Jun 10, 2013, 3:56:59 PM6/10/13
to andro...@googlegroups.com
I'm not sure, I'm executing native debugging through Eclipse, not the command line. I right click my project and hit "Debug as  -> Android Native Application". This is the message I get in the CDT Global Build Console in Eclipse:

**** Build of configuration Default for project PROJB ****

/home/common/Devtools/android-ndk-r8e/ndk-build NDK_DEBUG=1 all
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
Gdbsetup       : libs/armeabi-v7a/gdb.setup
Install        :
libA.so => libs/armeabi/libA.so
Install        : libgnustl_shared.so => libs/armeabi/libgnustl_shared.so
Install        :
libA.so => libs/armeabi-v7a/libA.so
Install        : libgnustl_shared.so => libs/armeabi-v7a/libgnustl_shared.so

**** Build Finished ****

 
I also am receiving this message from the gdb console in Eclipse:

Error while mapping shared library sections:
`/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/libjpeg.so': not in executable format: File format not recognized
warning: Could not load shared library symbols for 90 libraries, e.g. /system/bin/linker.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Unable to find dynamic linker breakpoint function.
GDB will retry eventurally.  Meanwhile, it is likely
that GDB is unable to debug shared library initializers
or resolve pending breakpoints after dlopen().

On Monday, June 10, 2013 9:18:43 AM UTC-4, jar...@iocom.com wrote:
What is the ndk-gdb command you are using? It's tricky to point it to the correct place. And even then, I find it more miss than hit, esp. after a crash.

mpel...@istucf.org

unread,
Jun 20, 2013, 12:31:54 PM6/20/13
to andro...@googlegroups.com
Anyone have a general idea of how to debug native libraries? If someone needs more info please tell me.


On Friday, June 7, 2013 10:46:16 AM UTC-4, mpel...@istucf.org wrote:

Radovan Chytracek

unread,
Jun 20, 2013, 12:42:31 PM6/20/13
to andro...@googlegroups.com
Hi,

If you have AndroidManifest.xml which caontains android:debuggable="true" and you have built your project with NDK_DEBUG=1 then in principle you should be able to run ndk-gdb.

What is the output when you run ndk-gdb from the directory where the jni sub-directory is located?

Radovan

mpel...@istucf.org

unread,
Jun 20, 2013, 1:33:19 PM6/20/13
to andro...@googlegroups.com
Here's the output on the command line:

GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
warning: .dynamic section for "/home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/linker" is not at the expected address (wrong library or version mismatch?)
warning: Could not load shared library symbols for 94 libraries, e.g. libstdc++.so.

Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Breakpoint address adjusted from 0x40197aa5 to 0x40197aa4.
0x5dc0595c in ?? ()
(gdb)

I'm hoping to get this working under Eclipse with the NDK plugin though. The error I got then is in a previous post in case it helps.

Radovan Chytracek

unread,
Jun 21, 2013, 5:16:12 AM6/21/13
to andro...@googlegroups.com
Well, I tried to make Eclipse working with ndk-gdb but it does not work out of the box as it is a script and Eclipse assumes talking to the gdb directly.
I can debug in Eclipse using ARM EABI gdb on a rooted device with a gdbserver started on the device and attached to the process I want to debug.

It seems you can debug with ndk-gdb now using command line though.
What you need also is to configure gdb.setup or .gdbinit to let know gdb where are the non-stripped versions of the libraries, something like:

set solib-search-path ./obj/local/armeabi
directory /path/to/the/ndk8d/platforms/android-8/arch-arm/usr/include jni/armeabi /path/to/the/ndk8d/sources/cxx-stl/system
file ./obj/local/armeabi-v7a/app_process
target remote :5039

also make sure you have your non-stripped libraries linked or copied into the directory mentioned above ./obj/local/armeabi .

Hope this helps

mpel...@istucf.org

unread,
Jun 21, 2013, 9:48:49 AM6/21/13
to andro...@googlegroups.com
I noticed in the obj/local/armeabi directory there is a gdb.setup file which I used to configure gdb on the command line. The gdb.setup file contains:

set solib-search-path ./obj/local/armeabi
directory /home/common/Devtools/android-ndk-r8e/platforms/android-9/arch-arm/usr/include jni /home/common/Devtools/android-ndk-r8e/sources/cxx-stl/system
file ./obj/local/armeabi/app_process
target remote :5039

Here's the output I was receiving:

GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
warning: .dynamic section for "/home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/linker" is not at the expected address (wrong library or version mismatch?)
warning: Could not load shared library symbols for 94 libraries, e.g. libstdc++.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Breakpoint address adjusted from 0x40197aa5 to 0x40197aa4.
0x400c0a70 in epoll_wait () from /home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/libc.so
(gdb) set solib-search-path ./obj/local/armeabi

warning: Breakpoint address adjusted from 0x40197aa5 to 0x40197aa4.
(gdb) directory /home/common/Devtools/android-ndk-r8e/platforms/android-9/arch-arm/usr/include jni /home/common/Devtools/android-ndk-r8e/sources/cxx-stl/system
Source directories searched: /home/common/Devtools/android-ndk-r8e/platforms/android-9/arch-arm/usr/include:/home/common/STEP3D/trunk/STEP3D/jni:/home/common/Devtools/android-ndk-r8e/sources/cxx-stl/system:$cdir:$cwd
(gdb) file ./obj/local/armeabi/app_process
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Please answer y or n.
A program is being debugged already.
Are you sure you want to change the file? (y or n) y

Load new symbol table from "/home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/app_process"? (y or n) y
Reading symbols from /home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/app_process...done.

WARNING: no debugging symbols found in /home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/app_process.
Either the binary was compiled without debugging information
or the debugging information was removed (e.g., with strip or strip -g).
Debugger capabilities will be very limited.
For further information: http://wiki/Main/GdbFaq#No_debugging_symbols_found

(gdb) directory /home/common/Devtools/android-ndk-r8e/platforms/android-9/arch-arm/usr/include jni /home/common/Devtools/android-ndk-r8e/sources/cxx-stl/system
Source directories searched: /home/common/Devtools/android-ndk-r8e/platforms/android-9/arch-arm/usr/include:/home/common/STEP3D/trunk/STEP3D/jni:/home/common/Devtools/android-ndk-r8e/sources/cxx-stl/system:$cdir:$cwd
(gdb) file ./obj/local/armeabi/app_process
A program is being debugged already.
Are you sure you want to change the file? (y or n) y

Load new symbol table from "/home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/app_process"? (y or n) y
Reading symbols from /home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/app_process...done.

WARNING: no debugging symbols found in /home/common/STEP3D/trunk/STEP3D/obj/local/armeabi/app_process.
Either the binary was compiled without debugging information
or the debugging information was removed (e.g., with strip or strip -g).
Debugger capabilities will be very limited.
For further information: http://wiki/Main/GdbFaq#No_debugging_symbols_found

(gdb) target remote :5039
A program is being debugged already.  Kill it? (y or n) y

Remote debugging using :5039
Remote communication error.  Target disconnected.: Connection reset by peer.

badcc0de

unread,
Jun 21, 2013, 3:18:13 PM6/21/13
to andro...@googlegroups.com
The libs are stripped... So you either need to use the unstripped version in $(OUT)/obj/... Or add the cflags -g to your modules.

You'll still need to point gdb to the source code directory and connect everything to gdb-server.

Bill

mpel...@istucf.org

unread,
Jun 21, 2013, 4:25:31 PM6/21/13
to andro...@googlegroups.com
I saw that message also about app_process having no debugging symbols. I am using the .so found in libA's /obj directory. Where should I add the -g flag though, if libA's Android.mk or in projB's?

mpel...@istucf.org

unread,
Jun 21, 2013, 5:23:26 PM6/21/13
to andro...@googlegroups.com
Also, this is libA's Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_MODULE := stepwrapper

LOCAL_CPP_FEATURES := rtti exceptions

#tell compiler to compile headers in these gamekit directories
GK_PROJECT_ROOT := $(LOCAL_PATH)/../../../projA
GK_ENGINE_PATH := $(GK_PROJECT_ROOT)/Engine
GK_FILE_TOOLS_PATH := $(GK_PROJECT_ROOT)/Tools/FileTools
GK_FILE_TOOLS_FILE_PATH := $(GK_FILE_TOOLS_PATH)/File/
GK_FILE_TOOLS_BLEND_PATH := $(GK_FILE_TOOLS_PATH)/FileFormats/Blend/
GK_LOGIC_NODES_PATH := $(GK_ENGINE_PATH)/Logic
GK_LOGIC_BRICKS_PATH := $(GK_PROJECT_ROOT)/Engine/LogicBricks
GK_SCRIPTING_PATH := $(GK_ENGINE_PATH)/Script/Api
GK_AI_PATH := $(GK_ENGINE_PATH)/AI
GK_PHYSICS_PATH = $(GK_ENGINE_PATH)/Physics
GK_HEADER_BUILD_PATH := $(GK_PROJECT_ROOT)/build/Engine
GK_LOADER_PATH := $(GK_ENGINE_PATH)/Loaders/Blender2
OGRE_PATH := $(GK_PROJECT_ROOT)/Ogre-1.9a
OGRE_MAIN_HEADER_PATH :=  $(OGRE_PATH)/OgreMain/include
OGRE_OVERLAY_PATH := $(OGRE_PATH)/Components/Overlay/include
OGRE_SETTINGS_HEADER_PATH :=  $(GK_PROJECT_ROOT)/build/include
OGRE_BULLET_HEADER_PATH := $(GK_PROJECT_ROOT)/bullet/src
OGRE_BULLET_HEADERS := $(GK_PROJECT_ROOT)
DEPENDANCIES_SRC_PATH := $(GK_PROJECT_ROOT)/Dependencies/Source
DEPENDANCIES_UTIL_PATH := $(DEPENDANCIES_SRC_PATH)/GameKit/Utils
DEPENDANCIES_ANIMKIT_PATH := $(DEPENDANCIES_SRC_PATH)/GameKit/AnimKit
DEPENDANCIES_OIS_PATH := $(DEPENDANCIES_SRC_PATH)/OIS/include
DEPENDANCIES_LUA_PATH := $(DEPENDANCIES_SRC_PATH)/Lua/lua

#does not work!
#LOCAL_EXPORT_C_INCLUDES += -I$(GK_HEADER_PATH) -I$(GK_AI_PATH)  -I$(DEPENDANCIES_LUA_PATH) 
#LOCAL_EXPORT_C_INCLUDES += -I$(GK_HEADER_BUILD_PATH) -I$(OGRE_MAIN_HEADER_PATH) -I$(OGRE_SETTINGS_HEADER_PATH)
#LOCAL_EXPORT_C_INCLUDES += -I$(GK_LOADER_PATH)
#LOCAL_EXPORT_C_INCLUDES += -I$(GK_LOGIC_BRICKS_PATH)
#LOCAL_EXPORT_C_INCLUDES += -I$(DEPENDANCIES_UTIL_PATH) -I$(OGRE_BULLET_HEADER_PATH) -I$(DEPENDANCIES_ANIMKIT_PATH)
#LOCAL_EXPORT_C_INCLUDES += -I$(OGRE_OVERLAY_PATH) -I$(DEPENDANCIES_OIS_PATH)
#LOCAL_EXPORT_C_INCLUDES += -I$(GK_LOGIC_NODES_PATH) -I$(GK_LOGIC_BRICKS_PATH) -I$(GK_PHYSICS_PATH) -I$(GK_SCRIPTING_PATH)

#doesn't work!
#LOCAL_C_INCLUDES += -I$(GK_HEADER_PATH) -I$(GK_AI_PATH)  -I$(DEPENDANCIES_LUA_PATH) 
#LOCAL_C_INCLUDES += -I$(GK_HEADER_BUILD_PATH) -I$(OGRE_MAIN_HEADER_PATH) -I$(OGRE_SETTINGS_HEADER_PATH)
#LOCAL_C_INCLUDES += -I$(GK_LOADER_PATH)
#LOCAL_C_INCLUDES += -I$(GK_LOGIC_BRICKS_PATH)
#LOCAL_C_INCLUDES += -I$(DEPENDANCIES_UTIL_PATH) -I$(OGRE_BULLET_HEADER_PATH) -I$(DEPENDANCIES_ANIMKIT_PATH)
#LOCAL_C_INCLUDES += -I$(OGRE_OVERLAY_PATH) -I$(DEPENDANCIES_OIS_PATH)
#LOCAL_C_INCLUDES += -I$(GK_LOGIC_NODES_PATH) -I$(GK_LOGIC_BRICKS_PATH) -I$(GK_PHYSICS_PATH) -I$(GK_SCRIPTING_PATH)

#works!
LOCAL_CFLAGS += -I$(GK_ENGINE_PATH) -I$(GK_AI_PATH)  -I$(DEPENDANCIES_LUA_PATH) 
LOCAL_CFLAGS += -I$(GK_FILE_TOOLS_FILE_PATH) -I$(GK_FILE_TOOLS_BLEND_PATH)
LOCAL_CFLAGS += -I$(GK_HEADER_BUILD_PATH) -I$(OGRE_MAIN_HEADER_PATH) -I$(OGRE_SETTINGS_HEADER_PATH)
LOCAL_CFLAGS += -I$(GK_LOADER_PATH)
LOCAL_CFLAGS += -I$(GK_LOGIC_BRICKS_PATH)
LOCAL_CFLAGS += -I$(DEPENDANCIES_UTIL_PATH) -I$(OGRE_BULLET_HEADER_PATH) -I$(DEPENDANCIES_ANIMKIT_PATH)
LOCAL_CFLAGS += -I$(OGRE_OVERLAY_PATH) -I$(DEPENDANCIES_OIS_PATH)
LOCAL_CFLAGS += -I$(GK_LOGIC_NODES_PATH) -I$(GK_LOGIC_BRICKS_PATH) -I$(GK_PHYSICS_PATH) -I$(GK_SCRIPTING_PATH)

#tell compiler to compile using these flags
    #android specific flags
#LOCAL_CFLAGS += -O3 #not recommended to optimize when debugging
LOCAL_CFLAGS += -Werror
    #?
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_CFLAGS += -DUT_USE_ZLIB
LOCAL_CFLAGS += -DNO_MALLINFO=1
    #gamekit specific flags
LOCAL_CFLAGS += -DOGRE_BUILD_PLATFORM_ANDROID=1 -DOGREKIT_UNITY_BUILD=1 -DGAMEKIT_GRAPHIC_BACKEND=2
LOCAL_CFLAGS += -DOGRE_UNITY_BUILD=1 -DOGREKIT_MINIMAL_FREEIMAGE_CODEC=1 -DOGREKIT_BUILD_ANDROID=1
    #?
LOCAL_CFLAGS += -DANDROID_ABI="armeabi-v7a" -DANDROID_NATIVE_API_LEVEL=9
LOCAL_CFLAGS += -D_STEP3D_GK #SELF Defined to avoid redefinition of TICKS

#tell linker to use these paths to find libraries
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Engine
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/GameKit/AnimKit
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/FileTools/File
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/FileTools/FileFormats/Blend
LOCAL_LDLIBS += -L$(DEPENDANCIES_SRC_PATH)/GameKit/Utils
LOCAL_LDLIBS += -L$(DEPENDANCIES_SRC_PATH)/OIS
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Bin/lib
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/bullet/src/BulletCollision
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/bullet/src/BulletDynamics
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/bullet/src/LinearMath
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/systemlibs/armeabi-v7a
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/OIS
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/GameKit/Utils
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/Lua/lua
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/FreeImage
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/FreeImage/ZLib
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/ZZipLib
LOCAL_LDLIBS += -L$(GK_PROJECT_ROOT)/build/Dependencies/Source/FreeType
LOCAL_LDLIBS += -L$(ANDROID_NDK)/platforms/android-9/arch-arm/usr/lib

#tell linker to add these static libraries to the list of files to link
LOCAL_LDLIBS += -llog #android log library
LOCAL_LDLIBS += -ldl #android dynamic linker library
    #gamekit static libraries (order matters)
LOCAL_LDLIBS += -lOgreKitCore -lAnimKit  -lGameKitUtils  -lOgreMainStatic
LOCAL_LDLIBS += -lbfBlend -lfbtFile
LOCAL_LDLIBS +=  -lOIS  -lOgreRTShaderSystemStatic
LOCAL_LDLIBS += -lRenderSystem_GLES2Static -lPlugin_ParticleFXStatic -lBulletDynamics -lBulletCollision  -lLinearMath -lLua
LOCAL_LDLIBS += -lFreeImage -lfreetype
LOCAL_LDLIBS += -lZZipLib -lZLib -lGLESv2

# By default, ARM target binaries will be generated in 'thumb' mode, where
# each instruction are 16-bit wide. You can define this variable to 'arm'
# if you want to force the generation of the module's object files in
# 'arm' (32-bit instructions) mode
LOCAL_ARM_MODE := arm

include $(BUILD_SHARED_LIBRARY)

You can see how I'm including the headers on the path and how I'm grabbing the static libraries to add to the shared library. I was looking at the ndk/docs/PREBUILTS and various forum threads and I noticed that there were suggestions to use LOCAL_C_INCLUDES instead of LOCAL_CFLAGS because the former let gdb know about the library's header paths. I also heard using LOCAL_EXPORT_C_INCLUDES would allow my projB, who's make file I already posted, to add those header files to the search path too. But when I do use them, and not the LOCAL_CFLAGS, I get errors that so and so header couldn't be found.
Reply all
Reply to author
Forward
0 new messages