【问题标题】:Valgrind not working properly on OpenWRT, do I need to rebuild libc?Valgrind 在 OpenWRT 上无法正常工作,我需要重建 libc 吗?
【发布时间】:2021-11-14 20:30:38
【问题描述】:

我可以在我的 PC (Ubuntu) 上使用 Valgrind 检查某个 SW,但为了获得更真实的结果,我还想在 OpenWRT (21.02.0-rc4) 上检查相同的 SW。

基本上 Valgrind 在 OpenWRT 中运行,但目前存在几个问题:

1- 我在跑步

valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./my_SW

这在 PC 上有效,但在 OpenWRT 上,--track-origins=yes 参数会在 Valgrind 启动后立即导致“Killed”消息。

2- 当我跳过 track-origins 参数时,Valgrind 能够运行我的软件,但在最后的报告中:

==12462== HEAP SUMMARY:
==12462==     in use at exit: 0 bytes in 0 blocks
==12462==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==12462== 
==12462== All heap blocks were freed -- no leaks are possible

在 PC 上,Valgrind 报告了数千个分配和相同数量的空闲,但在 OpenWRT 上它似乎无法检测到任何堆使用情况。

3- 在 OpenWRT 上,我遇到许多错误,如下所示,而相同的软件在 PC 上运行时没有错误:

==12462== Conditional jump or move depends on uninitialised value(s)
==12462==    at 0x4079058: ??? (in /lib/libc.so)
==12462==    by 0x408A4B4: ??? (in /lib/libc.so)

我认为我的问题可能与以下问题有关:

cross-compiled Valgrind does not detect obvious leaks

所以我尝试应用建议的解决方案并使用我的 SW、Valgrind 和 libc 的未剥离版本。我为我的 SW 和 Valgrind 做了这个,但我不知道如何在 OpenWRT 中构建一个未剥离的 libc 版本。我找不到相关的makefile。有什么想法吗?

更新:@Paul Floyd 我尝试了您的建议,但似乎我的 valgrind 甚至不适用于 pwd:

root@OpenWrt:/opt# valgrind --tool=none pwd
==2919== Nulgrind, the minimal Valgrind tool
==2919== Copyright (C) 2002-2017, and GNU GPL'd, by Nicholas Nethercote.
==2919== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==2919== Command: pwd
==2919== 
vex mips->IR: unhandled instruction bytes: 0xE8 0x67 0x25 0xB3
==2919== 
==2919== Process terminating with default action of signal 4 (SIGILL)
==2919==    at 0x43B405: ??? (in /bin/busybox)
==2919==    by 0x4021A0C: ??? (in /lib/libc.so)
==2919== 
Illegal instruction
root@OpenWrt:/opt# 

【问题讨论】:

  • 被杀死的消息到底是什么?
  • root@OpenWrt:/opt# valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./my_SW ==12453== Memcheck ,内存错误检测器 ==12453== 版权所有 (C) 2002-2017 和 GNU GPL,由 Julian Seward 等人撰写。 ==12453== 使用 Valgrind-3.16.1 和 LibVEX;使用 -h 重新运行以获取版权信息 ==12453== 命令:./my_SW ==12453== Killed root@OpenWrt:/opt#

标签: linux valgrind openwrt


【解决方案1】:

我的建议是从简单开始。

获取 'valgrind --tool=none pwd' 或类似的工作。

不要添加“--track-origins=yes”,除非您遇到诸如“条件跳转或移动取决于未初始化的值”之类的错误,并且您无法从错误消息中找到问题所在。

再一次,您不需要“泄漏”选项。在没有它们的情况下运行,如果摘要表明存在泄漏,则根据需要添加它们。

你不应该需要 libc debuginfo。它会使错误调用堆栈更清晰一些,但没有它 Valgrind 应该可以正常工作。

您可以在 Ubuntu 机器和 OpenWRT 机器上将输出与“--tool=none --trace-redir=yes”进行比较。

你应该看到类似的东西

paulf> ./vg-in-place --tool=none --trace-redir=yes pwd 2>&1 | grep Reading
--42969-- Reading syms from /bin/pwd
--42969-- Reading syms from /libexec/ld-elf.so.1
--42969-- Reading syms from /usr/home/paulf/scratch/valgrind/none/none-amd64-freebsd
--42969-- Reading syms from /usr/home/paulf/scratch/valgrind/coregrind/vgpreload_core-amd64-freebsd.so
--42969-- Reading syms from /lib/libc.so.7
--42969-- Reading syms from /lib/libc.so.

路径和文件名可能不同,但应该总是这样

  1. 可执行文件
  2. 动态加载器库
  3. valgrind 工具
  4. valgrind 核心
  5. 链接到可执行文件的动态库

如果你没有看到“Reading syms from libc.so”,那么 Valgrind 将无法拦截对 malloc 和 free 的调用。

最后,您可以使用 --trace-symtab=yes 查看输出。这会很长,但是两个平台之间也不应该有任何莫名其妙的主要差异。

【讨论】:

  • 在 Ubuntu 上,命令输出与您的非常相似,但在 OpenWRT 上:root@OpenWrt:/opt# valgrind --tool=none --trace-redir=yes pwd 2>&1 | grep Reading --2893-- 从/usr/lib/valgrind/none-mips32-linux 读取syms --2893-- 从/usr/lib/valgrind/vgpreload_core-mips32-linux.so 读取syms 非法指令root@OpenWrt: /选择#​​
  • 如果 Valgrind 本身正在生成 SIGILL,那么编译 Valgrind 或硬件存在问题。
  • 顺便说一下,我最初认为问题可能与我自建的openWRT和Valgrind有关。因此,我将 OpenWRT 网站上提供的预构建 OpenWRT 映像刷入了我的目标,然后安装了标准的 Valgrind 包。但是同样的问题依然存在!这些问题要么是特定于目标的(TP-Link Archer C7),要么是特定于 CPU 架构的(MIPS)。我认为 Valgrind 应该在其他一些 OpenWRT 平台上工作,因为他们为它提供了一个包:) 我现在只在 Ubuntu 上使用 Valgrind...
猜你喜欢
  • 2018-02-09
  • 2018-03-27
  • 2015-05-06
  • 1970-01-01
  • 1970-01-01
  • 2019-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多