美文网首页
VSCode 单步混合调试OWT Server的NodeJS和C

VSCode 单步混合调试OWT Server的NodeJS和C

作者: 电台_Fang | 来源:发表于2022-05-16 21:13 被阅读0次

之前在Docker已经配置成功单步混合调试,但是再次配置本机的OWT Server 单步调试环境,折腾了一些时间,写此文记录要点。

1,使用VSCode 打开 OWT Server 目录源码

2,安装必要的插件

C/C++

Nodejs Snippets

JavaScript (ES6) code snippets

3,  创建 .vscode/launch.json 文件,内容如下:

"version": "0.2.0",

    "configurations": [

        {

            "name": "(gdb) Attach",

            "type": "cppdbg",

            "request": "attach",

            "program": "/home/oem/.nvm/versions/node/v14.19.1/bin/node",

            "processId": "${command:pickProcess}",

            "MIMode": "gdb",

            "setupCommands": [

                {

                    "description": "Enable pretty-printing for gdb",

                    "text": "-enable-pretty-printing",

                    "ignoreFailures": true

                },

                {

                    "description":  "Set Disassembly Flavor to Intel",

                    "text": "-gdb-set disassembly-flavor intel",

                    "ignoreFailures": true

                }

            ]

        },

        {

            "name": "LaunchVideo",

            "localRoot": "${workspaceFolder}/dist-debug/video_agent/",

            "cwd":"${workspaceFolder}/dist-debug/video_agent/",

            "program": "index.js",

            "args": ["-U",  "video"],

            "env":{ "LD_LIBRARY_PATH" : "./lib" },

            "request": "launch",

            "skipFiles": [

                "<node_internals>/**"

            ],

            "type": "node",

            "runtimeArgs": ["--preserve-symlinks"]

        }

    ]

}

4,操作说明:

这里我们调试的是 video_agent进程。调试webrtc_agent、audio_agent等nodejs  NAN 调用C++ 代码的进程,操作是一样的。

第一步,执行LaunchVideo, 启动NodeJS 进程,此时nodejs已经可以断点调试

需要先停掉用脚本批量启动的进程:./bin/daemon.sh stop video-agent

第二步,此时会启动两个进程, index.js是管理进程, workingNode是具体的工作进程,C++代码在这个进程,进程id 32505。

第三步,执行(gdb) Attach,进程ID 写上面的id  32505.  

此时,在源码目录 source/agent/video 内的CPP源文件,就可以加上断点了。

例如断点加在mcu::VideoMixer::VideoMixer, 打开chrome进入房间https://192.168.3.106:3004/,命中断点,如下图。

相关文章

网友评论

      本文标题:VSCode 单步混合调试OWT Server的NodeJS和C

      本文链接:https://www.haomeiwen.com/subject/qxwwurtx.html