[Lldb-commits] [PATCH] D117462: [lldb/python] Use PythonObject in LLDBSwigPython functions

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

LGTM, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117462

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


[Lldb-commits] [PATCH] D117547: [lldb] Simplify RemoteAwarePlatform::ResolveExecutable

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: jarin, PatriosTheGreat, EugeneBi, yuri.
labath requested review of this revision.
Herald added a project: LLDB.

The function had three branches:

- host
- remote-but-not-connected
- remote-and-connected

All three branches overlap to varying degrees. This patch reduces them
to two by merging the two remote branches. The main difference between
the two is (or should be -- the code is fairly convoluted, so it's hard
to be certain) that in the connected case we can try to download the
module from the remote system.

However, there's no need to fork the code for that. We can just proceed
with the normal (connected) search sequence and let the sub-operations
that require a connected host fail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117547

Files:
  lldb/source/Target/RemoteAwarePlatform.cpp


Index: lldb/source/Target/RemoteAwarePlatform.cpp
===
--- lldb/source/Target/RemoteAwarePlatform.cpp
+++ lldb/source/Target/RemoteAwarePlatform.cpp
@@ -32,62 +32,43 @@
 Status RemoteAwarePlatform::ResolveExecutable(
 const ModuleSpec &module_spec, ModuleSP &exe_module_sp,
 const FileSpecList *module_search_paths_ptr) {
-  Status error;
-  // Nothing special to do here, just use the actual file and architecture
 
-  char exe_path[PATH_MAX];
   ModuleSpec resolved_module_spec(module_spec);
 
-  if (IsHost()) {
-// If we have "ls" as the exe_file, resolve the executable location based
-// on the current path variables
-if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
-  resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
-  resolved_module_spec.GetFileSpec().SetFile(exe_path,
- FileSpec::Style::native);
-  FileSystem::Instance().Resolve(resolved_module_spec.GetFileSpec());
-}
-
-if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
-  FileSystem::Instance().ResolveExecutableLocation(
-  resolved_module_spec.GetFileSpec());
+  if (IsRemote())
+return GetCachedExecutable(resolved_module_spec, exe_module_sp,
+   module_search_paths_ptr);
 
-// Resolve any executable within a bundle on MacOSX
-Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
 
-if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
-  error.Clear();
-else {
-  const uint32_t permissions = FileSystem::Instance().GetPermissions(
-  resolved_module_spec.GetFileSpec());
-  if (permissions && (permissions & eFilePermissionsEveryoneR) == 0)
-error.SetErrorStringWithFormat(
-"executable '%s' is not readable",
-resolved_module_spec.GetFileSpec().GetPath().c_str());
-  else
-error.SetErrorStringWithFormat(
-"unable to find executable for '%s'",
-resolved_module_spec.GetFileSpec().GetPath().c_str());
-}
-  } else {
-if (m_remote_platform_sp) {
-  return GetCachedExecutable(resolved_module_spec, exe_module_sp,
- module_search_paths_ptr);
-}
+  // If we have "ls" as the exe_file, resolve the executable location based
+  // on the current path variables
+  if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
+char exe_path[PATH_MAX];
+resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
+resolved_module_spec.GetFileSpec().SetFile(exe_path,
+   FileSpec::Style::native);
+FileSystem::Instance().Resolve(resolved_module_spec.GetFileSpec());
+  }
 
-// We may connect to a process and use the provided executable (Don't use
-// local $PATH).
+  if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
+FileSystem::Instance().ResolveExecutableLocation(
+resolved_module_spec.GetFileSpec());
 
-// Resolve any executable within a bundle on MacOSX
-Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
+  // Resolve any executable within a bundle on MacOSX
+  Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
 
-if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
-  error.Clear();
+  Status error;
+  if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
+const uint32_t permissions = FileSystem::Instance().GetPermissions(
+resolved_module_spec.GetFileSpec());
+if (permissions && (permissions & eFilePermissionsEveryoneR) == 0)
+  error.SetErrorStringWithFormat(
+  "executable '%s' is not readable",
+  resolved_module_spec.GetFileSpec().GetPath().c_str());
 else
-  error.SetErrorStringWithFormat("the platform is not currently "
- "connected, and '%s' doesn't exist in "
- 

[Lldb-commits] [PATCH] D117547: [lldb] Simplify RemoteAwarePlatform::ResolveExecutable

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.
Herald added a subscriber: JDevlieghere.

I've added as reviewers everyone who has touched this function recently, in 
case you have some checks/use-cases you want to try, or can think of other 
reasons to not do this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117547

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


[Lldb-commits] [lldb] c154f39 - [lldb/python] Use PythonObject in LLDBSwigPython functions

2022-01-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-18T10:28:58+01:00
New Revision: c154f397eeb86ea1a5b8fa46405104ace962cec3

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

LOG: [lldb/python] Use PythonObject in LLDBSwigPython functions

Return our PythonObject wrappers instead of raw PyObjects (obfuscated as
void *). This ensures that ownership (reference counts) of python
objects is automatically tracked.

Differential Revision: https://reviews.llvm.org/D117462

Added: 


Modified: 
lldb/bindings/python/python-wrapper.swig
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Removed: 




diff  --git a/lldb/bindings/python/python-wrapper.swig 
b/lldb/bindings/python/python-wrapper.swig
index 4f1d65200b10f..626fc47bebb9f 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -152,12 +152,12 @@ bool lldb_private::LLDBSwigPythonCallTypeScript(
   return true;
 }
 
-void *lldb_private::LLDBSwigPythonCreateSyntheticProvider(
+PythonObject lldb_private::LLDBSwigPythonCreateSyntheticProvider(
 const char *python_class_name, const char *session_dictionary_name,
 const lldb::ValueObjectSP &valobj_sp) {
   if (python_class_name == NULL || python_class_name[0] == '\0' ||
   !session_dictionary_name)
-Py_RETURN_NONE;
+return PythonObject();
 
   PyErr_Cleaner py_err_cleaner(true);
 
@@ -167,29 +167,29 @@ void *lldb_private::LLDBSwigPythonCreateSyntheticProvider(
   python_class_name, dict);
 
   if (!pfunc.IsAllocated())
-Py_RETURN_NONE;
+return PythonObject();
 
   auto sb_value = std::make_unique(valobj_sp);
   sb_value->SetPreferSyntheticValue(false);
 
   PythonObject val_arg = ToSWIGWrapper(std::move(sb_value));
   if (!val_arg.IsAllocated())
-Py_RETURN_NONE;
+return PythonObject();
 
   PythonObject result = pfunc(val_arg, dict);
 
   if (result.IsAllocated())
-return result.release();
+return result;
 
-  Py_RETURN_NONE;
+  return PythonObject();
 }
 
-void *lldb_private::LLDBSwigPythonCreateCommandObject(
+PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
 const char *python_class_name, const char *session_dictionary_name,
 lldb::DebuggerSP debugger_sp) {
   if (python_class_name == NULL || python_class_name[0] == '\0' ||
   !session_dictionary_name)
-Py_RETURN_NONE;
+return PythonObject();
 
   PyErr_Cleaner py_err_cleaner(true);
   auto dict = PythonModule::MainModule().ResolveName(
@@ -198,24 +198,19 @@ void *lldb_private::LLDBSwigPythonCreateCommandObject(
   python_class_name, dict);
 
   if (!pfunc.IsAllocated())
-return nullptr;
-
-  PythonObject result = pfunc(ToSWIGWrapper(std::move(debugger_sp)), dict);
+return PythonObject();
 
-  if (result.IsAllocated())
-return result.release();
-
-  Py_RETURN_NONE;
+  return pfunc(ToSWIGWrapper(std::move(debugger_sp)), dict);
 }
 
-void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
+PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
 const char *python_class_name, const char *session_dictionary_name,
 const lldb::TargetSP &target_sp,
 const lldb_private::StructuredDataImpl &args_impl,
 std::string &error_string) {
   if (python_class_name == NULL || python_class_name[0] == '\0' ||
   !session_dictionary_name)
-Py_RETURN_NONE;
+return PythonObject();
 
   PyErr_Cleaner py_err_cleaner(true);
 
@@ -227,7 +222,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
   if (!pfunc.IsAllocated()) {
 error_string.append("could not find script class: ");
 error_string.append(python_class_name);
-return nullptr;
+return PythonObject();
   }
 
   PythonObject target_arg = ToSWIGWrapper(target_sp);
@@ -240,7 +235,7 @@ void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
 [&](const llvm::ErrorInfoBase &E) {
   error_string.append(E.message());
 });
-Py_RETURN_NONE;
+return PythonObject();
   }
 
   PythonObject result = {};
@@ -249,21 +244,17 @@ void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
   } else {
 error_string.assign("wrong number of arguments in __init__, should be 2 "
 "(not including self)");
-Py_RETURN_NONE;
   }
-
-  if (result.IsAllocated())
-return result.release();
-  Py_RETURN_NONE;
+  return res

[Lldb-commits] [PATCH] D117462: [lldb/python] Use PythonObject in LLDBSwigPython functions

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc154f397eeb8: [lldb/python] Use PythonObject in 
LLDBSwigPython functions (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117462

Files:
  lldb/bindings/python/python-wrapper.swig
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -80,23 +80,23 @@
   return false;
 }
 
