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:
95  operator=(const ScriptedStackFrameRecognizer &) = delete;
96 };
97 
98 /// \class StackFrameRecognizerManager
99 ///
100 /// Static class that provides a registry of known stack frame recognizers.
101 /// Has static methods to add, enumerate, remove, query and invoke recognizers.
102 
104 public:
105  static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
106  ConstString module,
107  llvm::ArrayRef<ConstString> symbols,
108  bool first_instruction_only = true);
109 
110  static void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
111  lldb::RegularExpressionSP module,
112  lldb::RegularExpressionSP symbol,
113  bool first_instruction_only = true);
114 
115  static void
116  ForEach(std::function<void(uint32_t recognizer_id,
117  std::string recognizer_name, std::string module,
118  llvm::ArrayRef<ConstString> symbols,
119  bool regexp)> const &callback);
120 
121  static bool RemoveRecognizerWithID(uint32_t recognizer_id);
122 
123  static void RemoveAllRecognizers();
124 
125  static lldb::StackFrameRecognizerSP GetRecognizerForFrame(
126  lldb::StackFrameSP frame);
127 
128  static lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame);
129 };
130 
131 /// \class ValueObjectRecognizerSynthesizedValue
132 ///
133 /// ValueObject subclass that presents the passed ValueObject as a recognized
134 /// value with the specified ValueType. Frame recognizers should return
135 /// instances of this class as the returned objects in GetRecognizedArguments().
136 
138  public:
139  static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type) {
140  return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
141  }
143  lldb::ValueType type)
144  : ValueObject(parent), m_type(type) {
145  SetName(parent.GetName());
146  }
147 
148  uint64_t GetByteSize() override { return m_parent->GetByteSize(); }
149  lldb::ValueType GetValueType() const override { return m_type; }
150  bool UpdateValue() override {
151  if (!m_parent->UpdateValueIfNeeded()) return false;
152  m_value = m_parent->GetValue();
153  return true;
154  }
155  size_t CalculateNumChildren(uint32_t max = UINT32_MAX) override {
156  return m_parent->GetNumChildren(max);
157  }
159  return m_parent->GetCompilerType();
160  }
161  bool IsSynthetic() override { return true; }
162 
163  private:
165 };
166 
167 } // namespace lldb_private
168 
169 #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()