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"
30 /// @brief This class works with SearchFilter to resolve logical breakpoints to
32 /// of concrete breakpoint locations.
33 //----------------------------------------------------------------------
35 //----------------------------------------------------------------------
37 /// The BreakpointResolver is a Searcher. In that protocol,
38 /// the SearchFilter asks the question "At what depth of the symbol context
39 /// descent do you want your callback to get called?" of the filter. The
41 /// answers this question (in the GetDepth method) and provides the resolution
43 /// Each Breakpoint has a BreakpointResolver, and it calls either
45 /// or ResolveBreakpointInModules to tell it to look for new breakpoint
47 //----------------------------------------------------------------------
49 class BreakpointResolver : public Searcher {
50 friend class Breakpoint;
53 //------------------------------------------------------------------
54 /// The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint
55 /// to make sense. It can be constructed without a breakpoint, but you have
57 /// call SetBreakpoint before ResolveBreakpoint.
60 /// The breakpoint that owns this resolver.
61 /// @param[in] resolverType
62 /// The concrete breakpoint resolver type for this breakpoint.
65 /// Returns breakpoint location id.
66 //------------------------------------------------------------------
67 BreakpointResolver(Breakpoint *bkpt, unsigned char resolverType,
68 lldb::addr_t offset = 0);
70 //------------------------------------------------------------------
71 /// The Destructor is virtual, all significant breakpoint resolvers derive
73 //------------------------------------------------------------------
74 ~BreakpointResolver() override;
76 //------------------------------------------------------------------
77 /// This sets the breakpoint for this resolver.
80 /// The breakpoint that owns this resolver.
81 //------------------------------------------------------------------
82 void SetBreakpoint(Breakpoint *bkpt);
84 //------------------------------------------------------------------
85 /// This updates the offset for this breakpoint. All the locations currently
86 /// set for this breakpoint will have their offset adjusted when this is
90 /// The offset to add to all locations.
91 //------------------------------------------------------------------
92 void SetOffset(lldb::addr_t offset);
94 //------------------------------------------------------------------
95 /// This updates the offset for this breakpoint. All the locations currently
96 /// set for this breakpoint will have their offset adjusted when this is
100 /// The offset to add to all locations.
101 //------------------------------------------------------------------
102 lldb::addr_t GetOffset() const { return m_offset; }
104 //------------------------------------------------------------------
105 /// In response to this method the resolver scans all the modules in the
107 /// target, and adds any new locations it finds.
109 /// @param[in] filter
110 /// The filter that will manage the search for this resolver.
111 //------------------------------------------------------------------
112 virtual void ResolveBreakpoint(SearchFilter &filter);
114 //------------------------------------------------------------------
115 /// In response to this method the resolver scans the modules in the module
117 /// \a modules, and adds any new locations it finds.
119 /// @param[in] filter
120 /// The filter that will manage the search for this resolver.
121 //------------------------------------------------------------------
122 virtual void ResolveBreakpointInModules(SearchFilter &filter,
123 ModuleList &modules);
125 //------------------------------------------------------------------
126 /// Prints a canonical description for the breakpoint to the stream \a s.
129 /// Stream to which the output is copied.
130 //------------------------------------------------------------------
131 void GetDescription(Stream *s) override = 0;
133 //------------------------------------------------------------------
134 /// Standard "Dump" method. At present it does nothing.
135 //------------------------------------------------------------------
136 virtual void Dump(Stream *s) const = 0;
138 /// This section handles serializing and deserializing from StructuredData
141 static lldb::BreakpointResolverSP
142 CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict,
145 virtual StructuredData::ObjectSP SerializeToStructuredData() {
146 return StructuredData::ObjectSP();
149 static const char *GetSerializationKey() { return "BKPTResolver"; }
151 static const char *GetSerializationSubclassKey() { return "Type"; }
153 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
155 StructuredData::DictionarySP
156 WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
158 //------------------------------------------------------------------
159 //------------------------------------------------------------------
160 /// An enumeration for keeping track of the concrete subclass that
161 /// is actually instantiated. Values of this enumeration are kept in the
162 /// BreakpointResolver's SubclassID field. They are used for concrete type
165 FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
166 AddressResolver, // This is an instance of BreakpointResolverAddress
167 NameResolver, // This is an instance of BreakpointResolverName
170 LastKnownResolverType = ExceptionResolver,
174 // Translate the Ty to name for serialization,
175 // the "+2" is one for size vrs. index, and one for UnknownResolver.
176 static const char *g_ty_to_name[LastKnownResolverType + 2];
178 //------------------------------------------------------------------
179 /// getResolverID - Return an ID for the concrete type of this object. This
180 /// is used to implement the LLVM classof checks. This should not be used
181 /// for any other purpose, as the values may change as LLDB evolves.
182 unsigned getResolverID() const { return SubclassID; }
184 enum ResolverTy GetResolverTy() {
185 if (SubclassID > ResolverTy::LastKnownResolverType)
186 return ResolverTy::UnknownResolver;
188 return (enum ResolverTy)SubclassID;
191 const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
193 static const char *ResolverTyToName(enum ResolverTy);
195 static ResolverTy NameToResolverTy(llvm::StringRef name);
197 virtual lldb::BreakpointResolverSP
198 CopyForBreakpoint(Breakpoint &breakpoint) = 0;
201 // Used for serializing resolver options:
202 // The options in this enum and the strings in the
203 // g_option_names must be kept in sync.
204 enum class OptionNames : uint32_t {
221 *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
224 static const char *GetKey(OptionNames enum_value) {
225 return g_option_names[static_cast<uint32_t>(enum_value)];
229 //------------------------------------------------------------------
230 /// SetSCMatchesByLine - Takes a symbol context list of matches which
231 /// supposedly represent the same file and
232 /// line number in a CU, and find the nearest actual line number that matches,
233 /// and then filter down the
234 /// matching addresses to unique entries, and skip the prologue if asked to do
236 /// breakpoint locations in this breakpoint for all the resultant addresses.
237 void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list,
238 bool skip_prologue, llvm::StringRef log_ident);
239 void SetSCMatchesByLine(SearchFilter &, SymbolContextList &, bool,
240 const char *) = delete;
242 lldb::BreakpointLocationSP AddLocation(Address loc_addr,
243 bool *new_location = NULL);
245 Breakpoint *m_breakpoint; // This is the breakpoint we add locations to.
246 lldb::addr_t m_offset; // A random offset the user asked us to add to any
247 // breakpoints we set.
250 // Subclass identifier (for llvm isa/dyn_cast)
251 const unsigned char SubclassID;
252 DISALLOW_COPY_AND_ASSIGN(BreakpointResolver);
255 } // namespace lldb_private
257 #endif // liblldb_BreakpointResolver_h_