-void *lldb_private::LLDBSwigPythonCreateSyntheticProvider(
+python::PythonObject lldb_private::LLDBSwigPythonCreateSyntheticProvider(
 const char *python_class_name, const char *session_dictionary_name,
 const lldb::ValueObjectSP &valobj_sp) {
-  return nullptr;
+  return python::PythonObject();
 }
 
-void *lldb_private::LLDBSwigPythonCreateCommandObject(
+python::PythonObject lldb_private::LLDBSwigPythonCreateCommandObject(
 const char *python_class_name, const char *session_dictionary_name,
 lldb::DebuggerSP debugger_sp) {
-  return nullptr;
+  return python::PythonObject();
 }
 
-void *lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
+python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThreadPlan(
 const char *python_class_name, const char *session_dictionary_name,
 const StructuredDataImpl &args_data, std::string &error_string,
 const lldb::ThreadPlanSP &thread_plan_sp) {
-  return nullptr;
+  return python::PythonObject();
 }
 
 bool lldb_private::LLDBSWIGPythonCallThreadPlan(void *implementor,
@@ -106,10 +106,11 @@
   return false;
 }
 
-void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
+python::PythonObject
+lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver(
 const char *python_class_name, const char *session_dictionary_name,
 const StructuredDataImpl &args, const lldb::BreakpointSP &bkpt_sp) {
-  return nullptr;
+  return python::PythonObject();
 }
 
 unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver(
@@ -191,30 +192,30 @@
   return false;
 }
 
-void *
+python::PythonObject
 lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
const char *session_dictionary_name,
const lldb::ProcessSP &process_sp) {
-  return nullptr;
+  return python::PythonObject();
 }
 
-void *lldb_private::LLDBSwigPythonCreateScriptedProcess(
+python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
 const char *python_class_name, const char *session_dictionary_name,
 const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl,
 std::string &error_string) {
-  return nullptr;
+  return python::PythonObject();
 }
 
-void *lldb_private::LLDBSwigPythonCreateScriptedThread(
+python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThread(
 const char *python_class_name, const char *session_dictionary_name,
 const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
 std::string &error_string) {
-  return nullptr;
+  return python::PythonObject();
 }
 
-void *lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
+python::PythonObject lldb_private::LLDBSWIGPython_CreateFrameRecognizer(
 const char *python_class_name, const char *session_dictionary_name) {
-  return nullptr;
+  return python::PythonObject();
 }
 
 PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments(
@@ -257,11 +258,11 @@
   return nullptr;
 }
 
-void *lldb_private::LLDBSwigPythonCreateScriptedStopHook(
+python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedStopHook(
 lldb::TargetSP target_sp, const char *python_class_name,
 const char *session_dictionary_name, const StructuredDataImpl &args_impl,
 Status &error) {
-  return nullptr;
+  return python::PythonObject();
 }
 
 bool lldb_private::LLDBSwigPythonStopHookCallHandleStop(
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
@@ -43,7 +43,7 @@
   Locker py_lock(&m_interpreter, Locker::Ac

[Lldb-commits] [lldb] 04f13da - [lldb] Fix compiler warning in CommunicationTest

2022-01-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-18T10:31:37+01:00
New Revision: 04f13da677d11f447e6332cf3171f5f1547d01a3

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

LOG: [lldb] Fix compiler warning in CommunicationTest

"0x80 changes value when converted to char"

Added: 


Modified: 
lldb/unittests/Core/CommunicationTest.cpp

Removed: 




diff  --git a/lldb/unittests/Core/CommunicationTest.cpp 
b/lldb/unittests/Core/CommunicationTest.cpp
index c9aba8bb1f1a8..bb57a7b14670f 100644
--- a/lldb/unittests/Core/CommunicationTest.cpp
+++ b/lldb/unittests/Core/CommunicationTest.cpp
@@ -76,7 +76,7 @@ TEST(CommunicationTest, WriteAll) {
   // Write 1 MiB of data into the pipe.
   lldb::ConnectionStatus conn_status;
   Status error;
-  std::vector data(1024 * 1024, 0x80);
+  std::vector data(1024 * 1024, 0x80);
   EXPECT_EQ(write_comm.WriteAll(data.data(), data.size(), conn_status, &error),
 data.size());
   EXPECT_EQ(conn_status, lldb::eConnectionStatusSuccess);



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


[Lldb-commits] [lldb] afb196c - [lldb] s/dyn_cast/isa in TypeSystemClang

2022-01-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-18T10:33:40+01:00
New Revision: afb196c357f787c6e1e960aeca9531494102ad30

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

LOG: [lldb] s/dyn_cast/isa in TypeSystemClang

Added: 


Modified: 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index f8f0689ee2ac4..51b34669ebadc 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -1476,7 +1476,7 @@ void 
TypeSystemClang::CreateFunctionTemplateSpecializationInfo(
 /// as `int I = 3`.
 static bool TemplateParameterAllowsValue(NamedDecl *param,
  const TemplateArgument &value) {
-  if (auto *type_param = llvm::dyn_cast(param)) {
+  if (llvm::isa(param)) {
 // Compare the argument kind, i.e. ensure that  != .
 if (value.getKind() != TemplateArgument::Type)
   return false;



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


[Lldb-commits] [PATCH] D117550: [lldb] Introduce SBPlatform::SetSDKRoot

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: JDevlieghere, jingham.
labath requested review of this revision.
Herald added a project: LLDB.

It complements the existing SBDebugger::SetCurrentPlatformSDKRoot and
allows one to set the sysroot of a platform without making it current.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117550

Files:
  lldb/bindings/interface/SBPlatform.i
  lldb/include/lldb/API/SBPlatform.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Target/Platform.cpp
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py


Index: lldb/test/API/python_api/sbplatform/TestSBPlatform.py
===
--- lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -20,3 +20,11 @@
 cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
 self.assertTrue(plat.Run(cmd).Success())
 self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", 
cmd.GetOutput())
+
+def test_SetSDKRoot(self):
+plat = lldb.SBPlatform("remote-linux") # arbitrary choice
+self.assertTrue(plat)
+plat.SetSDKRoot(self.getBuildDir())
+self.dbg.SetCurrentPlatform("remote-linux")
+self.expect("platform status",
+substrs=["Sysroot:", self.getBuildDir()])
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -428,6 +428,9 @@
 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
   }
 
+  if (GetSDKRootDirectory()) {
+strm.Format("   Sysroot: {0}\n", GetSDKRootDirectory());
+  }
   if (GetWorkingDirectory()) {
 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
   }
Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -513,6 +513,12 @@
   return version.getSubminor().getValueOr(UINT32_MAX);
 }
 
+void SBPlatform::SetSDKRoot(const char *sysroot) {
+  LLDB_RECORD_METHOD(void, SBPlatform, SetSDKRoot, (const char *), sysroot);
+  if (PlatformSP platform_sp = GetSP())
+platform_sp->SetSDKRootDirectory(ConstString(sysroot));
+}
+
 SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get,
  (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -1533,18 +1533,9 @@
   LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
  (const char *), sysroot);
 
-  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
-  if (m_opaque_sp) {
-PlatformSP platform_sp(
-m_opaque_sp->GetPlatformList().GetSelectedPlatform());
-
-if (platform_sp) {
-  if (log && sysroot)
-LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")",
-  sysroot);
-  platform_sp->SetSDKRootDirectory(ConstString(sysroot));
-  return true;
-}
+  if (SBPlatform platform = GetSelectedPlatform()) {
+platform.SetSDKRoot(sysroot);
+return true;
   }
   return false;
 }
Index: lldb/include/lldb/API/SBPlatform.h
===
--- lldb/include/lldb/API/SBPlatform.h
+++ lldb/include/lldb/API/SBPlatform.h
@@ -137,6 +137,8 @@
 
   uint32_t GetOSUpdateVersion();
 
+  void SetSDKRoot(const char *sysroot);
+
   SBError Put(SBFileSpec &src, SBFileSpec &dst);
 
   SBError Get(SBFileSpec &src, SBFileSpec &dst);
Index: lldb/bindings/interface/SBPlatform.i
===
--- lldb/bindings/interface/SBPlatform.i
+++ lldb/bindings/interface/SBPlatform.i
@@ -177,6 +177,9 @@
 uint32_t
 GetOSUpdateVersion ();
 
+void
+SetSDKRoot(const char *sysroot);
+
 lldb::SBError
 Get (lldb::SBFileSpec &src, lldb::SBFileSpec &dst);
 


Index: lldb/test/API/python_api/sbplatform/TestSBPlatform.py
===
--- lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -20,3 +20,11 @@
 cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
 self.assertTrue(plat.Run(cmd).Success())
 self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", cmd.GetOutput())
+
+def test_SetSDKRoot(self):
+plat = lldb.SBPlatform("remote-linux") # arbitrary choice
+self.assertTrue(plat)
+plat.SetSDKRoot(self.getBuildDir())
+self.dbg.SetCurrentPlatform("remote-linux")
+self.expect("platform status",
+substrs=["Sys

[Lldb-commits] [PATCH] D117068: [lldb/Plugins] Add ScriptedProcess::GetThreadsInfo interface

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400799.

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

https://reviews.llvm.org/D117068

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h


Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -39,6 +39,8 @@
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
 
+  StructuredData::DictionarySP GetThreadsInfo() override;
+
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -92,6 +92,17 @@
   return mem_region;
 }
 
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() {
+  Status error;
+  StructuredData::DictionarySP dict =
+  Dispatch("get_threads_info", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
+return {};
+
+  return dict;
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) {
   Status error;
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -41,6 +41,8 @@
 return {};
   }
 
+  virtual StructuredData::DictionarySP GetThreadsInfo() { return nullptr; }
+
   virtual StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) {
 return nullptr;
   }
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -19,6 +19,7 @@
 memory_regions = None
 stack_memory_dump = None
 loaded_images = None
+threads = {}
 
 @abstractmethod
 def __init__(self, target, args):
@@ -51,6 +52,16 @@
 """
 pass
 
+def get_threads_info(self):
+""" Get the dictionary describing the process' Scripted Threads.
+
+Returns:
+Dict: The dictionary of threads, with the thread ID as the key and
+a Scripted Thread instance as the value.
+The dictionary can be empty.
+"""
+return self.threads
+
 @abstractmethod
 def get_thread_with_id(self, tid):
 """ Get the scripted process thread with a specific ID.


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -39,6 +39,8 @@
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
 
+  StructuredData::DictionarySP GetThreadsInfo() override;
+
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -92,6 +92,17 @@
   return mem_region;
 }
 
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() {
+  Status error;
+  StructuredData::DictionarySP dict =
+  Dispatch("get_threads_info", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
+return {};
+
+  return dict;
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) {
   Status error;
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Inter

[Lldb-commits] [PATCH] D117068: [lldb/Plugins] Add ScriptedProcess::GetThreadsInfo interface

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

Rebase


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

https://reviews.llvm.org/D117068

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


[Lldb-commits] [PATCH] D117070: [lldb/Plugins] Move ScriptedThreadInterface to ScriptedThread

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400800.
mib added a comment.

Rebase


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

https://reviews.llvm.org/D117070

Files:
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h


Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -57,7 +57,7 @@
   llvm::Optional GetScriptedThreadPluginName() override;
 
 private:
-  lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() override;
+  lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
 };
 } // namespace lldb_private
 
Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -165,12 +165,8 @@
 }
 
 lldb::ScriptedThreadInterfaceSP
-ScriptedProcessPythonInterface::GetScriptedThreadInterface() {
-  if (!m_scripted_thread_interface_sp)
-m_scripted_thread_interface_sp =
-std::make_shared(m_interpreter);
-
-  return m_scripted_thread_interface_sp;
+ScriptedProcessPythonInterface::CreateScriptedThreadInterface() {
+  return std::make_shared(m_interpreter);
 }
 
 #endif
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -59,6 +59,7 @@
   std::shared_ptr GetDynamicRegisterInfo();
 
   const ScriptedProcess &m_scripted_process;
+  lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
   lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -29,7 +29,9 @@
 }
 
 ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process) {
+: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
+  m_scripted_thread_interface_sp(
+  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
   if (!process.IsValid()) {
 error.SetErrorString("Invalid scripted process");
 return;
@@ -190,7 +192,7 @@
 }
 
 lldb::ScriptedThreadInterfaceSP ScriptedThread::GetInterface() const {
-  return m_scripted_process.GetInterface().GetScriptedThreadInterface();
+  return m_scripted_thread_interface_sp;
 }
 
 std::shared_ptr ScriptedThread::GetDynamicRegisterInfo() {
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -68,11 +68,9 @@
 
 protected:
   friend class ScriptedThread;
-  virtual lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() {
+  virtual lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() {
 return nullptr;
   }
-
-  lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
 };
 
 class ScriptedThreadInterface : virtual public ScriptedInterface {


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -57,7 +57,7 @@
   llvm::Optional GetScriptedThreadPluginName() override;
 
 private:
-  lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() override;
+  lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
 };
 } // namespace lldb_private
 
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -165,12 +165,8 @@
 }
 
 lldb

[Lldb-commits] [PATCH] D117071: [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400801.
mib added a comment.

Rebase


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

https://reviews.llvm.org/D117071

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/main.c
  lldb/test/API/functionalities/scripted_process/main.cpp
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -1,4 +1,4 @@
-import os,struct,signal
+import os,json,struct,signal
 
 from typing import Any, Dict
 
@@ -21,6 +21,14 @@
 idx = int(self.backing_target_idx.GetStringValue(100))
 self.corefile_target = target.GetDebugger().GetTargetAtIndex(idx)
 self.corefile_process = self.corefile_target.GetProcess()
+for corefile_thread in self.corefile_process:
+structured_data = lldb.SBStructuredData()
+structured_data.SetFromJSON(json.dumps({
+"backing_target_idx" : idx,
+"thread_idx" : corefile_thread.GetIndexID()
+}))
+
+self.threads[corefile_thread.GetThreadID()] = StackCoreScriptedThread(self, structured_data)
 
 def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
 mem_region = lldb.SBMemoryRegionInfo()
@@ -70,23 +78,43 @@
 class StackCoreScriptedThread(ScriptedThread):
 def __init__(self, process, args):
 super().__init__(process, args)
-self.backing_target_idx = args.GetValueForKey("backing_target_idx")
+backing_target_idx = args.GetValueForKey("backing_target_idx")
+thread_idx = args.GetValueForKey("thread_idx")
+
+def extract_value_from_structured_data(data, default_val):
+if data and data.IsValid():
+if data.GetType() == lldb.eStructuredDataTypeInteger:
+return data.GetIntegerValue(default_val)
+if data.GetType() == lldb.eStructuredDataTypeString:
+return int(data.GetStringValue(100))
+return None
+
+#TODO: Change to Walrus operator (:=) with oneline if assignment
+# Requires python 3.8
+val = extract_value_from_structured_data(thread_idx, 0)
+if val is not None:
+self.idx = val
 
 self.corefile_target = None
 self.corefile_process = None
-if (self.backing_target_idx and self.backing_target_idx.IsValid()):
-if self.backing_target_idx.GetType() == lldb.eStructuredDataTypeInteger:
-idx = self.backing_target_idx.GetIntegerValue(42)
-if self.backing_target_idx.GetType() == lldb.eStructuredDataTypeString:
-idx = int(self.backing_target_idx.GetStringValue(100))
-self.corefile_target = self.target.GetDebugger().GetTargetAtIndex(idx)
+self.corefile_thread = None
+
+#TODO: Change to Walrus operator (:=) with oneline if assignment
+# Requires python 3.8
+val = extract_value_from_structured_data(backing_target_idx, 42)
+if val is not None:
+self.corefile_target = self.target.GetDebugger().GetTargetAtIndex(val)
 self.corefile_process = self.corefile_target.GetProcess()
+self.corefile_thread = self.corefile_process.GetThreadByIndexID(self.idx)
+
+if self.corefile_thread:
+self.id = self.corefile_thread.GetThreadID()
 
 def get_thread_id(self) -> int:
-return 0x19
+return self.id
 
 def get_name(self) -> str:
-return StackCoreScriptedThread.__name__ + ".thread-1"
+return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
@@ -109,10 +137,9 @@
 return self

[Lldb-commits] [PATCH] D117074: [lldb/Plugins] Enrich ScriptedThreads Stop Reasons with Exceptions

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400802.
mib added a comment.

Rebase


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

https://reviews.llvm.org/D117074

Files:
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -117,9 +117,21 @@
 return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
-return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
-} }
+stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
+
+if self.corefile_thread and self.corefile_thread.IsValid:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
+
+if self.corefile_thread.GetStopReasonDataCount() > 0:
+if stop_reason["type"] == lldb.eStopReasonBreakpoint:
+stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
+stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
+elif stop_reason["type"] == lldb.eStopReasonSignal:
+stop_reason["data"]["signal"] = signal.SIGINT
+elif stop_reason["type"] == lldb.eStopReasonException:
+stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+
+return stop_reason
 
 def get_stackframes(self):
 class ScriptedStackFrame:
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -190,11 +190,11 @@
 self.assertEqual(process.GetNumThreads(), 3)
 thread = process.GetSelectedThread()
 self.assertTrue(thread, "Invalid thread.")
-self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-0")
+self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
 
-self.assertEqual(thread.GetNumFrames(), 2)
+self.assertEqual(thread.GetNumFrames(), 6)
 frame = thread.GetSelectedFrame()
 self.assertTrue(frame, "Invalid frame.")
-# self.assertEqual(frame.GetFunctionName(), "bar")
-# self.assertEqual(int(frame.FindValue("i", lldb.eValueTypeVariableArgument).GetValue()), 42)
-# self.assertEqual(int(frame.FindValue("j", lldb.eValueTypeVariableLocal).GetValue()), 42 * 42)
+self.assertIn("bar", frame.GetFunctionName())
+self.assertEqual(int(frame.FindValue("i", lldb.eValueTypeVariableArgument).GetValue()), 42)
+self.assertEqual(int(frame.FindValue("j", lldb.eValueTypeVariableLocal).GetValue()), 42 * 42)
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -145,6 +145,11 @@
   StructuredData::DictionarySP dict_sp = GetInterface()->GetStopReason();
 
   Status error;
+  if (!dict_sp)
+return GetInterface()->ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "Failed to get scripted thread stop info.", error,
+LIBLLDB_LOG_THREAD);
+
   lldb::StopInfoSP stop_info_sp;
   lldb::StopReason stop_reason_type;
 
@@ -158,7 +163,7 @@
   if (!dict_sp->GetValueForKeyAsDictionary("data", data_dict))
 return GetInterface()->ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
-"Couldn't find value for key 'type' in stop reason dictionary.", error,
+"Couldn't find value for key 'data' in stop reason dictionary.", error,
 LIBLLDB_LOG_THREAD);
 
   switch (stop_reason_type) {
@@ -180,6 +185,13 @@
 stop_info_sp =
 StopInfo::CreateStopReasonWithSignal(*this, signal, description.data());
   } break;
+  case lldb::eStopReasonException: {
+llvm::StringRef description;
+data_dict->GetValueForKeyAsString("desc", description);
+
+stop_info_sp =
+StopInfo::CreateStopReasonWithException(*this, description.data());
+  } break;
   default:
 return GetInterface()->ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/Script

[Lldb-commits] [PATCH] D117076: [lldb/Plugins] Fix ScriptedThread IndexID reporting

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400803.
mib edited the summary of this revision.
mib added a comment.

Rebase and address @labath comments.


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

https://reviews.llvm.org/D117076

Files:
  lldb/include/lldb/Target/Thread.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h

Index: lldb/source/Plugins/Process/scripted/ScriptedThread.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -25,12 +25,18 @@
 namespace lldb_private {
 
 class ScriptedThread : public lldb_private::Thread {
+
 public:
-  ScriptedThread(ScriptedProcess &process, Status &error,
- StructuredData::Generic *script_object = nullptr);
+  ScriptedThread(ScriptedProcess &process,
+ lldb::ScriptedThreadInterfaceSP interface_sp, lldb::tid_t tid,
+ StructuredData::GenericSP script_object_sp = nullptr);
 
   ~ScriptedThread() override;
 
+  static llvm::Expected>
+  Create(ScriptedProcess &process,
+ StructuredData::Generic *script_object = nullptr);
+
   lldb::RegisterContextSP GetRegisterContext() override;
 
   lldb::RegisterContextSP
@@ -61,8 +67,8 @@
 
   const ScriptedProcess &m_scripted_process;
   lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
+  lldb_private::StructuredData::GenericSP m_script_object_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
-  lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };
 
 } // namespace lldb_private
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -28,52 +28,57 @@
   lldbassert(GetInterface() && "Invalid Scripted Thread Interface.");
 }
 
-ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error,
-   StructuredData::Generic *script_object)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
-  m_scripted_thread_interface_sp(
-  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
-  if (!process.IsValid()) {
-error.SetErrorString("Invalid scripted process");
-return;
-  }
+llvm::Expected>
+ScriptedThread::Create(ScriptedProcess &process,
+   StructuredData::Generic *script_object) {
+  if (!process.IsValid())
+return llvm::make_error("Invalid scripted process.",
+   llvm::inconvertibleErrorCode());
 
   process.CheckInterpreterAndScriptObject();
 
-  auto scripted_thread_interface = GetInterface();
-  if (!scripted_thread_interface) {
-error.SetErrorString("Failed to get scripted thread interface.");
-return;
-  }
+  auto scripted_thread_interface =
+  process.GetInterface().CreateScriptedThreadInterface();
+  if (!scripted_thread_interface)
+return llvm::make_error(
+"Failed to create scripted thread interface.",
+llvm::inconvertibleErrorCode());
 
   llvm::Optional class_name =
   process.GetInterface().GetScriptedThreadPluginName();
-  if (!class_name || class_name->empty()) {
-error.SetErrorString("Failed to get scripted thread class name.");
-return;
-  }
+  if (!class_name || class_name->empty())
+return llvm::make_error(
+"Failed to get scripted thread class name.",
+llvm::inconvertibleErrorCode());
 
   ExecutionContext exe_ctx(process);
-
-  m_script_object_sp = scripted_thread_interface->CreatePluginObject(
-  class_name->c_str(), exe_ctx, process.m_scripted_process_info.GetArgsSP(),
-  script_object);
-
-  if (!m_script_object_sp) {
-error.SetErrorString("Failed to create script object");
-return;
-  }
-
-  if (!m_script_object_sp->IsValid()) {
-m_script_object_sp = nullptr;
-error.SetErrorString("Created script object is invalid");
-return;
-  }
+  StructuredData::GenericSP owned_script_object_sp =
+  scripted_thread_interface->CreatePluginObject(
+  class_name->c_str(), exe_ctx,
+  process.m_scripted_process_info.GetArgsSP(), script_object);
+
+  if (!owned_script_object_sp)
+return llvm::make_error(
+"Failed to create script object.", llvm::inconvertibleErrorCode());
+  if (!owned_script_object_sp->IsValid())
+return llvm::make_error(
+"Failed to get scripted thread class name.",
+llvm::inconvertibleErrorCode());
 
   lldb::tid_t tid = scripted_thread_interface->GetThreadID();
-  SetID(tid);
+
+  return std::make_shared(process, scripted_thread_interface,
+  tid, owned_script_object_sp);
 }
 
+ScriptedThread

[Lldb-commits] [PATCH] D117374: [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400804.
mib added a comment.

Rebase


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

https://reviews.llvm.org/D117374

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_interpreter)
-return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "No interpreter.", error);
+return ScriptedInterface::ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "No interpreter.", error);
 
   lldb::DataExtractorSP data_extractor_sp =
   GetInterface().ReadMemoryAtAddress(addr, size, error);
