NS2 + Debug 工具 (Eclipse-CDT, 或者netbeans )

1. ns ,eclipse 安装完毕。

2. 

Open Eclipse
Set the workspace as the ns installation path( /home/username/ns-allinone-2.34 ) by selecting File -> Switch Workspace
Choose File -> New -> Project -> C++ Project
Select Project Type as Makefile Project -> Empty C++ Project.
Toolchains: Linux GCC
Enter Project Name as ns-2.34
Uncheck “Use default location” then browse to the directory NS-2 source directory ( …/ns-allione-2.34/ns-2.34 )
Select “Next” and “Finish.
From the workspace, Selecting the NS-2 Project and choosing Project -> Build All should not give Error.
Running the project must open the console with the NS-2 prompt, %
Setting Debug Configuration:

3. 使能debug

在 Makefile 中, 编译参数加上 -g -O0 。

CCOPT    = -g -O0 -Wall -Wno-write-strings

Select Run -> Debug Configurations
Choose C/C++ Application. Type in any name.
Under the Main tab, Choose the following:
Project as ns-2.34.
C/C++ Application as ns. (Search Project and Choose this)
Under the Debugger tab, choose GDB Debugger. Uncheck the “Stop on startup at” option.
Apply and Debug. 




4 。另一个参考。 
  • 建立一个Standard Make C++ Project,注意不是Managed Make C++ Project。当然,前提是Eclipse中已经安装CDT插件,才能建立C++项目。在选Location的时候,取消缺省复选框,指定 Location为/opt/ns-allinone-2.30/ns-2.30。
  • 安装ns后,并不能调试ns,因为在安装时的编译链接操作 并没有将调试信息加入到可执行文件ns中,此时的ns文件只有5M多大小。要调试ns,需要将调试信息加入到ns文件中,这就要修改Makefile文 件,使其中的gcc命令加入-g选项,但这不需要手动修改,具体操作如下:
进入/opt/ns-allinone-2.30/2.30目录:
songyadong@walter:~> cd /opt/ns-allinone-2.30/ns-2.30
执行configure脚本:
songyadong@walter:/opt/ns-allinone-2.30/ns-2.30> ./configure --enable-debug
此操作会生成新的Makefile,查看新Makefile文件中的编译命令会发现增加了-g选项。
  • 在Eclipse中打开为ns建的project,重新编译链接一下ns,成功完成之后,会发现增加了调试信息的ns文件有17M大小,此时的ns就可以被调试了。个人认为,Eclipse下图形界面下调试项目要比直接用gdb调试要方便的多。


二/  Eclipse-CDT 使用Tips

1.  跟踪 类的定义地方, open definition, open declaration 

要手动设置为full index:
Window->Preferences. Then find Indexer tab (the easiest is to use the Find box in the top left corner of the dialog), and select Full C/C++ Indexer in the drop down box.

参考: 
www.m-works.ca/index.php

Have you noticed that after installing Eclipse and CDT for development in C++, you cannot go from function name to it's definition? You can use open declaration, but that will only take you to the header file and show you the interface to the method? After searchin for a while, with very limited success, I learned that CDT uses two versions of indexer. The indexer is a component that parses your project and creates the database of 'who calls who', 'who inherits from who' etc. The two versions are:

  • Fast - the default indexer. It will not allow you to open definition.
  • Full - has much better accuracy when parsing. Creates a larger database, and you can actually go to function definition

To turn on the Full Indexer, go to Window->Preferences. Then find Indexer tab (the easiest is to use the Find box in the top left corner of the dialog), and select Full C/C++ Indexer in the drop down box.

三、 NS2 + netbeans  也可以查看代码并进行可视化的gdb 调试。

四、 怎样调试你写的ns 扩展?

How to debug my extension to ns2?

Answer:

There are two levels to debug:

1. C++ level: 

(1) To enable debug information in ns as follows:

in your ns-allinone directory, edit the install file. 

In a section which includes "# Build Tcl8.3.2", you need to add the option 

--enable-symbols, such that:
./configure --enable-gcc --disable-shared --prefix=$CUR_PATH || ....

becomes:
./configure --enable-gcc --enable-symbols --disable-shared --prefix=$CUR_PATH || ....

In another section which includes "# Build tclcl", you need to add --enable-debug 
to your configure line, such that:

./configure || ...

becomes 

./configure --enable-debug || ...

(2) To enter your ns-allinone/ns directory, and open your Makefile.in. You need to
change the line 

CFLAGS = $(CCOPT) $(DEFINE)

to 

CFLAGS = -g $(CCOPT) $(DEFINE)
(KARA ;或者直接在Makefile中, CCOPT中添加 -g, 然后make clean, make 即可。 )

(3) To go back to ns-allinone directory and type ./install

(4) the C++ debug with gdb
. gdb ns
.(gdb) set args myscript.tcl
.(gdb) b MyClass::myfunction 
# This line set breakpoint
.run

2. Tcl Level

You need to find a software which is called tcl-debug.

(1) To place tcl-debug-2.0/ parallel to ns-2.26/
(2) cd ns-2.26
./configure --enable-debug --with-tcldebug and examine Makefile to ensure tcl-debug 
options enabled.
(3) make clean; make; make install

(4) Add breakpts for tcl-debug
Add "debug 1" (it's one not 'L') into your script file where you want to 
debug.
------------------------------------------------------------------------------------
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值