From 701338a75f0a33b4feee85df8fe8e6f74fe7abda Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Thu, 24 Mar 2016 23:06:42 +0000 Subject: [PATCH] Make it possible for language plugins to provide additional custom help for 'type lookup' llvm-svn: 264356 --- lldb/include/lldb/Target/Language.h | 3 +++ lldb/source/Commands/CommandObjectType.cpp | 30 ++++++++++++++++++++++++++++-- lldb/source/Target/Language.cpp | 6 ++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h index 492425e..d1a3ff8 100644 --- a/lldb/include/lldb/Target/Language.h +++ b/lldb/include/lldb/Target/Language.h @@ -113,6 +113,9 @@ public: virtual std::unique_ptr GetTypeScavenger (); + virtual const char* + GetLanguageSpecificTypeLookupHelp (); + // if an individual data formatter can apply to several types and cross a language boundary // it makes sense for individual languages to want to customize the printing of values of that // type by appending proper prefix/suffix information in language-specific ways diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 23e3c0e9..ac71453 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -3265,8 +3265,8 @@ public: CommandObjectTypeLookup (CommandInterpreter &interpreter) : CommandObjectRaw (interpreter, "type lookup", - "Lookup a type by name in the select target.", - "type lookup ", + "Lookup types and declarations in the current target, following language-specific naming conventions.", + "type lookup ", eCommandRequiresTarget), m_option_group(interpreter), m_command_options() @@ -3283,6 +3283,32 @@ public: return &m_option_group; } + const char* + GetHelpLong () override + { + if (m_cmd_help_long.empty()) + { + StreamString stream; + // FIXME: hardcoding languages is not good + lldb::LanguageType languages[] = {eLanguageTypeObjC,eLanguageTypeC_plus_plus}; + + for(const auto lang_type : languages) + { + if (auto language = Language::FindPlugin(lang_type)) + { + if (const char* help = language->GetLanguageSpecificTypeLookupHelp()) + { + stream.Printf("%s\n", help); + } + } + } + + if (stream.GetData()) + m_cmd_help_long.assign(stream.GetString()); + } + return this->CommandObject::GetHelpLong(); + } + bool DoExecute (const char *raw_command_line, CommandReturnObject &result) override { diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp index 197da91..43fa9b3 100644 --- a/lldb/source/Target/Language.cpp +++ b/lldb/source/Target/Language.cpp @@ -368,6 +368,12 @@ Language::GetTypeScavenger () return nullptr; } +const char* +Language::GetLanguageSpecificTypeLookupHelp () +{ + return nullptr; +} + size_t Language::TypeScavenger::Find (ExecutionContextScope *exe_scope, const char *key, -- 2.7.4