您的位置:首页 > 编程语言 > C语言/C++

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

2016-07-14 17:43 846 查看


如何使用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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息