Using GDB_gdbclient.py_新生代CV搬运工的博客-程序员秘密

技术标签: debug  gdb  shell  android  google  

Using GDB

The GNU Project debugger (GDB) is a commonly used Unix debugger. This page details using gdb to debug Android apps and processes for platform developers. For third-party app development, see Debug Your App.

 

Prerequisites

To use GDB for debugging apps and processes:

  • Set up environment with envsetup.sh
  • Run the lunch command

For more help with setting up your environment, see Preparing to Build.

Debugging running apps or processes

To connect to an already-running app or native daemon, use gdbclient.py with a PID. For example, to debug the process with PID 1234, run:

gdbclient.py -p 1234

The script sets up port forwarding, starts the appropriate gdbserver on the device, starts the appropriate gdb on the host, configures gdb to find symbols, and connects gdb to the remote gdbserver.

Note: In Android 6 and lower the script was a shell script called gdbclient instead of a Python script called gdbclient.py.

 

Debugging native process startup

To debug a process as it starts, use gdbserver or gdbserver64. For a 64-bit executable:

adb shell gdbserver64 :5039 /system/bin/MY_TEST_64_BIT_APP

For a 32-bit executable:

adb shell gdbserver :5039 /system/bin/MY_TEST_32_BIT_APP

Example output:

Process MY_TEST_64_BIT_APP created; pid = 3460
Listening on port 5039

Next, identify the application PID from the gdbserver output and use it in another terminal window:

gdbclient.py -p APP_PID

Finally, enter continue at the gdb prompt.

Note: If you specify the wrong gdbserver, you'll get an unhelpful error message (such as "Reply contains invalid hex digit 59").

 

Debugging app startup

Sometimes you want to debug an app as it starts, such as when there's a crash and you want to step through code to see what happens before the crash. Attaching works in some cases, but in other cases is impossible because the app crashes before you can attach. The logwrapper approach (used for strace and valgrind) does not always work because the app might not have permissions to open a port, and gdbserver inherits that restriction.

To debug app startup, use the developer options in Settings to instruct the app to wait for a Java debugger to attach:

  • Go to Settings > Developer options > Select debug app and choose your app from the list, then press Wait for debugger.
  • Start the app, either from the launcher or by using the command line to run:
adb shell am start -a android.intent.action.MAIN -n APP_NAME/.APP_ACTIVITY
  • Wait for the app to load and a dialog to appear telling you the app is waiting for a debugger.
  • Attach gdbserver/gdbclient normally, set breakpoints, then continue the process.

To let the app actually run, attach a Java Debug Wire Protocol (JDWP) debugger such as Java Debugger (jdb):

adb forward tcp:12345 jdwp:XXX  # (Where XXX is the pid of the debugged process.)
jdb -attach localhost:12345

 

Debugging apps or processes that crash

If you want debuggerd to suspend crashed processes so you can attach gdb, set the appropriate property:

# Android 7.0 Nougat and later.
adb shell setprop debug.debuggerd.wait_for_gdb true

 

# Android 6.0 Marshmallow and earlier.
adb shell setprop debug.db.uid 999999

At the end of the usual crash output, debuggerd provides instructions on how to connect gdb using the command:

gdbclient.py -p PID

Debugging without symbols

For 32-bit ARM, if you don’t have symbols, gdb can get confused about the instruction set it is disassembling (ARM or Thumb). To specify the instruction set chosen as the default when symbol information is missing, set the following property:

set arm fallback-mode arm  # or thumb

 

Debugging with VS Code

GDB supports debugging platform code on Visual Studio Code. You can use the VS Code debugger frontend instead of the GDB CLI interface to control and debug native code running on devices.

Before using VS Code for debugging, make sure you install the C/C++ extension.

To debug code using VS Code:

  • Ensure all build artifacts (such as symbols) required to run gdbclient.py are present.
  • Run the following command:
gdbclient.py -p pid | -n proc-name | -r ... --setup-forwarding vscode ANY_OTHER_FLAGS

This prints a JSON object and gdbclient.py continues running. This is expected; do not kill the gdbclient.py program.

  • In the debugging tab in VS Code, select add configuration, then select C/C++ gdb attach. This opens a launch.json file and adds a new JSON object to a list.
  • Delete the newly added debugger configuration.
  • Copy the JSON object printed by gdbclient.py and paste it into the object you just deleted. Save the changes.
  • To reload the window to refresh the debugger list, press Ctrl+Shift+P and type "reload window".
  • Select the new debugger configuration and press run. The debugger should connect after 10 to 30 seconds.
  • When you are done debugging, go to the terminal running gdbclient.py and press enter to end the gdbclient.py program.

After setting up the debugger configuration for the first time, you can skip steps 3 through 6.

传送门https://source.android.com/devices/tech/debug/gdb

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/devwang_com/article/details/93509508

智能推荐

redis(六)redis消息拉取_你猜我猜不猜你猜不猜的博客-程序员秘密

