PrettyStackTraceLocationContext.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //==- PrettyStackTraceLocationContext.h - show analysis backtrace --*- C++ -*-//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_CLANG_LIB_STATICANALYZER_CORE_PRETTYSTACKTRACELOCATIONCONTEXT_H
  9. #define LLVM_CLANG_LIB_STATICANALYZER_CORE_PRETTYSTACKTRACELOCATIONCONTEXT_H
  10. #include "clang/Analysis/AnalysisDeclContext.h"
  11. namespace clang {
  12. namespace ento {
  13. /// While alive, includes the current analysis stack in a crash trace.
  14. ///
  15. /// Example:
  16. /// \code
  17. /// 0. Program arguments: ...
  18. /// 1. <eof> parser at end of file
  19. /// 2. While analyzing stack:
  20. /// #0 void inlined()
  21. /// #1 void test()
  22. /// 3. crash-trace.c:6:3: Error evaluating statement
  23. /// \endcode
  24. class PrettyStackTraceLocationContext : public llvm::PrettyStackTraceEntry {
  25. const LocationContext *LCtx;
  26. public:
  27. PrettyStackTraceLocationContext(const LocationContext *LC) : LCtx(LC) {
  28. assert(LCtx);
  29. }
  30. void print(raw_ostream &Out) const override {
  31. Out << "While analyzing stack: \n";
  32. LCtx->dumpStack(Out);
  33. }
  34. };
  35. } // end ento namespace
  36. } // end clang namespace
  37. #endif