[Lldb-commits] [PATCH] D71235: [lldb/Lua] Generate Lua Bindings and Make Them Available to the Script Interpreter

2019-12-22 Thread Martin Storsjö via Phabricator via lldb-commits
mstorsjo added inline comments.



Comment at: lldb/CMakeLists.txt:55
-  add_subdirectory(scripts)
 endif ()
 

This change here (unconditionally including the scripts subdir) made SWIG a 
hard dependency, even if both lua and python are disabled.

I pushed a commit to fix that, I hope that's ok.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71235



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 218601a - [lldb] Remove unused CompilerDeclContext::IsStructUnionOrClass

2019-12-22 Thread Raphael Isemann via lldb-commits

Author: Raphael Isemann
Date: 2019-12-22T14:01:37+01:00
New Revision: 218601ada1496f920fadddae9a21f7d6ccf48da5

URL: 
https://github.com/llvm/llvm-project/commit/218601ada1496f920fadddae9a21f7d6ccf48da5
DIFF: 
https://github.com/llvm/llvm-project/commit/218601ada1496f920fadddae9a21f7d6ccf48da5.diff

LOG: [lldb] Remove unused CompilerDeclContext::IsStructUnionOrClass

Added: 


Modified: 
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/include/lldb/Symbol/CompilerDeclContext.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/Symbol/ClangASTContext.cpp
lldb/source/Symbol/CompilerDeclContext.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h 
b/lldb/include/lldb/Symbol/ClangASTContext.h
index e0216cce3e10..b0b77305430d 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -444,8 +444,6 @@ class ClangASTContext : public TypeSystem {
   DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name,
 const bool ignore_using_decls) override;
 
-  bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override;
-
   ConstString DeclContextGetName(void *opaque_decl_ctx) override;
 
   ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override;

diff  --git a/lldb/include/lldb/Symbol/CompilerDeclContext.h 
b/lldb/include/lldb/Symbol/CompilerDeclContext.h
index fe8539ab30e6..d7785ada0ba2 100644
--- a/lldb/include/lldb/Symbol/CompilerDeclContext.h
+++ b/lldb/include/lldb/Symbol/CompilerDeclContext.h
@@ -98,8 +98,6 @@ class CompilerDeclContext {
 
   ConstString GetScopeQualifiedName() const;
 
-  bool IsStructUnionOrClass() const;
-
 private:
   TypeSystem *m_type_system = nullptr;
   void *m_opaque_decl_ctx = nullptr;

diff  --git a/lldb/include/lldb/Symbol/TypeSystem.h 
b/lldb/include/lldb/Symbol/TypeSystem.h
index 5143a53674ab..706831f7ee98 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -98,8 +98,6 @@ class TypeSystem : public PluginInterface {
   DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name,
 const bool ignore_imported_decls);
 
-  virtual bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) = 0;
-
   virtual ConstString DeclContextGetName(void *opaque_decl_ctx) = 0;
 
   virtual ConstString

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp 
b/lldb/source/Symbol/ClangASTContext.cpp
index 66a682c34937..0b723cee803f 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -9268,13 +9268,6 @@ uint32_t 
ClangASTContext::CountDeclLevels(clang::DeclContext *frame_decl_ctx,
   return LLDB_INVALID_DECL_LEVEL;
 }
 
