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 <optional>
21#include <vector>
22
23namespace lldb_private {
24
25/// \class RecognizedStackFrame
26///
27/// This class provides extra information about a stack frame that was
28/// provided by a specific stack frame recognizer. Right now, this class only
29/// holds recognized arguments (via GetRecognizedArguments).
30
32 : public std::enable_shared_from_this<RecognizedStackFrame> {
33public:
35 return m_arguments;
36 }
38 return lldb::ValueObjectSP();
39 }
40 virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
41 virtual ~RecognizedStackFrame() = default;
42
43 std::string GetStopDescription() { return m_stop_desc; }
44
45protected:
47 std::string m_stop_desc;
48};
49
50/// \class StackFrameRecognizer
51///
52/// A base class for frame recognizers. Subclasses (actual frame recognizers)
53/// should implement RecognizeFrame to provide a RecognizedStackFrame for a
54/// given stack frame.
55
57 : public std::enable_shared_from_this<StackFrameRecognizer> {
58public:
60 lldb::StackFrameSP frame) {
62 };
63 virtual std::string GetName() {
64 return "";
65 }
66
67 virtual ~StackFrameRecognizer() = default;
68};
69
70/// \class ScriptedStackFrameRecognizer
71///
72/// Python implementation for frame recognizers. An instance of this class
73/// tracks a particular Python classobject, which will be asked to recognize
74/// stack frames.
75
79 std::string m_python_class;
80
81public:
83 const char *pclass);
84 ~ScriptedStackFrameRecognizer() override = default;
85
86 std::string GetName() override {
87 return GetPythonClassName();
88 }
89
90 const char *GetPythonClassName() { return m_python_class.c_str(); }
91
93 lldb::StackFrameSP frame) override;
94
95private:
99};
100
101/// Class that provides a registry of known stack frame recognizers.
103public:
105 ConstString module, llvm::ArrayRef<ConstString> symbols,
106 bool first_instruction_only = true);
107
111 bool first_instruction_only = true);
112
113 void ForEach(std::function<
114 void(uint32_t recognizer_id, std::string recognizer_name,
115 std::string module, llvm::ArrayRef<ConstString> symbols,
116 bool regexp)> const &callback);
117
118 bool RemoveRecognizerWithID(uint32_t recognizer_id);
119
121
123
125
126private:
133 std::vector<ConstString> symbols;
136 };
137
138 std::deque<RegisteredEntry> m_recognizers;
139};
140
141/// \class ValueObjectRecognizerSynthesizedValue
142///
143/// ValueObject subclass that presents the passed ValueObject as a recognized
144/// value with the specified ValueType. Frame recognizers should return
145/// instances of this class as the returned objects in GetRecognizedArguments().
146
148 public:
150 return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
151 }
153 lldb::ValueType type)
154 : ValueObject(parent), m_type(type) {
155 SetName(parent.GetName());
156 }
157
158 std::optional<uint64_t> GetByteSize() override {
159 return m_parent->GetByteSize();
160 }
161 lldb::ValueType GetValueType() const override { return m_type; }
162 bool UpdateValue() override {
163 if (!m_parent->UpdateValueIfNeeded()) return false;
165 return true;
166 }
167 llvm::Expected<uint32_t>
168 CalculateNumChildren(uint32_t max = UINT32_MAX) override {
169 return m_parent->GetNumChildren(max);
170 }
172 return m_parent->GetCompilerType();
173 }
174 bool IsSynthetic() override { return true; }
175
176 private:
178};
179
180} // namespace lldb_private
181
182#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:835
bool UpdateValueIfNeeded(bool update_format=true)
void SetName(ConstString name)
Change the name of the current ValueObject.
Definition: ValueObject.h:550
ConstString GetName() const
Definition: ValueObject.h:463
const Value & GetValue() const
Definition: ValueObject.h:487
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:412
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
Definition: lldb-forward.h:395
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:472
std::shared_ptr< lldb_private::RegularExpression > RegularExpressionSP
Definition: lldb-forward.h:389
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP
Definition: lldb-forward.h:476
std::shared_ptr< lldb_private::StackFrameRecognizer > StackFrameRecognizerSP
Definition: lldb-forward.h:416