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 #include <vector>
21 
22 namespace lldb_private {
23 
24 /// \class RecognizedStackFrame
25 ///
26 /// This class provides extra information about a stack frame that was
27 /// provided by a specific stack frame recognizer. Right now, this class only
28 /// holds recognized arguments (via GetRecognizedArguments).
29 
31  : public std::enable_shared_from_this<RecognizedStackFrame> {
32 public:
33  virtual lldb::ValueObjectListSP GetRecognizedArguments() {
34  return m_arguments;
35  }
36  virtual lldb::ValueObjectSP GetExceptionObject() {
37  return lldb::ValueObjectSP();
38  }
39  virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
40  virtual ~RecognizedStackFrame() = default;
41 
43 
44 protected:
45  lldb::ValueObjectListSP m_arguments;
47 };
48 
49 /// \class StackFrameRecognizer
50 ///
51 /// A base class for frame recognizers. Subclasses (actual frame recognizers)
52 /// should implement RecognizeFrame to provide a RecognizedStackFrame for a
53 /// given stack frame.
54 
56  : public std::enable_shared_from_this<StackFrameRecognizer> {
57 public:
58  virtual lldb::RecognizedStackFrameSP RecognizeFrame(
59  lldb::StackFrameSP frame) {
60  return lldb::RecognizedStackFrameSP();
61  };
62  virtual std::string GetName() {
63  return "";
64  }
65 
66  virtual ~StackFrameRecognizer() = default;
67 };
68 
69 /// \class ScriptedStackFrameRecognizer
70 ///
71 /// Python implementation for frame recognizers. An instance of this class
72 /// tracks a particular Python classobject, which will be asked to recognize
73 /// stack frames.
74 
79 
80 public:
82  const char *pclass);
83  ~ScriptedStackFrameRecognizer() override = default;
84 
85  std::string GetName() override {
86  return GetPythonClassName();
87  }
88 
89  const char *GetPythonClassName() { return m_python_class.c_str(); }
90 
91  lldb::RecognizedStackFrameSP RecognizeFrame(
92  lldb::StackFrameSP frame) override;
93 
94 private:
97  operator=(const ScriptedStackFrameRecognizer &) = delete;
98 };
99 
100 /// Class that provides a registry of known stack frame recognizers.
102 public:
103  void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
104  ConstString module, llvm::ArrayRef<ConstString> symbols,
105  bool first_instruction_only = true);
106 
107  void AddRecognizer(lldb::StackFrameRecognizerSP recognizer,
108  lldb::RegularExpressionSP module,
109  lldb::RegularExpressionSP symbol,
110  bool first_instruction_only = true);
111 
112  void ForEach(std::function<
113  void(uint32_t recognizer_id, std::string recognizer_name,
114  std::string module, llvm::ArrayRef<ConstString> symbols,
115  bool regexp)> const &callback);
116 
117  bool RemoveRecognizerWithID(uint32_t recognizer_id);
118 
119  void RemoveAllRecognizers();
120 
121  lldb::StackFrameRecognizerSP GetRecognizerForFrame(lldb::StackFrameSP frame);
122 
123  lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame);
124 
125 private:
128  lldb::StackFrameRecognizerSP recognizer;
129  bool is_regexp;
131  lldb::RegularExpressionSP module_regexp;
132  std::vector<ConstString> symbols;
133  lldb::RegularExpressionSP symbol_regexp;
135  };
136 
137  std::deque<RegisteredEntry> m_recognizers;
138 };
139 
140 /// \class ValueObjectRecognizerSynthesizedValue
141 ///
142 /// ValueObject subclass that presents the passed ValueObject as a recognized
143 /// value with the specified ValueType. Frame recognizers should return
144 /// instances of this class as the returned objects in GetRecognizedArguments().
145 
147  public:
148  static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type) {
149  return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
150  }
152  lldb::ValueType type)
153  : ValueObject(parent), m_type(type) {
154  SetName(parent.GetName());
155  }
156 
157  llvm::Optional<uint64_t> GetByteSize() override {
158  return m_parent->GetByteSize();
159  }
160  lldb::ValueType GetValueType() const override { return m_type; }
161  bool UpdateValue() override {
162  if (!m_parent->UpdateValueIfNeeded()) return false;
164  return true;
165  }
166  size_t CalculateNumChildren(uint32_t max = UINT32_MAX) override {
167  return m_parent->GetNumChildren(max);
168  }
170  return m_parent->GetCompilerType();
171  }
172  bool IsSynthetic() override { return true; }
173 
174  private:
176 };
177 
178 } // namespace lldb_private
179 
180 #endif // LLDB_TARGET_STACKFRAMERECOGNIZER_H
lldb_private::StackFrameRecognizer
Definition: StackFrameRecognizer.h:55
lldb-public.h
lldb_private::StackFrameRecognizer::~StackFrameRecognizer
virtual ~StackFrameRecognizer()=default
lldb_private::StackFrameRecognizerManager::RecognizeFrame
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
Definition: StackFrameRecognizer.cpp:149
lldb_private::ValueObjectRecognizerSynthesizedValue::GetValueType
lldb::ValueType GetValueType() const override
Definition: StackFrameRecognizer.h:160
lldb_private::ValueObject::GetValue
const Value & GetValue() const
Definition: ValueObject.h:497
lldb_private::StackFrameRecognizerManager::RegisteredEntry::module_regexp
lldb::RegularExpressionSP module_regexp
Definition: StackFrameRecognizer.h:131
lldb_private::ValueObjectRecognizerSynthesizedValue::IsSynthetic
bool IsSynthetic() override
Definition: StackFrameRecognizer.h:172
StructuredData.h
lldb_private::ValueObjectRecognizerSynthesizedValue::GetCompilerTypeImpl
CompilerType GetCompilerTypeImpl() override
Definition: StackFrameRecognizer.h:169
lldb_private::ScriptedStackFrameRecognizer::m_python_class
std::string m_python_class
Definition: StackFrameRecognizer.h:78
lldb_private::ValueObjectRecognizerSynthesizedValue::Create
static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type)
Definition: StackFrameRecognizer.h:148
lldb_private::RecognizedStackFrame::GetStopDescription
std::string GetStopDescription()
Definition: StackFrameRecognizer.h:42
lldb_private::ScriptedStackFrameRecognizer::m_python_object_sp
lldb_private::StructuredData::ObjectSP m_python_object_sp
Definition: StackFrameRecognizer.h:77
lldb_private::ValueObjectRecognizerSynthesizedValue
Definition: StackFrameRecognizer.h:146
lldb_private::StackFrameRecognizerManager
Class that provides a registry of known stack frame recognizers.
Definition: StackFrameRecognizer.h:101
lldb_private::StackFrameRecognizerManager::GetRecognizerForFrame
lldb::StackFrameRecognizerSP GetRecognizerForFrame(lldb::StackFrameSP frame)
Definition: StackFrameRecognizer.cpp:108
lldb_private::ScriptedStackFrameRecognizer::operator=
const ScriptedStackFrameRecognizer & operator=(const ScriptedStackFrameRecognizer &)=delete
lldb_private::StackFrameRecognizerManager::RegisteredEntry::first_instruction_only
bool first_instruction_only
Definition: StackFrameRecognizer.h:134
lldb_private::ValueObjectRecognizerSynthesizedValue::UpdateValue
bool UpdateValue() override
Definition: StackFrameRecognizer.h:161
lldb_private::ScriptedStackFrameRecognizer::RecognizeFrame
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame) override
Definition: StackFrameRecognizer.cpp:34
lldb-private-forward.h
lldb_private::StackFrameRecognizerManager::m_recognizers
std::deque< RegisteredEntry > m_recognizers
Definition: StackFrameRecognizer.h:137
lldb_private::StackFrameRecognizerManager::ForEach
void ForEach(std::function< void(uint32_t recognizer_id, std::string recognizer_name, std::string module, llvm::ArrayRef< ConstString > symbols, bool regexp)> const &callback)
Definition: StackFrameRecognizer.cpp:66
lldb_private::StackFrameRecognizerManager::RemoveAllRecognizers
void RemoveAllRecognizers()
Definition: StackFrameRecognizer.cpp:103
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::ValueObjectRecognizerSynthesizedValue::CalculateNumChildren
size_t CalculateNumChildren(uint32_t max=UINT32_MAX) override
Should only be called by ValueObject::GetNumChildren().
Definition: StackFrameRecognizer.h:166
lldb_private::ValueObjectRecognizerSynthesizedValue::m_type
lldb::ValueType m_type
Definition: StackFrameRecognizer.h:175
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StackFrameRecognizer::RecognizeFrame
virtual lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
Definition: StackFrameRecognizer.h:58
lldb_private::ValueObject::UpdateValueIfNeeded
bool UpdateValueIfNeeded(bool update_format=true)
Definition: ValueObject.cpp:111
lldb_private::RecognizedStackFrame::m_arguments
lldb::ValueObjectListSP m_arguments
Definition: StackFrameRecognizer.h:45
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::StackFrameRecognizerManager::RegisteredEntry::recognizer_id
uint32_t recognizer_id
Definition: StackFrameRecognizer.h:127
lldb_private::StackFrameRecognizerManager::RegisteredEntry::module
ConstString module
Definition: StackFrameRecognizer.h:130
VariableList.h
lldb_private::ValueObject::SetName
void SetName(ConstString name)
Change the name of the current ValueObject.
Definition: ValueObject.h:560
ValueObject.h
lldb_private::RecognizedStackFrame::m_stop_desc
std::string m_stop_desc
Definition: StackFrameRecognizer.h:46
lldb_private::ScriptedStackFrameRecognizer::m_interpreter
lldb_private::ScriptInterpreter * m_interpreter
Definition: StackFrameRecognizer.h:76
lldb_private::StackFrameRecognizerManager::AddRecognizer
void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, ConstString module, llvm::ArrayRef< ConstString > symbols, bool first_instruction_only=true)
lldb_private::ScriptedStackFrameRecognizer
Definition: StackFrameRecognizer.h:75
lldb_private::StackFrameRecognizerManager::RegisteredEntry::symbol_regexp
lldb::RegularExpressionSP symbol_regexp
Definition: StackFrameRecognizer.h:133
lldb_private::ValueObject::GetNumChildren
size_t GetNumChildren(uint32_t max=UINT32_MAX)
Definition: ValueObject.cpp:496
lldb_private::ScriptedStackFrameRecognizer::ScriptedStackFrameRecognizer
ScriptedStackFrameRecognizer(lldb_private::ScriptInterpreter *interpreter, const char *pclass)
Definition: StackFrameRecognizer.cpp:26
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::StackFrameRecognizerManager::RegisteredEntry::symbols
std::vector< ConstString > symbols
Definition: StackFrameRecognizer.h:132
lldb_private::ValueObject::GetName
ConstString GetName() const
Definition: ValueObject.h:467
lldb::ValueType
ValueType
Definition: lldb-enumerations.h:315
lldb_private::RecognizedStackFrame::GetMostRelevantFrame
virtual lldb::StackFrameSP GetMostRelevantFrame()
Definition: StackFrameRecognizer.h:39
lldb_private::StackFrameRecognizerManager::RegisteredEntry::is_regexp
bool is_regexp
Definition: StackFrameRecognizer.h:129
uint32_t
lldb_private::ScriptedStackFrameRecognizer::GetPythonClassName
const char * GetPythonClassName()
Definition: StackFrameRecognizer.h:89
lldb_private::RecognizedStackFrame::~RecognizedStackFrame
virtual ~RecognizedStackFrame()=default
lldb_private::RecognizedStackFrame::GetRecognizedArguments
virtual lldb::ValueObjectListSP GetRecognizedArguments()
Definition: StackFrameRecognizer.h:33
lldb_private::ValueObject::m_value
Value m_value
Definition: ValueObject.h:852
lldb_private::ValueObject::m_parent
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
Definition: ValueObject.h:840
lldb_private::ScriptedStackFrameRecognizer::GetName
std::string GetName() override
Definition: StackFrameRecognizer.h:85
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::ValueObject::GetCompilerType
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb_private::RecognizedStackFrame
Definition: StackFrameRecognizer.h:30
lldb_private::StackFrameRecognizerManager::RegisteredEntry::recognizer
lldb::StackFrameRecognizerSP recognizer
Definition: StackFrameRecognizer.h:128
StopInfo.h
lldb_private::StackFrameRecognizerManager::RemoveRecognizerWithID
bool RemoveRecognizerWithID(uint32_t recognizer_id)
Definition: StackFrameRecognizer.cpp:89
lldb_private::ScriptedStackFrameRecognizer::~ScriptedStackFrameRecognizer
~ScriptedStackFrameRecognizer() override=default
lldb_private::ValueObjectRecognizerSynthesizedValue::ValueObjectRecognizerSynthesizedValue
ValueObjectRecognizerSynthesizedValue(ValueObject &parent, lldb::ValueType type)
Definition: StackFrameRecognizer.h:151
lldb_private::ScriptInterpreter
Definition: ScriptInterpreter.h:126
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ValueObjectRecognizerSynthesizedValue::GetByteSize
llvm::Optional< uint64_t > GetByteSize() override
Definition: StackFrameRecognizer.h:157
lldb_private::StackFrameRecognizerManager::RegisteredEntry
Definition: StackFrameRecognizer.h:126
ValueObjectList.h
lldb_private::StackFrameRecognizer::GetName
virtual std::string GetName()
Definition: StackFrameRecognizer.h:62
lldb_private::RecognizedStackFrame::GetExceptionObject
virtual lldb::ValueObjectSP GetExceptionObject()
Definition: StackFrameRecognizer.h:36
lldb_private::ValueObject::GetByteSize
virtual llvm::Optional< uint64_t > GetByteSize()=0