Programming c++ in ns-2 is a nightmare for beginners. It requires systematic planning and programming. Though the programming is systematically planned, even experienced programmers frequently encounter bugs called "Segmentation fault (Core Dumped)" and Floating point exception (Core Dumped). Generally, Floating point exception can be dealt with positive value in the denominator of an expression. This post explains how to debug these problem in ns2. The following procedure has been tested with ns-2.35.
Prerequisite: Your system should installed with gdb (GNU debugger).
Step 1: goto ns-allinone-2.35/ns-2.35, and edit the Makefile.in file
Prerequisite: Your system should installed with gdb (GNU debugger).
Step 1: goto ns-allinone-2.35/ns-2.35, and edit the Makefile.in file
replace from
CCOPT = @V_CCOPT@
to
CCOPT = @V_CCOPT@ -g
Next, replace the following from
DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test
to
DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@ -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@ -DUSE_SINGLE_ADDRESS_SPACE -Drng_test -DNDEBUG -DDEBUG
Step 2: Save the file and do the following
$ ./configure
$ make clean
$ make clean
$ make distclean
$ ./configure
$ make
$ sudo make install
Now debugging to your ns-2 is ready. If you have encountered the Segmentation fault bug while running any tcl file, then do the following
Step 3: goto the tcl folder and do the following
$ gdb ns
(gdb) run your_tcl_filename.tcl
TCL file runs with the above command and it stops at bug point showing the statement where the bug has present.