visual debugging ns3 with waf and MS vscode

1,781 views
Skip to first unread message

jared...@gmail.com

unread,
Aug 28, 2018, 4:00:33 PM8/28/18
to ns-3-users
All,

I like the MS Visual Studio Code IDE, it's a lot like atom with some nice plugins.  One problem I've had was that the visual debugger that's a major feature of the IDE did not play well with waf and that made debugging my ns3 programs difficult.

After much reading and experimentation I've found some launch configs (see below for a link on launch configs)that properly execute an ns3 test or example within the vscode debugger.  I'm posting it here in case someone else also experienced my frustrations.  This solution is obviously specific to gdb.

Below is an annotated and sanitized launch.json file:

{
   
// 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": [
       
{
            // Pipe Launch calls waf with appropriate arguments
           
"name": "(gdb) Pipe Launch",
           
"type": "cppdbg",
           
"request": "launch",
                      // my build folder is ${workspaceFolder}/build, substitute yours

           
"program": "${workspaceFolder}/build/utils/ns3-dev-test-runner-debug",
           
"args": [],
           
"stopAtEntry": false,
           
"cwd": "${workspaceFolder}",
           
"environment": [],
           
"externalConsole": false,
           
"pipeTransport": {
               
"debuggerPath": "",  // leave blank
               
"pipeProgram": "${workspaceFolder}/waf",
               
// pipeArgs is essentially the entire waf command line arguments
               
"pipeArgs": [
                   
"--command-template", "'",  // opening quote for command template
                   
"/usr/bin/gdb", "--interpreter=mi",  // --interpreter lets vscode talk to gdb
                   
"--args", "%s",
                   
"--suite=<test-suite>",  // must specify test suite here
                   
//"--verbose'",  // I don't think this will work in pipe mode, maybe
                   
"'",  // closing quote for command template
                   
"--run", "test-runner"],
               
"pipeCwd": ""
           
},
           
"MIMode": "gdb",
           
"setupCommands": [
               
{
                   
"description": "Enable pretty-printing for gdb",
                   
"text": "-enable-pretty-printing",
                   
"ignoreFailures": true
               
}
           
]
       
},
       
{
            // Launch config emulates waf environment, calls gdb directly

           
"name": "(gdb) Launch",
           
"type": "cppdbg",
           
"request": "launch",
            // my build folder is ${workspaceFolder}/build, substitute yours

           
"program": "${workspaceFolder}/build/utils/ns3-dev-test-runner-debug",
           
"args": [
               
"--suite=<test-suite>"  // specify test suite
           
],
           
"stopAtEntry": false,
           
"cwd": "${workspaceFolder}",
            // replace the values below with those found from running
            // $ waf shell
            // $ env

           
"environment": [
               
//{"Name": "NS_LOG", "Value": "Debug"}],
               
{"Name": "PYTHONPATH", "Value": "<from waf shell>"},
               
{"Name": "LD_LIBRARY_PATH", "Value": "<from waf shell>"},
               
{"Name": "NS3_MODULE_PATH", "Value": "<from waf shell>"},
               
{"Name": "NS3_EXECUTABLE_PATH", "Value": "<from waf shell>"},
               
{"Name": "PATH", "Value": "<from waf shell>"}
           
],
           
"externalConsole": false,
           
"MIMode": "gdb",
           
"miDebuggerPath": "/usr/bin/gdb",
           
"setupCommands": [
               
{
                   
"description": "Enable pretty-printing for gdb",
                   
"text": "-enable-pretty-printing",
                   
"ignoreFailures": true
               
}
           
],
           
"logging": {
               
"engineLogging" :true,
               
"trace": true
           
}
       
}
   
]
}


You still have to specify the test suite or example inside the launch.json, but this is not too big of a deal.  Some more info on vscode debugging and launch.json is at https://code.visualstudio.com/docs/editor/debugging .

Jared.

Peter Detzner

unread,
May 3, 2020, 3:37:31 PM5/3/20
to ns-3-users
this post has made my life much easier! Big THANKS!

Miguel Angel Murcia

unread,
Feb 16, 2021, 1:39:04 PM2/16/21
to ns-3-users

Dear all:

Thank you in advance, I think that post is quite helpful. I'm trying to fix all configurations, but after check for a days some info, I can't continue. 

I've fixed my build folder and also tried to get the propper "test-suite" (I think the problem is there). 

I attach a screenshoot of my workspace (/home/miguel/Descargas/ns-allinone-3.30.1/ns-3.30.1), the file which I wanna debug and also the screenshoot of the error message.

¿Could you show me the way to continue?

Thanks
Miguel Á.
PruebaPuntero.cc
Captura de pantalla de 2021-02-16 19-31-21.png
unnamed(1).png
launch.json

Pooya Monajemi

unread,
Sep 12, 2021, 4:00:39 AM9/12/21
to ns-3-users
Looks like they changed some behaviors in VS code pipe transport, this is a slightly updated version of Jared's launch config, also modified to run scratch instead of suites. Worked for me :

        {
            "name": "(gdb) Pipe Launch",
            "type": "cppdbg",
            "request": "launch",
            //"program": "${workspaceFolder}/build/utils/ns3-dev-test-runner-debug",
            "program": "${workspaceFolder}/build/scratch/${fileBasenameNoExtension}",
            "args": ["--nWifi=12"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "pipeTransport": {
                "debuggerPath": "",  // leave blank
                "pipeProgram": "${workspaceFolder}/waf",
                // pipeArgs is essentially the entire waf command line arguments                
                "pipeArgs": [                    
                    "--command-template", "\"",                 // opening double quote for command template 
                    "${debuggerCommand}",                       // gdb path and --interpreter arg already in debuggerCommand 
                    "--args", "%s",                             // Need to add --args %s to the gdb call
                    "\"",                                       // closing quote for command template
                    "--run", "${fileBasenameNoExtension}",      // Run call with the filename
                    ],
                    "quoteArgs":false,
                    "pipeCwd": ""
            },
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },

2021 11062

unread,
May 10, 2023, 5:01:07 PM5/10/23
to ns-3-users
It's a truly very helpful post.

Thank You.

Divyasheel

unread,
May 8, 2024, 2:48:00 AM (14 days ago) May 8
to ns-3-users
If somone is struggling with newer version of ns3 where waf is no longer used, this config might help - 
Works for me. 
{
// 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": "(gdb) Pipe Launch",
"type": "cppdbg",
"request": "launch",
//"program": "${workspaceFolder}/build/utils/ns3-dev-test-runner-debug",
"program": "${workspaceFolder}/build/scratch/ns3.36.1-${fileBasenameNoExtension}-debug",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"pipeTransport": {
"debuggerPath": "", // leave blank
"pipeProgram": "${workspaceFolder}/ns3",
// pipeArgs is essentially the entire waf command line arguments
"pipeArgs": [
"run", "${fileBasenameNoExtension}", // Run call with the filename
"--command-template", "\"", // opening double quote for command template
"${debuggerCommand}", // gdb path and --interpreter arg already in debuggerCommand
"--args", "%s", // Need to add --args %s to the gdb call
"\"", // closing quote for command template
],
"quoteArgs":false,
"pipeCwd": ""
},
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

Reply all
Reply to author
Forward
0 new messages