@@ -235,7 +235,7 @@
   0, data_extractor_sp->GetByteSize(), buf, size, GetByteOrder());
 
   if (!bytes_copied || bytes_copied == LLDB_INVALID_OFFSET)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error);
 
   return size;
@@ -293,7 +293,7 @@
   ScriptLanguage language = m_interpreter->GetLanguage();
 
   if (language != eScriptLanguagePython)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 llvm::Twine("ScriptInterpreter language (" +
 llvm::Twine(m_interpreter->LanguageToString(language)) +
@@ -304,7 +304,7 @@
   StructuredData::DictionarySP thread_info_sp = 
GetInterface().GetThreadsInfo();
 
   if (!thread_info_sp)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 "Couldn't fetch thread list from Scripted Process.", error);
 
@@ -312,13 +312,13 @@
   [this, &old_thread_list, &error,
&new_thread_list](ConstString key, StructuredData::Object *val) -> bool 
{
 if (!val)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, "Invalid thread info object", error);
 
 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
 if (!llvm::to_integer(key.AsCString(), tid))
-  return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "Invalid thread id", error);
+  return ScriptedInterface::ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, "Invalid thread id", error);
 
 if (ThreadSP thread_sp =
 old_thread_list.FindThreadByID(tid, false /*=can_update*/)) {
@@ -337,12 +337,12 @@
 ThreadSP thread_sp = thread_or_error.get();
 
 if (!thread_sp)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, "Couldn't initialize thread.", error);
 
 RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
 if (!reg_ctx_sp)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION,
   llvm::Twine("Invalid Register Context for thread " +
   llvm::Twine(key.AsCString()))
