How to set ASAN/UBSAN reporting output
Asked Answered
C

3

6

I would like to run my unit test suite with -fsanitize=address,undefined and have all sanitizer errors be written to a report.txt file. By default all sanitizer errors get written to stdout, however the software also writes info to stdout so this makes it difficult to detect errors. I tried:

export ASAN_OPTIONS="log_path=asan.log"
./mytests

And I also tried calling the C API before running tests:

#include <sanitizer/asan_interface.h>

__sanitizer_set_report_path("/tmp/asan.log")

However neither seems to work, all errors just get written to stdout. I am using Debian testing:

root@94e239ad460a:~# gcc --version
gcc (Debian 6.1.1-11) 6.1.1 20160802
Copyright (C) 2016 Free Software Foundation, Inc.

Is there any alternative method that I can save the sanitizer error from my unit tests somewhere?

Confound answered 25/9, 2016 at 12:8 Comment(0)
Z
2

Hm, I've successfully used log_path numerous times. If it does not work for you, please report a bug to ASan github (preferably with a minimal repro).

Zenobiazeolite answered 24/10, 2016 at 8:33 Comment(0)
D
1

I realize that my binaries were not having read permissions. A simple chmod 500 <exe_path> solved my problem.

Delphadelphi answered 26/2, 2020 at 19:34 Comment(1)
Note that Asan should have written an error message to stderr to diagnose that.Zenobiazeolite
D
0

What I always do is to make sure the directory exists. You could use Qt:

QDir().mkpath("/tmp");

Asan will append a PID to your filename though, and I don't think you can disable that.

In my common_interface_defs.h there is only __sanitizer_set_report_path but I see that gcc's master has a more recent function where you pass on a file descriptor:

void __sanitizer_set_report_fd(void *fd);

You could check out if your platform's gcc/clang has the newer function to set a file descriptor.

Daisey answered 20/8, 2018 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.