NS3 -Configuring VS Code for IntelliSence, Building and Debugging

Environments

Configuring Visual Studio Code for Auto-Completion & Syntax Highlighting

Lunch VS Code at the NS3 directory:

1
2
3
4
justin@justin-vm:~# cd NS3/ns-allinone-3.35/ns-3.35/
justin@justin-vm:~# code .
# or root user
root@justin-vm:~# code . --user-data-dir=/root/.vscode-root

Press F1 or (Ctrl + Shift + P) to access VS Code Command Palette, run “C/C++: Edit Configurations(JSON) ” to create/open a c_cpp_properties.json file and modify it

1
2
3
"includePath": [
"${workspaceFolder}/build/**"
]

The full file like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/build/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Save and close c_cpp_properties.json file. Auto-Completion & Syntax Highlighting function should work now.

Configuring Build

Click Menu→Terminal→Configure Default Build Task to edit tasks.jason file under .vscode folder

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp build active file",
//"command": "/usr/bin/cpp",
"command": "./waf",
"args": [
//"-fdiagnostics-color=always",
//"-g",
//"${file}",
//"-o",
//"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/cpp"
}
]
}

Save and exit tasks.jason. The click Menu→Terminal→ Run Build Task or shortcut key (Ctrl + Shift + B), you should see build works.

Config gdb Debugging

Open ./scratch/scratch-simulator.cc in the VS Code. Press F5, choose “C++(GDB/LLB)”, then select “Waf - build and debug active file …” a window pop out and hit Open ‘launch.json’

Replace the content of ‘launch.json’ with the following

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp build active file",
//"command": "/usr/bin/cpp",
"command": "./waf",
"args": [
//"-fdiagnostics-color=always",
//"-g",
//"${file}",
//"-o",
//"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/cpp"
}
]
}

Save and exit. Now set a breakpoint in scratch-simulator.cc source file and hit F5, you should see that the debugging works. Be patient, the pdb is generally slow.


NS3 -Configuring VS Code for IntelliSence, Building and Debugging
https://just1ngh.github.io/2022/06/19/ns3/
Author
Juquan Justin Mao
Posted on
June 19, 2022
Licensed under