Daily bump.
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_symbolizer.cc
blobf417b087ae2e9f4dcca3ef1a603d2f4fe8360715
1 //===-- sanitizer_symbolizer.cc -------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer
9 // run-time libraries.
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_platform.h"
13 #include "sanitizer_internal_defs.h"
14 #include "sanitizer_placement_new.h"
15 #include "sanitizer_symbolizer.h"
17 namespace __sanitizer {
19 Symbolizer *Symbolizer::symbolizer_;
20 StaticSpinMutex Symbolizer::init_mu_;
21 LowLevelAllocator Symbolizer::symbolizer_allocator_;
23 Symbolizer *Symbolizer::GetOrNull() {
24 SpinMutexLock l(&init_mu_);
25 return symbolizer_;
28 Symbolizer *Symbolizer::Get() {
29 SpinMutexLock l(&init_mu_);
30 RAW_CHECK_MSG(symbolizer_ != 0, "Using uninitialized symbolizer!");
31 return symbolizer_;
34 Symbolizer *Symbolizer::Disable() {
35 CHECK_EQ(0, symbolizer_);
36 // Initialize a dummy symbolizer.
37 symbolizer_ = new(symbolizer_allocator_) Symbolizer;
38 return symbolizer_;
41 void Symbolizer::AddHooks(Symbolizer::StartSymbolizationHook start_hook,
42 Symbolizer::EndSymbolizationHook end_hook) {
43 CHECK(start_hook_ == 0 && end_hook_ == 0);
44 start_hook_ = start_hook;
45 end_hook_ = end_hook;
48 Symbolizer::Symbolizer() : start_hook_(0), end_hook_(0) {}
50 Symbolizer::SymbolizerScope::SymbolizerScope(const Symbolizer *sym)
51 : sym_(sym) {
52 if (sym_->start_hook_)
53 sym_->start_hook_();
56 Symbolizer::SymbolizerScope::~SymbolizerScope() {
57 if (sym_->end_hook_)
58 sym_->end_hook_();
61 } // namespace __sanitizer