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;
229 CopyForBreakpoint (Breakpoint &breakpoint);
232 // These are utility functions to assist with the search iteration. They are used by the
233 // default Search method.
235 Searcher::CallbackReturn
236 DoModuleIteration (const SymbolContext &context,
239 Searcher::CallbackReturn
240 DoModuleIteration (const lldb::ModuleSP& module_sp,
243 Searcher::CallbackReturn
244 DoCUIteration (const lldb::ModuleSP& module_sp,
245 const SymbolContext &context,
248 Searcher::CallbackReturn
249 DoFunctionIteration (Function *function,
250 const SymbolContext &context,
253 virtual lldb::SearchFilterSP
254 DoCopyForBreakpoint (Breakpoint &breakpoint) = 0;
257 SetTarget(lldb::TargetSP &target_sp)
259 m_target_sp = target_sp;
262 lldb::TargetSP m_target_sp; // Every filter has to be associated with a target for
263 // now since you need a starting place for the search.
266 //----------------------------------------------------------------------
267 /// @class SearchFilterForUnconstrainedSearches SearchFilter.h "lldb/Core/SearchFilter.h"
268 /// @brief This is a SearchFilter that searches through all modules. It also consults the Target::ModuleIsExcludedForUnconstrainedSearches.
269 //----------------------------------------------------------------------
270 class SearchFilterForUnconstrainedSearches :
274 SearchFilterForUnconstrainedSearches (const lldb::TargetSP &target_sp) : SearchFilter(target_sp) {}
275 ~SearchFilterForUnconstrainedSearches() override = default;
278 ModulePasses (const FileSpec &module_spec) override;
281 ModulePasses (const lldb::ModuleSP &module_sp) override;
285 DoCopyForBreakpoint (Breakpoint &breakpoint) override;
288 //----------------------------------------------------------------------
289 /// @class SearchFilterByModule SearchFilter.h "lldb/Core/SearchFilter.h"
290 /// @brief This is a SearchFilter that restricts the search to a given module.
291 //----------------------------------------------------------------------
293 class SearchFilterByModule :
298 //------------------------------------------------------------------
299 /// The basic constructor takes a Target, which gives the space to search,
300 /// and the module to restrict the search to.
302 /// @param[in] target
303 /// The Target that provides the module list to search.
305 /// @param[in] module
306 /// The Module that limits the search.
307 //------------------------------------------------------------------
308 SearchFilterByModule (const lldb::TargetSP &targetSP,
309 const FileSpec &module);
311 SearchFilterByModule (const SearchFilterByModule& rhs);
313 ~SearchFilterByModule() override;
315 const SearchFilterByModule&
316 operator=(const SearchFilterByModule& rhs);
319 ModulePasses (const lldb::ModuleSP &module_sp) override;
322 ModulePasses (const FileSpec &spec) override;
325 AddressPasses (Address &address) override;
328 CompUnitPasses (FileSpec &fileSpec) override;
331 CompUnitPasses (CompileUnit &compUnit) override;
334 GetDescription(Stream *s) override;
337 GetFilterRequiredItems () override;
340 Dump (Stream *s) const override;
343 Search (Searcher &searcher) override;
347 DoCopyForBreakpoint (Breakpoint &breakpoint) override;
350 FileSpec m_module_spec;
353 class SearchFilterByModuleList :
358 //------------------------------------------------------------------
359 /// The basic constructor takes a Target, which gives the space to search,
360 /// and the module list to restrict the search to.
362 /// @param[in] target
363 /// The Target that provides the module list to search.
365 /// @param[in] module
366 /// The Module that limits the search.
367 //------------------------------------------------------------------
368 SearchFilterByModuleList (const lldb::TargetSP &targetSP,
369 const FileSpecList &module_list);
371 SearchFilterByModuleList (const SearchFilterByModuleList& rhs);
373 ~SearchFilterByModuleList() override;
375 const SearchFilterByModuleList&
376 operator=(const SearchFilterByModuleList& rhs);
379 ModulePasses (const lldb::ModuleSP &module_sp) override;
382 ModulePasses (const FileSpec &spec) override;
385 AddressPasses (Address &address) override;
388 CompUnitPasses (FileSpec &fileSpec) override;
391 CompUnitPasses (CompileUnit &compUnit) override;
394 GetDescription(Stream *s) override;
397 GetFilterRequiredItems () override;
400 Dump (Stream *s) const override;
403 Search (Searcher &searcher) override;
407 DoCopyForBreakpoint (Breakpoint &breakpoint) override;
410 FileSpecList m_module_spec_list;
413 class SearchFilterByModuleListAndCU :
414 public SearchFilterByModuleList
418 //------------------------------------------------------------------
419 /// The basic constructor takes a Target, which gives the space to search,
420 /// and the module list to restrict the search to.
422 /// @param[in] target
423 /// The Target that provides the module list to search.
425 /// @param[in] module
426 /// The Module that limits the search.
427 //------------------------------------------------------------------
428 SearchFilterByModuleListAndCU (const lldb::TargetSP &targetSP,
429 const FileSpecList &module_list,
430 const FileSpecList &cu_list);
432 SearchFilterByModuleListAndCU (const SearchFilterByModuleListAndCU& rhs);
434 ~SearchFilterByModuleListAndCU() override;
436 const SearchFilterByModuleListAndCU&
437 operator=(const SearchFilterByModuleListAndCU& rhs);
440 AddressPasses (Address &address) override;
443 CompUnitPasses (FileSpec &fileSpec) override;
446 CompUnitPasses (CompileUnit &compUnit) override;
449 GetDescription(Stream *s) override;
452 GetFilterRequiredItems () override;
455 Dump (Stream *s) const override;
458 Search (Searcher &searcher) override;
462 DoCopyForBreakpoint (Breakpoint &breakpoint) override;
465 FileSpecList m_cu_spec_list;
468 } // namespace lldb_private
470 #endif // liblldb_SearchFilter_h_