调试 Android 操作系统的原生库 [英] Debugging native libraries for Android OS

查看:11
本文介绍了调试 Android 操作系统的原生库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为 Android 操作系统创建一个共享库.虽然我已经在 Eclipse 中完成了一些 Android 应用程序,但我决定使用 Visual Studio 和 vs-Android 插件开始我的原生开发:

I am to create a shared library for Android OS. Although I have done some Android apps in Eclipse I decided to start my native development with Visual Studio and vs-Android add-on:

http://code.google.com/p/vs-android/

我对 VS 非常熟悉,Google 发现该插件是第一批结果之一.我已经完成了整个设置过程,安装了 JDK、NDK、Ant,设置了系统变量,最后得到了一个工作项目.它就像一个魅力!但是有一个很大的缺点.我无法调试本机代码.

I am really familiar with VS and Google found that add-on as one of the first results. I have gone through the whole setup procedure, installed JDK, NDK, Ant, set system variables and finally got a working project. It works like a charm! But there is a BIG drawback. I am not able to debug the native code.

我知道有 NDK-GDB 工具,但我在尝试设置它时总是失败.我已经阅读了 NDK-GDB.html 文档,丢弃了最初的 vs-Android 解决方案并成功完成了以下教程:

I know there is NDK-GDB tool, but I am constantly failing when trying to setup it. I have read NDK-GDB.html document, threw away the initial vs-Android solution and successfully gone through the following tutorial:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/

但现在我在尝试通过时再次卡住:

but now I am stuck again when trying to go through the:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/

http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/

我也尝试过 WinGDB - 只是导入了包含本机代码和 Java 代码的工作 Eclipse 项目,但它甚至无法编译.

I also tried WinGDB - just imported working Eclipse project containing both native and Java code, but it doesn't even compile.

简而言之,有很多拼图,但我仍然缺少一些.恐怕我错过了使用 NDK-GDB 之类的命令行工具调试代码的整个想法.

In short, there are many pieces of the puzzle, but I am still missing some of them. I am afraid that I am missing the whole idea of debugging code with a command line tool like NDK-GDB is.

谁能给我一些解释和明确的步骤如何调试本机库(不管是使用 vs-android 还是 Eclipse 或其他任何东西)?请注意,我不是 Linux 专家,也不熟悉 cygwin 或 gdbserver.

Can someone provide me some explanation and clear steps how to debug native libraries (doesn't matter if with vs-android or Eclipse or whatever else)? Please be aware I am not a Linux guru and also not familiar with cygwin or gdbserver.

推荐答案

为了能够使用 ndk-gdb

构建

在 jnk/Android.mk 中设置 -g 编译器标志来构建 gdb-server

Set the -g compiler flag in jnk/Android.mk to build the gdb-server

LOCAL_CFLAGS := -g

构建用于调试的原生库 NDK_DEBUG=1

Build the native lib for debugging NDK_DEBUG=1

ndk-build NDK_DEBUG=1

在清单中设置可调试的应用程序.

Set the application debuggable in the manifest.

android:debuggable=true

打开 cygwin 并 cd 到项目路径.设置 adb 的路径.

Open cygwin and cd to the project path. Set the path to adb.

export PATH=$PATH:/path_to_android_sdk/platform-tools

然后启动gdb

ndk-gdb --verbose --adb=adb.exe

当你连接到 gdb-server 后,你必须输入 continue

You will have to type continue when you have connected to the gdb-server

这篇关于调试 Android 操作系统的原生库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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