[Lldb-commits] [lldb] r250913 - Made the REPL choose a default language if only one REPL can be chosen.

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 21 10:43:18 PDT 2015


Author: spyffe
Date: Wed Oct 21 12:43:18 2015
New Revision: 250913

URL: http://llvm.org/viewvc/llvm-project?rev=250913&view=rev
Log:
Made the REPL choose a default language if only one REPL can be chosen.
This requires REPLs to enumerate the languages they support.

Modified:
    lldb/trunk/include/lldb/Core/PluginManager.h
    lldb/trunk/include/lldb/Target/Language.h
    lldb/trunk/include/lldb/lldb-private-interfaces.h
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/PluginManager.cpp
    lldb/trunk/source/Target/Language.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Core/PluginManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/PluginManager.h (original)
+++ lldb/trunk/include/lldb/Core/PluginManager.h Wed Oct 21 12:43:18 2015
@@ -449,7 +449,8 @@ public:
     static bool
     RegisterPlugin (const ConstString &name,
                     const char *description,
-                    REPLCreateInstance create_callback);
+                    REPLCreateInstance create_callback,
+                    REPLEnumerateSupportedLanguages enumerate_languages_callback);
     
     static bool
     UnregisterPlugin (REPLCreateInstance create_callback);
@@ -460,6 +461,12 @@ public:
     static REPLCreateInstance
     GetREPLCreateCallbackForPluginName (const ConstString &name);
     
+    static REPLEnumerateSupportedLanguages
+    GetREPLEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx);
+    
+    static REPLEnumerateSupportedLanguages
+    GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name);
+    
     //------------------------------------------------------------------
     // Some plug-ins might register a DebuggerInitializeCallback
     // callback when registering the plug-in. After a new Debugger

Modified: lldb/trunk/include/lldb/Target/Language.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Language.h?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Language.h (original)
+++ lldb/trunk/include/lldb/Target/Language.h Wed Oct 21 12:43:18 2015
@@ -149,6 +149,9 @@ public:
     static void
     GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
                                        std::set<lldb::LanguageType> &languages_for_expressions);
+
+    static void
+    GetLanguagesSupportingREPLs (std::set<lldb::LanguageType> &languages);
     
 protected:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/lldb-private-interfaces.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-interfaces.h?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-interfaces.h (original)
+++ lldb/trunk/include/lldb/lldb-private-interfaces.h Wed Oct 21 12:43:18 2015
@@ -51,6 +51,7 @@ namespace lldb_private
     typedef lldb::TypeSystemSP (*TypeSystemCreateInstance) (lldb::LanguageType language, Module *module, Target *target);
     typedef lldb::REPLSP (*REPLCreateInstance) (Error &error, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options);
     typedef void (*TypeSystemEnumerateSupportedLanguages) (std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions);
+    typedef void (*REPLEnumerateSupportedLanguages) (std::set<lldb::LanguageType> &languages);
     typedef int (*ComparisonFunction)(const void *, const void *);
     typedef void (*DebuggerInitializeCallback)(Debugger &debugger);
 

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Oct 21 12:43:18 2015
@@ -1805,11 +1805,6 @@ Debugger::RunREPL (LanguageType language
 {
     Error err;
     FileSpec repl_executable;
-    if (language == eLanguageTypeUnknown)
-    {
-        err.SetErrorString ("must specify a language for a REPL"); // TODO make it possible to specify a default language
-        return err;
-    }
     
     Target *const target = nullptr; // passing in an empty target means the REPL must create one
     

Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Wed Oct 21 12:43:18 2015
@@ -2662,6 +2662,7 @@ struct REPLInstance
     ConstString name;
     std::string description;
     REPLCreateInstance create_callback;
+    REPLEnumerateSupportedLanguages enumerate_languages_callback;
 };
 
 typedef std::vector<REPLInstance> REPLInstances;
@@ -2683,7 +2684,8 @@ GetREPLInstances ()
 bool
 PluginManager::RegisterPlugin (const ConstString &name,
                                const char *description,
-                               REPLCreateInstance create_callback)
+                               REPLCreateInstance create_callback,
+                               REPLEnumerateSupportedLanguages enumerate_languages_callback)
 {
     if (create_callback)
     {
@@ -2693,6 +2695,7 @@ PluginManager::RegisterPlugin (const Con
         if (description && description[0])
             instance.description = description;
         instance.create_callback = create_callback;
+        instance.enumerate_languages_callback = enumerate_languages_callback;
         Mutex::Locker locker (GetREPLMutex ());
         GetREPLInstances ().push_back (instance);
     }

Modified: lldb/trunk/source/Target/Language.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Language.cpp?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/source/Target/Language.cpp (original)
+++ lldb/trunk/source/Target/Language.cpp Wed Oct 21 12:43:18 2015
@@ -299,6 +299,17 @@ Language::GetLanguagesSupportingTypeSyst
     }
 }
 
+static void
+GetLanguagesSupportingREPLs (std::set<lldb::LanguageType> &languages)
+{
+    uint32_t idx = 0;
+    
+    while (REPLEnumerateSupportedLanguages enumerate = PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(idx++))
+    {
+        (*enumerate)(languages);
+    }
+}
+
 std::unique_ptr<Language::TypeScavenger>
 Language::GetTypeScavenger ()
 {

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=250913&r1=250912&r2=250913&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Wed Oct 21 12:43:18 2015
@@ -218,7 +218,19 @@ Target::GetREPL (Error &err, lldb::Langu
 {
     if (language == eLanguageTypeUnknown)
     {
-        return REPLSP(); // must provide a language
+        std::set<LanguageType> repl_languages;
+        
+        Language::GetLanguagesSupportingREPLs(repl_languages);
+        
+        if (repl_languages.size() == 1)
+        {
+            language = *repl_languages.begin();
+        }
+        else
+        {
+            err.SetErrorStringWithFormat("Multiple possible REPL languages.  Please specify a language.");
+            return REPLSP(); // must provide a language
+        }
     }
     
     REPLMap::iterator pos = m_repl_map.find(language);




More information about the lldb-commits mailing list