gpt4 book ai didi

linux - 了解 ASAN 输出

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:05 46 4
gpt4 key购买 nike

我无法弄清楚为什么 ASAN 会给出这个输出,为什么我看不到错误在我的代码中的位置和行中,这个错误是在我的代码中,还是在某些库中被程序使用?这就是我构建项目的方式:

CC=clang CXX=clang++ meson -Db_sanitize=address -Db_lundef=false build-clang

然后我配置 env 值并像这样运行可执行文件:

ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./executable

是的,这是 llvm-sybolizer 的有效路径

那么有没有办法让我知道 executable+0x431340 是什么意思以及它在我的代码中指向的位置?

=================================================================
==13110==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 16384 byte(s) in 1 object(s) allocated from:
#0 0x4e1340 in __interceptor_malloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1340)
#1 0x7ff16a2ccab8 in g_malloc (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51ab8)

Direct leak of 4352 byte(s) in 17 object(s) allocated from:
#0 0x4e1340 in __interceptor_malloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1340)
#1 0x7ff165e518ed (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1d8ed)

Direct leak of 3840 byte(s) in 6 object(s) allocated from:
#0 0x4e17c0 in realloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e17c0)
#1 0x7ff165e51998 (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1d998)

Direct leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x4e1340 in __interceptor_malloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1340)
#1 0x7ff16a2ccab8 in g_malloc (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51ab8)
#2 0x7ff168b5910c in g_closure_invoke (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x1010c)

Indirect leak of 10016 byte(s) in 313 object(s) allocated from:
#0 0x4e1340 in __interceptor_malloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1340)
#1 0x7ff165e3ffef (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0xbfef)

Indirect leak of 4887 byte(s) in 405 object(s) allocated from:
#0 0x43db60 in strdup (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x43db60)
#1 0x7ff165e512f4 in FcValueSave (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1d2f4)

Indirect leak of 4320 byte(s) in 135 object(s) allocated from:
#0 0x4e1568 in calloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1568)
#1 0x7ff165e51fd8 (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1dfd8)

Indirect leak of 2400 byte(s) in 75 object(s) allocated from:
#0 0x4e1568 in calloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1568)
#1 0x7ff165e515c4 (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1d5c4)

Indirect leak of 576 byte(s) in 18 object(s) allocated from:
#0 0x4e1568 in calloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1568)
#1 0x7ff165e51440 (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x1d440)

Indirect leak of 144 byte(s) in 3 object(s) allocated from:
#0 0x4e1340 in __interceptor_malloc (/home/maysara/Desktop/testscreen/build-clang/src/excutable+0x4e1340)
#1 0x7ff165e4bacd in FcLangSetCreate (/usr/lib/x86_64-linux-gnu/libfontconfig.so.1+0x17acd)

SUMMARY: AddressSanitizer: 46943 byte(s) leaked in 974 allocation(s).

最佳答案

为了将代码地址解析为源代码位置,您需要在启用调试符号的情况下编译代码,例如在编译器命令行上使用 -g 或通常与构建系统一起使用环境变量 CFLAGSCXXFLAGS 进行相应设置:

CFLAGS="-g"
CXXFLAGS="-g"

需要为实际引用的代码做这件事,这里指的不仅是executable的代码,还有glib等链接库fontconfig等,如果你想解析所有地址。

由于这些库可能是通过系统包管理器安装的,因此您需要查看发行版的文档以了解如何安装调试符号。例如,对于 Ubuntu,通常有带有 -dbg 后缀的软件包变体。

在任何情况下,您的堆栈跟踪看起来都不是很有帮助,因此不清楚找到源代码位置是否对您有任何帮助。您可能希望在运行可执行文件时使用 -fno-omit-frame-pointer 重新编译可执行文件和/或设置环境变量 ASAN_OPTIONS=fast_unwind_on_malloc=0 以尝试改进他们。另见 the ASAN faq .

关于linux - 了解 ASAN 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57742000/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com