1 / 14

Android & GDB

Android & GDB. What is GDB?. GDB the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.

kay-jensen
Télécharger la présentation

Android & GDB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android &GDB

  2. What is GDB? GDB the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: • Start your program, specifying anything that might affect its behavior. • Make your program stop on specified conditions. • Examine what has happened, when your program has stopped. • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. The program being debugged can be written in Ada, C, C++, Objective-C, Pascal (and many other languages). Those programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on most popular UNIX and Microsoft Windows variants.

  3. 主要内容 • GDB(gdbserver)工作原理 • Android 与 Gdb • Elastos3.1(架构在android上的) 与 Gdb

  4. GDB工作原理之组织架构

  5. GDB工作原理之与gdbserver关系 远程调试环境由宿主机GDB和目标机调试stub共同构成,两者通过串口或TCP连接。使用 GDB标准程串行协议协同工作,实现对目标机上的系统内核和上层应用的监控和调试功能。调试stub是嵌入式系统中的一段代码,作为宿主机GDB和目标机调试程序间的一个媒介而存在。 就目前而言,嵌入式Linux系统中,主要有三种远程调试方法,分别适用于不同场合的调试工作:用ROM Monitor调试目标机程序、用KGDB调试系统内核和用gdbserver调试用户空间程序。这三种调试方法的区别主要在于,目标机远程调试stub 的存在形式的不同,而其设计思路和实现方法则是大致相同的。 而我们最常用的是调试应用程序。就是采用gdb+gdbserver的方式进行调试。在很多情况下,用户需要对一个应用程序进行反复调试,特别是复杂的程序。采用GDB方法调试,由于嵌入式系统资源有限性,一般不能直接在目标系统上进行调试,通常采用gdb+gdbserver的方式进行调试。

  6. GDB工作原理之ptrace系统调用 • ptrace系统调用的原型 long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); request决定ptrace做什么, pid是被跟踪进程的ID, data存储从进程空间偏移量为addr的地方开始将被读取/写入的数据. • ptrace系统调用的简要说明 ptrace()是一个系统调用,它允许一个进程控制另外一个进程的执行.不仅如此,我们还可以借助于ptrace修改某个进程的空间(内存或寄存器),任何传递给一个进程(即被跟踪进程)的信号(除了会直接杀死进程的SIGKILL信号)都会使得这个进程进入暂停状态,这时系统通过wait()通知跟踪进程,这样,跟踪进程就可以修改被跟踪进程的行为了.

  7. Android 与 Gdb之ndk-build(一) Android NDK r4引入一个新的小型shell脚本,名字是ndk-build,以简化机器码的构建 脚本位于NDK的顶级目录,并且将在你的应用程序工程目录,或它的任意子目录中的命令行调用 参数选项: ndk-build 重新构建所需的机器代码 ndk-build clean 清除所有生成的二进制文件 ndk-build NDK_DEBUG=1/0 生产/不生产 可调试的本地代码 ndk-build V=1 启动构建,显示构建命令 ndk-build –B 强制完全重新构建

  8. Android 与 Gdb之ndk-build(二) 编译输出目录: Libs:(strip之后的) gdb.setup gdbserver (NDK_DEBUG=1) so或可执行文件 Obj: (未strip之前的) so或可执行文件

  9. Android 与 Gdb之gdb与gdbserver调试流程 Gdb 和 gdbserver 联合调试 Gdb运行在客户端,gdbserver运行在目标开发板上 Gdbserver是要按照android的一套工具和方法来编译的,否则编译出来在模拟器上不能执行。 (gingerbread/ndk/build/tools/build-gdbserver.sh ) 手动调试一段c代码可执行程序了解背后运作机制: 文件目录X:\eclipse3.7.1\android-ndk-r6b\samples\helloworld

  10. Android 与 Gdb之ndk-gdb 命令行调试native代码 从android 2.2开始(同样适用于未来更高版本的android系统),开发者可以使用“ndk-gdb”工具很方便地对native的模块进行调试 这个脚本中干了很多事,最后去启了gdb,中间包括了对模拟器的很多操作,例如端口重定向,启动gdbserver,获得应用程序的pid,等等。主机这边干的事就是傻瓜式的启动ndk-gdb。 手动编译调试一个android app java代码调用一个本地函数 文件目录x/eclipse3.7.1/android-ndk-r6b/samples/ndkfoo

  11. Android 与 Gdb之图形化调试native代码 要先配置好eclipse中关于SDK 和 NDK 的配置(两个world文件) 其中c代码的编译关键在为项目配置一个C_Builder。其实就是指定ndk_build路径 Windows下搭建整个Android开发环境(一)--SDK.doc Windows下搭建整个Android开发环境(二)--NDK.doc 事例:用eclipse联合调试java和native代码

  12. Elastos与 Gdb之C代码调试----- ServiceManager  命令行调试 ServiceManager 与helloworld的调试基本没区别,就是多设置个solib-search-path 图形化调试 ServiceManager(eclipse)

  13. Elastos与 Gdb之C代码调试----- ButtonDemo  命令行调试 ButtonDemo 要在想跟进某个动态库的代码是要确保这个动态库已经被gdb加载,命令shared(sharedlib)。 图形化调试 ButtonDemo(eclipse)

  14. 谢谢观赏 制作:李辉 2011.11.17

More Related