2017-10-10 125 views
0

我想檢查內存泄漏。這是我第一次使用Valgrind。 我有一個錯誤,我找不到 {VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/Valgrind。無法構建Android Valgrind

的Android ndkr10e 的Ubuntu 16.04 64 設備聯想A706

我也跟着:Android valgrind build fails

登錄

HOME: /home/trungle 
NDK: /home/trungle/Documents/Application/android-ndk-r10e 
SDK: /home/trungle/Android/Sdk/ 
VALGRIND: valgrind-3.13.0 
VALGRIND_DIRECTORY: valgrind-3.13.0 
BUILD: false 
adbd is already running as root 
remount succeeded 
cannot stat 'Inst': No such file or directory 
adb root 
/system/bin/sh: /data/local/Inst/bin/valgrind: not found 
~/Documents/Application/android-ndk-r10e/samples/hello-jni ~/Documents/Application/valgrindTool/valgrind-3.13.0 
./build_valgrind.sh: line 148: android: command not found 
Failure 
./build_valgrind.sh: line 180: ant: command not found 
~/Documents/Application/valgrindTool/valgrind-3.13.0 
Starting: Intent { act=android.intent.action.MAIN cmp=com.example.hellojni/.HelloJni } 
Error type 3 
Error: Activity class {com.example.hellojni/com.example.hellojni.HelloJni} does not exist. 
chmod: cannot access 'bootstrap_valgrind.sh': No such file or directory 
bash: bootstrap_valgrind.sh: No such file or directory 
/sdcard/*grind*: No such file or directory 
/storage/sdcard0/*grind*: No such file or directory 
/storage/sdcard1/*grind*: No such file or directory 

MYSCRIPT

function extract() 
{ 
    if [ -f "$1" ] ; then 
     case "$1" in 
      *.tar.bz2) tar xvjf "$1"  ;; 
      *.tar.gz) tar xvzf "$1"  ;; 
      *.bz2)  bunzip2 "$1"  ;; 
      *.rar)  unrar x "$1"  ;; 
      *.gz)  gunzip "$1"  ;; 
      *.tar)  tar xvf "$1"  ;; 
      *.tbz2)  tar xvjf "$1"  ;; 
      *.tgz)  tar xvzf "$1"  ;; 
      *.zip)  unzip "$1"  ;; 
      *.Z)   uncompress "$1" ;; 
      *.7z)  7z x "$1"   ;; 
      *)   echo "$1 cannot be extracted via >extract<" ;; 
     esac 
    else 
     echo "'$1' is not a valid file" 
    fi 
} 

RUN_HELLO_JNI_THROUGH_VALGRIND=true 
VALGRIND_VERSION="3.13.0" 
VALGRIND_EXTENSION=".tar.bz2" 
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}" 
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}" 

# Only download Valgrind tarball again if not already downloaded 
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then 
    wget -v -nc "ftp://sourceware.org/pub/valgrind/${VALGRIND_TARBALL}" 
fi 

# Only extract Valgrind tarball again if not already extracted 
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then 
    extract "$VALGRIND_TARBALL" 
fi 
echo "HOME: $HOME" 
export ANDROID_NDK_HOME="$HOME/Documents/Application/android-ndk-r10e" 
# Ensure ANDROID_NDK_HOME is set 
if [[ ! -z "$ANDROID_NDK_HOME" ]]; then 
    export ANDROID_NDK_HOME="$HOME/Documents/Application/android-ndk-r10e" 
fi 
echo "NDK: $ANDROID_NDK_HOME" 
# Ensure ANDOID_SDK_HOME is set 
export ANDROID_SDK_HOME="$HOME/Android/Sdk/" 
if [[ ! -z "$ANDROID_SDK_HOME" ]]; then 
    export ANDROID_SDK_HOME="$HOME/Android/Sdk/" 
fi 
echo "SDK: $ANDROID_SDK_HOME" 

if [[ ! -d "$VALGRIND_DIRECTORY" ]]; 
then 
    echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!" 
    exit -1 
fi 

echo "VALGRIND: $VALGRIND_DIRECTORY" 

# Move to extracted directory 
cd "$VALGRIND_DIRECTORY" 

# ARM Toolchain 
ARCH_ABI="arm-linux-androideabi-4.9" 
export AR="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar" 
export LD="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld" 
export CC="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc" 
export CXX="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++" 

[[ ! -d "$ANDROID_NDK_HOME" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK_HOME is defined also" && exit -1 

# Configure build 
export HWKIND="zenphone5" 
ANDROID_PLATFORM=android-18 
export CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND" 
export CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm" 

# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!! 
echo "VALGRIND_DIRECTORY: $VALGRIND_DIRECTORY" 

BUILD=false 

if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/Valgrind" = *"No such file or directoryy"* ]]; then 
    BUILD=true 
fi 

echo "BUILD: $BUILD" 

if [[ "$BUILD" = true ]]; 
then 
    ./configure --prefix="/data/local/Inst" \ 
    --host="armv7-unknown-linux" \ 
    --target="armv7-unknown-linux" \ 
    --with-tmpdir="/sdcard" 

    [[ $? -ne 0 ]] && echo "Can't configure!" && exit -1 

    # Determine the number of jobs (commands) to be run simultaneously by GNU Make 
    NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo) 

    if [ $NO_CPU_CORES -le 8 ]; then 
    JOBS=$(($NO_CPU_CORES+1)) 
    else 
    JOBS=${NO_CPU_CORES} 
    fi 

    # Compile Valgrind 
    make -j "${JOBS}" 

    [[ $? -ne 0 ]] && echo "Can't compile!" && exit -1 

    # Install Valgrind locally 
    make -j "${JOBS}" install DESTDIR="$(pwd)/Inst" 
    [[ $? -ne 0 ]] && echo "Can't install!" && exit -1 
fi 

# Push local Valgrind installtion to the phone 
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]]; 
then 
    adb root 
    adb remount 
    adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst" 
    adb push Inst /sdcard/ 
    echo "adb root" 
    adb shell "ls -l /data/local/Inst" 

    # Ensure Valgrind on the phone is running 
    adb shell "/data/local/Inst/bin/valgrind --version" 

    # Add Valgrind executable to PATH (this might fail) 
    adb shell "export PATH=$PATH:/data/local/Inst/bin/" 
fi 

if [ $RUN_HELLO_JNI_THROUGH_VALGRIND = true ]; then 
    PACKAGE="com.example.hellojni" 

    # The location of the Hello JNI sample application 
    HELLO_JNI_PATH="$ANDROID_NDK_HOME/samples/hello-jni" 

    pushd "$HELLO_JNI_PATH" 

    # Update build target to the desired Android SDK version 
    ANDROID_PROJECT_TARGET="android-18" 
    android update project --target "$ANDROID_PROJECT_TARGET" --path . --name hello-jni --subprojects 

    # Enable Android NDK build with Ant 
    echo '<?xml version="1.0" encoding="utf-8"?> 

    <project name="HelloJni" basedir="." default="debug"> 

    <target name="-pre-build"> 
     <exec executable="${ndk.dir}/ndk-build" failonerror="true"/> 
    </target> 

    <target name="clean" depends="android_rules.clean"> 
     <exec executable="${ndk.dir}/ndk-build" failonerror="true"> 
     <arg value="clean"/> 
     </exec> 
    </target> 

    </project> 
    ' > "custom_rules.xml" 

    # Set NDK HOME for Ant (only if not already set) 
    if ! grep -P -q "ndk.dir=.+" "local.properties" ; then 
    echo -e "\nndk.dir=$ANDROID_NDK_HOME" >> "local.properties" 
    fi 

    # Fix for Java 8 warning (warning: [options] source value 1.5 is obsolete and will be removed in a future release) 
    echo "java.compilerargs=-Xlint:-options" >> "ant.properties" 

    # Workaround INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES error 
    adb uninstall "$PACKAGE" 

    # Build Hello JNI project in debug mode and install it on the device 
    ant clean && ant debug && ant installd 

    popd 

    cd .. 

    # Start HelloJNI app 
    adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni 

    # Make the script executable 
    chmod a+x bootstrap_valgrind.sh 

    # Run application through Valgrind on the phone 
    /usr/bin/env bash bootstrap_valgrind.sh 

    adb shell ls -lR "/sdcard/*grind*" 
    adb shell ls -lR "/storage/sdcard0/*grind*" 
    adb shell ls -lR "/storage/sdcard1/*grind*" 
fi 

exit 0 

謝謝。

+0

可能重複[Android valgrind構建失敗](https://stackoverflow.com/questions/16450650/android-valgrind-build-fails) –

回答

0

我不明白

if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/Valgrind" = *"No such file or directoryy"* ]]; then 
    BUILD=true 
fi 

如何測試應該工作。一開始就有一個拼寫錯誤(目錄中的double y)。另外,如果您的文件系統區分大小寫,valgrind中不應該有大寫字母V.

其次,你的路徑看起來不對。你configure命令使用 「/數據/本地/出師表」 作爲前綴,但上面的測試擴展到

的valgrind-3.13.0 /安裝/數據/本地/安裝/斌/ Valgrind的

我認爲測試應該像

if [[ ! -e /data/local/Inst/bin/valgrind ]] ; then 
    BUILD = true 
fi 

另外,如果你的腳本應該被檢查就地Valgrind的(即獲得建立在源目錄中的一個),那對子級的東西像

if [[ ! -e coregrind/valgrind ]]; then 
    BUILD=true 
fi 
+0

謝謝。但拼寫錯誤不是問題,我想要檢查另一個問題。 我有一些問題,在目錄中的「Inst/data/local/Inst/bin/Valgrind」以及我如何創建它。 –

+0

我建議你簡化腳本並確保'configure'和'make'執行。 –

+0

我找不到Inst。我確定./configure並使執行完成。我在哪裏可以找到 –