Index: lldb/include/lldb/Interpreter/ScriptedInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -31,9 +31,9 @@
  StructuredData::Generic *script_obj = nullptr) = 0;
 
   template 
-  Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
-   Status &error,
-   uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
+  static Ret ErrorWithMessage(llvm::StringRef caller_name,
+  llvm::StringRef error_msg, Status &error,
+  uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
 LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
   caller_name.data(), error_msg.data());
 error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_interpreter)
-return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-

[Lldb-commits] [lldb] 7f4d66f - [lldb] Delete TestStopReplyContainsThreadPcs

2022-01-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-18T14:17:33+01:00
New Revision: 7f4d66f23e3e8a2a03e83a2df0ee3a56790e2b64

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

LOG: [lldb] Delete TestStopReplyContainsThreadPcs

This was meant to be a replacement for the lldb-server sub-test suite of
the API tests, but it never got off the ground and it's making the
windows bot flaky.

Deleting it does not reduce test coverage as the original api test is
still around.

Added: 


Modified: 
lldb/unittests/tools/lldb-server/tests/CMakeLists.txt

Removed: 
lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp



diff  --git a/lldb/unittests/tools/lldb-server/tests/CMakeLists.txt 
b/lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
index ed5eb88ba5270..cb9e138fbe61b 100644
--- a/lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
+++ b/lldb/unittests/tools/lldb-server/tests/CMakeLists.txt
@@ -3,7 +3,6 @@ add_lldb_unittest(LLDBServerTests
   MessageObjects.cpp
   TestBase.cpp
   TestClient.cpp
-  ThreadIdsInJstopinfoTest.cpp
 
   LINK_LIBS
 lldbHost

diff  --git 
a/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp 
b/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
deleted file mode 100644
index 2306b434a6df0..0
--- a/lldb/unittests/tools/lldb-server/tests/ThreadIdsInJstopinfoTest.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-//===-- ThreadsInJstopinfoTest.cpp 
===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "TestBase.h"
-#include "TestClient.h"
-#include "lldb/Utility/DataExtractor.h"
-#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Testing/Support/Error.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-#include 
-
-using namespace llgs_tests;
-using namespace lldb_private;
-using namespace llvm;
-using namespace lldb;
-using namespace testing;
-
-#ifdef __NetBSD__
-#define SKIP_ON_NETBSD(x) DISABLED_ ## x
-#else
-#define SKIP_ON_NETBSD(x) x
-#endif
-
-TEST_F(StandardStartupTest, SKIP_ON_NETBSD(TestStopReplyContainsThreadPcs)) {
-  // This inferior spawns 4 threads, then forces a break.
-  ASSERT_THAT_ERROR(
-  Client->SetInferior({getInferiorPath("thread_inferior"), "4"}),
-  Succeeded());
-
-  ASSERT_THAT_ERROR(Client->ListThreadsInStopReply(), Succeeded());
-  ASSERT_THAT_ERROR(Client->ContinueAll(), Succeeded());
-  unsigned int pc_reg = Client->GetPcRegisterId();
-  ASSERT_NE(pc_reg, UINT_MAX);
-
-  auto jthreads_info = Client->GetJThreadsInfo();
-  ASSERT_THAT_EXPECTED(jthreads_info, Succeeded());
-
-  auto stop_reply = Client->GetLatestStopReplyAs();
-  ASSERT_THAT_EXPECTED(stop_reply, Succeeded());
-  auto stop_reply_pcs = stop_reply->getThreadPcs();
-  auto thread_infos = jthreads_info->GetThreadInfos();
-  ASSERT_EQ(stop_reply_pcs.size(), thread_infos.size())
-  << "Thread count mismatch.";
-
-  for (auto stop_reply_pc : stop_reply_pcs) {
-unsigned long tid = stop_reply_pc.first;
-ASSERT_TRUE(thread_infos.find(tid) != thread_infos.end())
-<< "Thread ID: " << tid << " not in JThreadsInfo.";
-EXPECT_THAT(thread_infos[tid].ReadRegister(pc_reg),
-Pointee(Eq(stop_reply_pc.second)));
-  }
-}



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


[Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: hhb, omjavaid, ted.
labath requested review of this revision.
Herald added a project: LLDB.

It was only ever implemented for linux (and android), and even that
implementation is fairly hacky and flaky (e.g. it is relying on
launching the server multiple to avoid port collisions). It is also in
the way of making further changes/cleanups in this area.

If noone is relying on this feature, I think it'd be better to remove
it, and start over if it becomes needed again.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117559

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py

Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
===
--- lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -162,18 +162,11 @@
 self._verbose_log_handler = None
 TestBase.tearDown(self)
 
-def getLocalServerLogFile(self):
-return self.getLogBasenameForCurrentTest() + "-server.log"
-
 def setUpServerLogging(self, is_llgs):
 if len(lldbtest_config.channels) == 0:
 return  # No logging requested
 
-if lldb.remote_platform:
-log_file = lldbutil.join_remote_paths(
-lldb.remote_platform.GetWorkingDirectory(), "server.log")
-else:
-log_file = self.getLocalServerLogFile()
+log_file = self.getLogBasenameForCurrentTest() + "-server.log"
 
 if is_llgs:
 self.debug_monitor_extra_args.append("--log-file=" + log_file)
@@ -192,38 +185,7 @@
 
 def _init_llgs_test(self):
 reverse_connect = True
-if lldb.remote_platform:
-# Reverse connections may be tricky due to firewalls/NATs.
-reverse_connect = False
-
-# FIXME: This is extremely linux-oriented
-
-# Grab the ppid from /proc/[shell pid]/stat
-err, retcode, shell_stat = self.run_platform_command(
-"cat /proc/$$/stat")
-self.assertTrue(
-err.Success() and retcode == 0,
-"Failed to read file /proc/$$/stat: %s, retcode: %d" %
-(err.GetCString(),
- retcode))
-
-# [pid] ([executable]) [state] [*ppid*]
-pid = re.match(r"^\d+ \(.+\) . (\d+)", shell_stat).group(1)
-err, retcode, ls_output = self.run_platform_command(
-"ls -l /proc/%s/exe" % pid)
-self.assertTrue(
-err.Success() and retcode == 0,
-"Failed to read file /proc/%s/exe: %s, retcode: %d" %
-(pid,
- err.GetCString(),
- retcode))
-exe = ls_output.split()[-1]
-
-# If the binary has been deleted, the link name has " (deleted)" appended.
-# Remove if it's there.
-self.debug_monitor_exe = re.sub(r' \(deleted\)$', '', exe)
-else:
-self.debug_monitor_exe = get_lldb_server_exe()
+self.debug_monitor_exe = get_lldb_server_exe()
 
 self.debug_monitor_extra_args = ["gdbserver"]
 self.setUpServerLogging(is_llgs=True)
@@ -239,31 +201,6 @@
 # when the process truly dies.
 self.stub_sends_two_stop_notifications_on_kill = True
 
-def forward_adb_port(self, source, target, direction, device):
-adb = ['adb'] + (['-s', device] if device else []) + [direction]
-
-def remove_port_forward():
-subprocess.call(adb + ["--remove", "tcp:%d" % source])
-
-subprocess.call(adb + ["tcp:%d" % source, "tcp:%d" % target])
-self.addTearDownHook(remove_port_forward)
-
-def _verify_socket(self, sock):
-# Normally, when the remote stub is not ready, we will get ECONNREFUSED during the
-# connect() attempt. However, due to the way how ADB forwarding works, on android targets
-# the connect() will always be successful, but the connection will be immediately dropped
-# if ADB could not connect on the remote side. This function tries to detect this
-# situation, and report it as "connection refused" so that the upper layers attempt the
-# connection again.
-triple = self.dbg.GetSelectedPlatform().GetTriple()
-if not re.match(".*-.*-.*-android", triple):
-return  # Not android.
-can_read, _, _ = select.select([sock], [], [], 0.1)
-if sock not in can_read:
-return  # Data is not available, but the connection is alive.
-if len(sock.recv(1, socket.MSG_PEEK)) == 0:
-raise _ConnectionRefused()  # Got EOF, connection dropped.
-
 def create_socket(self):
 try:
 sock = socket.socket(family=socket.AF_INET)
@@ -274,14 +211,6 @@
 
 logger = self.l

[Lldb-commits] [PATCH] D117076: [lldb/Plugins] Fix ScriptedThread IndexID reporting

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added inline comments.
This revision is now accepted and ready to land.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp:340
+if (!thread_sp)
+  return GetInterface().ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, "Couldn't initialize thread.", error);

Although there's no way to exclude this via the type system (well... we could 
have a `nonnull_shared_ptr`...), this really shouldn't ever happen. All of 
our `Expected`-returning APIs assume that in the non-error 
case, the pointer object will be valid. At best, this deserves an assertion.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:61
+  if (!owned_script_object_sp)
+return llvm::make_error(
+"Failed to create script object.", llvm::inconvertibleErrorCode());

btw, there's a `llvm::createStringError`, which is (slightly) shorter.


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

https://reviews.llvm.org/D117076

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


[Lldb-commits] [PATCH] D117071: [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

I think this is as good as we can make it. Thanks for your patience.


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

https://reviews.llvm.org/D117071

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


[Lldb-commits] [PATCH] D117076: [lldb/Plugins] Fix ScriptedThread IndexID reporting

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400838.

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

https://reviews.llvm.org/D117076

Files:
  lldb/include/lldb/Target/Thread.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h

Index: lldb/source/Plugins/Process/scripted/ScriptedThread.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -25,12 +25,18 @@
 namespace lldb_private {
 
 class ScriptedThread : public lldb_private::Thread {
+
 public:
-  ScriptedThread(ScriptedProcess &process, Status &error,
- StructuredData::Generic *script_object = nullptr);
+  ScriptedThread(ScriptedProcess &process,
+ lldb::ScriptedThreadInterfaceSP interface_sp, lldb::tid_t tid,
+ StructuredData::GenericSP script_object_sp = nullptr);
 
   ~ScriptedThread() override;
 
+  static llvm::Expected>
+  Create(ScriptedProcess &process,
+ StructuredData::Generic *script_object = nullptr);
+
   lldb::RegisterContextSP GetRegisterContext() override;
 
   lldb::RegisterContextSP
@@ -61,8 +67,8 @@
 
   const ScriptedProcess &m_scripted_process;
   lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
+  lldb_private::StructuredData::GenericSP m_script_object_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
-  lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };
 
 } // namespace lldb_private
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -28,52 +28,54 @@
   lldbassert(GetInterface() && "Invalid Scripted Thread Interface.");
 }
 
-ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error,
-   StructuredData::Generic *script_object)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
-  m_scripted_thread_interface_sp(
-  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
-  if (!process.IsValid()) {
-error.SetErrorString("Invalid scripted process");
-return;
-  }
-
+llvm::Expected>
+ScriptedThread::Create(ScriptedProcess &process,
+   StructuredData::Generic *script_object) {
+  if (!process.IsValid())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Invalid scripted process.");
+  
   process.CheckInterpreterAndScriptObject();
 
-  auto scripted_thread_interface = GetInterface();
-  if (!scripted_thread_interface) {
-error.SetErrorString("Failed to get scripted thread interface.");
-return;
-  }
+  auto scripted_thread_interface =
+  process.GetInterface().CreateScriptedThreadInterface();
+  if (!scripted_thread_interface)
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Failed to create scripted thread interface.");
 
   llvm::Optional class_name =
   process.GetInterface().GetScriptedThreadPluginName();
-  if (!class_name || class_name->empty()) {
-error.SetErrorString("Failed to get scripted thread class name.");
-return;
-  }
+  if (!class_name || class_name->empty())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Failed to get scripted thread class name.");
 
   ExecutionContext exe_ctx(process);
-
-  m_script_object_sp = scripted_thread_interface->CreatePluginObject(
-  class_name->c_str(), exe_ctx, process.m_scripted_process_info.GetArgsSP(),
-  script_object);
-
-  if (!m_script_object_sp) {
-error.SetErrorString("Failed to create script object");
-return;
-  }
-
-  if (!m_script_object_sp->IsValid()) {
-m_script_object_sp = nullptr;
-error.SetErrorString("Created script object is invalid");
-return;
-  }
+  StructuredData::GenericSP owned_script_object_sp =
+  scripted_thread_interface->CreatePluginObject(
+  class_name->c_str(), exe_ctx,
+  process.m_scripted_process_info.GetArgsSP(), script_object);
+
+  if (!owned_script_object_sp)
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Failed to create script object.");
+  if (!owned_script_object_sp->IsValid())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Created script object is invalid.");
 
   lldb::tid_t tid = scripted_thread_interface->GetThreadID();
-  SetID(tid);
+
+  return std::make_shared(process, scripted_thread_interface,
+  tid, owned_script_object_sp);
 }
 
+ScriptedThread::Scr

[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
labath added reviewers: stella.stamenova, JDevlieghere.
Herald added a subscriber: mgorny.
labath requested review of this revision.
Herald added a project: LLDB.

This macro was being used to select the proper import/export annotations
on SB classes. Non-windows clients do not have such requirements.

Instead introduce a new macro (LLDB_IN_LIBLLDB), which signals that
we're compiling liblldb itself (and should use dllexport). The default
(no macro) is to use dllimport. I've moved the macro definition to
SBDefines.h, since it only makes sense when building the API library.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117564

Files:
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/lldb-defines.h
  lldb/source/API/CMakeLists.txt
  lldb/tools/driver/CMakeLists.txt
  lldb/tools/lldb-vscode/CMakeLists.txt


Index: lldb/tools/lldb-vscode/CMakeLists.txt
===
--- lldb/tools/lldb-vscode/CMakeLists.txt
+++ lldb/tools/lldb-vscode/CMakeLists.txt
@@ -1,5 +1,4 @@
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" 
)
-  add_definitions( -DIMPORT_LIBLLDB )
   list(APPEND extra_libs lldbHost)
 endif ()
 
Index: lldb/tools/driver/CMakeLists.txt
===
--- lldb/tools/driver/CMakeLists.txt
+++ lldb/tools/driver/CMakeLists.txt
@@ -23,10 +23,6 @@
 Support
   )
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DIMPORT_LIBLLDB )
-endif()
-
 add_dependencies(lldb
   LLDBOptionsTableGen
   ${tablegen_deps}
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -1,7 +1,3 @@
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DEXPORT_LIBLLDB )
-endif()
-
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
 
 if(LLDB_BUILD_FRAMEWORK)
@@ -165,6 +161,7 @@
   VERSION ${LLDB_VERSION}
 )
 
+target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   if (NOT LLDB_EXPORT_ALL_SYMBOLS)
 # If we're not exporting all symbols, we'll want to explicitly set
Index: lldb/include/lldb/lldb-defines.h
===
--- lldb/include/lldb/lldb-defines.h
+++ lldb/include/lldb/lldb-defines.h
@@ -11,18 +11,6 @@
 
 #include "lldb/lldb-types.h"
 
-#if defined(_WIN32)
-#if defined(EXPORT_LIBLLDB)
-#define LLDB_API __declspec(dllexport)
-#elif defined(IMPORT_LIBLLDB)
-#define LLDB_API __declspec(dllimport)
-#else
-#define LLDB_API
-#endif
-#else // defined (_WIN32)
-#define LLDB_API
-#endif
-
 #if !defined(INT32_MAX)
 #define INT32_MAX 2147483647
 #endif
Index: lldb/include/lldb/API/SBDefines.h
===
--- lldb/include/lldb/API/SBDefines.h
+++ lldb/include/lldb/API/SBDefines.h
@@ -15,6 +15,16 @@
 #include "lldb/lldb-types.h"
 #include "lldb/lldb-versioning.h"
 
+#if defined(_WIN32)
+#if defined(LLDB_IN_LIBLLDB)
+#define LLDB_API __declspec(dllexport)
+#else
+#define LLDB_API __declspec(dllimport)
+#endif
+#else // defined (_WIN32)
+#define LLDB_API
+#endif
+
 // Forward Declarations
 namespace lldb {
 


Index: lldb/tools/lldb-vscode/CMakeLists.txt
===
--- lldb/tools/lldb-vscode/CMakeLists.txt
+++ lldb/tools/lldb-vscode/CMakeLists.txt
@@ -1,5 +1,4 @@
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" )
-  add_definitions( -DIMPORT_LIBLLDB )
   list(APPEND extra_libs lldbHost)
 endif ()
 
Index: lldb/tools/driver/CMakeLists.txt
===
--- lldb/tools/driver/CMakeLists.txt
+++ lldb/tools/driver/CMakeLists.txt
@@ -23,10 +23,6 @@
 Support
   )
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DIMPORT_LIBLLDB )
-endif()
-
 add_dependencies(lldb
   LLDBOptionsTableGen
   ${tablegen_deps}
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -1,7 +1,3 @@
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DEXPORT_LIBLLDB )
-endif()
-
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
 
 if(LLDB_BUILD_FRAMEWORK)
@@ -165,6 +161,7 @@
   VERSION ${LLDB_VERSION}
 )
 
+target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   if (NOT LLDB_EXPORT_ALL_SYMBOLS)
 # If we're not exporting all symbols, we'll want to explicitly set
Index: lldb/include/lldb/lldb-defines.h
===
--- lldb/include/lldb/lldb-defines.h
+++ lldb/include/lldb/lldb-defines.h
@@ -11,18 +11,6 @@
 
 #include "lldb/lldb-types.h"
 
-#if defined(_

[Lldb-commits] [PATCH] D117076: [lldb/Plugins] Fix ScriptedThread IndexID reporting

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400843.

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

https://reviews.llvm.org/D117076

Files:
  lldb/include/lldb/Target/Thread.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
@@ -32,7 +32,7 @@
 StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
 StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
-  if (class_name.empty())
+  if (class_name.empty() && !script_obj)
 return {};
 
   ProcessSP process_sp = exe_ctx.GetProcessSP();
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -25,12 +25,18 @@
 namespace lldb_private {
 
 class ScriptedThread : public lldb_private::Thread {
+
 public:
-  ScriptedThread(ScriptedProcess &process, Status &error,
- StructuredData::Generic *script_object = nullptr);
+  ScriptedThread(ScriptedProcess &process,
+ lldb::ScriptedThreadInterfaceSP interface_sp, lldb::tid_t tid,
+ StructuredData::GenericSP script_object_sp = nullptr);
 
   ~ScriptedThread() override;
 
+  static llvm::Expected>
+  Create(ScriptedProcess &process,
+ StructuredData::Generic *script_object = nullptr);
+
   lldb::RegisterContextSP GetRegisterContext() override;
 
   lldb::RegisterContextSP
@@ -61,8 +67,8 @@
 
   const ScriptedProcess &m_scripted_process;
   lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
+  lldb_private::StructuredData::GenericSP m_script_object_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
-  lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };
 
 } // namespace lldb_private
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -28,52 +28,60 @@
   lldbassert(GetInterface() && "Invalid Scripted Thread Interface.");
 }
 
-ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error,
-   StructuredData::Generic *script_object)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
-  m_scripted_thread_interface_sp(
-  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
-  if (!process.IsValid()) {
-error.SetErrorString("Invalid scripted process");
-return;
-  }
+llvm::Expected>
+ScriptedThread::Create(ScriptedProcess &process,
+   StructuredData::Generic *script_object) {
+  if (!process.IsValid())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Invalid scripted process.");
 
   process.CheckInterpreterAndScriptObject();
 
-  auto scripted_thread_interface = GetInterface();
-  if (!scripted_thread_interface) {
-error.SetErrorString("Failed to get scripted thread interface.");
-return;
-  }
-
-  llvm::Optional class_name =
-  process.GetInterface().GetScriptedThreadPluginName();
-  if (!class_name || class_name->empty()) {
-error.SetErrorString("Failed to get scripted thread class name.");
-return;
+  auto scripted_thread_interface =
+  process.GetInterface().CreateScriptedThreadInterface();
+  if (!scripted_thread_interface)
+return llvm::createStringError(
+llvm::inconvertibleErrorCode(),
+"Failed to create scripted thread interface.");
+
+  llvm::StringRef thread_class_name;
+  if (!script_object) {
+llvm::Optional class_name =
+process.GetInterface().GetScriptedThreadPluginName();
+if (!class_name || class_name->empty())
+  return llvm::createStringError(
+  llvm::inconvertibleErrorCode(),
+  "Failed to get scripted thread class name.");
+thread_class_name = *class_name;
   }
 
   ExecutionContext exe_ctx(process);
-
-  m_script_object_sp = scripted_thread_interface->CreatePluginObject(
-  class_name->c_str(), exe_ctx, process.m_scripted_process_info.GetArgsSP(),
-  script_object);
-
-  if (!m_script_object_sp) {
-error.SetErrorString("Failed to create script object");
-return;
-  }
-
-  if (!m_script_object_sp->I

[Lldb-commits] [PATCH] D117374: [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400845.
mib added a comment.

Format


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

https://reviews.llvm.org/D117374

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_interpreter)
-return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "No interpreter.", error);
+return ScriptedInterface::ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "No interpreter.", error);
 
   lldb::DataExtractorSP data_extractor_sp =
   GetInterface().ReadMemoryAtAddress(addr, size, error);
@@ -235,7 +235,7 @@
   0, data_extractor_sp->GetByteSize(), buf, size, GetByteOrder());
 
   if (!bytes_copied || bytes_copied == LLDB_INVALID_OFFSET)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error);
 
   return size;
@@ -293,7 +293,7 @@
   ScriptLanguage language = m_interpreter->GetLanguage();
 
   if (language != eScriptLanguagePython)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 llvm::Twine("ScriptInterpreter language (" +
 llvm::Twine(m_interpreter->LanguageToString(language)) +
@@ -304,7 +304,7 @@
   StructuredData::DictionarySP thread_info_sp = 
GetInterface().GetThreadsInfo();
 
   if (!thread_info_sp)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 "Couldn't fetch thread list from Scripted Process.", error);
 
@@ -312,13 +312,13 @@
   [this, &old_thread_list, &error,
&new_thread_list](ConstString key, StructuredData::Object *val) -> bool 
{
 if (!val)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, "Invalid thread info object", error);
 
 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
 if (!llvm::to_integer(key.AsCString(), tid))
-  return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "Invalid thread id", error);
+  return ScriptedInterface::ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, "Invalid thread id", error);
 
 if (ThreadSP thread_sp =
 old_thread_list.FindThreadByID(tid, false /*=can_update*/)) {
@@ -331,7 +331,7 @@
 auto thread_or_error = ScriptedThread::Create(*this, val->GetAsGeneric());
 
 if (!thread_or_error)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, toString(thread_or_error.takeError()), error);
 
 ThreadSP thread_sp = thread_or_error.get();
