1 //===-- StackFrameRecognizer.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_StackFrameRecognizer_h_
11 #define liblldb_StackFrameRecognizer_h_
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"
19 namespace lldb_private {
21 /// @class RecognizedStackFrame
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).
27 class RecognizedStackFrame
28 : public std::enable_shared_from_this<RecognizedStackFrame> {
30 virtual lldb::ValueObjectListSP GetRecognizedArguments() {
33 virtual lldb::ValueObjectSP GetExceptionObject() {
34 return lldb::ValueObjectSP();
36 virtual ~RecognizedStackFrame(){};
39 lldb::ValueObjectListSP m_arguments;
42 /// @class StackFrameRecognizer
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.
48 class StackFrameRecognizer
49 : public std::enable_shared_from_this<StackFrameRecognizer> {
51 virtual lldb::RecognizedStackFrameSP RecognizeFrame(
52 lldb::StackFrameSP frame) {
53 return lldb::RecognizedStackFrameSP();
55 virtual std::string GetName() {
59 virtual ~StackFrameRecognizer(){};
62 #ifndef LLDB_DISABLE_PYTHON
64 /// @class ScriptedStackFrameRecognizer
66 /// Python implementation for frame recognizers. An instance of this class
67 /// tracks a particular Python classobject, which will be asked to recognize
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;
76 ScriptedStackFrameRecognizer(lldb_private::ScriptInterpreter *interpreter,
78 ~ScriptedStackFrameRecognizer() {}
80 std::string GetName() override {
81 return GetPythonClassName();
84 const char *GetPythonClassName() { return m_python_class.c_str(); }
86 lldb::RecognizedStackFrameSP RecognizeFrame(
87 lldb::StackFrameSP frame) override;
90 DISALLOW_COPY_AND_ASSIGN(ScriptedStackFrameRecognizer);
95 /// @class StackFrameRecognizerManager
97 /// Static class that provides a registry of known stack frame recognizers.
98 /// Has static methods to add, enumerate, remove, query and invoke recognizers.
100 class StackFrameRecognizerManager {
102 static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
103 const ConstString &module,
104 const ConstString &symbol,
105 bool first_instruction_only = true);
107 static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
108 lldb::RegularExpressionSP module,
109 lldb::RegularExpressionSP symbol,
110 bool first_instruction_only = true);
113 std::function<void(uint32_t recognizer_id, std::string recognizer_name,
114 std::string module, std::string symbol,
115 bool regexp)> const &callback);
117 static bool RemoveRecognizerWithID(uint32_t recognizer_id);
119 static void RemoveAllRecognizers();
121 static lldb::StackFrameRecognizerSP GetRecognizerForFrame(
122 lldb::StackFrameSP frame);
124 static lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame);
127 } // namespace lldb_private
129 #endif // liblldb_StackFrameRecognizer_h_