-bool ClangASTContext::DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) {
-  if (opaque_decl_ctx)
-return ((clang::DeclContext *)opaque_decl_ctx)->isRecord();
-  else
-return false;
-}
-
 ConstString ClangASTContext::DeclContextGetName(void *opaque_decl_ctx) {
   if (opaque_decl_ctx) {
 clang::NamedDecl *named_decl =

diff  --git a/lldb/source/Symbol/CompilerDeclContext.cpp 
b/lldb/source/Symbol/CompilerDeclContext.cpp
index 672de6ec34d1..25768fcb9f76 100644
--- a/lldb/source/Symbol/CompilerDeclContext.cpp
+++ b/lldb/source/Symbol/CompilerDeclContext.cpp
@@ -37,13 +37,6 @@ ConstString CompilerDeclContext::GetScopeQualifiedName() 
const {
 return ConstString();
 }
 
-bool CompilerDeclContext::IsStructUnionOrClass() const {
-  if (IsValid())
-return m_type_system->DeclContextIsStructUnionOrClass(m_opaque_decl_ctx);
-  else
-return false;
-}
-
 bool CompilerDeclContext::IsClassMethod(lldb::LanguageType *language_ptr,
 bool *is_instance_method_ptr,
 ConstString *language_object_name_ptr) 
{



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D71235: [lldb/Lua] Generate Lua Bindings and Make Them Available to the Script Interpreter

2019-12-22 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/CMakeLists.txt:55
-  add_subdirectory(scripts)
 endif ()
 

mstorsjo wrote:
> This change here (unconditionally including the scripts subdir) made SWIG a 
> hard dependency, even if both lua and python are disabled.
> 
> I pushed a commit to fix that, I hope that's ok.
Totally, thanks for fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71235



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 2046d72 - build: improve python checks for Windows

2019-12-22 Thread Saleem Abdulrasool via lldb-commits

Author: Saleem Abdulrasool
Date: 2019-12-22T13:57:46-08:00
New Revision: 2046d72e91670114625c87e122db6e013ba089d5

URL: 
https://github.com/llvm/llvm-project/commit/2046d72e91670114625c87e122db6e013ba089d5
DIFF: 
https://github.com/llvm/llvm-project/commit/2046d72e91670114625c87e122db6e013ba089d5.diff

LOG: build: improve python checks for Windows

Require a newer CMake on Windows to use the Python3 support that is
packaged in CMake. This version is able to check both 32-bit and 64-bit
versions and will setup everything properly without the user needing to
specify PYTHON_HOME. This enables building lldb's python bindings on
Windows under Azure's CI again.

Added: 


Modified: 
lldb/CMakeLists.txt
lldb/cmake/modules/LLDBConfig.cmake

Removed: 




diff  --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index ff3d8ae70747..6170ab625c54 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -1,4 +1,7 @@
 cmake_minimum_required(VERSION 3.4.3)
+if(CMAKE_SYSTEM_NAME STREQUAL Windows)
+  cmake_minimum_required(VERSION 3.13)
+endif()
 
 if(POLICY CMP0075)
   cmake_policy(SET CMP0075 NEW)

diff  --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index c34ef76cb652..e1da76cf6249 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -138,184 +138,39 @@ if (LLDB_ENABLE_LIBEDIT)
   set(CMAKE_EXTRA_INCLUDE_FILES)
 endif()
 
-# On Windows, we can't use the normal FindPythonLibs module that comes with 
CMake,
-# for a number of reasons.
-# 1) Prior to MSVC 2015, it is only possible to embed Python if python itself 
was
-#compiled with an identical version (and build configuration) of MSVC as 
LLDB.
-#The standard algorithm does not take into account the 
diff erences between
-#a binary release distribution of python and a custom built distribution.
-# 2) From MSVC 2015 and onwards, it is only possible to use Python 3.5 or 
later.
-# 3) FindPythonLibs queries the registry to locate Python, and when looking 
for a
-#64-bit version of Python, since cmake.exe is a 32-bit executable, it will 
see
-#a 32-bit view of the registry.  As such, it is impossible for 
FindPythonLibs to
-#locate 64-bit Python libraries.
-# This function is designed to address those limitations.  Currently it only 
partially
-# addresses them, but it can be improved and extended on an as-needed basis.
-function(find_python_libs_windows_helper LOOKUP_DEBUG OUT_EXE_PATH_VARNAME 
OUT_LIB_PATH_VARNAME OUT_DLL_PATH_VARNAME OUT_VERSION_VARNAME)
-  if(LOOKUP_DEBUG)
-  set(POSTFIX "_d")
-  else()
-  set(POSTFIX "")
-  endif()
-
-  file(TO_CMAKE_PATH "${PYTHON_HOME}/python${POSTFIX}.exe" 
  PYTHON_EXE)
-  file(TO_CMAKE_PATH 
"${PYTHON_HOME}/libs/${PYTHONLIBS_BASE_NAME}${POSTFIX}.lib" PYTHON_LIB)
-  file(TO_CMAKE_PATH "${PYTHON_HOME}/${PYTHONLIBS_BASE_NAME}${POSTFIX}.dll"
  PYTHON_DLL)
-
-  foreach(component PYTHON_EXE;PYTHON_LIB;PYTHON_DLL)
-if(NOT EXISTS ${${component}})
-  message(WARNING "Unable to find ${component}")
-  unset(${component})
-endif()
-  endforeach()
-
-  if (NOT PYTHON_EXE OR NOT PYTHON_LIB OR NOT PYTHON_DLL)
-message(WARNING "Unable to find all Python components.  Python support 
will be disabled for this build.")
-set(LLDB_ENABLE_PYTHON 0 PARENT_SCOPE)
-return()
-  endif()
-
-  # Find the version of the Python interpreter.
-  execute_process(COMMAND "${PYTHON_EXE}" -c
-  "import sys; sys.stdout.write('.'.join([str(x) for x in 
sys.version_info[:3]]))"
-  OUTPUT_VARIABLE PYTHON_VERSION_OUTPUT
-  RESULT_VARIABLE PYTHON_VERSION_RESULT
-  ERROR_QUIET)
-
-  if(PYTHON_VERSION_RESULT)
-message(WARNING "Unable to retrieve Python executable version")
-set(PYTHON_VERSION_OUTPUT "")
-  endif()
-
-  set(${OUT_EXE_PATH_VARNAME} ${PYTHON_EXE} PARENT_SCOPE)
-  set(${OUT_LIB_PATH_VARNAME} ${PYTHON_LIB} PARENT_SCOPE)
-  set(${OUT_DLL_PATH_VARNAME} ${PYTHON_DLL} PARENT_SCOPE)
-  set(${OUT_VERSION_VARNAME}  ${PYTHON_VERSION_OUTPUT} PARENT_SCOPE)
-endfunction()
-
-function(find_python_libs_windows)
-  if ("${PYTHON_HOME}" STREQUAL "")
-message(WARNING "LLDB embedded Python on Windows requires specifying a 
value for PYTHON_HOME.  Python support disabled.")
-set(LLDB_ENABLE_PYTHON 0 PARENT_SCOPE)
-return()
-  endif()
-
-  file(TO_CMAKE_PATH "${PYTHON_HOME}/Include" PYTHON_INCLUDE_DIR)
-
-  if(EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h")
-file(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" python_version_str
- REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
-string(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"+]+)[+]?\".*" 
"\\1"
- PYTHONLIBS_VERSION_STRING "${python_version_str}")
-message(STATUS "Found Python library version ${PYTHONLIBS_VERSION_STRING}")
-string(REGEX REPLACE "([0-9]+

[Lldb-commits] [PATCH] D69535: build: improve python check for Windows

2019-12-22 Thread Saleem Abdulrasool via Phabricator via lldb-commits
compnerd closed this revision.
compnerd added a comment.

GIT 2046d72e916 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69535



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] bd5c8d1 - [lldb/ScriptInterpreter] Unify error message for command script import

2019-12-22 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2019-12-22T16:47:28-08:00
New Revision: bd5c8d167b7cce3290d755e29623d047c2ad8e3e

URL: 
https://github.com/llvm/llvm-project/commit/bd5c8d167b7cce3290d755e29623d047c2ad8e3e
DIFF: 
https://github.com/llvm/llvm-project/commit/bd5c8d167b7cce3290d755e29623d047c2ad8e3e.diff

LOG: [lldb/ScriptInterpreter] Unify error message for command script import

Rather than checking for Python explicitly, let the script interpreter
handle things and print an error if the functionality is not supported.

Added: 
lldb/test/Shell/ScriptInterpreter/None/import_module.test

Modified: 
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Interpreter/ScriptInterpreter.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index b32962b80355..4b866949514d 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -459,10 +459,7 @@ class ScriptInterpreter : public PluginInterface {
   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; }
 

diff  --git a/lldb/source/Commands/CommandObjectCommands.cpp 
b/lldb/source/Commands/CommandObjectCommands.cpp
index b47cc372b4c1..36d6b83d1156 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1426,13 +1426,6 @@ class CommandObjectCommandsScriptImport : public 
CommandObjectParsed {
   };
 
   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);

diff  --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 0ef859061ab1..c7207db5523d 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -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
index ..0af7bfaf24f4
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/None/import_module.test
@@ -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.



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D71824: Add the 'start' and 'length' to the completions response. This will fix an issue where applying a completion 'foo.bar' to 'po foo.b' inserts the entire completion result

2019-12-22 Thread Ivan Hernandez via Phabricator via lldb-commits
ivanhernandez13 created this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71824

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -947,6 +947,7 @@
 0, -1, matches, descriptions);
   size_t count = std::min((uint32_t)50, matches.GetSize());
   targets.reserve(count);
+  auto command_prefix = llvm::StringRef(text).rsplit(" ").second;
   for (size_t i = 0; i < count; i++) {
 std::string match = matches.GetStringAtIndex(i);
 std::string description = descriptions.GetStringAtIndex(i);
@@ -958,6 +959,15 @@
 else
   EmplaceSafeString(item, "label", match + " -- " + description);
 
+auto command_prefix_size = command_prefix.size();
+if (command_prefix_size && match.find(command_prefix, 0) == 0) {
+  EmplaceSafeString(item, "start",
+llvm::StringRef(std::to_string(actual_column -
+   command_prefix_size)));
+  EmplaceSafeString(item, "length",
+llvm::StringRef(std::to_string(command_prefix_size)));
+}
+
 targets.emplace_back(std::move(item));
   }
 


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -947,6 +947,7 @@
 0, -1, matches, descriptions);
   size_t count = std::min((uint32_t)50, matches.GetSize());
   targets.reserve(count);
+  auto command_prefix = llvm::StringRef(text).rsplit(" ").second;
   for (size_t i = 0; i < count; i++) {
 std::string match = matches.GetStringAtIndex(i);
 std::string description = descriptions.GetStringAtIndex(i);
@@ -958,6 +959,15 @@
 else
   EmplaceSafeString(item, "label", match + " -- " + description);
 
+auto command_prefix_size = command_prefix.size();
+if (command_prefix_size && match.find(command_prefix, 0) == 0) {
+  EmplaceSafeString(item, "start",
+llvm::StringRef(std::to_string(actual_column -
+   command_prefix_size)));
+  EmplaceSafeString(item, "length",
+llvm::StringRef(std::to_string(command_prefix_size)));
+}
+
 targets.emplace_back(std::move(item));
   }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D71825: [lldb/Lua] Support loading Lua modules.

2019-12-22 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: LLDB, labath.
Herald added a project: LLDB.

This implements the `command script import` command for Lua.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D71825

Files:
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
  lldb/test/Shell/ScriptInterpreter/Lua/Inputs/testmodule.lua
  lldb/test/Shell/ScriptInterpreter/Lua/command_script_import.test

Index: lldb/test/Shell/ScriptInterpreter/Lua/command_script_import.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/command_script_import.test
@@ -0,0 +1,3 @@
+# REQUIRES: lua
+# RUN: %lldb --script-language lua -o 'command script import /%S/Inputs/testmodule.lua' -o 'script testmodule.foo()' 2>&1 | FileCheck %s
+# CHECK: Hello World!
Index: lldb/test/Shell/ScriptInterpreter/Lua/Inputs/testmodule.lua
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/Inputs/testmodule.lua
@@ -0,0 +1,7 @@
+local mymodule = {}
+
+function mymodule.foo()
+  print("Hello World!")
+end
+
+return mymodule
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
@@ -25,6 +25,11 @@
 
   void ExecuteInterpreterLoop() override;
 
+  virtual bool
+  LoadScriptingModule(const char *filename, bool can_reload, bool init_session,
+  lldb_private::Status &error,
+  StructuredData::ObjectSP *module_sp = nullptr) override;
+
   // Static Functions
   static void Initialize();
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -77,6 +77,18 @@
   debugger.PushIOHandler(io_handler_sp);
 }
 
