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
19#include "lldb/lldb-public.h"
20
21#include <cstdint>
22#include <deque>
23#include <optional>
24#include <vector>
25
26namespace lldb_private {
27
28/// \class RecognizedStackFrame
29///
30/// This class provides extra information about a stack frame that was
31/// provided by a specific stack frame recognizer. Right now, this class only
32/// holds recognized arguments (via GetRecognizedArguments).
34 : public std::enable_shared_from_this<RecognizedStackFrame> {
35public:
36 virtual ~RecognizedStackFrame() = default;
37
44 virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; }
45
46 std::string GetStopDescription() { return m_stop_desc; }
47 /// Controls whether this frame should be filtered out when
48 /// displaying backtraces, for example.
49 virtual bool ShouldHide() { return false; }
50
51 virtual lldb::ThreadPlanSP GetStepThroughPlan() { return {}; }
52
53protected:
55 std::string m_stop_desc;
56};
57
58/// \class StackFrameRecognizer
59///
60/// A base class for frame recognizers. Subclasses (actual frame recognizers)
61/// should implement RecognizeFrame to provide a RecognizedStackFrame for a
62/// given stack frame.
64 : public std::enable_shared_from_this<StackFrameRecognizer> {
65public:
70 virtual std::string GetName() {
71 return "";
72 }
73
74 virtual ~StackFrameRecognizer() = default;
75};
76
77/// \class ScriptedStackFrameRecognizer
78///
79/// Python implementation for frame recognizers. An instance of this class
80/// tracks a particular Python classobject, which will be asked to recognize
81/// stack frames.
106
107/// Class that provides a registry of known stack frame recognizers.
109public:
110 /// Add a new recognizer that triggers on a given symbol name.
111 ///
112 /// \param symbol_mangling controls whether the symbol name should be
113 /// compared to the mangled or demangled name.
115 std::string module, std::vector<ConstString> symbols,
116 Mangled::NamePreference symbol_mangling,
117 bool first_instruction_only = true);
118
119 /// Add a new recognizer that triggers on a symbol regex.
120 ///
121 /// \param symbol_mangling controls whether the regex should apply
122 /// to the mangled or demangled name.
126 Mangled::NamePreference symbol_mangling,
127 bool first_instruction_only = true);
128
129 void
130 ForEach(std::function<void(uint32_t recognizer_id, bool enabled,
131 std::string recognizer_name, std::string module,
132 llvm::ArrayRef<ConstString> symbols,
133 Mangled::NamePreference name_preference,
134 bool regexp)> const &callback);
135
136 bool SetEnabledForID(uint32_t recognizer_id, bool enabled);
137 bool RemoveRecognizerWithID(uint32_t recognizer_id);
138
140
142
144 /// Returns a number that changes whenever the list of recognizers
145 /// has been modified.
146 uint16_t GetGeneration() const { return m_generation; }
147
148private:
149 /// Increase the generation counter.
150 void BumpGeneration();
151
164
165 std::deque<RegisteredEntry> m_recognizers;
166 uint16_t m_generation = 0;
167};
168
169/// Frame recognizers should return ValueObjectSynthesizedValue instances as the
170/// returned objects in GetRecognizedArguments().
172
173} // namespace lldb_private
174
175#endif // LLDB_TARGET_STACKFRAMERECOGNIZER_H
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 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)
void AddRecognizer(lldb::StackFrameRecognizerSP recognizer, std::string module, std::vector< ConstString > symbols, Mangled::NamePreference symbol_mangling, bool first_instruction_only=true)
Add a new recognizer that triggers on a given symbol name.
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)
Presents another ValueObject under the given ValueType.
A class that represents a running process on the host machine.
ValueObjectSynthesizedValue ValueObjectRecognizerSynthesizedValue
Frame recognizers should return ValueObjectSynthesizedValue instances as the returned objects in GetR...
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