23#include "llvm/ADT/StringRef.h"
24#include "llvm/Support/ErrorHandling.h"
45 "ModulesAndCU",
"Unknown"};
49 "ModuleList",
"CUList"};
73 : m_target_sp(target_sp), SubclassID(filterType) {}
84 "Can't deserialize from an invalid data object.");
88 llvm::StringRef subclass_name;
107 if (!success || !subclass_options || !subclass_options->
IsValid()) {
113 switch (filter_type) {
116 target_sp, *subclass_options,
error);
120 target_sp, *subclass_options,
error);
124 target_sp, *subclass_options,
error);
128 target_sp, *subclass_options,
error);
135 llvm_unreachable(
"Should never get an uresolvable filter type.");
161 return (lldb::SymbolContextItem)0;
170 ret_sp->SetTarget(target_sp);
178 if (!options_dict_sp || !options_dict_sp->IsValid())
181 auto type_dict_sp = std::make_shared<StructuredData::Dictionary>();
191 size_t num_modules = file_list.
GetSize();
194 if (num_modules == 0)
197 auto module_array_sp = std::make_shared<StructuredData::Array>();
198 for (
size_t i = 0; i < num_modules; i++) {
199 module_array_sp->AddItem(std::make_shared<StructuredData::String>(
202 options_dict_sp->AddItem(
GetKey(name), module_array_sp);
278 return shouldContinue;
283 return shouldContinue;
304 const size_t num_comp_units = module_sp->GetNumCompileUnits();
305 for (
size_t i = 0; i < num_comp_units; i++) {
306 CompUnitSP cu_sp(module_sp->GetCompileUnitAtIndex(i));
315 shouldContinue = searcher.
SearchCallback(*
this, matchingContext,
nullptr);
320 return shouldContinue;
327 SymbolFile *sym_file = module_sp->GetSymbolFile();
333 cu_sp->ForeachFunction([&](
const FunctionSP &func_sp) {
337 SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get(),
340 searcher.SearchCallback(*this, matchingContext, nullptr);
342 shouldContinue = DoFunctionIteration(func_sp.get(), context, searcher);
364 return std::make_shared<SearchFilterForUnconstrainedSearches>(target_sp);
370 auto result_sp = std::make_shared<StructuredData::Dictionary>();
376 return !
m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_spec);
383 else if (
m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_sp))
389 return std::make_shared<SearchFilterForUnconstrainedSearches>(*
this);
430 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
450 return eSymbolContextModule;
456 return std::make_shared<SearchFilterByModule>(*
this);
468 "SFBM::CFSD: Could not find the module list key.");
472 size_t num_modules = modules_array->
GetSize();
473 if (num_modules > 1) {
475 "SFBM::CFSD: Only one modules allowed for SearchFilterByModule.");
479 std::optional<llvm::StringRef> maybe_module =
486 FileSpec module_spec(*maybe_module);
488 return std::make_shared<SearchFilterByModule>(target_sp, module_spec);
492 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
493 auto module_array_sp = std::make_shared<StructuredData::Array>();
494 module_array_sp->AddItem(
506 m_module_spec_list(module_list) {}
511 :
SearchFilter(target_sp, filter_ty), m_module_spec_list(module_list) {}
520 0, module_sp->GetFileSpec(),
false) !=
UINT32_MAX;
563 if (num_modules == 1) {
571 s->
Printf(
", modules(%" PRIu64
") = ", (uint64_t)num_modules);
572 for (
size_t i = 0; i < num_modules; i++) {
576 if (i != num_modules - 1)
582 return eSymbolContextModule;
588 return std::make_shared<SearchFilterByModuleList>(*
this);
600 return std::make_shared<SearchFilterByModuleList>(target_sp,
603 size_t num_modules = modules_array->
GetSize();
604 for (
size_t i = 0; i < num_modules; i++) {
605 std::optional<llvm::StringRef> maybe_module =
609 "SFBM::CFSD: filter module item %zu not a string.", i);
612 modules.EmplaceBack(*maybe_module);
614 return std::make_shared<SearchFilterByModuleList>(target_sp, modules);
624 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
637 m_cu_spec_list(cu_list) {}
651 size_t num_modules = modules_array->
GetSize();
652 for (
size_t i = 0; i < num_modules; i++) {
653 std::optional<llvm::StringRef> maybe_module =
657 "SFBM::CFSD: filter module item %zu not a string.", i);
673 size_t num_cus = cus_array->
GetSize();
675 for (
size_t i = 0; i < num_cus; i++) {
676 std::optional<llvm::StringRef> maybe_cu =
680 "SFBM::CFSD: filter CU item %zu not a string.", i);
686 return std::make_shared<SearchFilterByModuleListAndCU>(
687 target_sp, modules, cus);
692 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
748 if (!no_modules_in_filter &&
763 const size_t num_cu = module_sp->GetNumCompileUnits();
764 for (
size_t cu_idx = 0; cu_idx < num_cu; cu_idx++) {
765 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(cu_idx);
773 shouldContinue =
DoCUIteration(module_sp, matchingContext, searcher);
782 if (num_modules == 1) {
787 }
else if (num_modules > 0) {
788 s->
Printf(
", modules(%" PRIu64
") = ",
static_cast<uint64_t
>(num_modules));
789 for (
size_t i = 0; i < num_modules; i++) {
793 if (i != num_modules - 1)
800 return eSymbolContextModule | eSymbolContextCompUnit;
806 return std::make_shared<SearchFilterByModuleListAndCU>(*
this);
static llvm::raw_ostream & error(Stream &strm)
Address & GetBaseAddress()
Get accessor for the base address of the range.
A section + offset based address class.
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
A class that describes a compilation unit.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
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.
size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const
Find a file index.
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
const ConstString & GetFilename() const
Filename string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
A class that describes a function.
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
std::recursive_mutex & GetMutex() const
ModuleIterable Modules() const
StructuredData::ObjectSP SerializeToStructuredData() override
lldb::SearchFilterSP DoCreateCopy() override
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.
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...
~SearchFilterByModuleListAndCU() override
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.
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
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...
FileSpecList m_cu_spec_list
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.
~SearchFilterByModuleList() override
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)
lldb::SearchFilterSP DoCreateCopy() override
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.
FileSpecList m_module_spec_list
StructuredData::ObjectSP SerializeToStructuredData() 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 lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
~SearchFilterByModule() override
bool AddressPasses(Address &address) override
Call this method with a Address to see if address passes the filter.
StructuredData::ObjectSP SerializeToStructuredData() override
bool ModulePasses(const lldb::ModuleSP &module_sp) override
Call this method with a Module to see if that module passes the filter.
lldb::SearchFilterSP DoCreateCopy() override
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
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.
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...
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
StructuredData::ObjectSP SerializeToStructuredData() override
lldb::SearchFilterSP DoCreateCopy() override
bool ModulePasses(const FileSpec &module_spec) override
Call this method with a file spec to see if that spec passes the filter.
General Outline: Provides the callback and search depth for the SearchFilter search.
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()
lldb::TargetSP m_target_sp
virtual lldb::SearchFilterSP DoCreateCopy()=0
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...
const char * GetFilterName()
virtual bool ModulePasses(const FileSpec &spec)
Call this method with a file spec to see if that spec passes the filter.
virtual void GetDescription(Stream *s)
Prints a canonical description for the search filter to the stream s.
lldb::SearchFilterSP CreateCopy(lldb::TargetSP &target_sp)
virtual uint32_t GetFilterRequiredItems()
This determines which items are REQUIRED for the filter to pass.
static lldb::SearchFilterSP CreateFromStructuredData(const lldb::TargetSP &target_sp, const StructuredData::Dictionary &data_dict, Status &error)
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
@ eCallbackReturnContinue
virtual void GetDescription(Stream *s)
Prints a canonical description for the searcher to the stream s.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
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
virtual bool IsValid() 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.
virtual size_t ParseFunctions(CompileUnit &comp_unit)=0
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Function > FunctionSP
std::shared_ptr< lldb_private::SearchFilter > SearchFilterSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP