valgrind

Google代码自带valgrind工具: xxx@u138-103:~/aosp/external/valgrind$ 

xxx@u138-103:~/aosp make -j64 valgrind           //即可生成valgrind

xxx@u138-103:~/aosp/external/valgrind$  mm     //生成相关的库文件   目录为: out/target/product/generic_arm64/system/lib64/valgrind/

adb push valgrind  /system/bin/

另外将out/target/product/generic_arm64/system/lib64/valgrind/中的库文件push到/system/lib64/valgrind (也可以是其它目录)中

并且export VALGRIND_LIB=/system/lib64/valgrind  

测试的程序:

// hello.c
#include <stdio.h>
#include <stdlib.h>
int main() {
  printf("aaaaaaaa\n");
  char *p = malloc(100);
  printf("bbbbbbb\n");
  return 0;
}        

 

#Android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := hello
LOCAL_SRC_FILES := hello.c

include $(BUILD_EXECUTABLE)

 

kn:/system/lib64/valgrind # export VALGRIND_LIB=/system/lib64/valgrind
1|kn:/system/lib64/valgrind # valgrind   --leak-check=full --track-origins=yes  hello
==20878== Memcheck, a memory error detector
==20878== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==20878== Using Valgrind-3.11.0.SVN.aosp and LibVEX; rerun with -h for copyright info
==20878== Command: hello
==20878==
WARNING: linker: "/system/lib64/valgrind/vgpreload_core-arm64-linux.so" has unsupported flags DT_FLAGS_1=0x421
WARNING: linker: "/system/lib64/valgrind/vgpreload_memcheck-arm64-linux.so" has unsupported flags DT_FLAGS_1=0x421
==20878== Source and destination overlap in memcpy(0x4c9eb08, 0x4c9eb08, 104)
==20878==    at 0x4CCDE70: memcpy (in /system/lib64/valgrind/vgpreload_memcheck-arm64-linux.so)
==20878==    by 0x4C71943: je_malloc_tsd_boot0 (in /system/lib64/libc.so)
==20878==    by 0x4C67A03: jemalloc_constructor (in /system/lib64/libc.so)
==20878==    by 0x401F1A7: __dl__ZL10call_arrayIPFviPPcS1_EEvPKcPT_mbS5_ (in /system/bin/linker64)
==20878==    by 0x401F3D7: __dl__ZN6soinfo17call_constructorsEv (in /system/bin/linker64)
==20878==    by 0x401F2CF: __dl__ZN6soinfo17call_constructorsEv (in /system/bin/linker64)
==20878==    by 0x401F2CF: __dl__ZN6soinfo17call_constructorsEv (in /system/bin/linker64)
==20878==    by 0x401F2CF: __dl__ZN6soinfo17call_constructorsEv (in /system/bin/linker64)
==20878==    by 0x401B3DF: __dl___linker_init (in /system/bin/linker64)
==20878==    by 0x4021A17: _start (in /system/bin/linker64)
==20878==    by 0x4021A17: _start (in /system/bin/linker64)
==20878==    by 0x4021A17: _start (in /system/bin/linker64)
==20878==
aaaaaaaa
bbbbbbb
==20878==
==20878== HEAP SUMMARY:
==20878==     in use at exit: 15,230 bytes in 421 blocks
==20878==   total heap usage: 781 allocs, 360 frees, 35,644 bytes allocated
==20878==
==20878== LEAK SUMMARY:
==20878==    definitely lost: 0 bytes in 0 blocks
==20878==    indirectly lost: 0 bytes in 0 blocks
==20878==      possibly lost: 0 bytes in 0 blocks
==20878==    still reachable: 15,230 bytes in 421 blocks
==20878==         suppressed: 0 bytes in 0 blocks
==20878== Reachable blocks (those to which a pointer was found) are not shown.
==20878== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==20878==
==20878== For counts of detected and suppressed errors, rerun with: -v
==20878== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

 

posted @ 2017-09-25 15:21  牧 天  阅读(1187)  评论(0)    收藏  举报