Learn android5.0 after the art virtual machine, looked at the source code, compared to the headache, decided by the dynamic debugging way to learn.
The art virtual machine has a dex2oat executable program. I thought of debugging this dex2oat through GDB and Gdbserver.
Record the Debugging method:
GDB runs on the Local System (Windows/linux)
Gdbserver run on Android real/emulator (adb shell Ls/system/bin to see if there are gdbserver, if not, can be obtained from the source Code Prebuild folder, or it can be obtained from the NDK file)
The PS:GDB and Gdbserver versions are consistent, or they will go wrong.
One: "
1. Preparation work :
1-1. Find the GDB and Gdbserver executables in the Prebuild folder (also available in the NDK)
1-2, put gdbserver through adb shell push into system/bin
1-3, push the Hello.jar needed by Dex2oat to/data/test/.
2, through the ADB in the Android emulator through the Gdbserver association related processes or start related processes
2-1,gdbserver Associated processes: adb shell gdbserver: Port number 1234--attach process PID
(Process PID can be attach system_process (without testing) through ADB shell, debug application)
2-2,gdbserver Start related process: adb shell gdbserver: port number 1234 Dex2oat--dex-file=/data/test/hello.jar--oat-file=/data/ Test/hello.dex
3, Port mapping :
On the local command line: adb forward tcp:1234 tcp:1234
4, start gdb in the directory where GDB is located
4-1,cd/home/zero/android-5.0.0_r3.0.1/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin
4-2,./arm-linux-androideabi-gdb
5, after entering GDB:
5-1, (GDB) target remote localhost:1234 (connection target)
5-2, (GDB) file/home/zero/android-5.0.0_r3.0.1/out/target/product/generic/symbols/system/bin/dex2oat (Find executable file dex2oat, all in the Android source of this bin directory)
5-3, (GDB) set Solib-absolute-prefix/home/zero/android-5.0.0_r3.0.1/out/target/product/generic/symbols (do not understand why this sentence)
5-4, (GDB) Set Solib-search-path/home/zero/android-5.0.0_r3.0.1/out/target/product/generic/symbols/system/lib (Set the function path?? )
6, set breakpoints, start execution
6-1, (GDB) b main
6-2, (GDB) c
II: Gdbclient and GDB
1, execute in Source directory:
1-1,source build/envsetup.sh
1-2,lunch Full-eng
2, similar to the above Gdbserver's boot and adb forward port mappings
3, Start gdbclient
Gdbclient dex2oat:1234
4, set breakpoints, start debugging
Source code for Gdbclient in envsetup.sh
<span style= "FONT-SIZE:18PX;" ># Gdbclient now determines whether the user wants to debug a 32-bit or 64-bit# executable, set up the approriate gdbse RVer, then invokes the proper host# gdb.function gdbclient () {local out_root=$ (Get_abs_build_var product_out) Local OU t_symbols=$ (Get_abs_build_var target_out_unstripped) Local out_so_symbols=$ (Get_abs_build_var TARGET_OUT_SHARED_ libraries_unstripped) Local out_vendor_so_symbols=$ (Get_abs_build_var Target_out_vendor_shared_libraries_ unstripped) Local out_exe_symbols=$ (get_symbols_directory) Local prebuilts=$ (Get_abs_build_var ANDROID_PREBUILTS) Lo Cal arch=$ (Get_build_var target_arch) Local GDB case "$ARCH" in arm) gdb=arm-linux-androideabi-gdb;; arm64) Gdb=arm-linux-androideabi-gdb; Gdb64=aarch64-linux-android-gdb;; MIPS|MIPS64) gdb=mips64el-linux-android-gdb;; x86) Gdb=x86_64-linux-android-gdb;; x86_64) gdb=x86_64-linux-android-gdb;; *) echo "Unknown arch $ARCH"; return 1;; Esac #参数1 <span style= "White-space:pre" ></span> if ["$OUT _root"-A "$PREBUILTS"]; Then local exe= "$" if ["$EXE"]; Then exe=$1 if [[$EXE =~ ^[^/].*]; Then exe= "system/bin/" $EXE fi else exe= "app_process" fi #参数2 <span S Tyle= "White-space:pre" ></span> local port= "$" if ["$PORT"]; Then port=$2 else port= ": 5039" fi local pid= "$" if ["$PID"]; Then if [[! "$PID" =~ ^[0-9]+$]]; Then pid= ' PID $ ' if [[! "$PID" =~ ^[0-9]+$]]; Then # this likely didn ' t work because of returning multiple processes # try again, fi Ltering by root processes (don ' t contain colon) pid= ' adb shell PS | \grep | \grep-v ":" | awk ' {print $} ' if [[! "$PID" =~ ^[0-9]+$]] then echo "couldn' t resolve ' to a single PID return 1 else Echo ' echo "Warning:multiple processes matching ' $ ' observed, using root process" echo " Fi fi fi adb Forward "tcp$port" "tcp$port" local use64bit= " $ (is64bit $PID) "adb shell gdbserver$use64bit $PORT--attach $PID & Sleep 2 Else echo "echo" If you haven ' t did so already, does this first on the device: "Echo" Gdbse RVer $PORT/system/bin/$EXE "echo" or "echo" Gdbserver $PORT--attach <PID> " echo "" Fi out_so_symbols= $OUT _so_symbols$use64bit out_vendor_so_symbols= $OUT _vendor_so_symb Ols$use64bit echo >| " $OUT _root/gdbclient.cmds "" Set Solib-absolute-prefix $OUT _symbols "echo >> $OUT _root/gdbclient.cmds" "SeT Solib-search-path $OUT _so_symbols: $OUT _so_symbols/hw: $OUT _so_symbols/ssl/engines: $OUT _so_symbols/drm: $OUT _so_ SYMBOLS/EGL: $OUT _so_symbols/soundfx: $OUT _vendor_so_symbols: $OUT _vendor_so_symbols/hw: $OUT _vendor_so_symbols/ EGL "Echo >>" $OUT _root/gdbclient.cmds "" Source $ANDROID _build_top/development/scripts/gdb/dalvik.gdb "EC Ho >> "$OUT _root/gdbclient.cmds" "Target remote $PORT" # Enable Special Debugging for ART processes. if [[$EXE =~ (^|/) (APP_PROCESS|DALVIKVM) (|32|64) $]]; Then echo >> "$OUT _root/gdbclient.cmds" "art-on" fi echo >> "$OUT _root/gdbclient.cmds" "" Local which_gdb= # 64-bit EXE found if ["$USE 64BIT"! = ""]; Then which_gdb= $ANDROID _toolchain/$GDB # 32-bit exe/32-bit platform Elif ["$ (Get_build_var Targ Et_2nd_arch) "=" "]; Then which_gdb= $ANDROID _toolchain/$GDB # 32-bit exe/64-bit platform Else which_gdb= $ANDR oid_toolchain_2nd_arch/$GDB fi gdbwrapper $WHICH _gdb "$OUT _root/gdbclient.cmds" "$OUT _exe_symbols/$EXE" Else echo "unabl E to determine build system output dir. " Fi}</span>
GDB and Gdbserver debug Android app with executable