@@ -139,6 +139,11 @@ static cl::opt<std::string>
139139 cl::desc (" Restrict search to the context of the given variable." ),
140140 cl::value_desc(" variable" ), cl::sub(SymbolsSubcommand));
141141
142+ static cl::opt<std::string> CompilerContext (
143+ " compiler-context" ,
144+ cl::desc (" Specify a compiler context as \" kind:name,...\" ." ),
145+ cl::value_desc(" context" ), cl::sub(SymbolsSubcommand));
146+
142147static cl::list<FunctionNameType> FunctionNameFlags (
143148 " function-flags" , cl::desc(" Function search flags:" ),
144149 cl::values(clEnumValN(eFunctionNameTypeAuto, " auto" ,
@@ -220,6 +225,44 @@ int evaluateMemoryMapCommands(Debugger &Dbg);
220225
221226} // namespace opts
222227
228+ std::vector<CompilerContext> parseCompilerContext () {
229+ std::vector<CompilerContext> result;
230+ if (opts::symbols::CompilerContext.empty ())
231+ return result;
232+
233+ StringRef str{opts::symbols::CompilerContext};
234+ SmallVector<StringRef, 8 > entries_str;
235+ str.split (entries_str, ' ,' , /* maxSplit*/ -1 , /* keepEmpty=*/ false );
236+ for (auto entry_str : entries_str) {
237+ StringRef key, value;
238+ std::tie (key, value) = entry_str.split (' :' );
239+ auto kind =
240+ StringSwitch<CompilerContextKind>(key)
241+ .Case (" TranslationUnit" , CompilerContextKind::TranslationUnit)
242+ .Case (" Module" , CompilerContextKind::Module)
243+ .Case (" Namespace" , CompilerContextKind::Namespace)
244+ .Case (" Class" , CompilerContextKind::Class)
245+ .Case (" Structure" , CompilerContextKind::Structure)
246+ .Case (" Union" , CompilerContextKind::Union)
247+ .Case (" Function" , CompilerContextKind::Function)
248+ .Case (" Variable" , CompilerContextKind::Variable)
249+ .Case (" Enumeration" , CompilerContextKind::Enumeration)
250+ .Case (" Typedef" , CompilerContextKind::Typedef)
251+ .Default (CompilerContextKind::Invalid);
252+ if (value.empty ()) {
253+ WithColor::error () << " compiler context entry has no \" name\"\n " ;
254+ exit (1 );
255+ }
256+ result.push_back ({kind, ConstString{value}});
257+ }
258+ outs () << " Search context: {\n " ;
259+ for (auto entry: result)
260+ entry.Dump ();
261+ outs () << " }\n " ;
262+
263+ return result;
264+ }
265+
223266template <typename ... Args>
224267static Error make_string_error (const char *Format, Args &&... args) {
225268 return llvm::make_error<llvm::StringError>(
@@ -464,8 +507,11 @@ Error opts::symbols::findTypes(lldb_private::Module &Module) {
464507
465508 DenseSet<SymbolFile *> SearchedFiles;
466509 TypeMap Map;
467- Symfile.FindTypes (ConstString (Name), ContextPtr, true , UINT32_MAX,
468- SearchedFiles, Map);
510+ if (!Name.empty ())
511+ Symfile.FindTypes (ConstString (Name), ContextPtr, true , UINT32_MAX,
512+ SearchedFiles, Map);
513+ else
514+ Symfile.FindTypes (parseCompilerContext (), true , Map);
469515
470516 outs () << formatv (" Found {0} types:\n " , Map.GetSize ());
471517 StreamString Stream;
@@ -679,6 +725,9 @@ Expected<Error (*)(lldb_private::Module &)> opts::symbols::getAction() {
679725 if (Regex || !File.empty () || Line != 0 )
680726 return make_string_error (" Cannot search for types using regular "
681727 " expressions, file names or line numbers." );
728+ if (!Name.empty () && !CompilerContext.empty ())
729+ return make_string_error (" Name is ignored if compiler context present." );
730+
682731 return findTypes;
683732
684733 case FindType::Variable:
0 commit comments