gdb 调试zygote进程

系统4.4.4 手机n4
zygote本来是app_system程序但是里面 也有java的部分,上次用as没用成功调试他,这次用gdb调试。
进入手机直接用adbserver 附加。手机默认seliunx开启,需要输入 setenforce 0

130|shell@mako:/ # reboot
haidragon@ubuntu:~$ adb devices
List of devices attached
047e3631ce95b902    device

haidragon@ubuntu:~$ adb shell
shell@mako:/ $ su
shell@mako:/ # ps | grep zygote
root      174   1     860932 42196 ffffffff 400c26d8 S zygote
shell@mako:/ # setenforce 1                                                    
shell@mako:/ # gdbserver :9999 --attach 174                                    
Attached; pid = 174
waitpid: Permission denied.
Exiting
1|shell@mako:/ # setenforce 0                                                  
shell@mako:/ # gdbserver :9999 --attach 174                                    
Attached; pid = 174

gdb 调试zygote进程
先端口转发 adb forward tcp:9999 tcp:9999
linux上找到 arm-linux版的gdb必须用要arm-linux的arm-linux-androideabi-gdb(网上都是在ndk里面找的我这边就它没有 其它全有,同时我这有俩个版只有4.7的能行 )
gdb 调试zygote进程
运行

'/home/haidragon/Desktop/android/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gdb'

gdb 调试zygote进程
加载二进制文件,加载符号根路径,加载源码根路径

haidragon@ubuntu:~/Desktop/android$ '/home/haidragon/Desktop/android/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gdb' 
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>.
(gdb) file '/home/haidragon/Desktop/android/out/target/product/mako/symbols/system/bin/app_process' 
Reading symbols from /home/haidragon/Desktop/android/out/target/product/mako/symbols/system/bin/app_process...done.
(gdb) set sysroot '/home/haidragon/Desktop/android/out/target/product/mako/symbols' 
(gdb) set dir '/home/haidragon/Desktop/android' 
(gdb) list
130 /*
131  * sets argv0 to as much of newArgv0 as will fit
132  */
133 static void setArgv0(const char *argv0, const char *newArgv0)
134 {
135     strlcpy(const_cast<char *>(argv0), newArgv0, strlen(argv0));
136 }
137 
138 int main(int argc, char* const argv[])
139 {
(gdb) 

可以选择进入gdb tui界面按 ctrl-x a
然后连接服务端 target remote:9999
gdb 调试zygote进程
调试c层就是这么调试的,gdb怎么使用的其它可以自己研究。

猜你喜欢

转载自blog.51cto.com/haidragon/2417493