+bool ScriptInterpreterLua::LoadScriptingModule(
+const char *filename, bool can_reload, bool init_session,
+lldb_private::Status &error, StructuredData::ObjectSP *module_sp) {
+
+  if (llvm::Error e = m_lua->LoadModule(filename, can_reload)) {
+error.SetErrorStringWithFormatv("lua failed to import '{0}': {1}\n",
+filename, llvm::toString(std::move(e)));
+return false;
+  }
+  return true;
+}
+
 void ScriptInterpreterLua::Initialize() {
   static llvm::once_flag g_once_flag;
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
@@ -36,6 +36,7 @@
   }
 
   llvm::Error Run(llvm::StringRef buffer);
+  llvm::Error LoadModule(llvm::StringRef filename, bool can_reload);
 
 private:
   std::mutex m_mutex;
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "Lua.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Utility/FileSpec.h"
 #include "llvm/Support/FormatVariadic.h"
 
 using namespace lldb_private;
@@ -26,3 +28,38 @@
   lua_pop(m_lua_state, 1);
   return e;
 }
+
+llvm::Error Lua::LoadModule(llvm::StringRef filename, bool can_reload) {
+  FileSpec file(filename);
+  if (!FileSystem::Instance().Exists(file)) {
+return llvm::make_error("invalid path",
+   llvm::inconvertibleErrorCode());
+  }
+
+  ConstString module_name = file.GetFileNameStrippingExtension();
+  if (!module_name) {
+return llvm::make_error("invalid module name",
+   llvm::inconvertibleErrorCode());
+  }
+
+  // Add the module path.
+  if (llvm::Error e =
+  Run(llvm::formatv("package.path = package.path .. \";{0}\"",
+file.GetCString())
+  .str())) {
+return e;
+  }
+
+  // Reload the module if requested.
+  if (can_reload) {
+if (llvm::Error e = Run(llvm::formatv("package.loaded.{0} = nil",
+  module_name.GetStringRef())
+.str())) {
+  return e;
+}
+  }
+
+  // Import the module.
+  return Run(
+  llvm::formatv("{0} = require \"{0}\"", module_name.GetStringRef()).str());
+}
_

[Lldb-commits] [lldb] b449d19 - build: use `find_package(Python3)` rather than `PYTHON_HOME`

2019-12-22 Thread Saleem Abdulrasool via lldb-commits

Author: Saleem Abdulrasool
Date: 2019-12-22T20:47:25-08:00
New Revision: b449d19e55888ab9554b04184c6d9716389820fd

URL: 
https://github.com/llvm/llvm-project/commit/b449d19e55888ab9554b04184c6d9716389820fd
DIFF: 
https://github.com/llvm/llvm-project/commit/b449d19e55888ab9554b04184c6d9716389820fd.diff

LOG: build: use `find_package(Python3)` rather than `PYTHON_HOME`

The behaviour of `PYTHON_HOME` can be emulated by setting
`Python3_EXECUTABLE` to the absolute path instead of the custom variable
now that we can find the python interpreter.

Added: 


Modified: 
lldb/cmake/modules/LLDBConfig.cmake

Removed: 




diff  --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index e1da76cf6249..674b024492ef 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -148,6 +148,7 @@ if (LLDB_ENABLE_PYTHON)
 include_directories(${Python3_INCLUDE_DIRS})
 
 if (NOT LLDB_RELOCATABLE_PYTHON)
+  get_filename_component(PYTHON_HOME "${Python3_EXECUTABLE}" DIRECTORY)
   file(TO_CMAKE_PATH "${PYTHON_HOME}" LLDB_PYTHON_HOME)
 endif()
   else()



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 1562511 - [lldb/ScriptInterpreter] Remove can_reload which is always true (NFC)

2019-12-22 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2019-12-22T21:36:03-08:00
New Revision: 1562511275fe1f002458194c085216cf9ae36d1f

URL: 
https://github.com/llvm/llvm-project/commit/1562511275fe1f002458194c085216cf9ae36d1f
DIFF: 
https://github.com/llvm/llvm-project/commit/1562511275fe1f002458194c085216cf9ae36d1f.diff

LOG: [lldb/ScriptInterpreter] Remove can_reload which is always true (NFC)

The `-r` option for `command script import` is there for legacy
compatibility, however the can_reload flag is always set to true. This
patch removes the flag and any code that relies on it being false.

Added: 


Modified: 
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Core/Module.cpp
lldb/source/Interpreter/ScriptInterpreter.cpp
lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 4b866949514d..1784c93adbac 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -457,7 +457,7 @@ class ScriptInterpreter : public PluginInterface {
   virtual bool CheckObjectExists(const char *name) { return false; }
 
   virtual bool
-  LoadScriptingModule(const char *filename, bool can_reload, bool init_session,
+  LoadScriptingModule(const char *filename, bool init_session,
   lldb_private::Status &error,
   StructuredData::ObjectSP *module_sp = nullptr);
 

diff  --git a/lldb/source/Commands/CommandObjectCommands.cpp 
b/lldb/source/Commands/CommandObjectCommands.cpp
index 36d6b83d1156..1796b6bbcf29 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1403,7 +1403,7 @@ class CommandObjectCommandsScriptImport : public 
CommandObjectParsed {
 
   switch (short_option) {
   case 'r':
-m_allow_reload = true;
+// NO-OP
 break;
   default:
 llvm_unreachable("Unimplemented option");
@@ -1413,16 +1413,11 @@ class CommandObjectCommandsScriptImport : public 
CommandObjectParsed {
 }
 
 void OptionParsingStarting(ExecutionContext *execution_context) override {
-  m_allow_reload = true;
 }
 
 llvm::ArrayRef GetDefinitions() override {
   return llvm::makeArrayRef(g_script_import_options);
 }
-
-// Instance variables to hold the values for command options.
-
-bool m_allow_reload;
   };
 
   bool DoExecute(Args &command, CommandReturnObject &result) override {
@@ -1446,7 +1441,7 @@ class CommandObjectCommandsScriptImport : public 
CommandObjectParsed {
   // more)
   m_exe_ctx.Clear();
   if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
-  entry.c_str(), m_options.m_allow_reload, init_session, error)) {
+  entry.c_str(), init_session, error)) {
 result.SetStatus(eReturnStatusSuccessFinishNoResult);
   } else {
 result.AppendErrorWithFormat("module importing failed: %s",

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 5bb6a55457dd..031892abdd24 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1512,11 +1512,9 @@ bool Module::LoadScriptingResourceInTarget(Target 
*target, Status &error,
 }
 StreamString scripting_stream;
 scripting_fspec.Dump(scripting_stream.AsRawOstream());
-const bool can_reload = true;
 const bool init_lldb_globals = false;
 bool did_load = script_interpreter->LoadScriptingModule(
-scripting_stream.GetData(), can_reload, init_lldb_globals,
-error);
+scripting_stream.GetData(), init_lldb_globals, error);
 if (!did_load)
   return false;
   }

diff  --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index c7207db5523d..208630dfbdb1 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -43,8 +43,8 @@ void 
ScriptInterpreter::CollectDataForWatchpointCommandCallback(
 }
 
 bool ScriptInterpreter::LoadScriptingModule(
-const char *filename, bool can_reload, bool init_session,
-lldb_private::Status &error, StructuredData::ObjectSP *module_sp) {
+const char *filename, bool init_session, lldb_private::Status &error,
+StructuredData::ObjectSP *module_sp) {
   error.SetErrorString(
   "This script interpreter does not support importing modules.");
   return false;

diff  --git 
a/lldb/source/Plugins/OperatingSystem/Python/OperatingS

[Lldb-commits] [PATCH] D71825: [lldb/Lua] Support loading Lua modules.

2019-12-22 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp:57
+
+  // Reload the module if requested.
+  if (llvm::Error e = Run(

`s/ if requested//`


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

https://reviews.llvm.org/D71825



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D71825: [lldb/Lua] Support loading Lua modules.

2019-12-22 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 235092.
JDevlieghere added a comment.

Rebase after `can_reload` removal


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

https://reviews.llvm.org/D71825

Files:
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
  lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
  lldb/test/Shell/ScriptInterpreter/Lua/Inputs/testmodule.lua
  lldb/test/Shell/ScriptInterpreter/Lua/command_script_import.test

Index: lldb/test/Shell/ScriptInterpreter/Lua/command_script_import.test
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/command_script_import.test
@@ -0,0 +1,4 @@
+# REQUIRES: lua
+# RUN: %lldb --script-language lua -o 'command script import %S/Inputs/testmodule.lua' -o 'script testmodule.foo()' 2>&1 | FileCheck %s
+# RUN: %lldb --script-language lua -o 'command script import %S/Inputs/testmodule.lua' -o 'command script import %S/Inputs/testmodule.lua' -o 'script testmodule.foo()'  2>&1 | FileCheck %s
+# CHECK: Hello World!
Index: lldb/test/Shell/ScriptInterpreter/Lua/Inputs/testmodule.lua
===
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Lua/Inputs/testmodule.lua
@@ -0,0 +1,7 @@
+local mymodule = {}
+
+function mymodule.foo()
+  print("Hello World!")
+end
+
+return mymodule
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
@@ -25,6 +25,11 @@
 
   void ExecuteInterpreterLoop() override;
 
+  virtual bool
+  LoadScriptingModule(const char *filename, bool init_session,
+  lldb_private::Status &error,
+  StructuredData::ObjectSP *module_sp = nullptr) override;
+
   // Static Functions
   static void Initialize();
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -77,6 +77,18 @@
   debugger.PushIOHandler(io_handler_sp);
 }
 
+bool ScriptInterpreterLua::LoadScriptingModule(
+const char *filename, bool init_session, lldb_private::Status &error,
+StructuredData::ObjectSP *module_sp) {
+
+  if (llvm::Error e = m_lua->LoadModule(filename)) {
+error.SetErrorStringWithFormatv("lua failed to import '{0}': {1}\n",
+filename, llvm::toString(std::move(e)));
+return false;
+  }
+  return true;
+}
+
 void ScriptInterpreterLua::Initialize() {
   static llvm::once_flag g_once_flag;
 
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
@@ -10,6 +10,7 @@
 #define liblldb_Lua_h_
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 
 #include "lua.hpp"
@@ -36,10 +37,12 @@
   }
 
   llvm::Error Run(llvm::StringRef buffer);
+  llvm::Error LoadModule(llvm::StringRef filename);
 
 private:
   std::mutex m_mutex;
   lua_State *m_lua_state;
+  llvm::StringSet<> m_loaded_modules;
 };
 
 } // namespace lldb_private
Index: lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
@@ -7,6 +7,8 @@
 //===--===//
 
 #include "Lua.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Utility/FileSpec.h"
 #include "llvm/Support/FormatVariadic.h"
 
 using namespace lldb_private;
@@ -26,3 +28,40 @@
   lua_pop(m_lua_state, 1);
   return e;
 }
+
+llvm::Error Lua::LoadModule(llvm::StringRef filename) {
+  FileSpec file(filename);
+  if (!FileSystem::Instance().Exists(file)) {
+return llvm::make_error("invalid path",
+   llvm::inconvertibleErrorCode());
+  }
+
+  ConstString module_name = file.GetFileNameStrippingExtension();
+  if (!module_name) {
+return llvm::make_error("invalid module name",
+   llvm::inconvertibleErrorCode());
+  }
+
+  // Don't clutter the package path and only add the module path if we haven't
+  // seen it before.
+  if (!m_loaded_modules.count(filename)) {
+if (llvm::Error e =
+Run(llvm::formatv("package.path = package.path .. \";{0}\"",
+  file.GetCString())
+