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