Archives for: April 2011
Debug android memory of c program ( JNI )
April 2nd, 2011Command
setprop dalvik.vm.checkjni true setprop libc.debug.malloc 10 setprop setprop dalvik.vm.jniopts forcecopy start stop
In your DDMS configuration file (e.g. ~/.android/ddms.cfg on Linux), add "native=true".
libc.debug.malloc
bionic/libc/bionic/mallocdebugcommon.c
/* Handle to shared library where actual memory allocation is implemented.
263 * This library is loaded and memory allocation calls are redirected there
264 * when libc.debug.malloc environment variable contains value other than
265 * zero:
266 * 1 - For memory leak detections.
267 * 5 - For filling allocated / freed memory with patterns defined by
268 * CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
269 * 10 - For adding pre-, and post- allocation stubs in order to detect
270 * buffer overruns.
271 * Note that emulator's memory allocation instrumentation is not controlled by
272 * libc.debug.malloc value, but rather by emulator, started with -memcheck
273 * option. Note also, that if emulator has started with -memcheck option,
274 * emulator's instrumented memory allocation will take over value saved in
275 * libc.debug.malloc. In other words, if emulator has started with -memcheck
276 * option, libc.debug.malloc value is ignored.
277 * Actual functionality for debug levels 1-10 is implemented in
278 * libc_malloc_debug_leak.so, while functionality for emultor's instrumented
279 * allocations is implemented in libc_malloc_debug_qemu.so and can be run inside
280 * the emulator only.
281 */