S60 3rd下如何使用HookLogger查找内存泄漏错误?(转)

近日,在一个S60 3rd的项目里,调试一个内存泄漏错误,总也找不到是哪里出了问题。想到以前曾碰到过一个HookLogger的工具可以检测内存泄漏,于是就下载过来。试用了一下效果相当不错,很快就找到了发生错误的位置。下面具体描述在S60 3rd环境下怎么安装与使用HookLogger:

1、下载:
http://developer.symbian.com/main/downloads/files/HookLogger_Setup.zip

2、安装:(假定使用的是S60 3rd MR版)
解压HookLogger_Setup.zip后运行安装程序,按默认安装。

在S60 3rd下使用HookLogger,稍微有些问题,修改如下:
1) 在系统的环境变量设置里,添加环境变量EPOCROOT,其值为/Symbian/9.1/S60_3rd_MR/
2) (可用记事本)打开文件
C:/Program Files/Common Files/Symbian/tools/HookEUSER.pl
替换
    my $cmd = "copy $hooks_src";

    my $cmd = "copy /"$hooks_src/"";
以及替换
    $cmd = "$Bin/AttachDll $euser $hooks $hooked_euser";

    $cmd = "/"$Bin/AttachDll/" $euser $hooks $hooked_euser";
保存后退出。
3)打开一个控制台(DOS窗口),改变当前目录为:
C:/Program Files/Common Files/Symbian/tools
然后运行
hookeuser winscw

3、使用:
先启动HookLogger,然后启动Emulator。运行你的程序,再现MemLeak直到异常退出。这时,转到HookLogger的Heap页,点击下面的按钮“List All Allocs”将列出发生内存泄漏的地址。然后双击某条信息即可查看明细情况,甚至可以打开源代码文件,非常方便!

详情可参考[注2]。

4、卸载:
参考2.3,运行
hookeuser -r winscw

评:HookLogger是一个好工具,在对内存泄漏毫无头绪时,可帮你迅速找到问题之所在。

[注1] http://developer.symbian.com/main/tools/devtools/code/index.jsp#debugging
[注2] http://www.symbian.net.cn/blog/post/5.html 

 

Use HookLogger to trace memroy leak in S60 3rd SDK

 

Link to download HoopLogger: http://developer.symbian.com/main/tools/devtools/code/index.jsp

The HookLogger application is a Windows GUI-based tool which provides easy journalling facilities for logging memory allocations, processes, thread  creation and leaves when executing an application under the Symbian OS Emulator. The main use for most developers is pin-pointing the source of a leaked  heap cell. This tool can be installed in any directory and monitors the execution of a Symbian application under any Symbian OS SDK. The user has to  issue a command in order to replace EUSER.DLL of the target Symbian OS SDK with a version that allows the attachment of "hooks" which are used by the  HookLogger tool. After the execution session is finished the user can issue the same command in order to restore the original version of EUSER.DLL.

This article demonstrates how to use the HoopLogger in S60 3rd SDK, refer to http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/symbian/p_hooklogger_trace_memory_leaks_uiq3.jsp to know about how to use it in UIQ3 SDK. OK, here we go!

First, you should download the software from the link above and install it. It's recommended that you install the software in the default directory. Then you have to tell "HoopLogger" what SDK she is working on, so you open a console window and input the command "HookEUSER winscw" ("HookEUSER wins" for Symbian v7.0 or below). This is done by modifying euser.dll, again, the user can issue the same command in order to restore the original version of the file.

However, usually you may meet some problems when you excuting this command. I met 2 actually. If you have the error code:

Failed setting cwd to epoc32/release/winscw/udeb at C:/Symbian/HookLogger/HookEUSER.pl line 54.

That is most likely to mean that your "EPOC ROOT" environment variable is not set properly. To get it right, you should set he epoc root as the diagram below(in this case, it's for S60 3rd SDK):

OK, let's go ahead. But you may meet the problem like:

The system cannot find the file specified.
Failed running "copy C:/Program Files/Common Files/Symbian/Tools/EUserParasite_eka1.dll" at C:/Program Files/Common Files/Symbian/Tools/HookEUSER.pl line 76.

This problem can be solved by modifying HookEUser.pl file. Open this and find the line

my $cmd = "copy $hooks_src";

Replace this by

my $cmd = "copy /"$hooks_src/"";

And locate the line

$cmd = "$Bin/AttachDll $euser $hooks $hooked_euser";

Replace this by

$cmd = "/"$Bin/AttachDll/" $euser $hooks $hooked_euser";

Then you are done, try to excute the command again, if the message below shows, then HoopLogger is ready.

Target path is /Symbian/9.1/S60_3rd_MR/epoc32/release/winscw/UDEB 1 file(s) copied.
Modified euser.dll to hook EUserParasite_eka2.dll, original is euser.orig.dll.
Run HookEUSER with -r to restore

 OK, now we open the IDE and make a little memory leak deliberately. We input the code like this:

TInt* i = new TInt;
 i = new TInt;
 delete i;

Compile the code and launch the HookLogger first and switch to the "thread" label, should be empty there. Then lauch the 3rd Emulator, you should see many running threads' info appear like the diagram below:

Then make the memory leak happen, record the error code(here's 250295e4), like this:

Next you choose all the threads in "thread" label then swith to "heap" label and click "list all allocs" button. Wait for a while then look for "250295e4" in "ptr"column like below:

Double click it and there will be a window poped:

Take a look at the line in blue, it indicates that the memory leak is caused by the code in line 44, Symbian1appui.cpp, check your source code, does it right? Cool ah...!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值