Valgrind 无法正常工作并出现错误

Valgrind 无法正常工作并出现错误
rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$ uname -r
4.10.0-42-generic
rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial
rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$

rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$ sudo make clean
rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$ sudo ./configure --host=powerpc-pc-linux LDFLAGS=-static CC=/opt/ELDK42/usr/bin/ppc_85xx-gcc CXX=/opt/ELDK42/usr/bin/ppc_85xx-g++ --enable-tls --prefix=/home/rajeshsingh/valgrind_bins/ --exec-prefix=/home/rajeshsingh/valgrind_bins
rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$ sudo make
rajeshsingh@rajesh-dt:~/Downloads/valgrind-3.13.0$ sudo make install

之后,我将其制作成 tar.gz 文件并复制到设备上并解压缩它。

在设备上:

tar -xjvf valgrind.tar.gz

mv valgrind_bins/bin/valgrind /etc/bin/
cp valgrind_bins/lib/valgrind/default.supp /etc/lib/valgrind/
VALGRIND_LIB=/tmp/valgrind_bins/lib/valgrind/
export VALGRIND_LIB
/etc/bin/valgrind ls

输出:

bash-4.3# /etc/bin/valgrind ls
==1797== Memcheck, a memory error detector
==1797== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1797== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==1797== Command: ls
==1797== 

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:  
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strlen
valgrind:  in an object with soname matching:   ld.so.1
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld.so.1
valgrind:  
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:  
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:  
valgrind:  Note that if you are debugging a 32 bit process on a
valgrind:  64 bit system, you will need a corresponding 32 bit debuginfo
valgrind:  package (e.g. libc6-dbg:i386).
valgrind:  
valgrind:  Cannot continue -- exiting now.  Sorry.

我在 m_redir.c 文件中添加了一些检查并编译和加载了 valgrind。

+#if CI_HACK_strlen
      add_hardwired_spec(
         "ld.so.1", "strlen",
         (Addr)&VG_(ppc32_linux_REDIR_FOR_strlen),
         complain_about_stripped_glibc_ldso
      );
+#endif

bash-4.3# mv valgrind_bins/bin/valgrind /etc/bin/
/default.supp /etc/lib/valgrind/
VALGRIND_LIB=/tmp/valgrind_bins/lib/valgrind/
export VALGRIND_LIBbash-4.3# cp valgrind_bins/lib/valgrind/default.supp /etc/lib/valgrind/
cp: can't create '/etc/lib/valgrind/': No such file or directory

bash-4.3# VALGRIND_LIB=/tmp/valgrind_bins/lib/valgrind/
bash-4.3# export VALGRIND_LIB
bash-4.3# /etc/bin/valgrind ls
==1836== Memcheck, a memory error detector
==1836== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1836== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==1836== Command: ls
==1836== 
==1836== Conditional jump or move depends on uninitialised value(s)
==1836==    at 0x4002820: ??? (in /lib/ld-2.6.so)
==1836==    by 0x4015693: ??? (in /lib/ld-2.6.so)
==1836== 
==1836== Conditional jump or move depends on uninitialised value(s)
==1836==    at 0x4002854: ??? (in /lib/ld-2.6.so)
==1836==    by 0x4015693: ??? (in /lib/ld-2.6.so)
==1836== 
disInstr(ppc): found an AltiVec or an e500 instruction 0x13C17320
that can't be handled by Valgrind.  If this instruction is an
Altivec instruction, Valgrind must be run on a host that supportsAltiVec instructions.  If the application was compiled for e500, then
unfortunately Valgrind does not yet support e500 instructions.
==1836== valgrind: Unrecognised instruction at address 0x400df78.
==1836==    at 0x400DF78: ??? (in /lib/ld-2.6.so)
==1836== Your program just tried to execute an instruction that Valgrind
==1836== did not recognise.  There are two possible reasons for this.
==1836== 1. Your program has a bug and erroneously jumped to a non-code
==1836==    location.  If you are running Memcheck and you just saw a
==1836==    warning about a bad jump, it's probably your program's fault.
==1836== 2. The instruction is legitimate but Valgrind doesn't handle it,
==1836==    i.e. it's Valgrind's fault.  If you think this is the case or
==1836==    you are not sure, please let us know and we'll try to fix it.
==1836== Either way, Valgrind will now raise a SIGILL signal which will
==1836== probably kill your program.
==1836== 
==1836== Process terminating with default action of signal 4 (SIGILL)
==1836==  Illegal opcode at address 0x400DF78
==1836==    at 0x400DF78: ??? (in /lib/ld-2.6.so)
==1836== 
==1836== HEAP SUMMARY:
==1836==     in use at exit: 0 bytes in 0 blocks
==1836==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==1836== 
==1836== All heap blocks were freed -- no leaks are possible
==1836== 
==1836== For counts of detected and suppressed errors, rerun with: -v
==1836== Use --track-origins=yes to see where uninitialised values come from
==1836== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 0 from 0)
Illegal instruction

答案1

您显然正在使用 Ubuntu 17.04,并希望使用 Ubuntu 17.10 中提供的 valgrind 版本 3.13。最简单的方法是升级到 Ubuntu 17.10 并从默认的 Ubuntu 存储库安装 valgrind。无论如何,Ubuntu 17.04 将在今年二月之前的一个月内终止服务。

相关内容