12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 24Debugging <strong>ns</strong><strong>ns</strong>is a simul<strong>at</strong>or engine built in C++ <strong>and</strong> has an OTcl (Object-oriented Tcl) interface th<strong>at</strong> is used for configur<strong>at</strong>ion <strong>and</strong>comm<strong>and</strong>s. Thus in order to debug <strong>ns</strong>we will have to deal with debugging issues involving both OTcl <strong>and</strong> C++. This chaptergives debugging tips <strong>at</strong> Tcl <strong>and</strong> C++ level <strong>and</strong> shows how to move to-fro the Tcl <strong>and</strong> C++ boundaries. It also briefly coversmemory debugging <strong>and</strong> memory co<strong>ns</strong>erv<strong>at</strong>ion in <strong>ns</strong>.24.1 Tcl-level DebuggingNs supports Don Libs’ Tcl debugger ( see its Postscript document<strong>at</strong>ion <strong>at</strong> http://expect.nist.gov/tcl-debug/tcl-debug.ps.Z <strong>and</strong>its source code <strong>at</strong> http://expect.nist.gov/tcl-debug/tcl-debug.tar.gz ). I<strong>ns</strong>tall the program or leave the source code in a directoryparallel to <strong>ns</strong>-2 <strong>and</strong> it will be built. Unlike expect, described in the tcl-debug document<strong>at</strong>ion, we do not support the -Dflag. To enter the debugger, add the lines "debug 1" to your script <strong>at</strong> the appropri<strong>at</strong>e loc<strong>at</strong>ion. In order to build <strong>ns</strong> withthe debugging flag turned on, configure <strong>ns</strong> with configur<strong>at</strong>ion option "–enable-debug" <strong>and</strong> incase the Tcl debugger has beeni<strong>ns</strong>talled in a directory not parallel to <strong>ns</strong>-2, provide the p<strong>at</strong>h with configur<strong>at</strong>ion option "–with-tcldebug=".An useful debugging comm<strong>and</strong> is $<strong>ns</strong>_ gen-map which may be used to list all OTcl objects in a raw form. This is usefulto correl<strong>at</strong>e the position <strong>and</strong> function of an object given its name. <strong>The</strong> name of the object is the OTcl h<strong>and</strong>le, usually of theform _o###. For TclObjects, this is also available in a C++ debugger, such as gdb, as this->name_.24.2 C++-Level DebuggingDebugging <strong>at</strong> C++ level can be done using any st<strong>and</strong>ard debugger. <strong>The</strong> following macro for gdb makes it easier to see wh<strong>at</strong>happe<strong>ns</strong> in Tcl-based subroutines:## for Tcl codedefine pargvcset $i=0while $i < argcp argv[$i]set $i=$i+1215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!