如何使用gdbclient gdbserver调试C/C++ native文件

如何使用gdbclient gdbserver调试C/C++ native文件

例如调试systemui Native文件

1.配置adb转发,手机端运行gdbserver命令

user@aclgcl-ubnt:/data1/AJ9_3$ adb forward tcp:5039 tcp:5039 
user@aclgcl-ubnt:/data1/AJ9_3$ adb shell 
root@idol347:/ # ps |grep systemui 
u0_a29    8320  320   1001848 88264 ffffffff b6fb14b8 S com.android.systemui 
root@idol347:/ # gdbserver :5039 --attach 8320                                 
Attached; pid = 8320 
Listening on port 5039 
Remote debugging from host 127.0.0.1 

(端口号5039也可以是其他未被占用的端口,例如1234等等)

2.PC端运行gclient命令

(gclient因为是在/build/envsetup里定义的,所以在此之前需要执行source build/envsetup.sh 和choosecombo命令)

user@aclgcl-ubnt:/data1/AJ9_3$ gdbclient app_process32 :5039

待手机shell端会显示:Remote debugging from host 127.0.0.1 就表示连接成功

3.之后就可以进行一系列的gdb调试操作

user@aclgcl-ubnt:/data1/AJ9_3$ gdbclient app_process32 :5039
Process is 'system/bin/app_process32'
Port is :5039

If you haven't done so already, do this first on the device:
    gdbserver :5039 /system/bin/app_process32
 or
    gdbserver :5039 --attach <PID>

GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>...
Reading symbols from /data1/AJ9_3/out/target/product/idol347/symbols/system/bin/app_process32...done.
warning: while parsing target library list: not well-formed (invalid token)
warning: Could not load shared library symbols for 10 libraries, e.g. libNimsWrap.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
getegid () at bionic/libc/arch-arm/syscalls/getegid.S:6
6	    mov     ip, r7
Function "art_sigsegv_fault" not defined.
Breakpoint 1 (art_sigsegv_fault) pending.
ART debugging mode is enabled.
If you are debugging a native only process, you need to
re-enable normal SIGSEGV handling using this command:
  handle SIGSEGV print stop
(gdb) b SetTorchBrightness
Breakpoint 2 at 0xa577c6b8: file frameworks/base/packages/SystemUI/jni/torchnative.cpp, line 152.
(gdb) c
Continuing.
[New Thread 2164]
[Switching to Thread 2164]

Breakpoint 2, SetTorchBrightness (env=0xb89d6180, thiz=0xa588fa2c, brightness=200) at frameworks/base/packages/SystemUI/jni/torchnative.cpp:152
warning: Source file is more recent than executable.
152	static jint SetTorchBrightness(JNIEnv *env, jobject thiz,jint brightness) {
(gdb) list
147	  //result = read_int(get_torch_path());
148	  //[BUGFIX] Mod-END-by-TSCD.jin.dong 01/14/2015 PR-890978
149	  return result;
150	}
151	
152	static jint SetTorchBrightness(JNIEnv *env, jobject thiz,jint brightness) {
153	  TCTALOGE("==========SetTorchBrightness");
154	  int result;
155	
156	  	char *ptr = "test";
157		strcpy(ptr, "TEST");
158		
(gdb) n
153	  TCTALOGE("==========SetTorchBrightness");
(gdb) n
152	static jint SetTorchBrightness(JNIEnv *env, jobject thiz,jint brightness) {
(gdb) n
153	  TCTALOGE("==========SetTorchBrightness");
(gdb) n
157		strcpy(ptr, "TEST");
(gdb) n
warning: while parsing target library list: not well-formed (invalid token)
warning: while parsing target library list: not well-formed (invalid token)

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值