如果该平台不支持Address Sanitizer说出detect_leaks,我该如何解决? [英] What should I fix when Address Sanitizer says detect_leaks is not supported on this platform?

查看:334
本文介绍了如果该平台不支持Address Sanitizer说出detect_leaks,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Clang在x86_64 OS X(MacOS 10.15.5 Catalina)上编译项目.

I'm using Clang to compile my project, on x86_64 OS X(MacOS 10.15.5 Catalina).

我想准确地确定从哪个文件,哪个函数,哪一行导致内存泄漏.我正在尝试使用地址清理器,特别是

I want to identify exactly from which file, which function, which line causes memory leaks. I am trying to use Address Sanitizer, specifically Leak Sanitizer.

以下是我在编译时使用的标志:

Here are flags that I'm using when compiling:

-Wall -Wextra -flto -O3 -march=native -ffast-math -fsanitize=address

成功编译.但是,当我尝试使用运行时标志 ASAN_OPTIONS = detect_leaks = 1 来启用Leak Sanitizer时,我看到以下错误:

It successfully compiles. However, when I try to use run-time flag ASAN_OPTIONS=detect_leaks=1 in order to enable Leak Sanitizer, I see the following error:

==26454==AddressSanitizer: detect_leaks is not supported on this platform.
Abort trap: 6

我做错了什么?我该如何解决?

What am I doing wrong? How could I fix this?

或者,除了Valgrind之外,还有别的好选择吗?Valgrind对我不起作用,因为1)我正在使用MacOS Catalina,2)我的程序运行时遇到无限循环.如果我是对的,Valgrind会在退出程序后显示消息,因此它将无法正常工作.

Or, is there another good alternative to a Valgrind? Valgrind doesn't work for me because 1)I'm using the MacOS Catalina, 2)My program runs with an infinite loop. If I'm right, Valgrind displays messages after exiting the program, so it won't work.

如果有人可以给我有关此问题的建议,我将不胜感激.

I would appreciate it if anyone could give me advice on this issue.

推荐答案

我在做什么错了?

What am I doing wrong?

什么都没有.问题是您的Clang版本不支持泄漏检测.但是,它看起来像最新版本.参见此答案

Nothing. The issue is that your version of Clang does not support leak detection. However, it looks like the latest version does. See this answer and this recipe.

Valgrind退出程序后显示消息,因此它将无法正常工作.

Valgrind displays messages after exiting the program, so it won't work.

您是正确的:默认情况下,Valgrind仅在程序退出时执行泄漏分析.

You are somewhat correct: by default, Valgrind will perform leak analysis only at program exit.

有两种解决方法:

  1. 使您的程序在执行中定义明确的位置退出,例如在执行N次计算或绘制K帧等之后.

  1. Make your program exit at some well defined place in the execution, e.g. after performing N calculations, or drawing K frames, etc.

使您的程序执行V​​ALGRIND_DO_LEAK_CHECK 客户请求.

Make your program perform VALGRIND_DO_LEAK_CHECK client request.

如果仅在某些条件成立时才执行泄漏检查,并且很难从程序内部检测到这些条件是否成立,则可以使用GDB和

If you want to perform the leak check only when certain conditions hold, and it's hard to detect whether these conditions are true from within the program, you could use GDB and the monitor command to ask Valgrind to perform leak check when desired.

这篇关于如果该平台不支持Address Sanitizer说出detect_leaks,我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