Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

Debugging Android NDK C/C++ code in Eclipse - breakpoints are not hit

I downloaded Android SDK Bundle for Linux and Android NDK. ADT was installed, I installed CDT.

I created a Android project and added native support (jni). Then I wrote native function in java-code which exporting in c++ code. In c++ code I defined this function.

Java-code:

static {
    System.loadLibrary("test");
}

private native String get_text_from_cpp();

c++ code (h):

extern "C"{
   JNIEXPORT jstring JNICALL Java_com_example_test_MainActivity_get_1text_1from_1cpp(JNIEnv *, jobject);
}

c++ code (cpp):

JNIEXPORT jstring JNICALL Java_com_example_test_MainActivity_get_1text_1from_1cpp(JNIEnv * env, jobject){
    return env->NewStringUTF( "hello from C++" );
}

Code works without errors. But when I set breakpoint in c++ code it is not hit.

build-nkd NDK_DEBUG = 1 - are included

I followed this instructions http://tools.android.com/recent/usingthendkplugin

Android.mk in jni/ has LOCAL_CFLAGS := -g

I have read very much information but I could't customized Eclipse. Please, help anybody.

PS: I am sorry for my English is not my native language. I have difficulty in writing.

Add: Also during debug in console shows: "warning: Could not load shared library symbols for 95 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()."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The trick I use is to put a usleep call as the very first native line in my debug code.

This makes your thread sleep and gives the debugger a chance to be ready for you.

#include <unistd.h>

.
.
.

#ifndef NDEBUG
usleep(5000 * 1000);
#endif

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...