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"
18#include "lldb/lldb-private.h"
19#include <optional>
20
21namespace lldb_private {
22
23/// \class BreakpointResolver BreakpointResolver.h
24/// "lldb/Breakpoint/BreakpointResolver.h" This class works with SearchFilter
25/// to resolve logical breakpoints to their of concrete breakpoint locations.
26
27/// General Outline:
28/// The BreakpointResolver is a Searcher. In that protocol, the SearchFilter
29/// asks the question "At what depth of the symbol context descent do you want
30/// your callback to get called?" of the filter. The resolver answers this
31/// question (in the GetDepth method) and provides the resolution callback.
32/// Each Breakpoint has a BreakpointResolver, and it calls either
33/// ResolveBreakpoint or ResolveBreakpointInModules to tell it to look for new
34/// breakpoint locations.
35
37 friend class Breakpoint;
38
39public:
40 /// The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint
41 /// to make sense. It can be constructed without a breakpoint, but you have
42 /// to call SetBreakpoint before ResolveBreakpoint.
43 ///
44 /// \param[in] bkpt
45 /// The breakpoint that owns this resolver.
46 /// \param[in] resolverType
47 /// The concrete breakpoint resolver type for this breakpoint.
49 unsigned char resolverType,
50 lldb::addr_t offset = 0);
51
52 /// The Destructor is virtual, all significant breakpoint resolvers derive
53 /// from this class.
55
56 /// This sets the breakpoint for this resolver.
57 ///
58 /// \param[in] bkpt
59 /// The breakpoint that owns this resolver.
60 void SetBreakpoint(const lldb::BreakpointSP &bkpt);
61
62 /// This gets the breakpoint for this resolver.
64 auto breakpoint_sp = m_breakpoint.expired() ? lldb::BreakpointSP() :
65 m_breakpoint.lock();
66 assert(breakpoint_sp);
67 return breakpoint_sp;
68 }
69
70 /// This updates the offset for this breakpoint. All the locations
71 /// currently set for this breakpoint will have their offset adjusted when
72 /// this is called.
73 ///
74 /// \param[in] offset
75 /// The offset to add to all locations.
76 void SetOffset(lldb::addr_t offset);
77
78 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
113 }
114
115 static const char *GetSerializationKey() { return "BKPTResolver"; }
116
117 static const char *GetSerializationSubclassKey() { return "Type"; }
118
119 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
120
123
124 /// An enumeration for keeping track of the concrete subclass that is
125 /// actually instantiated. Values of this enumeration are kept in the
126 /// BreakpointResolver's SubclassID field. They are used for concrete type
127 /// identification.
129 FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
130 AddressResolver, // This is an instance of BreakpointResolverAddress
131 NameResolver, // This is an instance of BreakpointResolverName
137 };
138
139 // Translate the Ty to name for serialization, the "+2" is one for size vrs.
140 // index, and one for UnknownResolver.
141 static const char *g_ty_to_name[LastKnownResolverType + 2];
142
143 /// getResolverID - Return an ID for the concrete type of this object. This
144 /// is used to implement the LLVM classof checks. This should not be used
145 /// for any other purpose, as the values may change as LLDB evolves.
146 unsigned getResolverID() const { return SubclassID; }
147
151 else
152 return (enum ResolverTy)SubclassID;
153 }
154
155 const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
156
157 static const char *ResolverTyToName(enum ResolverTy);
158
159 static ResolverTy NameToResolverTy(llvm::StringRef name);
160
163
164protected:
165 // Used for serializing resolver options:
166 // The options in this enum and the strings in the g_option_names must be
167 // kept in sync.
168 enum class OptionNames : uint32_t {
169 AddressOffset = 0,
171 FileName,
172 Inlines,
175 Column,
178 Offset,
187 };
188 static const char
190
191 virtual void NotifyBreakpointSet() {};
192
193public:
194 static const char *GetKey(OptionNames enum_value) {
195 return g_option_names[static_cast<uint32_t>(enum_value)];
196 }
197
198protected:
199 /// Takes a symbol context list of matches which supposedly represent the
200 /// same file and line number in a CU, and find the nearest actual line
201 /// number that matches, and then filter down the matching addresses to
202 /// unique entries, and skip the prologue if asked to do so, and then set
203 /// breakpoint locations in this breakpoint for all the resultant addresses.
204 /// When \p column is nonzero the \p line and \p column args are used to
205 /// filter the results to find the first breakpoint >= (line, column).
207 bool skip_prologue, llvm::StringRef log_ident,
208 uint32_t line = 0,
209 std::optional<uint16_t> column = std::nullopt);
211 const char *) = delete;
212
214 bool *new_location = nullptr);
215
216private:
217 /// Helper for \p SetSCMatchesByLine.
218 void AddLocation(SearchFilter &filter, const SymbolContext &sc,
219 bool skip_prologue, llvm::StringRef log_ident);
220
221 lldb::BreakpointWP m_breakpoint; // This is the breakpoint we add locations to.
222 lldb::addr_t m_offset; // A random offset the user asked us to add to any
223 // breakpoints we set.
224
225 // Subclass identifier (for llvm isa/dyn_cast)
226 const unsigned char SubclassID;
229};
230
231} // namespace lldb_private
232
233#endif // LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition: Address.h:62
General Outline: The BreakpointResolver is a Searcher.
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.
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)
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 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,...
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:81
This class finds address for source file and line.
A collection class for Module objects.
Definition: ModuleList.h:103
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
An error handling class.
Definition: Status.h:44
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.
Definition: SymbolContext.h:34
A class that represents a running process on the host machine.
std::weak_ptr< lldb_private::Breakpoint > BreakpointWP
Definition: lldb-forward.h:319
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
Definition: lldb-forward.h:325
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
Definition: lldb-forward.h:321
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
Definition: lldb-forward.h:318
uint64_t addr_t
Definition: lldb-types.h:80