Debugging shared libraries?

I’m really digging the Tegra Developer Pack on OSX. It’s made managing my Eclipse / NDK / SDK setup much more sane. However, I’m running into an issue when attempting to debug a native (c++) shared library. Here’s how things are configured:

I’m using a rooted and seemingly properly configured Nexus 7 device.

I have a Java Android application that references another Java library that dynamically loads a shared library built via an external makefile. There are a handful of native functions exposed to the Java library from the native library via the “native” keyword in Java.

The native library is built with debug info enabled. I’ve verified that symbols are loaded when the native library is loaded. I’m using the “Debug As Android NDK Application.” Yet when I try to step into a native function exposed by the native library, it ends up stepping over the function instead.

It feels like shared library debugging like this is not supported by the tool. But before I go down the road or refactoring the code to use static linkage, I thought I’d post here for any possible guidance on this issue. Surely someone has encountered this kind of problem before.

Any info / tips / suggestions would be helpful!

could you have a look at your debug configuration. is your gdb working?

It seems like its working. Can you be more specific as to how I’d go about verifying that? :D

Yeah, so I’ve verified that gdb / gdbserver are running properly. I’m able to navigate the threads executing and break into the native side of the app. Still can’t step across the java / native bride though. Damn peculiar.

I wonder if anyone that works on this tool can actually provide a minimum level of support here. :) It’s a good tool but these kinds of issues are pretty annoying to diagnose…

could you check your debug mode. there is three mode: java code. native code, Java and Native code. you need to use Java and Native code. you can find it project properties>Debugging>Debug Mode

Thanks for that info.

Turns out that ndk-build was stripping my shared library of all symbols. That was only obvious to me when breaking in with gdb and dumping loaded shared libraries. Verified with file command on the shared library on disk. It was my understanding that setting NDK_DEBUG=1 would stop that stripping from happening. Turns out that the NDK shipped with the tegra tools always strips shared libraries.

I had to modify the NDK makefile to resolve this problem nicely. Crazy, right?

Gamesalad-- Would you mind showing the changes you made to the ndk make file?

you can add additional java lib with Nsight Tegra, add the lib via project properties>Ant Build>Additional Dependencies.

I have the exact problem, and GameSalad, can you tell me what exactly you do to fix it. Let me rephrase the problem and make sure everyone is on the same page. What happen is that I have a project which is relay on another share library project,

Project A - contains Java and C++ code (A.java, A.cpp)
Project B - dynamic C++ library (B.cpp)

The output of these will contains
A.so - The C++ code from project A
B.so - The C++ code from project B

During the debug session, everything work fine as long as stepping through the code within Project A, meaning any code inside (A.java and A.cpp). However, GDB cannot find any debugging information when stepping through the code inside project B (B.cpp), GDB will just step over any function call into Project B (B.cpp)

I use the tool arm-linux-androideabi-gcc-nm under NDK toolchains folder to check if B.so contains any debug symbol by doing

arm-linux-androideabi-gcc-nm -a b.so

and I actually get some legitimate output, which I think it indicates the .so file contains the correct debug info.

Can someone tell me in the previous post, GameSalad said that ndk-build was stripping the shared library of all symbol, where is the ndk-build means in here? And where do I modified the “NDK_DEBUG=1” under Tegra Nsight? And where is the NDK makefile etc? Or is this problem already have a solution? Thanks!

I think this post should under Nsight Tegra, Visual Studio Edition

It is working wow.

yeah dude it is working perfect.