Header Sep

Symbian OS Tips, Tricks & Code

My Rating Score
Login to rate page

September 2006

HookLogger: how to track down memory leaks in UIQ 3

Do you recognize this error message?

"ALLOC: 850b5d4\n:0"

This is displayed when a memory leak occurs. These memory leaks can sometimes be very hard to trace down. To make it easier to locate memory leak Symbian have introduced a tool called HookLogger that can be used with the UIQ 3 emulator. The HookLogger application could be downloaded for free here>>

This article outlines how install and use Hooklogger for tracing down memory leaks:

  • Download the Hooklogger application using the link above.
  • Unpack the zip file and install.
  • Enter the folder to which you installed HookLogger via the command prompt.

To be able to use HookLogger you must now replace EUSER.DLL of the target Symbian OS v9.1 with a version that allows the attachment of "hooks" which are used by the HookLogger tool. When you are done using HookLogger you can easy restore the original version of EUSER.DLL using the same command.

In order to attach the hooks, execute "HookEUser.cmd".

This will give you the syntax to use for Hooklogger.

HookEUSER.pl [-r] <PLATFORM> [RELEASE] [ARCH]

where: <PLATFORM> == WINS | WINSCW

[RELEASE] == UDEB | UREL (default == UDEB)
[ARCH] == EKA1 | EKA2 (default == EKA1 for WINS, EKA2 for WINSCW)
-r restores original EUSER.DLL

In this case use the winscw platform in debug mode, so simply type:

HookEUSER.pl winscw

However, if you are prompted with an error message like this one:

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

The most common thing would be that HookLogger is unable to find the correct EPOCROOT. This is the path where EPOC32 folder is located.

You must set your EPOCROOT explicit. This can be done by right click "This Computer" and select properties -> Advanced -> Environment variables -> System Variables -> New

type EPOCROOT in "Variable name" and the location to your epoc32 directory in "Variable value".

Click "OK".

Now, your newly created system variable should appear among the other system variables.

Now, close down the old command prompt and start a new one.

Notice: In UIQ3 the EPOCROOT is deprecated and shouldn't be used so when you're done using HookLogger you should remove the EPOCROOT again.

Type HookEUSER.pl winscw once again

This time a proper message is displayed informing you that hooks are in place.

Target path is /Symbian/UIQ3SDK/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

To start hooklogger simply type "HookLogger" in the command prompt and then start the emulator as usual.

You will now see all currently running threads.

Here is a simple test application called "leaking memory" to demonstrate how this works. Here is the function that leaks memory.

void CleakingMemoryAppUi::LeakMemory)
   {
   HBufC* buf;
   buf = HBufC::NewL(15);
   }

When the application is terminated after running the function above, a memory leak is generated. Looking at the Call stack in CodeWarrior you can see the following "Alloc: 876b5d4\n".

Select the "Heap" tab in HookLogger and then select "List All Allocs". This will show the heap and what allocations have been made.

Locate the pointer from the call stack in Codewarrior.

"Alloc: 876b5d4\n"

Double clicking on this now gives me some useful information.

It's easy to see what's been allocated and causing the memory leak. In this case we can see that we've allocated memory for our HBufC by the call to HBUfC16::NewL()


   

My Rating Score
Login to rate page