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/Core/Address.h"
19 #include "lldb/Core/SearchFilter.h"
20 #include "lldb/Utility/ConstString.h"
21 #include "lldb/Utility/FileSpec.h"
22 #include "lldb/Utility/RegularExpression.h"
23 #include "lldb/lldb-private.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class BreakpointResolver BreakpointResolver.h
29 /// "lldb/Breakpoint/BreakpointResolver.h" This class works with SearchFilter
30 /// to resolve logical breakpoints to their of concrete breakpoint locations.
31 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
35 /// The BreakpointResolver is a Searcher. In that protocol, the SearchFilter
36 /// asks the question "At what depth of the symbol context descent do you want
37 /// your callback to get called?" of the filter. The resolver answers this
38 /// question (in the GetDepth method) and provides the resolution callback.
39 /// Each Breakpoint has a BreakpointResolver, and it calls either
40 /// ResolveBreakpoint or ResolveBreakpointInModules to tell it to look for new
41 /// breakpoint locations.
42 //----------------------------------------------------------------------
44 class BreakpointResolver : public Searcher {
45 friend class Breakpoint;
48 //------------------------------------------------------------------
49 /// The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint
50 /// to make sense. It can be constructed without a breakpoint, but you have
51 /// to call SetBreakpoint before ResolveBreakpoint.
54 /// The breakpoint that owns this resolver.
55 /// @param[in] resolverType
56 /// The concrete breakpoint resolver type for this breakpoint.
59 /// Returns breakpoint location id.
60 //------------------------------------------------------------------
61 BreakpointResolver(Breakpoint *bkpt, unsigned char resolverType,
62 lldb::addr_t offset = 0);
64 //------------------------------------------------------------------
65 /// The Destructor is virtual, all significant breakpoint resolvers derive
67 //------------------------------------------------------------------
68 ~BreakpointResolver() override;
70 //------------------------------------------------------------------
71 /// This sets the breakpoint for this resolver.
74 /// The breakpoint that owns this resolver.
75 //------------------------------------------------------------------
76 void SetBreakpoint(Breakpoint *bkpt);
78 //------------------------------------------------------------------
79 /// This updates the offset for this breakpoint. All the locations
80 /// currently set for this breakpoint will have their offset adjusted when
84 /// The offset to add to all locations.
85 //------------------------------------------------------------------
86 void SetOffset(lldb::addr_t offset);
88 //------------------------------------------------------------------
89 /// This updates the offset for this breakpoint. All the locations
90 /// currently set for this breakpoint will have their offset adjusted when
94 /// The offset to add to all locations.
95 //------------------------------------------------------------------
96 lldb::addr_t GetOffset() const { return m_offset; }
98 //------------------------------------------------------------------
99 /// In response to this method the resolver scans all the modules in the
100 /// breakpoint's target, and adds any new locations it finds.
102 /// @param[in] filter
103 /// The filter that will manage the search for this resolver.
104 //------------------------------------------------------------------
105 virtual void ResolveBreakpoint(SearchFilter &filter);
107 //------------------------------------------------------------------
108 /// In response to this method the resolver scans the modules in the module
109 /// list \a modules, and adds any new locations it finds.
111 /// @param[in] filter
112 /// The filter that will manage the search for this resolver.
113 //------------------------------------------------------------------
114 virtual void ResolveBreakpointInModules(SearchFilter &filter,
115 ModuleList &modules);
117 //------------------------------------------------------------------
118 /// Prints a canonical description for the breakpoint to the stream \a s.
121 /// Stream to which the output is copied.
122 //------------------------------------------------------------------
123 void GetDescription(Stream *s) override = 0;
125 //------------------------------------------------------------------
126 /// Standard "Dump" method. At present it does nothing.
127 //------------------------------------------------------------------
128 virtual void Dump(Stream *s) const = 0;
130 /// This section handles serializing and deserializing from StructuredData
133 static lldb::BreakpointResolverSP
134 CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict,
137 virtual StructuredData::ObjectSP SerializeToStructuredData() {
138 return StructuredData::ObjectSP();
141 static const char *GetSerializationKey() { return "BKPTResolver"; }
143 static const char *GetSerializationSubclassKey() { return "Type"; }
145 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
147 StructuredData::DictionarySP
148 WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
150 //------------------------------------------------------------------
151 //------------------------------------------------------------------
152 /// An enumeration for keeping track of the concrete subclass that is
153 /// actually instantiated. Values of this enumeration are kept in the
154 /// BreakpointResolver's SubclassID field. They are used for concrete type
157 FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
158 AddressResolver, // This is an instance of BreakpointResolverAddress
159 NameResolver, // This is an instance of BreakpointResolverName
162 LastKnownResolverType = ExceptionResolver,
166 // Translate the Ty to name for serialization, the "+2" is one for size vrs.
167 // index, and one for UnknownResolver.
168 static const char *g_ty_to_name[LastKnownResolverType + 2];
170 //------------------------------------------------------------------
171 /// getResolverID - Return an ID for the concrete type of this object. This
172 /// is used to implement the LLVM classof checks. This should not be used
173 /// for any other purpose, as the values may change as LLDB evolves.
174 unsigned getResolverID() const { return SubclassID; }
176 enum ResolverTy GetResolverTy() {
177 if (SubclassID > ResolverTy::LastKnownResolverType)
178 return ResolverTy::UnknownResolver;
180 return (enum ResolverTy)SubclassID;
183 const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
185 static const char *ResolverTyToName(enum ResolverTy);
187 static ResolverTy NameToResolverTy(llvm::StringRef name);
189 virtual lldb::BreakpointResolverSP
190 CopyForBreakpoint(Breakpoint &breakpoint) = 0;
193 // Used for serializing resolver options:
194 // The options in this enum and the strings in the g_option_names must be
196 enum class OptionNames : uint32_t {
213 *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
216 static const char *GetKey(OptionNames enum_value) {
217 return g_option_names[static_cast<uint32_t>(enum_value)];
221 //------------------------------------------------------------------
222 /// Takes a symbol context list of matches which supposedly represent the
223 /// same file and line number in a CU, and find the nearest actual line
224 /// number that matches, and then filter down the matching addresses to
225 /// unique entries, and skip the prologue if asked to do so, and then set
226 /// breakpoint locations in this breakpoint for all the resultant addresses.
227 void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list,
228 bool skip_prologue, llvm::StringRef log_ident);
229 void SetSCMatchesByLine(SearchFilter &, SymbolContextList &, bool,
230 const char *) = delete;
232 lldb::BreakpointLocationSP AddLocation(Address loc_addr,
233 bool *new_location = NULL);
235 Breakpoint *m_breakpoint; // This is the breakpoint we add locations to.
236 lldb::addr_t m_offset; // A random offset the user asked us to add to any
237 // breakpoints we set.
240 // Subclass identifier (for llvm isa/dyn_cast)
241 const unsigned char SubclassID;
242 DISALLOW_COPY_AND_ASSIGN(BreakpointResolver);
245 } // namespace lldb_private
247 #endif // liblldb_BreakpointResolver_h_