LLDB  mainline
SearchFilter.cpp
Go to the documentation of this file.
1 //===-- SearchFilter.cpp --------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/ModuleList.h"
16 #include "lldb/Symbol/SymbolFile.h"
17 #include "lldb/Target/Target.h"
19 #include "lldb/Utility/Status.h"
20 #include "lldb/Utility/Stream.h"
21 #include "lldb/lldb-enumerations.h"
22 
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/ErrorHandling.h"
25 
26 #include <memory>
27 #include <mutex>
28 #include <string>
29 
30 #include <cinttypes>
31 #include <cstring>
32 
33 namespace lldb_private {
34 class Address;
35 }
36 namespace lldb_private {
37 class Function;
38 }
39 
40 using namespace lldb;
41 using namespace lldb_private;
42 
43 const char *SearchFilter::g_ty_to_name[] = {"Unconstrained", "Exception",
44  "Module", "Modules",
45  "ModulesAndCU", "Unknown"};
46 
47 const char
48  *SearchFilter::g_option_names[SearchFilter::OptionNames::LastOptionName] = {
49  "ModuleList", "CUList"};
50 
51 const char *SearchFilter::FilterTyToName(enum FilterTy type) {
52  if (type > LastKnownFilterType)
53  return g_ty_to_name[UnknownFilter];
54 
55  return g_ty_to_name[type];
56 }
57 
58 SearchFilter::FilterTy SearchFilter::NameToFilterTy(llvm::StringRef name) {
59  for (size_t i = 0; i <= LastKnownFilterType; i++) {
60  if (name == g_ty_to_name[i])
61  return (FilterTy)i;
62  }
63  return UnknownFilter;
64 }
65 
66 Searcher::Searcher() = default;
67 
68 Searcher::~Searcher() = default;
69 
70 void Searcher::GetDescription(Stream *s) {}
71 
72 SearchFilter::SearchFilter(const TargetSP &target_sp, unsigned char filterType)
73  : m_target_sp(target_sp), SubclassID(filterType) {}
74 
75 SearchFilter::~SearchFilter() = default;
76 
78  const lldb::TargetSP& target_sp,
79  const StructuredData::Dictionary &filter_dict,
80  Status &error) {
81  SearchFilterSP result_sp;
82  if (!filter_dict.IsValid()) {
83  error.SetErrorString("Can't deserialize from an invalid data object.");
84  return result_sp;
85  }
86 
87  llvm::StringRef subclass_name;
88 
89  bool success = filter_dict.GetValueForKeyAsString(
90  GetSerializationSubclassKey(), subclass_name);
91  if (!success) {
92  error.SetErrorString("Filter data missing subclass key");
93  return result_sp;
94  }
95 
96  FilterTy filter_type = NameToFilterTy(subclass_name);
97  if (filter_type == UnknownFilter) {
98  error.SetErrorStringWithFormatv("Unknown filter type: {0}.", subclass_name);
99  return result_sp;
100  }
101 
102  StructuredData::Dictionary *subclass_options = nullptr;
103  success = filter_dict.GetValueForKeyAsDictionary(
104  GetSerializationSubclassOptionsKey(), subclass_options);
105  if (!success || !subclass_options || !subclass_options->IsValid()) {
106  error.SetErrorString("Filter data missing subclass options key.");
107  return result_sp;
108  }
109 
110  switch (filter_type) {
111  case Unconstrained:
113  target_sp, *subclass_options, error);
114  break;
115  case ByModule:
117  target_sp, *subclass_options, error);
118  break;
119  case ByModules:
121  target_sp, *subclass_options, error);
122  break;
123  case ByModulesAndCU:
125  target_sp, *subclass_options, error);
126  break;
127  case Exception:
128  error.SetErrorString("Can't serialize exception breakpoints yet.");
129  break;
130  default:
131  llvm_unreachable("Should never get an uresolvable filter type.");
132  }
133 
134  return result_sp;
135 }
136 
137 bool SearchFilter::ModulePasses(const FileSpec &spec) { return true; }
138 
139 bool SearchFilter::ModulePasses(const ModuleSP &module_sp) { return true; }
140 
141 bool SearchFilter::AddressPasses(Address &address) { return true; }
142 
143 bool SearchFilter::CompUnitPasses(FileSpec &fileSpec) { return true; }
144 
145 bool SearchFilter::CompUnitPasses(CompileUnit &compUnit) { return true; }
146 
148  // This is a slightly cheesy job, but since we don't have finer grained
149  // filters yet, just checking that the start address passes is probably
150  // good enough for the base class behavior.
151  Address addr = function.GetAddressRange().GetBaseAddress();
152  return AddressPasses(addr);
153 }
154 
155 
157  return (lldb::SymbolContextItem)0;
158 }
159 
161 
162 void SearchFilter::Dump(Stream *s) const {}
163 
164 lldb::SearchFilterSP SearchFilter::CreateCopy(lldb::TargetSP& target_sp) {
165  SearchFilterSP ret_sp = DoCreateCopy();
166  ret_sp->SetTarget(target_sp);
167  return ret_sp;
168 }
169 
170 // Helper functions for serialization.
171 
174  if (!options_dict_sp || !options_dict_sp->IsValid())
176 
177  auto type_dict_sp = std::make_shared<StructuredData::Dictionary>();
178  type_dict_sp->AddStringItem(GetSerializationSubclassKey(), GetFilterName());
179  type_dict_sp->AddItem(GetSerializationSubclassOptionsKey(), options_dict_sp);
180 
181  return type_dict_sp;
182 }
183 
185  StructuredData::DictionarySP &options_dict_sp, OptionNames name,
186  FileSpecList &file_list) {
187  size_t num_modules = file_list.GetSize();
188 
189  // Don't serialize empty lists.
190  if (num_modules == 0)
191  return;
192 
193  auto module_array_sp = std::make_shared<StructuredData::Array>();
194  for (size_t i = 0; i < num_modules; i++) {
195  module_array_sp->AddItem(std::make_shared<StructuredData::String>(
196  file_list.GetFileSpecAtIndex(i).GetPath()));
197  }
198  options_dict_sp->AddItem(GetKey(name), module_array_sp);
199 }
200 
201 // UTILITY Functions to help iterate down through the elements of the
202 // SymbolContext.
203 
205  SymbolContext empty_sc;
206 
207  if (!m_target_sp)
208  return;
209  empty_sc.target_sp = m_target_sp;
210 
211  if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
212  searcher.SearchCallback(*this, empty_sc, nullptr);
213  return;
214  }
215 
216  DoModuleIteration(empty_sc, searcher);
217 }
218 
220  SymbolContext empty_sc;
221 
222  if (!m_target_sp)
223  return;
224  empty_sc.target_sp = m_target_sp;
225 
226  if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
227  searcher.SearchCallback(*this, empty_sc, nullptr);
228  return;
229  }
230 
231  for (ModuleSP module_sp : modules.Modules()) {
232  if (!ModulePasses(module_sp))
233  continue;
234  if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop)
235  return;
236  }
237 }
238 
240 SearchFilter::DoModuleIteration(const lldb::ModuleSP &module_sp,
241  Searcher &searcher) {
242  SymbolContext matchingContext(m_target_sp, module_sp);
243  return DoModuleIteration(matchingContext, searcher);
244 }
245 
248  Searcher &searcher) {
249  if (searcher.GetDepth() < lldb::eSearchDepthModule)
251 
252  if (context.module_sp) {
253  if (searcher.GetDepth() != lldb::eSearchDepthModule)
254  return DoCUIteration(context.module_sp, context, searcher);
255 
256  SymbolContext matchingContext(context.module_sp.get());
257  searcher.SearchCallback(*this, matchingContext, nullptr);
259  }
260 
261  for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
262  // If this is the last level supplied, then call the callback directly,
263  // otherwise descend.
264  if (!ModulePasses(module_sp))
265  continue;
266 
267  if (searcher.GetDepth() == lldb::eSearchDepthModule) {
268  SymbolContext matchingContext(m_target_sp, module_sp);
269 
270  Searcher::CallbackReturn shouldContinue =
271  searcher.SearchCallback(*this, matchingContext, nullptr);
272  if (shouldContinue == Searcher::eCallbackReturnStop ||
273  shouldContinue == Searcher::eCallbackReturnPop)
274  return shouldContinue;
275  } else {
276  Searcher::CallbackReturn shouldContinue =
277  DoCUIteration(module_sp, context, searcher);
278  if (shouldContinue == Searcher::eCallbackReturnStop)
279  return shouldContinue;
280  else if (shouldContinue == Searcher::eCallbackReturnPop)
281  continue;
282  }
283  }
284 
286 }
287 
289 SearchFilter::DoCUIteration(const ModuleSP &module_sp,
290  const SymbolContext &context, Searcher &searcher) {
291  Searcher::CallbackReturn shouldContinue;
292  if (context.comp_unit != nullptr) {
293  if (CompUnitPasses(*context.comp_unit)) {
294  SymbolContext matchingContext(m_target_sp, module_sp, context.comp_unit);
295  return searcher.SearchCallback(*this, matchingContext, nullptr);
296  }
298  }
299 
300  const size_t num_comp_units = module_sp->GetNumCompileUnits();
301  for (size_t i = 0; i < num_comp_units; i++) {
302  CompUnitSP cu_sp(module_sp->GetCompileUnitAtIndex(i));
303  if (!cu_sp)
304  continue;
305  if (!CompUnitPasses(*(cu_sp.get())))
306  continue;
307 
308  if (searcher.GetDepth() == lldb::eSearchDepthCompUnit) {
309  SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get());
310 
311  shouldContinue = searcher.SearchCallback(*this, matchingContext, nullptr);
312 
313  if (shouldContinue == Searcher::eCallbackReturnPop)
315  else if (shouldContinue == Searcher::eCallbackReturnStop)
316  return shouldContinue;
317  continue;
318  }
319 
320  // First make sure this compile unit's functions are parsed
321  // since CompUnit::ForeachFunction only iterates over already
322  // parsed functions.
323  SymbolFile *sym_file = module_sp->GetSymbolFile();
324  if (!sym_file)
325  continue;
326  if (!sym_file->ParseFunctions(*cu_sp))
327  continue;
328  // If we got any functions, use ForeachFunction to do the iteration.
329  cu_sp->ForeachFunction([&](const FunctionSP &func_sp) {
330  if (!FunctionPasses(*func_sp.get()))
331  return false; // Didn't pass the filter, just keep going.
332  if (searcher.GetDepth() == lldb::eSearchDepthFunction) {
333  SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get(),
334  func_sp.get());
335  shouldContinue =
336  searcher.SearchCallback(*this, matchingContext, nullptr);
337  } else {
338  shouldContinue = DoFunctionIteration(func_sp.get(), context, searcher);
339  }
340  return shouldContinue != Searcher::eCallbackReturnContinue;
341  });
342  }
344 }
345 
347  Function *function, const SymbolContext &context, Searcher &searcher) {
348  // FIXME: Implement...
350 }
351 
352 // SearchFilterForUnconstrainedSearches:
353 // Selects a shared library matching a given file spec, consulting the targets
354 // "black list".
356  const lldb::TargetSP& target_sp,
357  const StructuredData::Dictionary &data_dict,
358  Status &error) {
359  // No options for an unconstrained search.
360  return std::make_shared<SearchFilterForUnconstrainedSearches>(target_sp);
361 }
362 
365  // The options dictionary is an empty dictionary:
366  auto result_sp = std::make_shared<StructuredData::Dictionary>();
367  return WrapOptionsDict(result_sp);
368 }
369 
371  const FileSpec &module_spec) {
372  return !m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_spec);
373 }
374 
376  const lldb::ModuleSP &module_sp) {
377  if (!module_sp)
378  return true;
379  else if (m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_sp))
380  return false;
381  return true;
382 }
383 
385  return std::make_shared<SearchFilterForUnconstrainedSearches>(*this);
386 }
387 
388 // SearchFilterByModule:
389 // Selects a shared library matching a given file spec
390 
391 SearchFilterByModule::SearchFilterByModule(const lldb::TargetSP &target_sp,
392  const FileSpec &module)
393  : SearchFilter(target_sp, FilterTy::ByModule), m_module_spec(module) {}
394 
396 
397 bool SearchFilterByModule::ModulePasses(const ModuleSP &module_sp) {
398  return (module_sp &&
399  FileSpec::Match(m_module_spec, module_sp->GetFileSpec()));
400 }
401 
403  return FileSpec::Match(m_module_spec, spec);
404 }
405 
407  // FIXME: Not yet implemented
408  return true;
409 }
410 
412  if (!m_target_sp)
413  return;
414 
415  if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
416  SymbolContext empty_sc;
417  empty_sc.target_sp = m_target_sp;
418  searcher.SearchCallback(*this, empty_sc, nullptr);
419  }
420 
421  // If the module file spec is a full path, then we can just find the one
422  // filespec that passes. Otherwise, we need to go through all modules and
423  // find the ones that match the file name.
424 
425  const ModuleList &target_modules = m_target_sp->GetImages();
426  std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
427 
428  for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
429  if (FileSpec::Match(m_module_spec, module_sp->GetFileSpec())) {
430  SymbolContext matchingContext(m_target_sp, module_sp);
431  Searcher::CallbackReturn shouldContinue;
432 
433  shouldContinue = DoModuleIteration(matchingContext, searcher);
434  if (shouldContinue == Searcher::eCallbackReturnStop)
435  return;
436  }
437  }
438 }
439 
441  s->PutCString(", module = ");
442  s->PutCString(m_module_spec.GetFilename().AsCString("<Unknown>"));
443 }
444 
446  return eSymbolContextModule;
447 }
448 
450 
452  return std::make_shared<SearchFilterByModule>(*this);
453 }
454 
456  const lldb::TargetSP& target_sp,
457  const StructuredData::Dictionary &data_dict,
458  Status &error) {
459  StructuredData::Array *modules_array;
460  bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
461  modules_array);
462  if (!success) {
463  error.SetErrorString("SFBM::CFSD: Could not find the module list key.");
464  return nullptr;
465  }
466 
467  size_t num_modules = modules_array->GetSize();
468  if (num_modules > 1) {
469  error.SetErrorString(
470  "SFBM::CFSD: Only one modules allowed for SearchFilterByModule.");
471  return nullptr;
472  }
473 
474  llvm::StringRef module;
475  success = modules_array->GetItemAtIndexAsString(0, module);
476  if (!success) {
477  error.SetErrorString("SFBM::CFSD: filter module item not a string.");
478  return nullptr;
479  }
480  FileSpec module_spec(module);
481 
482  return std::make_shared<SearchFilterByModule>(target_sp, module_spec);
483 }
484 
486  auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
487  auto module_array_sp = std::make_shared<StructuredData::Array>();
488  module_array_sp->AddItem(
489  std::make_shared<StructuredData::String>(m_module_spec.GetPath()));
490  options_dict_sp->AddItem(GetKey(OptionNames::ModList), module_array_sp);
491  return WrapOptionsDict(options_dict_sp);
492 }
493 
494 // SearchFilterByModuleList:
495 // Selects a shared library matching a given file spec
496 
498  const lldb::TargetSP &target_sp, const FileSpecList &module_list)
499  : SearchFilter(target_sp, FilterTy::ByModules),
500  m_module_spec_list(module_list) {}
501 
503  const lldb::TargetSP &target_sp, const FileSpecList &module_list,
504  enum FilterTy filter_ty)
505  : SearchFilter(target_sp, filter_ty), m_module_spec_list(module_list) {}
506 
508 
509 bool SearchFilterByModuleList::ModulePasses(const ModuleSP &module_sp) {
510  if (m_module_spec_list.GetSize() == 0)
511  return true;
512 
513  return module_sp && m_module_spec_list.FindFileIndex(
514  0, module_sp->GetFileSpec(), false) != UINT32_MAX;
515 }
516 
518  if (m_module_spec_list.GetSize() == 0)
519  return true;
520 
521  return m_module_spec_list.FindFileIndex(0, spec, true) != UINT32_MAX;
522 }
523 
525  // FIXME: Not yet implemented
526  return true;
527 }
528 
530  if (!m_target_sp)
531  return;
532 
533  if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
534  SymbolContext empty_sc;
535  empty_sc.target_sp = m_target_sp;
536  searcher.SearchCallback(*this, empty_sc, nullptr);
537  }
538 
539  // If the module file spec is a full path, then we can just find the one
540  // filespec that passes. Otherwise, we need to go through all modules and
541  // find the ones that match the file name.
542  for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
543  if (m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) ==
544  UINT32_MAX)
545  continue;
546  SymbolContext matchingContext(m_target_sp, module_sp);
547  Searcher::CallbackReturn shouldContinue;
548 
549  shouldContinue = DoModuleIteration(matchingContext, searcher);
550  if (shouldContinue == Searcher::eCallbackReturnStop)
551  return;
552  }
553 }
554 
556  size_t num_modules = m_module_spec_list.GetSize();
557  if (num_modules == 1) {
558  s->Printf(", module = ");
559  s->PutCString(
560  m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString(
561  "<Unknown>"));
562  return;
563  }
564 
565  s->Printf(", modules(%" PRIu64 ") = ", (uint64_t)num_modules);
566  for (size_t i = 0; i < num_modules; i++) {
567  s->PutCString(
568  m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString(
569  "<Unknown>"));
570  if (i != num_modules - 1)
571  s->PutCString(", ");
572  }
573 }
574 
576  return eSymbolContextModule;
577 }
578 
580 
582  return std::make_shared<SearchFilterByModuleList>(*this);
583 }
584 
586  const lldb::TargetSP& target_sp,
587  const StructuredData::Dictionary &data_dict,
588  Status &error) {
589  StructuredData::Array *modules_array;
590  bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
591  modules_array);
592 
593  if (!success)
594  return std::make_shared<SearchFilterByModuleList>(target_sp,
595  FileSpecList{});
596  FileSpecList modules;
597  size_t num_modules = modules_array->GetSize();
598  for (size_t i = 0; i < num_modules; i++) {
599  llvm::StringRef module;
600  success = modules_array->GetItemAtIndexAsString(i, module);
601  if (!success) {
602  error.SetErrorStringWithFormat(
603  "SFBM::CFSD: filter module item %zu not a string.", i);
604  return nullptr;
605  }
606  modules.EmplaceBack(module);
607  }
608  return std::make_shared<SearchFilterByModuleList>(target_sp, modules);
609 }
610 
612  StructuredData::DictionarySP &options_dict_sp) {
613  SerializeFileSpecList(options_dict_sp, OptionNames::ModList,
615 }
616 
618  auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
619  SerializeUnwrapped(options_dict_sp);
620  return WrapOptionsDict(options_dict_sp);
621 }
622 
623 // SearchFilterByModuleListAndCU:
624 // Selects a shared library matching a given file spec
625 
627  const lldb::TargetSP &target_sp, const FileSpecList &module_list,
628  const FileSpecList &cu_list)
629  : SearchFilterByModuleList(target_sp, module_list,
630  FilterTy::ByModulesAndCU),
631  m_cu_spec_list(cu_list) {}
632 
634 
636  const lldb::TargetSP& target_sp,
637  const StructuredData::Dictionary &data_dict,
638  Status &error) {
639  StructuredData::Array *modules_array = nullptr;
640  SearchFilterSP result_sp;
641  bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
642  modules_array);
643  FileSpecList modules;
644  if (success) {
645  size_t num_modules = modules_array->GetSize();
646  for (size_t i = 0; i < num_modules; i++) {
647  llvm::StringRef module;
648  success = modules_array->GetItemAtIndexAsString(i, module);
649  if (!success) {
650  error.SetErrorStringWithFormat(
651  "SFBM::CFSD: filter module item %zu not a string.", i);
652  return result_sp;
653  }
654  modules.EmplaceBack(module);
655  }
656  }
657 
658  StructuredData::Array *cus_array = nullptr;
659  success =
660  data_dict.GetValueForKeyAsArray(GetKey(OptionNames::CUList), cus_array);
661  if (!success) {
662  error.SetErrorString("SFBM::CFSD: Could not find the CU list key.");
663  return result_sp;
664  }
665 
666  size_t num_cus = cus_array->GetSize();
667  FileSpecList cus;
668  for (size_t i = 0; i < num_cus; i++) {
669  llvm::StringRef cu;
670  success = cus_array->GetItemAtIndexAsString(i, cu);
671  if (!success) {
672  error.SetErrorStringWithFormat(
673  "SFBM::CFSD: filter CU item %zu not a string.", i);
674  return nullptr;
675  }
676  cus.EmplaceBack(cu);
677  }
678 
679  return std::make_shared<SearchFilterByModuleListAndCU>(
680  target_sp, modules, cus);
681 }
682 
685  auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
687  SerializeFileSpecList(options_dict_sp, OptionNames::CUList, m_cu_spec_list);
688  return WrapOptionsDict(options_dict_sp);
689 }
690 
692  SymbolContext sym_ctx;
693  address.CalculateSymbolContext(&sym_ctx, eSymbolContextEverything);
694  if (!sym_ctx.comp_unit) {
695  if (m_cu_spec_list.GetSize() != 0)
696  return false; // Has no comp_unit so can't pass the file check.
697  }
698  FileSpec cu_spec;
699  if (sym_ctx.comp_unit)
700  cu_spec = sym_ctx.comp_unit->GetPrimaryFile();
701  if (m_cu_spec_list.FindFileIndex(0, cu_spec, false) == UINT32_MAX)
702  return false; // Fails the file check
704 }
705 
707  return m_cu_spec_list.FindFileIndex(0, fileSpec, false) != UINT32_MAX;
708 }
709 
711  bool in_cu_list = m_cu_spec_list.FindFileIndex(0, compUnit.GetPrimaryFile(),
712  false) != UINT32_MAX;
713  if (!in_cu_list)
714  return false;
715 
716  ModuleSP module_sp(compUnit.GetModule());
717  if (!module_sp)
718  return true;
719 
720  return SearchFilterByModuleList::ModulePasses(module_sp);
721 }
722 
724  if (!m_target_sp)
725  return;
726 
727  if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
728  SymbolContext empty_sc;
729  empty_sc.target_sp = m_target_sp;
730  searcher.SearchCallback(*this, empty_sc, nullptr);
731  }
732 
733  // If the module file spec is a full path, then we can just find the one
734  // filespec that passes. Otherwise, we need to go through all modules and
735  // find the ones that match the file name.
736 
737  ModuleList matching_modules;
738 
739  bool no_modules_in_filter = m_module_spec_list.GetSize() == 0;
740  for (ModuleSP module_sp : m_target_sp->GetImages().Modules()) {
741  if (!no_modules_in_filter &&
742  m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) ==
743  UINT32_MAX)
744  continue;
745 
746  SymbolContext matchingContext(m_target_sp, module_sp);
747  Searcher::CallbackReturn shouldContinue;
748 
749  if (searcher.GetDepth() == lldb::eSearchDepthModule) {
750  shouldContinue = DoModuleIteration(matchingContext, searcher);
751  if (shouldContinue == Searcher::eCallbackReturnStop)
752  return;
753  continue;
754  }
755 
756  const size_t num_cu = module_sp->GetNumCompileUnits();
757  for (size_t cu_idx = 0; cu_idx < num_cu; cu_idx++) {
758  CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx);
759  matchingContext.comp_unit = cu_sp.get();
760  if (!matchingContext.comp_unit)
761  continue;
762  if (m_cu_spec_list.FindFileIndex(
763  0, matchingContext.comp_unit->GetPrimaryFile(), false) ==
764  UINT32_MAX)
765  continue;
766  shouldContinue = DoCUIteration(module_sp, matchingContext, searcher);
767  if (shouldContinue == Searcher::eCallbackReturnStop)
768  return;
769  }
770  }
771 }
772 
774  size_t num_modules = m_module_spec_list.GetSize();
775  if (num_modules == 1) {
776  s->Printf(", module = ");
777  s->PutCString(
778  m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString(
779  "<Unknown>"));
780  } else if (num_modules > 0) {
781  s->Printf(", modules(%" PRIu64 ") = ", static_cast<uint64_t>(num_modules));
782  for (size_t i = 0; i < num_modules; i++) {
783  s->PutCString(
784  m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString(
785  "<Unknown>"));
786  if (i != num_modules - 1)
787  s->PutCString(", ");
788  }
789  }
790 }
791 
793  return eSymbolContextModule | eSymbolContextCompUnit;
794 }
795 
797 
799  return std::make_shared<SearchFilterByModuleListAndCU>(*this);
800 }
lldb_private::SearchFilterForUnconstrainedSearches::DoCreateCopy
lldb::SearchFilterSP DoCreateCopy() override
Definition: SearchFilter.cpp:384
lldb_private::SearchFilter::m_target_sp
lldb::TargetSP m_target_sp
Definition: SearchFilter.h:278
lldb::eSearchDepthCompUnit
@ eSearchDepthCompUnit
Definition: lldb-enumerations.h:287
lldb_private::SearchFilterByModuleListAndCU::DoCreateCopy
lldb::SearchFilterSP DoCreateCopy() override
Definition: SearchFilter.cpp:798
lldb_private::SymbolFile
Definition: SymbolFile.h:37
lldb_private::SearchFilterByModuleList::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
Definition: SearchFilter.cpp:555
lldb_private::SearchFilterByModule::CreateFromStructuredData
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
Definition: SearchFilter.cpp:455
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb_private::StructuredData::Dictionary
Definition: StructuredData.h:352
lldb_private::SearchFilterForUnconstrainedSearches::CreateFromStructuredData
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
Definition: SearchFilter.cpp:355
lldb_private::SearchFilterByModuleListAndCU::GetFilterRequiredItems
uint32_t GetFilterRequiredItems() override
This determines which items are REQUIRED for the filter to pass.
Definition: SearchFilter.cpp:792
lldb_private::SearchFilterByModuleListAndCU::m_cu_spec_list
FileSpecList m_cu_spec_list
Definition: SearchFilter.h:439
lldb_private::SearchFilterByModule::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData() override
Definition: SearchFilter.cpp:485
lldb_private::StructuredData::Object::IsValid
virtual bool IsValid() const
Definition: StructuredData.h:77
lldb_private::SearchFilterByModuleListAndCU::Search
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
Definition: SearchFilter.cpp:723
lldb_private::SearchFilterByModuleList::ModulePasses
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
lldb_private::SearchFilter::AddressPasses
virtual bool AddressPasses(Address &addr)
Call this method with a Address to see if address passes the filter.
Definition: SearchFilter.cpp:141
lldb::eSearchDepthFunction
@ eSearchDepthFunction
Definition: lldb-enumerations.h:288
lldb_private::ModuleList::Modules
ModuleIterable Modules() const
Definition: ModuleList.h:480
CompileUnit.h
lldb_private::SearchFilter::ModulePasses
virtual bool ModulePasses(const FileSpec &spec)
Call this method with a file spec to see if that spec passes the filter.
Definition: SearchFilter.cpp:137
lldb_private::StructuredData::Array
Definition: StructuredData.h:165
lldb::eSearchDepthTarget
@ eSearchDepthTarget
Definition: lldb-enumerations.h:285
lldb_private::SearchFilter::NameToFilterTy
static FilterTy NameToFilterTy(llvm::StringRef name)
Definition: SearchFilter.cpp:58
lldb_private::SymbolContext::target_sp
lldb::TargetSP target_sp
The Target for a given query.
Definition: SymbolContext.h:317
lldb_private::SearchFilter::DoModuleIteration
Searcher::CallbackReturn DoModuleIteration(const SymbolContext &context, Searcher &searcher)
Definition: SearchFilter.cpp:247
lldb_private::SearchFilterByModuleList::SearchFilterByModuleList
SearchFilterByModuleList(const lldb::TargetSP &targetSP, const FileSpecList &module_list)
The basic constructor takes a Target, which gives the space to search, and the module list to restric...
Definition: SearchFilter.cpp:497
lldb_private::SearchFilter::Dump
virtual void Dump(Stream *s) const
Standard "Dump" method. At present it does nothing.
Definition: SearchFilter.cpp:162
lldb_private::SearchFilter::GetFilterRequiredItems
virtual uint32_t GetFilterRequiredItems()
This determines which items are REQUIRED for the filter to pass.
Definition: SearchFilter.cpp:156
lldb_private::SearchFilterByModuleListAndCU::CompUnitPasses
bool CompUnitPasses(FileSpec &fileSpec) override
Call this method with a FileSpec to see if file spec passes the filter as the name of a compilation u...
Definition: SearchFilter.cpp:706
lldb_private::SymbolFile::ParseFunctions
virtual size_t ParseFunctions(CompileUnit &comp_unit)=0
lldb_private::SearchFilter::DoCUIteration
Searcher::CallbackReturn DoCUIteration(const lldb::ModuleSP &module_sp, const SymbolContext &context, Searcher &searcher)
Definition: SearchFilter.cpp:289
lldb_private::ModuleList::GetMutex
std::recursive_mutex & GetMutex() const
Definition: ModuleList.h:198
lldb_private::SearchFilter::ByModule
@ ByModule
Definition: SearchFilter.h:220
lldb_private::SearchFilter::SearchInModuleList
virtual void SearchInModuleList(Searcher &searcher, ModuleList &modules)
Call this method to do the search using the Searcher in the module list modules.
Definition: SearchFilter.cpp:219
Module.h
lldb_private::SearchFilterByModuleListAndCU::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData() override
Definition: SearchFilter.cpp:684
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::SearchFilterByModule::m_module_spec
FileSpec m_module_spec
Definition: SearchFilter.h:353
lldb_private::SearchFilter::WrapOptionsDict
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
Definition: SearchFilter.cpp:173
lldb_private::SearchFilter::Search
virtual void Search(Searcher &searcher)
Call this method to do the search using the Searcher.
Definition: SearchFilter.cpp:204
lldb_private::Stream
Definition: Stream.h:28
lldb_private::SearchFilter::SerializeFileSpecList
void SerializeFileSpecList(StructuredData::DictionarySP &options_dict_sp, OptionNames name, FileSpecList &file_list)
Definition: SearchFilter.cpp:184
lldb_private::SearchFilter::GetDescription
virtual void GetDescription(Stream *s)
Prints a canonical description for the search filter to the stream s.
Definition: SearchFilter.cpp:160
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::SearchFilter::UnknownFilter
@ UnknownFilter
Definition: SearchFilter.h:224
lldb_private::SearchFilter::DoCreateCopy
virtual lldb::SearchFilterSP DoCreateCopy()=0
lldb_private::SearchFilterByModule::Dump
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
Definition: SearchFilter.cpp:449
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb_private::SearchFilterByModule::DoCreateCopy
lldb::SearchFilterSP DoCreateCopy() override
Definition: SearchFilter.cpp:451
Target.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::SearchFilterByModule::~SearchFilterByModule
~SearchFilterByModule() override
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Function
Definition: Function.h:413
lldb_private::SearchFilterByModuleListAndCU::AddressPasses
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
Definition: SearchFilter.cpp:691
ModuleList.h
lldb_private::ModuleList
Definition: ModuleList.h:71
lldb_private::SearchFilter
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
SearchFilter.h
lldb_private::FileSpec::Match
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition: FileSpec.cpp:302
lldb_private::SearchFilterByModuleListAndCU::SearchFilterByModuleListAndCU
SearchFilterByModuleListAndCU(const lldb::TargetSP &targetSP, const FileSpecList &module_list, const FileSpecList &cu_list)
The basic constructor takes a Target, which gives the space to search, and the module list to restric...
Definition: SearchFilter.cpp:626
lldb_private::SearchFilter::ByModules
@ ByModules
Definition: SearchFilter.h:221
lldb_private::SearchFilterByModuleListAndCU::CreateFromStructuredData
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
Definition: SearchFilter.cpp:635
lldb_private::SearchFilterByModule::Search
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
Definition: SearchFilter.cpp:411
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::SearchFilter::ByModulesAndCU
@ ByModulesAndCU
Definition: SearchFilter.h:222
lldb_private::SearchFilter::FilterTy
FilterTy
Definition: SearchFilter.h:217
lldb_private::Searcher::CallbackReturn
CallbackReturn
Definition: SearchFilter.h:44
lldb_private::SearchFilterForUnconstrainedSearches::ModulePasses
bool ModulePasses(const FileSpec &module_spec) override
Call this method with a file spec to see if that spec passes the filter.
Definition: SearchFilter.cpp:370
lldb-enumerations.h
if
if(CMAKE_SYSTEM_NAME MATCHES "Windows") add_definitions(-DEXPORT_LIBLLDB) endif() get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS) if(LLDB_BUILD_FRAMEWORK) set(option_install_prefix INSTALL_PREFIX $
Definition: API/CMakeLists.txt:1
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb_private::SearchFilterByModuleList::SerializeUnwrapped
void SerializeUnwrapped(StructuredData::DictionarySP &options_dict_sp)
Definition: SearchFilter.cpp:611
lldb_private::CompileUnit::GetPrimaryFile
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
lldb_private::SearchFilter::Unconstrained
@ Unconstrained
Definition: SearchFilter.h:218
lldb_private::Searcher::eCallbackReturnStop
@ eCallbackReturnStop
Definition: SearchFilter.h:45
lldb::eSearchDepthModule
@ eSearchDepthModule
Definition: lldb-enumerations.h:286
lldb_private::SearchFilterForUnconstrainedSearches::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData() override
Definition: SearchFilter.cpp:364
lldb_private::Status
Definition: Status.h:44
lldb_private::SearchFilterByModuleList::DoCreateCopy
lldb::SearchFilterSP DoCreateCopy() override
Definition: SearchFilter.cpp:581
lldb_private::SearchFilter::Exception
@ Exception
Definition: SearchFilter.h:219
uint32_t
lldb_private::SearchFilterByModuleList::GetFilterRequiredItems
uint32_t GetFilterRequiredItems() override
This determines which items are REQUIRED for the filter to pass.
Definition: SearchFilter.cpp:575
lldb_private::SearchFilterByModuleList::m_module_spec_list
FileSpecList m_module_spec_list
Definition: SearchFilter.h:401
lldb_private::Address
Definition: Address.h:59
lldb_private::Searcher::SearchCallback
virtual CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr)=0
lldb_private::SearchFilter::CreateFromStructuredData
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
Definition: SearchFilter.cpp:77
lldb_private::Searcher::eCallbackReturnPop
@ eCallbackReturnPop
Definition: SearchFilter.h:47
lldb_private::SearchFilterByModuleList::Dump
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
Definition: SearchFilter.cpp:579
lldb_private::SearchFilterByModule::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
Definition: SearchFilter.cpp:440
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
lldb_private::SearchFilter::CreateCopy
lldb::SearchFilterSP CreateCopy(lldb::TargetSP &target_sp)
Definition: SearchFilter.cpp:164
lldb_private::SymbolContext::module_sp
lldb::ModuleSP module_sp
The Module for a given query.
Definition: SymbolContext.h:318
lldb_private::SearchFilterByModuleListAndCU::Dump
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
Definition: SearchFilter.cpp:796
lldb_private::SearchFilter::CompUnitPasses
virtual bool CompUnitPasses(FileSpec &fileSpec)
Call this method with a FileSpec to see if file spec passes the filter as the name of a compilation u...
Definition: SearchFilter.cpp:143
lldb_private::SearchFilterByModuleList
Definition: SearchFilter.h:356
lldb_private::SearchFilter::GetFilterName
const char * GetFilterName()
Definition: SearchFilter.h:236
lldb_private::SearchFilterByModule::SearchFilterByModule
SearchFilterByModule(const lldb::TargetSP &targetSP, const FileSpec &module)
The basic constructor takes a Target, which gives the space to search, and the module to restrict the...
Definition: SearchFilter.cpp:391
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
Status.h
SymbolContext.h
lldb_private::SearchFilter::GetKey
static const char * GetKey(enum OptionNames enum_value)
Definition: SearchFilter.h:247
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::StructuredData::Dictionary::GetValueForKeyAsDictionary
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
Definition: StructuredData.h:467
Breakpoint.h
lldb_private::SearchFilterByModuleList::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData() override
Definition: SearchFilter.cpp:617
lldb_private::SearchFilter::GetSerializationSubclassKey
static const char * GetSerializationSubclassKey()
Definition: SearchFilter.h:213
ConstString.h
lldb_private::Searcher
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
lldb_private::SearchFilterByModuleList::AddressPasses
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
Definition: SearchFilter.cpp:524
lldb_private::Searcher::GetDepth
virtual lldb::SearchDepth GetDepth()=0
lldb_private::SearchFilterByModule::AddressPasses
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
Definition: SearchFilter.cpp:406
lldb_private::SearchFilter::OptionNames
OptionNames
Definition: SearchFilter.h:244
lldb_private::StructuredData::Array::GetItemAtIndexAsString
bool GetItemAtIndexAsString(size_t idx, llvm::StringRef &result) const
Definition: StructuredData.h:216
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::StructuredData::Dictionary::GetValueForKeyAsString
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
Definition: StructuredData.h:423
lldb_private::StructuredData::Dictionary::GetValueForKeyAsArray
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
Definition: StructuredData.h:478
lldb_private::SearchFilterByModuleListAndCU::~SearchFilterByModuleListAndCU
~SearchFilterByModuleListAndCU() override
lldb_private::SearchFilterByModuleList::Search
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
Definition: SearchFilter.cpp:529
lldb_private::StructuredData::Array::GetSize
size_t GetSize() const
Definition: StructuredData.h:180
lldb_private::SearchFilter::FunctionPasses
virtual bool FunctionPasses(Function &function)
Call this method with a Function to see if function passes the filter.
Definition: SearchFilter.cpp:147
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:348
lldb_private::SearchFilterByModuleListAndCU::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
Definition: SearchFilter.cpp:773
lldb_private::SearchFilter::~SearchFilter
virtual ~SearchFilter()
lldb
Definition: SBAddress.h:15
lldb_private::SearchFilterByModule::GetFilterRequiredItems
uint32_t GetFilterRequiredItems() override
This determines which items are REQUIRED for the filter to pass.
Definition: SearchFilter.cpp:445
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:341
lldb_private::SearchFilterByModuleList::CreateFromStructuredData
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
Definition: SearchFilter.cpp:585
SymbolFile.h
lldb_private::Address::CalculateSymbolContext
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
Definition: Address.cpp:795
lldb_private::SearchFilter::DoFunctionIteration
Searcher::CallbackReturn DoFunctionIteration(Function *function, const SymbolContext &context, Searcher &searcher)
Definition: SearchFilter.cpp:346
lldb_private::SearchFilterByModuleList::~SearchFilterByModuleList
~SearchFilterByModuleList() override
lldb_private::SearchFilterByModule::ModulePasses
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
lldb_private::Searcher::eCallbackReturnContinue
@ eCallbackReturnContinue
Definition: SearchFilter.h:46
lldb_private::SearchFilter::GetSerializationSubclassOptionsKey
static const char * GetSerializationSubclassOptionsKey()
Definition: SearchFilter.h:215