@@ -339,7 +339,7 @@
 
 RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
 if (!reg_ctx_sp)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION,
   llvm::Twine("Invalid Register Context for thread " +
   llvm::Twine(key.AsCString()))
Index: lldb/include/lldb/Interpreter/ScriptedInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -31,9 +31,9 @@
  StructuredData::Generic *script_obj = nullptr) = 0;
 
   template 
-  Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
-   Status &error,
-   uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
+  static Ret ErrorWithMessage(llvm::StringRef caller_name,
+  llvm::StringRef error_msg, Status &error,
+  uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
 LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
   caller_name.data(), error_msg.data());
 error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  S

[Lldb-commits] [PATCH] D117374: [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 400847.

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

https://reviews.llvm.org/D117374

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_interpreter)
-return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "No interpreter.", error);
+return ScriptedInterface::ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "No interpreter.", error);
 
   lldb::DataExtractorSP data_extractor_sp =
   GetInterface().ReadMemoryAtAddress(addr, size, error);
@@ -235,7 +235,7 @@
   0, data_extractor_sp->GetByteSize(), buf, size, GetByteOrder());
 
   if (!bytes_copied || bytes_copied == LLDB_INVALID_OFFSET)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error);
 
   return size;
@@ -293,7 +293,7 @@
   ScriptLanguage language = m_interpreter->GetLanguage();
 
   if (language != eScriptLanguagePython)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 llvm::Twine("ScriptInterpreter language (" +
 llvm::Twine(m_interpreter->LanguageToString(language)) +
@@ -304,7 +304,7 @@
   StructuredData::DictionarySP thread_info_sp = 
GetInterface().GetThreadsInfo();
 
   if (!thread_info_sp)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 "Couldn't fetch thread list from Scripted Process.", error);
 
@@ -312,13 +312,13 @@
   [this, &old_thread_list, &error,
&new_thread_list](ConstString key, StructuredData::Object *val) -> bool 
{
 if (!val)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, "Invalid thread info object", error);
 
 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
 if (!llvm::to_integer(key.AsCString(), tid))
-  return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "Invalid thread id", error);
+  return ScriptedInterface::ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, "Invalid thread id", error);
 
 if (ThreadSP thread_sp =
 old_thread_list.FindThreadByID(tid, false /*=can_update*/)) {
@@ -331,7 +331,7 @@
 auto thread_or_error = ScriptedThread::Create(*this, val->GetAsGeneric());
 
 if (!thread_or_error)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, toString(thread_or_error.takeError()), error);
 
 ThreadSP thread_sp = thread_or_error.get();
@@ -339,7 +339,7 @@
 
 RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
 if (!reg_ctx_sp)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION,
   llvm::Twine("Invalid Register Context for thread " +
   llvm::Twine(key.AsCString()))
Index: lldb/include/lldb/Interpreter/ScriptedInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -31,9 +31,9 @@
  StructuredData::Generic *script_obj = nullptr) = 0;
 
   template 
-  Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
-   Status &error,
-   uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
+  static Ret ErrorWithMessage(llvm::StringRef caller_name,
+  llvm::StringRef error_msg, Status &error,
+  uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
 LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
   caller_name.data(), error_msg.data());
 error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_inte

[Lldb-commits] [PATCH] D117071: [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D117071#3251124 , @labath wrote:

> I think this is as good as we can make it. Thanks for your patience.

Thanks for your help :) !


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

https://reviews.llvm.org/D117071

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


[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-18 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova accepted this revision.
stella.stamenova added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [PATCH] D116972: [lldb] Run the test suite in verbose mode

2022-01-18 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

Since @omjavaid is working on a related change in 
https://reviews.llvm.org/D117363, perhaps he can make the necessary changes 
there to support `-j` for the tests?


Repository:
  rZORG LLVM Github Zorg

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

https://reviews.llvm.org/D116972

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


[Lldb-commits] [PATCH] D117581: [lldb] Use lldb-server by default on Windows

2022-01-18 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova created this revision.
stella.stamenova added reviewers: JDevlieghere, clayborg, labath.
stella.stamenova requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The current default is to not use lldb-server on Windows, however, lldb-server 
is more stable than ProcessWindows, so default to using lldb-server.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117581

Files:
  lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp


Index: lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
===
--- lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -79,17 +79,16 @@
 
 ProcessSP ProcessWindows::CreateInstance(lldb::TargetSP target_sp,
  lldb::ListenerSP listener_sp,
- const FileSpec *,
- bool can_connect) {
+ const FileSpec *, bool can_connect) {
   return ProcessSP(new ProcessWindows(target_sp, listener_sp));
 }
 
 static bool ShouldUseLLDBServer() {
   llvm::StringRef use_lldb_server = ::getenv("LLDB_USE_LLDB_SERVER");
-  return use_lldb_server.equals_insensitive("on") ||
- use_lldb_server.equals_insensitive("yes") ||
- use_lldb_server.equals_insensitive("1") ||
- use_lldb_server.equals_insensitive("true");
+  return !use_lldb_server.equals_insensitive("off") &&
+ !use_lldb_server.equals_insensitive("no") &&
+ !use_lldb_server.equals_insensitive("0") &&
+ !use_lldb_server.equals_insensitive("false");
 }
 
 void ProcessWindows::Initialize() {
@@ -97,9 +96,8 @@
 static llvm::once_flag g_once_flag;
 
 llvm::call_once(g_once_flag, []() {
-  PluginManager::RegisterPlugin(GetPluginNameStatic(),
-GetPluginDescriptionStatic(),
-CreateInstance);
+  PluginManager::RegisterPlugin(
+  GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance);
 });
   }
 }
@@ -115,9 +113,8 @@
 ProcessWindows::ProcessWindows(lldb::TargetSP target_sp,
lldb::ListenerSP listener_sp)
 : lldb_private::Process(target_sp, listener_sp),
-  m_watchpoint_ids(
-  RegisterContextWindows::GetNumHardwareBreakpointSlots(),
-  LLDB_INVALID_BREAK_ID) {}
+  m_watchpoint_ids(RegisterContextWindows::GetNumHardwareBreakpointSlots(),
+   LLDB_INVALID_BREAK_ID) {}
 
 ProcessWindows::~ProcessWindows() {}
 


Index: lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
===
--- lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -79,17 +79,16 @@
 
 ProcessSP ProcessWindows::CreateInstance(lldb::TargetSP target_sp,
  lldb::ListenerSP listener_sp,
- const FileSpec *,
- bool can_connect) {
+ const FileSpec *, bool can_connect) {
   return ProcessSP(new ProcessWindows(target_sp, listener_sp));
 }
 
 static bool ShouldUseLLDBServer() {
   llvm::StringRef use_lldb_server = ::getenv("LLDB_USE_LLDB_SERVER");
-  return use_lldb_server.equals_insensitive("on") ||
- use_lldb_server.equals_insensitive("yes") ||
- use_lldb_server.equals_insensitive("1") ||
- use_lldb_server.equals_insensitive("true");
+  return !use_lldb_server.equals_insensitive("off") &&
+ !use_lldb_server.equals_insensitive("no") &&
+ !use_lldb_server.equals_insensitive("0") &&
+ !use_lldb_server.equals_insensitive("false");
 }
 
 void ProcessWindows::Initialize() {
@@ -97,9 +96,8 @@
 static llvm::once_flag g_once_flag;
 
 llvm::call_once(g_once_flag, []() {
-  PluginManager::RegisterPlugin(GetPluginNameStatic(),
-GetPluginDescriptionStatic(),
-CreateInstance);
+  PluginManager::RegisterPlugin(
+  GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance);
 });
   }
 }
@@ -115,9 +113,8 @@
 ProcessWindows::ProcessWindows(lldb::TargetSP target_sp,
lldb::ListenerSP listener_sp)
 : lldb_private::Process(target_sp, listener_sp),
-  m_watchpoint_ids(
-  RegisterContextWindows::GetNumHardwareBreakpointSlots(),
-  LLDB_INVALID_BREAK_ID) {}
+  m_watchpoint_ids(RegisterContextWindows::GetNumHardwareBreakpointSlots(),
+   LLDB_INVALID_BREAK_ID) {}
 
 ProcessWindows::~ProcessWindows() {}
 
___
lldb-commi

[Lldb-commits] [PATCH] D117581: [lldb] Use lldb-server by default on Windows

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

ship it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117581

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


[Lldb-commits] [PATCH] D117113: [lldb] [llgs] Implement qXfer:siginfo:read

2022-01-18 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.
Herald added a subscriber: JDevlieghere.

This does not build correctly with gcc 7.3.1 on CentOS:

  /usr/bin/g++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/mnt/resource/1/b/llvm/Release/tools/lldb/source/Plugins/Process/Linux 
-I/mnt/resource/1/s/llvm-project/lldb/source/Plugins/Process/Linux 
-I/mnt/resource/1/s/llvm-project/lldb/include 
-I/mnt/resource/1/b/llvm/Release/tools/lldb/include 
-I/mnt/resource/1/b/llvm/Release/include 
-I/mnt/resource/1/s/llvm-project/llvm/include 
-I/mnt/resource/1/s/llvm-project/llvm/../clang/include 
-I/mnt/resource/1/b/llvm/Release/tools/lldb/../clang/include 
-I/mnt/resource/1/s/llvm-project/lldb/source 
-I/mnt/resource/1/b/llvm/Release/tools/lldb/source -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
-Wno-maybe-uninitialized -Wno-noexcept-type -Wdelete-non-virtual-dtor 
-Wno-comment -Wmisleading-indentation -fdiagnostics-color -ffunction-sections 
-fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas 
-Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG  
-fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT 
tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/NativeThreadLinux.cpp.o
 -MF 
tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/NativeThreadLinux.cpp.o.d
 -o 
tools/lldb/source/Plugins/Process/Linux/CMakeFiles/lldbPluginProcessLinux.dir/NativeThreadLinux.cpp.o
 -c 
/mnt/resource/1/s/llvm-project/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  
/mnt/resource/1/s/llvm-project/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp:
 In member function ‘virtual llvm::Expected 
> lldb_private::process_linux::NativeThreadLinux::GetSiginfo() const’:
  
/mnt/resource/1/s/llvm-project/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp:552:10:
 error: could not convert ‘siginfo_buf’ from 
‘std::unique_ptr’ to 
‘llvm::Expected >’
 return siginfo_buf;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117113

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


[Lldb-commits] [PATCH] D117113: [lldb] [llgs] Implement qXfer:siginfo:read

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

sounds like something that could be fixed by a couple of std::moves


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117113

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


