1 //===-- StackFrameRecognizer.h ----------------------------------*- C++ -*-===// 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 #ifndef liblldb_StackFrameRecognizer_h_ 11 #define liblldb_StackFrameRecognizer_h_ 12 13 #include "lldb/Core/ValueObjectList.h" 14 #include "lldb/Symbol/VariableList.h" 15 #include "lldb/Utility/StructuredData.h" 16 #include "lldb/lldb-private-forward.h" 17 #include "lldb/lldb-public.h" 18 19 namespace lldb_private { 20 21 /// @class RecognizedStackFrame 22 /// 23 /// This class provides extra information about a stack frame that was 24 /// provided by a specific stack frame recognizer. Right now, this class only 25 /// holds recognized arguments (via GetRecognizedArguments). 26 27 class RecognizedStackFrame 28 : public std::enable_shared_from_this<RecognizedStackFrame> { 29 public: GetRecognizedArguments()30 virtual lldb::ValueObjectListSP GetRecognizedArguments() { 31 return m_arguments; 32 } GetExceptionObject()33 virtual lldb::ValueObjectSP GetExceptionObject() { 34 return lldb::ValueObjectSP(); 35 } ~RecognizedStackFrame()36 virtual ~RecognizedStackFrame(){}; 37 38 protected: 39 lldb::ValueObjectListSP m_arguments; 40 }; 41 42 /// @class StackFrameRecognizer 43 /// 44 /// A base class for frame recognizers. Subclasses (actual frame recognizers) 45 /// should implement RecognizeFrame to provide a RecognizedStackFrame for a 46 /// given stack frame. 47 48 class StackFrameRecognizer 49 : public std::enable_shared_from_this<StackFrameRecognizer> { 50 public: RecognizeFrame(lldb::StackFrameSP frame)51 virtual lldb::RecognizedStackFrameSP RecognizeFrame( 52 lldb::StackFrameSP frame) { 53 return lldb::RecognizedStackFrameSP(); 54 }; GetName()55 virtual std::string GetName() { 56 return ""; 57 } 58 ~StackFrameRecognizer()59 virtual ~StackFrameRecognizer(){}; 60 }; 61 62 #ifndef LLDB_DISABLE_PYTHON 63 64 /// @class ScriptedStackFrameRecognizer 65 /// 66 /// Python implementation for frame recognizers. An instance of this class 67 /// tracks a particular Python classobject, which will be asked to recognize 68 /// stack frames. 69 70 class ScriptedStackFrameRecognizer : public StackFrameRecognizer { 71 lldb_private::ScriptInterpreter *m_interpreter; 72 lldb_private::StructuredData::ObjectSP m_python_object_sp; 73 std::string m_python_class; 74 75 public: 76 ScriptedStackFrameRecognizer(lldb_private::ScriptInterpreter *interpreter, 77 const char *pclass); ~ScriptedStackFrameRecognizer()78 ~ScriptedStackFrameRecognizer() {} 79 GetName()80 std::string GetName() override { 81 return GetPythonClassName(); 82 } 83 GetPythonClassName()84 const char *GetPythonClassName() { return m_python_class.c_str(); } 85 86 lldb::RecognizedStackFrameSP RecognizeFrame( 87 lldb::StackFrameSP frame) override; 88 89 private: 90 DISALLOW_COPY_AND_ASSIGN(ScriptedStackFrameRecognizer); 91 }; 92 93 #endif 94 95 /// @class StackFrameRecognizerManager 96 /// 97 /// Static class that provides a registry of known stack frame recognizers. 98 /// Has static methods to add, enumerate, remove, query and invoke recognizers. 99 100 class StackFrameRecognizerManager { 101 public: 102 static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, 103 const ConstString &module, 104 const ConstString &symbol, 105 bool first_instruction_only = true); 106 107 static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, 108 lldb::RegularExpressionSP module, 109 lldb::RegularExpressionSP symbol, 110 bool first_instruction_only = true); 111 112 static void ForEach( 113 std::function<void(uint32_t recognizer_id, std::string recognizer_name, 114 std::string module, std::string symbol, 115 bool regexp)> const &callback); 116 117 static bool RemoveRecognizerWithID(uint32_t recognizer_id); 118 119 static void RemoveAllRecognizers(); 120 121 static lldb::StackFrameRecognizerSP GetRecognizerForFrame( 122 lldb::StackFrameSP frame); 123 124 static lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame); 125 }; 126 127 } // namespace lldb_private 128 129 #endif // liblldb_StackFrameRecognizer_h_ 130