gdb debug android executable

For convenience of discussion, assume our android executable name is
hello-exe.

1. Compile debug version of android executable file, use following command
under project path.

ndk-build NDK_DEBUG=1

When compiling finished, make sure there are gdbserver, gdb.setup and
hello-exe in libs/armeabi-v7a/.

2. Push gdbserver, hello-exe to android device.

adb push libs/armeabi-v7a/gdbserver /data/local/tmp/
adb push libs/armeabi-v7a/hello-exe /data/local/tmp/

After that, pull app_process from android device to PC.

adb pull /system/bin/app_process ./

3. Prepare for debugging

1) Run hello-exe as background process.

adb shell /data/local/hello-exe &

And get PID of hello-exe, for convenience, let $HPID be PID of
hello-exe.

adb shell busybox ps aux | busybox grep hello-exe

Busybox includes a lot of useful commands, which make debugging easier. It is my strong recommandation to have busybox in
your android devices.

2) Start gdbserver to listen debugging requests.

adb shell /data/local/tmp/gdbserver tcp:5039 --attach $HPID

4 Start another terminal to perform remote debug

1) Start gdb

adb forward tcp:5039 tcp:5039
arm-linux-androideabi-gdb app_process

arm-linux-androideabi-gdb is included in android NDK package.

2) Perform debugging

(gdb) target remote :5039

Load symbols from obj/local/armeabi-v7a/hello-exe

(gdb) symbol-file obj/local/armeabi-v7a/hello-exe

Setup source path. gdb.setup contains information of solib-search-path and
source directory.

Typically, the commands will be

(gdb) directory jni
(gdb) set solib-search-path obj/local/armeabi-v7a

3) Do debugging as PC applications

5 Other issues

1) How to add breakpoints.

Before remote debugging, android executable must be in running state. Often,
this makes toggling breakpoints impossible.

Fortunately, there is simple method to work around. First, add the code

int endless_cnt = 0, useless_cnt;
while(endless_cnt) {
useless_cnt ++;
}

at entrance of the program. After starting hello-exe, it will be in endless
loop, waiting for debugging.

Next, before any debugging actions, use the following command to quit endless
loop.

(gdb) set var endless_cnt = 1

Then you can add breakpoints, and do debugging as usual.

gdb debug android executable

时间: 2024-08-19 01:37:22

gdb debug android executable的相关文章

Eclipse+CDT+GDB调试android NDK程序(转)

Eclipse+CDT+gdb调试android ndk程序 先介绍一下开发环境,在这个环境下,up主保证是没有问题的. ubuntu 11.10 eclipse 3.7(indego) for java jdk 6 android sdk 2.2 andrid ndk r7 当然,在windows环境下通过cygwin等工具也是可以实现gdb调试的,我也确实实现过.但是性能实在太低,卡的根本没法用.Linux下直接用gdb调试本地方法是很流畅的. 再确定安装并配置好开发环境之后,就可以开始了.

使用GDB调试Android NDK native(C/C++)程序

使用GDB调试Android NDK native(C/C++)程序 先说明下,这里所谓的ndk native程序跟Android上层java应用没有什么关系,也不需要涉及jni来封装native接口,通俗来讲,就是把编译好的纯C/C++程序,push到Android设备或者仿真器上,然后在设备上运行该程序.而调试则是通过attach到gdbserver来实现.推荐在Ubuntu或者mac osx下来进行,windows下要安装cygwin来模拟posix环境,速度很慢的说.具体操作如下: 0.

gdb Debug

源码会进行行号提示. 如果需要查看在其他文件中定义的函数,在l后加上函数名即可定位到这个函数的定义及查看附近的其他源码.或者:使用断点或单步运行,到某个函数处使用s进入这个函数. 3)设置断点 (gdb) b 6 这样会在运行到源码第6行时停止,可以查看变量的值.堆栈情况等:这个行号是gdb的行号. 4)查看断点处情况 (gdb) info b 可以键入"info b"来查看断点处情况,可以设置多个断点: 5)运行代码 (gdb) r 6)显示变量值 (gdb) p n 在程序暂停时,

使用GDB调试Android NDK native(C/C++)程序-转

最 近写了些需要跨平台兼容的C++库,Android是其中需要兼容的平台之一.区别于Windows,Mac中功能强大的IDE环境,官方并没有为 Android ndk提供太多的支持.因此,尝试了下通过一些配置使用gdb来调试Android ndk的C++程序,感觉还算方便,记录下来跟大家分享. 先 说明下,这里所谓的ndk native程序跟Android上层java应用没有什么关系,也不需要涉及jni来封装native接口,通俗来讲,就是把编译好的纯C/C++程 序,push到Android设

Android gdb so

gdb debug an android application 1.gdb 要有gdbserver 一般模拟器默认装有gdbserver,如2.3.3的模拟器,看一下有没有: D:\Developer\sdk\platform-tools>adb shell ls -l /system/bin/gdb*-rwxr-xr-x root shell 5664 2010-07-01 05:03 gdbjithelpe-rwxr-xr-x root shell 151868 2010-05-11 09

Android BuildConfig.DEBUG的妙用

在Android开发中,我们使用android.util.Log来打印日志,方便我们的开发调试.但是这些代码不想在发布后执行,我们并不想在软件发布后调试日志被其他开发者看到,现在我的方法是设置一个全局变量,标记软件为Debug模式还是Release模式.来看下代码: public class Log { private static final boolean DEBUG = true; public static void i(String tag, String msg) { if (DEB

Android Debug

我们今天将讨论的是8大你不得不知的Android调试工具,这些工具部分属于系统自带,也是一种方式方法,希望对大家有所帮助. ? ? 1. 查看当前堆栈 1) 功能:在程序中加入代码,使可以在logcat中看到打印出的当前函数调用关系 2) 方法:?new Exception("print trace").printStackTrace(); 2. MethodTracing 1) 功能:用于热点分析和性能优化,分析每个函数占用的CPU时间,调用次数,函数调用关系等 2) 方法: a)

android debug工具集(挺全的)

1.TraceView 1)功能:用于热点分析和性能优化,分析每个函数占用的CPU时间,调用次数,函数调用关系等 2)方法: a)在程序代码中加入追踪开关 import android.os.Debug; -- android.os.Debug.startMethodTracing("/data/tmp/test");// 先建/data/tmp目录 --// 被追踪的程序段 android.os.Debug.stopMethodTracing(); b)编译,运行后,设备端生成/da

【转】Android开发工具--android-studio-bundle-141.2288178

原文网址:http://www.androiddevtools.cn/ AndroidDevTools简介 Android Dev Tools官网地址:www.androiddevtools.cn 收集整理Android开发所需的Android SDK.开发中用到的工具.Android开发教程.Android设计规范,免费的设计素材等. 欢迎大家推荐自己在Android开发过程中用的好用的工具.学习开发教程.用到设计素材,欢迎Star.Fork ?. 如果你对翻译英文的Android开发技术文章