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) {}
83 error.SetErrorString(
"Can't deserialize from an invalid data object.");
87 llvm::StringRef subclass_name;
92 error.SetErrorString(
"Filter data missing subclass key");
98 error.SetErrorStringWithFormatv(
"Unknown filter type: {0}.", subclass_name);
105 if (!success || !subclass_options || !subclass_options->
IsValid()) {
106 error.SetErrorString(
"Filter data missing subclass options key.");
110 switch (filter_type) {
113 target_sp, *subclass_options,
error);
117 target_sp, *subclass_options,
error);
121 target_sp, *subclass_options,
error);
125 target_sp, *subclass_options,
error);
128 error.SetErrorString(
"Can't serialize exception breakpoints yet.");
131 llvm_unreachable(
"Should never get an uresolvable filter type.");
157 return (lldb::SymbolContextItem)0;
166 ret_sp->SetTarget(target_sp);
174 if (!options_dict_sp || !options_dict_sp->IsValid())
177 auto type_dict_sp = std::make_shared<StructuredData::Dictionary>();
187 size_t num_modules = file_list.
GetSize();
190 if (num_modules == 0)
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>(
198 options_dict_sp->AddItem(
GetKey(name), module_array_sp);
274 return shouldContinue;
279 return shouldContinue;
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));
311 shouldContinue = searcher.
SearchCallback(*
this, matchingContext,
nullptr);
316 return shouldContinue;
323 SymbolFile *sym_file = module_sp->GetSymbolFile();
329 cu_sp->ForeachFunction([&](
const FunctionSP &func_sp) {
333 SymbolContext matchingContext(m_target_sp, module_sp, cu_sp.get(),
336 searcher.SearchCallback(*this, matchingContext, nullptr);
338 shouldContinue = DoFunctionIteration(func_sp.get(), context, searcher);
360 return std::make_shared<SearchFilterForUnconstrainedSearches>(target_sp);
366 auto result_sp = std::make_shared<StructuredData::Dictionary>();
372 return !
m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_spec);
379 else if (
m_target_sp->ModuleIsExcludedForUnconstrainedSearches(module_sp))
385 return std::make_shared<SearchFilterForUnconstrainedSearches>(*
this);
426 std::lock_guard<std::recursive_mutex> guard(target_modules.
GetMutex());
446 return eSymbolContextModule;
452 return std::make_shared<SearchFilterByModule>(*
this);
463 error.SetErrorString(
"SFBM::CFSD: Could not find the module list key.");
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.");
474 std::optional<llvm::StringRef> maybe_module =
477 error.SetErrorString(
"SFBM::CFSD: filter module item not a string.");
480 FileSpec module_spec(*maybe_module);
482 return std::make_shared<SearchFilterByModule>(target_sp, module_spec);
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(
500 m_module_spec_list(module_list) {}
505 :
SearchFilter(target_sp, filter_ty), m_module_spec_list(module_list) {}
514 0, module_sp->GetFileSpec(),
false) !=
UINT32_MAX;
557 if (num_modules == 1) {
565 s->
Printf(
", modules(%" PRIu64
") = ", (uint64_t)num_modules);
566 for (
size_t i = 0; i < num_modules; i++) {
570 if (i != num_modules - 1)
576 return eSymbolContextModule;
582 return std::make_shared<SearchFilterByModuleList>(*
this);
594 return std::make_shared<SearchFilterByModuleList>(target_sp,
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 =
602 error.SetErrorStringWithFormat(
603 "SFBM::CFSD: filter module item %zu not a string.", i);
606 modules.EmplaceBack(*maybe_module);
608 return std::make_shared<SearchFilterByModuleList>(target_sp, modules);
618 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
631 m_cu_spec_list(cu_list) {}
645 size_t num_modules = modules_array->
GetSize();
646 for (
size_t i = 0; i < num_modules; i++) {
647 std::optional<llvm::StringRef> maybe_module =
650 error.SetErrorStringWithFormat(
651 "SFBM::CFSD: filter module item %zu not a string.", i);
662 error.SetErrorString(
"SFBM::CFSD: Could not find the CU list key.");
666 size_t num_cus = cus_array->
GetSize();
668 for (
size_t i = 0; i < num_cus; i++) {
669 std::optional<llvm::StringRef> maybe_cu =
672 error.SetErrorStringWithFormat(
673 "SFBM::CFSD: filter CU item %zu not a string.", i);
679 return std::make_shared<SearchFilterByModuleListAndCU>(
680 target_sp, modules, cus);
685 auto options_dict_sp = std::make_shared<StructuredData::Dictionary>();
741 if (!no_modules_in_filter &&
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);
766 shouldContinue =
DoCUIteration(module_sp, matchingContext, searcher);
775 if (num_modules == 1) {
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++) {
786 if (i != num_modules - 1)
793 return eSymbolContextModule | eSymbolContextCompUnit;
799 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()
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.
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