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
18#include "lldb/lldb-public.h"
19
20#include <deque>
21#include <optional>
22#include <vector>
23
24namespace lldb_private {
25
26/// \class RecognizedStackFrame
27///
28/// This class provides extra information about a stack frame that was
29/// provided by a specific stack frame recognizer. Right now, this class only
30/// holds recognized arguments (via GetRecognizedArguments).
31
33 : public std::enable_shared_from_this<RecognizedStackFrame> {
34public:
36 return m_arguments;
37 }
39 return lldb::ValueObjectSP();
40 }
41 virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
42 virtual ~RecognizedStackFrame() = default;
43
44 std::string GetStopDescription() { return m_stop_desc; }
45
46protected:
48 std::string m_stop_desc;
49};
50
51/// \class StackFrameRecognizer
52///
53/// A base class for frame recognizers. Subclasses (actual frame recognizers)
54/// should implement RecognizeFrame to provide a RecognizedStackFrame for a
55/// given stack frame.
56
58 : public std::enable_shared_from_this<StackFrameRecognizer> {
59public:
61 lldb::StackFrameSP frame) {
63 };
64 virtual std::string GetName() {
65 return "";
66 }
67
68 virtual ~StackFrameRecognizer() = default;
69};
70
71/// \class ScriptedStackFrameRecognizer
72///
73/// Python implementation for frame recognizers. An instance of this class
74/// tracks a particular Python classobject, which will be asked to recognize
75/// stack frames.
76
80 std::string m_python_class;
81
82public:
84 const char *pclass);
85 ~ScriptedStackFrameRecognizer() override = default;
86
87 std::string GetName() override {
88 return GetPythonClassName();
89 }
90
91 const char *GetPythonClassName() { return m_python_class.c_str(); }
92
94 lldb::StackFrameSP frame) override;
95
96private:
100};
101
102/// Class that provides a registry of known stack frame recognizers.
104public:
106 ConstString module, llvm::ArrayRef<ConstString> symbols,
107 bool first_instruction_only = true);
108
112 bool first_instruction_only = true);
113
114 void ForEach(std::function<
115 void(uint32_t recognizer_id, std::string recognizer_name,
116 std::string module, llvm::ArrayRef<ConstString> symbols,
117 bool regexp)> const &callback);
118
119 bool RemoveRecognizerWithID(uint32_t recognizer_id);
120
122
124
126
127private:
134 std::vector<ConstString> symbols;
137 };
138
139 std::deque<RegisteredEntry> m_recognizers;
140};
141
142/// \class ValueObjectRecognizerSynthesizedValue
143///
144/// ValueObject subclass that presents the passed ValueObject as a recognized
145/// value with the specified ValueType. Frame recognizers should return
146/// instances of this class as the returned objects in GetRecognizedArguments().
147
149 public:
151 return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
152 }
154 lldb::ValueType type)
155 : ValueObject(parent), m_type(type) {
156 SetName(parent.GetName());
157 }
158
159 std::optional<uint64_t> GetByteSize() override {
160 return m_parent->GetByteSize();
161 }
162 lldb::ValueType GetValueType() const override { return m_type; }
163 bool UpdateValue() override {
164 if (!m_parent->UpdateValueIfNeeded()) return false;
166 return true;
167 }
168 llvm::Expected<uint32_t>
169 CalculateNumChildren(uint32_t max = UINT32_MAX) override {
170 return m_parent->GetNumChildren(max);
171 }
173 return m_parent->GetCompilerType();
174 }
175 bool IsSynthetic() override { return true; }
176
177 private:
179};
180
181} // namespace lldb_private
182
183#endif // LLDB_TARGET_STACKFRAMERECOGNIZER_H
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
This class provides extra information about a stack frame that was provided by a specific stack frame...
virtual lldb::ValueObjectListSP GetRecognizedArguments()
virtual lldb::ValueObjectSP GetExceptionObject()
virtual lldb::StackFrameSP GetMostRelevantFrame()
virtual ~RecognizedStackFrame()=default
Python implementation for frame recognizers.
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame) override
ScriptedStackFrameRecognizer(const ScriptedStackFrameRecognizer &)=delete
lldb_private::StructuredData::ObjectSP m_python_object_sp
const ScriptedStackFrameRecognizer & operator=(const ScriptedStackFrameRecognizer &)=delete
lldb_private::ScriptInterpreter * m_interpreter
Class that provides a registry of known stack frame recognizers.
lldb::StackFrameRecognizerSP GetRecognizerForFrame(lldb::StackFrameSP frame)
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
bool RemoveRecognizerWithID(uint32_t recognizer_id)
void ForEach(std::function< void(uint32_t recognizer_id, std::string recognizer_name, std::string module, llvm::ArrayRef< ConstString > symbols, bool regexp)> const &callback)
std::deque< RegisteredEntry > m_recognizers
void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, ConstString module, llvm::ArrayRef< ConstString > symbols, bool first_instruction_only=true)
A base class for frame recognizers.
virtual ~StackFrameRecognizer()=default
virtual lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
std::shared_ptr< Object > ObjectSP
ValueObject subclass that presents the passed ValueObject as a recognized value with the specified Va...
ValueObjectRecognizerSynthesizedValue(ValueObject &parent, lldb::ValueType type)
llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max=UINT32_MAX) override
Should only be called by ValueObject::GetNumChildren().
static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type)
std::optional< uint64_t > GetByteSize() override
CompilerType GetCompilerType()
Definition: ValueObject.h:352
virtual std::optional< uint64_t > GetByteSize()=0
llvm::Expected< uint32_t > GetNumChildren(uint32_t max=UINT32_MAX)
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
Definition: ValueObject.h:915
bool UpdateValueIfNeeded(bool update_format=true)
void SetName(ConstString name)
Change the name of the current ValueObject.
Definition: ValueObject.h:574
ConstString GetName() const
Definition: ValueObject.h:487
const Value & GetValue() const
Definition: ValueObject.h:511
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:419
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
Definition: lldb-forward.h:400
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:479
std::shared_ptr< lldb_private::RegularExpression > RegularExpressionSP
Definition: lldb-forward.h:394
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP
Definition: lldb-forward.h:483
std::shared_ptr< lldb_private::StackFrameRecognizer > StackFrameRecognizerSP
Definition: lldb-forward.h:423