在 Eclipse 中调试 Android NDK C/C++ 代码 - 未命中断点 [英] Debugging Android NDK C/C++ code in Eclipse - breakpoints are not hit

查看:25
本文介绍了在 Eclipse 中调试 Android NDK C/C++ 代码 - 未命中断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了适用于 Linux 和 Android NDK 的 Android SDK Bundle.安装了ADT,我安装了CDT.

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

我创建了一个 Android 项目并添加了原生支持 (jni).然后我在java代码中编写了本地函数,在c++代码中导出.我在 C++ 代码中定义了这个函数.

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 代码:

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

private native String get_text_from_cpp();

c++ 代码(h):

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

c++ 代码(cpp):

c++ code (cpp):

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

代码运行没有错误.但是当我在 C++ 代码中设置断点时,它不会被命中.

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

build-nkd NDK_DEBUG = 1 - 包含

build-nkd NDK_DEBUG = 1 - are included

我按照此说明http://tools.android.com/recent/usingthendkplugin

jni/中的 Android.mk 有 LOCAL_CFLAGS := -g

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

我阅读了很多信息,但我无法自定义 Eclipse.请帮助任何人.

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

PS:很抱歉我的英语不是我的母语.我写作有困难.

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

添加:也在控制台中调试期间显示:警告:无法加载 95 个库的共享库符号,例如/system/bin/linker.使用info sharedlibrary"命令查看完整列表.你需要set solib-search-path"还是set sysroot"?警告:无法找到动态链接器断点函数.GDB 最终会重试.同时,很有可能GDB 无法调试共享库初始值设定项或在 dlopen() 之后解决挂起的断点."

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()."

推荐答案

我使用的技巧是将 usleep 调用作为调试代码中的第一行.

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

这篇关于在 Eclipse 中调试 Android NDK C/C++ 代码 - 未命中断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