gpt4 book ai didi

c++ - 如何将从 Google AddressSanitizer 抛出的错误记录到日志文件中

转载 作者:行者123 更新时间:2023-11-30 02:33:06 29 4
gpt4 key购买 nike

AddressSanitizer 默认情况下会将所有错误抛给 shell 本身,因此我尝试使用以下命令运行我的 ASAN 构建;

>MCTester_ASAN>asan.log

==15619==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61400000f9d0 at pc 0x46cff2 bp 0x7fffc062cb90 sp 0x7fffc062cb88
#0 0x46cff1 in heapOutOfBoundWrite() /home/MemTest/main.cpp:49
#1 0x46d68f in main /home/MemTest/main.cpp:116
#2 0x7fbd3365bc35 in __libc_start_main (/lib64/libc.so.6+0x1ec35)
#3 0x40a0f8 (/x01/exd10/bin/MCTester_ASAN+0x40a0f8)

ASAN:SIGSEGV
==15619==ERROR: AddressSanitizer: SEGV on unknown address 0x00000044ff97 (pc 0x00000046cff2 sp 0x7fffc062cba0 bp 0x7fffc062cbb0 T0)
#0 0x46cff1 in heapOutOfBoundWrite() /home/MemTest/main.cpp:49
#1 0x46d68f in main /home/MemTest/main.cpp:116
#2 0x7fbd3365bc35 in __libc_start_main (/lib64/libc.so.6+0x1ec35)
#3 0x40a0f8 (/x01/exd10/bin/MCTester_ASAN+0x40a0f8)

AddressSanitizer can not provide additional info.
Segmentation fault

但我仍然将输出发送到 shell 本身,而不是日志文件。

如何将输出捕获到日志文件?

最佳答案

要使 sanitizer 将报告写入文件,您可以将 log_path=log_file 作为 ASAN_OPTIONS 的一部分传递。如果您想将消息与任何其他输出分开,它可能会很方便。注意:文件名不会完全是 log_file,而是 log_file.$pid

例子:

$ cat test.cpp
int main() {
*((char*)0) = 0;
}
$ g++ test.cpp -o a -fsanitize=address -g3
$ ASAN_OPTIONS="log_path=asan.log" ./a
AddressSanitizer:DEADLYSIGNAL
$ cat asan.log.436962
=================================================================
==436962==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5626d3a50196 bp 0x7ffd0b2c2b00 sp 0x7ffd0b2c2b00 T0)
==436962==The signal is caused by a WRITE memory access.
==436962==Hint: address points to the zero page.
#0 0x5626d3a50196 in main /tmp/test.cpp:2
#1 0x7f79c3a78151 in __libc_start_main (/usr/lib/libc.so.6+0x28151)
#2 0x5626d3a5008d in _start (/tmp/a+0x108d)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /tmp/test.cpp:2 in main
==436962==ABORTING

关于c++ - 如何将从 Google AddressSanitizer 抛出的错误记录到日志文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35795716/

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