• GDB + gdbserver 远程调试mediaserver进程


    远程调试步骤

    Android设备上启动gdbserverattach你想调试的进程,并指定监听调试命令的端口(此端口是TV上的端口)

    $ adb shell

    # ps |grep media  #查看要调试进程的PID,mediaserver进程为例

    # gdbserver :1234 --attach 96   #:1234是端口号,96 是进程ID

    如果设备上没有gdbserver,可以由google ndk中获取,在ndk的如下目录可以找到这个文件:

    android-ndk-r8/toolchains/arm-linux-androideabi-4.9/prebuilt/android-arm

    可以将此文件先推送到设备上。

    进入源码服务器,比如5520编译服务器地址10.9.44.42

    进入到源码工程目录下,进行环境配置,执行build文件夹下的envsetup.shchoosecombo xx xx xx 命令,这时就可以使用gdbclient了。

    adb connect 电视,成功后执行端口映射,将pc机的1234端口映射到电视1234端口

    $ adb forward tcp:1234 tcp:1234   #端口映射,将pc机的1234端口映射到电视的1234端口

    pc端的源码根目录下,执行 gdbclient -e mediaserver -p 1234 #1234端口调试mediaserver

    $ target remote:1234

    接下来通过file命令来加载将要调试的可执行文件,对于android application来说,均为 out/target/product/generic/symbols/system/bin/app_process 这个文件,及设置搜索solib的搜索路径。

     $file /home/luckychou/share/workspace/MT5520_DEV_Q3/release/android/l-pdk/out/target/product/mt5520_ll/symbols/system/bin/app_process32

     $ set solib-search-path /home/luckychou/share/workspace/MT5520_DEV_Q3/release/android/l-pdk/out/target/product/mt5520_ll/symbols/system/lib

     $ set solib-absolute-prefix /home/luckychou/share/workspace/MT5520_DEV_Q3/release/android/l-pdk/out/target/product/mt5520_ll/symbols/system/lib

    之后,即可如调试PC端的C/C++ code一样,下断点,执行,查看内存内容,查看back trace等,来进行对librarydebug工作:

    If the program youre backtracing is multi-threaded, you might want to get a backtrace for all threads:

     (gdb) thread apply all bt

    Another thing which is quite helpful to report is what variables were set locally at each point in the stack:

     (gdb) bt full

    You might want to report the output of the combination of the preceding options:

     (gdb) thread apply all bt full

    And if this is too much irrelevant output, you might want to keep only a few calls, such as the top 10:

     (gdb) thread apply all bt full 10

    If you have a large backtrace, you can log gdb output to a file (the default is gdb.txt):

     (gdb) set logging on

     (gdb) set logging file myfile.txt

    还有很多其他gdb有用的命令,可以参考下网上的。

  • 相关阅读:
    SQL(二)语法
    SQL(一)简介
    linux学习(六)文件基本属性
    Linux学习(五)远程登录
    Linux学习(四) 忘记密码解决方法
    怎样理解阻塞非阻塞与同步异步的区别?
    Python的lambda匿名函数
    Twisted源码分析系列01-reactor
    Python装饰器学习(九步入门)
    Python关键字yield的解释
  • 原文地址:https://www.cnblogs.com/shakin/p/6950112.html
Copyright © 2020-2023  润新知