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"
17#include "lldb/Target/Target.h"
19#include "lldb/Utility/Status.h"
20#include "lldb/Utility/Stream.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
33namespace lldb_private {
34class Address;
35}
36namespace lldb_private {
37class Function;
38}
39
40using namespace lldb;
41using namespace lldb_private;
42
43const char *SearchFilter::g_ty_to_name[] = {"Unconstrained", "Exception",
44 "Module", "Modules",
45 "ModulesAndCU", "Unknown"};
46
47const char
49 "ModuleList", "CUList"};
50
51const char *SearchFilter::FilterTyToName(enum FilterTy type) {
52 if (type > LastKnownFilterType)
54
55 return g_ty_to_name[type];
56}
57
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
66Searcher::Searcher() = default;
67
68Searcher::~Searcher() = default;
69
71
72SearchFilter::SearchFilter(const TargetSP &target_sp, unsigned char filterType)
73 : m_target_sp(target_sp), SubclassID(filterType) {}
74
76
77std::unique_ptr<SearchFilter> SearchFilter::CreateFromStructuredData(
78 const lldb::TargetSP &target_sp,
79 const StructuredData::Dictionary &filter_dict, Status &error) {
80 if (!filter_dict.IsValid()) {
82 "Can't deserialize from an invalid data object.");
83 return nullptr;
84 }
85
86 llvm::StringRef subclass_name;
87
88 bool success = filter_dict.GetValueForKeyAsString(
89 GetSerializationSubclassKey(), subclass_name);
90 if (!success) {
91 error = Status::FromErrorString("Filter data missing subclass key");
92 return nullptr;
93 }
94
95 FilterTy filter_type = NameToFilterTy(subclass_name);
96 if (filter_type == UnknownFilter) {
97 error = Status::FromErrorStringWithFormatv("Unknown filter type: {0}.",
98 subclass_name);
99 return nullptr;
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 =
107 Status::FromErrorString("Filter data missing subclass options key.");
108 return nullptr;
109 }
110
111 switch (filter_type) {
112 case Unconstrained:
114 target_sp, *subclass_options, error);
115 case ByModule:
117 target_sp, *subclass_options, error);
118 case ByModules:
120 target_sp, *subclass_options, error);
121 case ByModulesAndCU:
123 target_sp, *subclass_options, error);
124 case Exception:
125 error =
126 Status::FromErrorString("Can't serialize exception breakpoints yet.");
127 break;
128 default:
129 llvm_unreachable("Should never get an uresolvable filter type.");
130 }
131
132 return nullptr;
133}
134
135bool SearchFilter::ModulePasses(const FileSpec &spec) { return true; }
136
137bool SearchFilter::ModulePasses(const ModuleSP &module_sp) { return true; }
138
139bool SearchFilter::AddressPasses(Address &address) { return true; }
140
141bool SearchFilter::CompUnitPasses(FileSpec &fileSpec) { return true; }
142
143bool SearchFilter::CompUnitPasses(CompileUnit &compUnit) { return true; }
144
146 // This is a slightly cheesy job, but since we don't have finer grained
147 // filters yet, just checking that the start address passes is probably
148 // good enough for the base class behavior.
149 Address addr = function.GetAddress();
150 return AddressPasses(addr);
151}
152
153
155 return (lldb::SymbolContextItem)0;
156}
157
159
160void SearchFilter::Dump(Stream *s) const {}
161
162std::unique_ptr<SearchFilter>
164 std::unique_ptr<SearchFilter> ret = DoCreateCopy();
165 ret->SetTarget(target_sp);
166 return ret;
167}
168
169// Helper functions for serialization.
170
173 if (!options_dict_sp || !options_dict_sp->IsValid())
175
176 auto type_dict_sp = std::make_shared<StructuredData::Dictionary>();
177 type_dict_sp->AddStringItem(GetSerializationSubclassKey(), GetFilterName());
178 type_dict_sp->AddItem(GetSerializationSubclassOptionsKey(), options_dict_sp);
179
180 return type_dict_sp;
181}
182
184 StructuredData::DictionarySP &options_dict_sp, OptionNames name,
185 FileSpecList &file_list) {
186 size_t num_modules = file_list.GetSize();
187
188 // Don't serialize empty lists.
189 if (num_modules == 0)
190 return;
191
192 auto module_array_sp = std::make_shared<StructuredData::Array>();
193 for (size_t i = 0; i < num_modules; i++) {
194 module_array_sp->AddItem(std::make_shared<StructuredData::String>(
195 file_list.GetFileSpecAtIndex(i).GetPath()));
196 }
197 options_dict_sp->AddItem(GetKey(name), module_array_sp);
198}
199
200// UTILITY Functions to help iterate down through the elements of the
201// SymbolContext.
202
204 SymbolContext empty_sc;
205
206 if (!m_target_sp)
207 return;
208 empty_sc.target_sp = m_target_sp;
209
210 if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
211 searcher.SearchCallback(*this, empty_sc, nullptr);
212 return;
213 }
214
215 DoModuleIteration(empty_sc, searcher);
216}
217
219 SymbolContext empty_sc;
220
221 if (!m_target_sp)
222 return;
223 empty_sc.target_sp = m_target_sp;
224
225 if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
226 searcher.SearchCallback(*this, empty_sc, nullptr);
227 return;
228 }
229
230 for (ModuleSP module_sp : modules.Modules()) {
231 if (!ModulePasses(module_sp))
232 continue;
233 if (DoModuleIteration(module_sp, searcher) == Searcher::eCallbackReturnStop)
234 return;
235 }
236}
237
240 Searcher &searcher) {
241 SymbolContext matchingContext(m_target_sp, module_sp);
242 return DoModuleIteration(matchingContext, searcher);
243}
244
247 Searcher &searcher) {
248 if (searcher.GetDepth() < lldb::eSearchDepthModule)
250
251 if (context.module_sp) {
252 if (searcher.GetDepth() != lldb::eSearchDepthModule)
253 return DoCUIteration(context.module_sp, context, searcher);
254
255 SymbolContext matchingContext(context.module_sp.get());
256 searcher.SearchCallback(*this, matchingContext, nullptr);
258 }
259
260 ModuleList module_list = m_target_sp->GetImages();
261 // Since we're iterating over a copy, no need to do any locking.
262 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
263 // If this is the last level supplied, then call the callback directly,
264 // otherwise descend.
265 if (!ModulePasses(module_sp))
266 continue;
267
268 if (searcher.GetDepth() == lldb::eSearchDepthModule) {
269 SymbolContext matchingContext(m_target_sp, module_sp);
270
271 Searcher::CallbackReturn shouldContinue =
272 searcher.SearchCallback(*this, matchingContext, nullptr);
273 if (shouldContinue == Searcher::eCallbackReturnStop ||
274 shouldContinue == Searcher::eCallbackReturnPop)
275 return shouldContinue;
276 } else {
277 Searcher::CallbackReturn shouldContinue =
278 DoCUIteration(module_sp, context, searcher);
279 if (shouldContinue == Searcher::eCallbackReturnStop)
280 return shouldContinue;
281 else if (shouldContinue == Searcher::eCallbackReturnPop)
282 continue;
283 }
284 }
285
287}
288
291 const SymbolContext &context, Searcher &searcher) {
292 Searcher::CallbackReturn shouldContinue;
293 if (context.comp_unit != nullptr) {
294 if (CompUnitPasses(*context.comp_unit)) {
295 SymbolContext matchingContext(m_target_sp, module_sp, context.comp_unit);
296 return searcher.SearchCallback(*this, matchingContext, nullptr);
297 }
299 }
300
301 const size_t num_comp_units = module_sp->GetNumCompileUnits();
302 for (size_t i = 0; i < num_comp_units; i++) {
303 CompUnitSP cu_sp(module_sp->GetCompileUnitAtIndex(i));
304 if (!cu_sp)
305 continue;
306 if (!CompUnitPasses(*(cu_sp.get())))
307 continue;
308
309 if (searcher.GetDepth() == lldb::eSearchDepthCompUnit) {
310 SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get());
311
312 shouldContinue = searcher.SearchCallback(*this, matchingContext, nullptr);
313
314 if (shouldContinue == Searcher::eCallbackReturnPop)
316 else if (shouldContinue == Searcher::eCallbackReturnStop)
317 return shouldContinue;
318 continue;
319 }
320
321 // First make sure this compile unit's functions are parsed
322 // since CompUnit::ForeachFunction only iterates over already
323 // parsed functions.
324 SymbolFile *sym_file = module_sp->GetSymbolFile();
325 if (!sym_file)
326 continue;
327 if (!sym_file->ParseFunctions(*cu_sp))
328 continue;
329 // If we got any functions, use ForeachFunction to do the iteration.
330 cu_sp->ForeachFunction([&](const FunctionSP &func_sp) {
331 if (!FunctionPasses(*func_sp.get()))
332 return false; // Didn't pass the filter, just keep going.
333 if (searcher.GetDepth() == lldb::eSearchDepthFunction) {
334 SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get(),
335 func_sp.get());
336 shouldContinue =
337 searcher.SearchCallback(*this, matchingContext, nullptr);
338 } else {
339 shouldContinue = DoFunctionIteration(func_sp.get(), context, searcher);
340 }
341 return shouldContinue != Searcher::eCallbackReturnContinue;
342 });
343 }
345}
346
348 Function *function, const SymbolContext &context, Searcher &searcher) {
349 // FIXME: Implement...
351}
352
353// SearchFilterForUnconstrainedSearches:
354// Selects a shared library matching a given file spec, consulting the targets
355// "black list".
356std::unique_ptr<SearchFilter>
358 const lldb::TargetSP &target_sp,
359 const StructuredData::Dictionary &data_dict, Status &error) {
360 // No options for an unconstrained search.
361 return std::make_unique<SearchFilterForUnconstrainedSearches>(target_sp);
362}
363
366 // The options dictionary is an empty dictionary:
367 auto result_sp = std::make_shared<StructuredData::Dictionary>();
368 return WrapOptionsDict(result_sp);
369}
370
372 const FileSpec &module_spec) {
373 return !m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_spec);
374}
375
377 const lldb::ModuleSP &module_sp) {
378 if (!module_sp)
379 return true;
380 else if (m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_sp))
381 return false;
382 return true;
383}
384
385std::unique_ptr<SearchFilter>
387 return std::make_unique<SearchFilterForUnconstrainedSearches>(*this);
388}
389
390// SearchFilterByModule:
391// Selects a shared library matching a given file spec
392
394 const FileSpec &module)
395 : SearchFilter(target_sp, FilterTy::ByModule), m_module_spec(module) {}
396
398
400 return (module_sp &&
401 FileSpec::Match(m_module_spec, module_sp->GetFileSpec()));
402}
403
407
409 // FIXME: Not yet implemented
410 return true;
411}
412
414 if (!m_target_sp)
415 return;
416
417 if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
418 SymbolContext empty_sc;
419 empty_sc.target_sp = m_target_sp;
420 searcher.SearchCallback(*this, empty_sc, nullptr);
421 }
422
423 ModuleList module_list = m_target_sp->GetImages();
424 // Since we're iterating over a copy, no need to do any locking.
425 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
426 if (FileSpec::Match(m_module_spec, module_sp->GetFileSpec())) {
427 SymbolContext matchingContext(m_target_sp, module_sp);
428 Searcher::CallbackReturn shouldContinue;
429
430 shouldContinue = DoModuleIteration(matchingContext, searcher);
431 if (shouldContinue == Searcher::eCallbackReturnStop)
432 return;
433 }
434 }
435}
436
438 s->PutCString(", module = ");
439 s->PutCString(m_module_spec.GetFilename().AsCString("<Unknown>"));
440}
441
443 return eSymbolContextModule;
444}
445
447
448std::unique_ptr<SearchFilter> SearchFilterByModule::DoCreateCopy() {
449 return std::make_unique<SearchFilterByModule>(*this);
450}
451
453 const lldb::TargetSP &target_sp,
454 const StructuredData::Dictionary &data_dict, Status &error) {
455 StructuredData::Array *modules_array;
456 bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
457 modules_array);
458 if (!success) {
460 "SFBM::CFSD: Could not find the module list key.");
461 return nullptr;
462 }
463
464 size_t num_modules = modules_array->GetSize();
465 if (num_modules > 1) {
467 "SFBM::CFSD: Only one modules allowed for SearchFilterByModule.");
468 return nullptr;
469 }
470
471 std::optional<llvm::StringRef> maybe_module =
472 modules_array->GetItemAtIndexAsString(0);
473 if (!maybe_module) {
474 error =
475 Status::FromErrorString("SFBM::CFSD: filter module item not a string.");
476 return nullptr;
477 }
478 FileSpec module_spec(*maybe_module);
479
480 return std::make_unique<SearchFilterByModule>(target_sp, module_spec);
481}
482
484 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
485 auto module_array_sp = std::make_shared<StructuredData::Array>();
486 module_array_sp->AddItem(
487 std::make_shared<StructuredData::String>(m_module_spec.GetPath()));
488 options_dict_sp->AddItem(GetKey(OptionNames::ModList), module_array_sp);
489 return WrapOptionsDict(options_dict_sp);
490}
491
492// SearchFilterByModuleList:
493// Selects a shared library matching a given file spec
494
496 const lldb::TargetSP &target_sp, const FileSpecList &module_list)
497 : SearchFilter(target_sp, FilterTy::ByModules),
498 m_module_spec_list(module_list) {}
499
501 const lldb::TargetSP &target_sp, const FileSpecList &module_list,
502 enum FilterTy filter_ty)
503 : SearchFilter(target_sp, filter_ty), m_module_spec_list(module_list) {}
504
506
508 if (m_module_spec_list.GetSize() == 0)
509 return true;
510
511 return module_sp && m_module_spec_list.FindFileIndex(
512 0, module_sp->GetFileSpec(), false) != UINT32_MAX;
513}
514
516 if (m_module_spec_list.GetSize() == 0)
517 return true;
518
519 return m_module_spec_list.FindFileIndex(0, spec, true) != UINT32_MAX;
520}
521
523 // FIXME: Not yet implemented
524 return true;
525}
526
528 if (!m_target_sp)
529 return;
530
531 if (searcher.GetDepth() == lldb::eSearchDepthTarget) {
532 SymbolContext empty_sc;
533 empty_sc.target_sp = m_target_sp;
534 searcher.SearchCallback(*this, empty_sc, nullptr);
535 }
536
537 // If the module file spec is a full path, then we can just find the one
538 // filespec that passes. Otherwise, we need to go through all modules and
539 // find the ones that match the file name.
540 ModuleList module_list = m_target_sp->GetImages();
541 // Since we're iterating over a copy, no need to do any locking.
542 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
543 if (m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) ==
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
581std::unique_ptr<SearchFilter> SearchFilterByModuleList::DoCreateCopy() {
582 return std::make_unique<SearchFilterByModuleList>(*this);
583}
584
585std::unique_ptr<SearchFilter>
587 const lldb::TargetSP &target_sp,
588 const StructuredData::Dictionary &data_dict, 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_unique<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 std::optional<llvm::StringRef> maybe_module =
600 modules_array->GetItemAtIndexAsString(i);
601 if (!maybe_module) {
603 "SFBM::CFSD: filter module item %zu not a string.", i);
604 return nullptr;
605 }
606 modules.EmplaceBack(*maybe_module);
607 }
608 return std::make_unique<SearchFilterByModuleList>(target_sp, modules);
609}
610
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,
631 m_cu_spec_list(cu_list) {}
632
634
635std::unique_ptr<SearchFilter>
637 const lldb::TargetSP &target_sp,
638 const StructuredData::Dictionary &data_dict, Status &error) {
639 StructuredData::Array *modules_array = nullptr;
640 bool success = data_dict.GetValueForKeyAsArray(GetKey(OptionNames::ModList),
641 modules_array);
642 FileSpecList modules;
643 if (success) {
644 size_t num_modules = modules_array->GetSize();
645 for (size_t i = 0; i < num_modules; i++) {
646 std::optional<llvm::StringRef> maybe_module =
647 modules_array->GetItemAtIndexAsString(i);
648 if (!maybe_module) {
650 "SFBM::CFSD: filter module item %zu not a string.", i);
651 return nullptr;
652 }
653 modules.EmplaceBack(*maybe_module);
654 }
655 }
656
657 StructuredData::Array *cus_array = nullptr;
658 success =
659 data_dict.GetValueForKeyAsArray(GetKey(OptionNames::CUList), cus_array);
660 if (!success) {
661 error =
662 Status::FromErrorString("SFBM::CFSD: Could not find the CU list key.");
663 return nullptr;
664 }
665
666 size_t num_cus = cus_array->GetSize();
667 FileSpecList cus;
668 for (size_t i = 0; i < num_cus; i++) {
669 std::optional<llvm::StringRef> maybe_cu =
670 cus_array->GetItemAtIndexAsString(i);
671 if (!maybe_cu) {
673 "SFBM::CFSD: filter CU item %zu not a string.", i);
674 return nullptr;
675 }
676 cus.EmplaceBack(*maybe_cu);
677 }
678
679 return std::make_unique<SearchFilterByModuleListAndCU>(target_sp, modules,
680 cus);
681}
682
685 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
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
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 ModuleList module_list = m_target_sp->GetImages();
741 // Since we're iterating over a copy, no need to do any locking.
742 for (ModuleSP module_sp : module_list.ModulesNoLocking()) {
743 if (!no_modules_in_filter &&
744 m_module_spec_list.FindFileIndex(0, module_sp->GetFileSpec(), false) ==
746 continue;
747
748 SymbolContext matchingContext(m_target_sp, module_sp);
749 Searcher::CallbackReturn shouldContinue;
750
751 if (searcher.GetDepth() == lldb::eSearchDepthModule) {
752 shouldContinue = DoModuleIteration(matchingContext, searcher);
753 if (shouldContinue == Searcher::eCallbackReturnStop)
754 return;
755 continue;
756 }
757
758 const size_t num_cu = module_sp->GetNumCompileUnits();
759 for (size_t cu_idx = 0; cu_idx < num_cu; cu_idx++) {
760 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx);
761 matchingContext.comp_unit = cu_sp.get();
762 if (!matchingContext.comp_unit)
763 continue;
764 if (m_cu_spec_list.FindFileIndex(
765 0, matchingContext.comp_unit->GetPrimaryFile(), false) ==
767 continue;
768 shouldContinue = DoCUIteration(module_sp, matchingContext, searcher);
769 if (shouldContinue == Searcher::eCallbackReturnStop)
770 return;
771 }
772 }
773}
774
776 size_t num_modules = m_module_spec_list.GetSize();
777 if (num_modules == 1) {
778 s->Printf(", module = ");
779 s->PutCString(
780 m_module_spec_list.GetFileSpecAtIndex(0).GetFilename().AsCString(
781 "<Unknown>"));
782 } else if (num_modules > 0) {
783 s->Printf(", modules(%" PRIu64 ") = ", static_cast<uint64_t>(num_modules));
784 for (size_t i = 0; i < num_modules; i++) {
785 s->PutCString(
786 m_module_spec_list.GetFileSpecAtIndex(i).GetFilename().AsCString(
787 "<Unknown>"));
788 if (i != num_modules - 1)
789 s->PutCString(", ");
790 }
791 }
792}
793
795 return eSymbolContextModule | eSymbolContextCompUnit;
796}
797
799
800std::unique_ptr<SearchFilter> SearchFilterByModuleListAndCU::DoCreateCopy() {
801 return std::make_unique<SearchFilterByModuleListAndCU>(*this);
802}
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
Definition Address.cpp:819
A class that describes a compilation unit.
Definition CompileUnit.h:43
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
A file collection class.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void EmplaceBack(Args &&...args)
Inserts a new FileSpec into the FileSpecList constructed in-place with the given arguments.
size_t GetSize() const
Get the number of files in the file list.
A file utility class.
Definition FileSpec.h:57
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition FileSpec.cpp:301
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
A class that describes a function.
Definition Function.h:392
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:445
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
Definition ModuleList.h:125
ModuleIterableNoLocking ModulesNoLocking() const
Definition ModuleList.h:576
ModuleIterable Modules() const
Definition ModuleList.h:570
static std::unique_ptr< SearchFilter > CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
StructuredData::ObjectSP SerializeToStructuredData() override
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
std::unique_ptr< SearchFilter > DoCreateCopy() override
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
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...
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
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...
uint32_t GetFilterRequiredItems() override
This determines which items are REQUIRED for the filter to pass.
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
uint32_t GetFilterRequiredItems() override
This determines which items are REQUIRED for the filter to pass.
void SerializeUnwrapped(StructuredData::DictionarySP &options_dict_sp)
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
StructuredData::ObjectSP SerializeToStructuredData() override
std::unique_ptr< SearchFilter > DoCreateCopy() override
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...
static std::unique_ptr< SearchFilter > CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
StructuredData::ObjectSP SerializeToStructuredData() override
std::unique_ptr< SearchFilter > DoCreateCopy() override
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
void Search(Searcher &searcher) override
Call this method to do the search using the Searcher.
uint32_t GetFilterRequiredItems() override
This determines which items are REQUIRED for the filter to pass.
static std::unique_ptr< SearchFilter > CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
void GetDescription(Stream *s) override
Prints a canonical description for the search filter to the stream s.
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...
std::unique_ptr< SearchFilter > DoCreateCopy() override
StructuredData::ObjectSP SerializeToStructuredData() override
static std::unique_ptr< SearchFilter > CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
bool ModulePasses(const FileSpec &module_spec) override
Call this method with a file spec to see if that spec passes the filter.
void SerializeFileSpecList(StructuredData::DictionarySP &options_dict_sp, OptionNames name, FileSpecList &file_list)
virtual void SearchInModuleList(Searcher &searcher, ModuleList &modules)
Call this method to do the search using the Searcher in the module list modules.
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
virtual bool AddressPasses(Address &addr)
Call this method with a Address to see if address passes the filter.
static const char * GetKey(enum OptionNames enum_value)
static FilterTy NameToFilterTy(llvm::StringRef name)
static const char * FilterTyToName(enum FilterTy)
Searcher::CallbackReturn DoFunctionIteration(Function *function, const SymbolContext &context, Searcher &searcher)
static const char * GetSerializationSubclassKey()
Searcher::CallbackReturn DoModuleIteration(const SymbolContext &context, Searcher &searcher)
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...
static std::unique_ptr< SearchFilter > CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
virtual bool ModulePasses(const FileSpec &spec)
Call this method with a file spec to see if that spec passes the filter.
std::unique_ptr< SearchFilter > CreateCopy(lldb::TargetSP &target_sp)
virtual std::unique_ptr< SearchFilter > DoCreateCopy()=0
virtual void GetDescription(Stream *s)
Prints a canonical description for the search filter to the stream s.
virtual uint32_t GetFilterRequiredItems()
This determines which items are REQUIRED for the filter to pass.
SearchFilter(const lldb::TargetSP &target_sp)
The basic constructor takes a Target, which gives the space to search.
static const char * GetSerializationSubclassOptionsKey()
Searcher::CallbackReturn DoCUIteration(const lldb::ModuleSP &module_sp, const SymbolContext &context, Searcher &searcher)
static const char * g_ty_to_name[LastKnownFilterType+2]
virtual bool FunctionPasses(Function &function)
Call this method with a Function to see if function passes the filter.
virtual void Dump(Stream *s) const
Standard "Dump" method. At present it does nothing.
static const char * g_option_names[LastOptionName]
virtual void Search(Searcher &searcher)
Call this method to do the search using the Searcher.
General Outline: Provides the callback and search depth for the SearchFilter search.
virtual CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr)=0
virtual lldb::SearchDepth GetDepth()=0
virtual void GetDescription(Stream *s)
Prints a canonical description for the searcher to the stream s.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
std::optional< llvm::StringRef > GetItemAtIndexAsString(size_t idx) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
lldb::TargetSP target_sp
The Target for a given query.
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
virtual size_t ParseFunctions(CompileUnit &comp_unit)=0
#define UINT32_MAX
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Function > FunctionSP
@ eSearchDepthFunction
@ eSearchDepthCompUnit
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP