]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Breakpoint/BreakpointResolver.h
Merge clang 7.0.1 and several follow-up changes
[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" This class works with SearchFilter
30 /// to resolve logical breakpoints to their of concrete breakpoint locations.
31 //----------------------------------------------------------------------
32
33 //----------------------------------------------------------------------
34 /// General Outline:
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 //----------------------------------------------------------------------
43
44 class BreakpointResolver : public Searcher {
45   friend class Breakpoint;
46
47 public:
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.
52   ///
53   /// @param[in] bkpt
54   ///   The breakpoint that owns this resolver.
55   /// @param[in] resolverType
56   ///   The concrete breakpoint resolver type for this breakpoint.
57   ///
58   /// @result
59   ///   Returns breakpoint location id.
60   //------------------------------------------------------------------
61   BreakpointResolver(Breakpoint *bkpt, unsigned char resolverType,
62                      lldb::addr_t offset = 0);
63
64   //------------------------------------------------------------------
65   /// The Destructor is virtual, all significant breakpoint resolvers derive
66   /// from this class.
67   //------------------------------------------------------------------
68   ~BreakpointResolver() override;
69
70   //------------------------------------------------------------------
71   /// This sets the breakpoint for this resolver.
72   ///
73   /// @param[in] bkpt
74   ///   The breakpoint that owns this resolver.
75   //------------------------------------------------------------------
76   void SetBreakpoint(Breakpoint *bkpt);
77
78   //------------------------------------------------------------------
79   /// This updates the offset for this breakpoint.  All the locations
80   /// currently set for this breakpoint will have their offset adjusted when
81   /// this is called.
82   ///
83   /// @param[in] offset
84   ///   The offset to add to all locations.
85   //------------------------------------------------------------------
86   void SetOffset(lldb::addr_t offset);
87
88   //------------------------------------------------------------------
89   /// This updates the offset for this breakpoint.  All the locations
90   /// currently set for this breakpoint will have their offset adjusted when
91   /// this is called.
92   ///
93   /// @param[in] offset
94   ///   The offset to add to all locations.
95   //------------------------------------------------------------------
96   lldb::addr_t GetOffset() const { return m_offset; }
97
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.
101   ///
102   /// @param[in] filter
103   ///   The filter that will manage the search for this resolver.
104   //------------------------------------------------------------------
105   virtual void ResolveBreakpoint(SearchFilter &filter);
106
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.
110   ///
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);
116
117   //------------------------------------------------------------------
118   /// Prints a canonical description for the breakpoint to the stream \a s.
119   ///
120   /// @param[in] s
121   ///   Stream to which the output is copied.
122   //------------------------------------------------------------------
123   void GetDescription(Stream *s) override = 0;
124
125   //------------------------------------------------------------------
126   /// Standard "Dump" method.  At present it does nothing.
127   //------------------------------------------------------------------
128   virtual void Dump(Stream *s) const = 0;
129
130   /// This section handles serializing and deserializing from StructuredData
131   /// objects.
132
133   static lldb::BreakpointResolverSP
134   CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict,
135                            Status &error);
136
137   virtual StructuredData::ObjectSP SerializeToStructuredData() {
138     return StructuredData::ObjectSP();
139   }
140
141   static const char *GetSerializationKey() { return "BKPTResolver"; }
142
143   static const char *GetSerializationSubclassKey() { return "Type"; }
144
145   static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
146
147   StructuredData::DictionarySP
148   WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
149
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
155   /// identification.
156   enum ResolverTy {
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
160     FileRegexResolver,
161     ExceptionResolver,
162     LastKnownResolverType = ExceptionResolver,
163     UnknownResolver
164   };
165
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];
169
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; }
175
176   enum ResolverTy GetResolverTy() {
177     if (SubclassID > ResolverTy::LastKnownResolverType)
178       return ResolverTy::UnknownResolver;
179     else
180       return (enum ResolverTy)SubclassID;
181   }
182
183   const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
184
185   static const char *ResolverTyToName(enum ResolverTy);
186
187   static ResolverTy NameToResolverTy(llvm::StringRef name);
188
189   virtual lldb::BreakpointResolverSP
190   CopyForBreakpoint(Breakpoint &breakpoint) = 0;
191
192 protected:
193   // Used for serializing resolver options:
194   // The options in this enum and the strings in the g_option_names must be
195   // kept in sync.
196   enum class OptionNames : uint32_t {
197     AddressOffset = 0,
198     ExactMatch,
199     FileName,
200     Inlines,
201     LanguageName,
202     LineNumber,
203     ModuleName,
204     NameMaskArray,
205     Offset,
206     RegexString,
207     SectionName,
208     SkipPrologue,
209     SymbolNameArray,
210     LastOptionName
211   };
212   static const char
213       *g_option_names[static_cast<uint32_t>(OptionNames::LastOptionName)];
214
215 public:
216   static const char *GetKey(OptionNames enum_value) {
217     return g_option_names[static_cast<uint32_t>(enum_value)];
218   }
219
220 protected:
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;
231
232   lldb::BreakpointLocationSP AddLocation(Address loc_addr,
233                                          bool *new_location = NULL);
234
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.
238
239 private:
240   // Subclass identifier (for llvm isa/dyn_cast)
241   const unsigned char SubclassID;
242   DISALLOW_COPY_AND_ASSIGN(BreakpointResolver);
243 };
244
245 } // namespace lldb_private
246
247 #endif // liblldb_BreakpointResolver_h_