您的路径中缺少 ASAN。以下是在 Xcode 之外完成的,以查看我是否可以显示错误,并且如果路径未定义,这很容易。我的猜测是 XCode 找不到它正在寻找的位置,或者在以下情况下 ASAN 路径未定义。
当您尝试此操作时,如果您在路径中添加和删除它,错误就会消失,但行号也会消失,即如果您想再次看到实际的错误消息,您需要使用
unset ASAN_SYMBOLIZER_PATH
不是
ASAN_SYMBOLIZER_PATH=
创建ac程序如下...
int main(void){
int a[3];
a[3] = 4;
return 0;
}
编译它,请暂时忽略警告...
gcc -std=c11 -Wall -g3 -fno-omit-frame-pointer -fsanitize=address broken_asan_test.c
./a.out
你应该看到这样的东西......
=================================================================
==29192==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff5ad1052c at pc 0x000104eefe78 bp 0x7fff5ad104f0 sp 0x7fff5ad104e8
WRITE of size 4 at 0x7fff5ad1052c thread T0
#0 0x104eefe77 in atos[29193]: [fatal] 'pid_for_task' failed: (os/kern) failure (5) (+0x100000e77)
==29192==WARNING: Can't write to symbolizer at fd 3
#1 0x7fff940495ac in atos[29206]: [fatal] 'pid_for_task' failed: (os/kern) failure (5) (+0x35ac)
#2 0x0 (<unknown module>)
注意这一行
==29192==WARNING: Can't write to symbolizer at fd 3
更改以将符号器添加到您的路径中...
export ASAN_SYMBOLIZER_PATH=/usr/local/Cellar/llvm/3.6.2/bin/llvm-symbolizer
并且错误消失了...
=================================================================
==29312==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff55ac450c at pc 0x00010a13be78 bp 0x7fff55ac44d0 sp 0x7fff55ac44c8
WRITE of size 4 at 0x7fff55ac450c thread T0
#0 0x10a13be77 in main (/git/ghub/doc/c/./a.out+0x100000e77)
#1 0x7fff940495ac in start (/usr/lib/system/libdyld.dylib+0x35ac)
#2 0x0 (<unknown module>)