]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointResolver.h
MFV: r336486
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Breakpoint / BreakpointResolver.h
1 //===-- BreakpointResolver.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_BreakpointResolver_h_
11 #define liblldb_BreakpointResolver_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project 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"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 /// @class BreakpointResolver BreakpointResolver.h
29 /// "lldb/Breakpoint/BreakpointResolver.h"
30 /// @brief This class works with SearchFilter to resolve logical breakpoints to
31 /// their
32 /// of concrete breakpoint locations.
33 //----------------------------------------------------------------------
34
35 //----------------------------------------------------------------------
36 /// General Outline:
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
40 /// resolver
41 /// answers this question (in the GetDepth method) and provides the resolution
42 /// callback.
43 /// Each Breakpoint has a BreakpointResolver, and it calls either
44 /// ResolveBreakpoint
45 /// or ResolveBreakpointInModules to tell it to look for new breakpoint
46 /// locations.
47 //----------------------------------------------------------------------
48
49 class BreakpointResolver : public Searcher {
50   friend class Breakpoint;
51
52 public:
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
56   /// to
57   /// call SetBreakpoint before ResolveBreakpoint.
58   ///
59   /// @param[in] bkpt
60   ///   The breakpoint that owns this resolver.
61   /// @param[in] resolverType
62   ///   The concrete breakpoint resolver type for this breakpoint.
63   ///
64   /// @result
65   ///   Returns breakpoint location id.
66   //------------------------------------------------------------------
67   BreakpointResolver(Breakpoint *bkpt, unsigned char resolverType,
68                      lldb::addr_t offset = 0);
69
70   //------------------------------------------------------------------
71   /// The Destructor is virtual, all significant breakpoint resolvers derive
72   /// from this class.
73   //------------------------------------------------------------------
74   ~BreakpointResolver() override;
75
76   //------------------------------------------------------------------
77   /// This sets the breakpoint for this resolver.
78   ///
79   /// @param[in] bkpt
80   ///   The breakpoint that owns this resolver.
81   //------------------------------------------------------------------
82   void SetBreakpoint(Breakpoint *bkpt);
83
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
87   /// called.
88   ///
89   /// @param[in] offset
90   ///   The offset to add to all locations.
91   //------------------------------------------------------------------
92   void SetOffset(lldb::addr_t offset);
93
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
97   /// called.
98   ///
99   /// @param[in] offset
100   ///   The offset to add to all locations.
101   //------------------------------------------------------------------
102   lldb::addr_t GetOffset() const { return m_offset; }
103
104   //------------------------------------------------------------------
105   /// In response to this method the resolver scans all the modules in the
106   /// breakpoint's
107   /// target, and adds any new locations it finds.
108   ///
109   /// @param[in] filter
110   ///   The filter that will manage the search for this resolver.
111   //------------------------------------------------------------------
112   virtual void ResolveBreakpoint(SearchFilter &filter);
113
114   //------------------------------------------------------------------
115   /// In response to this method the resolver scans the modules in the module
116   /// list
117   /// \a modules, and adds any new locations it finds.
118   ///
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);
124
125   //------------------------------------------------------------------
126   /// Prints a canonical description for the breakpoint to the stream \a s.
127   ///
128   /// @param[in] s
129   ///   Stream to which the output is copied.
130   //------------------------------------------------------------------
131   void GetDescription(Stream *s) override = 0;
132
133   //------------------------------------------------------------------
134   /// Standard "Dump" method.  At present it does nothing.
135   //------------------------------------------------------------------
136   virtual void Dump(Stream *s) const = 0;
137
138   /// This section handles serializing and deserializing from StructuredData
139   /// objects.
140
141   static lldb::BreakpointResolverSP
142   CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict,
143                            Status &error);
144
145   virtual StructuredData::ObjectSP SerializeToStructuredData() {
146     return StructuredData::ObjectSP();
147   }
148
149   static const char *GetSerializationKey() { return "BKPTResolver"; }
150
151   static const char *GetSerializationSubclassKey() { return "Type"; }
152
153   static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
154
155   StructuredData::DictionarySP
156   WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
157
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
163   /// identification.
164   enum ResolverTy {
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
168     FileRegexResolver,
169     ExceptionResolver,
170     LastKnownResolverType = ExceptionResolver,
171     UnknownResolver
172   };
173
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];
177
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; }
183
184   enum ResolverTy GetResolverTy() {
185     if (SubclassID > ResolverTy::LastKnownResolverType)
186       return ResolverTy::UnknownResolver;
187     else
188       return (enum ResolverTy)SubclassID;
189   }
190
191   const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
192
193   static const char *ResolverTyToName(enum ResolverTy);
194
195   static ResolverTy NameToResolverTy(llvm::StringRef name);
196
197   virtual lldb::BreakpointResolverSP
198   CopyForBreakpoint(Breakpoint &breakpoint) = 0;
199
200 protected:
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 {
205     AddressOffset = 0,
206     ExactMatch,
207     FileName,
208     Inlines,
209     LanguageName,
210     LineNumber,
211     ModuleName,
212     NameMaskArray,
213     Offset,
214     RegexString,
215     SectionName,
216     SkipPrologue,
217     SymbolNameArray,
218     LastOptionName
219   };
220   static const char
221       *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
222
223 public:
224   static const char *GetKey(OptionNames enum_value) {
225     return g_option_names[static_cast<uint32_t>(enum_value)];
226   }
227
228 protected:
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
235   /// so, and then set
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;
241
242   lldb::BreakpointLocationSP AddLocation(Address loc_addr,
243                                          bool *new_location = NULL);
244
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.
248
249 private:
250   // Subclass identifier (for llvm isa/dyn_cast)
251   const unsigned char SubclassID;
252   DISALLOW_COPY_AND_ASSIGN(BreakpointResolver);
253 };
254
255 } // namespace lldb_private
256
257 #endif // liblldb_BreakpointResolver_h_