sanitizer_symbolizer.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. //===----------------------------------------------------------------------===//
  11. #include "sanitizer_platform.h"
  12. #include "sanitizer_internal_defs.h"
  13. #include "sanitizer_placement_new.h"
  14. #include "sanitizer_symbolizer.h"
  15. namespace __sanitizer {
  16. Symbolizer *Symbolizer::symbolizer_;
  17. StaticSpinMutex Symbolizer::init_mu_;
  18. LowLevelAllocator Symbolizer::symbolizer_allocator_;
  19. Symbolizer *Symbolizer::Disable() {
  20. CHECK_EQ(0, symbolizer_);
  21. // Initialize a dummy symbolizer.
  22. symbolizer_ = new(symbolizer_allocator_) Symbolizer;
  23. return symbolizer_;
  24. }
  25. void Symbolizer::AddHooks(Symbolizer::StartSymbolizationHook start_hook,
  26. Symbolizer::EndSymbolizationHook end_hook) {
  27. CHECK(start_hook_ == 0 && end_hook_ == 0);
  28. start_hook_ = start_hook;
  29. end_hook_ = end_hook;
  30. }
  31. Symbolizer::Symbolizer() : start_hook_(0), end_hook_(0) {}
  32. Symbolizer::SymbolizerScope::SymbolizerScope(const Symbolizer *sym)
  33. : sym_(sym) {
  34. if (sym_->start_hook_)
  35. sym_->start_hook_();
  36. }
  37. Symbolizer::SymbolizerScope::~SymbolizerScope() {
  38. if (sym_->end_hook_)
  39. sym_->end_hook_();
  40. }
  41. } // namespace __sanitizer