溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vscode使用gdb調(diào)試的方法

發(fā)布時(shí)間:2020-12-19 10:47:00 來(lái)源:億速云 閱讀:428 作者:小新 欄目:軟件技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)vscode使用gdb調(diào)試的方法,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

1、vscode啟動(dòng)debug窗口

按Ctrl+Shift+D,打開Debug窗口

默認(rèn)是“No configurations”, 點(diǎn)擊“F5”,會(huì)提示你配置GDB參數(shù)(選擇gcc build and debug active file),配置文件名稱為launch.json(配置參考3)

配置完成后,再按F5, 會(huì)提示配置GCC,選擇“Configure Task”, 選擇“C/C++: build and debug active file”, 配置文件名稱為task.json(配置參考2)

2、GCC配置

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/share/mips-gcc-4.6/staging_dir/bin/mips-linux-gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

“command”: 編譯鏈的地址

3、GDB配置

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "miDebuggerServerAddress": "192.168.0.1:10000",
            "program": "/home/renyinshan/work/p53/apps/cmdlib/test",
            "args": [],
            "stopAtEntry": true,
            "cwd": "/home/renyinshan/work/p53/apps/cmdlib/",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file",
            "miDebuggerPath": "/home/renyinshan/work/p53/apps/gdb/install/bin/mips-linux-gdb"
        }
    ]
}

“program”: 要調(diào)試的程序名(包含路徑,最好絕對(duì)路徑,免得麻煩)

“miDebuggerServerAddress”: 服務(wù)器的地址和端口

“cwd”: 調(diào)試程度的路徑

“miDebuggerPath”: gdb的路徑

4、GDB server編譯及運(yùn)行

1)編譯

P53編譯時(shí),請(qǐng)打開如下開關(guān); P59需要從編譯鏈目錄拷貝一個(gè)。

scripts/tozedap-router_4g_industry/config.tozedap-router_4g_industry:564:export NO_CPP_LIB=0

GDB運(yùn)行需要libstdc++.so.6的庫(kù),所以需要把此開關(guān)打開。
./cool 3 gdb_build

等待完成即可

編譯完成后的文件如下:

renyinshan@renyinshan:~/work/p53/build$ ls ../apps/gdb/install/*
../apps/gdb/install/bin:
mips-linux-gdb  mips-linux-gdb-add-index  mips-linux-run

../apps/gdb/install/include:
gdb

../apps/gdb/install/lib:
libmips-linux-sim.a

../apps/gdb/install/share:
gdb  info  locale  man

renyinshan@renyinshan:~/work/p53/build$ ls ../apps/gdb/installgdbserver/bin/
mips-linux-gdbserver
renyinshan@renyinshan:~/work/p53/build$

說(shuō)明:

install/bin 目錄的mips-linux-gdb為vscode中配置需要的;

installgdbserver/bin/ 目錄中的mips-linux-gdbserver,需要拷貝到板子中;

2)ssh登錄設(shè)備,下載gdbserver到/tmp目錄中, 并增加+x權(quán)限

3)ssh登錄設(shè)備,下載可執(zhí)行程序到/tmp目錄中, 并增加+x權(quán)限

4)運(yùn)行

/tmp # ./mips-linux-gdbserver :10000 ./test

調(diào)試輸出:

/tmp # ./mips-linux-gdbserver :10000 test 
Process /tmp/test created; pid = 22608
Listening on port 10000
Remote debugging from host 192.168.0.245
APP is running!

備注說(shuō)明:
1) 下載的可執(zhí)行程序,必須保證是設(shè)備所需編譯鏈編譯的;
2) vscode中按F5調(diào)試時(shí),GCC編譯的配置和GDB參考1和2;

5、調(diào)試

準(zhǔn)備完成, 在VSCode進(jìn)行調(diào)試。

關(guān)于vscode使用gdb調(diào)試的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI