【问题标题】:-fsanitize=address doesn't work on QtCreator (mac10.13)-fsanitize=address 不适用于 QtCreator (mac10.13)
【发布时间】:2019-05-06 14:59:13
【问题描述】:

我在Mac10.13的Qtcreator中使用了-fsanitize=address,但是程序没有打印任何检测信息。是不是因为我的clang有问题?

泄漏.cpp

#include<iostream>
int main() {
    int * ptr = new int();
    std::cout << "test leak memory check" << std::endl;
    return 0;
}

构建命令:

clang++ leak.cpp -fsanitize=address -fno-omit-frame-pointer -o leak.out

终端输出:


test leak memory check

Clang 版本

Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

QtVerstion:5.11.1

【问题讨论】:

  • It's supposed to work as you have written it。检查 Compile Output 选项卡,看看这是否真的是 Qt Creator 使用的命令(有时它无法更新底层 makefile,您必须手动单击 Run Cmake 或 Run Qmake)。

标签: c++ macos clang


【解决方案1】:

您使用了错误的消毒剂。编译时使用

clang++ -fsanitize=leak -fno-omit-frame-pointer -o leak.out

并执行二进制文件(在 MacOS 10.13 上也测试过,从主干发出叮当声),你得到

 ==51079==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4 byte(s) in 1 object(s) allocated from:
#0 0x10fa8fb65 in wrap__Znwm lsan_interceptors.cc:288
#1 0x10fa7e1e8 in main (a.out:x86_64+0x1000011e8)
#2 0x7fff5f490014 in start (libdyld.dylib:x86_64+0x1014)

【讨论】:

  • 这是从trunk构建的clang,所以不是一个稳定的版本。
猜你喜欢
  • 2017-06-24
  • 2019-05-26
  • 1970-01-01
  • 2018-06-23
  • 2021-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
相关资源
最近更新 更多