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