[Lldb-commits] [PATCH] D117374: [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D117374

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


[Lldb-commits] [PATCH] D117113: [lldb] [llgs] Implement qXfer:siginfo:read

2022-01-18 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

In D117113#3251838 , 
@stella.stamenova wrote:

> This does not build correctly with gcc 7.3.1 on CentOS:

Could you please try adding some `std::move()`s to the relevant returns? I 
don't have an access to such an ancient compiler.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117113

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


[Lldb-commits] [PATCH] D117474: [lldb] Make StatsDuration thread-safe

2022-01-18 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Thanks for finding a solution. I tried originally doing a std::atomic 
but those are not supported. As long as you have verified that storing at a 
uint64_t reports the same kinds of durations and that they are accurate, I am 
good with this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117474

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


[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

Neat


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [PATCH] D117550: [lldb] Introduce SBPlatform::SetSDKRoot

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117550

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


[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, mib.
JDevlieghere requested review of this revision.

We got a few crash reports that showed LLDB initializing Python on two separate 
threads. Make `g_initialized` atomic to prevent that from happening.


https://reviews.llvm.org/D117601

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -85,7 +85,7 @@
   return static_cast(script_interpreter);
 }
 
-static bool g_initialized = false;
+static std::atomic g_initialized(false);
 
 namespace {
 
@@ -3194,11 +3194,12 @@
 #endif
 
 void ScriptInterpreterPythonImpl::InitializePrivate() {
-  if (g_initialized)
+  bool initialized = false;
+  const bool exchanged =
+  g_initialized.compare_exchange_strong(initialized, true);
+  if (!exchanged)
 return;
 
-  g_initialized = true;
-
   LLDB_SCOPED_TIMER();
 
   // RAII-based initialization which correctly handles multiple-initialization,


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -85,7 +85,7 @@
   return static_cast(script_interpreter);
 }
 
-static bool g_initialized = false;
+static std::atomic g_initialized(false);
 
 namespace {
 
@@ -3194,11 +3194,12 @@
 #endif
 
 void ScriptInterpreterPythonImpl::InitializePrivate() {
-  if (g_initialized)
+  bool initialized = false;
+  const bool exchanged =
+  g_initialized.compare_exchange_strong(initialized, true);
+  if (!exchanged)
 return;
 
-  g_initialized = true;
-
   LLDB_SCOPED_TIMER();
 
   // RAII-based initialization which correctly handles multiple-initialization,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D117601

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, jingham.
JDevlieghere requested review of this revision.

Use libobjc.A.dylib as a sentinel to detect situations where we're reading 
libraries from memory instead of the shared cache.


https://reviews.llvm.org/D117623

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2356,24 +2356,29 @@
 }
 
 void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
-  printf("We are checking to warn\n");
+#ifdef __APPLE__
   if (!m_objc_module_sp)
 return;
-  printf("We have a module\n");
 
   ObjectFile* object_file = m_objc_module_sp->GetObjectFile();
   if (!object_file)
 return;
-  printf("We have an object file\n");
 
   if (!object_file->IsInMemory())
 return;
-  printf("We are not in memory\n");
 
-  Debugger &debugger = GetProcess()->GetTarget().GetDebugger();
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
   if (auto stream = debugger.GetAsyncOutputStream()) {
-  stream->PutCString("warning: no expanded shared cache?\n");
+const char *shared_cache_type = "";
+if (PlatformSP platform_sp = target.GetPlatform())
+  shared_cache_type = platform_sp->IsHost() ? "host " : "expanded ";
+stream->Printf(
+"warning: libobjc.A.dylib is being read from memory instead of the %s"
+"shared cache. This will likely reduce performance.\n",
+shared_cache_type);
   }
+#endif
 }
 
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {


Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2356,24 +2356,29 @@
 }
 
 void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
-  printf("We are checking to warn\n");
+#ifdef __APPLE__
   if (!m_objc_module_sp)
 return;
-  printf("We have a module\n");
 
   ObjectFile* object_file = m_objc_module_sp->GetObjectFile();
   if (!object_file)
 return;
-  printf("We have an object file\n");
 
   if (!object_file->IsInMemory())
 return;
-  printf("We are not in memory\n");
 
-  Debugger &debugger = GetProcess()->GetTarget().GetDebugger();
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
   if (auto stream = debugger.GetAsyncOutputStream()) {
-  stream->PutCString("warning: no expanded shared cache?\n");
+const char *shared_cache_type = "";
+if (PlatformSP platform_sp = target.GetPlatform())
+  shared_cache_type = platform_sp->IsHost() ? "host " : "expanded ";
+stream->Printf(
+"warning: libobjc.A.dylib is being read from memory instead of the %s"
+"shared cache. This will likely reduce performance.\n",
+shared_cache_type);
   }
+#endif
 }
 
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2377-2378
+stream->Printf(
+"warning: libobjc.A.dylib is being read from memory instead of the %s"
+"shared cache. This will likely reduce performance.\n",
+shared_cache_type);

Let's bikeshed about the wording!


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117581: [lldb] Use lldb-server by default on Windows

2022-01-18 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

So, sadly, I am going to have to backtrack here. When I set 
`LLDB_USE_LLDB_SERVER` in my environment and ran the tests, they did appear to 
be more stable (fewer failures across 10 test runs), but it was all a joke my 
machine was playing on me.

Running the tests with this current change to default `LLDB_USE_LLDB_SERVER` to 
ON has significantly more failures than without. I haven't investigated yet 
exactly where the failures are coming from, but I did figure out that by 
default not all variables from the environment are preserved when the tests are 
executed, so my setting of `LLDB_USE_LLDB_SERVER` locally did absolutely 
nothing and it wasn't until it was defaulted to ON that the tests ran as 
intended.

I'm going to spend a bit of time to see if I can figure out where the failures 
are coming from, but I suspect it won't be trivial. One of the fun new errors 
is: `error: Execution was interrupted, reason: Attempted to dereference an 
invalid pointer..`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117581

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 401034.
JDevlieghere added a comment.

Unbotch the patch


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

https://reviews.llvm.org/D117623

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();
Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,32 @@
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *shared_cache_type = "";
+if (PlatformSP platform_sp = target.GetPlatform())
+  shared_cache_type = platform_sp->IsHost() ? "host " : "expanded ";
+stream->Printf(
+"warning: libobjc.A.dylib is being read from memory instead of the %s"
+"shared cache. This will likely reduce performance.\n",
+shared_cache_type);
+  }
+#endif
+}
+
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
   if (!m_decl_vendor_up)
 m_decl_vendor_up = std::make_unique(*this);


Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,32 @@
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *shared_cache_type = "";
+if (PlatformSP platform_sp = target.GetPlatform())
+  shared_cache_type = platform_sp->IsHost() ? "host " : "expanded ";
+stream->Printf(
+"warning: libobjc.A.dylib is being read from memory instead of the %s"
+"shared cache. This will likely reduce performance.\n",
+shared_cache_type);
+  }
+#endif
+}
+
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
   if (!m_decl_vendor_up)
 m_decl_vendor_up = std::make_unique(*this);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117490: [lldb] Log prototype

2022-01-18 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

I like the idea of the templates that would not allow bitfields from one log 
channel to be used on another log channel as there we a few incorrect ones in 
the GDB remote process plug-in. See inlined comments




Comment at: lldb/include/lldb/Utility/Logging.h:19
+enum class LLDBLog : uint32_t {
+  Process = 1u << 1,
+  LLVM_MARK_AS_BITMASK_ENUM(UINT32_MAX)

Why wouldn't we just add all of the categories in the enum? Are we trying to 
reduce code changes?



Comment at: lldb/include/lldb/Utility/Logging.h:20
+  Process = 1u << 1,
+  LLVM_MARK_AS_BITMASK_ENUM(UINT32_MAX)
+};

Can we add members here to grab the log channels directly from the LLLDBLog 
enum? Something like:

```
static Log *GetLogIfAll(LLDBLog mask);
static Log *GetLogIfAny(LLDBLog mask);
```



Comment at: lldb/include/lldb/Utility/Logging.h:26
 // Log Bits specific to logging in lldb
-#define LIBLLDB_LOG_PROCESS (1u << 1)
-#define LIBLLDB_LOG_THREAD (1u << 2)
-#define LIBLLDB_LOG_DYNAMIC_LOADER (1u << 3)
-#define LIBLLDB_LOG_EVENTS (1u << 4)
-#define LIBLLDB_LOG_BREAKPOINTS (1u << 5)
-#define LIBLLDB_LOG_WATCHPOINTS (1u << 6)
-#define LIBLLDB_LOG_STEP (1u << 7)
-#define LIBLLDB_LOG_EXPRESSIONS (1u << 8)
-#define LIBLLDB_LOG_TEMPORARY (1u << 9)
-#define LIBLLDB_LOG_STATE (1u << 10)
-#define LIBLLDB_LOG_OBJECT (1u << 11)
-#define LIBLLDB_LOG_COMMUNICATION (1u << 12)
-#define LIBLLDB_LOG_CONNECTION (1u << 13)
-#define LIBLLDB_LOG_HOST (1u << 14)
-#define LIBLLDB_LOG_UNWIND (1u << 15)
-#define LIBLLDB_LOG_API (1u << 16)
-#define LIBLLDB_LOG_SCRIPT (1u << 17)
-#define LIBLLDB_LOG_COMMANDS (1U << 18)
-#define LIBLLDB_LOG_TYPES (1u << 19)
-#define LIBLLDB_LOG_SYMBOLS (1u << 20)
-#define LIBLLDB_LOG_MODULES (1u << 21)
-#define LIBLLDB_LOG_TARGET (1u << 22)
-#define LIBLLDB_LOG_MMAP (1u << 23)
-#define LIBLLDB_LOG_OS (1u << 24)
-#define LIBLLDB_LOG_PLATFORM (1u << 25)
-#define LIBLLDB_LOG_SYSTEM_RUNTIME (1u << 26)
-#define LIBLLDB_LOG_JIT_LOADER (1u << 27)
-#define LIBLLDB_LOG_LANGUAGE (1u << 28)
-#define LIBLLDB_LOG_DATAFORMATTERS (1u << 29)
-#define LIBLLDB_LOG_DEMANGLE (1u << 30)
-#define LIBLLDB_LOG_AST (1u << 31)
-#define LIBLLDB_LOG_ALL (UINT32_MAX)
+#define LIBLLDB_LOG_PROCESS ::lldb_private::LLDBLog::Process
+#define LIBLLDB_LOG_THREAD ::lldb_private::LLDBLog(1u << 2)

Seems like using LLDBLog::Process everywhere instead of LIBLLDB_LOG_PROCESS 
would be cleaner? Are we just trying to reduce code changes?



