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" 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
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" Class
103 /// descends through the SymbolContext space of the target, applying a filter
104 /// at each stage till it reaches the depth specified by the GetDepth method
105 /// 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
113 /// searcher. The search filter does the heavy work of recursing through the
114 /// SymbolContext space of the target program's symbol space. The Searcher
115 /// specifies the depth at which it wants its callback to be invoked. Note
116 /// that since the resolution of the Searcher may be greater than that of the
117 /// SearchFilter, before the Searcher qualifies an address it should pass it
118 /// to "AddressPasses." The default implementation is "Everything Passes."
119 //----------------------------------------------------------------------
123 //------------------------------------------------------------------
124 /// The basic constructor takes a Target, which gives the space to search.
126 /// @param[in] target
127 /// The Target that provides the module list to search.
128 //------------------------------------------------------------------
129 SearchFilter(const lldb::TargetSP &target_sp);
131 SearchFilter(const SearchFilter &rhs);
133 SearchFilter(const lldb::TargetSP &target_sp, unsigned char filterType);
135 virtual ~SearchFilter();
137 SearchFilter &operator=(const SearchFilter &rhs);
139 //------------------------------------------------------------------
140 /// Call this method with a file spec to see if that spec passes the filter.
143 /// The file spec to check against the filter.
145 /// \b true if \a spec passes, and \b false otherwise.
146 //------------------------------------------------------------------
147 virtual bool ModulePasses(const FileSpec &spec);
149 //------------------------------------------------------------------
150 /// Call this method with a Module to see if that module passes the filter.
152 /// @param[in] module
153 /// The Module to check against the filter.
156 /// \b true if \a module passes, and \b false otherwise.
157 //------------------------------------------------------------------
158 virtual bool ModulePasses(const lldb::ModuleSP &module_sp);
160 //------------------------------------------------------------------
161 /// Call this method with a Address to see if \a address passes the filter.
164 /// The address to check against the filter.
167 /// \b true if \a address passes, and \b false otherwise.
168 //------------------------------------------------------------------
169 virtual bool AddressPasses(Address &addr);
171 //------------------------------------------------------------------
172 /// Call this method with a FileSpec to see if \a file spec passes the
173 /// filter as the name of a compilation unit.
175 /// @param[in] fileSpec
176 /// The file spec to check against the filter.
179 /// \b true if \a file spec passes, and \b false otherwise.
180 //------------------------------------------------------------------
181 virtual bool CompUnitPasses(FileSpec &fileSpec);
183 //------------------------------------------------------------------
184 /// Call this method with a CompileUnit to see if \a comp unit passes the
187 /// @param[in] compUnit
188 /// The CompileUnit to check against the filter.
191 /// \b true if \a Comp Unit passes, and \b false otherwise.
192 //------------------------------------------------------------------
193 virtual bool CompUnitPasses(CompileUnit &compUnit);
195 //------------------------------------------------------------------
196 /// Call this method to do the search using the Searcher.
198 /// @param[in] searcher
199 /// The searcher to drive with this search.
201 //------------------------------------------------------------------
202 virtual void Search(Searcher &searcher);
204 //------------------------------------------------------------------
205 /// Call this method to do the search using the Searcher in the module list
208 /// @param[in] searcher
209 /// The searcher to drive with this search.
211 /// @param[in] modules
212 /// The module list within which to restrict the search.
214 //------------------------------------------------------------------
215 virtual void SearchInModuleList(Searcher &searcher, ModuleList &modules);
217 //------------------------------------------------------------------
218 /// This determines which items are REQUIRED for the filter to pass. For
219 /// instance, if you are filtering by Compilation Unit, obviously symbols
220 /// that have no compilation unit can't pass So return eSymbolContextCU and
221 /// search callbacks can then short cut the search to avoid looking at
222 /// things that obviously won't pass.
225 /// The required elements for the search, which is an or'ed together
226 /// set of lldb:SearchContextItem enum's.
228 //------------------------------------------------------------------
229 virtual uint32_t GetFilterRequiredItems();
231 //------------------------------------------------------------------
232 /// Prints a canonical description for the search filter to the stream \a s.
235 /// Stream to which the output is copied.
236 //------------------------------------------------------------------
237 virtual void GetDescription(Stream *s);
239 //------------------------------------------------------------------
240 /// Standard "Dump" method. At present it does nothing.
241 //------------------------------------------------------------------
242 virtual void Dump(Stream *s) const;
244 lldb::SearchFilterSP CopyForBreakpoint(Breakpoint &breakpoint);
246 static lldb::SearchFilterSP
247 CreateFromStructuredData(Target &target,
248 const StructuredData::Dictionary &data_dict,
251 virtual StructuredData::ObjectSP SerializeToStructuredData() {
252 return StructuredData::ObjectSP();
255 static const char *GetSerializationKey() { return "SearchFilter"; }
257 static const char *GetSerializationSubclassKey() { return "Type"; }
259 static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
267 LastKnownFilterType = ByModulesAndCU,
271 static const char *g_ty_to_name[LastKnownFilterType + 2];
273 enum FilterTy GetFilterTy() {
274 if (SubclassID > FilterTy::LastKnownFilterType)
275 return FilterTy::UnknownFilter;
277 return (enum FilterTy)SubclassID;
280 const char *GetFilterName() { return FilterTyToName(GetFilterTy()); }
282 static const char *FilterTyToName(enum FilterTy);
284 static FilterTy NameToFilterTy(llvm::StringRef name);
287 // Serialization of SearchFilter options:
288 enum OptionNames { ModList = 0, CUList, LanguageName, LastOptionName };
289 static const char *g_option_names[LastOptionName];
291 static const char *GetKey(enum OptionNames enum_value) {
292 return g_option_names[enum_value];
295 StructuredData::DictionarySP
296 WrapOptionsDict(StructuredData::DictionarySP options_dict_sp);
298 void SerializeFileSpecList(StructuredData::DictionarySP &options_dict_sp,
299 OptionNames name, FileSpecList &file_list);
301 // These are utility functions to assist with the search iteration. They are
302 // used by the default Search method.
304 Searcher::CallbackReturn DoModuleIteration(const SymbolContext &context,
307 Searcher::CallbackReturn DoModuleIteration(const lldb::ModuleSP &module_sp,
310 Searcher::CallbackReturn DoCUIteration(const lldb::ModuleSP &module_sp,
311 const SymbolContext &context,
314 Searcher::CallbackReturn DoFunctionIteration(Function *function,
315 const SymbolContext &context,
318 virtual lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) = 0;
320 void SetTarget(lldb::TargetSP &target_sp) { m_target_sp = target_sp; }
323 m_target_sp; // Every filter has to be associated with a target for
324 // now since you need a starting place for the search.
326 unsigned char SubclassID;
329 //----------------------------------------------------------------------
330 /// @class SearchFilterForUnconstrainedSearches SearchFilter.h
331 /// "lldb/Core/SearchFilter.h" This is a SearchFilter that searches through
332 /// all modules. It also consults the
333 /// Target::ModuleIsExcludedForUnconstrainedSearches.
334 //----------------------------------------------------------------------
335 class SearchFilterForUnconstrainedSearches : public SearchFilter {
337 SearchFilterForUnconstrainedSearches(const lldb::TargetSP &target_sp)
338 : SearchFilter(target_sp, FilterTy::Unconstrained) {}
340 ~SearchFilterForUnconstrainedSearches() override = default;
342 bool ModulePasses(const FileSpec &module_spec) override;
344 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
346 static lldb::SearchFilterSP
347 CreateFromStructuredData(Target &target,
348 const StructuredData::Dictionary &data_dict,
351 StructuredData::ObjectSP SerializeToStructuredData() override;
354 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
357 //----------------------------------------------------------------------
358 /// @class SearchFilterByModule SearchFilter.h "lldb/Core/SearchFilter.h" This
359 /// is a SearchFilter that restricts the search to a given module.
360 //----------------------------------------------------------------------
362 class SearchFilterByModule : public SearchFilter {
364 //------------------------------------------------------------------
365 /// The basic constructor takes a Target, which gives the space to search,
366 /// and the module to restrict the search to.
368 /// @param[in] target
369 /// The Target that provides the module list to search.
371 /// @param[in] module
372 /// The Module that limits the search.
373 //------------------------------------------------------------------
374 SearchFilterByModule(const lldb::TargetSP &targetSP, const FileSpec &module);
376 SearchFilterByModule(const SearchFilterByModule &rhs);
378 ~SearchFilterByModule() override;
380 SearchFilterByModule &operator=(const SearchFilterByModule &rhs);
382 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
384 bool ModulePasses(const FileSpec &spec) override;
386 bool AddressPasses(Address &address) override;
388 bool CompUnitPasses(FileSpec &fileSpec) override;
390 bool CompUnitPasses(CompileUnit &compUnit) override;
392 void GetDescription(Stream *s) override;
394 uint32_t GetFilterRequiredItems() override;
396 void Dump(Stream *s) const override;
398 void Search(Searcher &searcher) override;
400 static lldb::SearchFilterSP
401 CreateFromStructuredData(Target &target,
402 const StructuredData::Dictionary &data_dict,
405 StructuredData::ObjectSP SerializeToStructuredData() override;
408 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
411 FileSpec m_module_spec;
414 class SearchFilterByModuleList : public SearchFilter {
416 //------------------------------------------------------------------
417 /// The basic constructor takes a Target, which gives the space to search,
418 /// and the module list to restrict the search to.
420 /// @param[in] target
421 /// The Target that provides the module list to search.
423 /// @param[in] module
424 /// The Module that limits the search.
425 //------------------------------------------------------------------
426 SearchFilterByModuleList(const lldb::TargetSP &targetSP,
427 const FileSpecList &module_list);
429 SearchFilterByModuleList(const lldb::TargetSP &targetSP,
430 const FileSpecList &module_list,
431 enum FilterTy filter_ty);
433 SearchFilterByModuleList(const SearchFilterByModuleList &rhs);
435 ~SearchFilterByModuleList() override;
437 SearchFilterByModuleList &operator=(const SearchFilterByModuleList &rhs);
439 bool ModulePasses(const lldb::ModuleSP &module_sp) override;
441 bool ModulePasses(const FileSpec &spec) override;
443 bool AddressPasses(Address &address) override;
445 bool CompUnitPasses(FileSpec &fileSpec) override;
447 bool CompUnitPasses(CompileUnit &compUnit) override;
449 void GetDescription(Stream *s) override;
451 uint32_t GetFilterRequiredItems() override;
453 void Dump(Stream *s) const override;
455 void Search(Searcher &searcher) override;
457 static lldb::SearchFilterSP
458 CreateFromStructuredData(Target &target,
459 const StructuredData::Dictionary &data_dict,
462 StructuredData::ObjectSP SerializeToStructuredData() override;
464 void SerializeUnwrapped(StructuredData::DictionarySP &options_dict_sp);
467 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
470 FileSpecList m_module_spec_list;
473 class SearchFilterByModuleListAndCU : public SearchFilterByModuleList {
475 //------------------------------------------------------------------
476 /// The basic constructor takes a Target, which gives the space to search,
477 /// and the module list to restrict the search to.
479 /// @param[in] target
480 /// The Target that provides the module list to search.
482 /// @param[in] module
483 /// The Module that limits the search.
484 //------------------------------------------------------------------
485 SearchFilterByModuleListAndCU(const lldb::TargetSP &targetSP,
486 const FileSpecList &module_list,
487 const FileSpecList &cu_list);
489 SearchFilterByModuleListAndCU(const SearchFilterByModuleListAndCU &rhs);
491 ~SearchFilterByModuleListAndCU() override;
493 SearchFilterByModuleListAndCU &
494 operator=(const SearchFilterByModuleListAndCU &rhs);
496 bool AddressPasses(Address &address) override;
498 bool CompUnitPasses(FileSpec &fileSpec) override;
500 bool CompUnitPasses(CompileUnit &compUnit) override;
502 void GetDescription(Stream *s) override;
504 uint32_t GetFilterRequiredItems() override;
506 void Dump(Stream *s) const override;
508 void Search(Searcher &searcher) override;
510 static lldb::SearchFilterSP
511 CreateFromStructuredData(Target &target,
512 const StructuredData::Dictionary &data_dict,
515 StructuredData::ObjectSP SerializeToStructuredData() override;
518 lldb::SearchFilterSP DoCopyForBreakpoint(Breakpoint &breakpoint) override;
521 FileSpecList m_cu_spec_list;
524 } // namespace lldb_private
526 #endif // liblldb_SearchFilter_h_