static CoverageData coverage_data;
void CoverageData::DirectInit() {
- InternalScopedString path(64);
- internal_snprintf((char *)path.data(), path.size(), "%zd.sancov.raw",
- internal_getpid());
+ InternalScopedString path(1024);
+ internal_snprintf((char *)path.data(), path.size(), "%s/%zd.sancov.raw",
+ common_flags()->coverage_dir, internal_getpid());
pc_fd = OpenFile(path.data(), true);
if (internal_iserror(pc_fd)) {
Report(" Coverage: failed to open %s for writing\n", path.data());
InternalScopedBuffer<char> path(1024);
if (!packed) {
CHECK(name);
- internal_snprintf((char *)path.data(), path.size(), "%s.%zd.sancov",
- name, internal_getpid());
+ Printf("%s\n", common_flags()->coverage_dir);
+ internal_snprintf((char *)path.data(), path.size(), "%s/%s.%zd.sancov",
+ common_flags()->coverage_dir, name, internal_getpid());
} else {
if (!name)
- internal_snprintf((char *)path.data(), path.size(), "%zd.sancov.packed",
+ internal_snprintf((char *)path.data(), path.size(),
+ "%s/%zd.sancov.packed", common_flags()->coverage_dir,
internal_getpid());
else
- internal_snprintf((char *)path.data(), path.size(), "%s.sancov.packed",
- name);
+ internal_snprintf((char *)path.data(), path.size(), "%s/%s.sancov.packed",
+ common_flags()->coverage_dir, name);
}
uptr fd = OpenFile(path.data(), true);
if (internal_iserror(fd)) {
}
} else {
// One file per module per process.
- internal_snprintf((char *)path.data(), path.size(), "%s.%zd.sancov",
- module_name, internal_getpid());
+ internal_snprintf((char *)path.data(), path.size(), "%s/%s.%zd.sancov",
+ common_flags()->coverage_dir, module_name,
+ internal_getpid());
int fd = CovOpenFile(false /* packed */, module_name);
if (fd > 0) {
internal_write(fd, offsets.data(), offsets.size() * sizeof(u32));
if (!common_flags()->coverage || !common_flags()->coverage_direct) return;
int err;
- InternalScopedString tmp_path(64);
- internal_snprintf((char *)tmp_path.data(), tmp_path.size(),
- "%zd.sancov.map.tmp", internal_getpid());
+ InternalScopedString tmp_path(64 +
+ internal_strlen(common_flags()->coverage_dir));
+ uptr res = internal_snprintf((char *)tmp_path.data(), tmp_path.size(),
+ "%s/%zd.sancov.map.tmp", common_flags()->coverage_dir,
+ internal_getpid());
+ CHECK_LE(res, tmp_path.size());
uptr map_fd = OpenFile(tmp_path.data(), true);
if (internal_iserror(map_fd)) {
Report(" Coverage: failed to open %s for writing\n", tmp_path.data());
InternalScopedString line(4096);
line.append("%d\n", sizeof(uptr) * 8);
- uptr res = internal_write(map_fd, line.data(), line.length());
+ res = internal_write(map_fd, line.data(), line.length());
if (internal_iserror(res, &err)) {
Printf("sancov.map write failed: %d\n", err);
Die();
internal_close(map_fd);
- InternalScopedString path(64);
- internal_snprintf((char *)path.data(), path.size(), "%zd.sancov.map",
- internal_getpid());
+ InternalScopedString path(64 + internal_strlen(common_flags()->coverage_dir));
+ res = internal_snprintf((char *)path.data(), path.size(), "%s/%zd.sancov.map",
+ common_flags()->coverage_dir, internal_getpid());
+ CHECK_LE(res, path.size());
res = internal_rename(tmp_path.data(), path.data());
if (internal_iserror(res, &err)) {
Printf("sancov.map rename failed: %d\n", err);
f->intercept_tls_get_addr = false;
f->coverage = false;
f->coverage_direct = false;
+ f->coverage_dir = ".";
f->full_address_space = false;
}
"If set, coverage information will be dumped directly to a memory "
"mapped file. This way data is not lost even if the process is "
"suddenly killed.");
+ ParseFlag(str, &f->coverage_dir, "coverage_dir",
+ "Target directory for coverage dumps. Defaults to the current "
+ "directory.");
ParseFlag(str, &f->full_address_space, "full_address_space",
"Sanitize complete address space; "
"by default kernel area on 32-bit platforms will not be sanitized");
uptr mmap_limit_mb;
bool coverage;
bool coverage_direct;
+ const char *coverage_dir;
bool full_address_space;
};
// RUN: rm -rf %T/coverage-direct
-// RUN: mkdir -p %T/coverage-direct/normal && cd %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
+// RUN: mkdir -p %T/coverage-direct/normal
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
+// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
-// RUN: mkdir -p %T/coverage-direct/direct && cd %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t
+// RUN: mkdir -p %T/coverage-direct/direct
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
+// RUN: cd %T/coverage-direct/direct
// RUN: %sancov rawunpack *.sancov.raw
// RUN: %sancov print *.sancov >out.txt
// RUN: cd ../..