Skip to content

Commit 76f1c27

Browse files
authored
Merge pull request #1 from StevenCJ1/main
add debug setup for VSCode and fix commands in vm-env.md
2 parents b8f8cb7 + 7f8ecaf commit 76f1c27

2 files changed

Lines changed: 81 additions & 5 deletions

File tree

doc/debug_vscode.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Debug Setup in VS Code
2+
3+
Debugging NS-3 with VSCode (built with waf) is divided into the following steps: first compile NS-3, then configure the debugging tasks in VSCode (launch.json and tasks.json), and finally you can set breakpoints, single-step debugging, and view variables in the IDE.
4+
5+
## 1. Compiling NS-3
6+
Before debug NS-3 make sure you have successfully compile the NS-3 by follwing the steps in [ vm-env.md](#vm-env.md)
7+
8+
## 2. Configuring Debugging Tasks for VS Code
9+
10+
Configuring `tasks.json`: `tasks.json` is used to define build tasks that can automatically invoke build commands before starting debugging. Create a `.vscode/tasks.json` file with content similar to the following:
11+
12+
```json
13+
{
14+
"version": "2.0.0",
15+
"tasks": [
16+
{
17+
"label": "Build NS-3",
18+
"type": "shell",
19+
"command": "./ns3",
20+
"args": [
21+
"build"
22+
],
23+
"options": {
24+
"cwd": "${workspaceFolder}"
25+
},
26+
"group": {
27+
"kind": "build",
28+
"isDefault": true
29+
},
30+
"problemMatcher": []
31+
}
32+
]
33+
}
34+
```
35+
Configuring `launch.json`: `launch.json` is used to tell VSCode how to launch the debugger to run the NS-3 emulation program. Since NS-3 uses waf scripts to manage execution, you can launch the emulation via waf and debug the emulation scripts you specify internally. Create a `.vscode/launch.json` file with content similar to the following (change the `exampleA` to the code name, which you want to debug):
36+
37+
```json
38+
{
39+
"version": "0.2.0",
40+
"configurations": [
41+
{
42+
"name": "Debug NS-3: exampleA",
43+
"type": "cppdbg",
44+
"request": "launch",
45+
"program": "${workspaceFolder}/ns3.39/build/contrib/p4sim/examples/exampleA",
46+
"args": [],
47+
"stopAtEntry": false,
48+
"cwd": "${workspaceFolder}/ns3.39",
49+
"environment": [],
50+
"externalConsole": false,
51+
"MIMode": "gdb",
52+
"setupCommands": [
53+
{
54+
"description": "Enable GDB beautification printing",
55+
"text": "-enable-pretty-printing",
56+
"ignoreFailures": true
57+
},
58+
{
59+
"description": "Set the disassembly format to Intel",
60+
"text": "-gdb-set disassembly-flavor intel",
61+
"ignoreFailures": true
62+
}
63+
]
64+
}
65+
]
66+
}
67+
```
68+
**program**: here you specify the path to the waf script. Since NS-3 simulation is started by waf, debugging the waf process directly will start the corresponding executable file inside waf.
69+
70+
**args**: the running parameter passed to waf. You can change it to the path of the script you want to run or other parameters according to the actual situation.
71+
72+
## 3.Starting Debugging
73+
In VSCode's debugging panel (the “Run and Debug” icon in the sidebar), select the “Debug NS-3 Simulation” configuration you just configured.
74+
Set the breakpoints you want.
75+
Click on the Start Debug button. The debugger calls the pre-configured build task (tasks.json), then starts waf and executes the specified NS-3 simulation program.
76+
When it reaches the breakpoint, VSCode pauses the program and you can view the call stack, variable values, and single-step execution code.

doc/vm-env.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cd ../..
8888
You can run a built-in example using:
8989

9090
```bash
91-
./waf --run "exampleA"
91+
./ns3 run "exampleA" # This will run exampleA (name).
9292
```
9393

9494
---
@@ -195,13 +195,13 @@ git apply ./contrib/p4sim/doc/changes.patch
195195
### 6. Configure & Build NS-3
196196
```bash
197197
# in ns-3 root directory
198-
./waf configure --enable-examples --enable-tests
199-
./waf build
198+
./ns3 configure --enable-examples --enable-tests
199+
./ns3 build
200200
```
201201

202202
### 7. Run a Simulation Example
203203
```bash
204-
./waf --run "exampleA" # This will run exampleA (name).
204+
./ns3 run "exampleA" # This will run exampleA (name).
205205

206206
# In the p4sim example, you may need to adjust the path of p4 and other files.
207207
# For example:
@@ -278,7 +278,7 @@ sudo ./set_pkg_config_env.sh
278278

279279
### 7. Run a Simulation Example
280280
```bash
281-
./waf --run "exampleA" # This will run exampleA (name).
281+
./ns3 run "exampleA" # This will run exampleA (name).
282282

283283
# In the p4sim example, you may need to adjust the path of p4 and other files.
284284
# For example:

0 commit comments

Comments
 (0)