Finding Memory leak in native code

13,400 views
Skip to first unread message

clikx

unread,
Aug 5, 2009, 8:16:35 AM8/5/09
to android-porting
Hi,

Is there any tool available to find memory leak in native code?
Is there any tool like 'memprof' or 'mtrace' ported to work in Android
platform?

Regards
Clikx

fadden

unread,
Aug 5, 2009, 1:41:56 PM8/5/09
to android-porting
On Aug 5, 5:16 am, clikx <click...@gmail.com> wrote:
> Is there any tool available to find memory leak in native code?
> Is there any tool like 'memprof' or 'mtrace' ported to work in Android
> platform?

If you have the right kind of build on the phone, you can replace /
system/lib/libc.so with /system/lib/libc_debug.so and restart the
framework. Add "native=true" to your ~/.android/ddms.cfg, and start
the stand-alone version of DDMS. You should now have a "Native Heap"
tab that you can use to examine native allocations.

clikx

unread,
Aug 7, 2009, 12:13:51 AM8/7/09
to android-porting
Thanks Fadden !!!

Thanks for the info. It works fine. Able to see the 'Native Heap' tab
(with data).

Required some more information i.e
The coloumns 'File' and 'Line' (only) are not populated. What needs to
be enabled to get data in 'File' and 'Line' coloumns.

Regards
Clikx

fadden

unread,
Aug 7, 2009, 1:20:13 PM8/7/09
to android-porting
On Aug 6, 9:13 pm, clikx <click...@gmail.com> wrote:
> Required some more information i.e
> The coloumns 'File' and 'Line' (only) are not populated. What needs to
> be enabled to get data in 'File' and 'Line' coloumns.

DDMS needs the "symbols" directory under "out" in a build tree. The
stand-alone DDMS is set up so that, if you run it out of the same
source tree that was used to build the code on the device, it will
automatically find the copies of the shared libraries that have
symbols in them. (And it automatically uses the symbols from
libc_debug.so rather than libc.so.) The shared objects on the device
have had their symbols stripped.

Are you building your own tree or using the SDK?

clikx

unread,
Aug 18, 2009, 7:49:33 AM8/18/09
to android-porting
Hi Fadden.

I am using own tree.

I am still facing the problem of the columns not populating.
I am using the standalone ddms (and adb).

I am getting the following error for all the libraries.
03:48 E/ddm-Addr2Line: Error while trying to start arm-eabi-addr2line
process for library /system/lib/libssl.so

I am not able to find; which file, the path preferences of "/<path>/
arm-eabi-addr2line" and "/out/target/product/<prod>/symbols/system/
lib/" are to be updated.

Regards
Clikx

fadden

unread,
Aug 18, 2009, 3:54:45 PM8/18/09
to android-porting
On Aug 18, 4:49 am, clikx <click...@gmail.com> wrote:
> I am using own tree.
...
> I am getting the following error for all the libraries.
> 03:48 E/ddm-Addr2Line: Error while trying to start arm-eabi-addr2line
> process for library /system/lib/libssl.so
>
> I am not able to find; which file, the path preferences of "/<path>/
> arm-eabi-addr2line" and "/out/target/product/<prod>/symbols/system/
> lib/" are to be updated.

When I type "which arm-eabi-addr2line", I find it in ./prebuilt/linux-
x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-addr2line. Are you setting
your path with ". build/envsetup.sh" and an appropriate "lunch"
command?

There appears to be an addr2line preference in File->Preferences, but
you shouldn't have to mess with that.

clikx

unread,
Aug 19, 2009, 5:02:18 AM8/19/09
to android-porting
Hi Fadden,

Things seems to be working. Both the coloumns are getting populated
with file and function names.

I have updated following environment variables
1. $PATH with ~/open_src/prebuilt/linux-x86/toolchain/arm-eabi-XXX/bin
2. $ANDROID_PRODUCT_OUT with ~/open_src/out/target/product/<XXX>/

'PATH' is used for getting "arm-eabi-addr2line" and
ANDROID_PRODUCT_OUT for getting the path to /symbol folder.

Thanks and Regards
Supriyo

RK

unread,
Sep 2, 2009, 8:28:04 AM9/2/09
to android-porting


On 8月6日, 上午1時41分, fadden <fad...@android.com> wrote:
> On Aug 5, 5:16 am, clikx <click...@gmail.com> wrote:
>
> > Is there any tool available to find memoryleakin native code?
> > Is there any tool like 'memprof' or 'mtrace' ported to work in Android
> > platform?
>
> If you have the right kind of build on the phone, you can replace /
> system/lib/libc.so with /system/lib/libc_debug.so and restart the
> framework.  Add "native=true" to your ~/.android/ddms.cfg, and start
> the stand-alone version of DDMS.  You should now have a "Native Heap"
> tab that you can use to examine native allocations.

I am using android-sdk-windows-1.5_r2, instead of linux. I did not
find the file ddms.cfg. So I added "native=true" to my ddms.bat.
Howver, I was not able to see the "Native Heap" tab in the ddms UI.
Did I miss something important?

RK

unread,
Sep 24, 2009, 2:53:26 AM9/24/09
to android-porting
Hi all,
I have followed the stpes to set the environment variables: $PATH, and
$ANDROID_PRODUCT_OUT correctly. However, I still can not see both
columns: File, and Line shown in the Native heap tab. Could anyone
give some suggestions?

