1 //===-- SearchFilter.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_SearchFilter_h_
11 #define liblldb_SearchFilter_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Core/FileSpecList.h"
20 namespace lldb_private {
22 //----------------------------------------------------------------------
23 /// @class Searcher SearchFilter.h "lldb/Core/SearchFilter.h"
24 /// @brief Class that is driven by the SearchFilter to search the
25 /// SymbolContext space of the target program.
26 //----------------------------------------------------------------------
28 //----------------------------------------------------------------------
30 /// Provides the callback and search depth for the SearchFilter search.
31 //----------------------------------------------------------------------
37 eCallbackReturnStop = 0, // Stop the iteration
38 eCallbackReturnContinue, // Continue the iteration
39 eCallbackReturnPop // Pop one level up and continue iterating
55 virtual CallbackReturn
56 SearchCallback (SearchFilter &filter,
57 SymbolContext &context,
64 //------------------------------------------------------------------
65 /// Prints a canonical description for the searcher to the stream \a s.
68 /// Stream to which the output is copied.
69 //------------------------------------------------------------------
71 GetDescription(Stream *s);
74 //----------------------------------------------------------------------
75 /// @class SearchFilter SearchFilter.h "lldb/Core/SearchFilter.h"
76 /// @brief Class descends through the SymbolContext space of the target,
77 /// applying a filter at each stage till it reaches the depth specified by
78 /// the GetDepth method of the searcher, and calls its callback at that point.
79 //----------------------------------------------------------------------
81 //----------------------------------------------------------------------
83 /// Provides the callback and search depth for the SearchFilter search.
85 /// The search is done by cooperation between the search filter and the searcher.
86 /// The search filter does the heavy work of recursing through the SymbolContext
87 /// space of the target program's symbol space. The Searcher specifies the depth
88 /// at which it wants its callback to be invoked. Note that since the resolution
89 /// of the Searcher may be greater than that of the SearchFilter, before the
90 /// Searcher qualifies an address it should pass it to "AddressPasses."
91 /// The default implementation is "Everything Passes."
92 //----------------------------------------------------------------------
98 //------------------------------------------------------------------
99 /// The basic constructor takes a Target, which gives the space to search.
101 /// @param[in] target
102 /// The Target that provides the module list to search.
103 //------------------------------------------------------------------
104 SearchFilter (const lldb::TargetSP &target_sp);
106 SearchFilter (const SearchFilter& rhs);
112 operator=(const SearchFilter& rhs);
114 //------------------------------------------------------------------
115 /// Call this method with a file spec to see if that spec passes the filter.
118 /// The file spec to check against the filter.
120 /// \b true if \a spec passes, and \b false otherwise.
121 //------------------------------------------------------------------
123 ModulePasses (const FileSpec &spec);
125 //------------------------------------------------------------------
126 /// Call this method with a Module to see if that module passes the filter.
128 /// @param[in] module
129 /// The Module to check against the filter.
132 /// \b true if \a module passes, and \b false otherwise.
133 //------------------------------------------------------------------
135 ModulePasses (const lldb::ModuleSP &module_sp);
137 //------------------------------------------------------------------
138 /// Call this method with a Address to see if \a address passes the filter.
141 /// The address to check against the filter.
144 /// \b true if \a address passes, and \b false otherwise.
145 //------------------------------------------------------------------
147 AddressPasses (Address &addr);
149 //------------------------------------------------------------------
150 /// Call this method with a FileSpec to see if \a file spec passes the filter
151 /// as the name of a compilation unit.
153 /// @param[in] fileSpec
154 /// The file spec to check against the filter.
157 /// \b true if \a file spec passes, and \b false otherwise.
158 //------------------------------------------------------------------
160 CompUnitPasses (FileSpec &fileSpec);
162 //------------------------------------------------------------------
163 /// Call this method with a CompileUnit to see if \a comp unit passes the filter.
165 /// @param[in] compUnit
166 /// The CompileUnit to check against the filter.
169 /// \b true if \a Comp Unit passes, and \b false otherwise.
170 //------------------------------------------------------------------
172 CompUnitPasses (CompileUnit &compUnit);
174 //------------------------------------------------------------------
175 /// Call this method to do the search using the Searcher.
177 /// @param[in] searcher
178 /// The searcher to drive with this search.
180 //------------------------------------------------------------------
182 Search (Searcher &searcher);
184 //------------------------------------------------------------------
185 /// Call this method to do the search using the Searcher in the module list
188 /// @param[in] searcher
189 /// The searcher to drive with this search.
191 /// @param[in] modules
192 /// The module list within which to restrict the search.
194 //------------------------------------------------------------------
196 SearchInModuleList (Searcher &searcher, ModuleList &modules);
198 //------------------------------------------------------------------
199 /// This determines which items are REQUIRED for the filter to pass.
200 /// For instance, if you are filtering by Compilation Unit, obviously
201 /// symbols that have no compilation unit can't pass So return eSymbolContextCU
202 /// and search callbacks can then short cut the search to avoid looking at
203 /// things that obviously won't pass.
206 /// The required elements for the search, which is an or'ed together
207 /// set of lldb:SearchContextItem enum's.
209 //------------------------------------------------------------------
211 GetFilterRequiredItems ();
213 //------------------------------------------------------------------
214 /// Prints a canonical description for the search filter to the stream \a s.
217 /// Stream to which the output is copied.
218 //------------------------------------------------------------------
220 GetDescription(Stream *s);
222 //------------------------------------------------------------------
223 /// Standard "Dump" method. At present it does nothing.
224 //------------------------------------------------------------------
226 Dump (Stream *s) const;
230 // These are utility functions to assist with the search iteration. They are used by the
231 // default Search method.
233 Searcher::CallbackReturn
234 DoModuleIteration (const SymbolContext &context,
237 Searcher::CallbackReturn
238 DoModuleIteration (const lldb::ModuleSP& module_sp,
241 Searcher::CallbackReturn
242 DoCUIteration (const lldb::ModuleSP& module_sp,
243 const SymbolContext &context,
246 Searcher::CallbackReturn
247 DoFunctionIteration (Function *function,
248 const SymbolContext &context,
251 lldb::TargetSP m_target_sp; // Every filter has to be associated with a target for
252 // now since you need a starting place for the search.
255 //----------------------------------------------------------------------
256 /// @class SearchFilterForNonModuleSpecificSearches SearchFilter.h "lldb/Core/SearchFilter.h"
257 /// @brief This is a SearchFilter that searches through all modules. It also consults the Target::ModuleIsExcludedForNonModuleSpecificSearches.
258 //----------------------------------------------------------------------
259 class SearchFilterForNonModuleSpecificSearches :
263 SearchFilterForNonModuleSpecificSearches (const lldb::TargetSP &targetSP) : SearchFilter(targetSP) {}
264 ~SearchFilterForNonModuleSpecificSearches () {}
267 ModulePasses (const FileSpec &module_spec);
270 ModulePasses (const lldb::ModuleSP &module_sp);
273 //----------------------------------------------------------------------
274 /// @class SearchFilterByModule SearchFilter.h "lldb/Core/SearchFilter.h"
275 /// @brief This is a SearchFilter that restricts the search to a given module.
276 //----------------------------------------------------------------------
278 class SearchFilterByModule :
283 //------------------------------------------------------------------
284 /// The basic constructor takes a Target, which gives the space to search,
285 /// and the module to restrict the search to.
287 /// @param[in] target
288 /// The Target that provides the module list to search.
290 /// @param[in] module
291 /// The Module that limits the search.
292 //------------------------------------------------------------------
293 SearchFilterByModule (const lldb::TargetSP &targetSP,
294 const FileSpec &module);
296 SearchFilterByModule (const SearchFilterByModule& rhs);
299 ~SearchFilterByModule ();
301 const SearchFilterByModule&
302 operator=(const SearchFilterByModule& rhs);
305 ModulePasses (const lldb::ModuleSP &module_sp);
308 ModulePasses (const FileSpec &spec);
311 AddressPasses (Address &address);
314 CompUnitPasses (FileSpec &fileSpec);
317 CompUnitPasses (CompileUnit &compUnit);
320 GetDescription(Stream *s);
323 GetFilterRequiredItems ();
326 Dump (Stream *s) const;
329 Search (Searcher &searcher);
332 FileSpec m_module_spec;
335 class SearchFilterByModuleList :
340 //------------------------------------------------------------------
341 /// The basic constructor takes a Target, which gives the space to search,
342 /// and the module list to restrict the search to.
344 /// @param[in] target
345 /// The Target that provides the module list to search.
347 /// @param[in] module
348 /// The Module that limits the search.
349 //------------------------------------------------------------------
350 SearchFilterByModuleList (const lldb::TargetSP &targetSP,
351 const FileSpecList &module_list);
353 SearchFilterByModuleList (const SearchFilterByModuleList& rhs);
356 ~SearchFilterByModuleList ();
358 const SearchFilterByModuleList&
359 operator=(const SearchFilterByModuleList& rhs);
362 ModulePasses (const lldb::ModuleSP &module_sp);
365 ModulePasses (const FileSpec &spec);
368 AddressPasses (Address &address);
371 CompUnitPasses (FileSpec &fileSpec);
374 CompUnitPasses (CompileUnit &compUnit);
377 GetDescription(Stream *s);
380 GetFilterRequiredItems ();
383 Dump (Stream *s) const;
386 Search (Searcher &searcher);
389 FileSpecList m_module_spec_list;
392 class SearchFilterByModuleListAndCU :
393 public SearchFilterByModuleList
397 //------------------------------------------------------------------
398 /// The basic constructor takes a Target, which gives the space to search,
399 /// and the module list to restrict the search to.
401 /// @param[in] target
402 /// The Target that provides the module list to search.
404 /// @param[in] module
405 /// The Module that limits the search.
406 //------------------------------------------------------------------
407 SearchFilterByModuleListAndCU (const lldb::TargetSP &targetSP,
408 const FileSpecList &module_list,
409 const FileSpecList &cu_list);
411 SearchFilterByModuleListAndCU (const SearchFilterByModuleListAndCU& rhs);
414 ~SearchFilterByModuleListAndCU ();
416 const SearchFilterByModuleListAndCU&
417 operator=(const SearchFilterByModuleListAndCU& rhs);
420 AddressPasses (Address &address);
423 CompUnitPasses (FileSpec &fileSpec);
426 CompUnitPasses (CompileUnit &compUnit);
429 GetDescription(Stream *s);
432 GetFilterRequiredItems ();
435 Dump (Stream *s) const;
438 Search (Searcher &searcher);
441 FileSpecList m_module_spec_list;
442 FileSpecList m_cu_spec_list;
445 } // namespace lldb_private
447 #endif // liblldb_SearchFilter_h_