Skip to content

Commit

Permalink
[libFuzzer] use __sanitizer_get_module_and_offset_for_pc to get the m…
Browse files Browse the repository at this point in the history
…odule name while printing the coverage

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289310 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kcc committed Dec 10, 2016
1 parent f4fb506 commit bd91868
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/Fuzzer/FuzzerExtFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ EXT_FUNC(__sanitizer_print_memory_profile, int, (size_t), false);
EXT_FUNC(__sanitizer_print_stack_trace, void, (), true);
EXT_FUNC(__sanitizer_symbolize_pc, void,
(void *, const char *fmt, char *out_buf, size_t out_buf_size), false);
EXT_FUNC(__sanitizer_get_module_and_offset_for_pc, int,
(void *pc, char *module_path,
size_t module_path_len,void **pc_offset), false);
EXT_FUNC(__sanitizer_reset_coverage, void, (), true);
EXT_FUNC(__sanitizer_set_death_callback, void, (void (*)(void)), true);
EXT_FUNC(__sanitizer_set_report_fd, void, (void*), false);
Expand Down
19 changes: 12 additions & 7 deletions lib/Fuzzer/FuzzerTracePC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ void TracePC::PrintNewPCs() {
}

void TracePC::PrintCoverage() {
if (!EF->__sanitizer_symbolize_pc) {
Printf("INFO: __sanitizer_symbolize_pc is not available,"
if (!EF->__sanitizer_symbolize_pc ||
!EF->__sanitizer_get_module_and_offset_for_pc) {
Printf("INFO: __sanitizer_symbolize_pc or "
"__sanitizer_get_module_and_offset_for_pc is not available,"
" not printing coverage\n");
return;
}
Expand All @@ -106,12 +108,15 @@ void TracePC::PrintCoverage() {
std::string FixedPCStr = DescribePC("%p", PCs[i]);
std::string FunctionStr = DescribePC("%F", PCs[i]);
std::string LineStr = DescribePC("%l", PCs[i]);
// TODO(kcc): get the module using some other way since this
// does not work with ASAN_OPTIONS=strip_path_prefix=something.
std::string Module = DescribePC("%m", PCs[i]);
std::string OffsetStr = DescribePC("%o", PCs[i]);
char ModulePathRaw[4096] = ""; // What's PATH_MAX in portable C++?
void *OffsetRaw = nullptr;
if (!EF->__sanitizer_get_module_and_offset_for_pc(
reinterpret_cast<void *>(PCs[i]), ModulePathRaw,
sizeof(ModulePathRaw), &OffsetRaw))
continue;
std::string Module = ModulePathRaw;
uintptr_t FixedPC = std::stol(FixedPCStr, 0, 16);
uintptr_t PcOffset = std::stol(OffsetStr, 0, 16);
uintptr_t PcOffset = reinterpret_cast<uintptr_t>(OffsetRaw);
ModuleOffsets[Module] = FixedPC - PcOffset;
CoveredPCsPerModule[Module].push_back(PcOffset);
CoveredFunctions.insert(FunctionStr);
Expand Down

0 comments on commit bd91868

Please sign in to comment.