This document provides instructions for debugging NetSim simulations using both the graphical user interface (GUI) and command line interface (CLI). It describes making backups of simulation files, setting breakpoints in protocol initialization functions, attaching the Visual Studio debugger to NetSimCore.exe, and correlating the debug session with generated event traces to view variable values at different points in the simulation run.
2. www.tetcos.com
1:Debugging through GUI
1. Before start any simulation
or debugging, make sure you
make a back up of
simulation folder present in
<NetSim_Install_Dir>src
Simulation. Eg: “C:Program
Files (x86)NetSim
StandardsrcSimulation”.
2. Work on the folder
Simulation
3. The folder simulation-copy
is a back-up of the original
files
A prerequisite to debugging is that the user has already
completed the “Hello World” Program in NetSim
3. www.tetcos.com
1:Debugging through GUI
4. Create a scenario in GUI of
the respective protocol
5. Open the protocol’s init
function. This will be present
in the .c file of respective
protocol
6. Ex : fn_NetSim_Zigbee_Init()
in 802_15_4.c.
fn_NetSim_CR_Init( ) in
802.22.c
7. Write getch() at the start of
the above function.
4. www.tetcos.com
1:Debugging through GUI
8. Build the protocol and replace the dll in bin folder in NetSim. Do not
close Visual Studio.
9. In NetSim, create a network scenario and simulate.
10. The simulation won’t start and will pause (because of getch()).
11. Switch to the Visual Studio window and put break point inside the
source code where you want to debug.
12. Go to “Debug->Attach to Process” in Visual studio and attach to
NetSimCore.exe.
6. www.tetcos.com
1. The App path is the file location in the system in which NetSim has
been installed.
2. Typically this path would be “C:Program FilesNetSim
Standardbin”
3. To get it, right click on the NetSim icon and select Open File
Location.
4. The IO path (Input/output Path) is the path where the input and
output files of an application is written.
5. For NetSim, the IO path can be got by Start -> Run->
%temp%/NetSim.
6. Once you reach this folder, the user would notice that the path would
be something like “C:UsersRamAppDataLocalTempNetSim”
2:Information needed for CLI
7. www.tetcos.com
2:Information needed for CLI
7. The IO path is the path where the Configuration.xml (NetSim
Config file) of the scenario, that will be simulated, should be
present.
8. Create the required scenario in GUI as described previously to get
the config file( Ignore steps 4 and 7 of GUI)
9. You may also need the IP Address of the License Server. If the
user is running a floating license then this is the address of where
the dongle is running
10. For node locked licenses the IP Address need not be entered
8. www.tetcos.com
3:Debugging through CLI
1. Create the required scenario in GUI as described previously to get
the config file( Ignore steps 4 and 7 of GUI)
2. In the command window (cmd), open your apppath ( Write cd
<apppath> in cmd)
3. Then type NetSimCore.exe<space> -apppath<space><app
path><space>-iopath<space><io path><space>-
license<space>5053@<Server IP Address> -d
Figure 3.1
10. www.tetcos.com
5. Now follow the steps 8 to 10 as mentioned in Debugging with
GUI section
3:Debugging through CLI
11. www.tetcos.com
3:Debugging through CLI
6. Enter the desired event id where you want to break ( see prev.
fig.) Execution will stop at the desired Event Id ( see fig. below)
12. www.tetcos.com
3:Debugging through CLI
7. Press enter then control goes to visual studio and stops at the
break point in the source code as shown in figure below.
8. All debugging options like step over (F10), step into (F11),
step out (Shift + F11), continue(F5) are available.
13. www.tetcos.com
4:Co-relating with Event Trace (CLI)
1. Enable the Event trace manually in the config file.
2. The config file Configuration.xml is located inside the IO Path.
Open this file in notepad / visual studio and change file name &
path in line marked in figure below; and set STATUS=ENABLE.
3. Sometimes in visual studio the entire file is opened in 1 line and to
see it in the correct format, click the reformat selection icon
14. www.tetcos.com
4:Co-relating with Event Trace (CLI)
4. Run the simulation as described in debugging through CLI
section without the the debug (–d) option.( This generates the event
trace)
5. Rename the Event trace file generated in previous step. This is done
to avoid over writing of the file when the simulation is run. So while
debugging the code flow is compared against a recorded event trace.
6. Run the simulation as described in Debugging Through CLI section
again and enter -1 as event id to break in .This is required to watch the
variable.
15. www.tetcos.com
7. Open the C file inside the protocol folder inside Simulation folder
that has the init function as explained in the earlier slides. The run
function will be present in the same file.
8. There will be a switch case statement , where the switch
is on the variable nEventType.
4:Co-relating with Event Trace (CLI)
16. www.tetcos.com
4:Co-relating with Event Trace (CLI)
9. Set a break point there and check the values of members of this
struct as the code executes using F5, F10 and F11 keys
10. Add a watch as described in the coming slides on
pstruEventDetails variable .
11. Compare it with the event trace file generated in steps 1-4. The
values will match exactly.
17. www.tetcos.com
5:Viewing & Accessing variables
1. To follow a variable through execution, use “Add Watch” option
available.
2. Some variables cannot be viewed directly when added in the watch
tab, as this would throw the error: “CX0017: Error:symbol
“Variable_Name”not found”.
3. In the call stack window one can find the file in which that variable
is situated.
4. If this file is grey color in the call stack window, then load it
knowing the location of its .pdb file (Refer to user manual)
18. www.tetcos.com
5. Otherwise, if variable is already loaded add prefix
{,,<filename>.dll} to the variable name and press enter (Refer to
user manual)
6. For eg. For viewing pstruEventDetails prefix {,,NetworkStack.dll}.
5:Viewing & Accessing variables
• Prefixing {,,Networkstack.dll} before
variable name and press Enter to see
the watch window.