GDB调试手机工程

GDB调试手机工程

挂载自己编译好的工程

  • 以我自己在10.1.6.32编译的工程为例.

    sudo mount -t cifs -o username="android",password="mobile#5" //10.1.6.32/android /mnt/10.1.6.32
  • 错误提示:

    mount: block device //10.1.6.36/android is write-protected, mounting read-only
    mount: cannot mount block device //10.1.6.36/android read-only
  • 实际是密码错误:

    sudo mount -t cifs -o username="android",password="hipad@123" //10.1.6.36/android /mnt/10.1.6.36
sudo mount -t cifs -o username="android",password="hipad@123" //10.1.6.14/android /mnt/10.1.6.14

CIFS文件系统的读写权限

编译gdbserver(或者直接用ndk里面的)

mmm prebuilts/misc/android-arm/gdbserver/ -j8

adb push out/target/product/QS5509QL/system/bin/gdbserver system/bin/

Gdbserver attatch 你要测试的程序

adb shell gdbserver :5039 --attach 2275 (3474 是你要debug的PROCESS PID)

设置手机端口映射到PC

adb forward tcp:5039 tcp:5039

GDB 调试连接

  • 启动GDB

    android@NSGWD180021:/mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak$

    prebuilts/gdb/linux-x86/bin/gdb

    (gdb) set solib-absolute-prefix /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/
    (gdb) set solib-search-path /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/lib/
    (gdb) target remote :5039
    (gdb) b jpeg_start_decompress
    (gdb) b je_malloc if size > 100000 && size != 1336
    (gdb) c
  • 结果

Thread 40 "Measurement Wor" hit Breakpoint 2, je_malloc (size=120000) at external/jemalloc/src/jemalloc.c:1649
1649 if (likely(!malloc_slow)) {
(gdb) bt
#0 je_malloc (size=120000) at external/jemalloc/src/jemalloc.c:1649
#1 0xa99da590 in sqlite3MemMalloc (nByte=120000) at external/sqlite/dist/sqlite3.c:20840
#2 0xa9986d1c in mallocWithAlarm (n=120000, pp=<optimized out>) at external/sqlite/dist/sqlite3.c:24524
#3 sqlite3Malloc (n=5153960875200) at external/sqlite/dist/sqlite3.c:24554
#4 0xa999007c in setupLookaside (db=0x8b9e6e00, pBuf=0x0, sz=1200, cnt=100) at external/sqlite/dist/sqlite3.c:141298
#5 0xa99915f2 in openDatabase (zFilename=<optimized out>, ppDb=<optimized out>, flags=<optimized out>, zVfs=<optimized out>) at external/sqlite/dist/sqlite3.c:143682
#6 0xa9f94f3c in android::nativeOpen (env=0x9d6daf80, clazz=<optimized out>, pathStr=<optimized out>, openFlags=268435456, labelStr=<optimized out>, enableTrace=6 '\006', enableProfile=0 '\000',
lookasideSz=0, lookasideCnt=-2024916864) at frameworks/base/core/jni/android_database_SQLiteConnection.cpp:135
#7 0x70f9719c in android.database.sqlite.SQLiteConnection.nativeOpen ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#8 0x70f975ba in android.database.sqlite.SQLiteConnection.open ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#9 0x70f974ce in android.database.sqlite.SQLiteConnection.open ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#10 0x70f9bf86 in android.database.sqlite.SQLiteConnectionPool.open ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#11 0x70f9bf12 in android.database.sqlite.SQLiteConnectionPool.open ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#12 0x70fa0c8a in android.database.sqlite.SQLiteDatabase.openInner ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#13 0x70fa0858 in android.database.sqlite.SQLiteDatabase.open ()
from /mnt/10.1.6.32/black/QS5509QL-black/v1A5Z-black-test_memory_leak/out/target/product/QS5509QL/symbols/system/framework/arm/boot-framework.oat
#14 0x70fa0ba6 in android.database.sqlite.SQLiteDatabase.openDatabase ()

参考文档:

https://wladimir-tm4pda.github.io/porting/debugging_gdb.html