LLDB  mainline
StackFrameRecognizer.h
Go to the documentation of this file.
1 //===-- StackFrameRecognizer.h ----------------------------------*- 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 
9 #ifndef LLDB_TARGET_STACKFRAMERECOGNIZER_H
10 #define LLDB_TARGET_STACKFRAMERECOGNIZER_H
11 
12 #include "lldb/Core/ValueObject.h"
15 #include "lldb/Target/StopInfo.h"
18 #include "lldb/lldb-public.h"
19 
20 namespace lldb_private {
21 
22 /// \class RecognizedStackFrame
23 ///
24 /// This class provides extra information about a stack frame that was
25 /// provided by a specific stack frame recognizer. Right now, this class only
26 /// holds recognized arguments (via GetRecognizedArguments).
27 
29  : public std::enable_shared_from_this<RecognizedStackFrame> {
30 public:
31  virtual lldb::ValueObjectListSP GetRecognizedArguments() {
32  return m_arguments;
33  }
34  virtual lldb::ValueObjectSP GetExceptionObject() {
35  return lldb::ValueObjectSP();
36  }
37  virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
38  virtual ~RecognizedStackFrame(){};
39 
40  std::string GetStopDescription() { return m_stop_desc; }
41 
42 protected:
43  lldb::ValueObjectListSP m_arguments;
44  std::string m_stop_desc;
45 };
46 
47 /// \class StackFrameRecognizer
48 ///
49 /// A base class for frame recognizers. Subclasses (actual frame recognizers)
50 /// should implement RecognizeFrame to provide a RecognizedStackFrame for a
51 /// given stack frame.
52 
54  : public std::enable_shared_from_this<StackFrameRecognizer> {
55 public:
56  virtual lldb::RecognizedStackFrameSP RecognizeFrame(
57  lldb::StackFrameSP frame) {
58  return lldb::RecognizedStackFrameSP();
59  };
60  virtual std::string GetName() {
61  return "";
62  }
63 
64  virtual ~StackFrameRecognizer(){};
65 };
66 
67 /// \class ScriptedStackFrameRecognizer
68 ///
69 /// Python implementation for frame recognizers. An instance of this class
70 /// tracks a particular Python classobject, which will be asked to recognize
71 /// stack frames.
72 
76  std::string m_python_class;
77 
78 public:
80  const char *pclass);
82 
83  std::string GetName() override {
84  return GetPythonClassName();
85  }
86 
87  const char *GetPythonClassName() { return m_python_class.c_str(); }
88 
89  lldb::RecognizedStackFrameSP RecognizeFrame(
90  lldb::StackFrameSP frame) override;
91 
92 private:
93  DISALLOW_COPY_AND_ASSIGN(ScriptedStackFrameRecognizer);
94 };
95 
96 /// \class StackFrameRecognizerManager
97 ///
98 /// Static class that provides a registry of known stack frame recognizers.
99 /// Has static methods to add, enumerate, remove, query and invoke recognizers.
100 
102 public:
103  static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
104  ConstString module,
105  llvm::ArrayRef<ConstString> symbols,
106  bool first_instruction_only = true);
107 
108  static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
109  lldb::RegularExpressionSP module,
110  lldb::RegularExpressionSP symbol,
111  bool first_instruction_only = true);
112 
113  static void
114  ForEach(std::function<void(uint32_t recognizer_id,
115  std::string recognizer_name, std::string module,
116  llvm::ArrayRef<ConstString> symbols,
117  bool regexp)> const &callback);
118 
119  static bool RemoveRecognizerWithID(uint32_t recognizer_id);
120 
121  static void RemoveAllRecognizers();
122 
123  static lldb::StackFrameRecognizerSP GetRecognizerForFrame(
124  lldb::StackFrameSP frame);
125 
126  static lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame);
127 };
128 
129 /// \class ValueObjectRecognizerSynthesizedValue
130 ///
131 /// ValueObject subclass that presents the passed ValueObject as a recognized
132 /// value with the specified ValueType. Frame recognizers should return
133 /// instances of this class as the returned objects in GetRecognizedArguments().
134 
136  public:
137  static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type) {
138  return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
139  }
141  lldb::ValueType type)
142  : ValueObject(parent), m_type(type) {
143  SetName(parent.GetName());
144  }
145 
146  uint64_t GetByteSize() override { return m_parent->GetByteSize(); }
147  lldb::ValueType GetValueType() const override { return m_type; }
148  bool UpdateValue() override {
149  if (!m_parent->UpdateValueIfNeeded()) return false;
150  m_value = m_parent->GetValue();
151  return true;
152  }
153  size_t CalculateNumChildren(uint32_t max = UINT32_MAX) override {
154  return m_parent->GetNumChildren(max);
155  }
157  return m_parent->GetCompilerType();
158  }
159  bool IsSynthetic() override { return true; }
160 
161  private:
163 };
164 
165 } // namespace lldb_private
166 
167 #endif // LLDB_TARGET_STACKFRAMERECOGNIZER_H
A class that represents a running process on the host machine.
ConstString GetName() const
lldb_private::StructuredData::ObjectSP m_python_object_sp
ValueObject subclass that presents the passed ValueObject as a recognized value with the specified Va...
static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type)
ValueObjectRecognizerSynthesizedValue(ValueObject &parent, lldb::ValueType type)
A base class for frame recognizers.
Static class that provides a registry of known stack frame recognizers.
#define UINT32_MAX
Definition: lldb-defines.h:31
virtual lldb::ValueObjectListSP GetRecognizedArguments()
virtual lldb::ValueObjectSP GetExceptionObject()
lldb_private::ScriptInterpreter * m_interpreter
size_t CalculateNumChildren(uint32_t max=UINT32_MAX) override
Python implementation for frame recognizers.
A uniqued constant string class.
Definition: ConstString.h:40
Represents a generic type in a programming language.
Definition: CompilerType.h:33
std::shared_ptr< Object > ObjectSP
This class provides extra information about a stack frame that was provided by a specific stack frame...
virtual lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
virtual lldb::StackFrameSP GetMostRelevantFrame()