[lldb/Commands] Honor the scripting language passed (2/2)
authorJonas Devlieghere <jonas@devlieghere.com>
Sun, 22 Dec 2019 06:20:03 +0000 (22:20 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Sun, 22 Dec 2019 06:32:13 +0000 (22:32 -0800)
This ensures that watchpoint command honors the scripting language
passed with `-s`. Currently the argument ignores the actual language and
only uses it to differentiate between lldb and script commands.

lldb/source/Commands/CommandObjectWatchpointCommand.cpp

index 237c4e2..4cc74e7 100644 (file)
@@ -37,6 +37,11 @@ static constexpr OptionEnumValueElement g_script_option_enumeration[] = {
         "Commands are in the Python language.",
     },
     {
+        eScriptLanguageLua,
+        "lua",
+        "Commands are in the Python language.",
+    },
+    {
         eSortOrderByName,
         "default-script",
         "Commands are in the default scripting language.",
@@ -331,8 +336,16 @@ are no syntax errors may indicate that a function was declared but never called.
             option_arg, GetDefinitions()[option_idx].enum_values,
             eScriptLanguageNone, error);
 
-        m_use_script_language = (m_script_language == eScriptLanguagePython ||
-                                 m_script_language == eScriptLanguageDefault);
+        switch (m_script_language) {
+        case eScriptLanguagePython:
+        case eScriptLanguageLua:
+          m_use_script_language = true;
+          break;
+        case eScriptLanguageNone:
+        case eScriptLanguageUnknown:
+          m_use_script_language = false;
+          break;
+        }
         break;
 
       case 'e': {
@@ -347,7 +360,6 @@ are no syntax errors may indicate that a function was declared but never called.
 
       case 'F':
         m_use_one_liner = false;
-        m_use_script_language = true;
         m_function_name.assign(option_arg);
         break;
 
@@ -398,12 +410,11 @@ protected:
       return false;
     }
 
-    if (!m_options.m_use_script_language &&
-        !m_options.m_function_name.empty()) {
-      result.AppendError("need to enable scripting to have a function run as a "
-                         "watchpoint command");
-      result.SetStatus(eReturnStatusFailed);
-      return false;
+    if (!m_options.m_function_name.empty()) {
+      if (!m_options.m_use_script_language) {
+        m_options.m_script_language = GetDebugger().GetScriptLanguage();
+        m_options.m_use_script_language = true;
+      }
     }
 
     std::vector<uint32_t> valid_wp_ids;
@@ -433,9 +444,11 @@ protected:
         // to set or collect command callback.  Otherwise, call the methods
         // associated with this object.
         if (m_options.m_use_script_language) {
+          ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter(
+              /*can_create=*/true, m_options.m_script_language);
           // Special handling for one-liner specified inline.
           if (m_options.m_use_one_liner) {
-            GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback(
+            script_interp->SetWatchpointCommandCallback(
                 wp_options, m_options.m_one_liner.c_str());
           }
           // Special handling for using a Python function by name instead of
@@ -445,12 +458,11 @@ protected:
           else if (!m_options.m_function_name.empty()) {
             std::string oneliner(m_options.m_function_name);
             oneliner += "(frame, wp, internal_dict)";
-            GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback(
+            script_interp->SetWatchpointCommandCallback(
                 wp_options, oneliner.c_str());
           } else {
-            GetDebugger()
-                .GetScriptInterpreter()
-                ->CollectDataForWatchpointCommandCallback(wp_options, result);
+            script_interp->CollectDataForWatchpointCommandCallback(wp_options,
+                                                                   result);
           }
         } else {
           // Special handling for one-liner specified inline.