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
38 return m_arguments;
39 }
41 return lldb::ValueObjectSP();
42 }
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:
64 lldb::StackFrameSP frame) {
66 };
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.
82
83 std::string m_python_class;
84
85public:
87 const char *pclass);
88 ~ScriptedStackFrameRecognizer() override = default;
89
90 std::string GetName() override {
91 return GetPythonClassName();
92 }
93
94 const char *GetPythonClassName() { return m_python_class.c_str(); }
95
97 lldb::StackFrameSP frame) override;
98
99private:
103};
104
105/// Class that provides a registry of known stack frame recognizers.
107public:
109 ConstString module, llvm::ArrayRef<ConstString> symbols,
110 bool first_instruction_only = true);
111
115 bool first_instruction_only = true);
116
117 void ForEach(std::function<
118 void(uint32_t recognizer_id, std::string recognizer_name,
119 std::string module, llvm::ArrayRef<ConstString> symbols,
120 bool regexp)> const &callback);
121
122 bool RemoveRecognizerWithID(uint32_t recognizer_id);
123
125
127
129 /// Returns a number that changes whenever the list of recognizers
130 /// has been modified.
131 uint16_t GetGeneration() const { return m_generation; }
132
133private:
134 /// Increase the generation counter.
135 void BumpGeneration();
136
143 std::vector<ConstString> symbols;
146 };
147
148 std::deque<RegisteredEntry> m_recognizers;
149 uint16_t m_generation;
150};
151
152/// \class ValueObjectRecognizerSynthesizedValue
153///
154/// ValueObject subclass that presents the passed ValueObject as a recognized
155/// value with the specified ValueType. Frame recognizers should return
156/// instances of this class as the returned objects in GetRecognizedArguments().
158 public:
160 return (new ValueObjectRecognizerSynthesizedValue(parent, type))->GetSP();
161 }
163 lldb::ValueType type)
164 : ValueObject(parent), m_type(type) {
165 SetName(parent.GetName());
166 }
167
168 std::optional<uint64_t> GetByteSize() override {
169 return m_parent->GetByteSize();
170 }
171 lldb::ValueType GetValueType() const override { return m_type; }
172 bool UpdateValue() override {
173 if (!m_parent->UpdateValueIfNeeded()) return false;
175 return true;
176 }
177 llvm::Expected<uint32_t>
178 CalculateNumChildren(uint32_t max = UINT32_MAX) override {
179 return m_parent->GetNumChildren(max);
180 }
182 return m_parent->GetCompilerType();
183 }
184 bool IsSynthetic() override { return true; }
185
186 private:
188};
189
190} // namespace lldb_private
191
192#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 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
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.
void BumpGeneration()
Increase the generation counter.
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)
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
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:420
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
Definition: lldb-forward.h:401
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:480
std::shared_ptr< lldb_private::RegularExpression > RegularExpressionSP
Definition: lldb-forward.h:395
std::shared_ptr< lldb_private::ValueObjectList > ValueObjectListSP
Definition: lldb-forward.h:484
std::shared_ptr< lldb_private::StackFrameRecognizer > StackFrameRecognizerSP
Definition: lldb-forward.h:424