• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- sanitizer_symbolizer.cc -------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is shared between AddressSanitizer and ThreadSanitizer
11 // run-time libraries.
12 //===----------------------------------------------------------------------===//
13 
14 #include "sanitizer_platform.h"
15 #include "sanitizer_internal_defs.h"
16 #include "sanitizer_placement_new.h"
17 #include "sanitizer_symbolizer.h"
18 
19 namespace __sanitizer {
20 
21 Symbolizer *Symbolizer::symbolizer_;
22 StaticSpinMutex Symbolizer::init_mu_;
23 LowLevelAllocator Symbolizer::symbolizer_allocator_;
24 
GetOrNull()25 Symbolizer *Symbolizer::GetOrNull() {
26   SpinMutexLock l(&init_mu_);
27   return symbolizer_;
28 }
29 
Get()30 Symbolizer *Symbolizer::Get() {
31   SpinMutexLock l(&init_mu_);
32   RAW_CHECK_MSG(symbolizer_ != 0, "Using uninitialized symbolizer!");
33   return symbolizer_;
34 }
35 
Disable()36 Symbolizer *Symbolizer::Disable() {
37   CHECK_EQ(0, symbolizer_);
38   // Initialize a dummy symbolizer.
39   symbolizer_ = new(symbolizer_allocator_) Symbolizer;
40   return symbolizer_;
41 }
42 
AddHooks(Symbolizer::StartSymbolizationHook start_hook,Symbolizer::EndSymbolizationHook end_hook)43 void Symbolizer::AddHooks(Symbolizer::StartSymbolizationHook start_hook,
44                           Symbolizer::EndSymbolizationHook end_hook) {
45   CHECK(start_hook_ == 0 && end_hook_ == 0);
46   start_hook_ = start_hook;
47   end_hook_ = end_hook;
48 }
49 
Symbolizer()50 Symbolizer::Symbolizer() : start_hook_(0), end_hook_(0) {}
51 
SymbolizerScope(const Symbolizer * sym)52 Symbolizer::SymbolizerScope::SymbolizerScope(const Symbolizer *sym)
53     : sym_(sym) {
54   if (sym_->start_hook_)
55     sym_->start_hook_();
56 }
57 
~SymbolizerScope()58 Symbolizer::SymbolizerScope::~SymbolizerScope() {
59   if (sym_->end_hook_)
60     sym_->end_hook_();
61 }
62 
63 }  // namespace __sanitizer
64