LLDB mainline
BreakpointResolver.h
Go to the documentation of this file.
1//===-- BreakpointResolver.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_BREAKPOINT_BREAKPOINTRESOLVER_H
10#define LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
11
13#include "lldb/Core/Address.h"
17#include "lldb/lldb-private.h"
18#include <optional>
19
20namespace lldb_private {
21
22/// \class BreakpointResolver BreakpointResolver.h
23/// "lldb/Breakpoint/BreakpointResolver.h" This class works with SearchFilter
24/// to resolve logical breakpoints to their of concrete breakpoint locations.
25
26/// General Outline:
27/// The BreakpointResolver is a Searcher. In that protocol, the SearchFilter
28/// asks the question "At what depth of the symbol context descent do you want
29/// your callback to get called?" of the filter. The resolver answers this
30/// question (in the GetDepth method) and provides the resolution callback.
31/// Each Breakpoint has a BreakpointResolver, and it calls either
32/// ResolveBreakpoint or ResolveBreakpointInModules to tell it to look for new
33/// breakpoint locations.
34
36 friend class Breakpoint;
37
38public:
39 /// The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint
40 /// to make sense. It can be constructed without a breakpoint, but you have
41 /// to call SetBreakpoint before ResolveBreakpoint.
42 ///
43 /// \param[in] bkpt
44 /// The breakpoint that owns this resolver.
45 /// \param[in] resolverType
46 /// The concrete breakpoint resolver type for this breakpoint.
47 BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType,
48 lldb::addr_t offset = 0,
49 bool offset_is_insn_count = false);
50
51 /// The Destructor is virtual, all significant breakpoint resolvers derive
52 /// from this class.
54
55 /// This sets the breakpoint for this resolver.
56 ///
57 /// \param[in] bkpt
58 /// The breakpoint that owns this resolver.
59 void SetBreakpoint(const lldb::BreakpointSP &bkpt);
60
61 /// This gets the breakpoint for this resolver.
63 auto breakpoint_sp = m_breakpoint.expired() ? lldb::BreakpointSP() :
64 m_breakpoint.lock();
65 assert(breakpoint_sp);
66 return breakpoint_sp;
67 }
68
69 /// This updates the offset for this breakpoint. All the locations
70 /// currently set for this breakpoint will have their offset adjusted when
71 /// this is called.
72 ///
73 /// \param[in] offset
74 /// The offset to add to all locations.
75 void SetOffset(lldb::addr_t offset);
76
77 lldb::addr_t GetOffset() const { return m_offset; }
79
80 /// In response to this method the resolver scans all the modules in the
81 /// breakpoint's target, and adds any new locations it finds.
82 ///
83 /// \param[in] filter
84 /// The filter that will manage the search for this resolver.
85 virtual void ResolveBreakpoint(SearchFilter &filter);
86
87 /// In response to this method the resolver scans the modules in the module
88 /// list \a modules, and adds any new locations it finds.
89 ///
90 /// \param[in] filter
91 /// The filter that will manage the search for this resolver.
92 virtual void ResolveBreakpointInModules(SearchFilter &filter,
93 ModuleList &modules);
94
95 /// Prints a canonical description for the breakpoint to the stream \a s.
96 ///
97 /// \param[in] s
98 /// Stream to which the output is copied.
99 void GetDescription(Stream *s) override = 0;
100
101 /// Standard "Dump" method. At present it does nothing.
102 virtual void Dump(Stream *s) const = 0;
103
104 /// This section handles serializing and deserializing from StructuredData
105 /// objects.
106
109 Status &error);
110
114
115 /// The resolver_sp won't have had its breakpoint set by the time we are
116 /// checking the Override, but it might need to access the Target, so we pass
117 /// that in here.
118 virtual bool OverridesResolver(Target &target,
119 lldb::BreakpointResolverSP resolver_sp) {
120 return false;
121 }
122
123 static const char *GetSerializationKey() { return "BKPTResolver"; }
124
125 static const char *GetSerializationSubclassKey() { return "Type"; }
126
127 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
128
131
132 /// An enumeration for keeping track of the concrete subclass that is
133 /// actually instantiated. Values of this enumeration are kept in the
134 /// BreakpointResolver's SubclassID field. They are used for concrete type
135 /// identification.
137 FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
138 AddressResolver, // This is an instance of BreakpointResolverAddress
139 NameResolver, // This is an instance of BreakpointResolverName
145 };
146
147 // Translate the Ty to name for serialization, the "+2" is one for size vrs.
148 // index, and one for UnknownResolver.
149 static const char *g_ty_to_name[LastKnownResolverType + 2];
150
151 /// getResolverID - Return an ID for the concrete type of this object. This
152 /// is used to implement the LLVM classof checks. This should not be used
153 /// for any other purpose, as the values may change as LLDB evolves.
154 unsigned getResolverID() const { return SubclassID; }
155
156 /// This checks whether the resolver's type matches the enum
157 /// lldb::BreakpointResolverType.
158 bool ResolverTyInMask(uint64_t mask);
159
160 static bool TypeMaskIsValid(uint64_t mask);
161
167
168 uint64_t MaskForResolverTy();
169
170 static std::string DescribeMask(uint64_t mask);
171 const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
172
173 static const char *ResolverTyToName(enum ResolverTy);
174
175 static ResolverTy NameToResolverTy(llvm::StringRef name);
176
179
180protected:
181 // Used for serializing resolver options:
182 // The options in this enum and the strings in the g_option_names must be
183 // kept in sync.
204 static const char
206
207 virtual void NotifyBreakpointSet() {};
208
209public:
210 static const char *GetKey(OptionNames enum_value) {
211 return g_option_names[static_cast<uint32_t>(enum_value)];
212 }
213
214protected:
215 /// Takes a symbol context list of matches which supposedly represent the
216 /// same file and line number in a CU, and find the nearest actual line
217 /// number that matches, and then filter down the matching addresses to
218 /// unique entries, and skip the prologue if asked to do so, and then set
219 /// breakpoint locations in this breakpoint for all the resultant addresses.
220 /// When \p column is nonzero the \p line and \p column args are used to
221 /// filter the results to find the first breakpoint >= (line, column).
223 bool skip_prologue, llvm::StringRef log_ident,
224 uint32_t line = 0,
225 std::optional<uint16_t> column = std::nullopt);
227 const char *) = delete;
228
230 bool *new_location = nullptr);
231
232private:
233 /// Helper for \p SetSCMatchesByLine.
234 void AddLocation(SearchFilter &filter, const SymbolContext &sc,
235 bool skip_prologue, llvm::StringRef log_ident);
236
237 lldb::BreakpointWP m_breakpoint; // This is the breakpoint we add locations to.
238 lldb::addr_t m_offset; // A random offset the user asked us to add to any
239 // breakpoints we set.
240 bool m_offset_is_insn_count; // Use the offset as an instruction count
241 // instead of an address offset.
242
243 // Subclass identifier (for llvm isa/dyn_cast)
244 const unsigned char SubclassID;
247};
248
249} // namespace lldb_private
250
251#endif // LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
bool ResolverTyInMask(uint64_t mask)
This checks whether the resolver's type matches the enum lldb::BreakpointResolverType.
void GetDescription(Stream *s) override=0
Prints a canonical description for the breakpoint to the stream s.
virtual lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP &breakpoint)=0
void SetBreakpoint(const lldb::BreakpointSP &bkpt)
This sets the breakpoint for this resolver.
~BreakpointResolver() override
The Destructor is virtual, all significant breakpoint resolvers derive from this class.
lldb::BreakpointLocationSP AddLocation(Address loc_addr, bool *new_location=nullptr)
static const char * GetKey(OptionNames enum_value)
static lldb::BreakpointResolverSP CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict, Status &error)
This section handles serializing and deserializing from StructuredData objects.
static ResolverTy NameToResolverTy(llvm::StringRef name)
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
virtual void Dump(Stream *s) const =0
Standard "Dump" method. At present it does nothing.
virtual bool OverridesResolver(Target &target, lldb::BreakpointResolverSP resolver_sp)
The resolver_sp won't have had its breakpoint set by the time we are checking the Override,...
ResolverTy
An enumeration for keeping track of the concrete subclass that is actually instantiated.
void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue, llvm::StringRef log_ident, uint32_t line=0, std::optional< uint16_t > column=std::nullopt)
Takes a symbol context list of matches which supposedly represent the same file and line number in a ...
static const char * GetSerializationKey()
void SetSCMatchesByLine(SearchFilter &, SymbolContextList &, bool, const char *)=delete
lldb::BreakpointSP GetBreakpoint() const
This gets the breakpoint for this resolver.
void SetOffset(lldb::addr_t offset)
This updates the offset for this breakpoint.
static const char * g_option_names[static_cast< uint32_t >(OptionNames::LastOptionName)]
static const char * ResolverTyToName(enum ResolverTy)
static bool TypeMaskIsValid(uint64_t mask)
unsigned getResolverID() const
getResolverID - Return an ID for the concrete type of this object.
virtual StructuredData::ObjectSP SerializeToStructuredData()
const BreakpointResolver & operator=(const BreakpointResolver &)=delete
BreakpointResolver(const BreakpointResolver &)=delete
static std::string DescribeMask(uint64_t mask)
static const char * g_ty_to_name[LastKnownResolverType+2]
static const char * GetSerializationSubclassKey()
virtual void ResolveBreakpointInModules(SearchFilter &filter, ModuleList &modules)
In response to this method the resolver scans the modules in the module list modules,...
static const char * GetSerializationSubclassOptionsKey()
virtual void ResolveBreakpoint(SearchFilter &filter)
In response to this method the resolver scans all the modules in the breakpoint's target,...
BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType, lldb::addr_t offset=0, bool offset_is_insn_count=false)
The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint to make sense.
A collection class for Module objects.
Definition ModuleList.h:125
General Outline: Provides the callback and search depth for the SearchFilter search.
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
Defines a list of symbol context objects.
Defines a symbol context baton that can be handed other debug core functions.
A class that represents a running process on the host machine.
std::weak_ptr< lldb_private::Breakpoint > BreakpointWP
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
uint64_t addr_t
Definition lldb-types.h:80