[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/99814

>From 723b57776128fd5e71af0646e383c01a66611a73 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 23 Jul 2024 02:26:38 -0700
Subject: [PATCH] [lldb/Plugins] Introduce Scripted Platform Plugin

This patch introduces Scripted Platform, a new platform plugin that can
be customized with a python script.

For now this can list processes described in the python script file but
eventually, it will be used to spawn scripted processes and act as an
interface between them.

This patch is also a less intrusive implementation of 2d53527.

It introduces a new PlatformMetadata held by every platform that
contains various objects that might be used by a platform instance.

In its current form, the PlatformMetadata holds a reference to the
Debugger and a ScriptedMetadata pointer. These are necessary in other to
instanciate the scripted object that the ScriptedPlatform interacts with.

In order to make it less introsive with the rest of lldb's platform
creation code, platform metadata are set after the platform creation,
and requires to platform to reload them (using `Platform::ReloadMetadata`).

This approach has the tradeoff that the ScriptedPlaform instance is
technically invalid and useless right after its creation. However, the user
should never be in that situation, since we reload the platform metadata
everytime with create or select the platform.

This work was previously reviewed in:
- https://reviews.llvm.org/D139252
- https://reviews.llvm.org/D142266

Signed-off-by: Med Ismail Bennani 
---
 .../bindings/interface/SBPlatformDocstrings.i |  12 +
 lldb/bindings/python/CMakeLists.txt   |   1 +
 lldb/bindings/python/python-swigsafecast.swig |  10 +
 lldb/bindings/python/python-wrapper.swig  |  36 +++
 .../python/templates/scripted_platform.py |   9 +-
 lldb/include/lldb/API/SBDebugger.h|   2 +
 lldb/include/lldb/API/SBPlatform.h|   4 +-
 lldb/include/lldb/API/SBProcess.h |   2 +
 lldb/include/lldb/API/SBStructuredData.h  |   1 +
 lldb/include/lldb/API/SBTarget.h  |   2 +
 .../Interfaces/ScriptedPlatformInterface.h|   7 +-
 .../lldb/Interpreter/OptionGroupPlatform.h|  10 +-
 .../lldb/Interpreter/ScriptInterpreter.h  |  19 +-
 lldb/include/lldb/Target/Platform.h   |  22 ++
 lldb/include/lldb/Utility/ScriptedMetadata.h  |   4 +-
 lldb/source/API/SBPlatform.cpp|  42 +++
 lldb/source/API/SBStructuredData.cpp  |   8 +-
 .../source/Commands/CommandObjectPlatform.cpp |  20 +-
 lldb/source/Interpreter/ScriptInterpreter.cpp |  15 +
 lldb/source/Plugins/Platform/CMakeLists.txt   |   1 +
 .../Plugins/Platform/scripted/CMakeLists.txt  |   8 +
 .../Platform/scripted/ScriptedPlatform.cpp| 305 ++
 .../Platform/scripted/ScriptedPlatform.h  |  84 +
 .../Process/scripted/ScriptedProcess.h|   2 +-
 .../Process/scripted/ScriptedThread.cpp   |   5 -
 .../Plugins/Process/scripted/ScriptedThread.h |   6 +-
 .../ScriptedPlatformPythonInterface.cpp   |  42 ++-
 .../ScriptedPlatformPythonInterface.h |   5 +-
 .../Interfaces/ScriptedPythonInterface.cpp|  45 +++
 .../Interfaces/ScriptedPythonInterface.h  |  25 +-
 .../Python/SWIGPythonBridge.h |   3 +
 .../Python/ScriptInterpreterPython.cpp|   5 +
 .../Python/ScriptInterpreterPythonImpl.h  |   2 +
 lldb/source/Target/Platform.cpp   |  10 +-
 .../scripted_platform/TestScriptedPlatform.py | 108 +++
 .../scripted_platform/my_scripted_platform.py |  27 +-
 .../Python/PythonTestSuite.cpp|  15 +
 37 files changed, 869 insertions(+), 55 deletions(-)
 create mode 100644 lldb/source/Plugins/Platform/scripted/CMakeLists.txt
 create mode 100644 lldb/source/Plugins/Platform/scripted/ScriptedPlatform.cpp
 create mode 100644 lldb/source/Plugins/Platform/scripted/ScriptedPlatform.h
 create mode 100644 
lldb/test/API/functionalities/scripted_platform/TestScriptedPlatform.py

diff --git a/lldb/bindings/interface/SBPlatformDocstrings.i 
b/lldb/bindings/interface/SBPlatformDocstrings.i
index ef09d5bce13fd..b8cdf21e90f82 100644
--- a/lldb/bindings/interface/SBPlatformDocstrings.i
+++ b/lldb/bindings/interface/SBPlatformDocstrings.i
@@ -29,3 +29,15 @@ and executable type. If the architecture or executable type 
do not match,
 a suitable platform will be found automatically."
 
 ) lldb::SBPlatform;
