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" // for FileSpec
17 #include "lldb/lldb-forward.h" // for SearchFilterSP, TargetSP, Modu...
19 #include <stdint.h> // for uint32_t
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"
56 /// @brief Class that is driven by the SearchFilter to search the
57 /// SymbolContext space of the target program.
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
86 virtual CallbackReturn SearchCallback(SearchFilter &filter,
87 SymbolContext &context, Address *addr,
90 virtual Depth GetDepth() = 0;
92 //------------------------------------------------------------------
93 /// Prints a canonical description for the searcher to the stream \a s.
96 /// Stream to which the output is copied.
97 //------------------------------------------------------------------
98 virtual void GetDescription(Stream *s);
101 //----------------------------------------------------------------------
102 /// @class SearchFilter SearchFilter.h "lldb/Core/SearchFilter.h"
103 /// @brief Class descends through the SymbolContext space of the target,
104 /// applying a filter at each stage till it reaches the depth specified by
105 /// the GetDepth method of the searcher, and calls its callback at that point.
106 //----------------------------------------------------------------------
108 //----------------------------------------------------------------------
110 /// Provides the callback and search depth for the SearchFilter search.
112 /// The search is done by cooperation between the search filter and the
114 /// The search filter does the heavy work of recursing through the SymbolContext
115 /// space of the target program's symbol space. The Searcher specifies the
117 /// at which it wants its callback to be invoked. Note that since the
119 /// of the Searcher may be greater than that of the SearchFilter, before the
120 /// Searcher qualifies an address it should pass it to "AddressPasses."
121 /// The default implementation is "Everything Passes."
122 //----------------------------------------------------------------------
126 //------------------------------------------------------------------
127 /// The basic constructor takes a Target, which gives the space to search.
129 /// @param[in] target
130 /// The Target that provides the module list to search.
131 //------------------------------------------------------------------
132 SearchFilter(const lldb::TargetSP &target_sp);
134 SearchFilter(const SearchFilter &rhs);
136 SearchFilter(const lldb::TargetSP &target_sp, unsigned char filterType);
138 virtual ~SearchFilter();
140 SearchFilter &operator=(const SearchFilter &rhs);
142 //------------------------------------------------------------------
143 /// Call this method with a file spec to see if that spec passes the filter.
146 /// The file spec to check against the filter.
148 /// \b true if \a spec passes, and \b false otherwise.
149 //------------------------------------------------------------------
150 virtual bool ModulePasses(const FileSpec &spec);
152 //------------------------------------------------------------------
153 /// Call this method with a Module to see if that module passes the filter.
155 /// @param[in] module
156 /// The Module to check against the filter.
159 /// \b true if \a module passes, and \b false otherwise.
160 //------------------------------------------------------------------
161 virtual bool ModulePasses(const lldb::ModuleSP &module_sp);
163 //------------------------------------------------------------------
164 /// Call this method with a Address to see if \a address passes the filter.
167 /// The address to check against the filter.
170 /// \b true if \a address passes, and \b false otherwise.
171 //------------------------------------------------------------------
172 virtual bool AddressPasses(Address &addr);
174 //------------------------------------------------------------------
175 /// Call this method with a FileSpec to see if \a file spec passes the filter
176 /// as the name of a compilation unit.
178 /// @param[in] fileSpec
179 /// The file spec to check against the filter.
182 /// \b true if \a file spec passes, and \b false otherwise.
183 //------------------------------------------------------------------
184 virtual bool CompUnitPasses(FileSpec &fileSpec);
186 //------------------------------------------------------------------
187 /// Call this method with a CompileUnit to see if \a comp unit passes the
190 /// @param[in] compUnit
191 /// The CompileUnit to check against the filter.
194 /// \b true if \a Comp Unit passes, and \b false otherwise.
195 //------------------------------------------------------------------
196 virtual bool CompUnitPasses(CompileUnit &compUnit);
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.
222 /// For instance, if you are filtering by Compilation Unit, obviously
223 /// symbols that have no compilation unit can't pass So return
225 /// and search callbacks can then short cut the search to avoid looking at
226 /// things that obviously won't pass.
229 /// The required elements for the search, which is an or'ed together
230 /// set of lldb:SearchContextItem enum's.
232 //------------------------------------------------------------------
233 virtual uint32_t GetFilterRequiredItems();
235 //------------------------------------------------------------------
236 /// Prints a canonical description for the search filter to the stream \a s.
239 /// Stream to which the output is copied.
240 //------------------------------------------------------------------
241 virtual void GetDescription(Stream *s);
243 //------------------------------------------------------------------
244 /// Standard "Dump" method. At present it does nothing.
245 //------------------------------------------------------------------
246 virtual void Dump(Stream *s) const;
248 lldb::SearchFilterSP CopyForBreakpoint(Breakpoint &breakpoint);
250 static lldb::SearchFilterSP
251 CreateFromStructuredData(Target &target,
252 const StructuredData::Dictionary &data_dict,
255 virtual StructuredData::ObjectSP SerializeToStructuredData() {
256 return StructuredData::ObjectSP();
259 static const char *GetSerializationKey() { return "SearchFilter"; }
261 static const char *GetSerializationSubclassKey() { return "Type"; }
263 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
271 LastKnownFilterType = ByModulesAndCU,
275 static const char *g_ty_to_name[LastKnownFilterType + 2];
277 enum FilterTy GetFilterTy() {
278 if (SubclassID > FilterTy::LastKnownFilterType)
279 return FilterTy::UnknownFilter;
281 return (enum FilterTy)SubclassID;
284 const char *GetFilterName() { return FilterTyToName(GetFilterTy()); }
286 static const char *FilterTyToName(enum FilterTy);
288 static FilterTy NameToFilterTy(llvm::StringRef name);
291 // Serialization of SearchFilter options:
292 enum OptionNames { ModList = 0, CUList, LanguageName, LastOptionName };
293 static const char *g_option_names[LastOptionName];
295 static const char *GetKey(enum OptionNames enum_value) {
296 return g_option_names[enum_value];
299 StructuredData::DictionarySP
300 WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
302 void SerializeFileSpecList(StructuredData::DictionarySP &options_dict_sp,
303 OptionNames name, FileSpecList &file_list);
305 // These are utility functions to assist with the search iteration. They are
307 // default Search method.
309 Searcher::CallbackReturn DoModuleIteration(const SymbolContext &context,
312 Searcher::CallbackReturn DoModuleIteration(const lldb::ModuleSP &module_sp,
315 Searcher::CallbackReturn DoCUIteration(const lldb::ModuleSP &module_sp,
316 const SymbolContext &context,
319 Searcher::CallbackReturn DoFunctionIteration(Function *function,
320 const SymbolContext &context,
323 virtual lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) = 0;
325 void SetTarget(lldb::TargetSP &target_sp) { m_target_sp = target_sp; }
328 m_target_sp; // Every filter has to be associated with a target for
329 // now since you need a starting place for the search.
331 unsigned char SubclassID;
334 //----------------------------------------------------------------------
335 /// @class SearchFilterForUnconstrainedSearches SearchFilter.h
336 /// "lldb/Core/SearchFilter.h"
337 /// @brief This is a SearchFilter that searches through all modules. It also
338 /// consults the Target::ModuleIsExcludedForUnconstrainedSearches.
339 //----------------------------------------------------------------------
340 class SearchFilterForUnconstrainedSearches : public SearchFilter {
342 SearchFilterForUnconstrainedSearches(const lldb::TargetSP &target_sp)
343 : SearchFilter(target_sp, FilterTy::Unconstrained) {}
345 ~SearchFilterForUnconstrainedSearches() override = default;
347 bool ModulePasses(const FileSpec &module_spec) override;
349 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
351 static lldb::SearchFilterSP
352 CreateFromStructuredData(Target &target,
353 const StructuredData::Dictionary &data_dict,
356 StructuredData::ObjectSP SerializeToStructuredData() override;
359 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
362 //----------------------------------------------------------------------
363 /// @class SearchFilterByModule SearchFilter.h "lldb/Core/SearchFilter.h"
364 /// @brief This is a SearchFilter that restricts the search to a given module.
365 //----------------------------------------------------------------------
367 class SearchFilterByModule : public SearchFilter {
369 //------------------------------------------------------------------
370 /// The basic constructor takes a Target, which gives the space to search,
371 /// and the module to restrict the search to.
373 /// @param[in] target
374 /// The Target that provides the module list to search.
376 /// @param[in] module
377 /// The Module that limits the search.
378 //------------------------------------------------------------------
379 SearchFilterByModule(const lldb::TargetSP &targetSP, const FileSpec &module);
381 SearchFilterByModule(const SearchFilterByModule &rhs);
383 ~SearchFilterByModule() override;
385 SearchFilterByModule &operator=(const SearchFilterByModule &rhs);
387 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
389 bool ModulePasses(const FileSpec &spec) override;
391 bool AddressPasses(Address &address) override;
393 bool CompUnitPasses(FileSpec &fileSpec) override;
395 bool CompUnitPasses(CompileUnit &compUnit) override;
397 void GetDescription(Stream *s) override;
399 uint32_t GetFilterRequiredItems() override;
401 void Dump(Stream *s) const override;
403 void Search(Searcher &searcher) override;
405 static lldb::SearchFilterSP
406 CreateFromStructuredData(Target &target,
407 const StructuredData::Dictionary &data_dict,
410 StructuredData::ObjectSP SerializeToStructuredData() override;
413 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
416 FileSpec m_module_spec;
419 class SearchFilterByModuleList : public SearchFilter {
421 //------------------------------------------------------------------
422 /// The basic constructor takes a Target, which gives the space to search,
423 /// and the module list to restrict the search to.
425 /// @param[in] target
426 /// The Target that provides the module list to search.
428 /// @param[in] module
429 /// The Module that limits the search.
430 //------------------------------------------------------------------
431 SearchFilterByModuleList(const lldb::TargetSP &targetSP,
432 const FileSpecList &module_list);
434 SearchFilterByModuleList(const lldb::TargetSP &targetSP,
435 const FileSpecList &module_list,
436 enum FilterTy filter_ty);
438 SearchFilterByModuleList(const SearchFilterByModuleList &rhs);
440 ~SearchFilterByModuleList() override;
442 SearchFilterByModuleList &operator=(const SearchFilterByModuleList &rhs);
444 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
446 bool ModulePasses(const FileSpec &spec) override;
448 bool AddressPasses(Address &address) override;
450 bool CompUnitPasses(FileSpec &fileSpec) override;
452 bool CompUnitPasses(CompileUnit &compUnit) override;
454 void GetDescription(Stream *s) override;
456 uint32_t GetFilterRequiredItems() override;
458 void Dump(Stream *s) const override;
460 void Search(Searcher &searcher) override;
462 static lldb::SearchFilterSP
463 CreateFromStructuredData(Target &target,
464 const StructuredData::Dictionary &data_dict,
467 StructuredData::ObjectSP SerializeToStructuredData() override;
469 void SerializeUnwrapped(StructuredData::DictionarySP &options_dict_sp);
472 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
475 FileSpecList m_module_spec_list;
478 class SearchFilterByModuleListAndCU : public SearchFilterByModuleList {
480 //------------------------------------------------------------------
481 /// The basic constructor takes a Target, which gives the space to search,
482 /// and the module list to restrict the search to.
484 /// @param[in] target
485 /// The Target that provides the module list to search.
487 /// @param[in] module
488 /// The Module that limits the search.
489 //------------------------------------------------------------------
490 SearchFilterByModuleListAndCU(const lldb::TargetSP &targetSP,
491 const FileSpecList &module_list,
492 const FileSpecList &cu_list);
494 SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU &rhs);
496 ~SearchFilterByModuleListAndCU() override;
498 SearchFilterByModuleListAndCU &
499 operator=(const SearchFilterByModuleListAndCU &rhs);
501 bool AddressPasses(Address &address) override;
503 bool CompUnitPasses(FileSpec &fileSpec) override;
505 bool CompUnitPasses(CompileUnit &compUnit) override;
507 void GetDescription(Stream *s) override;
509 uint32_t GetFilterRequiredItems() override;
511 void Dump(Stream *s) const override;
513 void Search(Searcher &searcher) override;
515 static lldb::SearchFilterSP
516 CreateFromStructuredData(Target &target,
517 const StructuredData::Dictionary &data_dict,
520 StructuredData::ObjectSP SerializeToStructuredData() override;
523 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
526 FileSpecList m_cu_spec_list;
529 } // namespace lldb_private
531 #endif // liblldb_SearchFilter_h_