I also have a question.
I could see many lines shown in the Native heap tab, as well as the
string like: "/system/bin/sh using MALLOC_DEBUG = 1 (leak checker)"
shown in the logcat log.
1. What is the next step for me to find out the memory leakage?
2. Does string "/system/bin/sh using MALLOC_DEBUG = 1 (leak checker)"
mean that /system/bin/sh has memory leak? or it just means that /
system/bin/sh calls malloc() api at some time?


regards,
RK

Raghu

unread,
Sep 28, 2009, 6:46:39 AM9/28/09
to android-porting
Hi,
Thanks for such good explanation.

Currently I am able to see "native heap" tab in ddms and in Logcat
MALLOC_DEBUG=1 for Native Executable indicating leak. Could you please
suggest/ give some more information about, how to use/ interpret
"native heap" block information.

Thank you,
Raghu


On Sep 24, 3:53 pm, RK <bcsf...@gmail.com> wrote:
> Hi all,
> I have followed the stpes to set the environment variables: $PATH, and
> $ANDROID_PRODUCT_OUT correctly. However, I still can not see both
> columns: File, and Line shown in the Native heap tab. Could anyone
> give some suggestions?
>
> I also have a question.
> I could see many lines shown in the Native heap tab, as well as the
> string like: "/system/bin/sh using MALLOC_DEBUG = 1 (leakchecker)"
> shown in the logcat log.
> 1. What is the next step for me to find out thememoryleakage?
> 2. Does string "/system/bin/sh using MALLOC_DEBUG = 1 (leakchecker)"
> mean that /system/bin/sh hasmemoryleak? or it just means that /
> > > you shouldn't have to mess with that.- Hide quoted text -
>
> - Show quoted text -

allstars

unread,
Sep 28, 2009, 2:17:33 PM9/28/09
to android-porting
i would like to ask how to restart framework
using adb???

thanks

Dianne Hackborn

unread,
Sep 28, 2009, 9:51:30 PM9/28/09
to android...@googlegroups.com
adb shell stop && adb shell start
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Raghu

unread,
Sep 29, 2009, 4:50:11 AM9/29/09
to android-porting
Hi,
I was also facing "03:48 E/ddm-Addr2Line: Error while trying to start
arm-eabi-addr2line process for library /system/lib/libssl.so" error.
Then I provided "out\target\product\surf\symbols\system\lib" in DDMS-
>file>preference->device->default images save dir.

But I couldn’t see any file or method name populating. Please let me
know if I am missed anything.

And I believe by using native heap tab information I can able to get
memory leak information about my native shared object. Please comment
on it.

Thank you,
Raghu

Raghu

unread,
Sep 29, 2009, 10:15:58 PM9/29/09
to android-porting
hi,
i am getting Error like "Received unsupported chunk type NGEN". what
is the reason???

thank you,
raghu
> > > Are you building your own tree or using the SDK?- Hide quoted text -

RK

unread,
Oct 4, 2009, 11:33:53 PM10/4/09
to android-porting
Hi,
I have followed your instructions to update the following
environment variable: $PATH, and $ANDROID_PRODUCT_OUT. And verify they
are set correctly by the following ways:
1. $PATH: I could run arm-eabi-addr2line from everywhere, which means
that the path for arm-eabi-addr2line is set correctly.
2. $ANDROID_PRODUCT_OUT: I could execute "cd $ANDROID_PRODUCT_OUT/
symbols" successfully, and it indeed changed to the symbols folder,
which means that the path for symbols under $ANDROID_PRODUCT_OUT is
set correctly.

With the settings for $PATH, and $ANDROID_PRODUCT_OUT, I run ddms to
see the Native Heap tab. However, I still failed to locate the memory
leak. The problems I faced are:
1. The button "Load Symbol" is disabled.
2. The following fields are blank, nothing seen.
a) library,
b) file,
c) line

I believed that there must be something I did not follow. Could anyone
just give me some instruction? Thanks in advance.



regards,
RK

On 8月19日, 下午5時02分, clikx <click...@gmail.com> wrote:

Raghu

unread,
Oct 14, 2009, 1:33:52 AM10/14/09
to android-porting
hi,
please provide updates .....

thank you,
Raghu
> > > you shouldn't have to mess with that.- Hide quoted text -

RK

unread,
Oct 19, 2009, 4:59:52 AM10/19/09
to android-porting
Hi, Raghu,
1. Are you able to see the library name shown in your ddms?
2. May you share the addresses lies in libc.so in your ddms? Are all
these addresses shown in ddms lies in the address range for libc.so
specified in the prelink file (\android\build\core\prelink-linux-
arm.map)

regards,
RK

RK

unread,
Nov 6, 2009, 12:56:12 AM11/6/09
to android-porting
Hi all,
I found the way to let ddms show the library name, file , and line no.
correctly.
1. library:
- Modify your HandleNativeHeap( android\development\tools\ddms\libs
\ddmlib\src\com\android\ddmlib\HandleNativeHeap.java)
* change the following line in parseMaps(ClientData cd, byte[]
maps) according to your prelink-linux-arm.map file to let ddms can
scan the address range the libraries will be.
if (tmpStart >= 0x40000000L && tmpEnd <= 0x6FFFFFFFL)
- rebuild
- copy android\out\YOUR_TARGET\host\linux-x86\framework\ddmlib.jar
to android-sdk-linux_x86-1.6_r1\tools\lib\
2. file, and line no
- Set the $PATH correctly
- Set the $ANDROID_PRODUCT_OUT correctly.

Howver, I found that it is still hard to find the memory leakage with
this tool. Since With this information, I could just know that there
was an malloc occured, I could not tell if this was an leakage or
not.
Does anyone give me some suggestion?

regards,
RK
Reply all
Reply to author
Forward
0 new messages