Sunday, February 21, 2016

Handling Segmentation Fault (Core Dumped) in ns-2

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

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 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. 

 
 
 

1 comment:

Anonymous said...

hi i had tired this problem segmentation fault(core dumped) while i was implement your solution for solve the problem after ./configure command this error shows for me (configure: error: Installation of tcl seems incomplete or can't be found automatically.
Please correct the problem by telling configure where tcl is
using the argument --with-tcl=/path/to/package
(perhaps after installing it),
or the package is not required, disable it with --with-tcl=no.)

whats wrong?? how can i fix this ??
thanx