vscode單步調試Android c++源碼


步驟

注意:這個過程需要在Android源碼環境中運行,可以使用adb端口轉發工具,來連接服務器端的源碼進行運行

關於adb端口轉發:請看https://www.cnblogs.com/pyjetson/p/14828485.html

1. 運行gdbclient.py腳本

首先是使用vscode remote ssh終端連接服務器
1. 找到進程的pid號
adb shell "ps -A | grep vold"

2. 運行gdbclient.py腳本
gdbclient.py -p 20750 --setup-forwarding vscode

2. 復制生成的launch.json並新建/home/jetson/android_aosp/aosp/.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [

        {
            "miDebuggerPath": "/home/jetson/android_aosp/aosp/prebuilts/gdb/linux-x86/bin/gdb", 
            "program": "/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/bin/vold", 
            "setupCommands": [
                {
                    "text": "-enable-pretty-printing", 
                    "description": "Enable pretty-printing for gdb", 
                    "ignoreFailures": true
                }, 
                {
                    "text": "-environment-directory /home/jetson/android_aosp/aosp", 
                    "description": "gdb command: dir", 
                    "ignoreFailures": false
                }, 
                {
                    "text": "-gdb-set solib-search-path /home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/lib/:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/lib/hw:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/lib/ssl/engines:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/lib/drm:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/lib/egl:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/system/lib/soundfx:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/vendor/lib/:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/vendor/lib/hw:/home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols/vendor/lib/egl", 
                    "description": "gdb command: set solib-search-path", 
                    "ignoreFailures": false
                },
                {
                    "text": "-gdb-set solib-absolute-prefix /home/jetson/android_aosp/aosp/out/target/product/generic_x86/symbols", 
                    "description": "gdb command: set solib-absolute-prefix", 
                    "ignoreFailures": false
                }, 
                {
                    "text": "-interpreter-exec console \"source /home/jetson/android_aosp/aosp/development/scripts/gdb/dalvik.gdb\"", 
                    "description": "gdb command: source art commands", 
                    "ignoreFailures": false
                }
            ], 
            "name": "(gdbclient.py) Attach vold (port: 5039)", 
            "miDebuggerServerAddress": "localhost:5039", 
            "request": "launch", 
            "type": "cppdbg", 
            "cwd": "/home/jetson/android_aosp/aosp", 
            "MIMode": "gdb"
        }
    ]
}

3. 運行gdb即可,打斷點

參考

1. 使用調試程序
https://source.android.com/devices/tech/debug/gdb


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM