Backtrace in libmemunreachable

473 views
Skip to first unread message

SHUBHAM SALUNKHE

unread,
Feb 15, 2022, 3:29:02 PM2/15/22
to Android Building
Hi All,
         I am trying to find memory leak using libmemunreachable library in AOSP. i have getting following output on adb shell, but not able to find line number of code where memory leak present or any backtrace logs in adb logs. following commands are executed as mentioned in link.

Commands:-
adb root
adb shell setprop libc.debug.malloc.program app_process
adb shell setprop wrap.[process] "\$\@"
adb shell setprop libc.debug.malloc.options backtrace=4
dumpsys -t 600 meminfo --unreachable [process].

adb shell output:-
 Unreachable memory
  704 bytes in 5 unreachable allocations
  ABI: 'arm64'

  288 bytes unreachable at 7862adf450
   first 20 bytes of contents:
   7862adf450: 88 13 e8 07 00 00 00 00 9e 9f 15 08 00 00 00 00 ................
   7862adf460: 2c bb 17 08 00 00 00 00 23 8a 89 08 00 00 00 00 ,.......#.......

         No. of backtrace frames are 0 in debug logs.  is there any way to enable backtrace in adb logs or to get line no. of source code from above adb shell output.

Thanks & Regards,
Shubham Salunkhe

enh

unread,
Feb 15, 2022, 3:42:50 PM2/15/22
to android-...@googlegroups.com
you did replace `[process]` with your actual process name, right?

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/3f5dac22-6aad-4e6a-b840-8afc564fce28n%40googlegroups.com.

enh

unread,
Feb 15, 2022, 4:22:17 PM2/15/22
to android-...@googlegroups.com
oh, and if you're on a recent AOSP build, you might want to try cherrypicking https://android-review.googlesource.com/c/platform/frameworks/base/+/1978990 --- the `wrap.` system properties are a bit broken atm. (the wrap.sh stuff for apps works fine though.)

SHUBHAM SALUNKHE

unread,
Feb 22, 2022, 9:14:21 PM2/22/22
to Android Building
yes,replaced with process name.

SHUBHAM SALUNKHE

unread,
Feb 22, 2022, 9:14:32 PM2/22/22
to Android Building
Hi,
       Thanks for reply.

        I tried to print debug statement in system/memory/libmemunreachable/MemUnreachable.cpp as follows. so getting "No. of frames: 0" as adb shell output. hence, backtrace call is not happening.

   ssize_t num_backtrace_frames = malloc_backtrace(reinterpret_cast<void*>(it.range.begin), leak->backtrace.frames, leak->backtrace.max_frames);
   MEM_ALOGI("No. of Frames: %zd",num_backtrace_frames);
    if (num_backtrace_frames > 0) {



Can you please give some suggestion about why No. of frames are 0 even if memory leak address i have getting as mentioned above?

Thanks & Regards,
Shubham Salunkhe

SHUBHAM SALUNKHE

unread,
Feb 22, 2022, 9:15:20 PM2/22/22
to Android Building
Hi,
     Thanks for reply.
       I have added debug statement as follows in system/memory/libmemunreachable/MemUnreachable.cpp. i giving "No. of Frames:0". that's why backtrace call is not happening. How it is possible if adb shell is giving memory leak address but backtrace frames are not available?

Debug tatement:-
    ssize_t num_backtrace_frames = malloc_backtrace(reinterpret_cast<void*>(it.range.begin), leak->backtrace.frames, leak->backtrace.max_frames);
    MEM_ALOGI("No. of Frames: %zd",num_backtrace_frames);
    if (num_backtrace_frames > 0) {
      leak->backtrace.num_frames = num_backtrace_frames;

adb shell output:
  Unreachable memory
  704 bytes in 5 unreachable allocations
  ABI: 'arm64'

  288 bytes unreachable at 7862adf450
   first 20 bytes of contents:
   7862adf450: 88 13 e8 07 00 00 00 00 9e 9f 15 08 00 00 00 00 ................
   7862adf460: 2c bb 17 08 00 00 00 00 23 8a 89 08 00 00 00 00 ,.......#.......

Thanks & Regards,
Shubham Salunkhe
On Wednesday, February 16, 2022 at 2:52:17 AM UTC+5:30 e...@google.com wrote:

enh

unread,
Mar 1, 2022, 12:23:04 PM3/1/22
to android-...@googlegroups.com
the wrap.* properties are broken in AOSP right now... (they're broken in S too.)

here's the workaround to make the wrap. properties work:

adb shell setprop dalvik.vm.force-java-zygote-fork-loop true
adb shell stop
adb shell start

the commands you're using don't look right ... try this instead:

adb shell setprop wrap.<app_name> '"LIBC_DEBUG_MALLOC_OPTIONS=backtrace=4 logwrapper"'

and then restart the app.

SHUBHAM SALUNKHE

unread,
Jun 27, 2022, 2:01:49 PM6/27/22
to Android Building
Hi,
Thanks for solution. it worked but sometime its giving following timeout exception after executing command

adb shell dumpsys -t 120 meminfo --unreachable <app_process>

Exception:-
Applications Memory Usage (in Kilobytes):
Uptime: 277719 Realtime: 277719
 ** MEMINFO in pid 5953 [<app_process>] **
 Got IoException! java.io.IOException: Timeout

in above command, -t is 120 sec. still it is exiting with above exception after 30 sec only. please help me in solving this exception.


Thanks & Regards,
Shubham Salunkhe

enh

unread,
Jun 27, 2022, 2:04:51 PM6/27/22
to android-...@googlegroups.com
you'll need to find whatever that 30s timeout is and increase it.

SHUBHAM SALUNKHE

unread,
Jun 28, 2022, 10:49:17 AM6/28/22
to Android Building
But i am giving 120 sec with -t option.

enh

unread,
Jun 28, 2022, 10:56:09 AM6/28/22
to android-...@googlegroups.com
which is why i said "whatever timeout that is" --- it's obviously a _different_ timeout. (or `-t` is broken, but it looks like the message is coming from elsewhere.)

Reply all
Reply to author
Forward
0 new messages