如何调试应用程序在Android与GDBSERVER? [英] How to debug an App on Android with GDBSERVER?

查看:97
本文介绍了如何调试应用程序在Android与GDBSERVER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调试我的应用程序使用通过JNI本机共享库。我可以附加到正在运行的应用程序就好了的gdbserver --attach PID,但我需要真正启动我的应用程序,当我启动gdbserver的命令。

I'm trying to debug a native shared library that my App uses through JNI. I can attach to a running app just fine with "gdbserver --attach pid" but i need to actually launch my app when i launch the gdbserver command.

有一个关于这个话题上百万博客点击率,但他们都不是明确的,以你如何启动应用程序。他们都说只需键入gdbserver的10.0.2.2:1234 ./MyProgram,但究竟什么是MyProgram。那是MyProgram.apk?它是MyProgram.so?它是已安装应用程序时被创建其他一些文件?如果是这样,什么是它的路径?

There's a million blog hits on this topic but none of them seem to be clear as to how you launch your app. They all say to just type "gdbserver 10.0.2.2:1234 ./MyProgram" but what exactly is "MyProgram". Is that MyProgram.apk? Is it MyProgram.so? Is it some other file that gets created when the app is installed? If so, what's its path?

推荐答案

虽然有可能开发出可以直接从壳为他人所描述的推出自由站立的应用程序,这听起来像你code范围内运行Android应用程序框架。因此,你没有一个可执行的,而是有一个包含你的Dalvik类文件和其他资源,包括你的本地共享对象的APK。

While it is possible to develop free standing applications that can be launched directly from the shell as others are describing, it sounds like your code runs within the Android application framework. Therefore, you don't have an executable and instead have an APK that contains your Dalvik class files along with other resources including your native shared object.

启动在APK应用程序包括几个步骤

Launching an application in an APK involves several steps

  1. 的system_server过程中接收到的意图,要求你的应用程序。
  2. 在受精卵过程叫叉掀起了新的进程和运行类的方法。
  3. 您的应用程序在新的进程中运行。

虽然不能直接传递一个可执行文件GDBSERVER发动APK,它很容易使用触发从外壳一推出就凌晨命令。

While you can't launch an APK directly by passing an executable to gdbserver, its fairly easy to trigger a launch it from the shell using the am command.

$ adb -d shell
# am
usage: am [subcommand] [options]

    start an Activity: am start [-D] <INTENT>
        -D: enable debugging

    send a broadcast Intent: am broadcast <INTENT>

    start an Instrumentation: am instrument [flags] <COMPONENT>
        -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
        -e <NAME> <VALUE>: set argument <NAME> to <VALUE>
        -p <FILE>: write profiling data to <FILE>
        -w: wait for instrumentation to finish before returning

    start profiling: am profile <PROCESS> start <FILE>
    stop profiling: am profile <PROCESS> stop

    <INTENT> specifications include these flags:
        [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
        [-c <CATEGORY> [-c <CATEGORY>] ...]
        [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
        [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
        [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
        [-n <COMPONENT>] [-f <FLAGS>] [<URI>]


# am start -n com.android.browser/.BrowserActivity
Starting: Intent { cmp=com.android.browser/.BrowserActivity }
#

在您的应用程序正在运行,使用 gdbserver的--attach&LT; PID&GT; 像你面前。如果你是幸运的您的应用程序调用到本机code给你一个机会,附加和设置断点GDB前等待一些用户交互。

Once your application is running, use gdbserver --attach <pid> like you have before. If you are lucky your application waits for some user interaction before calling into your native code to give you a chance to attach and set your breakpoints in GDB.

这篇关于如何调试应用程序在Android与GDBSERVER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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