1 //===-- BreakpointResolver.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_BreakpointResolver_h_
11 #define liblldb_BreakpointResolver_h_
15 // Other libraries and framework includes
17 #include "lldb/Breakpoint/Breakpoint.h"
18 #include "lldb/Breakpoint/BreakpointResolver.h"
19 #include "lldb/Core/Address.h"
20 #include "lldb/Core/ConstString.h"
21 #include "lldb/Core/RegularExpression.h"
22 #include "lldb/Core/SearchFilter.h"
23 #include "lldb/Host/FileSpec.h"
24 #include "lldb/lldb-private.h"
26 namespace lldb_private {
28 //----------------------------------------------------------------------
29 /// @class BreakpointResolver BreakpointResolver.h
30 /// "lldb/Breakpoint/BreakpointResolver.h"
31 /// @brief This class works with SearchFilter to resolve logical breakpoints to
33 /// of concrete breakpoint locations.
34 //----------------------------------------------------------------------
36 //----------------------------------------------------------------------
38 /// The BreakpointResolver is a Searcher. In that protocol,
39 /// the SearchFilter asks the question "At what depth of the symbol context
40 /// descent do you want your callback to get called?" of the filter. The
42 /// answers this question (in the GetDepth method) and provides the resolution
44 /// Each Breakpoint has a BreakpointResolver, and it calls either
46 /// or ResolveBreakpointInModules to tell it to look for new breakpoint
48 //----------------------------------------------------------------------
50 class BreakpointResolver : public Searcher {
51 friend class Breakpoint;
54 //------------------------------------------------------------------
55 /// The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint
56 /// to make sense. It can be constructed without a breakpoint, but you have
58 /// call SetBreakpoint before ResolveBreakpoint.
61 /// The breakpoint that owns this resolver.
62 /// @param[in] resolverType
63 /// The concrete breakpoint resolver type for this breakpoint.
66 /// Returns breakpoint location id.
67 //------------------------------------------------------------------
68 BreakpointResolver(Breakpoint *bkpt, unsigned char resolverType,
69 lldb::addr_t offset = 0);
71 //------------------------------------------------------------------
72 /// The Destructor is virtual, all significant breakpoint resolvers derive
74 //------------------------------------------------------------------
75 ~BreakpointResolver() override;
77 //------------------------------------------------------------------
78 /// This sets the breakpoint for this resolver.
81 /// The breakpoint that owns this resolver.
82 //------------------------------------------------------------------
83 void SetBreakpoint(Breakpoint *bkpt);
85 //------------------------------------------------------------------
86 /// This updates the offset for this breakpoint. All the locations currently
87 /// set for this breakpoint will have their offset adjusted when this is
91 /// The offset to add to all locations.
92 //------------------------------------------------------------------
93 void SetOffset(lldb::addr_t offset);
95 //------------------------------------------------------------------
96 /// This updates the offset for this breakpoint. All the locations currently
97 /// set for this breakpoint will have their offset adjusted when this is
100 /// @param[in] offset
101 /// The offset to add to all locations.
102 //------------------------------------------------------------------
103 lldb::addr_t GetOffset() const { return m_offset; }
105 //------------------------------------------------------------------
106 /// In response to this method the resolver scans all the modules in the
108 /// target, and adds any new locations it finds.
110 /// @param[in] filter
111 /// The filter that will manage the search for this resolver.
112 //------------------------------------------------------------------
113 virtual void ResolveBreakpoint(SearchFilter &filter);
115 //------------------------------------------------------------------
116 /// In response to this method the resolver scans the modules in the module
118 /// \a modules, and adds any new locations it finds.
120 /// @param[in] filter
121 /// The filter that will manage the search for this resolver.
122 //------------------------------------------------------------------
123 virtual void ResolveBreakpointInModules(SearchFilter &filter,
124 ModuleList &modules);
126 //------------------------------------------------------------------
127 /// Prints a canonical description for the breakpoint to the stream \a s.
130 /// Stream to which the output is copied.
131 //------------------------------------------------------------------
132 void GetDescription(Stream *s) override = 0;
134 //------------------------------------------------------------------
135 /// Standard "Dump" method. At present it does nothing.
136 //------------------------------------------------------------------
137 virtual void Dump(Stream *s) const = 0;
139 /// This section handles serializing and deserializing from StructuredData
142 static lldb::BreakpointResolverSP
143 CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict,
146 virtual StructuredData::ObjectSP SerializeToStructuredData() {
147 return StructuredData::ObjectSP();
150 static const char *GetSerializationKey() { return "BKPTResolver"; }
152 static const char *GetSerializationSubclassKey() { return "Type"; }
154 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
156 StructuredData::DictionarySP
157 WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
159 //------------------------------------------------------------------
160 //------------------------------------------------------------------
161 /// An enumeration for keeping track of the concrete subclass that
162 /// is actually instantiated. Values of this enumeration are kept in the
163 /// BreakpointResolver's SubclassID field. They are used for concrete type
166 FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
167 AddressResolver, // This is an instance of BreakpointResolverAddress
168 NameResolver, // This is an instance of BreakpointResolverName
171 LastKnownResolverType = ExceptionResolver,
175 // Translate the Ty to name for serialization,
176 // the "+2" is one for size vrs. index, and one for UnknownResolver.
177 static const char *g_ty_to_name[LastKnownResolverType + 2];
179 //------------------------------------------------------------------
180 /// getResolverID - Return an ID for the concrete type of this object. This
181 /// is used to implement the LLVM classof checks. This should not be used
182 /// for any other purpose, as the values may change as LLDB evolves.
183 unsigned getResolverID() const { return SubclassID; }
185 enum ResolverTy GetResolverTy() {
186 if (SubclassID > ResolverTy::LastKnownResolverType)
187 return ResolverTy::UnknownResolver;
189 return (enum ResolverTy)SubclassID;
192 const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
194 static const char *ResolverTyToName(enum ResolverTy);
196 static ResolverTy NameToResolverTy(const char *name);
198 virtual lldb::BreakpointResolverSP
199 CopyForBreakpoint(Breakpoint &breakpoint) = 0;
202 // Used for serializing resolver options:
203 // The options in this enum and the strings in the
204 // g_option_names must be kept in sync.
205 enum class OptionNames : uint32_t {
222 *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
225 static const char *GetKey(OptionNames enum_value) {
226 return g_option_names[static_cast<uint32_t>(enum_value)];
230 //------------------------------------------------------------------
231 /// SetSCMatchesByLine - Takes a symbol context list of matches which
232 /// supposedly represent the same file and
233 /// line number in a CU, and find the nearest actual line number that matches,
234 /// and then filter down the
235 /// matching addresses to unique entries, and skip the prologue if asked to do
237 /// breakpoint locations in this breakpoint for all the resultant addresses.
238 void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list,
239 bool skip_prologue, llvm::StringRef log_ident);
240 void SetSCMatchesByLine(SearchFilter &, SymbolContextList &, bool,
241 const char *) = delete;
243 lldb::BreakpointLocationSP AddLocation(Address loc_addr,
244 bool *new_location = NULL);
246 Breakpoint *m_breakpoint; // This is the breakpoint we add locations to.
247 lldb::addr_t m_offset; // A random offset the user asked us to add to any
248 // breakpoints we set.
251 // Subclass identifier (for llvm isa/dyn_cast)
252 const unsigned char SubclassID;
253 DISALLOW_COPY_AND_ASSIGN(BreakpointResolver);
256 } // namespace lldb_private
258 #endif // liblldb_BreakpointResolver_h_