Comment at: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp:17
 
 static constexpr Log::Category g_categories[] = {
+{{"async"}, {"log asynchronous activity"}, uint32_t(GDBR_LOG_ASYNC)},

Should the Log::Category be templatized with GDBRLog and then we just store 
GDBRLog enum values instead of uint32_t values?



Comment at: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp:18
 static constexpr Log::Category g_categories[] = {
-{{"async"}, {"log asynchronous activity"}, GDBR_LOG_ASYNC},
-{{"break"}, {"log breakpoints"}, GDBR_LOG_BREAKPOINTS},
-{{"comm"}, {"log communication activity"}, GDBR_LOG_COMM},
-{{"packets"}, {"log gdb remote packets"}, GDBR_LOG_PACKETS},
-{{"memory"}, {"log memory reads and writes"}, GDBR_LOG_MEMORY},
+{{"async"}, {"log asynchronous activity"}, uint32_t(GDBR_LOG_ASYNC)},
+{{"break"}, {"log breakpoints"}, uint32_t(GDBR_LOG_BREAKPOINTS)},

If we do templatize Log::Category with GDBRLog (like "Log::Category") 
then we can just use the real enums here?



Comment at: lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp:57
   ProcessSP process_sp(GetProcess());
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+  Log *log(GetLogIfAny(GDBR_LOG_THREAD));
   LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this,

I would love these to be cleaner. Maybe something like:
```
Log *log = GDBRLog.GetLogIfAny(GDBRLog::Thread);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2377
+stream->Printf(
+"warning: libobjc.A.dylib is being read from memory instead of the %s"
+"shared cache. This will likely reduce performance.\n",

Here's my take:

```
libobjc.A.dylib is being read from process memory. This indicates that LLDB 
could not find the the on-disk %s shared cache for this device. This will 
likely reduce debugging performance.
```


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 401036.
JDevlieghere added a comment.

Update warning message


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

https://reviews.llvm.org/D117623

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();
Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,34 @@
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *msg = "read from the shared cache";
+if (PlatformSP platform_sp = target.GetPlatform())
+  msg = platform_sp->IsHost()
+? "read from the host's in-memory shared cache"
+: "find the on-disk shared cache for this device";
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that we could not %s. This will "
+   "likely reduce debugging performance.\n",
+   msg);
+  }
+#endif
+}
+
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
   if (!m_decl_vendor_up)
 m_decl_vendor_up = std::make_unique(*this);


Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,34 @@
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *msg = "read from the shared cache";
+if (PlatformSP platform_sp = target.GetPlatform())
+  msg = platform_sp->IsHost()
+? "read from the host's in-memory shared cache"
+: "find the on-disk shared cache for this device";
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that we could not %s. This will "
+   "likely reduce debugging performance.\n",
+   msg);
+  }
+#endif
+}
+
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
   if (!m_decl_vendor_up)
 m_decl_vendor_up = std::make_unique(*this);
___
lld

[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2379
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that we could not %s. This will "
+   "likely reduce debugging performance.\n",

I would replace `we` with `LLDB`. Users might see this in their IDE's console 
and not even know who `we` is.


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jim Ingham via Phabricator via lldb-commits
jingham added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2359
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)

Why is this code #ifdef APPLE?

If you were debugging from a Linux machine to a macOS system, wouldn't you also 
want to at least see the warning so you would know why their session was slow?


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2379
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that we could not %s. This will "
+   "likely reduce debugging performance.\n",

aprantl wrote:
> I would replace `we` with `LLDB`. Users might see this in their IDE's console 
> and not even know who `we` is.
Good point!


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked an inline comment as done.
JDevlieghere added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2359
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)

jingham wrote:
> Why is this code #ifdef APPLE?
> 
> If you were debugging from a Linux machine to a macOS system, wouldn't you 
> also want to at least see the warning so you would know why their session was 
> slow?
My reasoning was that the error wouldn't be actionable so I'd rather not show 
it all. I don't feel strongly about it though. 


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jim Ingham via Phabricator via lldb-commits
jingham added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2359
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)

JDevlieghere wrote:
> jingham wrote:
> > Why is this code #ifdef APPLE?
> > 
> > If you were debugging from a Linux machine to a macOS system, wouldn't you 
> > also want to at least see the warning so you would know why their session 
> > was slow?
> My reasoning was that the error wouldn't be actionable so I'd rather not show 
> it all. I don't feel strongly about it though. 
It would save people wasting time to try to figure out why this seemed slow, 
which is worth something on its own.  And the Linux user could expand the cache 
on the Mac, copy it over and lldb should be able to use it - with "target 
modules add" by hand if nothing more automatic works.


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere marked 4 inline comments as done.
JDevlieghere added inline comments.



Comment at: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp:2359
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+#ifdef __APPLE__
+  if (!m_objc_module_sp)

jingham wrote:
> JDevlieghere wrote:
> > jingham wrote:
> > > Why is this code #ifdef APPLE?
> > > 
> > > If you were debugging from a Linux machine to a macOS system, wouldn't 
> > > you also want to at least see the warning so you would know why their 
> > > session was slow?
> > My reasoning was that the error wouldn't be actionable so I'd rather not 
> > show it all. I don't feel strongly about it though. 
> It would save people wasting time to try to figure out why this seemed slow, 
> which is worth something on its own.  And the Linux user could expand the 
> cache on the Mac, copy it over and lldb should be able to use it - with 
> "target modules add" by hand if nothing more automatic works.
Fair enough! 


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

https://reviews.llvm.org/D117623

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


[Lldb-commits] [lldb] d230848 - [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-01-18T17:23:38-08:00
New Revision: d230848a85a922260b7ad6984f2dd19222c125a6

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

LOG: [lldb] Print an error message when we're reading libobjc.A.dylib from 
memory

Use libobjc.A.dylib as a sentinel to detect situations where we're
reading libraries from process memory instead of the shared cache.

Differential revision: https://reviews.llvm.org/D117623

Added: 


Modified: 

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h

Removed: 




diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index bd6b6335ca8c9..f2cf25f93eb23 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@ AppleObjCRuntimeV2::AppleObjCRuntimeV2(Process *process,
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,32 @@ void AppleObjCRuntimeV2::WarnIfNoClassesCached(
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *msg = "read from the shared cache";
+if (PlatformSP platform_sp = target.GetPlatform())
+  msg = platform_sp->IsHost()
+? "read from the host's in-memory shared cache"
+: "find the on-disk shared cache for this device";
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that LLDB could not %s. This will "
+   "likely reduce debugging performance.\n",
+   msg);
+  }
+}
+
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
   if (!m_decl_vendor_up)
 m_decl_vendor_up = std::make_unique(*this);

diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
index 6266634e64c56..e1a6b7cde48a7 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@ class AppleObjCRuntimeV2 : public AppleObjCRuntime {
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();



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


[Lldb-commits] [PATCH] D117623: [lldb] Print an error message when we're reading libobjc.A.dylib from memory

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
JDevlieghere marked an inline comment as done.
Closed by commit rGd230848a85a9: [lldb] Print an error message when we're 
reading libobjc.A.dylib from memory (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D117623?vs=401036&id=401058#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117623

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();
Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,32 @@
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *msg = "read from the shared cache";
+if (PlatformSP platform_sp = target.GetPlatform())
+  msg = platform_sp->IsHost()
+? "read from the host's in-memory shared cache"
+: "find the on-disk shared cache for this device";
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that LLDB could not %s. This will "
+   "likely reduce debugging performance.\n",
+   msg);
+  }
+}
+
 DeclVendor *AppleObjCRuntimeV2::GetDeclVendor() {
   if (!m_decl_vendor_up)
 m_decl_vendor_up = std::make_unique(*this);


Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -399,6 +399,7 @@
   };
 
   void WarnIfNoClassesCached(SharedCacheWarningReason reason);
+  void WarnIfNoExpandedSharedCache();
 
   lldb::addr_t GetSharedCacheReadOnlyAddress();
   lldb::addr_t GetSharedCacheBaseAddress();
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -671,7 +671,7 @@
   static const ConstString g_objc_copyRealizedClassList(
   "_ZL33objc_copyRealizedClassList_nolockPj");
   m_has_objc_copyRealizedClassList = HasSymbol(g_objc_copyRealizedClassList);
-
+  WarnIfNoExpandedSharedCache();
   RegisterObjCExceptionRecognizer(process);
 }
 
@@ -2355,6 +2355,32 @@
   }
 }
 
+void AppleObjCRuntimeV2::WarnIfNoExpandedSharedCache() {
+  if (!m_objc_module_sp)
+return;
+
+  ObjectFile *object_file = m_objc_module_sp->GetObjectFile();
+  if (!object_file)
+return;
+
+  if (!object_file->IsInMemory())
+return;
+
+  Target &target = GetProcess()->GetTarget();
+  Debugger &debugger = target.GetDebugger();
+  if (auto stream = debugger.GetAsyncOutputStream()) {
+const char *msg = "read from the shared cache";
+if (PlatformSP platform_sp = target.GetPlatform())
+  msg = platform_sp->IsHost()
+? "read from the host's in-memory shared cache"
+: "find the on-disk shared cache for this device";
+stream->Printf("warning: libobjc.A.dylib is being read from process "
+   "memory. This indicates that LLDB could not %s. This will "
+  

[Lldb-commits] [PATCH] D117632: Instrument SBAPI with scoped timers

2022-01-18 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

I was about to say this shouldn't matter, since most people don't run with 
timers enabled and the timers should be no-ops when timing is off.  But 
LLDB_SCOPED_TIMER seems to do a bunch of work even when the timers are 
disabled.  The work includes "look up the Category in the map of categories, 
making a new one if not found", get the current time of day and stash that 
away, and do whatever the Signpost chooses to do on entry & exit.  So this 
would be adding non-trivial work for everybody for every SB API call.

Is this really necessary?  Seems like you could have LLDB_SCOPED_TIMER do 
nothing if the Timer::g_display_depth == 0.  That would mean that you wouldn't 
get timings for the remaining bit of any timers that would have been active 
when you enabled the timers, but that doesn't seem particularly wrong to me...

I'm a little confused about what you want to achieve as well.  You said you 
want to see "on whose behalf LLDB spends time".  This change will tell you that 
during the course of the debug session, SBWatchpoint::SetSP consumed N seconds, 
and SBWatchpoint::GetSP M seconds.  It will also dump some text to the console 
when an SB API is called, but I'm not sure how you would get access to that 
info and attribute it back to the caller.

But the timers don't record stacks, so you won't know anything about the 
callers, you will just know that that SB API consumed N seconds.  I'm not sure 
how that tells you "on whose behalf lldb spends time".  Of course, the Signpost 
call could do anything you want, so you could have a variant that captures 
stacks, but then these calls are going to get even more expensive...


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117637: Fix build break on CentOS due to gcc 7.3.1

2022-01-18 Thread M. Zeeshan Siddiqui via Phabricator via lldb-commits
codemzs created this revision.
codemzs added reviewers: mgorny, labath, emaste, krytarowski, stella.stamenova.
codemzs requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Pursuant to discussion here https://reviews.llvm.org/D117113


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117637

Files:
  lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp


Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -549,5 +549,5 @@
   GetProcess().GetSignalInfo(GetID(), siginfo_buf->getBufferStart());
   if (!error.Success())
 return error.ToError();
-  return siginfo_buf;
+  return std::move(siginfo_buf);
 }


Index: lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -549,5 +549,5 @@
   GetProcess().GetSignalInfo(GetID(), siginfo_buf->getBufferStart());
   if (!error.Success())
 return error.ToError();
-  return siginfo_buf;
+  return std::move(siginfo_buf);
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117637: Fix build break on CentOS due to gcc 7.3.1

2022-01-18 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova accepted this revision.
stella.stamenova added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117637

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


[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-18 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I don't think that `atomic` is what you want here. In the case of a race, 
the "loser" will immediately continue to use python as if it was initialized, 
even though the winner has not finished the initialization. You most likely 
need `call_once` semantics, blocking all threads until the initialization 
completes.

That said, I think think it would be better to do this initialization in the 
`Initialize` static function. Out of general cleanliness, but with a particular 
with a view towards the SIGINT patch. That way the initialization functions 
happens in a predictable and single-threaded context (as you can see, threads 
are hard), hopefully at a point where nobody will care that we're mucking with 
the SIGINT handlers.


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

https://reviews.llvm.org/D117601

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


[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere planned changes to this revision.
JDevlieghere added a comment.

In D117601#3253663 , @labath wrote:

> I don't think that `atomic` is what you want here. In the case of a 
> race, the "loser" will immediately continue to use python as if it was 
> initialized, even though the winner has not finished the initialization. You 
> most likely need `call_once` semantics, blocking all threads until the 
> initialization completes.
>
> That said, I think think it would be better to do this initialization in the 
> `Initialize` static function. Out of general cleanliness, but with a 
> particular with a view towards the SIGINT patch. That way the initialization 
> functions happens in a predictable and single-threaded context (as you can 
> see, threads are hard), hopefully at a point where nobody will care that 
> we're mucking with the SIGINT handlers.

Makes sense. I’ll update the patch tomorrow.


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

https://reviews.llvm.org/D117601

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