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
50protected:
52 std::string m_stop_desc;
53};
54
55/// \class StackFrameRecognizer
56///
57/// A base class for frame recognizers. Subclasses (actual frame recognizers)
58/// should implement RecognizeFrame to provide a RecognizedStackFrame for a
59/// given stack frame.
61 : public std::enable_shared_from_this<StackFrameRecognizer> {
62public:
67 virtual std::string GetName() {
68 return "";
69 }
70
71 virtual ~StackFrameRecognizer() = default;
72};
73
74/// \class ScriptedStackFrameRecognizer
75///
76/// Python implementation for frame recognizers. An instance of this class
77/// tracks a particular Python classobject, which will be asked to recognize
78/// stack frames.
104
105/// Class that provides a registry of known stack frame recognizers.
107public:
108 /// Add a new recognizer that triggers on a given symbol name.
109 ///
110 /// \param symbol_mangling controls whether the symbol name should be
111 /// compared to the mangled or demangled name.
113 ConstString module, llvm::ArrayRef<ConstString> symbols,
114 Mangled::NamePreference symbol_mangling,
115 bool first_instruction_only = true);
116
117 /// Add a new recognizer that triggers on a symbol regex.
118 ///
119 /// \param symbol_mangling controls whether the regex should apply
120 /// to the mangled or demangled name.
124 Mangled::NamePreference symbol_mangling,
125 bool first_instruction_only = true);
126
127 void
128 ForEach(std::function<void(uint32_t recognizer_id, bool enabled,
129 std::string recognizer_name, std::string module,
130 llvm::ArrayRef<ConstString> symbols,
131 Mangled::NamePreference name_preference,
132 bool regexp)> const &callback);
133
134 bool SetEnabledForID(uint32_t recognizer_id, bool enabled);
135 bool RemoveRecognizerWithID(uint32_t recognizer_id);
136
138
140
142 /// Returns a number that changes whenever the list of recognizers
143 /// has been modified.
144 uint16_t GetGeneration() const { return m_generation; }
145
146private:
147 /// Increase the generation counter.
148 void BumpGeneration();
149
162
163 std::deque<RegisteredEntry> m_recognizers;
164 uint16_t m_generation = 0;
165};
166
167/// \class ValueObjectRecognizerSynthesizedValue
168///
169/// ValueObject subclass that presents the passed ValueObject as a recognized
170/// value with the specified ValueType. Frame recognizers should return
171/// instances of this class as the returned objects in GetRecognizedArguments().
173 public:
175 return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
176 }
178 lldb::ValueType type)
179 : ValueObject(parent), m_type(type) {
180 SetName(parent.GetName());
181 }
182
183 llvm::Expected<uint64_t> GetByteSize() override {
184 return m_parent->GetByteSize();
185 }
186 lldb::ValueType GetValueType() const override { return m_type; }
187 bool UpdateValue() override {
188 if (!m_parent->UpdateValueIfNeeded()) return false;
189 m_value = m_parent->GetValue();
190 return true;
191 }
192 llvm::Expected<uint32_t>
193 CalculateNumChildren(uint32_t max = UINT32_MAX) override {
194 return m_parent->GetNumChildren(max);
195 }
197 return m_parent->GetCompilerType();
198 }
199 bool IsSynthetic() override { return true; }
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 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_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.
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)
std::shared_ptr< Object > ObjectSP
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(ConstString 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::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