2013-10-26 07:03:29 +08:00
|
|
|
//===-- sanitizer_symbolizer.cc -------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
|
|
|
// run-time libraries.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-12-03 03:48:40 +08:00
|
|
|
#include "sanitizer_allocator_internal.h"
|
2013-10-26 07:03:29 +08:00
|
|
|
#include "sanitizer_platform.h"
|
|
|
|
#include "sanitizer_internal_defs.h"
|
2014-12-03 03:48:40 +08:00
|
|
|
#include "sanitizer_libc.h"
|
2013-10-26 07:03:29 +08:00
|
|
|
#include "sanitizer_placement_new.h"
|
2015-03-10 02:36:28 +08:00
|
|
|
#include "sanitizer_symbolizer_internal.h"
|
2013-10-26 07:03:29 +08:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
2014-12-03 03:48:40 +08:00
|
|
|
AddressInfo::AddressInfo() {
|
|
|
|
internal_memset(this, 0, sizeof(AddressInfo));
|
|
|
|
function_offset = kUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressInfo::Clear() {
|
|
|
|
InternalFree(module);
|
|
|
|
InternalFree(function);
|
|
|
|
InternalFree(file);
|
|
|
|
internal_memset(this, 0, sizeof(AddressInfo));
|
|
|
|
function_offset = kUnknown;
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:18:44 +08:00
|
|
|
void AddressInfo::FillModuleInfo(const char *mod_name, uptr mod_offset) {
|
2014-12-03 03:48:40 +08:00
|
|
|
module = internal_strdup(mod_name);
|
|
|
|
module_offset = mod_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolizedStack::SymbolizedStack() : next(nullptr), info() {}
|
|
|
|
|
|
|
|
SymbolizedStack *SymbolizedStack::New(uptr addr) {
|
|
|
|
void *mem = InternalAlloc(sizeof(SymbolizedStack));
|
|
|
|
SymbolizedStack *res = new(mem) SymbolizedStack();
|
|
|
|
res->info.address = addr;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SymbolizedStack::ClearAll() {
|
|
|
|
info.Clear();
|
|
|
|
if (next)
|
|
|
|
next->ClearAll();
|
|
|
|
InternalFree(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DataInfo::DataInfo() {
|
|
|
|
internal_memset(this, 0, sizeof(DataInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataInfo::Clear() {
|
|
|
|
InternalFree(module);
|
2016-03-01 23:38:12 +08:00
|
|
|
InternalFree(file);
|
2014-12-03 03:48:40 +08:00
|
|
|
InternalFree(name);
|
|
|
|
internal_memset(this, 0, sizeof(DataInfo));
|
|
|
|
}
|
|
|
|
|
2013-10-31 01:05:37 +08:00
|
|
|
Symbolizer *Symbolizer::symbolizer_;
|
|
|
|
StaticSpinMutex Symbolizer::init_mu_;
|
2013-10-26 07:03:29 +08:00
|
|
|
LowLevelAllocator Symbolizer::symbolizer_allocator_;
|
|
|
|
|
2013-11-01 05:44:07 +08:00
|
|
|
void Symbolizer::AddHooks(Symbolizer::StartSymbolizationHook start_hook,
|
|
|
|
Symbolizer::EndSymbolizationHook end_hook) {
|
|
|
|
CHECK(start_hook_ == 0 && end_hook_ == 0);
|
|
|
|
start_hook_ = start_hook;
|
|
|
|
end_hook_ = end_hook;
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:50:05 +08:00
|
|
|
const char *Symbolizer::ModuleNameOwner::GetOwnedCopy(const char *str) {
|
|
|
|
mu_->CheckLocked();
|
|
|
|
|
|
|
|
// 'str' will be the same string multiple times in a row, optimize this case.
|
|
|
|
if (last_match_ && !internal_strcmp(last_match_, str))
|
|
|
|
return last_match_;
|
|
|
|
|
|
|
|
// FIXME: this is linear search.
|
|
|
|
// We should optimize this further if this turns out to be a bottleneck later.
|
|
|
|
for (uptr i = 0; i < storage_.size(); ++i) {
|
|
|
|
if (!internal_strcmp(storage_[i], str)) {
|
|
|
|
last_match_ = storage_[i];
|
|
|
|
return last_match_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_match_ = internal_strdup(str);
|
|
|
|
storage_.push_back(last_match_);
|
|
|
|
return last_match_;
|
|
|
|
}
|
|
|
|
|
2015-03-10 02:36:28 +08:00
|
|
|
Symbolizer::Symbolizer(IntrusiveList<SymbolizerTool> tools)
|
2016-02-23 02:52:51 +08:00
|
|
|
: module_names_(&mu_), modules_(), modules_fresh_(false), tools_(tools),
|
2015-04-06 20:49:30 +08:00
|
|
|
start_hook_(0), end_hook_(0) {}
|
2013-11-01 05:44:07 +08:00
|
|
|
|
|
|
|
Symbolizer::SymbolizerScope::SymbolizerScope(const Symbolizer *sym)
|
|
|
|
: sym_(sym) {
|
|
|
|
if (sym_->start_hook_)
|
|
|
|
sym_->start_hook_();
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbolizer::SymbolizerScope::~SymbolizerScope() {
|
|
|
|
if (sym_->end_hook_)
|
|
|
|
sym_->end_hook_();
|
|
|
|
}
|
|
|
|
|
2013-10-26 07:03:29 +08:00
|
|
|
} // namespace __sanitizer
|