1、安卓機器中本地使用gdb調試linux
!android shell $cd /data/local/tmp $wget http://dan.drown.org/android/gdb-static.tar.gz $tar zxf gdb-static.tar.gz $chmod 777 gdb $./gdb 程序名 ....
2、雙機(安卓上安裝gdbserver,PC端運行gdbclient)android
一、編譯native代碼時使用NDK_DEBUG參數,編譯完成後會在libs/armeabi-v7/下多生成兩個文件gdb.setup和gdbserver;ios
!windows shell $ndk-build NDK_DEBUG=1
二、將gdbserver拷貝到手機目錄下shell
!windows shell $adb push gdbserver /data/local/tmp/ $adb shell chmod 777 /data/local/tmp/gdbserver
三、運行gdbserverwindows
!android shell 1 $cd /data/local/tmp $./gdbserver :1234 ;若是附加進程則--attach 2222 。。。
四、轉發端口(另開一個shell)sass
!windows shell $adb forward tcp:1234 tcp:1234
五、PC端使用gdbclient連接(使用NDK中自帶的gdb)bash
!windows shell $cd <your_path>\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\linux-x86_64\bin $./arm-linux-androideabi-gdb $$ target remote :1234 ;鏈接遠程gdbserver $$ set args "Hello, World" Test ;設置參數 $$ show args $$ set solib-search-path obj/local/armeabi ;設置符號路徑 $$ bt ;查看堆棧 $$ l ;有符號會顯示pc附件源碼 $$ break main ;下斷點 $$ run ;運行 $$ n ;n單步執行 s單指令執行 $$ x ;查看內存 $$ info sharedlibrary ;查看加載的共享模塊 $$ show debug-file-directory ;調試符號目錄 $$ set debug-file-directory <directory> ;設置調試符號目錄 $$ set symbol-file <directory> ;設置符號文件 $$ set arm fallback-mode ;設置thumb模式 $$ set arm force-mode ;設置arm模式 $$ break 0x400c0e88 + (($cpsr>>5)&1) ;thumb模式下斷點須要+1 $$ break context_switch if next == init_task ;break condition $$ command 1 > print xx1 > print xx2 >end ;斷點一中斷時輸出的信息 $$ p MACROS ;宏顯示不了須要編譯時make KCFLAGS=-ggdb3 $$ disass ;顯示彙編代碼 $$ set $r0=1 ;設置寄存器的值 $$ po self ;po是print-object的簡寫 ios特有 $$ info proc ;all -- List all available /proc info $$ info proc ;cmdline -- List command line arguments of the process $$ info proc ;cwd -- List current working directory of the process $$ info proc ;exe -- List absolute filename for executable of the process $$ info proc ;mappings -- List of mapped memory regions $$ info proc ;stat -- List process info from /proc/PID/stat $$ info proc ;status -- List process info from /proc/PID/status
x /nfu 0x<addr>:查看內存地址中的值。 n表示要顯示的內存單元的個數 f表示顯示方式, 可取以下值 x 按十六進制格式顯示變量。 d 按十進制格式顯示變量。 u 按十進制格式顯示無符號整型。 o 按八進制格式顯示變量。 t 按二進制格式顯示變量。 a 按十六進制格式顯示變量。 i 指令地址格式 c 按字符格式顯示變量。 f 按浮點數格式顯示變量。 u表示一個地址單元的長度 b表示單字節, h表示雙字節, w表示四字節, g表示八字節
查看架構信息等命令 架構
$set arm disassembler This commands selects from a list of disassembly styles. The "std" style is the standard style. $show arm disassembler Show the current disassembly style. $set arm apcs32 This command toggles ARM operation mode between 32-bit and 26-bit. $show arm apcs32 Display the current usage of the ARM 32-bit mode. $set arm fpu fputype This command sets the ARM floating-point unit (FPU) type. The argument fputype can be one of these: auto Determine the FPU type by querying the OS ABI. softfpa Software FPU, with mixed-endian doubles on little-endian ARM processors. fpa GCC-compiled FPA co-processor. softvfp Software FPU with pure-endian doubles. vfp VFP co-processor. $show arm fpu Show the current type of the FPU. $set arm abi This command forces gdb to use the specified ABI. $show arm abi Show the currently used ABI. $set arm fallback-mode (arm|thumb|auto) gdb uses the symbol table, when available, to determine whether instructions are ARM or Thumb. This command controls gdbs default behavior when the symbol table is not available. The default is ‘auto’, which causes gdb to use the current execution mode (from the T bit in the CPSR register). $show arm fallback-mode Show the current fallback instruction mode. $set arm force-mode (arm|thumb|auto) This command overrides use of the symbol table to determine whether instructions are ARM or Thumb. The default is ‘auto’, which causes gdb to use the symbol table and then the setting of ‘set arm fallback-mode’. $show arm force-mode Show the current forced instruction mode. $set debug arm Toggle whether to display ARM-specific debugging messages from the ARM target support subsystem. $show debug arm Show whether ARM-specific debugging messages are enabled.
切換匯編與源碼調試app
$set disassemble-next-line on $set disassemble-next-line off $show disassemble-next-line
調試子進程tcp
set follow-fork-mode [parent|child] parent: fork以後繼續調試父進程,子進程不受影響。 child: fork以後調試子進程,父進程不受影響。 detach-on-fork參數,指示GDB在fork以後是否斷開(detach)某個進程的調試,或者都交由GDB控制: set detach-on-fork [on|off] on: 斷開調試follow-fork-mode指定的進程。 off: gdb將控制父進程和子進程。follow-fork-mode指定的進程將被調試,另外一個進程置於暫停(suspended)狀態。