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_
13 #include "lldb/Core/FileSpecList.h"
14 #include "lldb/Utility/StructuredData.h"
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/lldb-forward.h"
21 namespace lldb_private {
24 namespace lldb_private {
27 namespace lldb_private {
30 namespace lldb_private {
33 namespace lldb_private {
36 namespace lldb_private {
39 namespace lldb_private {
42 namespace lldb_private {
45 namespace lldb_private {
48 namespace lldb_private {
52 namespace lldb_private {
54 //----------------------------------------------------------------------
55 /// @class Searcher SearchFilter.h "lldb/Core/SearchFilter.h" Class that is
56 /// driven by the SearchFilter to search the SymbolContext space of the target
58 //----------------------------------------------------------------------
60 //----------------------------------------------------------------------
62 /// Provides the callback and search depth for the SearchFilter search.
63 //----------------------------------------------------------------------
68 eCallbackReturnStop = 0, // Stop the iteration
69 eCallbackReturnContinue, // Continue the iteration
70 eCallbackReturnPop // Pop one level up and continue iterating
77 virtual CallbackReturn SearchCallback(SearchFilter &filter,
78 SymbolContext &context, Address *addr,
81 virtual lldb::SearchDepth GetDepth() = 0;
83 //------------------------------------------------------------------
84 /// Prints a canonical description for the searcher to the stream \a s.
87 /// Stream to which the output is copied.
88 //------------------------------------------------------------------
89 virtual void GetDescription(Stream *s);
92 //----------------------------------------------------------------------
93 /// @class SearchFilter SearchFilter.h "lldb/Core/SearchFilter.h" Class
94 /// descends through the SymbolContext space of the target, applying a filter
95 /// at each stage till it reaches the depth specified by the GetDepth method
96 /// of the searcher, and calls its callback at that point.
97 //----------------------------------------------------------------------
99 //----------------------------------------------------------------------
101 /// Provides the callback and search depth for the SearchFilter search.
103 /// The search is done by cooperation between the search filter and the
104 /// searcher. The search filter does the heavy work of recursing through the
105 /// SymbolContext space of the target program's symbol space. The Searcher
106 /// specifies the depth at which it wants its callback to be invoked. Note
107 /// that since the resolution of the Searcher may be greater than that of the
108 /// SearchFilter, before the Searcher qualifies an address it should pass it
109 /// to "AddressPasses." The default implementation is "Everything Passes."
110 //----------------------------------------------------------------------
114 //------------------------------------------------------------------
115 /// The basic constructor takes a Target, which gives the space to search.
117 /// @param[in] target
118 /// The Target that provides the module list to search.
119 //------------------------------------------------------------------
120 SearchFilter(const lldb::TargetSP &target_sp);
122 SearchFilter(const SearchFilter &rhs);
124 SearchFilter(const lldb::TargetSP &target_sp, unsigned char filterType);
126 virtual ~SearchFilter();
128 SearchFilter &operator=(const SearchFilter &rhs);
130 //------------------------------------------------------------------
131 /// Call this method with a file spec to see if that spec passes the filter.
134 /// The file spec to check against the filter.
136 /// \b true if \a spec passes, and \b false otherwise.
137 //------------------------------------------------------------------
138 virtual bool ModulePasses(const FileSpec &spec);
140 //------------------------------------------------------------------
141 /// Call this method with a Module to see if that module passes the filter.
143 /// @param[in] module
144 /// The Module to check against the filter.
147 /// \b true if \a module passes, and \b false otherwise.
148 //------------------------------------------------------------------
149 virtual bool ModulePasses(const lldb::ModuleSP &module_sp);
151 //------------------------------------------------------------------
152 /// Call this method with a Address to see if \a address passes the filter.
155 /// The address to check against the filter.
158 /// \b true if \a address passes, and \b false otherwise.
159 //------------------------------------------------------------------
160 virtual bool AddressPasses(Address &addr);
162 //------------------------------------------------------------------
163 /// Call this method with a FileSpec to see if \a file spec passes the
164 /// filter as the name of a compilation unit.
166 /// @param[in] fileSpec
167 /// The file spec to check against the filter.
170 /// \b true if \a file spec passes, and \b false otherwise.
171 //------------------------------------------------------------------
172 virtual bool CompUnitPasses(FileSpec &fileSpec);
174 //------------------------------------------------------------------
175 /// Call this method with a CompileUnit to see if \a comp unit passes the
178 /// @param[in] compUnit
179 /// The CompileUnit to check against the filter.
182 /// \b true if \a Comp Unit passes, and \b false otherwise.
183 //------------------------------------------------------------------
184 virtual bool CompUnitPasses(CompileUnit &compUnit);
186 //------------------------------------------------------------------
187 /// Call this method with a Function to see if \a function passes the
190 /// @param[in] function
191 /// The Functions to check against the filter.
194 /// \b true if \a function passes, and \b false otherwise.
195 //------------------------------------------------------------------
196 virtual bool FunctionPasses(Function &function);
198 //------------------------------------------------------------------
199 /// Call this method to do the search using the Searcher.
201 /// @param[in] searcher
202 /// The searcher to drive with this search.
204 //------------------------------------------------------------------
205 virtual void Search(Searcher &searcher);
207 //------------------------------------------------------------------
208 /// Call this method to do the search using the Searcher in the module list
211 /// @param[in] searcher
212 /// The searcher to drive with this search.
214 /// @param[in] modules
215 /// The module list within which to restrict the search.
217 //------------------------------------------------------------------
218 virtual void SearchInModuleList(Searcher &searcher, ModuleList &modules);
220 //------------------------------------------------------------------
221 /// This determines which items are REQUIRED for the filter to pass. For
222 /// instance, if you are filtering by Compilation Unit, obviously symbols
223 /// that have no compilation unit can't pass So return eSymbolContextCU and
224 /// search callbacks can then short cut the search to avoid looking at
225 /// things that obviously won't pass.
228 /// The required elements for the search, which is an or'ed together
229 /// set of lldb:SearchContextItem enum's.
231 //------------------------------------------------------------------
232 virtual uint32_t GetFilterRequiredItems();
234 //------------------------------------------------------------------
235 /// Prints a canonical description for the search filter to the stream \a s.
238 /// Stream to which the output is copied.
239 //------------------------------------------------------------------
240 virtual void GetDescription(Stream *s);
242 //------------------------------------------------------------------
243 /// Standard "Dump" method. At present it does nothing.
244 //------------------------------------------------------------------
245 virtual void Dump(Stream *s) const;
247 lldb::SearchFilterSP CopyForBreakpoint(Breakpoint &breakpoint);
249 static lldb::SearchFilterSP
250 CreateFromStructuredData(Target &target,
251 const StructuredData::Dictionary &data_dict,
254 virtual StructuredData::ObjectSP SerializeToStructuredData() {
255 return StructuredData::ObjectSP();
258 static const char *GetSerializationKey() { return "SearchFilter"; }
260 static const char *GetSerializationSubclassKey() { return "Type"; }
262 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
270 LastKnownFilterType = ByModulesAndCU,
274 static const char *g_ty_to_name[LastKnownFilterType + 2];
276 enum FilterTy GetFilterTy() {
277 if (SubclassID > FilterTy::LastKnownFilterType)
278 return FilterTy::UnknownFilter;
280 return (enum FilterTy)SubclassID;
283 const char *GetFilterName() { return FilterTyToName(GetFilterTy()); }
285 static const char *FilterTyToName(enum FilterTy);
287 static FilterTy NameToFilterTy(llvm::StringRef name);
290 // Serialization of SearchFilter options:
291 enum OptionNames { ModList = 0, CUList, LanguageName, LastOptionName };
292 static const char *g_option_names[LastOptionName];
294 static const char *GetKey(enum OptionNames enum_value) {
295 return g_option_names[enum_value];
298 StructuredData::DictionarySP
299 WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
301 void SerializeFileSpecList(StructuredData::DictionarySP &options_dict_sp,
302 OptionNames name, FileSpecList &file_list);
304 // These are utility functions to assist with the search iteration. They are
305 // used by the default Search method.
307 Searcher::CallbackReturn DoModuleIteration(const SymbolContext &context,
310 Searcher::CallbackReturn DoModuleIteration(const lldb::ModuleSP &module_sp,
313 Searcher::CallbackReturn DoCUIteration(const lldb::ModuleSP &module_sp,
314 const SymbolContext &context,
317 Searcher::CallbackReturn DoFunctionIteration(Function *function,
318 const SymbolContext &context,
321 virtual lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) = 0;
323 void SetTarget(lldb::TargetSP &target_sp) { m_target_sp = target_sp; }
326 m_target_sp; // Every filter has to be associated with a target for
327 // now since you need a starting place for the search.
329 unsigned char SubclassID;
332 //----------------------------------------------------------------------
333 /// @class SearchFilterForUnconstrainedSearches SearchFilter.h
334 /// "lldb/Core/SearchFilter.h" This is a SearchFilter that searches through
335 /// all modules. It also consults the
336 /// Target::ModuleIsExcludedForUnconstrainedSearches.
337 //----------------------------------------------------------------------
338 class SearchFilterForUnconstrainedSearches : public SearchFilter {
340 SearchFilterForUnconstrainedSearches(const lldb::TargetSP &target_sp)
341 : SearchFilter(target_sp, FilterTy::Unconstrained) {}
343 ~SearchFilterForUnconstrainedSearches() override = default;
345 bool ModulePasses(const FileSpec &module_spec) override;
347 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
349 static lldb::SearchFilterSP
350 CreateFromStructuredData(Target &target,
351 const StructuredData::Dictionary &data_dict,
354 StructuredData::ObjectSP SerializeToStructuredData() override;
357 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
360 //----------------------------------------------------------------------
361 /// @class SearchFilterByModule SearchFilter.h "lldb/Core/SearchFilter.h" This
362 /// is a SearchFilter that restricts the search to a given module.
363 //----------------------------------------------------------------------
365 class SearchFilterByModule : public SearchFilter {
367 //------------------------------------------------------------------
368 /// The basic constructor takes a Target, which gives the space to search,
369 /// and the module to restrict the search to.
371 /// @param[in] target
372 /// The Target that provides the module list to search.
374 /// @param[in] module
375 /// The Module that limits the search.
376 //------------------------------------------------------------------
377 SearchFilterByModule(const lldb::TargetSP &targetSP, const FileSpec &module);
379 SearchFilterByModule(const SearchFilterByModule &rhs);
381 ~SearchFilterByModule() override;
383 SearchFilterByModule &operator=(const SearchFilterByModule &rhs);
385 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
387 bool ModulePasses(const FileSpec &spec) override;
389 bool AddressPasses(Address &address) override;
391 bool CompUnitPasses(FileSpec &fileSpec) override;
393 bool CompUnitPasses(CompileUnit &compUnit) override;
395 void GetDescription(Stream *s) override;
397 uint32_t GetFilterRequiredItems() override;
399 void Dump(Stream *s) const override;
401 void Search(Searcher &searcher) override;
403 static lldb::SearchFilterSP
404 CreateFromStructuredData(Target &target,
405 const StructuredData::Dictionary &data_dict,
408 StructuredData::ObjectSP SerializeToStructuredData() override;
411 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
414 FileSpec m_module_spec;
417 class SearchFilterByModuleList : public SearchFilter {
419 //------------------------------------------------------------------
420 /// The basic constructor takes a Target, which gives the space to search,
421 /// and the module list to restrict the search to.
423 /// @param[in] target
424 /// The Target that provides the module list to search.
426 /// @param[in] module
427 /// The Module that limits the search.
428 //------------------------------------------------------------------
429 SearchFilterByModuleList(const lldb::TargetSP &targetSP,
430 const FileSpecList &module_list);
432 SearchFilterByModuleList(const lldb::TargetSP &targetSP,
433 const FileSpecList &module_list,
434 enum FilterTy filter_ty);
436 SearchFilterByModuleList(const SearchFilterByModuleList &rhs);
438 ~SearchFilterByModuleList() override;
440 SearchFilterByModuleList &operator=(const SearchFilterByModuleList &rhs);
442 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
444 bool ModulePasses(const FileSpec &spec) override;
446 bool AddressPasses(Address &address) override;
448 bool CompUnitPasses(FileSpec &fileSpec) override;
450 bool CompUnitPasses(CompileUnit &compUnit) override;
452 void GetDescription(Stream *s) override;
454 uint32_t GetFilterRequiredItems() override;
456 void Dump(Stream *s) const override;
458 void Search(Searcher &searcher) override;
460 static lldb::SearchFilterSP
461 CreateFromStructuredData(Target &target,
462 const StructuredData::Dictionary &data_dict,
465 StructuredData::ObjectSP SerializeToStructuredData() override;
467 void SerializeUnwrapped(StructuredData::DictionarySP &options_dict_sp);
470 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
473 FileSpecList m_module_spec_list;
476 class SearchFilterByModuleListAndCU : public SearchFilterByModuleList {
478 //------------------------------------------------------------------
479 /// The basic constructor takes a Target, which gives the space to search,
480 /// and the module list to restrict the search to.
482 /// @param[in] target
483 /// The Target that provides the module list to search.
485 /// @param[in] module
486 /// The Module that limits the search.
487 //------------------------------------------------------------------
488 SearchFilterByModuleListAndCU(const lldb::TargetSP &targetSP,
489 const FileSpecList &module_list,
490 const FileSpecList &cu_list);
492 SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU &rhs);
494 ~SearchFilterByModuleListAndCU() override;
496 SearchFilterByModuleListAndCU &
497 operator=(const SearchFilterByModuleListAndCU &rhs);
499 bool AddressPasses(Address &address) override;
501 bool CompUnitPasses(FileSpec &fileSpec) override;
503 bool CompUnitPasses(CompileUnit &compUnit) override;
505 void GetDescription(Stream *s) override;
507 uint32_t GetFilterRequiredItems() override;
509 void Dump(Stream *s) const override;
511 void Search(Searcher &searcher) override;
513 static lldb::SearchFilterSP
514 CreateFromStructuredData(Target &target,
515 const StructuredData::Dictionary &data_dict,
518 StructuredData::ObjectSP SerializeToStructuredData() override;
521 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
524 FileSpecList m_cu_spec_list;
527 } // namespace lldb_private
529 #endif // liblldb_SearchFilter_h_