消息拉取两个或多个客户端在互相发送和接受消息的时候,通常会使用以下两种方法来传递消息 。第一种方法被称为消息推送(push messaging),也就是由发送者来确保所有接收者已经成功接受到了消息。Redis内置了用于进行消息推送的PUBLISH命令和SUBSCRIBE命令。以前我们说过了这两个命令的缺陷。第二种方法被称为消息拉取(pull messaging),这种方法要求接收者

vscode妙用 java golang go_学生宫布的博客-程序员秘密

快捷键自定义系统快捷键代码补全 也属于快捷键

oracle优化方法之一_cuiyun1675的博客-程序员秘密

oracle数据库优化有很多种方法,下面介绍中采用session跟踪的方式:select event "Wait Event", time_waited "Time waited", time_waited /(...

PHP:案例2--商品价格计算(案例分析+设计思路+知识点讲解+源码+结果展示)_php商品价格计算代码_Yummyik的博客-程序员秘密

一、案例分析1、需求分析若用户在一个全场8折的网站中购买了2斤香蕉、1斤苹果和3斤橘子,它们的价格分别为7.99元/斤、6.89元/斤、3.99元/斤,那么如何使用PHP程序来计算此用户实际需支付的费用呢? 下面通过PHP中提供的变量与常量、算术运算符以及赋值运算符等相关知识来实现PHP中的商品价格计算。2、设计思路使用PHP提供的变量保存用户所购买商品的名称、价格及数量。 由于网站中所有商品的折扣相同,所以使用PHP提供的常量来保存。 分别计算用户购买香蕉、苹果和橘子的价格。 计算打

TOJ1062_dfce62214326的博客-程序员秘密

#include<iostream>using namespace std;int main(){ int n; while (cin >> n, n != 0) { int m=1; for (int i = 1;i < n;++i) { ...

HashSet 与HashMap底层实现_北京-星辰的博客-程序员秘密

1. HashSet底层通过包装HashMap来实现,HashSet在添加一个值的时候,实际上是将此值作为HashMap中的key来进行保存。2. HashMap的底层实现是通过初始化化一个Entry数组来实现key、value的保存。3. 在HashMap的Entry中有四个变量,key、value、hash、next,其中next用于在hash方法添加值冲突时候,所指向的下一个

随便推点

神经网络fully_connected层的forward 和backward实现_啥哈哈哈的博客-程序员秘密

接着上篇tensorflow compute graph的理解,其中operation node 需要给运算定义forward 和backward函数。这篇中我们实现一个简单的fully_connected layer的forward 和backward 函数:class fullyconnect(Operation): def __init__(self, x, w, b):...

倒计时天时分秒函数(cocos-js)_滑天下大稽的博客-程序员秘密

倒计时天时分秒函数(cocos-js)第一次写的方法,和优化后的方法第一次优化后在onload()中创建定时器感谢第一次写的方法,和优化后的方法第一次doSomething1(second_time) { if (parseInt(second_time) < 60) { var time = "<color=#ffffff>倒计时:...

mac系统python读取文件路径_python读取文件常见问题(Mac版)_weixin_39690958的博客-程序员秘密

python读取数据文件以进行下一步分析我一般用pandas,代码很简单import pandas as pdimport numpy as npdata_file = pd.read_csv(file_name)但这会遇到两个问题:文件路径和编码1.文件路径选择mac不存在地址栏,有时候你去获取文件路径粘贴过来打开会报错File b'***.csv' does not exist而你不想每次要去...

Cisco Packet Tracer 实验之动态路由,ospf_小小小辣鸡zz的博客-程序员秘密

Cisco Packet Tracer 实验之动态路由,ospf文章目录Cisco Packet Tracer 实验之动态路由,ospf准备工作1.动态路由2.ospf准备工作先配置电脑ip和路由器网关–en 进入全局模式–conf t 进入配置模式在全局模式下,先指定一个接口,告诉路由器,我现在要配置那个接口,然后,配置指定接口的 ip地址(也称网关)–最后打开(默认状态下,该接口链路是关闭的)如上图,先配置每一个接口的ip地址,直到所有接口都配置完成,如下图所示,每个接口的灯都变亮

hive导出数据导本地的方法_将hive表中的数据导出到本地系统_test_soy的博客-程序员秘密

hive导出查询文件到本地文件的2种办法 通过HQL语句可以将hive  中表的数据生成到指定的目录。有时候 我们可以利用hive来生成统计的中间文件(比源文件小的多的)方法有如下2种:   www.2cto.com  1.INSERT OVERWRITE LOCAL DIRECTORY将结果输出到指定的目录:生成的文件数 和

windows服务器上定时任务上次运行结果0x6_树欲静而风不止的博客-程序员秘密

定时任务每天凌晨1分30秒执行 bat脚本脚本内容@echo offset path=%path%;D:\mysql-5.7.34-winx64\binset y=%date:~0,4%set m=%date:~5,2%set d=%date:~8,2%set h=%time:~0,2%set cdate=%y%%m%%d%_%h%mysqldump -uroot -proot chemical > D:\database_backup\chemical_%cdate%.sql

推荐文章

热门文章

相关标签