libuv源碼調(diào)試

mac 環(huán)境說明

  • 系統(tǒng): mac 10.15.7
  • vscode: 1.59.1
  • python: 3.6.12
  • libuv: 1.42

安裝依賴

libtool 默認(rèn)mac有自帶 如果沒有的話需要源碼編譯

curl -O http://mirrors.kernel.org/gnu/libtool/libtool-2.4.6.tar.gz
tar xzvf libtool-2.4.6.tar.gz
cd libtool-2.4.6
./configure --prefix=/usr/local
make
sudo make install

automake,如果brew install automake 不能安裝的話可以源碼編譯安裝

curl -O http://mirrors.kernel.org/gnu/automake/automake-1.16.4.tar.gz
tar xzvf automake-1.16.4.tar.gz
cd automake-1.16.4
./configure --prefix=/usr/local
make
sudo make install

下載libuv并編譯

git clone https://github.com/libuv/libuv.git
sh autogen.sh 
make -j4
make install

make生成.libs目錄,里面是編譯好的靜態(tài)庫,核心是 libuv.a 文件。
make install會把uh.h頭文件復(fù)制到/usr/local/include/。libuv.a 復(fù)制到 /usr/local/lib

vscode 調(diào)試

打開vscode加載libuv項(xiàng)目。
添加launch.json

{
    // 使用 IntelliSense 了解相關(guān)屬性。 
    // 懸停以查看現(xiàn)有屬性的描述。
    // 欲了解更多信息,請?jiān)L問: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc - 生成和調(diào)試活動(dòng)文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: gcc 生成活動(dòng)文件"
        }
    ]
}

添加tasks.json 注意args要添加-luv,因?yàn)閘ibuv的頭文件生成功到include/uv目錄下

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc 生成活動(dòng)文件",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-luv"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "調(diào)試器生成的任務(wù)。"
        }
    ],
    "version": "2.0.0"
}

創(chuàng)建my-test/test-once.c


#include <stdio.h>
#include <stdlib.h>
#include <uv.h>

int main()
{
    uv_loop_t *loop = malloc(sizeof(uv_loop_t));
    uv_loop_init(loop);
    
    printf("suc\n");
    uv_run(loop, UV_RUN_DEFAULT);

    uv_loop_close(loop);
    free(loop);
    return 0;
}

點(diǎn)擊debug


debugging.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容