[lldb/ScriptInterpreter] Unify error message for command script import
authorJonas Devlieghere <jonas@devlieghere.com>
Mon, 23 Dec 2019 00:46:01 +0000 (16:46 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Mon, 23 Dec 2019 00:47:28 +0000 (16:47 -0800)
Rather than checking for Python explicitly, let the script interpreter
handle things and print an error if the functionality is not supported.

lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Interpreter/ScriptInterpreter.cpp
lldb/test/Shell/ScriptInterpreter/None/import_module.test [new file with mode: 0644]

index b32962b..4b86694 100644 (file)
@@ -459,10 +459,7 @@ public:
   virtual bool
   LoadScriptingModule(const char *filename, bool can_reload, bool init_session,
                       lldb_private::Status &error,
-                      StructuredData::ObjectSP *module_sp = nullptr) {
-    error.SetErrorString("loading unimplemented");
-    return false;
-  }
+                      StructuredData::ObjectSP *module_sp = nullptr);
 
   virtual bool IsReservedWord(const char *word) { return false; }
 
index b47cc37..36d6b83 100644 (file)
@@ -1426,13 +1426,6 @@ protected:
   };
 
   bool DoExecute(Args &command, CommandReturnObject &result) override {
-    if (GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) {
-      result.AppendError("only scripting language supported for module "
-                         "importing is currently Python");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
-    }
-
     if (command.empty()) {
       result.AppendError("command script import needs one or more arguments");
       result.SetStatus(eReturnStatusFailed);
index 0ef8590..c7207db 100644 (file)
@@ -42,6 +42,14 @@ void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
       "This script interpreter does not support watchpoint callbacks.");
 }
 
+bool ScriptInterpreter::LoadScriptingModule(
+    const char *filename, bool can_reload, bool init_session,
+    lldb_private::Status &error, StructuredData::ObjectSP *module_sp) {
+  error.SetErrorString(
+      "This script interpreter does not support importing modules.");
+  return false;
+}
+
 std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
   switch (language) {
   case eScriptLanguageNone:
diff --git a/lldb/test/Shell/ScriptInterpreter/None/import_module.test b/lldb/test/Shell/ScriptInterpreter/None/import_module.test
new file mode 100644 (file)
index 0000000..0af7bfa
--- /dev/null
@@ -0,0 +1,2 @@
+# RUN: %lldb --script-language none -o 'command script import %t' 2>&1 | FileCheck %s
+# CHECK: error: module importing failed: This script interpreter does not support importing modules.