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.
48 BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType,
49 lldb::addr_t offset = 0,
50 bool offset_is_insn_count = false);
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; }
80
81 /// In response to this method the resolver scans all the modules in the
82 /// breakpoint's target, and adds any new locations it finds.
83 ///
84 /// \param[in] filter
85 /// The filter that will manage the search for this resolver.
86 virtual void ResolveBreakpoint(SearchFilter &filter);
87
88 /// In response to this method the resolver scans the modules in the module
89 /// list \a modules, and adds any new locations it finds.
90 ///
91 /// \param[in] filter
92 /// The filter that will manage the search for this resolver.
93 virtual void ResolveBreakpointInModules(SearchFilter &filter,
94 ModuleList &modules);
95
96 /// Prints a canonical description for the breakpoint to the stream \a s.
97 ///
98 /// \param[in] s
99 /// Stream to which the output is copied.
100 void GetDescription(Stream *s) override = 0;
101
102 /// Standard "Dump" method. At present it does nothing.
103 virtual void Dump(Stream *s) const = 0;
104
105 /// This section handles serializing and deserializing from StructuredData
106 /// objects.
107
110 Status &error);
111
115
116 /// The resolver_sp won't have had its breakpoint set by the time we are
117 /// checking the Override, but it might need to access the Target, so we pass
118 /// that in here.
119 virtual bool OverridesResolver(Target &target,
120 lldb::BreakpointResolverSP resolver_sp) {
121 return false;
122 }
123
124 static const char *GetSerializationKey() { return "BKPTResolver"; }
125
126 static const char *GetSerializationSubclassKey() { return "Type"; }
127
128 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
129
132
133 /// An enumeration for keeping track of the concrete subclass that is
134 /// actually instantiated. Values of this enumeration are kept in the
135 /// BreakpointResolver's SubclassID field. They are used for concrete type
136 /// identification.
138 FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
139 AddressResolver, // This is an instance of BreakpointResolverAddress
140 NameResolver, // This is an instance of BreakpointResolverName
146 };
147
148 // Translate the Ty to name for serialization, the "+2" is one for size vrs.
149 // index, and one for UnknownResolver.
150 static const char *g_ty_to_name[LastKnownResolverType + 2];
151
152 /// getResolverID - Return an ID for the concrete type of this object. This
153 /// is used to implement the LLVM classof checks. This should not be used
154 /// for any other purpose, as the values may change as LLDB evolves.
155 unsigned getResolverID() const { return SubclassID; }
156
162
163 const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
164
165 static const char *ResolverTyToName(enum ResolverTy);
166
167 static ResolverTy NameToResolverTy(llvm::StringRef name);
168
171
172protected:
173 // Used for serializing resolver options:
174 // The options in this enum and the strings in the g_option_names must be
175 // kept in sync.
196 static const char
198
199 virtual void NotifyBreakpointSet() {};
200
201public:
202 static const char *GetKey(OptionNames enum_value) {
203 return g_option_names[static_cast<uint32_t>(enum_value)];
204 }
205
206protected:
207 /// Takes a symbol context list of matches which supposedly represent the
208 /// same file and line number in a CU, and find the nearest actual line
209 /// number that matches, and then filter down the matching addresses to
210 /// unique entries, and skip the prologue if asked to do so, and then set
211 /// breakpoint locations in this breakpoint for all the resultant addresses.
212 /// When \p column is nonzero the \p line and \p column args are used to
213 /// filter the results to find the first breakpoint >= (line, column).
215 bool skip_prologue, llvm::StringRef log_ident,
216 uint32_t line = 0,
217 std::optional<uint16_t> column = std::nullopt);
219 const char *) = delete;
220
222 bool *new_location = nullptr);
223
224private:
225 /// Helper for \p SetSCMatchesByLine.
226 void AddLocation(SearchFilter &filter, const SymbolContext &sc,
227 bool skip_prologue, llvm::StringRef log_ident);
228
229 lldb::BreakpointWP m_breakpoint; // This is the breakpoint we add locations to.
230 lldb::addr_t m_offset; // A random offset the user asked us to add to any
231 // breakpoints we set.
232 bool m_offset_is_insn_count; // Use the offset as an instruction count
233 // instead of an address offset.
234
235 // Subclass identifier (for llvm isa/dyn_cast)
236 const unsigned char SubclassID;
239};
240
241} // namespace lldb_private
242
243#endif // LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
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)
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,...
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