+
+%feature("docstring", "
+Create a platform instance using a specific platform plugin name, debugger,
+script name and user-provided dictionary.
+
+:param platform_name: name of the platform plugin to use to create the platform
+:param debugger: debugger instance owning the platform
+:param script_name: name of the script class and module to use to create the 
platform
+:param dict: user-provided dictionary that can be used when instanciating a 
platform
+") lldb::SBPlatform (const char *, con

[Lldb-commits] [lldb] [lldb] Change GetStartSymbol to GetStartAddress in DynamicLoader (PR #99909)

2024-07-23 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

Thanks.

https://github.com/llvm/llvm-project/pull/99909
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -180,7 +184,19 @@ class CommandObjectPlatformSelect : public 
CommandObjectParsed {
 m_interpreter, ArchSpec(), select, error, platform_arch));
 if (platform_sp) {
   GetDebugger().GetPlatformList().SetSelectedPlatform(platform_sp);
-
+  OptionGroupPythonClassWithDict &script_class_opts =

labath wrote:

What happens if one tries to set metadata on a platform that doesn't 
support/care about it?

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -61,7 +61,11 @@ class ScriptedThread : public lldb_private::Thread {
   StructuredData::ObjectSP FetchThreadExtendedInfo() override;
 
 private:
-  void CheckInterpreterAndScriptObject() const;
+  inline void CheckInterpreterAndScriptObject() const {

labath wrote:

`inline` is the default in this context.

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,108 @@
+"""
+Test python scripted platform in lldb
+"""
+
+import os, shutil
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class ScriptedPlatformTestCase(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipUnlessDarwin

labath wrote:

What's the reason this doesn't work elsewhere?

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -86,7 +86,11 @@ lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream 
&stream) {
   StructuredData::ParseJSON(stream.GetData());
   m_impl_up->SetObjectSP(json_obj);
 
-  if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)
+  static constexpr StructuredDataType structured_data_record_type[] = {

labath wrote:

Can we put this into a separate patch (with a test case) ?

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -1003,6 +1010,21 @@ class Platform : public PluginInterface {
   FileSpec GetModuleCacheRoot();
 };
 
+class PlatformMetadata {
+public:
+  PlatformMetadata(Debugger &debugger, const ScriptedMetadata metadata);
+  ~PlatformMetadata() = default;
+
+  Debugger &GetDebugger() const { return m_debugger; }
+  const ScriptedMetadata GetScriptedMetadata() const {
+return m_scripted_metadata;
+  }
+
+protected:
+  Debugger &m_debugger;

labath wrote:

I'm somewhat worried about how this makes a platform debugger-specific through 
a back door. I take it this is needed to access the script interpreter (?) What 
happens if this platform is later added to a different debugger object?

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,288 @@
+//===-- ScriptedPlatform.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 "ScriptedPlatform.h"
+
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Utility/LLDBLog.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(ScriptedPlatform)
+
+static uint32_t g_initialize_count = 0;
+
+static constexpr lldb::ScriptLanguage g_supported_script_languages[] = {
+ScriptLanguage::eScriptLanguagePython,
+};
+
+bool ScriptedPlatform::IsScriptLanguageSupported(
+lldb::ScriptLanguage language) {
+  llvm::ArrayRef supported_languages(
+  g_supported_script_languages);
+
+  return llvm::is_contained(supported_languages, language);
+}
+
+ScriptedPlatformInterface &ScriptedPlatform::GetInterface() const {
+  return *m_interface_up;
+}
+
+lldb::PlatformSP ScriptedPlatform::CreateInstance(bool force,
+  const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  if (log) {
+const char *arch_name;
+if (arch && arch->GetArchitectureName())
+  arch_name = arch->GetArchitectureName();
+else
+  arch_name = "";
+
+const char *triple_cstr =
+arch ? arch->GetTriple().getTriple().c_str() : "";
+
+LLDB_LOGF(log, "ScriptedPlatform::%s(force=%s, arch={%s,%s})",
+  __PRETTY_FUNCTION__, force ? "true" : "false", arch_name,
+  triple_cstr);
+  }
+
+  return std::make_shared();
+}
+
+ScriptedPlatform::ScriptedPlatform() : Platform(false) {}
+
+bool ScriptedPlatform::SetupScriptedObject(Status &error) {
+
+  auto error_with_message = [&error](llvm::StringRef message) {
+return ScriptedInterface::ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, message, error, LLDBLog::Platform);
+  };
+
+  Debugger &debugger = m_metadata->GetDebugger();
+
+  if (!IsScriptLanguageSupported(debugger.GetScriptLanguage()))
+return error_with_message("Debugger language not supported");
+
+  ScriptInterpreter *interpreter = debugger.GetScriptInterpreter();
+  if (!interpreter)
+return error_with_message("Debugger has no Script Interpreter");
+
+  // Create platform instance interface
+  m_interface_up = interpreter->CreateScriptedPlatformInterface();
+  if (!m_interface_up)
+return error_with_message(
+"Script interpreter couldn't create Scripted Process Interface");
+
+  const ScriptedMetadata scripted_metadata = m_metadata->GetScriptedMetadata();
+
+  ExecutionContext e;
+  auto obj_or_err = GetInterface().CreatePluginObject(
+  scripted_metadata.GetClassName(), e, scripted_metadata.GetArgsSP());
+
+  if (!obj_or_err) {
+llvm::consumeError(obj_or_err.takeError());
+return error_with_message("Failed to create script object.");
+  }
+
+  StructuredData::GenericSP object_sp = *obj_or_err;
+  if (!object_sp || !object_sp->IsValid())
+return error_with_message("Failed to create valid script object");
+
+  m_hostname = GetHostPlatform()->GetHostname();
+  return true;
+}
+
+ScriptedPlatform::~ScriptedPlatform() {}
+
+bool ScriptedPlatform::ReloadMetadata() {
+  if (!m_metadata)
+return false;
+
+  Status error;
+  return SetupScriptedObject(error);
+}
+
+void ScriptedPlatform::Initialize() {
+  if (g_initialize_count++ == 0) {

labath wrote:

In most cases that is completely unnecessary cargo-culted code. `Initialize` is 
called just once, from `SBDebugger::Initialize()`. The only case where this 
might be useful is when a platform class is (also) used as a base class of some 
other platform (and the other platform delegates the Initialize call to the 
base). However:
- that's not the case here
- even for those cases, I think that pattern could be replaced by something 
cleaner

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,108 @@
+"""
+Test python scripted platform in lldb
+"""
+
+import os, shutil
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class ScriptedPlatformTestCase(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+@skipUnlessDarwin
+def test_python_plugin_package(self):
+"""Test that the lldb python module has a `plugins.scripted_platform`
+package."""
+self.expect(
+"script import lldb.plugins",
+substrs=["ModuleNotFoundError"],
+matching=False,
+)
+
+self.expect("script dir(lldb.plugins)", substrs=["scripted_platform"])
+
+self.expect(
+"script import lldb.plugins.scripted_platform",
+substrs=["ModuleNotFoundError"],
+matching=False,
+)
+
+self.expect(
+"script dir(lldb.plugins.scripted_platform)", 
substrs=["ScriptedPlatform"]
+)
+
+self.expect(
+"script from lldb.plugins.scripted_platform import 
ScriptedPlatform",
+substrs=["ImportError"],
+matching=False,
+)
+
+self.expect(
+"script dir(ScriptedPlatform)",
+substrs=[
+"attach_to_process",
+"kill_process",
+"launch_process",
+"list_processes",
+],
+)
+
+@skipUnlessDarwin
+def test_list_processes(self):
+"""Test that we can load and select an lldb scripted platform using the
+SBAPI, check its process ID, parent, name & triple.
+"""
+os.environ["SKIP_SCRIPTED_PLATFORM_SELECT"] = "1"
+
+def cleanup():
+del os.environ["SKIP_SCRIPTED_PLATFORM_SELECT"]
+
+self.addTearDownHook(cleanup)

labath wrote:

Is it important that the HandleCommand thingy happens in __lldb_init_module. 
Could we remove this environment business and move the call to the relevant 
test instead?

https://github.com/llvm/llvm-project/pull/99814
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,305 @@
+//===-- ScriptedPlatform.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 "ScriptedPlatform.h"
+
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Utility/LLDBLog.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(ScriptedPlatform)
+
+static uint32_t g_initialize_count = 0;
+
+static constexpr lldb::ScriptLanguage g_supported_script_languages[] = {
+ScriptLanguage::eScriptLanguagePython,
+};
+
+bool ScriptedPlatform::IsScriptLanguageSupported(
+lldb::ScriptLanguage language) {
+  return llvm::is_contained(g_supported_script_languages, language);
+}
+
+ScriptedPlatformInterface &ScriptedPlatform::GetInterface() const {
+  return *m_interface_up;
+}
+
+lldb::PlatformSP ScriptedPlatform::CreateInstance(bool force,
+  const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  if (log) {
+const char *arch_name;
+if (arch && arch->GetArchitectureName())
+  arch_name = arch->GetArchitectureName();
+else
+  arch_name = "";
+
+const char *triple_cstr =
+arch ? arch->GetTriple().getTriple().c_str() : "";
+
+LLDB_LOGF(log, "ScriptedPlatform::%s(force=%s, arch={%s,%s})",
+  __PRETTY_FUNCTION__, force ? "true" : "false", arch_name,
+  triple_cstr);
+  }
+
+  return std::make_shared();
+}
+
+ScriptedPlatform::ScriptedPlatform() : Platform(false) {}
+
+llvm::Error ScriptedPlatform::SetupScriptedObject() {
+
+  auto error_with_message = [](llvm::StringRef message) -> llvm::Error {
+Status error;
+ScriptedInterface::ErrorWithMessage(LLVM_PRETTY_FUNCTION, message,
+  error, LLDBLog::Platform);
+return error.ToError();
+  };
+
+  Debugger &debugger = m_metadata->GetDebugger();
+
+  if (!IsScriptLanguageSupported(debugger.GetScriptLanguage()))
+return error_with_message("Debugger language not supported");
+
+  ScriptInterpreter *interpreter = debugger.GetScriptInterpreter();
+  if (!interpreter)
+return error_with_message("Debugger has no Script Interpreter");
+
+  // Create platform instance interface
+  m_interface_up = interpreter->CreateScriptedPlatformInterface();
+  if (!m_interface_up)
+return error_with_message(
+"Script interpreter couldn't create Scripted Process Interface");
+
+  const ScriptedMetadata scripted_metadata = m_metadata->GetScriptedMetadata();
+
+  ExecutionContext e(&debugger.GetSelectedOrDummyTarget());
+  auto obj_or_err = GetInterface().CreatePluginObject(
+  scripted_metadata.GetClassName(), e, scripted_metadata.GetArgsSP());
+
+  if (!obj_or_err) {
+llvm::consumeError(obj_or_err.takeError());
+return error_with_message("Failed to create script object.");
+  }
+
+  StructuredData::GenericSP object_sp = *obj_or_err;
+  if (!object_sp || !object_sp->IsValid())
+return error_with_message("Failed to create valid script object");
+
+  m_hostname = GetHostPlatform()->GetHostname();
+  return llvm::Error::success();
+}
+
+ScriptedPlatform::~ScriptedPlatform() {}
+
+llvm::Error ScriptedPlatform::ReloadMetadata() {
+  if (!m_metadata)
+return llvm::createStringError(
+"Scripted Platform has no platform metadata.");
+  return SetupScriptedObject();
+}
+
+void ScriptedPlatform::Initialize() {
+  if (g_initialize_count++ == 0) {
+// NOTE: This should probably be using the driving process platform
+PluginManager::RegisterPlugin(ScriptedPlatform::GetPluginNameStatic(),
+  ScriptedPlatform::GetDescriptionStatic(),
+  ScriptedPlatform::CreateInstance);
+  }
+}
+
+void ScriptedPlatform::Terminate() {
+  if (g_initialize_count > 0) {
+if (--g_initialize_count == 0) {
+  PluginManager::UnregisterPlugin(ScriptedPlatform::CreateInstance);
+}
+  }
+}
+
+std::vector
+ScriptedPlatform::GetSupportedArchitectures(const ArchSpec &process_host_arch) 
{

labath wrote:

This doesn't seem right. Normally a platform should "know" which architectures 
it supports without having access to any specific process. In this case, that 
would probably mean calling out to python so that the plugin author can specify 
those. `process_host_arch` was only added to disambiguate some cases (and I 
don't remember what those cases were, but I think it had something to do with 
macos simulator platforms). This may be fine for now, but we probably shouldn't 

[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

I've only really reviewed the test code, but that looks (mostly) good to me.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,176 @@
+import logging
+import os
+import os.path
+import random
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.gdbclientutils import *
+import lldbgdbserverutils
+from lldbsuite.support import seven
+
+
+class GDBProxyTestBase(TestBase):
+"""
+Base class for gdbserver proxy tests.
+
+This class will setup and start a mock GDB server for the test to use.
+It pases through requests to a regular lldb-server/debugserver and
+forwards replies back to the LLDB under test.
+"""
+
+"""The gdbserver that we implement."""
+server = None
+"""The inner lldb-server/debugserver process that we proxy requests 
into."""
+monitor_server = None
+monitor_sock = None
+
+server_socket_class = TCPServerSocket
+
+DEFAULT_TIMEOUT = 20 * (10 if ("ASAN_OPTIONS" in os.environ) else 1)
+
+_verbose_log_handler = None
+_log_formatter = logging.Formatter(fmt="%(asctime)-15s %(levelname)-8s 
%(message)s")
+
+def setUpBaseLogging(self):
+self.logger = logging.getLogger(__name__)
+
+if len(self.logger.handlers) > 0:
+return  # We have set up this handler already
+
+self.logger.propagate = False
+self.logger.setLevel(logging.DEBUG)
+
+# log all warnings to stderr
+handler = logging.StreamHandler()
+handler.setLevel(logging.WARNING)
+handler.setFormatter(self._log_formatter)
+self.logger.addHandler(handler)
+
+def setUp(self):
+TestBase.setUp(self)
+
+self.setUpBaseLogging()
+
+if self.isVerboseLoggingRequested():
+# If requested, full logs go to a log file
+log_file_name = self.getLogBasenameForCurrentTest() + "-proxy.log"
+self._verbose_log_handler = logging.FileHandler(
+   log_file_name
+)
+self._verbose_log_handler.setFormatter(self._log_formatter)
+self._verbose_log_handler.setLevel(logging.DEBUG)
+self.logger.addHandler(self._verbose_log_handler)
+
+self.port = self.get_next_port()

labath wrote:

This isn't actually used, right?

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Pavel Labath via lldb-commits

https://github.com/labath edited https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,119 @@
+import lldb
+import time
+import unittest
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test.gdbclientutils import *
+from lldbsuite.test.lldbreverse import ReverseTestBase
+from lldbsuite.test import lldbutil
+
+
+class TestReverseContinueBreakpoints(ReverseTestBase):
+@add_test_categories(["dwarf"])

labath wrote:

You probably want to set `NO_DEBUG_INFO_TESTCASE = True` class property instead.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-23 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/97273
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-23 Thread Jonas Devlieghere via lldb-commits


@@ -127,6 +130,157 @@ class CommandObjectScriptingRun : public CommandObjectRaw 
{
   CommandOptions m_options;
 };
 
+#pragma mark CommandObjectScriptingTemplateList
+
+#define LLDB_OPTIONS_scripting_template_list
+#include "CommandOptions.inc"
+
+class CommandObjectScriptingTemplateList : public CommandObjectParsed {
+public:
+  CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
+  : CommandObjectParsed(
+interpreter, "scripting template list",
+"List all the available scripting affordances templates. ",
+"scripting template list [--language  --]") {}
+
+  ~CommandObjectScriptingTemplateList() override = default;
+
+  Options *GetOptions() override { return &m_options; }
+
+  class CommandOptions : public Options {
+  public:
+CommandOptions() = default;
+~CommandOptions() override = default;
+Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+  ExecutionContext *execution_context) override {
+  Status error;
+  const int short_option = m_getopt_table[option_idx].val;
+
+  switch (short_option) {
+  case 'l':
+m_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
+option_arg, GetDefinitions()[option_idx].enum_values,
+eScriptLanguageNone, error);
+if (!error.Success())
+  error.SetErrorStringWithFormat("unrecognized value for language 
'%s'",
+ option_arg.str().c_str());
+break;
+  default:
+llvm_unreachable("Unimplemented option");
+  }
+
+  return error;
+}
+
+void OptionParsingStarting(ExecutionContext *execution_context) override {
+  m_language = lldb::eScriptLanguageDefault;
+}
+
+llvm::ArrayRef GetDefinitions() override {
+  return llvm::ArrayRef(g_scripting_template_list_options);
+}
+
+lldb::ScriptLanguage m_language = lldb::eScriptLanguageDefault;
+  };
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+Stream &s = result.GetOutputStream();
+s.Printf("Available scripted extension templates:");
+
+auto print_field = [&s](llvm::StringRef key, llvm::StringRef value,
+bool check_validity = false) {
+  if (!check_validity || !value.empty()) {

JDevlieghere wrote:

You marked this as resolved because you check its value, but that variable is 
still never set? 

https://github.com/llvm/llvm-project/pull/97273
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-23 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.

LGTM modulo comment.

https://github.com/llvm/llvm-project/pull/97273
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [lldb] [clang] Split ObjectFilePCHContainerReader from ObjectFilePCHContainerWriter (PR #99599)

2024-07-23 Thread Chuanqi Xu via lldb-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/99599

>From 2249d5021fb3f9de213772603893e6fa2a0ff7f8 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 19 Jul 2024 11:02:36 +0800
Subject: [PATCH] [clang] Split ObjectFilePCHContainerReader from
 ObjectFilePCHContainerWriter

Close https://github.com/llvm/llvm-project/issues/99479

See https://github.com/llvm/llvm-project/issues/99479 for details
---
 ...tions.h => ObjectFilePCHContainerWriter.h} | 10 +---
 .../ObjectFilePCHContainerReader.h| 25 +
 clang/lib/CodeGen/CMakeLists.txt  |  2 +-
 ...s.cpp => ObjectFilePCHContainerWriter.cpp} | 47 +---
 clang/lib/Interpreter/Interpreter.cpp |  3 +-
 clang/lib/Interpreter/InterpreterUtils.h  |  1 -
 clang/lib/Serialization/CMakeLists.txt|  2 +
 .../ObjectFilePCHContainerReader.cpp  | 56 +++
 .../Tooling/DependencyScanning/CMakeLists.txt |  1 -
 .../DependencyScanningWorker.cpp  |  2 +-
 clang/tools/c-index-test/CMakeLists.txt   |  1 -
 clang/tools/c-index-test/core_main.cpp|  2 +-
 clang/tools/clang-check/ClangCheck.cpp|  1 -
 clang/tools/driver/cc1_main.cpp   |  3 +-
 lldb/source/Commands/CommandObjectTarget.cpp  |  2 +-
 lldb/tools/lldb-instr/Instrument.cpp  |  3 +-
 16 files changed, 96 insertions(+), 65 deletions(-)
 rename clang/include/clang/CodeGen/{ObjectFilePCHContainerOperations.h => 
ObjectFilePCHContainerWriter.h} (74%)
 create mode 100644 
clang/include/clang/Serialization/ObjectFilePCHContainerReader.h
 rename clang/lib/CodeGen/{ObjectFilePCHContainerOperations.cpp => 
ObjectFilePCHContainerWriter.cpp} (89%)
 create mode 100644 clang/lib/Serialization/ObjectFilePCHContainerReader.cpp

diff --git a/clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h 
b/clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
similarity index 74%
rename from clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h
rename to clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
index 7a02d8725885a..26ee9f22258c1 100644
--- a/clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h
+++ b/clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
@@ -1,4 +1,4 @@
-//===-- CodeGen/ObjectFilePCHContainerOperations.h - *- C++ 
-*-===//
+//===-- CodeGen/ObjectFilePCHContainerWriter.h --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -29,14 +29,6 @@ class ObjectFilePCHContainerWriter : public 
PCHContainerWriter {
   std::shared_ptr Buffer) const 
override;
 };
 
-/// A PCHContainerReader implementation that uses LLVM to
-/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
-class ObjectFilePCHContainerReader : public PCHContainerReader {
-  ArrayRef getFormats() const override;
-
-  /// Returns the serialized AST inside the PCH container Buffer.
-  StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
-};
 }
 
 #endif
diff --git a/clang/include/clang/Serialization/ObjectFilePCHContainerReader.h 
b/clang/include/clang/Serialization/ObjectFilePCHContainerReader.h
new file mode 100644
index 0..6281a3f428869
--- /dev/null
+++ b/clang/include/clang/Serialization/ObjectFilePCHContainerReader.h
@@ -0,0 +1,25 @@
+//===-- Serialization/ObjectFilePCHContainerReader.h *- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_SERIALIZATION_OBJECTFILEPCHCONTAINERREADER_H
+#define LLVM_CLANG_SERIALIZATION_OBJECTFILEPCHCONTAINERREADER_H
+
+#include "clang/Frontend/PCHContainerOperations.h"
+
+namespace clang {
+/// A PCHContainerReader implementation that uses LLVM to
+/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
+class ObjectFilePCHContainerReader : public PCHContainerReader {
+  ArrayRef getFormats() const override;
+
+  /// Returns the serialized AST inside the PCH container Buffer.
+  StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
+};
+} // namespace clang
+
+#endif
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index 2a179deddcc31..deb7b27266d73 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -110,7 +110,7 @@ add_clang_library(clangCodeGen
   MacroPPCallbacks.cpp
   MicrosoftCXXABI.cpp
   ModuleBuilder.cpp
-  ObjectFilePCHContainerOperations.cpp
+  ObjectFilePCHContainerWriter.cpp
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp 
b/clang/lib/Cod

[Lldb-commits] [lldb] d64eccf - [clang] Split ObjectFilePCHContainerReader from ObjectFilePCHContainerWriter (#99599)

2024-07-23 Thread via lldb-commits

Author: Chuanqi Xu
Date: 2024-07-23T23:55:31+08:00
New Revision: d64eccf4335e99360132b724d060d704892fbb02

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

LOG: [clang] Split ObjectFilePCHContainerReader from 
ObjectFilePCHContainerWriter (#99599)

Close https://github.com/llvm/llvm-project/issues/99479

See https://github.com/llvm/llvm-project/issues/99479 for details

Added: 
clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
clang/include/clang/Serialization/ObjectFilePCHContainerReader.h
clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
clang/lib/Serialization/ObjectFilePCHContainerReader.cpp

Modified: 
clang/lib/CodeGen/CMakeLists.txt
clang/lib/Interpreter/Interpreter.cpp
clang/lib/Interpreter/InterpreterUtils.h
clang/lib/Serialization/CMakeLists.txt
clang/lib/Tooling/DependencyScanning/CMakeLists.txt
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
clang/tools/c-index-test/CMakeLists.txt
clang/tools/c-index-test/core_main.cpp
clang/tools/clang-check/ClangCheck.cpp
clang/tools/driver/cc1_main.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/tools/lldb-instr/Instrument.cpp

Removed: 
clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h
clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp



diff  --git a/clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h 
b/clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
similarity index 74%
rename from clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h
rename to clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
index 7a02d8725885a..26ee9f22258c1 100644
--- a/clang/include/clang/CodeGen/ObjectFilePCHContainerOperations.h
+++ b/clang/include/clang/CodeGen/ObjectFilePCHContainerWriter.h
@@ -1,4 +1,4 @@
-//===-- CodeGen/ObjectFilePCHContainerOperations.h - *- C++ 
-*-===//
+//===-- CodeGen/ObjectFilePCHContainerWriter.h --*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -29,14 +29,6 @@ class ObjectFilePCHContainerWriter : public 
PCHContainerWriter {
   std::shared_ptr Buffer) const 
override;
 };
 
-/// A PCHContainerReader implementation that uses LLVM to
-/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
-class ObjectFilePCHContainerReader : public PCHContainerReader {
-  ArrayRef getFormats() const override;
-
-  /// Returns the serialized AST inside the PCH container Buffer.
-  StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
-};
 }
 
 #endif

diff  --git a/clang/include/clang/Serialization/ObjectFilePCHContainerReader.h 
b/clang/include/clang/Serialization/ObjectFilePCHContainerReader.h
new file mode 100644
index 0..6281a3f428869
--- /dev/null
+++ b/clang/include/clang/Serialization/ObjectFilePCHContainerReader.h
@@ -0,0 +1,25 @@
+//===-- Serialization/ObjectFilePCHContainerReader.h *- C++ 
-*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_SERIALIZATION_OBJECTFILEPCHCONTAINERREADER_H
+#define LLVM_CLANG_SERIALIZATION_OBJECTFILEPCHCONTAINERREADER_H
+
+#include "clang/Frontend/PCHContainerOperations.h"
+
+namespace clang {
+/// A PCHContainerReader implementation that uses LLVM to
+/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
+class ObjectFilePCHContainerReader : public PCHContainerReader {
+  ArrayRef getFormats() const override;
+
+  /// Returns the serialized AST inside the PCH container Buffer.
+  StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
+};
+} // namespace clang
+
+#endif

diff  --git a/clang/lib/CodeGen/CMakeLists.txt 
b/clang/lib/CodeGen/CMakeLists.txt
index 2a179deddcc31..deb7b27266d73 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -110,7 +110,7 @@ add_clang_library(clangCodeGen
   MacroPPCallbacks.cpp
   MicrosoftCXXABI.cpp
   ModuleBuilder.cpp
-  ObjectFilePCHContainerOperations.cpp
+  ObjectFilePCHContainerWriter.cpp
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp

diff  --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp 
b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
similarity index 89%
rename from clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
rename to clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index ee543e40b4609..3a1f745d9ed77 100644
--- a/

[Lldb-commits] [clang] [lldb] [clang] Split ObjectFilePCHContainerReader from ObjectFilePCHContainerWriter (PR #99599)

2024-07-23 Thread Chuanqi Xu via lldb-commits

https://github.com/ChuanqiXu9 closed 
https://github.com/llvm/llvm-project/pull/99599
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Updated README.md for newly added attach properties. (PR #99926)

2024-07-23 Thread via lldb-commits

tedwoodward wrote:

Please update the version number in package.json, so we can publish the new 
extension to the marketplace

https://github.com/llvm/llvm-project/pull/99926
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 87f2c25 - [lldb] Unify WaitForSetEvents and WaitForEventsToReset (#99997)

2024-07-23 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2024-07-23T09:06:32-07:00
New Revision: 87f2c25f3dad65890fc8e9abbe9765e44979ed9d

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

LOG: [lldb] Unify WaitForSetEvents and WaitForEventsToReset (#7)

Unify the implementations of WaitForSetEvents and WaitForEventsToReset.
The former deals with the possibility of a race between the timeout and
the predicate while the latter does not. The functions were also
inconsistent in when they would recompute the mask. This patch unifies
the two implementations and make them behave exactly the same modulo the
predicate.

rdar://130562344

Added: 


Modified: 
lldb/tools/debugserver/source/PThreadEvent.cpp
lldb/tools/debugserver/source/PThreadEvent.h

Removed: 




diff  --git a/lldb/tools/debugserver/source/PThreadEvent.cpp 
b/lldb/tools/debugserver/source/PThreadEvent.cpp
index e77c7511ae5ba..f9166a1b63d06 100644
--- a/lldb/tools/debugserver/source/PThreadEvent.cpp
+++ b/lldb/tools/debugserver/source/PThreadEvent.cpp
@@ -108,79 +108,55 @@ void PThreadEvent::ResetEvents(const uint32_t mask) {
 // Wait until 'timeout_abstime' for any events that are set in
 // 'mask'. If 'timeout_abstime' is NULL, then wait forever.
 uint32_t
-PThreadEvent::WaitForSetEvents(const uint32_t mask,
-   const struct timespec *timeout_abstime) const {
+PThreadEvent::WaitForEventsImpl(const uint32_t mask,
+const struct timespec *timeout_abstime,
+std::function predicate) const {
   // DNBLogThreadedIf(LOG_EVENTS, "%p PThreadEvent::%s (0x%8.8x, %p)", this,
   // __FUNCTION__, mask, timeout_abstime);
+
   int err = 0;
+
   // pthread_cond_timedwait() or pthread_cond_wait() will atomically
   // unlock the mutex and wait for the condition to be set. When either
   // function returns, they will re-lock the mutex. We use an auto lock/unlock
   // class (PThreadMutex::Locker) to allow us to return at any point in this
   // function and not have to worry about unlocking the mutex.
   PTHREAD_MUTEX_LOCKER(locker, m_mutex);
-  do {
-// Check our predicate (event bits) in case any are already set
-if (mask & m_bits) {
-  uint32_t bits_set = mask & m_bits;
-  // Our PThreadMutex::Locker will automatically unlock our mutex
-  return bits_set;
-}
+
+  // Check the predicate and the error code. The functions below do not return
+  // EINTR so that's not something we need to handle.
+  while (!predicate() && err == 0) {
 if (timeout_abstime) {
   // Wait for condition to get broadcast, or for a timeout. If we get
-  // a timeout we will drop out of the do loop and return false which
-  // is what we want.
+  // a timeout we will drop out of the loop on the next iteration and we
+  // will recompute the mask in case of a race between the condition and 
the
+  // timeout.
   err = ::pthread_cond_timedwait(m_set_condition.Condition(),
  m_mutex.Mutex(), timeout_abstime);
-  // Retest our predicate in case of a race condition right at the end
-  // of the timeout.
-  if (err == ETIMEDOUT) {
-uint32_t bits_set = mask & m_bits;
-return bits_set;
-  }
 } else {
-  // Wait for condition to get broadcast. The only error this function
-  // should return is if
+  // Wait for condition to get broadcast.
   err = ::pthread_cond_wait(m_set_condition.Condition(), m_mutex.Mutex());
 }
-  } while (err == 0);
-  return 0;
+  }
+
+  // Either the predicate passed, we hit the specified timeout (ETIMEDOUT) or 
we
+  // encountered an unrecoverable error (EINVAL, EPERM). Regardless of how we
+  // got here, recompute and return the mask indicating which bits (if any) are
+  // set.
+  return GetBitsMasked(mask);
+}
+
+uint32_t
+PThreadEvent::WaitForSetEvents(const uint32_t mask,
+   const struct timespec *timeout_abstime) const {
+  auto predicate = [&]() -> uint32_t { return GetBitsMasked(mask) != 0; };
+  return WaitForEventsImpl(mask, timeout_abstime, predicate);
 }
 
-// Wait until 'timeout_abstime' for any events in 'mask' to reset.
-// If 'timeout_abstime' is NULL, then wait forever.
 uint32_t PThreadEvent::WaitForEventsToReset(
 const uint32_t mask, const struct timespec *timeout_abstime) const {
-  // DNBLogThreadedIf(LOG_EVENTS, "%p PThreadEvent::%s (0x%8.8x, %p)", this,
-  // __FUNCTION__, mask, timeout_abstime);
-  int err = 0;
-  // pthread_cond_timedwait() or pthread_cond_wait() will atomically
-  // unlock the mutex and wait for the condition to be set. When either
-  // function returns, they will re-lock the mutex. We use an auto lock/unlock
-  // class (PThreadMutex::Locker) to 

[Lldb-commits] [lldb] [lldb] Unify WaitForSetEvents and WaitForEventsToReset (PR #99997)

2024-07-23 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere closed 
https://github.com/llvm/llvm-project/pull/7
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] ca102b2 - lldb: android: fix missing Python import of urlparse in lldb test utilities (#99934)

2024-07-23 Thread via lldb-commits

Author: Andrew Rogers
Date: 2024-07-23T09:23:51-07:00
New Revision: ca102b2114fa8a00096d71ff9fc3b1b218f0f01a

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

LOG: lldb: android: fix missing Python import of urlparse in lldb test 
utilities (#99934)

## Issue
Attempting to run the lldb API tests against a remote-android target
fails with the error `NameError: name 'urlparse' is not defined`.

## Root Cause
It looks the Python import of `urlparse` was removed by mistake in
22ea97d7bfd65abf68a68b13bf96ad69be23df54. This import is only used when
running the lldb API tests against a remote-android target so it went
unnoticed.

## Fix
This change simply puts back the missing import. It is a one line
change.

fixes #99931

## Validation
Tested on Fedora 39 with an attached Android device:

`cd llvm-project`
`cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS='clang;lldb'
-DCMAKE_BUILD_TYPE=Release -DLLDB_ENABLE_PYTHON=On`
`ninja -C build`
`./build/bin/lldb-dotest --arch aarch64 --out-of-tree-debugserver
--platform-name=remote-android
--platform-working-dir=/data/local/tmp/ds2
--platform-url=connect://localhost:5432 --compiler
~/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang`

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/lldbplatformutil.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index b7e6f240f59f6..e3c6fd1a99568 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -9,6 +9,7 @@
 import sys
 import os
 from packaging import version
+from urllib.parse import urlparse
 
 # LLDB modules
 import lldb



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


[Lldb-commits] [lldb] lldb: android: fix missing Python import of urlparse in lldb test utilities (PR #99934)

2024-07-23 Thread Saleem Abdulrasool via lldb-commits

https://github.com/compnerd closed 
https://github.com/llvm/llvm-project/pull/99934
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] lldb: android: fix missing Python import of urlparse in lldb test utilities (PR #99934)

2024-07-23 Thread via lldb-commits

github-actions[bot] wrote:



@andrurogerz Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


https://github.com/llvm/llvm-project/pull/99934
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] lldb: android: fix missing Python import of urlparse in lldb test utilities (PR #99934)

2024-07-23 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building `lldb` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/59/builds/2088

Here is the relevant piece of the build log for the reference:
```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: commands/platform/basic/TestPlatformCommand.py (180 of 1994)
PASS: lldb-api :: commands/memory/write/TestMemoryWrite.py (181 of 1994)
PASS: lldb-api :: commands/platform/file/read/TestPlatformFileRead.py (182 of 
1994)
PASS: lldb-api :: commands/platform/file/close/TestPlatformFileClose.py (183 of 
1994)
PASS: lldb-api :: commands/memory/read/TestMemoryRead.py (184 of 1994)
PASS: lldb-api :: commands/platform/connect/TestPlatformConnect.py (185 of 1994)
UNSUPPORTED: lldb-api :: commands/platform/sdk/TestPlatformSDK.py (186 of 1994)
PASS: lldb-api :: commands/platform/process/list/TestProcessList.py (187 of 
1994)
PASS: lldb-api :: commands/platform/process/launch/TestPlatformProcessLaunch.py 
(188 of 1994)
UNRESOLVED: lldb-api :: commands/gui/spawn-threads/TestGuiSpawnThreads.py (189 
of 1994)
 TEST 'lldb-api :: 
commands/gui/spawn-threads/TestGuiSpawnThreads.py' FAILED 
Script:
--
/usr/bin/python3.8 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env 
OBJCOPY=/usr/bin/llvm-objcopy --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb 
--lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/commands/gui/spawn-threads
 -p TestGuiSpawnThreads.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
ca102b2114fa8a00096d71ff9fc3b1b218f0f01a)
  clang revision ca102b2114fa8a00096d71ff9fc3b1b218f0f01a
  llvm revision ca102b2114fa8a00096d71ff9fc3b1b218f0f01a
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
FAIL: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_gui (TestGuiSpawnThreads.TestGuiSpawnThreadsTest)
==
ERROR: test_gui (TestGuiSpawnThreads.TestGuiSpawnThreadsTest)
--
Traceback (most recent call last):
  File 
"/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py",
 line 148, in wrapper
return func(*args, **kwargs)
  File 
"/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py",
 line 44, in test_gui
self.child.expect_exact(f"thread #{i + 2}: tid =")
  File "/usr/local/lib/python3.8/dist-packages/pexpect/spawnbase.py", line 432, 
in expect_exact
return exp.expect_loop(timeout)
  File "/usr/local/lib/python3.8/dist-packages/pexpect/expect.py", line 179, in 
expect_loop
return self.eof(e)
  File "/usr/local/lib/python3.8/dist-packages/pexpect/expect.py", line 122, in 
eof
raise exc
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.

command: /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/lldb
args: ['/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/lldb', 
'--no-lldbinit', '--no-use-colors', '-O', 'settings clear -all', '-O', 
'settings set symbols.enable-external-lookup false', '-O', 'settings set 
target.inherit-tcc true', '-O', 'settings set target.disable-aslr false', '-O', 
'settings set target.detach-on-error false', '-O', 'settings set 
target.auto-apply-fixits false', '-O', 'settings set 
plugin.process.gdb-remote.packet-timeout 60', '-O', 'settings set 
symbols.clang-modules-cache-path 
"/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noind

[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -3139,6 +3146,7 @@ void PruneThreadPlans();
// m_currently_handling_do_on_removals are true,
// Resume will only request a resume, using this
// flag to check.
+  lldb::RunDirection m_last_run_direction;

clayborg wrote:

Feel free to initialize this here so we don't have to change the constructor:
```
lldb::RunDirection m_last_run_direction = lldb::eRunForward;
```

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits

https://github.com/clayborg requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -90,7 +90,7 @@ class ProcessKDP : public lldb_private::Process {
   // Process Control
   lldb_private::Status WillResume() override;
 
-  lldb_private::Status DoResume() override;
+  lldb_private::Status DoResume(lldb::RunDirection direction) override;

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -111,7 +111,7 @@ class ProcessGDBRemote : public Process,
   // Process Control
   Status WillResume() override;
 
-  Status DoResume() override;
+  Status DoResume(lldb::RunDirection direction) override;

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change will add a new 
interface definition.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -874,10 +874,10 @@ class Process : public 
std::enable_shared_from_this,
   /// \see Thread:Resume()
   /// \see Thread:Step()
   /// \see Thread:Suspend()
-  Status Resume();
+  Status Resume(lldb::RunDirection direction = lldb::eRunForward);

clayborg wrote:

internal APIs, anything not in the `lldb` namespace _can_ be changed. So this 
is ok. Though I personally would like to see a:
```
Status ReverseResume();
```
I am open to feedback from other here as my mind can easily be changed.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -182,10 +182,17 @@ void ScriptedProcess::DidResume() {
   m_pid = GetInterface().GetProcessID();
 }
 
-Status ScriptedProcess::DoResume() {
+Status ScriptedProcess::DoResume(RunDirection direction) {

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -203,11 +203,17 @@ ProcessWindows::DoAttachToProcessWithID(lldb::pid_t pid,
   return error;
 }
 
-Status ProcessWindows::DoResume() {
+Status ProcessWindows::DoResume(RunDirection direction) {
   Log *log = GetLog(WindowsLog::Process);
   llvm::sys::ScopedLock lock(m_mutex);
   Status error;
 
+  if (direction == RunDirection::eRunReverse) {

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -52,7 +52,7 @@ class ScriptedProcess : public Process {
 
   void DidResume() override;
 
-  Status DoResume() override;
+  Status DoResume(lldb::RunDirection direction) override;

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -402,9 +402,16 @@ lldb_private::DynamicLoader 
*ProcessKDP::GetDynamicLoader() {
 
 Status ProcessKDP::WillResume() { return Status(); }
 
-Status ProcessKDP::DoResume() {
+Status ProcessKDP::DoResume(RunDirection direction) {

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -135,6 +135,9 @@ FLAGS_ENUM(LaunchFlags){
 /// Thread Run Modes.
 enum RunMode { eOnlyThisThread, eAllThreads, eOnlyDuringStepping };
 
+/// Execution directions
+enum RunDirection { eRunForward, eRunReverse };
+

clayborg wrote:

If we don't add an overload to continue by adding 
`SBProcess::ReverseContinue()` then this should be kept internal and not in 
this header file. If you add a new `SBProcess::Continue(lldb::RunDirection)` 
overload then this is needed. I would prefer a dedicated 
`SBProcess::ReverseContinue()` function. 

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -203,11 +203,17 @@ ProcessWindows::DoAttachToProcessWithID(lldb::pid_t pid,
   return error;
 }
 
-Status ProcessWindows::DoResume() {
+Status ProcessWindows::DoResume(RunDirection direction) {

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -52,7 +52,7 @@ class ProcessWindows : public Process, public ProcessDebugger 
{
   Status DoAttachToProcessWithID(
   lldb::pid_t pid,
   const lldb_private::ProcessAttachInfo &attach_info) override;
-  Status DoResume() override;
+  Status DoResume(lldb::RunDirection direction) override;

clayborg wrote:

We should use `DoResumeReverse()` in Process.h and this change won't need to 
happen.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -1129,10 +1129,15 @@ class Process : public 
std::enable_shared_from_this,
   /// \see Thread:Resume()
   /// \see Thread:Step()
   /// \see Thread:Suspend()
-  virtual Status DoResume() {
+  virtual Status DoResume(lldb::RunDirection direction) {

clayborg wrote:

I would rather have a new `DoResumeReverse()` instead of changing this virtual 
API. Many modified files in this patch are a result of the process plugins 
having to add support for not supporting reverse resumes.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits


@@ -158,7 +158,7 @@ class LLDB_API SBProcess {
 
   lldb::SBError Destroy();
 
-  lldb::SBError Continue();
+  lldb::SBError Continue(RunDirection direction = RunDirection::eRunForward);

clayborg wrote:

Our public API has rules:
- can't change any existing API call, you can add an overload, but you can't 
change any public APIs that are already there. Anything in the `lldb` namespace 
can't be changed. 
- no virtual functions
- can't change any ivars or the size of the object

That being said, I would rather have a:
```
lldb::SBError ReverseContinue();
```
call than have everyone using the `Continue` API to say wether they want to go 
forward or in reverse. 

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread via lldb-commits


@@ -1363,6 +1374,43 @@ Status ProcessGDBRemote::DoResume() {
   }
 }
 
+if (direction == RunDirection::eRunReverse && continue_packet_error) {
+  if (num_continue_C_tids > 0 || num_continue_S_tids > 0) {
+error.SetErrorString("can't deliver signals while running in reverse");
+LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: Signals not 
supported");
+return error;
+  }
+
+  if (num_continue_s_tids > 0) {
+if (num_continue_s_tids > 1) {
+  error.SetErrorString("can't step multiple threads while 
reverse-stepping");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: can't step 
multiple threads");
+  return error;
+}
+
+if (!m_gdb_comm.GetReverseStepSupported()) {
+  error.SetErrorString("target does not support reverse-stepping");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: target does not 
support reverse-stepping");
+  return error;
+}
+
+m_gdb_comm.SetCurrentThreadForRun(m_continue_s_tids.front());
+continue_packet.PutCString("bs");
+  } else {
+if (!m_gdb_comm.GetReverseContinueSupported()) {

jimingham wrote:

Why do you wait till this late do check that someone asked for a reverse 
continue but that's not supported?  I would expect that to be the first thing 
you checked since you aren't going to do any useful work if that's not true.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread via lldb-commits

jimingham wrote:



> On Jul 23, 2024, at 9:47 AM, Greg Clayton ***@***.***> wrote:
> 
> 
> @clayborg requested changes on this pull request.
> 
> In lldb/include/lldb/API/SBProcess.h 
> :
> 
> > -  lldb::SBError Continue();
> +  lldb::SBError Continue(RunDirection direction = RunDirection::eRunForward);
> Our public API has rules:
> 
> can't change any existing API call, you can add an overload, but you can't 
> change any public APIs that are already there. Anything in the lldb namespace 
> can't be changed.
> no virtual functions
> can't change any ivars or the size of the object
> That being said, I would rather have a:
> 
> lldb::SBError ReverseContinue();
> call than have everyone using the Continue API to say wether they want to go 
> forward or in reverse.
> 
> In lldb/include/lldb/Target/Process.h 
> :
> 
> > -  Status Resume();
> +  Status Resume(lldb::RunDirection direction = lldb::eRunForward);
> internal APIs, anything not in the lldb namespace can be changed. So this is 
> ok. Though I personally would like to see a:
> 
> Status ReverseResume();
> I am open to feedback from other here as my mind can easily be changed.
> 
You just have to omit the default argument, and leave the 0 argument form in 
place.  That will have the effect you want, all previous code will use the 
forward continue, and new code that wants to be explicit can pass the argument.

I asked for this change, because it seems like where you are going to use it 
you will have some variable telling yourself which direction you are going, and 
so if there's an argument, you will find yourself writing:

my_process.Continue(the_direction_parameter_i_already_had)

as opposed to

if the_direction_parameter_i_already_had == lldb::eRunForward:
my_process.Continue()
else:
my_process.ReverseContinue()

The former seemed much nicer to me.


> 
> In lldb/include/lldb/Target/Process.h 
> :
> 
> > @@ -3139,6 +3146,7 @@ void PruneThreadPlans();
> // m_currently_handling_do_on_removals are true,
> // Resume will only request a resume, using this
> // flag to check.
> +  lldb::RunDirection m_last_run_direction;
> Feel free to initialize this here so we don't have to change the constructor:
> 
> lldb::RunDirection m_last_run_direction = lldb::eRunForward;
> In lldb/include/lldb/lldb-enumerations.h 
> :
> 
> > +/// Execution directions
> +enum RunDirection { eRunForward, eRunReverse };
> +
> If we don't add an overload to continue by adding 
> SBProcess::ReverseContinue() then this should be kept internal and not in 
> this header file. If you add a new SBProcess::Continue(lldb::RunDirection) 
> overload then this is needed. I would prefer a dedicated 
> SBProcess::ReverseContinue() function.
> 

Can you explain why?  It seems like that usage is going to be more verbose to 
no purpose, as I showed above.

> 
> In lldb/include/lldb/Target/Process.h 
> :
> 
> > @@ -1129,10 +1129,15 @@ class Process : public 
> > std::enable_shared_from_this,
>/// \see Thread:Resume()
>/// \see Thread:Step()
>/// \see Thread:Suspend()
> -  virtual Status DoResume() {
> +  virtual Status DoResume(lldb::RunDirection direction) {
> I would rather have a new DoResumeReverse() instead of changing this virtual 
> API. Many modified files in this patch are a result of the process plugins 
> having to add support for not supporting reverse resumes.
> 
I also asked for this change in the review.  Ever other API that does resume 
takes this parameter, its odd and asymmetric not to do so.  

> 
> In lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h 
> :
> 
> > @@ -90,7 +90,7 @@ class ProcessKDP : public lldb_private::Process {
>// Process Control
>lldb_private::Status WillResume() override;
>  
> -  lldb_private::Status DoResume() override;
> +  lldb_private::Status DoResume(lldb::RunDirection direction) override;
> We should use DoResumeReverse() in Process.h and this change won't need to 
> happen.
> 
> In lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
> :
> 
> > @@ -203,11 +203,17 @@ ProcessWindows::DoAttachToProcessWithID(lldb::pid_t 
> > pid,
>return error;
>  }
>  
> -Status ProcessWindows::DoResume() {
> +Status ProcessWindows::DoResume(RunDirection direction) {
> We should use DoResumeReverse() in Process.h and this change won't need to 
> happen.
> 
> In lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp 
> 

[Lldb-commits] [lldb] [lldb/Commands] Add `scripting template list` command with auto discovery (PR #97273)

2024-07-23 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/97273

>From 52bdaaca9b1688eea7f5d20ceba50796f8816b77 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 23 Jul 2024 10:14:41 -0700
Subject: [PATCH] [lldb/Commands] Add `scripting template list` command with
 auto discovery

This patch introduces a new `template` multiword sub-command to the
`scripting` top-level command. As the name suggests, this sub-command
operates on scripting templates, and currently has the ability to
automatically discover the various scripting extensions that lldb
supports.

Signed-off-by: Med Ismail Bennani 
---
 lldb/include/lldb/Core/PluginManager.h|  20 +++
 .../Interfaces/ScriptedInterface.h|   7 +
 .../Interfaces/ScriptedInterfaceUsages.h  |  43 ++
 lldb/include/lldb/lldb-private-interfaces.h   |   3 +
 .../Commands/CommandObjectScripting.cpp   | 126 +-
 lldb/source/Commands/Options.td   |   6 +
 lldb/source/Core/PluginManager.cpp|  65 +
 lldb/source/Interpreter/CMakeLists.txt|   4 +
 .../Interpreter/Interfaces/CMakeLists.txt |  10 ++
 .../Interfaces/ScriptedInterfaceUsages.cpp|  37 +
 lldb/source/Plugins/CMakeLists.txt|   3 +
 .../Python/Interfaces/CMakeLists.txt  |   9 +-
 .../CMakeLists.txt|  15 +++
 .../OperatingSystemPythonInterface.cpp|  25 +++-
 .../OperatingSystemPythonInterface.h  |  18 ++-
 .../CMakeLists.txt|  15 +++
 .../ScriptedPlatformPythonInterface.cpp   |  24 +++-
 .../ScriptedPlatformPythonInterface.h |  17 ++-
 .../CMakeLists.txt|  15 +++
 .../ScriptedProcessPythonInterface.cpp|  39 +-
 .../ScriptedProcessPythonInterface.h  |  18 ++-
 .../CMakeLists.txt|  15 +++
 .../ScriptedThreadPlanPythonInterface.cpp |  26 +++-
 .../ScriptedThreadPlanPythonInterface.h   |  18 ++-
 .../Python/ScriptInterpreterPython.cpp|   8 +-
 25 files changed, 546 insertions(+), 40 deletions(-)
 create mode 100644 
lldb/include/lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h
 create mode 100644 lldb/source/Interpreter/Interfaces/CMakeLists.txt
 create mode 100644 
lldb/source/Interpreter/Interfaces/ScriptedInterfaceUsages.cpp
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/CMakeLists.txt
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
OperatingSystemPythonInterface}/OperatingSystemPythonInterface.cpp (76%)
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
OperatingSystemPythonInterface}/OperatingSystemPythonInterface.h (83%)
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface/CMakeLists.txt
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedPlatformPythonInterface}/ScriptedPlatformPythonInterface.cpp (84%)
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedPlatformPythonInterface}/ScriptedPlatformPythonInterface.h (84%)
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedProcessPythonInterface}/ScriptedProcessPythonInterface.cpp (86%)
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedProcessPythonInterface}/ScriptedProcessPythonInterface.h (88%)
 create mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface/CMakeLists.txt
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedThreadPlanPythonInterface}/ScriptedThreadPlanPythonInterface.cpp (79%)
 rename lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ => 
ScriptedThreadPlanPythonInterface}/ScriptedThreadPlanPythonInterface.h (82%)

diff --git a/lldb/include/lldb/Core/PluginManager.h 
b/lldb/include/lldb/Core/PluginManager.h
index 38a291d9f0afd..a23f834f471fb 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -10,6 +10,7 @@
 #define LLDB_CORE_PLUGINMANAGER_H
 
 #include "lldb/Core/Architecture.h"
+#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
 #include "lldb/Symbol/TypeSystem.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/FileSpec.h"
@@ -487,6 +488,25 @@ class PluginManager {
 
   static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
 
+  // Scripted Interface
+  static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
+ ScriptedInterfaceCreateInstance create_callback,
+ lldb::ScriptLanguage language,
+ ScriptedInterfaceUsages usages);
+
+  static bool UnregisterPlugin(Scri

[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread via lldb-commits

jimingham wrote:

More generally, I think it will be more natural if reverse and forward 
continuations to be as much as possible "the exact same execution control 
machinery with a direction" not separate "forward" and "reverse" facilities.  
So I'd rather we not start off separating them artificially.

Jim


> On Jul 23, 2024, at 10:02 AM, Jim Ingham ***@***.***> wrote:
> 
>> 
>> 
>> 
>>> On Jul 23, 2024, at 9:47 AM, Greg Clayton ***@***.***> wrote:
>>> 
>>> 
>>> @clayborg requested changes on this pull request.
>>> 
>>> In lldb/include/lldb/API/SBProcess.h 
>>> :
>>> 
>>> > -  lldb::SBError Continue();
>>> +  lldb::SBError Continue(RunDirection direction = 
>>> RunDirection::eRunForward);
>>> Our public API has rules:
>>> 
>>> can't change any existing API call, you can add an overload, but you can't 
>>> change any public APIs that are already there. Anything in the lldb 
>>> namespace can't be changed.
>>> no virtual functions
>>> can't change any ivars or the size of the object
>>> That being said, I would rather have a:
>>> 
>>> lldb::SBError ReverseContinue();
>>> call than have everyone using the Continue API to say wether they want to 
>>> go forward or in reverse.
>>> 
>>> In lldb/include/lldb/Target/Process.h 
>>> :
>>> 
>>> > -  Status Resume();
>>> +  Status Resume(lldb::RunDirection direction = lldb::eRunForward);
>>> internal APIs, anything not in the lldb namespace can be changed. So this 
>>> is ok. Though I personally would like to see a:
>>> 
>>> Status ReverseResume();
>>> I am open to feedback from other here as my mind can easily be changed.
>>> 
>> You just have to omit the default argument, and leave the 0 argument form in 
>> place.  That will have the effect you want, all previous code will use the 
>> forward continue, and new code that wants to be explicit can pass the 
>> argument.
>> 
>> I asked for this change, because it seems like where you are going to use it 
>> you will have some variable telling yourself which direction you are going, 
>> and so if there's an argument, you will find yourself writing:
>> 
>> my_process.Continue(the_direction_parameter_i_already_had)
>> 
>> as opposed to
>> 
>> if the_direction_parameter_i_already_had == lldb::eRunForward:
>> my_process.Continue()
>> else:
>> my_process.ReverseContinue()
>> 
>> The former seemed much nicer to me.
>> 
>> 
>>> 
>>> In lldb/include/lldb/Target/Process.h 
>>> :
>>> 
>>> > @@ -3139,6 +3146,7 @@ void PruneThreadPlans();
>>> // m_currently_handling_do_on_removals are true,
>>> // Resume will only request a resume, using this
>>> // flag to check.
>>> +  lldb::RunDirection m_last_run_direction;
>>> Feel free to initialize this here so we don't have to change the 
>>> constructor:
>>> 
>>> lldb::RunDirection m_last_run_direction = lldb::eRunForward;
>>> In lldb/include/lldb/lldb-enumerations.h 
>>> :
>>> 
>>> > +/// Execution directions
>>> +enum RunDirection { eRunForward, eRunReverse };
>>> +
>>> If we don't add an overload to continue by adding 
>>> SBProcess::ReverseContinue() then this should be kept internal and not in 
>>> this header file. If you add a new SBProcess::Continue(lldb::RunDirection) 
>>> overload then this is needed. I would prefer a dedicated 
>>> SBProcess::ReverseContinue() function.
>>> 
>> 
>> Can you explain why?  It seems like that usage is going to be more verbose 
>> to no purpose, as I showed above.
>> 
>>> 
>>> In lldb/include/lldb/Target/Process.h 
>>> :
>>> 
>>> > @@ -1129,10 +1129,15 @@ class Process : public 
>>> > std::enable_shared_from_this,
>>>/// \see Thread:Resume()
>>>/// \see Thread:Step()
>>>/// \see Thread:Suspend()
>>> -  virtual Status DoResume() {
>>> +  virtual Status DoResume(lldb::RunDirection direction) {
>>> I would rather have a new DoResumeReverse() instead of changing this 
>>> virtual API. Many modified files in this patch are a result of the process 
>>> plugins having to add support for not supporting reverse resumes.
>>> 
>> I also asked for this change in the review.  Ever other API that does resume 
>> takes this parameter, its odd and asymmetric not to do so.  
>> 
>>> 
>>> In lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h 
>>> :
>>> 
>>> > @@ -90,7 +90,7 @@ class ProcessKDP : public lldb_private::Process {
>>>// Process Control
>>>lldb_private::Status WillResume() override;
>>>  
>>> -  lldb_private::Status DoResume() override;
>>> +  lldb_private::Status DoResume(lldb::RunDirection direction) override;
>>>

[Lldb-commits] [lldb] 34e67ff - [lldb] Drop LOG_CONS from openlog call.

2024-07-23 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2024-07-23T11:29:12-07:00
New Revision: 34e67ffe1947b399f57002f8cf60340a391ce8c0

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

LOG: [lldb] Drop LOG_CONS from openlog call.

Don't pass `LOG_CONS` to the openlog call.

> Write directly to the system console if there is an error while
> sending to the system logger.

This seemed like a good idea at the time, but it turns out to be
extremely annoying when this happens and LLDB is overwhelmed by log
messages in the console.

rdar://132243490

Added: 


Modified: 
lldb/source/Host/common/Host.cpp

Removed: 




diff  --git a/lldb/source/Host/common/Host.cpp 
b/lldb/source/Host/common/Host.cpp
index 06ccc0e2b3424..e03d36e9cad4a 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -93,9 +93,8 @@ using namespace lldb_private;
 #include 
 void Host::SystemLog(Severity severity, llvm::StringRef message) {
   static llvm::once_flag g_openlog_once;
-  llvm::call_once(g_openlog_once, [] {
-openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
-  });
+  llvm::call_once(g_openlog_once,
+  [] { openlog("lldb", LOG_PID | LOG_NDELAY, LOG_USER); });
   int level = LOG_DEBUG;
   switch (severity) {
   case lldb::eSeverityInfo:



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


[Lldb-commits] [lldb] [llvm] [DRAFT][llvm]Added lib/Telemetry (PR #98528)

2024-07-23 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo updated 
https://github.com/llvm/llvm-project/pull/98528

>From 2fa1fa227e6ff93f8904d0f9d56432401d673ed7 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Wed, 10 Jul 2024 15:27:38 -0400
Subject: [PATCH 1/2] [llvm]Added lib/Telemetry  - Provide a base API for llvm
 Telemetry  - Provide some concrete implementation for it in lldb/Telemetry

---
 lldb/include/lldb/API/SBDebugger.h|   4 +
 lldb/include/lldb/Core/Debugger.h |   8 +
 lldb/include/lldb/Core/Telemetry.h| 153 +
 lldb/include/lldb/Target/Process.h|   3 +
 lldb/source/API/SBDebugger.cpp|   9 +
 lldb/source/Core/CMakeLists.txt   |   2 +
 lldb/source/Core/Debugger.cpp |  31 +-
 lldb/source/Core/Telemetry.cpp| 606 ++
 .../source/Interpreter/CommandInterpreter.cpp |  44 +-
 lldb/source/Target/Process.cpp|   7 +-
 lldb/source/Target/Target.cpp |  15 +-
 lldb/tools/lldb-dap/DAP.cpp   |   6 +-
 llvm/include/llvm/Telemetry/Telemetry.h   |  99 +++
 llvm/lib/CMakeLists.txt   |   1 +
 llvm/lib/Telemetry/CMakeLists.txt |   6 +
 llvm/lib/Telemetry/Telemetry.cpp  |  32 +
 16 files changed, 1011 insertions(+), 15 deletions(-)
 create mode 100644 lldb/include/lldb/Core/Telemetry.h
 create mode 100644 lldb/source/Core/Telemetry.cpp
 create mode 100644 llvm/include/llvm/Telemetry/Telemetry.h
 create mode 100644 llvm/lib/Telemetry/CMakeLists.txt
 create mode 100644 llvm/lib/Telemetry/Telemetry.cpp

diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index 84ea9c0f772e1..de09995679ad9 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -9,10 +9,12 @@
 #ifndef LLDB_API_SBDEBUGGER_H
 #define LLDB_API_SBDEBUGGER_H
 
+#include 
 #include 
 
 #include "lldb/API/SBDefines.h"
 #include "lldb/API/SBPlatform.h"
+#include "lldb/API/SBStructuredData.h"
 
 namespace lldb_private {
 class CommandPluginInterfaceImplementation;
@@ -245,6 +247,8 @@ class LLDB_API SBDebugger {
 
   lldb::SBTarget GetDummyTarget();
 
+  void SendTelemetry(SBStructuredData *entry);
+
   // Return true if target is deleted from the target list of the debugger.
   bool DeleteTarget(lldb::SBTarget &target);
 
diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index a72c2596cc2c5..13a444e438fec 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -19,6 +19,7 @@
 #include "lldb/Core/FormatEntity.h"
 #include "lldb/Core/IOHandler.h"
 #include "lldb/Core/SourceManager.h"
+#include "lldb/Core/Telemetry.h"
 #include "lldb/Core/UserSettingsController.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/StreamFile.h"
@@ -31,6 +32,7 @@
 #include "lldb/Utility/Diagnostics.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Status.h"
+#include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
@@ -137,6 +139,10 @@ class Debugger : public 
std::enable_shared_from_this,
 
   lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
 
+  std::shared_ptr GetTelemeter() { return m_telemeter; }
+
+  void SendClientTelemetry(lldb_private::StructuredData::Object *entry);
+
   File &GetInputFile() { return *m_input_file_sp; }
 
   File &GetOutputFile() { return m_output_stream_sp->GetFile(); }
@@ -754,6 +760,7 @@ class Debugger : public 
std::enable_shared_from_this,
   uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
   std::mutex m_interrupt_mutex;
 
+  std::shared_ptr m_telemeter;
   // Events for m_sync_broadcaster
   enum {
 eBroadcastBitEventThreadIsListening = (1 << 0),
@@ -766,6 +773,7 @@ class Debugger : public 
std::enable_shared_from_this,
 
   Debugger(const Debugger &) = delete;
   const Debugger &operator=(const Debugger &) = delete;
+  TelemetryEventStats stats;
 };
 
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
new file mode 100644
index 0..15cc3139764ad
--- /dev/null
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -0,0 +1,153 @@
+#ifndef LLDB_CORE_TELEMETRY_H
+#define LLDB_CORE_TELEMETRY_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Telemetry/Telemetry.h"
+
+using namespace llvm::telemetry;
+
+namespace lldb_private {
+
+struct DebuggerTelemetryInfo : public ::llvm::telemetry::TelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+
+  std::string ToString() const override;
+};
+
+struct TargetTelemetryInfo : public ::llvm::t

[Lldb-commits] [lldb] [llvm] [llvm]Added lib/Telemetry (PR #98528)

2024-07-23 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo edited 
https://github.com/llvm/llvm-project/pull/98528
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Robert O'Callahan via lldb-commits


@@ -0,0 +1,176 @@
+import logging
+import os
+import os.path
+import random
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.gdbclientutils import *
+import lldbgdbserverutils
+from lldbsuite.support import seven
+
+
+class GDBProxyTestBase(TestBase):
+"""
+Base class for gdbserver proxy tests.
+
+This class will setup and start a mock GDB server for the test to use.
+It pases through requests to a regular lldb-server/debugserver and
+forwards replies back to the LLDB under test.
+"""
+
+"""The gdbserver that we implement."""
+server = None
+"""The inner lldb-server/debugserver process that we proxy requests 
into."""
+monitor_server = None
+monitor_sock = None
+
+server_socket_class = TCPServerSocket
+
+DEFAULT_TIMEOUT = 20 * (10 if ("ASAN_OPTIONS" in os.environ) else 1)
+
+_verbose_log_handler = None
+_log_formatter = logging.Formatter(fmt="%(asctime)-15s %(levelname)-8s 
%(message)s")
+
+def setUpBaseLogging(self):
+self.logger = logging.getLogger(__name__)
+
+if len(self.logger.handlers) > 0:
+return  # We have set up this handler already
+
+self.logger.propagate = False
+self.logger.setLevel(logging.DEBUG)
+
+# log all warnings to stderr
+handler = logging.StreamHandler()
+handler.setLevel(logging.WARNING)
+handler.setFormatter(self._log_formatter)
+self.logger.addHandler(handler)
+
+def setUp(self):
+TestBase.setUp(self)
+
+self.setUpBaseLogging()
+
+if self.isVerboseLoggingRequested():
+# If requested, full logs go to a log file
+log_file_name = self.getLogBasenameForCurrentTest() + "-proxy.log"
+self._verbose_log_handler = logging.FileHandler(
+   log_file_name
+)
+self._verbose_log_handler.setFormatter(self._log_formatter)
+self._verbose_log_handler.setLevel(logging.DEBUG)
+self.logger.addHandler(self._verbose_log_handler)
+
+self.port = self.get_next_port()

rocallahan wrote:

Yes, fixed.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Robert O'Callahan via lldb-commits


@@ -0,0 +1,119 @@
+import lldb
+import time
+import unittest
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test.gdbclientutils import *
+from lldbsuite.test.lldbreverse import ReverseTestBase
+from lldbsuite.test import lldbutil
+
+
+class TestReverseContinueBreakpoints(ReverseTestBase):
+@add_test_categories(["dwarf"])

rocallahan wrote:

Yes, thanks for that.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Robert O'Callahan via lldb-commits


@@ -158,7 +158,7 @@ class LLDB_API SBProcess {
 
   lldb::SBError Destroy();
 
-  lldb::SBError Continue();
+  lldb::SBError Continue(RunDirection direction = RunDirection::eRunForward);

rocallahan wrote:

Yeah, I originally wrote everything as you suggested, and @jimingham asked me 
to change it to what you see now. So I need you two to come to an agreement and 
tell me what it is.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Robert O'Callahan via lldb-commits


@@ -1363,6 +1374,43 @@ Status ProcessGDBRemote::DoResume() {
   }
 }
 
+if (direction == RunDirection::eRunReverse && continue_packet_error) {
+  if (num_continue_C_tids > 0 || num_continue_S_tids > 0) {
+error.SetErrorString("can't deliver signals while running in reverse");
+LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: Signals not 
supported");
+return error;
+  }
+
+  if (num_continue_s_tids > 0) {
+if (num_continue_s_tids > 1) {
+  error.SetErrorString("can't step multiple threads while 
reverse-stepping");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: can't step 
multiple threads");
+  return error;
+}
+
+if (!m_gdb_comm.GetReverseStepSupported()) {
+  error.SetErrorString("target does not support reverse-stepping");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: target does not 
support reverse-stepping");
+  return error;
+}
+
+m_gdb_comm.SetCurrentThreadForRun(m_continue_s_tids.front());
+continue_packet.PutCString("bs");
+  } else {
+if (!m_gdb_comm.GetReverseContinueSupported()) {

rocallahan wrote:

We need to determine whether we're going to step or continue first, so we can 
check whether the specific packet (`bs` or `bc`) we need is supported. I 
suppose we could collapse them into one feature flag and check that flag a bit 
earlier --- that would work fine in practice --- but I think what I have here, 
with a feature flag check right where we use that exact feature,  is a little 
more intuitive. I think the priority here should be the simplest, clearest 
code; "user tries to reverse-continue but that's not supported" is not a case 
that needs to be optimized.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread Robert O'Callahan via lldb-commits

https://github.com/rocallahan updated 
https://github.com/llvm/llvm-project/pull/99736

>From 026930762e967f84f48f8958c2448734692ad62f Mon Sep 17 00:00:00 2001
From: Robert O'Callahan 
Date: Fri, 19 Jul 2024 22:46:42 +1200
Subject: [PATCH] [lldb] Implement basic support for reverse-continue

This commit only adds support for the
`SBProcess::ReverseContinue()` API. A user-accessible command
for this will follow in a later commit.

This feature depends on a gdbserver implementation (e.g. `rr`)
providing support for the `bc` and `bs` packets. `lldb-server`
does not support those packets, and there is no plan to change that.
So, for testing purposes, `lldbreverse.py` wraps `lldb-server`
with a Python implementation of *very limited* record-and-replay
functionality.
---
 lldb/include/lldb/API/SBProcess.h |   2 +-
 lldb/include/lldb/Target/Process.h|  20 +-
 lldb/include/lldb/Target/StopInfo.h   |   3 +
 lldb/include/lldb/lldb-enumerations.h |   6 +
 .../Python/lldbsuite/test/gdbclientutils.py   |   5 +-
 .../Python/lldbsuite/test/lldbgdbproxy.py | 175 
 .../Python/lldbsuite/test/lldbreverse.py  | 418 ++
 .../Python/lldbsuite/test/lldbtest.py |   2 +
 lldb/source/API/SBProcess.cpp |   6 +-
 lldb/source/API/SBThread.cpp  |   2 +
 .../source/Interpreter/CommandInterpreter.cpp |   3 +-
 .../Process/Linux/NativeThreadLinux.cpp   |   3 +
 .../Process/MacOSX-Kernel/ProcessKDP.cpp  |   9 +-
 .../Process/MacOSX-Kernel/ProcessKDP.h|   2 +-
 .../Process/Windows/Common/ProcessWindows.cpp |   8 +-
 .../Process/Windows/Common/ProcessWindows.h   |   2 +-
 .../GDBRemoteCommunicationClient.cpp  |  22 +
 .../gdb-remote/GDBRemoteCommunicationClient.h |   6 +
 .../GDBRemoteCommunicationServerLLGS.cpp  |   1 +
 .../Process/gdb-remote/ProcessGDBRemote.cpp   |  78 +++-
 .../Process/gdb-remote/ProcessGDBRemote.h |   2 +-
 .../Process/scripted/ScriptedProcess.cpp  |  11 +-
 .../Process/scripted/ScriptedProcess.h|   2 +-
 lldb/source/Target/Process.cpp|  25 +-
 lldb/source/Target/StopInfo.cpp   |  29 ++
 lldb/source/Target/Thread.cpp |   8 +-
 .../reverse-execution/Makefile|   3 +
 .../TestReverseContinueBreakpoints.py | 115 +
 .../TestReverseContinueNotSupported.py|  30 ++
 .../functionalities/reverse-execution/main.c  |  14 +
 lldb/tools/lldb-dap/JSONUtils.cpp |   3 +
 lldb/tools/lldb-dap/LLDBUtils.cpp |   1 +
 32 files changed, 972 insertions(+), 44 deletions(-)
 create mode 100644 lldb/packages/Python/lldbsuite/test/lldbgdbproxy.py
 create mode 100644 lldb/packages/Python/lldbsuite/test/lldbreverse.py
 create mode 100644 lldb/test/API/functionalities/reverse-execution/Makefile
 create mode 100644 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
 create mode 100644 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py
 create mode 100644 lldb/test/API/functionalities/reverse-execution/main.c

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 778be79583990..cb7775ae94e46 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -158,7 +158,7 @@ class LLDB_API SBProcess {
 
   lldb::SBError Destroy();
 
-  lldb::SBError Continue();
+  lldb::SBError Continue(RunDirection direction = RunDirection::eRunForward);
 
   lldb::SBError Stop();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index c8475db8ae160..51d9c166fdda5 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -874,10 +874,10 @@ class Process : public 
std::enable_shared_from_this,
   /// \see Thread:Resume()
   /// \see Thread:Step()
   /// \see Thread:Suspend()
-  Status Resume();
+  Status Resume(lldb::RunDirection direction = lldb::eRunForward);
 
   /// Resume a process, and wait for it to stop.
-  Status ResumeSynchronous(Stream *stream);
+  Status ResumeSynchronous(Stream *stream, lldb::RunDirection direction = 
lldb::eRunForward);
 
   /// Halts a running process.
   ///
@@ -1129,10 +1129,15 @@ class Process : public 
std::enable_shared_from_this,
   /// \see Thread:Resume()
   /// \see Thread:Step()
   /// \see Thread:Suspend()
-  virtual Status DoResume() {
+  virtual Status DoResume(lldb::RunDirection direction) {
 Status error;
-error.SetErrorStringWithFormatv(
-"error: {0} does not support resuming processes", GetPluginName());
+if (direction == lldb::RunDirection::eRunForward) {
+  error.SetErrorStringWithFormatv(
+  "error: {0} does not support resuming processes", GetPluginName());
+} else {
+  error.SetErrorStringWithFormatv(
+  "error: {0} does not support reverse execution of processes", 
GetPluginName());
+}
 return error;
   }
 
@@ -2

[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread via lldb-commits


@@ -1363,6 +1374,43 @@ Status ProcessGDBRemote::DoResume() {
   }
 }
 
+if (direction == RunDirection::eRunReverse && continue_packet_error) {
+  if (num_continue_C_tids > 0 || num_continue_S_tids > 0) {
+error.SetErrorString("can't deliver signals while running in reverse");
+LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: Signals not 
supported");
+return error;
+  }
+
+  if (num_continue_s_tids > 0) {
+if (num_continue_s_tids > 1) {
+  error.SetErrorString("can't step multiple threads while 
reverse-stepping");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: can't step 
multiple threads");
+  return error;
+}
+
+if (!m_gdb_comm.GetReverseStepSupported()) {
+  error.SetErrorString("target does not support reverse-stepping");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoResumeReverse: target does not 
support reverse-stepping");
+  return error;
+}
+
+m_gdb_comm.SetCurrentThreadForRun(m_continue_s_tids.front());
+continue_packet.PutCString("bs");
+  } else {
+if (!m_gdb_comm.GetReverseContinueSupported()) {

jimingham wrote:

Ah, right, I forgot that those were separate capabilities.  I thought it would 
be useful to see that early out, but there's no need to complicate the logic in 
service of that.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][debuginfod] Fix the DebugInfoD PR that caused issues when working with stripped binaries (PR #99362)

2024-07-23 Thread Greg Clayton via lldb-commits

https://github.com/clayborg approved this pull request.


https://github.com/llvm/llvm-project/pull/99362
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #99736)

2024-07-23 Thread via lldb-commits


@@ -158,7 +158,7 @@ class LLDB_API SBProcess {
 
   lldb::SBError Destroy();
 
-  lldb::SBError Continue();
+  lldb::SBError Continue(RunDirection direction = RunDirection::eRunForward);

jimingham wrote:

I think it should be possible for most of lldb not to care which direction we 
happen to be going in.  We just need to know the current direction, or the 
intended direction of the active thread plan.  If we have to start putting in 
lots of special purpose logic for forward and backward outside of the 
ProcessGDBRemote plugin, I think we're doing it wrong.
But that's going to be harder to do if we start having a bunch of forward and 
reverse specific functions, since they all act as sites where you forget the 
"current direction" and then have to re-infer it later on.  It's particularly 
awkward having some take a direction and some be special purpose forward or 
backward.

https://github.com/llvm/llvm-project/pull/99736
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][debuginfod] Fix the DebugInfoD PR that caused issues when working with stripped binaries (PR #99362)

2024-07-23 Thread Kevin Frei via lldb-commits

kevinfrei wrote:

@JDevlieghere I think this still wants your approval. I squashed all the 
original commits, but kept the single final change to address the issue Walter 
found as a separate commit.

https://github.com/llvm/llvm-project/pull/99362
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Revert "[lldb/Commands] Add `scripting template list` command with auto discovery" (PR #100273)

2024-07-23 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/100273

Reverts llvm/llvm-project#97273 since it broke the windows bot:

https://lab.llvm.org/buildbot/#/builders/141/builds/1025/steps/4/logs/stdio

>From 70d2d397e2040c2dcc87a3dea12ad057e06632c4 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Tue, 23 Jul 2024 16:04:15 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[lldb/Commands]=20Add=20`scripting=20?=
 =?UTF-8?q?template=20list`=20command=20with=20auto=20disco=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 43ca63149dfbaa401a3bcee8b4835dccbac6d832.
---
 lldb/include/lldb/Core/PluginManager.h|  20 ---
 .../Interfaces/ScriptedInterface.h|   7 -
 .../Interfaces/ScriptedInterfaceUsages.h  |  43 --
 lldb/include/lldb/lldb-private-interfaces.h   |   3 -
 .../Commands/CommandObjectScripting.cpp   | 126 +-
 lldb/source/Commands/Options.td   |   6 -
 lldb/source/Core/PluginManager.cpp|  65 -
 lldb/source/Interpreter/CMakeLists.txt|   4 -
 .../Interpreter/Interfaces/CMakeLists.txt |  10 --
 .../Interfaces/ScriptedInterfaceUsages.cpp|  37 -
 lldb/source/Plugins/CMakeLists.txt|   3 -
 .../Python/Interfaces/CMakeLists.txt  |   9 +-
 .../OperatingSystemPythonInterface.cpp|  25 +---
 .../OperatingSystemPythonInterface.h  |  18 +--
 .../CMakeLists.txt|  15 ---
 .../ScriptedPlatformPythonInterface.cpp   |  24 +---
 .../ScriptedPlatformPythonInterface.h |  17 +--
 .../CMakeLists.txt|  15 ---
 .../ScriptedProcessPythonInterface.cpp|  39 +-
 .../ScriptedProcessPythonInterface.h  |  18 +--
 .../CMakeLists.txt|  15 ---
 .../ScriptedThreadPlanPythonInterface.cpp |  26 +---
 .../ScriptedThreadPlanPythonInterface.h   |  18 +--
 .../CMakeLists.txt|  15 ---
 .../Python/ScriptInterpreterPython.cpp|   8 +-
 25 files changed, 40 insertions(+), 546 deletions(-)
 delete mode 100644 
lldb/include/lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h
 delete mode 100644 lldb/source/Interpreter/Interfaces/CMakeLists.txt
 delete mode 100644 
lldb/source/Interpreter/Interfaces/ScriptedInterfaceUsages.cpp
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{OperatingSystemPythonInterface
 => }/OperatingSystemPythonInterface.cpp (76%)
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{OperatingSystemPythonInterface
 => }/OperatingSystemPythonInterface.h (83%)
 delete mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/CMakeLists.txt
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ScriptedPlatformPythonInterface
 => }/ScriptedPlatformPythonInterface.cpp (84%)
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ScriptedPlatformPythonInterface
 => }/ScriptedPlatformPythonInterface.h (84%)
 delete mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface/CMakeLists.txt
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ScriptedProcessPythonInterface
 => }/ScriptedProcessPythonInterface.cpp (86%)
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ScriptedProcessPythonInterface
 => }/ScriptedProcessPythonInterface.h (88%)
 delete mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ScriptedThreadPlanPythonInterface
 => }/ScriptedThreadPlanPythonInterface.cpp (79%)
 rename 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/{ScriptedThreadPlanPythonInterface
 => }/ScriptedThreadPlanPythonInterface.h (82%)
 delete mode 100644 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface/CMakeLists.txt

diff --git a/lldb/include/lldb/Core/PluginManager.h 
b/lldb/include/lldb/Core/PluginManager.h
index a23f834f471fb..38a291d9f0afd 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -10,7 +10,6 @@
 #define LLDB_CORE_PLUGINMANAGER_H
 
 #include "lldb/Core/Architecture.h"
-#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
 #include "lldb/Symbol/TypeSystem.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/FileSpec.h"
@@ -488,25 +487,6 @@ class PluginManager {
 
   static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
 
-  // Scripted Interface
-  static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
- ScriptedInterfaceCreateInstance create_callback,
- lldb::ScriptLanguage language,
- ScriptedInterfaceUsages usa

[Lldb-commits] [lldb] 39c23a3 - Revert "[lldb/Commands] Add `scripting template list` command with auto discovery" (#100273)

2024-07-23 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2024-07-23T16:04:48-07:00
New Revision: 39c23a31d2ab9a6068fcaa22ed9b1e10101db5ff

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

LOG: Revert "[lldb/Commands] Add `scripting template list` command with auto 
discovery" (#100273)

Reverts llvm/llvm-project#97273 since it broke the windows bot:

https://lab.llvm.org/buildbot/#/builders/141/builds/1025/steps/4/logs/stdio

Added: 

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h

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

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h

Modified: 
lldb/include/lldb/Core/PluginManager.h
lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
lldb/include/lldb/lldb-private-interfaces.h
lldb/source/Commands/CommandObjectScripting.cpp
lldb/source/Commands/Options.td
lldb/source/Core/PluginManager.cpp
lldb/source/Interpreter/CMakeLists.txt
lldb/source/Plugins/CMakeLists.txt
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Removed: 
lldb/include/lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h
lldb/source/Interpreter/Interfaces/CMakeLists.txt
lldb/source/Interpreter/Interfaces/ScriptedInterfaceUsages.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/CMakeLists.txt

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface/CMakeLists.txt

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface/ScriptedPlatformPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface/ScriptedPlatformPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt

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

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface/CMakeLists.txt

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface/ScriptedThreadPlanPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface/ScriptedThreadPlanPythonInterface.h



diff  --git a/lldb/include/lldb/Core/PluginManager.h 
b/lldb/include/lldb/Core/PluginManager.h
index a23f834f471fb..38a291d9f0afd 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -10,7 +10,6 @@
 #define LLDB_CORE_PLUGINMANAGER_H
 
 #include "lldb/Core/Architecture.h"
-#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
 #include "lldb/Symbol/TypeSystem.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/FileSpec.h"
@@ -488,25 +487,6 @@ class PluginManager {
 
   static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
 
-  // Scripted Interface
-  static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
- ScriptedInterfaceCreateInstance create_callback,
- lldb::ScriptLanguage language,
- ScriptedInterfaceUsages usages);
-
-  static bool UnregisterPlugin(ScriptedInterfaceCreateInstance 
create_callback);
-
-  static uint32_t GetNumScriptedInterfaces();
-
-  static llvm::StringRef GetScriptedInterfaceNameAtIndex(uint32_t idx);
-
-  static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx);
-
-  static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t 
idx);
-
-  static ScriptedInterfaceUsages
-  GetScriptedInterfaceUsagesAtIndex(uint32_t idx);
-
   // 

[Lldb-commits] [lldb] Revert "[lldb/Commands] Add `scripting template list` command with auto discovery" (PR #100273)

2024-07-23 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben closed 
https://github.com/llvm/llvm-project/pull/100273
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Revert "[lldb/Commands] Add `scripting template list` command with auto discovery" (PR #100273)

2024-07-23 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)


Changes

Reverts llvm/llvm-project#97273 since it broke the windows bot:

https://lab.llvm.org/buildbot/#/builders/141/builds/1025/steps/4/logs/stdio

---

Patch is 41.15 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/100273.diff


25 Files Affected:

- (modified) lldb/include/lldb/Core/PluginManager.h (-20) 
- (modified) lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h (-7) 
- (removed) lldb/include/lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h 
(-43) 
- (modified) lldb/include/lldb/lldb-private-interfaces.h (-3) 
- (modified) lldb/source/Commands/CommandObjectScripting.cpp (+2-124) 
- (modified) lldb/source/Commands/Options.td (-6) 
- (modified) lldb/source/Core/PluginManager.cpp (-65) 
- (modified) lldb/source/Interpreter/CMakeLists.txt (-4) 
- (removed) lldb/source/Interpreter/Interfaces/CMakeLists.txt (-10) 
- (removed) lldb/source/Interpreter/Interfaces/ScriptedInterfaceUsages.cpp 
(-37) 
- (modified) lldb/source/Plugins/CMakeLists.txt (-3) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/CMakeLists.txt (+4-5) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.cpp
 (+3-22) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface.h
 (+3-15) 
- (removed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/OperatingSystemPythonInterface/CMakeLists.txt
 (-15) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
 (+5-19) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.h
 (+3-14) 
- (removed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface/CMakeLists.txt
 (-15) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.cpp
 (+7-32) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface.h
 (+3-15) 
- (removed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedProcessPythonInterface/CMakeLists.txt
 (-15) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.cpp
 (+3-23) 
- (renamed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface.h
 (+3-15) 
- (removed) 
lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPlanPythonInterface/CMakeLists.txt
 (-15) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+4-4) 


``diff
diff --git a/lldb/include/lldb/Core/PluginManager.h 
b/lldb/include/lldb/Core/PluginManager.h
index a23f834f471fb..38a291d9f0afd 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -10,7 +10,6 @@
 #define LLDB_CORE_PLUGINMANAGER_H
 
 #include "lldb/Core/Architecture.h"
-#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
 #include "lldb/Symbol/TypeSystem.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/FileSpec.h"
@@ -488,25 +487,6 @@ class PluginManager {
 
   static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
 
-  // Scripted Interface
-  static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
- ScriptedInterfaceCreateInstance create_callback,
- lldb::ScriptLanguage language,
- ScriptedInterfaceUsages usages);
-
-  static bool UnregisterPlugin(ScriptedInterfaceCreateInstance 
create_callback);
-
-  static uint32_t GetNumScriptedInterfaces();
-
-  static llvm::StringRef GetScriptedInterfaceNameAtIndex(uint32_t idx);
-
-  static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx);
-
-  static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t 
idx);
-
-  static ScriptedInterfaceUsages
-  GetScriptedInterfaceUsagesAtIndex(uint32_t idx);
-
   // REPL
   static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
  REPLCreateInstance create_callback,
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 3ce47d0584a8a..69504dbcda5dc 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -9,8 +9,6 @@
 #ifndef LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
 #define LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
 
-#include "ScriptedInterfaceUsages.h"
-
 #include "lldb/Core/StructuredDataImpl.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
@@ -70,11 +68,6 @@ class ScriptedInterface {
 return true;
   }
 
-  static bool CreateInstance(lldb::ScriptLangu

[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Add parallelization for processing of DWO debug information (PR #100282)

2024-07-23 Thread Sayhaan Siddiqui via lldb-commits

https://github.com/sayhaan created 
https://github.com/llvm/llvm-project/pull/100282

Enables parallelization for the processing of DWO CUs.

>From 11fff0b2d1868f1e8fce988b2b41a38de42dff61 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Tue, 1 Jun 2021 11:37:41 -0700
Subject: [PATCH 1/5] Rebase: [Facebook] Add clang driver options to test debug
 info and BOLT

Summary:
This is an essential piece of infrastructure for us to be
continuously testing debug info with BOLT. We can't only make changes
to a test repo because we need to change debuginfo tests to call BOLT,
hence, this diff needs to sit in our opensource repo. But when upstreaming
to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming,
we need to git diff and check all folders that are being modified by our
commits and discard this one (and leave as an internal diff).

To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON.
Then run check-lldb and check-debuginfo.

Manual rebase conflict history:
https://phabricator.intern.facebook.com/D29205224
https://phabricator.intern.facebook.com/D29564078
https://phabricator.intern.facebook.com/D33289118
https://phabricator.intern.facebook.com/D34957174
https://phabricator.intern.facebook.com/D35317341

Test Plan:
tested locally
Configured with:
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests"
-DLLVM_TEST_BOLT=ON
Ran test suite with:
ninja check-debuginfo
ninja check-lldb

Reviewers: maks, #llvm-bolt

Reviewed By: maks

Subscribers: ayermolo, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D46256657

Tasks: T92898286
---
 clang/include/clang/Driver/Options.td  |  4 
 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++
 cross-project-tests/lit.cfg.py | 14 -
 cross-project-tests/lit.site.cfg.py.in |  4 
 lldb/test/API/lit.cfg.py   |  5 +
 lldb/test/API/lit.site.cfg.py.in   |  8 +++
 lldb/test/Shell/helper/toolchain.py|  5 +
 lldb/test/Shell/lit.site.cfg.py.in |  9 
 llvm/CMakeLists.txt|  4 
 9 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9c6cebd77ff0a..8ccbc4b372ba3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5553,6 +5553,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount 
instrumentation">,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
   HelpText<"Use pipes between commands, when possible">;
+// Facebook T92898286
+def post_link_optimize : Flag<["--"], "post-link-optimize">,
+  HelpText<"Apply post-link optimizations using BOLT">;
+// End Facebook T92898286
 def prebind__all__twolevel__modules : Flag<["-"], 
"prebind_all_twolevel_modules">;
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 52c2ee90b1b28..ff20deb9c4f86 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation 
&C, const JobAction &JA,
 }
   }
 
+  // Facebook T92898286
+  if (Args.hasArg(options::OPT_post_link_optimize))
+CmdArgs.push_back("-q");
+  // End Facebook T92898286
+
   Args.AddAllArgs(CmdArgs, options::OPT_T);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
  Exec, CmdArgs, Inputs, Output));
+  // Facebook T92898286
+  if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename())
+return;
+
+  const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv"));
+  ArgStringList MoveCmdArgs;
+  MoveCmdArgs.push_back(Output.getFilename());
+  const char *PreBoltBin =
+  Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt");
+  MoveCmdArgs.push_back(PreBoltBin);
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ MvExec, MoveCmdArgs, std::nullopt));
+
+  ArgStringList BoltCmdArgs;
+  const char *BoltExec =
+  Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt"));
+  BoltCmdArgs.push_back(PreBoltBin);
+  BoltCmdArgs.push_back("-reorder-blocks=reverse");
+  BoltCmdArgs.push_back("-update-debug-sections");
+  BoltCmdArgs.push_back("-o");
+  BoltCmdArgs.push_back(Output.getFilename());
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ BoltExec, BoltCmdArgs, std::nullopt));
+  // End Facebook T92898286
 }
 
 void tools::gnutools::Assembler::ConstructJob(Compilation &C,
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index 774c4eaf4d976..61963457

[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Add parallelization for processing of DWO debug information (PR #100282)

2024-07-23 Thread Sayhaan Siddiqui via lldb-commits

https://github.com/sayhaan updated 
https://github.com/llvm/llvm-project/pull/100282

>From 8824746a8fe2390a6cb35075f2595f0a6c9586f0 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Tue, 1 Jun 2021 11:37:41 -0700
Subject: [PATCH 1/3] Rebase: [Facebook] Add clang driver options to test debug
 info and BOLT

Summary:
This is an essential piece of infrastructure for us to be
continuously testing debug info with BOLT. We can't only make changes
to a test repo because we need to change debuginfo tests to call BOLT,
hence, this diff needs to sit in our opensource repo. But when upstreaming
to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming,
we need to git diff and check all folders that are being modified by our
commits and discard this one (and leave as an internal diff).

To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON.
Then run check-lldb and check-debuginfo.

Manual rebase conflict history:
https://phabricator.intern.facebook.com/D29205224
https://phabricator.intern.facebook.com/D29564078
https://phabricator.intern.facebook.com/D33289118
https://phabricator.intern.facebook.com/D34957174
https://phabricator.intern.facebook.com/D35317341

Test Plan:
tested locally
Configured with:
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests"
-DLLVM_TEST_BOLT=ON
Ran test suite with:
ninja check-debuginfo
ninja check-lldb

Reviewers: maks, #llvm-bolt

Reviewed By: maks

Subscribers: ayermolo, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D46256657

Tasks: T92898286
---
 clang/include/clang/Driver/Options.td  |  4 
 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++
 cross-project-tests/lit.cfg.py | 14 -
 cross-project-tests/lit.site.cfg.py.in |  4 
 lldb/test/API/lit.cfg.py   |  5 +
 lldb/test/API/lit.site.cfg.py.in   |  8 +++
 lldb/test/Shell/helper/toolchain.py|  5 +
 lldb/test/Shell/lit.site.cfg.py.in |  9 
 llvm/CMakeLists.txt|  4 
 9 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fa36405ec1bdd..6d925afb2cf42 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5561,6 +5561,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount 
instrumentation">,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
   HelpText<"Use pipes between commands, when possible">;
+// Facebook T92898286
+def post_link_optimize : Flag<["--"], "post-link-optimize">,
+  HelpText<"Apply post-link optimizations using BOLT">;
+// End Facebook T92898286
 def prebind__all__twolevel__modules : Flag<["-"], 
"prebind_all_twolevel_modules">;
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 52c2ee90b1b28..ff20deb9c4f86 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation 
&C, const JobAction &JA,
 }
   }
 
+  // Facebook T92898286
+  if (Args.hasArg(options::OPT_post_link_optimize))
+CmdArgs.push_back("-q");
+  // End Facebook T92898286
+
   Args.AddAllArgs(CmdArgs, options::OPT_T);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
  Exec, CmdArgs, Inputs, Output));
+  // Facebook T92898286
+  if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename())
+return;
+
+  const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv"));
+  ArgStringList MoveCmdArgs;
+  MoveCmdArgs.push_back(Output.getFilename());
+  const char *PreBoltBin =
+  Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt");
+  MoveCmdArgs.push_back(PreBoltBin);
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ MvExec, MoveCmdArgs, std::nullopt));
+
+  ArgStringList BoltCmdArgs;
+  const char *BoltExec =
+  Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt"));
+  BoltCmdArgs.push_back(PreBoltBin);
+  BoltCmdArgs.push_back("-reorder-blocks=reverse");
+  BoltCmdArgs.push_back("-update-debug-sections");
+  BoltCmdArgs.push_back("-o");
+  BoltCmdArgs.push_back(Output.getFilename());
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ BoltExec, BoltCmdArgs, std::nullopt));
+  // End Facebook T92898286
 }
 
 void tools::gnutools::Assembler::ConstructJob(Compilation &C,
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index 9935fe6a199da..232d9811e00ad 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/

[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Add parallelization for processing of DWO debug information (PR #100282)

2024-07-23 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
ef8de68faebee0226b4836e66574f225f724e768...cbcf4b3fb0ccad7eea5c1672b90a564e707028f6
 cross-project-tests/lit.cfg.py lldb/test/API/lit.cfg.py 
lldb/test/Shell/helper/toolchain.py
``





View the diff from darker here.


``diff
--- cross-project-tests/lit.cfg.py  2024-07-23 23:48:08.00 +
+++ cross-project-tests/lit.cfg.py  2024-07-23 23:52:14.734146 +
@@ -82,11 +82,14 @@
 if not hasattr(config, "clang_src_dir"):
 config.clang_src_dir = ""
 # Facebook T92898286
 should_test_bolt = get_required_attr(config, "llvm_test_bolt")
 if should_test_bolt:
-llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects), 
additional_flags=["--post-link-optimize"])
+llvm_config.use_clang(
+required=("clang" in config.llvm_enabled_projects),
+additional_flags=["--post-link-optimize"],
+)
 else:
 llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects))
 # End Facebook T92898286
 
 if not hasattr(config, "lld_src_dir"):

``




https://github.com/llvm/llvm-project/pull/100282
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Don't crash when attaching to pid and no binaries found (PR #100287)

2024-07-23 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda created 
https://github.com/llvm/llvm-project/pull/100287

There is a narrow window during process launch on macOS where lldb can attach 
and no binaries will be seen as loaded in the process (none reported by libdyld 
SPI).  A year ago I made changes to set the new-binary-loaded breakpoint 
correctly despite this.  But we've seen a crash when this combination is seen, 
where CommandObjectProcessAttach::DoExecute assumed there was at least one 
binary registered in the Target.  Fix that.

Also fix two FileSpec API uses from when we didn't have a GetPath() method that 
returned a std::string, and was copying the filepaths into fixed length 
buffers.  All of this code was from ~14 years ago when we didn't have that API.

rdar://131631627

>From 4cec9c8e71229cb47ab0d0536f7e654caf05d2f1 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Tue, 23 Jul 2024 17:33:24 -0700
Subject: [PATCH] [lldb] Don't crash when attaching to pid and no binaries
 found

There is a narrow window during process launch on macOS where
lldb can attach and no binaries will be seen as loaded in the
process (none reported by libdyld SPI).  A year ago I made
changes to set the new-binary-loaded breakpoint correctly despite
this.  But we've seen a crash when this combination is seen, where
CommandObjectProcessAttach::DoExecute assumed there was at least
one binary registered in the Target.  Fix that.

Also fix two FileSpec API uses from when we didn't have a GetPath()
method that returned a std::string, and was copying the filepaths
into fixed length buffers.  All of this code was from ~14 years ago
when we didn't have that API.

rdar://131631627
---
 lldb/source/Commands/CommandObjectProcess.cpp | 18 --
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lldb/source/Commands/CommandObjectProcess.cpp 
b/lldb/source/Commands/CommandObjectProcess.cpp
index 50695af556939..e605abdb3c771 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -369,25 +369,23 @@ class CommandObjectProcessAttach : public 
CommandObjectProcessLaunchOrAttach {
 
 // Okay, we're done.  Last step is to warn if the executable module has
 // changed:
-char new_path[PATH_MAX];
 ModuleSP new_exec_module_sp(target->GetExecutableModule());
 if (!old_exec_module_sp) {
   // We might not have a module if we attached to a raw pid...
   if (new_exec_module_sp) {
-new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
-result.AppendMessageWithFormat("Executable module set to \"%s\".\n",
-   new_path);
+result.AppendMessageWithFormat(
+"Executable binary set to \"%s\".\n",
+new_exec_module_sp->GetFileSpec().GetPath().c_str());
   }
+} else if (!new_exec_module_sp) {
+  result.AppendWarningWithFormat("No executable binary.");
 } else if (old_exec_module_sp->GetFileSpec() !=
new_exec_module_sp->GetFileSpec()) {
-  char old_path[PATH_MAX];
-
-  old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX);
-  new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
 
   result.AppendWarningWithFormat(
-  "Executable module changed from \"%s\" to \"%s\".\n", old_path,
-  new_path);
+  "Executable binary changed from \"%s\" to \"%s\".\n",
+  old_exec_module_sp->GetFileSpec().GetPath().c_str(),
+  new_exec_module_sp->GetFileSpec().GetPath().c_str());
 }
 
 if (!old_arch_spec.IsValid()) {

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


[Lldb-commits] [lldb] [lldb] Don't crash when attaching to pid and no binaries found (PR #100287)

2024-07-23 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jason Molenda (jasonmolenda)


Changes

There is a narrow window during process launch on macOS where lldb can attach 
and no binaries will be seen as loaded in the process (none reported by libdyld 
SPI).  A year ago I made changes to set the new-binary-loaded breakpoint 
correctly despite this.  But we've seen a crash when this combination is seen, 
where CommandObjectProcessAttach::DoExecute assumed there was at least one 
binary registered in the Target.  Fix that.

Also fix two FileSpec API uses from when we didn't have a GetPath() method that 
returned a std::string, and was copying the filepaths into fixed length 
buffers.  All of this code was from ~14 years ago when we didn't have that API.

rdar://131631627

---
Full diff: https://github.com/llvm/llvm-project/pull/100287.diff


1 Files Affected:

- (modified) lldb/source/Commands/CommandObjectProcess.cpp (+8-10) 


``diff
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp 
b/lldb/source/Commands/CommandObjectProcess.cpp
index 50695af556939..e605abdb3c771 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -369,25 +369,23 @@ class CommandObjectProcessAttach : public 
CommandObjectProcessLaunchOrAttach {
 
 // Okay, we're done.  Last step is to warn if the executable module has
 // changed:
-char new_path[PATH_MAX];
 ModuleSP new_exec_module_sp(target->GetExecutableModule());
 if (!old_exec_module_sp) {
   // We might not have a module if we attached to a raw pid...
   if (new_exec_module_sp) {
-new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
-result.AppendMessageWithFormat("Executable module set to \"%s\".\n",
-   new_path);
+result.AppendMessageWithFormat(
+"Executable binary set to \"%s\".\n",
+new_exec_module_sp->GetFileSpec().GetPath().c_str());
   }
+} else if (!new_exec_module_sp) {
+  result.AppendWarningWithFormat("No executable binary.");
 } else if (old_exec_module_sp->GetFileSpec() !=
new_exec_module_sp->GetFileSpec()) {
-  char old_path[PATH_MAX];
-
-  old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX);
-  new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
 
   result.AppendWarningWithFormat(
-  "Executable module changed from \"%s\" to \"%s\".\n", old_path,
-  new_path);
+  "Executable binary changed from \"%s\" to \"%s\".\n",
+  old_exec_module_sp->GetFileSpec().GetPath().c_str(),
+  new_exec_module_sp->GetFileSpec().GetPath().c_str());
 }
 
 if (!old_arch_spec.IsValid()) {

``




https://github.com/llvm/llvm-project/pull/100287
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Don't crash when attaching to pid and no binaries found (PR #100287)

2024-07-23 Thread via lldb-commits

https://github.com/jimingham approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/100287
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 56535a0 - [lldb] Don't crash when attaching to pid and no binaries found (#100287)

2024-07-23 Thread via lldb-commits

Author: Jason Molenda
Date: 2024-07-23T17:50:40-07:00
New Revision: 56535a090d91ff10a60c884bacbd314dcf9659db

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

LOG: [lldb] Don't crash when attaching to pid and no binaries found (#100287)

There is a narrow window during process launch on macOS where lldb can
attach and no binaries will be seen as loaded in the process (none
reported by libdyld SPI). A year ago I made changes to set the
new-binary-loaded breakpoint correctly despite this. But we've seen a
crash when this combination is seen, where
CommandObjectProcessAttach::DoExecute assumed there was at least one
binary registered in the Target. Fix that.

Also fix two FileSpec API uses from when we didn't have a GetPath()
method that returned a std::string, and was copying the filepaths into
fixed length buffers. All of this code was from ~14 years ago when we
didn't have that API.

rdar://131631627

Added: 


Modified: 
lldb/source/Commands/CommandObjectProcess.cpp

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectProcess.cpp 
b/lldb/source/Commands/CommandObjectProcess.cpp
index 50695af556939..e605abdb3c771 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -369,25 +369,23 @@ class CommandObjectProcessAttach : public 
CommandObjectProcessLaunchOrAttach {
 
 // Okay, we're done.  Last step is to warn if the executable module has
 // changed:
-char new_path[PATH_MAX];
 ModuleSP new_exec_module_sp(target->GetExecutableModule());
 if (!old_exec_module_sp) {
   // We might not have a module if we attached to a raw pid...
   if (new_exec_module_sp) {
-new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
-result.AppendMessageWithFormat("Executable module set to \"%s\".\n",
-   new_path);
+result.AppendMessageWithFormat(
+"Executable binary set to \"%s\".\n",
+new_exec_module_sp->GetFileSpec().GetPath().c_str());
   }
+} else if (!new_exec_module_sp) {
+  result.AppendWarningWithFormat("No executable binary.");
 } else if (old_exec_module_sp->GetFileSpec() !=
new_exec_module_sp->GetFileSpec()) {
-  char old_path[PATH_MAX];
-
-  old_exec_module_sp->GetFileSpec().GetPath(old_path, PATH_MAX);
-  new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
 
   result.AppendWarningWithFormat(
-  "Executable module changed from \"%s\" to \"%s\".\n", old_path,
-  new_path);
+  "Executable binary changed from \"%s\" to \"%s\".\n",
+  old_exec_module_sp->GetFileSpec().GetPath().c_str(),
+  new_exec_module_sp->GetFileSpec().GetPath().c_str());
 }
 
 if (!old_arch_spec.IsValid()) {



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


[Lldb-commits] [lldb] [lldb] Don't crash when attaching to pid and no binaries found (PR #100287)

2024-07-23 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda closed 
https://github.com/llvm/llvm-project/pull/100287
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Don't use a vm addr range starting at 0 for local memory (PR #100288)

2024-07-23 Thread Jason Molenda via lldb-commits

https://github.com/jasonmolenda created 
https://github.com/llvm/llvm-project/pull/100288

When an inferior stub cannot allocate memory for lldb, and lldb needs to store 
the result of expressions, it will do it in lldb's own memory range ("host 
memory").  But it needs to find a virtual address range that is not used in the 
inferior process.  It tries to use the qMemoryRegionInfo gdb remote serial 
protocol packet to find a range that is inaccessible, starting at address 0 and 
moving up the size of each region.

If the first region found at address 0 is inaccessible, lldb will use the 
address range starting at 0 to mean "read lldb's host memory, not the process 
memory", and programs that crash with a null dereference will have poor 
behavior.

This patch skips consideration of a memory region that starts at address 0.

I also clarified the documentation of qMemoryRegionInfo to make it clear that 
the stub is required to provide permissions for a memory range that is 
accessable, it is not an optional key in this response. This issue was 
originally found by a stub that did not list permissions in its response, and 
lldb treated the first region returned as the one it would use.  (the stub also 
didn't support the memory-allocate packet)

>From 28439443b9e44a242e59bf1cdd114486380d54fc Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Tue, 23 Jul 2024 18:54:31 -0700
Subject: [PATCH] [lldb] Don't use a vm addr range starting at 0 for local
 memory

When an inferior stub cannot allocate memory for lldb, and lldb
needs to store the result of expressions, it will do it in lldb's
own memory range ("host memory").  But it needs to find a virtual
address range that is not used in the inferior process.  It tries
to use the qMemoryRegionInfo gdb remote serial protocol packet to
find a range that is inaccessible, starting at address 0 and moving
up the size of each region.

If the first region found at address 0 is inaccessible, lldb will
use the address range starting at 0 to mean "read lldb's host memory,
not the process memory", and programs that crash with a null
dereference will have poor behavior.

This patch skips consideration of a memory region that starts at
address 0.

I also clarified the documentation of qMemoryRegionInfo to make it
clear that the stub is required to provide permissions for a memory
range that is accessable, it is not an optional key in this response.
This issue was originally found by a stub that did not list
permissions, and lldb treated the first region returned as the one
it would use.
---
 lldb/docs/resources/lldbgdbremote.md   |  8 +++-
 lldb/source/Expression/IRMemoryMap.cpp | 17 -
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/lldb/docs/resources/lldbgdbremote.md 
b/lldb/docs/resources/lldbgdbremote.md
index 7076a75032dae..5cac3736337a8 100644
--- a/lldb/docs/resources/lldbgdbremote.md
+++ b/lldb/docs/resources/lldbgdbremote.md
@@ -1403,6 +1403,12 @@ For instance, with a macOS process which has nothing 
mapped in the first
 The lack of `permissions:` indicates that none of read/write/execute are valid
 for this region.
 
+The stub must include `permissions:` key-value on all memory ranges
+that are valid to access in the inferior process -- the lack of
+`permissions:` means that this is an inaccessible (no page table
+entries exist, in a system using VM) memory range.  If a stub cannot
+determine actual permissions, return `rwx`.
+
 **Priority To Implement:** Medium
 
 This is nice to have, but it isn't necessary. It helps LLDB
@@ -2434,4 +2440,4 @@ The `0x` prefixes are optional - like most of the 
gdb-remote packets,
 omitting them will work fine; these numbers are always base 16.
 
 The length of the payload is not provided.  A reliable, 8-bit clean,
-transport layer is assumed.
\ No newline at end of file
+transport layer is assumed.
diff --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index de631370bb048..bb3e4e0a9a9fc 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -84,7 +84,7 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // any allocations.  Otherwise start at the beginning of memory.
 
   if (m_allocations.empty()) {
-ret = 0x0;
+ret = 0;
   } else {
 auto back = m_allocations.rbegin();
 lldb::addr_t addr = back->first;
@@ -116,10 +116,17 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
 Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
 if (err.Success()) {
   while (true) {
-if (region_info.GetReadable() != MemoryRegionInfo::OptionalBool::eNo ||
-region_info.GetWritable() != MemoryRegionInfo::OptionalBool::eNo ||
-region_info.GetExecutable() !=
-MemoryRegionInfo::OptionalBool::eNo) {
+if (region_info.GetRange().GetRangeBase() == 0 &&
+region_info.GetRange().GetRangeEnd() - 1 < end_of_memory) {
+  // Don

[Lldb-commits] [lldb] [lldb] Don't use a vm addr range starting at 0 for local memory (PR #100288)

2024-07-23 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

I created this PR as an alternative approach to the issue reported in 
https://github.com/llvm/llvm-project/pull/99045

https://github.com/llvm/llvm-project/pull/100288
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Don't use a vm addr range starting at 0 for local memory (PR #100288)

2024-07-23 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jason Molenda (jasonmolenda)


Changes

When an inferior stub cannot allocate memory for lldb, and lldb needs to store 
the result of expressions, it will do it in lldb's own memory range ("host 
memory").  But it needs to find a virtual address range that is not used in the 
inferior process.  It tries to use the qMemoryRegionInfo gdb remote serial 
protocol packet to find a range that is inaccessible, starting at address 0 and 
moving up the size of each region.

If the first region found at address 0 is inaccessible, lldb will use the 
address range starting at 0 to mean "read lldb's host memory, not the process 
memory", and programs that crash with a null dereference will have poor 
behavior.

This patch skips consideration of a memory region that starts at address 0.

I also clarified the documentation of qMemoryRegionInfo to make it clear that 
the stub is required to provide permissions for a memory range that is 
accessable, it is not an optional key in this response. This issue was 
originally found by a stub that did not list permissions in its response, and 
lldb treated the first region returned as the one it would use.  (the stub also 
didn't support the memory-allocate packet)

---
Full diff: https://github.com/llvm/llvm-project/pull/100288.diff


2 Files Affected:

- (modified) lldb/docs/resources/lldbgdbremote.md (+7-1) 
- (modified) lldb/source/Expression/IRMemoryMap.cpp (+12-5) 


``diff
diff --git a/lldb/docs/resources/lldbgdbremote.md 
b/lldb/docs/resources/lldbgdbremote.md
index 7076a75032dae..5cac3736337a8 100644
--- a/lldb/docs/resources/lldbgdbremote.md
+++ b/lldb/docs/resources/lldbgdbremote.md
@@ -1403,6 +1403,12 @@ For instance, with a macOS process which has nothing 
mapped in the first
 The lack of `permissions:` indicates that none of read/write/execute are valid
 for this region.
 
+The stub must include `permissions:` key-value on all memory ranges
+that are valid to access in the inferior process -- the lack of
+`permissions:` means that this is an inaccessible (no page table
+entries exist, in a system using VM) memory range.  If a stub cannot
+determine actual permissions, return `rwx`.
+
 **Priority To Implement:** Medium
 
 This is nice to have, but it isn't necessary. It helps LLDB
@@ -2434,4 +2440,4 @@ The `0x` prefixes are optional - like most of the 
gdb-remote packets,
 omitting them will work fine; these numbers are always base 16.
 
 The length of the payload is not provided.  A reliable, 8-bit clean,
-transport layer is assumed.
\ No newline at end of file
+transport layer is assumed.
diff --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index de631370bb048..bb3e4e0a9a9fc 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -84,7 +84,7 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
   // any allocations.  Otherwise start at the beginning of memory.
 
   if (m_allocations.empty()) {
-ret = 0x0;
+ret = 0;
   } else {
 auto back = m_allocations.rbegin();
 lldb::addr_t addr = back->first;
@@ -116,10 +116,17 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
 Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
 if (err.Success()) {
   while (true) {
-if (region_info.GetReadable() != MemoryRegionInfo::OptionalBool::eNo ||
-region_info.GetWritable() != MemoryRegionInfo::OptionalBool::eNo ||
-region_info.GetExecutable() !=
-MemoryRegionInfo::OptionalBool::eNo) {
+if (region_info.GetRange().GetRangeBase() == 0 &&
+region_info.GetRange().GetRangeEnd() - 1 < end_of_memory) {
+  // Don't use a region that starts at address 0,
+  // that can mask null dereferences in the inferior.
+  ret = region_info.GetRange().GetRangeEnd();
+} else if (region_info.GetReadable() !=
+   MemoryRegionInfo::OptionalBool::eNo ||
+   region_info.GetWritable() !=
+   MemoryRegionInfo::OptionalBool::eNo ||
+   region_info.GetExecutable() !=
+   MemoryRegionInfo::OptionalBool::eNo) {
   if (region_info.GetRange().GetRangeEnd() - 1 >= end_of_memory) {
 ret = LLDB_INVALID_ADDRESS;
 break;

``




https://github.com/llvm/llvm-project/pull/100288
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] IRMemoryMap zero address mapping fix (PR #99045)

2024-07-23 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

I put up a PR that avoids a memory region starting at address 0, and also 
clarifies the documentation of the qMemoryRegionInfo packet to state that 
permissions: are required for all memory regions that are accessible by the 
inferior process.  A memory region with no `permissions:` key means that it is 
not an accessible region of memory.  I put this PR up at 
https://github.com/llvm/llvm-project/pull/100288  
@dlav-sc what do you think?  I know you've moved past this issue by 
implementing memory-allocation and fixing your qMemoryRegionInfo packet 
response, but I wanted to get a final fix before we all walk away from this PR.

https://github.com/llvm/llvm-project/pull/99045
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Updated README.md for newly added attach properties. (PR #99926)

2024-07-23 Thread Santhosh Kumar Ellendula via lldb-commits

https://github.com/santhoshe447 updated 
https://github.com/llvm/llvm-project/pull/99926

>From 960351c9abf51f42d92604ac6297aa5b76ddfba5 Mon Sep 17 00:00:00 2001
From: Santhosh Kumar Ellendula 
Date: Fri, 17 Nov 2023 15:09:10 +0530
Subject: [PATCH 01/18] [lldb][test] Add the ability to extract the variable
 value out of the summary.

---
 .../Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py   | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index 9d79872b029a3..0cf9d4fde4948 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -195,6 +195,9 @@ def collect_console(self, duration):
 
 def get_local_as_int(self, name, threadId=None):
 value = self.dap_server.get_local_variable_value(name, 
threadId=threadId)
+# 'value' may have the variable value and summary.
+# Extract the variable value since summary can have nonnumeric 
characters.
+value = value.split(" ")[0]
 if value.startswith("0x"):
 return int(value, 16)
 elif value.startswith("0"):

>From ab44a6991c5bc8ac5764c3f71cbe3acc747b3776 Mon Sep 17 00:00:00 2001
From: Santhosh Kumar Ellendula 
Date: Fri, 3 May 2024 02:47:05 -0700
Subject: [PATCH 02/18] [lldb-dap] Added "port" property to vscode "attach"
 command.

Adding a "port" property to the VsCode "attach" command likely extends the 
functionality of the debugger configuratiuon to allow attaching to a process 
using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We tell the 
user to use the attachCommands property to run "gdb-remote ".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not, use that 
port to attach. If both port and pid are specified, return an error saying that 
the user can't specify both pid and port.

Ex - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "lldb-dap Debug",
"type": "lldb-dap",
"request": "attach",
"port":1234,
"program": "${workspaceFolder}/a.out",
"args": [],
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"env": [],

}
]
}
---
 lldb/include/lldb/lldb-defines.h  |   1 +
 .../Python/lldbsuite/test/lldbtest.py |   9 ++
 .../test/tools/lldb-dap/dap_server.py |   6 +
 .../test/tools/lldb-dap/lldbdap_testcase.py   |  20 +++
 .../attach/TestDAP_attachByPortNum.py | 120 ++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  36 +-
 lldb/tools/lldb-dap/package.json  |  11 ++
 7 files changed, 199 insertions(+), 4 deletions(-)
 create mode 100644 
lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py

diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h
index c7bd019c5c90e..a1e6ee2ce468c 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -96,6 +96,7 @@
 #define LLDB_INVALID_QUEUE_ID 0
 #define LLDB_INVALID_CPU_ID UINT32_MAX
 #define LLDB_INVALID_WATCHPOINT_RESOURCE_ID UINT32_MAX
+#define LLDB_INVALID_PORT_NUMBER 0
 
 /// CPU Type definitions
 #define LLDB_ARCH_DEFAULT "systemArch"
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 5fd686c143e9f..fb3cd22959df2 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1572,6 +1572,15 @@ def findBuiltClang(self):
 
 return os.environ["CC"]
 
+def getBuiltServerTool(self, server_tool):
+# Tries to find simulation/lldb-server/gdbserver tool at the same 
folder as the lldb.
+lldb_dir = os.path.dirname(lldbtest_config.lldbExec)
+path = shutil.which(server_tool, path=lldb_dir)
+if path is not None:
+return path
+
+return ""
+
 def yaml2obj(self, yaml_path, obj_path, max_size=None):
 """
 Create an object file at the given path from a yaml file.
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 5838281bcb1a1..96d312565f953 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -568,6 +568,8 @@ def request_attach(
 coreFile=None,
 postRunCommands=None,
 sourceMap=None,
+port=None,
+hostname=None
 ):
 args_dict = {}
 if pid is not None:
@@ -597,6 +599,10 @@ def request_attach(
 args_dict["postRunCommands"] = postRunCo

[Lldb-commits] [lldb] [lldb-dap] Updated README.md for newly added attach properties. (PR #99926)

2024-07-23 Thread Santhosh Kumar Ellendula via lldb-commits

https://github.com/santhoshe447 updated 
https://github.com/llvm/llvm-project/pull/99926

>From 960351c9abf51f42d92604ac6297aa5b76ddfba5 Mon Sep 17 00:00:00 2001
From: Santhosh Kumar Ellendula 
Date: Fri, 17 Nov 2023 15:09:10 +0530
Subject: [PATCH 01/19] [lldb][test] Add the ability to extract the variable
 value out of the summary.

---
 .../Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py   | 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index 9d79872b029a3..0cf9d4fde4948 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -195,6 +195,9 @@ def collect_console(self, duration):
 
 def get_local_as_int(self, name, threadId=None):
 value = self.dap_server.get_local_variable_value(name, 
threadId=threadId)
+# 'value' may have the variable value and summary.
+# Extract the variable value since summary can have nonnumeric 
characters.
+value = value.split(" ")[0]
 if value.startswith("0x"):
 return int(value, 16)
 elif value.startswith("0"):

>From ab44a6991c5bc8ac5764c3f71cbe3acc747b3776 Mon Sep 17 00:00:00 2001
From: Santhosh Kumar Ellendula 
Date: Fri, 3 May 2024 02:47:05 -0700
Subject: [PATCH 02/19] [lldb-dap] Added "port" property to vscode "attach"
 command.

Adding a "port" property to the VsCode "attach" command likely extends the 
functionality of the debugger configuratiuon to allow attaching to a process 
using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We tell the 
user to use the attachCommands property to run "gdb-remote ".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not, use that 
port to attach. If both port and pid are specified, return an error saying that 
the user can't specify both pid and port.

Ex - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "lldb-dap Debug",
"type": "lldb-dap",
"request": "attach",
"port":1234,
"program": "${workspaceFolder}/a.out",
"args": [],
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"env": [],

}
]
}
---
 lldb/include/lldb/lldb-defines.h  |   1 +
 .../Python/lldbsuite/test/lldbtest.py |   9 ++
 .../test/tools/lldb-dap/dap_server.py |   6 +
 .../test/tools/lldb-dap/lldbdap_testcase.py   |  20 +++
 .../attach/TestDAP_attachByPortNum.py | 120 ++
 lldb/tools/lldb-dap/lldb-dap.cpp  |  36 +-
 lldb/tools/lldb-dap/package.json  |  11 ++
 7 files changed, 199 insertions(+), 4 deletions(-)
 create mode 100644 
lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py

diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h
index c7bd019c5c90e..a1e6ee2ce468c 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -96,6 +96,7 @@
 #define LLDB_INVALID_QUEUE_ID 0
 #define LLDB_INVALID_CPU_ID UINT32_MAX
 #define LLDB_INVALID_WATCHPOINT_RESOURCE_ID UINT32_MAX
+#define LLDB_INVALID_PORT_NUMBER 0
 
 /// CPU Type definitions
 #define LLDB_ARCH_DEFAULT "systemArch"
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 5fd686c143e9f..fb3cd22959df2 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1572,6 +1572,15 @@ def findBuiltClang(self):
 
 return os.environ["CC"]
 
+def getBuiltServerTool(self, server_tool):
+# Tries to find simulation/lldb-server/gdbserver tool at the same 
folder as the lldb.
+lldb_dir = os.path.dirname(lldbtest_config.lldbExec)
+path = shutil.which(server_tool, path=lldb_dir)
+if path is not None:
+return path
+
+return ""
+
 def yaml2obj(self, yaml_path, obj_path, max_size=None):
 """
 Create an object file at the given path from a yaml file.
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 5838281bcb1a1..96d312565f953 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -568,6 +568,8 @@ def request_attach(
 coreFile=None,
 postRunCommands=None,
 sourceMap=None,
+port=None,
+hostname=None
 ):
 args_dict = {}
 if pid is not None:
@@ -597,6 +599,10 @@ def request_attach(
 args_dict["postRunCommands"] = postRunCo