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 <cstdint>
21#include <deque>
22#include <optional>
23#include <vector>
24
25namespace lldb_private {
26
27/// \class RecognizedStackFrame
28///
29/// This class provides extra information about a stack frame that was
30/// provided by a specific stack frame recognizer. Right now, this class only
31/// holds recognized arguments (via GetRecognizedArguments).
33 : public std::enable_shared_from_this<RecognizedStackFrame> {
34public:
35 virtual ~RecognizedStackFrame() = default;
36
43 virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; }
44
45 std::string GetStopDescription() { return m_stop_desc; }
46 /// Controls whether this frame should be filtered out when
47 /// displaying backtraces, for example.
48 virtual bool ShouldHide() { return false; }
49
50 virtual lldb::ThreadPlanSP GetStepThroughPlan() { return {}; }
51
52protected:
54 std::string m_stop_desc;
55};
56
57/// \class StackFrameRecognizer
58///
59/// A base class for frame recognizers. Subclasses (actual frame recognizers)
60/// should implement RecognizeFrame to provide a RecognizedStackFrame for a
61/// given stack frame.
63 : public std::enable_shared_from_this<StackFrameRecognizer> {
64public:
69 virtual std::string GetName() {
70 return "";
71 }
72
73 virtual ~StackFrameRecognizer() = default;
74};
75
76/// \class ScriptedStackFrameRecognizer
77///
78/// Python implementation for frame recognizers. An instance of this class
79/// tracks a particular Python classobject, which will be asked to recognize
80/// stack frames.
105
106/// Class that provides a registry of known stack frame recognizers.
108public:
109 /// Add a new recognizer that triggers on a given symbol name.
110 ///
111 /// \param symbol_mangling controls whether the symbol name should be
112 /// compared to the mangled or demangled name.
114 ConstString module, llvm::ArrayRef<ConstString> symbols,
115 Mangled::NamePreference symbol_mangling,
116 bool first_instruction_only = true);
117
118 /// Add a new recognizer that triggers on a symbol regex.
119 ///
120 /// \param symbol_mangling controls whether the regex should apply
121 /// to the mangled or demangled name.
125 Mangled::NamePreference symbol_mangling,
126 bool first_instruction_only = true);
127
128 void
129 ForEach(std::function<void(uint32_t recognizer_id, bool enabled,
130 std::string recognizer_name, std::string module,
131 llvm::ArrayRef<ConstString> symbols,
132 Mangled::NamePreference name_preference,
133 bool regexp)> const &callback);
134
135 bool SetEnabledForID(uint32_t recognizer_id, bool enabled);
136 bool RemoveRecognizerWithID(uint32_t recognizer_id);
137
139
141
143 /// Returns a number that changes whenever the list of recognizers
144 /// has been modified.
145 uint16_t GetGeneration() const { return m_generation; }
146
147private:
148 /// Increase the generation counter.
149 void BumpGeneration();
150
163
164 std::deque<RegisteredEntry> m_recognizers;
165 uint16_t m_generation = 0;
166};
167
168/// \class ValueObjectRecognizerSynthesizedValue
169///
170/// ValueObject subclass that presents the passed ValueObject as a recognized
171/// value with the specified ValueType. Frame recognizers should return
172/// instances of this class as the returned objects in GetRecognizedArguments().
174 public:
176 return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
177 }
179 lldb::ValueType type)
180 : ValueObject(parent), m_type(type) {
181 SetName(parent.GetName());
182 }
183
184 llvm::Expected<uint64_t> GetByteSize() override {
185 return m_parent->GetByteSize();
186 }
187 lldb::ValueType GetValueType() const override { return m_type; }
188 bool UpdateValue() override {
189 if (!m_parent->UpdateValueIfNeeded()) return false;
190 m_value = m_parent->GetValue();
191 return true;
192 }
193 llvm::Expected<uint32_t>
194 CalculateNumChildren(uint32_t max = UINT32_MAX) override {
195 return m_parent->GetNumChildren(max);
196 }
198 return m_parent->GetCompilerType();
199 }
200
201 private:
203};
204
205} // namespace lldb_private
206
207#endif // LLDB_TARGET_STACKFRAMERECOGNIZER_H
Generic representation of a type in a programming language.
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::ThreadPlanSP GetStepThroughPlan()
virtual bool ShouldHide()
Controls whether this frame should be filtered out when displaying backtraces, for example.
virtual lldb::ValueObjectSP GetExceptionObject()
virtual lldb::StackFrameSP GetMostRelevantFrame()
virtual ~RecognizedStackFrame()=default
ScriptedStackFrameRecognizer(lldb_private::ScriptInterpreter *interpreter, const char *pclass)
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame) override
ScriptedStackFrameRecognizer(const ScriptedStackFrameRecognizer &)=delete
lldb::ScriptedStackFrameRecognizerInterfaceSP m_interface_sp
const ScriptedStackFrameRecognizer & operator=(const ScriptedStackFrameRecognizer &)=delete
Class that provides a registry of known stack frame recognizers.
void BumpGeneration()
Increase the generation counter.
void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, ConstString module, llvm::ArrayRef< ConstString > symbols, Mangled::NamePreference symbol_mangling, bool first_instruction_only=true)
Add a new recognizer that triggers on a given symbol name.
void ForEach(std::function< void(uint32_t recognizer_id, bool enabled, std::string recognizer_name, std::string module, llvm::ArrayRef< ConstString > symbols, Mangled::NamePreference name_preference, bool regexp)> const &callback)
lldb::StackFrameRecognizerSP GetRecognizerForFrame(lldb::StackFrameSP frame)
lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
bool RemoveRecognizerWithID(uint32_t recognizer_id)
bool SetEnabledForID(uint32_t recognizer_id, bool enabled)
uint16_t GetGeneration() const
Returns a number that changes whenever the list of recognizers has been modified.
A base class for frame recognizers.
virtual ~StackFrameRecognizer()=default
virtual lldb::RecognizedStackFrameSP RecognizeFrame(lldb::StackFrameSP frame)
ValueObjectRecognizerSynthesizedValue(ValueObject &parent, lldb::ValueType type)
llvm::Expected< uint32_t > CalculateNumChildren(uint32_t max=UINT32_MAX) override
Should only be called by ValueObject::GetNumChildren().
llvm::Expected< uint64_t > GetByteSize() override
static lldb::ValueObjectSP Create(ValueObject &parent, lldb::ValueType type)
ValueObject(ExecutionContextScope *exe_scope, ValueObjectManager &manager, AddressType child_ptr_or_ref_addr_type=eAddressTypeLoad)
Use this constructor to create a "root variable object".
ValueObject * m_parent
The parent value object, or nullptr if this has no parent.
void SetName(llvm::StringRef name)
Change the name of the current ValueObject.
ConstString GetName() const
#define UINT32_MAX
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::RegularExpression > RegularExpressionSP
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP
std::shared_ptr< lldb_private::StackFrameRecognizer > StackFrameRecognizerSP
std::shared_ptr< lldb_private::ScriptedStackFrameRecognizerInterface > ScriptedStackFrameRecognizerInterfaceSP