JDevlieghere updated this revision to Diff 198935.
JDevlieghere added a comment.

Move the function into SBDebugger


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61090/new/

https://reviews.llvm.org/D61090

Files:
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/API/SBFileSpec.h
  lldb/include/lldb/API/SBHostOS.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBHostOS.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
  lldb/tools/driver/Driver.cpp

Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -391,7 +391,7 @@
   }
 
   if (m_option_data.m_print_python_path) {
-    SBFileSpec python_file_spec = SBHostOS::GetLLDBPythonPath();
+    SBFileSpec python_file_spec = m_debugger.GetScriptDirectory();
     if (python_file_spec.IsValid()) {
       char python_path[PATH_MAX];
       size_t num_chars = python_file_spec.GetPath(python_path, PATH_MAX);
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h
@@ -46,6 +46,8 @@
   static const char *GetPluginDescriptionStatic();
   static FileSpec GetPythonDir();
 
+  virtual FileSpec GetModuleDirectory() { return GetPythonDir(); };
+
 protected:
   static void ComputePythonDirForApple(llvm::SmallVectorImpl<char> &path);
   static void ComputePythonDirForPosix(llvm::SmallVectorImpl<char> &path);
Index: lldb/source/API/SBHostOS.cpp
===================================================================
--- lldb/source/API/SBHostOS.cpp
+++ lldb/source/API/SBHostOS.cpp
@@ -60,9 +60,7 @@
     fspec = HostInfo::GetHeaderDir();
     break;
   case ePathTypePythonDir:
-#ifndef LLDB_DISABLE_PYTHON
-    fspec = ScriptInterpreterPython::GetPythonDir();
-#endif
+    // Deprecated. Use SBCommandInpterpreter::GetScriptModuleDirectory instead.
     break;
   case ePathTypeLLDBSystemPlugins:
     fspec = HostInfo::GetSystemPluginDir();
Index: lldb/source/API/SBDebugger.cpp
===================================================================
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -577,6 +577,19 @@
       llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);
 }
 
+lldb::SBFileSpec SBDebugger::GetScriptDirectory() const {
+  if (!m_opaque_sp)
+    return {};
+
+  ScriptInterpreter *script_interpreter =
+      m_opaque_sp->GetScriptInterpreter(true);
+
+  if (!script_interpreter)
+    return {};
+
+  return SBFileSpec(script_interpreter->GetModuleDirectory());
+}
+
 const char *SBDebugger::GetVersionString() {
   LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBDebugger, GetVersionString);
 
Index: lldb/include/lldb/Interpreter/ScriptInterpreter.h
===================================================================
--- lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -467,6 +467,8 @@
 
   lldb::ScriptLanguage GetLanguage() { return m_script_lang; }
 
+  virtual FileSpec GetModuleDirectory() { return {}; };
+
 protected:
   Debugger &m_debugger;
   lldb::ScriptLanguage m_script_lang;
Index: lldb/include/lldb/API/SBHostOS.h
===================================================================
--- lldb/include/lldb/API/SBHostOS.h
+++ lldb/include/lldb/API/SBHostOS.h
@@ -18,6 +18,7 @@
 public:
   static lldb::SBFileSpec GetProgramFileSpec();
 
+  // Deprecated. Use SBCommandInpterpreter::GetScriptModuleDirectory instead.
   static lldb::SBFileSpec GetLLDBPythonPath();
 
   static lldb::SBFileSpec GetLLDBPath(lldb::PathType path_type);
Index: lldb/include/lldb/API/SBFileSpec.h
===================================================================
--- lldb/include/lldb/API/SBFileSpec.h
+++ lldb/include/lldb/API/SBFileSpec.h
@@ -61,6 +61,7 @@
   friend class SBBlock;
   friend class SBCommandInterpreter;
   friend class SBCompileUnit;
+  friend class SBDebugger;
   friend class SBDeclaration;
   friend class SBFileSpecList;
   friend class SBHostOS;
Index: lldb/include/lldb/API/SBDebugger.h
===================================================================
--- lldb/include/lldb/API/SBDebugger.h
+++ lldb/include/lldb/API/SBDebugger.h
@@ -180,6 +180,9 @@
 
   lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name);
 
+  /// Return the module path for the script interpreter, if one is registered.
+  lldb::SBFileSpec GetScriptDirectory() const;
+
   static const char *GetVersionString();
 
   static const char *StateAsCString(lldb::StateType state);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to