[Lldb-commits] [lldb] [lldb] Move TestBase.runCmd() to the Base class (PR #92252)

2024-05-16 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][Windows] Fixed the TestIOHandlerResizeNoEditline test (PR #92286)

2024-05-16 Thread Pavel Labath via lldb-commits

labath wrote:

This probably means you can also remove the skipIfWindows decorator, as the 
test doesn't actually do anything target-specific.

(It also feels a bit like this is working around something -- I don't see why 
not closing a file should cause anything to crash -- but that's probably fine 
since the test is about terminal resizing.)

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


[Lldb-commits] [lldb] [lldb][Windows] Disable the TestGdbRemoteLibrariesSvr4Support test for Windows host (PR #92341)

2024-05-16 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Fixed an invalid error message in the DAP disconnect response (PR #92345)

2024-05-16 Thread Pavel Labath via lldb-commits


@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
 g_dap.debugger.SetAsync(false);
 lldb::SBError error = terminateDebuggee ? process.Kill() : 
process.Detach();
 if (!error.Success())
-  response.try_emplace("error", error.GetCString());
+  response.try_emplace("error", std::string(error.GetCString()));

labath wrote:

`EmplaceSafeString` sounds like the right thing to use here.

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


[Lldb-commits] [lldb] [lldb][Windows] Disable the TestGdbRemoteLibrariesSvr4Support test for Windows host (PR #92341)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] 2bc9af9 - [lldb][Windows] Disable the TestGdbRemoteLibrariesSvr4Support test for Windows host (#92341)

2024-05-16 Thread via lldb-commits

Author: Dmitry Vasilyev
Date: 2024-05-16T16:49:56+04:00
New Revision: 2bc9af96567eeda1effdf0cb7662511d896fb386

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

LOG: [lldb][Windows] Disable the TestGdbRemoteLibrariesSvr4Support test for 
Windows host (#92341)

Windows does not allow quotes in file names. So it is impossible to
build `libsvr4lib_b".so` on Windows.

Added: 


Modified: 

lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
 
b/lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
index 846adade34402..02c9d318525fb 100644
--- 
a/lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
+++ 
b/lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
@@ -4,6 +4,8 @@
 from lldbsuite.test.lldbtest import *
 
 
+# Windows does not allow quotes in file names.
+@skipIf(hostoslist=["windows"])
 class 
TestGdbRemoteLibrariesSvr4Support(gdbremote_testcase.GdbRemoteTestCaseBase):
 FEATURE_NAME = "qXfer:libraries-svr4:read"
 



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


[Lldb-commits] [lldb] 44eded3 - [lldb] Move TestBase.runCmd() to the Base class (#92252)

2024-05-16 Thread via lldb-commits

Author: Dmitry Vasilyev
Date: 2024-05-16T16:55:06+04:00
New Revision: 44eded31e0bd5739391298497affe3412e4091aa

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

LOG: [lldb] Move TestBase.runCmd() to the Base class (#92252)

runCmd() is called from Base.getCPUInfo() but implemented only in
TestBase(Base). Usually it works if TestBase is used. But call
getCPUInfo() from a class based on Base will cause something like
```
File 
"E:\projects\llvm-nino\lldb\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py",
 line 1256, in getCPUInfo
  self.runCmd('platform get-file "/proc/cpuinfo" ' + cpuinfo_path)
AttributeError: 'TestGdbRemoteExpeditedRegisters' object has no attribute 
'runCmd'
```
BTW, TestBase.setUp() called runCmd() before applying
LLDB_MAX_LAUNCH_COUNT and LLDB_TIME_WAIT_NEXT_LAUNCH.

This patch fixes the test TestGdbRemoteExpeditedRegisters in case of
Windows host and Linux target.

Added: 


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

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 5fd686c143e9f..1ad8ab6e6e462 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -531,6 +531,14 @@ class Base(unittest.TestCase):
 # Keep track of the old current working directory.
 oldcwd = None
 
+# Maximum allowed attempts when launching the inferior process.
+# Can be overridden by the LLDB_MAX_LAUNCH_COUNT environment variable.
+maxLaunchCount = 1
+
+# Time to wait before the next launching attempt in second(s).
+# Can be overridden by the LLDB_TIME_WAIT_NEXT_LAUNCH environment variable.
+timeWaitNextLaunch = 1.0
+
 @staticmethod
 def compute_mydir(test_file):
 """Subclasses should call this function to correctly calculate the
@@ -796,6 +804,12 @@ def setUp(self):
 # import traceback
 # traceback.print_stack()
 
+if "LLDB_MAX_LAUNCH_COUNT" in os.environ:
+self.maxLaunchCount = int(os.environ["LLDB_MAX_LAUNCH_COUNT"])
+
+if "LLDB_TIME_WAIT_NEXT_LAUNCH" in os.environ:
+self.timeWaitNextLaunch = 
float(os.environ["LLDB_TIME_WAIT_NEXT_LAUNCH"])
+
 if "LIBCXX_PATH" in os.environ:
 self.libcxxPath = os.environ["LIBCXX_PATH"]
 else:
@@ -937,6 +951,57 @@ def spawnSubprocess(self, executable, args=[], 
extra_env=None, install_remote=Tr
 self.subprocesses.append(proc)
 return proc
 
+def runCmd(self, cmd, msg=None, check=True, trace=False, inHistory=False):
+"""
+Ask the command interpreter to handle the command and then check its
+return status.
+"""
+# Fail fast if 'cmd' is not meaningful.
+if cmd is None:
+raise Exception("Bad 'cmd' parameter encountered")
+
+trace = True if traceAlways else trace
+
+if cmd.startswith("target create "):
+cmd = cmd.replace("target create ", "file ")
+
+running = cmd.startswith("run") or cmd.startswith("process launch")
+
+for i in range(self.maxLaunchCount if running else 1):
+with recording(self, trace) as sbuf:
+print("runCmd:", cmd, file=sbuf)
+if not check:
+print("check of return status not required", file=sbuf)
+
+self.ci.HandleCommand(cmd, self.res, inHistory)
+
+with recording(self, trace) as sbuf:
+if self.res.Succeeded():
+print("output:", self.res.GetOutput(), file=sbuf)
+else:
+print("runCmd failed!", file=sbuf)
+print(self.res.GetError(), file=sbuf)
+
+if self.res.Succeeded():
+break
+elif running:
+# For process launch, wait some time before possible next try.
+time.sleep(self.timeWaitNextLaunch)
+with recording(self, trace) as sbuf:
+print("Command '" + cmd + "' failed!", file=sbuf)
+
+if check:
+output = ""
+if self.res.GetOutput():
+output += "\nCommand output:\n" + self.res.GetOutput()
+if self.res.GetError():
+output += "\nError output:\n" + self.res.GetError()
+if msg:
+msg += output
+if cmd:
+cmd += output
+self.assertTrue(self.res.Succeeded(), msg if (msg) else 
CMD_MSG(cmd))
+
 def HideStdout(self):
 """Hide output to stdout from the user.
 
@@ -1764,14 +1829,6 @@ class TestBase(Base, metaclass=LLDBTestCaseFactory):
 # test multiple times with various debug info types.
 NO

[Lldb-commits] [lldb] [lldb] Move TestBase.runCmd() to the Base class (PR #92252)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fixed an invalid error message in the DAP disconnect response (PR #92345)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman updated 
https://github.com/llvm/llvm-project/pull/92345

>From 95336abaa000fa889888ce0f17af8098dfaeb8ea Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Thu, 16 May 2024 08:09:19 +0400
Subject: [PATCH 1/2] [lldb] Fixed an invalid error message in the DAP
 disconnect response

The `disconnect` response contains the `error` message with invalid characters 
(a junk data).
To reproduce this issue it is enough to run the TestDAP_commands test on 
Windows host and Linux target. The test will fail to run ELF file on Windows 
and dap_server will be disconnected unexpectedly.

Note dap_server hangs if read_packet() cannot decode JSON with invalid 
characters. read_packet() must return None in this case instead of an 
exception. But dap_server does not require any fix after this patch.
---
 lldb/tools/lldb-dap/lldb-dap.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 96da458be21d1..e9810f83678eb 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
 g_dap.debugger.SetAsync(false);
 lldb::SBError error = terminateDebuggee ? process.Kill() : 
process.Detach();
 if (!error.Success())
-  response.try_emplace("error", error.GetCString());
+  response.try_emplace("error", std::string(error.GetCString()));
 g_dap.debugger.SetAsync(true);
 break;
   }

>From 6528ad5c4e21f5cecaafb7a3b06285936e8dc1b3 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Thu, 16 May 2024 17:06:58 +0400
Subject: [PATCH 2/2] Replaced with EmplaceSafeString().

---
 lldb/tools/lldb-dap/lldb-dap.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e9810f83678eb..170fa88f1e8b8 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
 g_dap.debugger.SetAsync(false);
 lldb::SBError error = terminateDebuggee ? process.Kill() : 
process.Detach();
 if (!error.Success())
-  response.try_emplace("error", std::string(error.GetCString()));
+  EmplaceSafeString(response, "error", error.GetCString());
 g_dap.debugger.SetAsync(true);
 break;
   }

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


[Lldb-commits] [lldb] [lldb] Fixed an invalid error message in the DAP disconnect response (PR #92345)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits


@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
 g_dap.debugger.SetAsync(false);
 lldb::SBError error = terminateDebuggee ? process.Kill() : 
process.Detach();
 if (!error.Success())
-  response.try_emplace("error", error.GetCString());
+  response.try_emplace("error", std::string(error.GetCString()));

slydiman wrote:

I have updated the patch. Thanks.

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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92398)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman created 
https://github.com/llvm/llvm-project/pull/92398

These tests failed in case of Windows host and Linux target, because dap_server 
tried to run ELF file on Windows.

>From 74fd3f5b36c5a91a2269bff8261ba494ae6553cc Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Thu, 16 May 2024 17:23:08 +0400
Subject: [PATCH] [lldb] Fixed the DAP tests in case of a remote target

These tests failed in case of Windows host and Linux target, because dap_server 
tried to run ELF file on Windows.
---
 lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py   | 2 ++
 .../API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py | 1 +
 2 files changed, 3 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..bfdf9ef2897b2 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -7,6 +7,7 @@
 
 
 class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_command_directive_quiet_on_success(self):
 program = self.getBuildArtifact("a.out")
 command_quiet = (
@@ -60,6 +61,7 @@ def 
test_command_directive_abort_on_error_launch_commands(self):
 def test_command_directive_abort_on_error_pre_run_commands(self):
 self.do_test_abort_on_error(use_pre_run_commands=True)
 
+@skipIfRemote
 def test_command_directive_abort_on_error_post_run_commands(self):
 self.do_test_abort_on_error(use_post_run_commands=True)
 
diff --git 
a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py 
b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
index fd48e69cae5e2..7700c65f862dc 100644
--- a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
+++ b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
@@ -11,6 +11,7 @@
 
 
 class TestDAP_startDebugging(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_startDebugging(self):
 """
 Tests the "startDebugging" reverse request. It makes sure that the IDE 
can

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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92398)

2024-05-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)


Changes

These tests failed in case of Windows host and Linux target, because dap_server 
tried to run ELF file on Windows.

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


2 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py (+2) 
- (modified) 
lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py (+1) 


``diff
diff --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..bfdf9ef2897b2 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -7,6 +7,7 @@
 
 
 class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_command_directive_quiet_on_success(self):
 program = self.getBuildArtifact("a.out")
 command_quiet = (
@@ -60,6 +61,7 @@ def 
test_command_directive_abort_on_error_launch_commands(self):
 def test_command_directive_abort_on_error_pre_run_commands(self):
 self.do_test_abort_on_error(use_pre_run_commands=True)
 
+@skipIfRemote
 def test_command_directive_abort_on_error_post_run_commands(self):
 self.do_test_abort_on_error(use_post_run_commands=True)
 
diff --git 
a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py 
b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
index fd48e69cae5e2..7700c65f862dc 100644
--- a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
+++ b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
@@ -11,6 +11,7 @@
 
 
 class TestDAP_startDebugging(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_startDebugging(self):
 """
 Tests the "startDebugging" reverse request. It makes sure that the IDE 
can

``




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


[Lldb-commits] [lldb] [lldb] Fixed an invalid error message in the DAP disconnect response (PR #92345)

2024-05-16 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,102 @@
+//===-- SBAddressRange.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 "lldb/API/SBAddressRange.h"
+#include "Utils.h"
+#include "lldb/API/SBAddress.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/Stream.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBAddressRange::SBAddressRange()
+: m_opaque_up(std::make_unique()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBAddressRange::SBAddressRange(const SBAddressRange &rhs) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  m_opaque_up = clone(rhs.m_opaque_up);
+}
+
+SBAddressRange::SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size)
+: m_opaque_up(std::make_unique(addr.ref(), byte_size)) {
+  LLDB_INSTRUMENT_VA(this, addr, byte_size);
+}
+
+SBAddressRange::~SBAddressRange() = default;
+
+const SBAddressRange &SBAddressRange::operator=(const SBAddressRange &rhs) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (this != &rhs)
+m_opaque_up = clone(rhs.m_opaque_up);
+  return *this;
+}
+
+bool SBAddressRange::operator==(const SBAddressRange &rhs) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (!IsValid() || !rhs.IsValid())
+return false;
+  return m_opaque_up->operator==(*(rhs.m_opaque_up));
+}
+
+bool SBAddressRange::operator!=(const SBAddressRange &rhs) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  return !(*this == rhs);
+}
+
+void SBAddressRange::Clear() {
+  LLDB_INSTRUMENT_VA(this);
+
+  m_opaque_up.reset();
+}
+
+bool SBAddressRange::IsValid() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up && m_opaque_up->IsValid();
+}
+
+lldb::SBAddress SBAddressRange::GetBaseAddress() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!IsValid())
+return lldb::SBAddress();
+  return lldb::SBAddress(m_opaque_up->GetBaseAddress());
+}
+
+lldb::addr_t SBAddressRange::GetByteSize() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  if (!IsValid())
+return 0;
+  return m_opaque_up->GetByteSize();
+}
+
+bool SBAddressRange::GetDescription(SBStream &description) {
+  LLDB_INSTRUMENT_VA(this, description);
+
+  Stream &stream = description.ref();
+
+  if (!IsValid()) {
+stream << "Invalid address range";
+return true;
+  }
+  m_opaque_up->DumpDebug(&stream);

mbucko wrote:

>>> print(range)
0x562434ae16b0: AddressRange section = 0x56243482eb90, offset = 
0x0130, byte_size = 0x0039

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From dc84f8b94c2500b3c1caf2b0c053069989cfc082 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  66 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  59 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  17 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 189 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 685 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
obj

[Lldb-commits] [lldb] [lldb] Fixed an invalid error message in the DAP disconnect response (PR #92345)

2024-05-16 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92398)

2024-05-16 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From a169c0fd5bd599c8f4dc77555616a2bd5b967647 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  17 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 682 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
obj

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits


@@ -0,0 +1,139 @@
+//===-- SBAddressRangeList.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 "lldb/API/SBAddressRangeList.h"
+#include "Utils.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/Core/AddressRange.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/Stream.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+class AddressRangeListImpl {
+public:
+  AddressRangeListImpl() : m_ranges() {}
+
+  AddressRangeListImpl(const AddressRangeListImpl &rhs) = default;
+
+  AddressRangeListImpl &operator=(const AddressRangeListImpl &rhs) {
+if (this == &rhs)
+  return *this;
+m_ranges = rhs.m_ranges;
+return *this;
+  }
+
+  size_t GetSize() const { return m_ranges.size(); }
+
+  void Reserve(size_t capacity) { m_ranges.reserve(capacity); }
+
+  void Append(const AddressRange &sb_region) {
+m_ranges.emplace_back(sb_region);
+  }
+
+  void Append(const AddressRangeListImpl &list) {
+Reserve(GetSize() + list.GetSize());
+
+for (const auto &range : list.m_ranges)
+  Append(range);
+  }
+
+  void Clear() { m_ranges.clear(); }
+
+  lldb_private::AddressRange GetAddressRangeAtIndex(size_t index) {
+if (index >= GetSize())
+  return AddressRange();
+return m_ranges[index];
+  }
+
+  AddressRanges &Ref() { return m_ranges; }
+
+private:
+  AddressRanges m_ranges;
+};
+
+SBAddressRangeList::SBAddressRangeList()
+: m_opaque_up(new AddressRangeListImpl()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBAddressRangeList::SBAddressRangeList(const SBAddressRangeList &rhs)
+: m_opaque_up(new AddressRangeListImpl(*rhs.m_opaque_up)) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+}
+
+SBAddressRangeList::~SBAddressRangeList() = default;
+
+const SBAddressRangeList &
+SBAddressRangeList::operator=(const SBAddressRangeList &rhs) {
+  LLDB_INSTRUMENT_VA(this, rhs);
+
+  if (this != &rhs)
+*m_opaque_up = *rhs.m_opaque_up;
+  return *this;
+}
+
+uint32_t SBAddressRangeList::GetSize() const {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up->GetSize();
+}
+
+SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
+  LLDB_INSTRUMENT_VA(this, idx);
+
+  SBAddressRange sb_addr_range;
+  (*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
+  return sb_addr_range;
+}
+
+void SBAddressRangeList::Clear() {
+  LLDB_INSTRUMENT_VA(this);
+
+  m_opaque_up->Clear();
+}
+
+void SBAddressRangeList::Append(const SBAddressRange &sb_addr_range) {
+  LLDB_INSTRUMENT_VA(this, sb_addr_range);
+
+  m_opaque_up->Append(*sb_addr_range.m_opaque_up);
+}
+
+void SBAddressRangeList::Append(const SBAddressRangeList &sb_addr_range_list) {
+  LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
+
+  m_opaque_up->Append(*sb_addr_range_list);
+}
+
+const AddressRangeListImpl *SBAddressRangeList::operator->() const {
+  return m_opaque_up.get();
+}
+
+const AddressRangeListImpl &SBAddressRangeList::operator*() const {
+  assert(m_opaque_up.get());
+  return *m_opaque_up;
+}
+
+AddressRanges &SBAddressRangeList::ref() { return m_opaque_up->Ref(); }
+
+bool SBAddressRangeList::GetDescription(SBStream &description) {
+  LLDB_INSTRUMENT_VA(this, description);
+
+  Stream &stream = description.ref();
+
+  const auto num_ranges = GetSize();
+  stream.Printf("%d address ranges:\n", num_ranges);
+  for (uint32_t i = 0; i < num_ranges; ++i) {
+stream << "";
+GetAddressRangeAtIndex(i).GetDescription(description);
+  }

mbucko wrote:

Which address would we print? There's the load address, file address and bunch 
of offsets

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


[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-05-16 Thread Walter Erquinigo via lldb-commits


@@ -0,0 +1,146 @@
+"""
+Test lldb-dap "port" configuration to "attach" request
+"""
+
+
+import dap_server
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbplatformutil
+import lldbgdbserverutils
+import lldbdap_testcase
+import os
+import shutil
+import subprocess
+import tempfile
+import threading
+import time
+import sys
+
+
+class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
+def runTargetProgramOnPort(self, port=None, program=None):
+server_tool = None
+if lldbplatformutil.getPlatform() == "linux":
+server_tool = lldbgdbserverutils.get_lldb_server_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "lldb-server not found.")
+server_tool += " g localhost:" + port + " "
+elif lldbplatformutil.getPlatform() == "macosx":
+server_tool = lldbgdbserverutils.get_debugserver_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "debugserver not found.")
+server_tool += " --listen localhost:" + port + " "
+
+self.process = subprocess.Popen(
+[server_tool + program],
+shell=True,
+stdin=subprocess.PIPE,
+stdout=subprocess.PIPE,
+stderr=subprocess.PIPE,
+)
+
+return self.process
+
+def set_and_hit_breakpoint(self, continueToExit=True):
+source = "main.c"
+main_source_path = os.path.join(os.getcwd(), source)
+breakpoint1_line = line_number(main_source_path, "// breakpoint 1")
+lines = [breakpoint1_line]
+# Set breakpoint in the thread function so we can step the threads
+breakpoint_ids = self.set_source_breakpoints(main_source_path, lines)
+self.assertEqual(
+len(breakpoint_ids), len(lines), "expect correct number of 
breakpoints"
+)
+self.continue_to_breakpoints(breakpoint_ids)
+if continueToExit:
+self.continue_to_exit()
+
+@skipIfWindows
+@skipIfNetBSD  # Hangs on NetBSD as well

walter-erquinigo wrote:

This "as well" looks weird. Did you test it there in fact?

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


[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-05-16 Thread Walter Erquinigo via lldb-commits


@@ -1572,6 +1572,15 @@ def findBuiltClang(self):
 
 return os.environ["CC"]
 
+def getBuiltinServerTool(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 ""

walter-erquinigo wrote:

return None instead of an empty string

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


[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-05-16 Thread Walter Erquinigo via lldb-commits


@@ -676,6 +676,8 @@ void request_attach(const llvm::json::Object &request) {
   auto arguments = request.getObject("arguments");
   const lldb::pid_t pid =
   GetUnsigned(arguments, "pid", LLDB_INVALID_PROCESS_ID);
+  const auto port = GetUnsigned(arguments, "port", LLDB_INVALID_PORT_NUMBER);
+  llvm::StringRef hostname = GetString(arguments, "hostname");

walter-erquinigo wrote:

you can here set the default to "localhost", which will simplify the logic below

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


[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-05-16 Thread Walter Erquinigo via lldb-commits


@@ -0,0 +1,146 @@
+"""
+Test lldb-dap "port" configuration to "attach" request
+"""
+
+
+import dap_server
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbplatformutil
+import lldbgdbserverutils
+import lldbdap_testcase
+import os
+import shutil
+import subprocess
+import tempfile
+import threading
+import time
+import sys
+
+
+class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
+def runTargetProgramOnPort(self, port=None, program=None):
+server_tool = None
+if lldbplatformutil.getPlatform() == "linux":
+server_tool = lldbgdbserverutils.get_lldb_server_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "lldb-server not found.")
+server_tool += " g localhost:" + port + " "
+elif lldbplatformutil.getPlatform() == "macosx":
+server_tool = lldbgdbserverutils.get_debugserver_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "debugserver not found.")
+server_tool += " --listen localhost:" + port + " "

walter-erquinigo wrote:

could you move the logic that finds automatically the path to lldb-server or 
debugserver to lldbdap_testcase? This logic seems to be useful to reuse



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


[Lldb-commits] [lldb] [lldb-dap] Added "port" property to vscode "attach" command. (PR #91570)

2024-05-16 Thread Walter Erquinigo via lldb-commits


@@ -0,0 +1,146 @@
+"""
+Test lldb-dap "port" configuration to "attach" request
+"""
+
+
+import dap_server
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbplatformutil
+import lldbgdbserverutils
+import lldbdap_testcase
+import os
+import shutil
+import subprocess
+import tempfile
+import threading
+import time
+import sys
+
+
+class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
+def runTargetProgramOnPort(self, port=None, program=None):
+server_tool = None
+if lldbplatformutil.getPlatform() == "linux":
+server_tool = lldbgdbserverutils.get_lldb_server_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "lldb-server not found.")
+server_tool += " g localhost:" + port + " "
+elif lldbplatformutil.getPlatform() == "macosx":
+server_tool = lldbgdbserverutils.get_debugserver_exe()
+if server_tool is None:
+self.dap_server.request_disconnect(terminateDebuggee=True)
+self.assertIsNotNone(server_tool, "debugserver not found.")
+server_tool += " --listen localhost:" + port + " "
+
+self.process = subprocess.Popen(
+[server_tool + program],
+shell=True,
+stdin=subprocess.PIPE,
+stdout=subprocess.PIPE,
+stderr=subprocess.PIPE,
+)
+
+return self.process
+
+def set_and_hit_breakpoint(self, continueToExit=True):
+source = "main.c"
+main_source_path = os.path.join(os.getcwd(), source)
+breakpoint1_line = line_number(main_source_path, "// breakpoint 1")
+lines = [breakpoint1_line]
+# Set breakpoint in the thread function so we can step the threads
+breakpoint_ids = self.set_source_breakpoints(main_source_path, lines)
+self.assertEqual(
+len(breakpoint_ids), len(lines), "expect correct number of 
breakpoints"
+)
+self.continue_to_breakpoints(breakpoint_ids)
+if continueToExit:
+self.continue_to_exit()
+
+@skipIfWindows
+@skipIfNetBSD  # Hangs on NetBSD as well
+@skipIfRemote
+def test_by_port(self):
+"""
+Tests attaching to a process by port.
+"""
+self.build_and_create_debug_adaptor()
+program = self.getBuildArtifact("a.out")
+
+port = "2345"
+self.process = self.runTargetProgramOnPort(port=port, program=program)
+pid = self.process.pid
+response = self.attach(program=program, port=int(port), 
sourceInitFile=True)
+self.set_and_hit_breakpoint(continueToExit=True)
+self.process.kill()
+
+@skipIfWindows
+@skipIfNetBSD  # Hangs on NetBSD as well
+@skipIfRemote
+def test_by_port_and_pid(self):
+"""
+Tests attaching to a process by process ID and port number.
+"""
+self.build_and_create_debug_adaptor()
+program = self.getBuildArtifact("a.out")
+
+port = "2345"

walter-erquinigo wrote:

use a different port for each test, just in case the test runner executes them 
simultaneously

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 18c711d13a82a1c2559700c6b23d9300b0e5275b Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 681 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
obj

[Lldb-commits] [lldb] f579dcf - [lldb] Fixed an invalid error message in the DAP disconnect response (#92345)

2024-05-16 Thread via lldb-commits

Author: Dmitry Vasilyev
Date: 2024-05-16T18:34:22+04:00
New Revision: f579dcf816b5626724e9eae5feea594008b5c863

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

LOG: [lldb] Fixed an invalid error message in the DAP disconnect response 
(#92345)

The `disconnect` response contains the `error` message with invalid
characters (a junk data). To reproduce this issue it is enough to run
the `TestDAP_commands` test on Windows host and Linux target. The test
will fail to run ELF file on Windows and dap_server will be disconnected
unexpectedly.

Note dap_server hangs if read_packet() cannot decode JSON with invalid
characters. read_packet() must return None in this case instead of an
exception. But dap_server does not require any fix after this patch.

Added: 


Modified: 
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/tools/lldb-dap/lldb-dap.cpp 
b/lldb/tools/lldb-dap/lldb-dap.cpp
index 96da458be21d1..170fa88f1e8b8 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -977,7 +977,7 @@ void request_disconnect(const llvm::json::Object &request) {
 g_dap.debugger.SetAsync(false);
 lldb::SBError error = terminateDebuggee ? process.Kill() : 
process.Detach();
 if (!error.Success())
-  response.try_emplace("error", error.GetCString());
+  EmplaceSafeString(response, "error", error.GetCString());
 g_dap.debugger.SetAsync(true);
 break;
   }



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


[Lldb-commits] [lldb] [lldb] Fixed an invalid error message in the DAP disconnect response (PR #92345)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] d665d51 - [lldb] Fixed the DAP tests in case of a remote target (#92398)

2024-05-16 Thread via lldb-commits

Author: Dmitry Vasilyev
Date: 2024-05-16T18:34:58+04:00
New Revision: d665d51c9296fc0b57945bb67e06040e26cd03c5

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

LOG: [lldb] Fixed the DAP tests in case of a remote target (#92398)

These tests failed in case of Windows host and Linux target, because
dap_server tried to run ELF file on Windows.

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..bfdf9ef2897b2 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -7,6 +7,7 @@
 
 
 class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_command_directive_quiet_on_success(self):
 program = self.getBuildArtifact("a.out")
 command_quiet = (
@@ -60,6 +61,7 @@ def 
test_command_directive_abort_on_error_launch_commands(self):
 def test_command_directive_abort_on_error_pre_run_commands(self):
 self.do_test_abort_on_error(use_pre_run_commands=True)
 
+@skipIfRemote
 def test_command_directive_abort_on_error_post_run_commands(self):
 self.do_test_abort_on_error(use_post_run_commands=True)
 

diff  --git 
a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py 
b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
index fd48e69cae5e2..7700c65f862dc 100644
--- a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
+++ b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
@@ -11,6 +11,7 @@
 
 
 class TestDAP_startDebugging(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_startDebugging(self):
 """
 Tests the "startDebugging" reverse request. It makes sure that the IDE 
can



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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92398)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] d665d51 - [lldb] Fixed the DAP tests in case of a remote target (#92398)

2024-05-16 Thread via lldb-commits

Author: Dmitry Vasilyev
Date: 2024-05-16T18:34:58+04:00
New Revision: d665d51c9296fc0b57945bb67e06040e26cd03c5

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

LOG: [lldb] Fixed the DAP tests in case of a remote target (#92398)

These tests failed in case of Windows host and Linux target, because
dap_server tried to run ELF file on Windows.

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py 
b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
index 226b9385fe719..bfdf9ef2897b2 100644
--- a/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
+++ b/lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py
@@ -7,6 +7,7 @@
 
 
 class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_command_directive_quiet_on_success(self):
 program = self.getBuildArtifact("a.out")
 command_quiet = (
@@ -60,6 +61,7 @@ def 
test_command_directive_abort_on_error_launch_commands(self):
 def test_command_directive_abort_on_error_pre_run_commands(self):
 self.do_test_abort_on_error(use_pre_run_commands=True)
 
+@skipIfRemote
 def test_command_directive_abort_on_error_post_run_commands(self):
 self.do_test_abort_on_error(use_post_run_commands=True)
 

diff  --git 
a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py 
b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
index fd48e69cae5e2..7700c65f862dc 100644
--- a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
+++ b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
@@ -11,6 +11,7 @@
 
 
 class TestDAP_startDebugging(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 def test_startDebugging(self):
 """
 Tests the "startDebugging" reverse request. It makes sure that the IDE 
can



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


[Lldb-commits] [lldb] [lldb] Fixed the test TestGdbRemoteAttachWait running on a remote target (PR #92413)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman created 
https://github.com/llvm/llvm-project/pull/92413

Install `_exe_to_attach` to a remote target if necessary.

>From d88cc6d992e1f753066aa5dccaa510d8a0a35b94 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Thu, 16 May 2024 19:18:21 +0400
Subject: [PATCH] [lldb] Fixed the test TestGdbRemoteAttachWait running on a
 remote target

Install `_exe_to_attach` to a remote target if necessary.
---
 .../lldb-server/attach-wait/TestGdbRemoteAttachWait.py   | 9 +
 1 file changed, 9 insertions(+)

diff --git 
a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py 
b/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
index f4c31fe2f5c07..a8333210a72b1 100644
--- a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
+++ b/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
@@ -52,6 +52,9 @@ def test_attach_with_vAttachWait(self):
 server = self.connect_to_debug_monitor()
 self.do_handshake()
 
+if self._run_args:
+self._run_args[0] = lldbutil.install_to_target(self, 
self._run_args[0])
+
 # Launch the first inferior (we shouldn't attach to this one).
 self._launch_and_wait_for_init()
 
@@ -101,6 +104,9 @@ def test_launch_before_attach_with_vAttachOrWait(self):
 server = self.connect_to_debug_monitor()
 self.do_handshake()
 
+if self._run_args:
+self._run_args[0] = lldbutil.install_to_target(self, 
self._run_args[0])
+
 inferior = self._launch_and_wait_for_init()
 
 # Add attach packets.
@@ -141,6 +147,9 @@ def test_launch_after_attach_with_vAttachOrWait(self):
 server = self.connect_to_debug_monitor()
 self.do_handshake()
 
+if self._run_args:
+self._run_args[0] = lldbutil.install_to_target(self, 
self._run_args[0])
+
 
self.test_sequence.add_log_lines([self._attach_packet("vAttachOrWait")], True)
 # Run the stream until attachWait.
 context = self.expect_gdbremote_sequence()

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


[Lldb-commits] [lldb] [lldb] Fixed the test TestGdbRemoteAttachWait running on a remote target (PR #92413)

2024-05-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)


Changes

Install `_exe_to_attach` to a remote target if necessary.

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


1 Files Affected:

- (modified) 
lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py (+9) 


``diff
diff --git 
a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py 
b/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
index f4c31fe2f5c07..a8333210a72b1 100644
--- a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
+++ b/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
@@ -52,6 +52,9 @@ def test_attach_with_vAttachWait(self):
 server = self.connect_to_debug_monitor()
 self.do_handshake()
 
+if self._run_args:
+self._run_args[0] = lldbutil.install_to_target(self, 
self._run_args[0])
+
 # Launch the first inferior (we shouldn't attach to this one).
 self._launch_and_wait_for_init()
 
@@ -101,6 +104,9 @@ def test_launch_before_attach_with_vAttachOrWait(self):
 server = self.connect_to_debug_monitor()
 self.do_handshake()
 
+if self._run_args:
+self._run_args[0] = lldbutil.install_to_target(self, 
self._run_args[0])
+
 inferior = self._launch_and_wait_for_init()
 
 # Add attach packets.
@@ -141,6 +147,9 @@ def test_launch_after_attach_with_vAttachOrWait(self):
 server = self.connect_to_debug_monitor()
 self.do_handshake()
 
+if self._run_args:
+self._run_args[0] = lldbutil.install_to_target(self, 
self._run_args[0])
+
 
self.test_sequence.add_log_lines([self._attach_packet("vAttachOrWait")], True)
 # Run the stream until attachWait.
 context = self.expect_gdbremote_sequence()

``




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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92416)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman created 
https://github.com/llvm/llvm-project/pull/92416

These tests are based on dap_server which runs locally. These tests failed in 
case of Windows host and Linux target.

>From 1760995804d1a37e144fc778fcda7de23903e337 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Thu, 16 May 2024 19:42:17 +0400
Subject: [PATCH] [lldb] Fixed the DAP tests in case of a remote target

These tests are based on dap_server which runs locally. These tests failed in 
case of Windows host and Linux target.
---
 lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py | 1 +
 lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py 
b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
index 2b3ec656c107a..3250a5093cac4 100644
--- a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
+++ b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
@@ -19,6 +19,7 @@ def verify_completions(self, actual_list, expected_list, 
not_expected_list=[]):
 self.assertNotIn(not_expected_item, actual_list)
 
 @skipIfWindows
+@skipIfRemote
 @skipIf(compiler="clang", compiler_version=["<", "17.0"])
 def test_completions(self):
 """
diff --git a/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py 
b/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
index 8c2c0154ba65c..58a67d8164368 100644
--- a/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
+++ b/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
@@ -9,6 +9,7 @@
 
 
 class TestDAP_exception(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 @skipIfWindows
 def test_stopped_description(self):
 """

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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92416)

2024-05-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)


Changes

These tests are based on dap_server which runs locally. These tests failed in 
case of Windows host and Linux target.

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


2 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py 
(+1) 
- (modified) lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py (+1) 


``diff
diff --git a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py 
b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
index 2b3ec656c107a..3250a5093cac4 100644
--- a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
+++ b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
@@ -19,6 +19,7 @@ def verify_completions(self, actual_list, expected_list, 
not_expected_list=[]):
 self.assertNotIn(not_expected_item, actual_list)
 
 @skipIfWindows
+@skipIfRemote
 @skipIf(compiler="clang", compiler_version=["<", "17.0"])
 def test_completions(self):
 """
diff --git a/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py 
b/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
index 8c2c0154ba65c..58a67d8164368 100644
--- a/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
+++ b/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
@@ -9,6 +9,7 @@
 
 
 class TestDAP_exception(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 @skipIfWindows
 def test_stopped_description(self):
 """

``




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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread via lldb-commits


@@ -247,13 +247,13 @@ class SBCommandInterpreter {
lldb::SBStringList &matches,
lldb::SBStringList &descriptions);
 
-  /// Returns whether an interrupt flag was raised either by the SBDebugger - 
+  /// Returns whether an interrupt flag was raised either by the SBDebugger -
   /// when the function is not running on the RunCommandInterpreter thread, or
   /// by SBCommandInterpreter::InterruptCommand if it is.  If your code is 
doing
-  /// interruptible work, check this API periodically, and interrupt if it 
+  /// interruptible work, check this API periodically, and interrupt if it
   /// returns true.
   bool WasInterrupted() const;
-  
+

royitaqi wrote:

I was wondering how to only format the lines I touched. Thanks for the advice.

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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread via lldb-commits


@@ -135,7 +136,8 @@ CommandInterpreter::CommandInterpreter(Debugger &debugger,
   m_skip_lldbinit_files(false), m_skip_app_init_files(false),
   m_comment_char('#'), m_batch_command_mode(false),
   m_truncation_warning(eNoOmission), m_max_depth_warning(eNoOmission),
-  m_command_source_depth(0) {
+  m_command_source_depth(0),
+  m_transcript(std::make_shared()) {

royitaqi wrote:

Doesn't the default ctor create an empty shared pointer? Here what we want is 
to create the object, thus `make_shared`.

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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread via lldb-commits


@@ -1891,6 +1893,12 @@ bool CommandInterpreter::HandleCommand(const char 
*command_line,
 
   m_transcript_stream << "(lldb) " << command_line << '\n';
 
+  // The same `transcript_item` will be used below to add output and error of
+  // the command.
+  auto transcript_item = std::make_shared();

royitaqi wrote:

Two reasons for using the `shared_ptr`:
1. `m_transcript` holds a `shared_ptr` anyways. The 
`m_transcript->AddItem(transcript_item)` call below this line also requires a 
`shared_ptr`.
2. Many lines below this line, the `transcript_item` is used again in order to 
add the command's output and error.

If we use `unique_ptr` instead, then the code will look like:
```
  auto transcript_item = std::make_unique();
  transcript_item->AddStringItem("command", command_line);
  m_transcript->AddItem(std::move(transcript_item));

  ...

  auto last_transcript_item = m_transcript.last();
  last_transcript_item->AddStringItem("output", result.GetOutputData());
  last_transcript_item->AddStringItem("error", result.GetErrorData());
```

I feel the last part is weird (i.e. first creating `transcript_item` and move 
into `m_transcript`, then getting it again from `m_transcript`). I feel a 
`shared_ptr` is more readable and performant (since `m_transcript` holds a 
`shared_ptr` anyways, rather than adding then getting).

WDYT?

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Zequan Wu via lldb-commits

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits


@@ -44,6 +45,8 @@ class LLDB_API SBFunction {
 
   lldb::SBAddress GetEndAddress();
 
+  lldb::SBAddressRange GetRange();
+

mbucko wrote:

Or did you want me to return SBAddressRangeList which will always contain only 
one SBAddressRange unless SBFunction ever changes?

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


[Lldb-commits] [lldb] [lldb-dap] Separate user and developer documentation (PR #92428)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/92428

The README.md is what users see when they look for the extension in the 
Marketplace [1]. Right now, it's a mix of developer documentation (for us) and 
user documentation. This commit moves the developer docs into `docs` and the 
lldb website and refocuses the README on using the extension.

[1] 
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap

>From 729a9699cce518790e4077e41f659eff505cdc6e Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 16 May 2024 09:44:57 -0700
Subject: [PATCH] [lldb-dap] Separate user and developer documentation

The README.md is what users see when they look for the extension in the
Marketplace [1]. Right now, it's a mix of developer documentation (for us)
and user documentation. This commit moves the developer docs into `docs`
and the lldb website and refocuses the README on using the extension.

[1] 
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap
---
 lldb/docs/index.rst|   1 +
 lldb/docs/resources/lldbdap.md |  97 
 lldb/tools/lldb-dap/README.md  | 156 +
 3 files changed, 119 insertions(+), 135 deletions(-)
 create mode 100644 lldb/docs/resources/lldbdap.md

diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 7a27f6914fa89..1e7d69002dd3e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -161,6 +161,7 @@ interesting areas to contribute to lldb.
resources/lldbplatformpackets
resources/caveats
resources/projects
+   resources/lldbdap
Public C++ API 
Private C++ API 
 
diff --git a/lldb/docs/resources/lldbdap.md b/lldb/docs/resources/lldbdap.md
new file mode 100644
index 0..6c2252d77e55c
--- /dev/null
+++ b/lldb/docs/resources/lldbdap.md
@@ -0,0 +1,97 @@
+# LLDB-DAP
+
+The `lldb-dap` tool (formerly `lldb-vscode`) creates a command line tool that
+implements the [Debug Adapter
+Protocol](https://microsoft.github.io/debug-adapter-protocol/). It can be
+installed as an extension for Visual Studio Code and other IDEs supporting DAP.
+The protocol is easy to run remotely and also can allow other tools and IDEs to
+get a full featured debugger with a well defined protocol.
+
+## Local Installation for Visual Studio Code
+
+Installing the plug-in is very straightforward and involves just a few steps.
+
+### Pre-requisites
+
+- Install a modern version of node (e.g. `v20.0.0`).
+- On VS Code, execute the command `Install 'code' command in PATH`. You need to
+  do it only once. This enables the command `code` in the PATH.
+
+### Packaging and installation
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package # This also compiles the extension.
+npm run vscode-install
+```
+
+On VS Code, set the setting `lldb-dap.executable-path` to the path of your 
local
+build of `lldb-dap`.
+
+And then you are ready!
+
+### Updating the extension
+
+*Note: It's not necessary to update the extension if there has been changes
+to  `lldb-dap`. The extension needs to be updated only if the TypesScript code
+has changed.*
+
+Updating the extension is pretty much the same process as installing it from
+scratch. However, VS Code expects the version number of the upgraded extension
+to be greater than the previous one, otherwise the installation step might have
+no effect.
+
+```bash
+# Bump version in package.json
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package
+npm run vscode-install
+```
+
+Another way upgrade without bumping the extension version is to first uninstall
+the extension, then reload VS Code, and then install it again. This is
+an unfortunate limitation of the editor.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm run vscode-uninstall
+# Then reload VS Code: reopen the IDE or execute the `Developer: Reload Window`
+# command.
+npm run package
+npm run vscode-install
+```
+
+### Deploying for Visual Studio Code
+
+The easiest way to deploy the extension for execution on other machines 
requires
+copying `lldb-dap` and its dependencies into a`./bin` subfolder and then 
create a
+standalone VSIX package.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+mkdir -p ./bin
+cp /path/to/a/built/lldb-dap ./bin/
+cp /path/to/a/built/liblldb.so ./bin/
+npm run package
+```
+
+This will produce the file `./out/lldb-dap.vsix` that can be distributed. In
+this type of installation, users don't need to manually set the path to
+`lldb-dap`. The extension will automatically look for it in the `./bin`
+subfolder.
+
+*Note: It's not possible to use symlinks to `lldb-dap`, as the packaging tool
+forcefully performs a deep copy of all symlinks.*
+
+*Note: It's possible to use this kind flow for local installations, but it's
+not recommended because updating `lldb-dap` requires rebuilding the exten

[Lldb-commits] [lldb] [lldb-dap] Separate user and developer documentation (PR #92428)

2024-05-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

The README.md is what users see when they look for the extension in the 
Marketplace [1]. Right now, it's a mix of developer documentation (for us) and 
user documentation. This commit moves the developer docs into `docs` and the 
lldb website and refocuses the README on using the extension.

[1] 
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap

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


3 Files Affected:

- (modified) lldb/docs/index.rst (+1) 
- (added) lldb/docs/resources/lldbdap.md (+97) 
- (modified) lldb/tools/lldb-dap/README.md (+21-135) 


``diff
diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 7a27f6914fa89..1e7d69002dd3e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -161,6 +161,7 @@ interesting areas to contribute to lldb.
resources/lldbplatformpackets
resources/caveats
resources/projects
+   resources/lldbdap
Public C++ API 
Private C++ API 
 
diff --git a/lldb/docs/resources/lldbdap.md b/lldb/docs/resources/lldbdap.md
new file mode 100644
index 0..6c2252d77e55c
--- /dev/null
+++ b/lldb/docs/resources/lldbdap.md
@@ -0,0 +1,97 @@
+# LLDB-DAP
+
+The `lldb-dap` tool (formerly `lldb-vscode`) creates a command line tool that
+implements the [Debug Adapter
+Protocol](https://microsoft.github.io/debug-adapter-protocol/). It can be
+installed as an extension for Visual Studio Code and other IDEs supporting DAP.
+The protocol is easy to run remotely and also can allow other tools and IDEs to
+get a full featured debugger with a well defined protocol.
+
+## Local Installation for Visual Studio Code
+
+Installing the plug-in is very straightforward and involves just a few steps.
+
+### Pre-requisites
+
+- Install a modern version of node (e.g. `v20.0.0`).
+- On VS Code, execute the command `Install 'code' command in PATH`. You need to
+  do it only once. This enables the command `code` in the PATH.
+
+### Packaging and installation
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package # This also compiles the extension.
+npm run vscode-install
+```
+
+On VS Code, set the setting `lldb-dap.executable-path` to the path of your 
local
+build of `lldb-dap`.
+
+And then you are ready!
+
+### Updating the extension
+
+*Note: It's not necessary to update the extension if there has been changes
+to  `lldb-dap`. The extension needs to be updated only if the TypesScript code
+has changed.*
+
+Updating the extension is pretty much the same process as installing it from
+scratch. However, VS Code expects the version number of the upgraded extension
+to be greater than the previous one, otherwise the installation step might have
+no effect.
+
+```bash
+# Bump version in package.json
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package
+npm run vscode-install
+```
+
+Another way upgrade without bumping the extension version is to first uninstall
+the extension, then reload VS Code, and then install it again. This is
+an unfortunate limitation of the editor.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm run vscode-uninstall
+# Then reload VS Code: reopen the IDE or execute the `Developer: Reload Window`
+# command.
+npm run package
+npm run vscode-install
+```
+
+### Deploying for Visual Studio Code
+
+The easiest way to deploy the extension for execution on other machines 
requires
+copying `lldb-dap` and its dependencies into a`./bin` subfolder and then 
create a
+standalone VSIX package.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+mkdir -p ./bin
+cp /path/to/a/built/lldb-dap ./bin/
+cp /path/to/a/built/liblldb.so ./bin/
+npm run package
+```
+
+This will produce the file `./out/lldb-dap.vsix` that can be distributed. In
+this type of installation, users don't need to manually set the path to
+`lldb-dap`. The extension will automatically look for it in the `./bin`
+subfolder.
+
+*Note: It's not possible to use symlinks to `lldb-dap`, as the packaging tool
+forcefully performs a deep copy of all symlinks.*
+
+*Note: It's possible to use this kind flow for local installations, but it's
+not recommended because updating `lldb-dap` requires rebuilding the extension.*
+
+## Formatting the Typescript code
+
+This is also very simple, just run:
+
+```bash
+npm run format
+```
diff --git a/lldb/tools/lldb-dap/README.md b/lldb/tools/lldb-dap/README.md
index 16ce4672be71c..8ecbaf7ce9816 100644
--- a/lldb/tools/lldb-dap/README.md
+++ b/lldb/tools/lldb-dap/README.md
@@ -1,133 +1,19 @@
+# LLDB DAP
 
-# Table of Contents
-
-- [Table of Contents](#table-of-contents)
-- [Introduction](#introduction)
-- [Local Installation for Visual Studio 
Code](#local-installation-for-visual-studio-code)
-  - [Pre-requisites](#pre-requisites)
-  - [Packaging and installation](#packaging-a

[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92416)

2024-05-16 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


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


[Lldb-commits] [lldb] bd6c358 - [lldb-dap] Update repository in package.json

2024-05-16 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2024-05-16T09:54:47-07:00
New Revision: bd6c358d01f6ebc3851996e2c29c47b08e992525

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

LOG: [lldb-dap] Update repository in package.json

Use https://github.com/llvm/vscode-lldb instead of the monorepo, for
consistency with the other two extensions (mlir, clangd).

Added: 


Modified: 
lldb/tools/lldb-dap/package.json

Removed: 




diff  --git a/lldb/tools/lldb-dap/package.json 
b/lldb/tools/lldb-dap/package.json
index aeb24445551c1..45fcb83cf81d8 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -8,7 +8,7 @@
   "license": "Apache 2.0 License with LLVM exceptions",
   "repository": {
 "type": "git",
-"url": "https://github.com/llvm/llvm-project.git";
+"url": "https://github.com/llvm/vscode-lldb.git";
   },
   "bugs": {
 "url": "https://github.com/llvm/llvm-project/issues";



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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -571,6 +571,15 @@ SBStructuredData SBCommandInterpreter::GetStatistics() {
   return data;
 }
 
+SBStructuredData SBCommandInterpreter::GetTranscript() {
+  LLDB_INSTRUMENT_VA(this);
+
+  SBStructuredData data;
+  if (IsValid())
+data.m_impl_up->SetObjectSP(m_opaque_ptr->GetTranscript());

clayborg wrote:

Here don't want to hand out a shared pointer to the internal transcript. If we 
do and the caller starts accessing it, we can crash if new commands are added 
to the structured data. If we to not copy things, one thing we could do it to 
grab the transript shared pointer from the command interpreter and have it 
create a new one.

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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -766,6 +768,12 @@ class CommandInterpreter : public Broadcaster,
   CommandUsageMap m_command_usages;
 
   StreamString m_transcript_stream;
+
+  /// Contains a list of handled commands, output and error. Each element in
+  /// the list is a dictionary with three keys: "command" (string), "output"
+  /// (list of strings) and optionally "error" (list of strings). Each string
+  /// in "output" and "error" is a line (without EOL characters).
+  StructuredData::ArraySP m_transcript;

clayborg wrote:

This shouldn't be a shared pointer, we don't want to hand out references to 
this structured data across the API boundary because it can be accessed by the 
caller and also be updated by new commands coming in. This should be a 
`StructuredData::Array` object and we should copy it when we hand it out across 
the API boundary.

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


[Lldb-commits] [lldb] [lldb-dap] Separate user and developer documentation (PR #92428)

2024-05-16 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.

beautiful

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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -766,6 +768,12 @@ class CommandInterpreter : public Broadcaster,
   CommandUsageMap m_command_usages;
 
   StreamString m_transcript_stream;
+
+  /// Contains a list of handled commands, output and error. Each element in
+  /// the list is a dictionary with three keys: "command" (string), "output"
+  /// (list of strings) and optionally "error" (list of strings). Each string
+  /// in "output" and "error" is a line (without EOL characters).
+  StructuredData::ArraySP m_transcript;

clayborg wrote:

Or we can leave this as a shared pointer and when  people call GetTranscript() 
on this object we give away our copy and start a new one.

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


[Lldb-commits] [lldb] Add new Python API `SBCommandInterpreter::GetTranscript()` (PR #90703)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -766,6 +768,12 @@ class CommandInterpreter : public Broadcaster,
   CommandUsageMap m_command_usages;
 
   StreamString m_transcript_stream;
+
+  /// Contains a list of handled commands, output and error. Each element in
+  /// the list is a dictionary with three keys: "command" (string), "output"
+  /// (list of strings) and optionally "error" (list of strings). Each string
+  /// in "output" and "error" is a line (without EOL characters).
+  StructuredData::ArraySP m_transcript;

clayborg wrote:

Not sure if this would make sense to the user though...

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Michael Buch via lldb-commits


@@ -2306,6 +2345,11 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const 
DWARFDIE &die,
 
   if (!die)
 return false;
+  ParsedDWARFTypeAttributes attrs(die);

Michael137 wrote:

I've been wondering how expensive constructing this object is. On a brief 
glance it seems to be doing a lot of work, but maybe all of that work is 
actually not that slow? Do you know why we get here for forward declarations 
with your patch, but didn't before?

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Michael Buch via lldb-commits


@@ -321,6 +326,10 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
   std::vector m_func_indexes; // Sorted by address
   std::vector m_glob_indexes;
   std::map>, OSOInfoSP> 
m_oso_map;
+  // A map from CompilerType to the struct/class/union/enum DIE (might be a
+  // declaration or a definition) that is used to construct it.
+  llvm::DenseMap
+  m_forward_decl_compiler_type_to_die;

Michael137 wrote:

Could you elaborate on why this wasn't necessary before? We're now mixing 
CompilerType's (which originate from different ASTContext's) in the same map, 
which might not be a problem, since we do this for `UniqueDWARFASTTypeMap` 
already, whose `Type`s can also originate from different context's.

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fixed unresolved test lldb-api python_api/debugger/TestDebuggerAPI.py on x86_64 host (PR #90580)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman updated 
https://github.com/llvm/llvm-project/pull/90580

>From 0d6ff964ed83e06ed3947d709884ed6dd43e90b5 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Tue, 30 Apr 2024 13:42:45 +0400
Subject: [PATCH 1/2] [lldb][Windows] Fixed unresolved test lldb-api
 python_api/debugger/TestDebuggerAPI.py

It is necessary to select the expected platform at the beginning.
In case of `Windows` host platform1.GetName() returned `host`. 
platform2.GetName() returned `remote-linux`, but 
platform2.GetWorkingDirectory() was None and finally
```
  File "llvm-project\lldb\test\API\python_api\debugger\TestDebuggerAPI.py", 
line 108, in test_CreateTarget_platform
platform2.GetWorkingDirectory().endswith("bar"),
AttributeError: 'NoneType' object has no attribute 'endswith'
```
---
 lldb/test/API/python_api/debugger/TestDebuggerAPI.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py 
b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
index 522de2466012e..3d6484e5c9fbc 100644
--- a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
+++ b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
@@ -95,6 +95,7 @@ def test_CreateTarget_platform(self):
 exe = self.getBuildArtifact("a.out")
 self.yaml2obj("elf.yaml", exe)
 error = lldb.SBError()
+self.dbg.SetSelectedPlatform(lldb.SBPlatform("remote-linux"))
 target1 = self.dbg.CreateTarget(exe, None, "remote-linux", False, 
error)
 self.assertSuccess(error)
 platform1 = target1.GetPlatform()

>From 012d95b3ed4c83c9d439cae1e2b53cbea5dcb441 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Thu, 16 May 2024 21:25:51 +0400
Subject: [PATCH 2/2] Updated to use @expectedFailureAll with a bugnumber.

---
 lldb/test/API/python_api/debugger/TestDebuggerAPI.py | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py 
b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
index 3d6484e5c9fbc..55071d6da8f8a 100644
--- a/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
+++ b/lldb/test/API/python_api/debugger/TestDebuggerAPI.py
@@ -91,11 +91,15 @@ def get_cache_line_size():
 # Test the local property again, is it set to new_cache_line_size?
 self.assertEqual(get_cache_line_size(), new_cache_line_size)
 
+@expectedFailureAll(
+hostoslist=["windows"],
+remote=True,
+bugnumber="github.com/llvm/llvm-project/issues/92419",
+)
 def test_CreateTarget_platform(self):
 exe = self.getBuildArtifact("a.out")
 self.yaml2obj("elf.yaml", exe)
 error = lldb.SBError()
-self.dbg.SetSelectedPlatform(lldb.SBPlatform("remote-linux"))
 target1 = self.dbg.CreateTarget(exe, None, "remote-linux", False, 
error)
 self.assertSuccess(error)
 platform1 = target1.GetPlatform()

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


[Lldb-commits] [lldb] [lldb] Fixed unresolved test lldb-api python_api/debugger/TestDebuggerAPI.py on x86_64 host (PR #90580)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

slydiman wrote:

I have added [the issuee](https://github.com/llvm/llvm-project/issues/92419)  
and updated the test with @expectedFailureAll and the bugnumber.

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 750414bde848902d3fe471e84912020a1f67d193 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 681 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
obj

[Lldb-commits] [lldb] c7ae8c6 - [lldb] Fixed the DAP tests in case of a remote target (#92416)

2024-05-16 Thread via lldb-commits

Author: Dmitry Vasilyev
Date: 2024-05-16T21:30:31+04:00
New Revision: c7ae8c6639370ccbc583dca019bbb78761ce423d

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

LOG: [lldb] Fixed the DAP tests in case of a remote target (#92416)

These tests are based on dap_server which runs locally. These tests
failed in case of Windows host and Linux target.

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py 
b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
index 2b3ec656c107a..3250a5093cac4 100644
--- a/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
+++ b/lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py
@@ -19,6 +19,7 @@ def verify_completions(self, actual_list, expected_list, 
not_expected_list=[]):
 self.assertNotIn(not_expected_item, actual_list)
 
 @skipIfWindows
+@skipIfRemote
 @skipIf(compiler="clang", compiler_version=["<", "17.0"])
 def test_completions(self):
 """

diff  --git a/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py 
b/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
index 8c2c0154ba65c..58a67d8164368 100644
--- a/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
+++ b/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py
@@ -9,6 +9,7 @@
 
 
 class TestDAP_exception(lldbdap_testcase.DAPTestCaseBase):
+@skipIfRemote
 @skipIfWindows
 def test_stopped_description(self):
 """



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


[Lldb-commits] [lldb] [lldb] Fixed the DAP tests in case of a remote target (PR #92416)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] SBDebugger: Add new APIs `AddDestroyCallback` and `RemoveDestroyCallback` (PR #89868)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -731,8 +746,11 @@ class Debugger : public 
std::enable_shared_from_this,
   lldb::TargetSP m_dummy_target_sp;
   Diagnostics::CallbackID m_diagnostics_callback_id;
 
-  lldb_private::DebuggerDestroyCallback m_destroy_callback = nullptr;
-  void *m_destroy_callback_baton = nullptr;
+  std::recursive_mutex m_destroy_callback_mutex;
+  lldb::destroy_callback_token_t m_destroy_callback_next_token = 0;
+  llvm::SmallDenseMap>
+  m_destroy_callback_and_baton;

clayborg wrote:

This doesn't guarantee that callbacks will be called in the right order. This 
should be a simple SmallVector so we can guarantee the order that they are 
called in. This array will not be large and it is easy to search for when 
searching for things by token. Maybe use 2 items and the size of the SmallVector

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -6410,12 +6410,20 @@ GetCoreFileSaveRangesStackOnly(Process &process,
 if (!reg_ctx_sp)
   continue;
 const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();
 lldb_private::MemoryRegionInfo sp_region;
 if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
   // Only add this region if not already added above. If our stack pointer
   // is pointing off in the weeds, we will want this range.
-  if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0)
+  if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0) {
+// Take only the start of the stack to the stack pointer and include 
the redzone.
+// Because stacks grow 'down' to include the red_zone we have to 
subtract it from the sp.
+const size_t stack_head = (sp - red_zone);

clayborg wrote:

> It depends on where does the API get the value from. I haven't looked but it 
> is likely `GetRedZoneSize()` value is fetched from dwarf, which can be bogus 
> value generated from compiler/linker/BOLT etc...
> 
> Simply sanity check that `if (stack_head > 
> sp_region.GetRange().GetRangeBase())` will ensure we are not reading reading 
> beyond valid memory region.

Red zone is gotten from the ABI plug-ins. This is correct behavior, but we 
should make sure that `(sp - red_zone)` is actually not before the start of the 
memory region.

```
const addr_t stack_head = (sp - red_zone) > sp_region.GetRange.GetRangeBase() ? 
(sp - red_zone) : sp_region.GetRange.GetRangeBase();
```

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


[Lldb-commits] [lldb] [lldb-dap] Separate user and developer documentation (PR #92428)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/92428

>From ca9fc570e4b721c36e5a0f9154e3158573bc5483 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 16 May 2024 09:44:57 -0700
Subject: [PATCH] [lldb-dap] Separate user and developer documentation

The README.md is what users see when they look for the extension in the
Marketplace [1]. Right now, it's a mix of developer documentation (for us)
and user documentation. This commit moves the developer docs into `docs`
and the lldb website and refocuses the README on using the extension.

[1] 
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap
---
 lldb/docs/index.rst|   1 +
 lldb/docs/resources/lldbdap.md |  97 
 lldb/tools/lldb-dap/README.md  | 156 +
 3 files changed, 119 insertions(+), 135 deletions(-)
 create mode 100644 lldb/docs/resources/lldbdap.md

diff --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 7a27f6914fa89..1e7d69002dd3e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -161,6 +161,7 @@ interesting areas to contribute to lldb.
resources/lldbplatformpackets
resources/caveats
resources/projects
+   resources/lldbdap
Public C++ API 
Private C++ API 
 
diff --git a/lldb/docs/resources/lldbdap.md b/lldb/docs/resources/lldbdap.md
new file mode 100644
index 0..2d345e26b7e57
--- /dev/null
+++ b/lldb/docs/resources/lldbdap.md
@@ -0,0 +1,97 @@
+# LLDB-DAP
+
+The `lldb-dap` tool (formerly `lldb-vscode`) is a command line tool that
+implements the [Debug Adapter
+Protocol](https://microsoft.github.io/debug-adapter-protocol/). It can be
+installed as an extension for Visual Studio Code and other IDEs supporting DAP.
+The protocol is easy to run remotely and also can allow other tools and IDEs to
+get a full featured debugger with a well defined protocol.
+
+## Local Installation for Visual Studio Code
+
+Installing the plug-in is very straightforward and involves just a few steps.
+
+### Pre-requisites
+
+- Install a modern version of node (e.g. `v20.0.0`).
+- On VS Code, execute the command `Install 'code' command in PATH`. You need to
+  do it only once. This enables the command `code` in the PATH.
+
+### Packaging and installation
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package # This also compiles the extension.
+npm run vscode-install
+```
+
+On VS Code, set the setting `lldb-dap.executable-path` to the path of your 
local
+build of `lldb-dap`.
+
+And then you are ready!
+
+### Updating the extension
+
+*Note: It's not necessary to update the extension if there has been changes
+to  `lldb-dap`. The extension needs to be updated only if the TypesScript code
+has changed.*
+
+Updating the extension is pretty much the same process as installing it from
+scratch. However, VS Code expects the version number of the upgraded extension
+to be greater than the previous one, otherwise the installation step might have
+no effect.
+
+```bash
+# Bump version in package.json
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package
+npm run vscode-install
+```
+
+Another way upgrade without bumping the extension version is to first uninstall
+the extension, then reload VS Code, and then install it again. This is
+an unfortunate limitation of the editor.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm run vscode-uninstall
+# Then reload VS Code: reopen the IDE or execute the `Developer: Reload Window`
+# command.
+npm run package
+npm run vscode-install
+```
+
+### Deploying for Visual Studio Code
+
+The easiest way to deploy the extension for execution on other machines 
requires
+copying `lldb-dap` and its dependencies into a`./bin` subfolder and then 
create a
+standalone VSIX package.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+mkdir -p ./bin
+cp /path/to/a/built/lldb-dap ./bin/
+cp /path/to/a/built/liblldb.so ./bin/
+npm run package
+```
+
+This will produce the file `./out/lldb-dap.vsix` that can be distributed. In
+this type of installation, users don't need to manually set the path to
+`lldb-dap`. The extension will automatically look for it in the `./bin`
+subfolder.
+
+*Note: It's not possible to use symlinks to `lldb-dap`, as the packaging tool
+forcefully performs a deep copy of all symlinks.*
+
+*Note: It's possible to use this kind flow for local installations, but it's
+not recommended because updating `lldb-dap` requires rebuilding the extension.*
+
+## Formatting the Typescript code
+
+This is also very simple, just run:
+
+```bash
+npm run format
+```
diff --git a/lldb/tools/lldb-dap/README.md b/lldb/tools/lldb-dap/README.md
index 16ce4672be71c..8ecbaf7ce9816 100644
--- a/lldb/tools/lldb-dap/README.md
+++ b/lldb/tools/lldb-dap/README.md
@@ -1,133 +1,19 @@
+# LLDB DAP
 
-# Table of Contents
-
-- [Table of Contents](#table-

[Lldb-commits] [lldb] 525bd66 - [lldb-dap] Separate user and developer documentation (#92428)

2024-05-16 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2024-05-16T10:41:06-07:00
New Revision: 525bd66fc29fd056ef18118dfff3c9cc05fdd5e3

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

LOG: [lldb-dap] Separate user and developer documentation (#92428)

The README.md is what users see when they look for the extension in the
Marketplace [1]. Right now, it's a mix of developer documentation (for
us) and user documentation. This commit moves the developer docs into
`docs` and the lldb website and refocuses the README on using the
extension.

[1] 
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap

Added: 
lldb/docs/resources/lldbdap.md

Modified: 
lldb/docs/index.rst
lldb/tools/lldb-dap/README.md

Removed: 




diff  --git a/lldb/docs/index.rst b/lldb/docs/index.rst
index 7a27f6914fa89..1e7d69002dd3e 100644
--- a/lldb/docs/index.rst
+++ b/lldb/docs/index.rst
@@ -161,6 +161,7 @@ interesting areas to contribute to lldb.
resources/lldbplatformpackets
resources/caveats
resources/projects
+   resources/lldbdap
Public C++ API 
Private C++ API 
 

diff  --git a/lldb/docs/resources/lldbdap.md b/lldb/docs/resources/lldbdap.md
new file mode 100644
index 0..2d345e26b7e57
--- /dev/null
+++ b/lldb/docs/resources/lldbdap.md
@@ -0,0 +1,97 @@
+# LLDB-DAP
+
+The `lldb-dap` tool (formerly `lldb-vscode`) is a command line tool that
+implements the [Debug Adapter
+Protocol](https://microsoft.github.io/debug-adapter-protocol/). It can be
+installed as an extension for Visual Studio Code and other IDEs supporting DAP.
+The protocol is easy to run remotely and also can allow other tools and IDEs to
+get a full featured debugger with a well defined protocol.
+
+## Local Installation for Visual Studio Code
+
+Installing the plug-in is very straightforward and involves just a few steps.
+
+### Pre-requisites
+
+- Install a modern version of node (e.g. `v20.0.0`).
+- On VS Code, execute the command `Install 'code' command in PATH`. You need to
+  do it only once. This enables the command `code` in the PATH.
+
+### Packaging and installation
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package # This also compiles the extension.
+npm run vscode-install
+```
+
+On VS Code, set the setting `lldb-dap.executable-path` to the path of your 
local
+build of `lldb-dap`.
+
+And then you are ready!
+
+### Updating the extension
+
+*Note: It's not necessary to update the extension if there has been changes
+to  `lldb-dap`. The extension needs to be updated only if the TypesScript code
+has changed.*
+
+Updating the extension is pretty much the same process as installing it from
+scratch. However, VS Code expects the version number of the upgraded extension
+to be greater than the previous one, otherwise the installation step might have
+no effect.
+
+```bash
+# Bump version in package.json
+cd /path/to/lldb/tools/lldb-dap
+npm install
+npm run package
+npm run vscode-install
+```
+
+Another way upgrade without bumping the extension version is to first uninstall
+the extension, then reload VS Code, and then install it again. This is
+an unfortunate limitation of the editor.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+npm run vscode-uninstall
+# Then reload VS Code: reopen the IDE or execute the `Developer: Reload Window`
+# command.
+npm run package
+npm run vscode-install
+```
+
+### Deploying for Visual Studio Code
+
+The easiest way to deploy the extension for execution on other machines 
requires
+copying `lldb-dap` and its dependencies into a`./bin` subfolder and then 
create a
+standalone VSIX package.
+
+```bash
+cd /path/to/lldb/tools/lldb-dap
+mkdir -p ./bin
+cp /path/to/a/built/lldb-dap ./bin/
+cp /path/to/a/built/liblldb.so ./bin/
+npm run package
+```
+
+This will produce the file `./out/lldb-dap.vsix` that can be distributed. In
+this type of installation, users don't need to manually set the path to
+`lldb-dap`. The extension will automatically look for it in the `./bin`
+subfolder.
+
+*Note: It's not possible to use symlinks to `lldb-dap`, as the packaging tool
+forcefully performs a deep copy of all symlinks.*
+
+*Note: It's possible to use this kind flow for local installations, but it's
+not recommended because updating `lldb-dap` requires rebuilding the extension.*
+
+## Formatting the Typescript code
+
+This is also very simple, just run:
+
+```bash
+npm run format
+```

diff  --git a/lldb/tools/lldb-dap/README.md b/lldb/tools/lldb-dap/README.md
index 16ce4672be71c..8ecbaf7ce9816 100644
--- a/lldb/tools/lldb-dap/README.md
+++ b/lldb/tools/lldb-dap/README.md
@@ -1,133 +1,19 @@
+# LLDB DAP
 
-# Table of Contents
-
-- [Table of Conte

[Lldb-commits] [lldb] [lldb-dap] Separate user and developer documentation (PR #92428)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fixed the TestDebuggerAPI test on x86_64 Windows host (PR #90580)

2024-05-16 Thread Dmitry Vasilyev via lldb-commits

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -6335,16 +6335,51 @@ static void AddRegion(const MemoryRegionInfo ®ion, 
bool try_dirty_pages,
   ranges.push_back(CreateCoreFileMemoryRange(region));
 }
 
+static void
+SaveOffRegionsWithStackPointers(Process &process,
+   const MemoryRegionInfos ®ions,
+   Process::CoreFileMemoryRanges &ranges,
+   std::set &stack_ends) {
+  const bool try_dirty_pages = true;
+
+  // Before we take any dump, we want to save off the used portions of the 
stacks
+  // and mark those memory regions as saved. This prevents us from saving the 
unused portion
+  // of the stack below the stack pointer. Saving space on the dump.
+  for (lldb::ThreadSP thread_sp : process.GetThreadList().Threads()) {
+if (!thread_sp)
+  continue;
+StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
+if (!frame_sp)
+  continue;
+RegisterContextSP reg_ctx_sp = frame_sp->GetRegisterContext();
+if (!reg_ctx_sp)
+  continue;
+const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();
+lldb_private::MemoryRegionInfo sp_region;
+if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
+const size_t stack_head = (sp - red_zone);
+const size_t stack_size = sp_region.GetRange().GetRangeEnd() - 
stack_head;

clayborg wrote:

Use `addr_t` as this will cause 32 bit compiled LLDB's to not be able to 
correctly save 64 bit core files because `size_t` is 32 bits on 32 bit systems

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -6335,16 +6335,51 @@ static void AddRegion(const MemoryRegionInfo ®ion, 
bool try_dirty_pages,
   ranges.push_back(CreateCoreFileMemoryRange(region));
 }
 
+static void
+SaveOffRegionsWithStackPointers(Process &process,
+   const MemoryRegionInfos ®ions,
+   Process::CoreFileMemoryRanges &ranges,
+   std::set &stack_ends) {
+  const bool try_dirty_pages = true;
+
+  // Before we take any dump, we want to save off the used portions of the 
stacks
+  // and mark those memory regions as saved. This prevents us from saving the 
unused portion
+  // of the stack below the stack pointer. Saving space on the dump.
+  for (lldb::ThreadSP thread_sp : process.GetThreadList().Threads()) {
+if (!thread_sp)
+  continue;
+StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
+if (!frame_sp)
+  continue;
+RegisterContextSP reg_ctx_sp = frame_sp->GetRegisterContext();
+if (!reg_ctx_sp)
+  continue;
+const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();
+lldb_private::MemoryRegionInfo sp_region;
+if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
+const size_t stack_head = (sp - red_zone);
+const size_t stack_size = sp_region.GetRange().GetRangeEnd() - 
stack_head;
+sp_region.GetRange().SetRangeBase(stack_head);
+sp_region.GetRange().SetByteSize(stack_size);
+stack_ends.insert(sp_region.GetRange().GetRangeEnd());
+AddRegion(sp_region, try_dirty_pages, ranges);
+}

clayborg wrote:

We should check if the stack head makes sense before adusting it:
We should make sure stack_head is >= sp_region.GetRange().GetRangeBase():
```
// Adjust start of head of stack if possible 
const size_t stack_head = (sp - red_zone);
if (stack_head > sp_region.GetRange().GetRangeBase()) {
  const size_t stack_size = sp_region.GetRange().GetRangeEnd() - stack_head;
  sp_region.GetRange().SetRangeBase(stack_head);
  sp_region.GetRange().SetByteSize(stack_size);
}
stack_ends.insert(sp_region.GetRange().GetRangeEnd());
AddRegion(sp_region, try_dirty_pages, ranges);
```

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -490,9 +491,12 @@ findStackHelper(const lldb::ProcessSP &process_sp, 
uint64_t rsp) {
 return llvm::createStringError(
 std::errc::not_supported,
 "unable to load stack segment of the process");
-
-  const addr_t addr = range_info.GetRange().GetRangeBase();
-  const addr_t size = range_info.GetRange().GetByteSize();
+  // This is a duplicate of the logic in 
Process::SaveOffRegionsWithStackPointers
+  // but ultimately, we need to only save up from the start of `the stack down 
to the stack pointer.
+  const addr_t range_end = range_info.GetRange().GetRangeEnd();
+  const size_t red_zone = process_sp->GetABI()->GetRedZoneSize();

clayborg wrote:

In general we don't want to use `size_t`, it is 32 bits on 32 bit system and 64 
on 64 bit systems. Change to `addr_t`

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits


@@ -6335,16 +6335,51 @@ static void AddRegion(const MemoryRegionInfo ®ion, 
bool try_dirty_pages,
   ranges.push_back(CreateCoreFileMemoryRange(region));
 }
 
+static void
+SaveOffRegionsWithStackPointers(Process &process,
+   const MemoryRegionInfos ®ions,
+   Process::CoreFileMemoryRanges &ranges,
+   std::set &stack_ends) {
+  const bool try_dirty_pages = true;
+
+  // Before we take any dump, we want to save off the used portions of the 
stacks
+  // and mark those memory regions as saved. This prevents us from saving the 
unused portion
+  // of the stack below the stack pointer. Saving space on the dump.
+  for (lldb::ThreadSP thread_sp : process.GetThreadList().Threads()) {
+if (!thread_sp)
+  continue;
+StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
+if (!frame_sp)
+  continue;
+RegisterContextSP reg_ctx_sp = frame_sp->GetRegisterContext();
+if (!reg_ctx_sp)
+  continue;
+const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();

clayborg wrote:

Don't use size_t due to 32 bit systems... I know the red_zone won't be over 
4GB, but just good to not use `size_t`
```
s/size_t/addr_t/
```

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


[Lldb-commits] [clang] [lldb] [llvm] [openmp] [polly] fix(python): fix comparison to True/False (PR #91858)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

I don't think Alex is arguing in favor of keeping the old (wrong) behavior, but 
the first file looks like this:

```
foundSpec = False
if [...]
  foundSpec = True
[...]
if foundSpec is False:
```

It's pretty obvious this is a boolean and should use `if not foundSpec`. 

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/92014

>From 1be2c95ae31621c6f5df72159f35b938318f9ed7 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Fri, 10 May 2024 12:42:03 -0700
Subject: [PATCH] Add AddressRange to SB API

Summary:
This adds new SB API calls and classes to allow a user of the SB API to
obtain an address range from SBFunction and SBBlock.

Test Plan:
llvm-lit -sv 
llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py

Reviewers: clayborg

Subscribers: lldb-commits

Tasks:

Tags:
---
 lldb/bindings/headers.swig|   2 +
 .../interface/SBAddressRangeDocstrings.i  |   3 +
 .../interface/SBAddressRangeExtensions.i  |   1 +
 .../interface/SBAddressRangeListDocstrings.i  |   3 +
 .../interface/SBAddressRangeListExtensions.i  |  25 +++
 lldb/bindings/interfaces.swig |   6 +
 lldb/include/lldb/API/LLDB.h  |   2 +
 lldb/include/lldb/API/SBAddress.h |   1 +
 lldb/include/lldb/API/SBAddressRange.h|  65 ++
 lldb/include/lldb/API/SBAddressRangeList.h|  58 ++
 lldb/include/lldb/API/SBBlock.h   |   4 +
 lldb/include/lldb/API/SBDefines.h |   2 +
 lldb/include/lldb/API/SBFunction.h|   3 +
 lldb/include/lldb/API/SBStream.h  |   2 +
 lldb/include/lldb/Core/AddressRange.h |  12 ++
 lldb/include/lldb/Symbol/Block.h  |   2 +
 lldb/include/lldb/lldb-forward.h  |   3 +
 lldb/source/API/CMakeLists.txt|   2 +
 lldb/source/API/SBAddressRange.cpp| 102 ++
 lldb/source/API/SBAddressRangeList.cpp| 134 +
 lldb/source/API/SBBlock.cpp   |   9 +
 lldb/source/API/SBFunction.cpp|  10 +
 lldb/source/Core/AddressRange.cpp |  15 ++
 lldb/source/Symbol/Block.cpp  |  16 ++
 .../API/python_api/address_range/Makefile |   3 +
 .../address_range/TestAddressRange.py | 188 ++
 .../API/python_api/address_range/main.cpp |   8 +
 27 files changed, 681 insertions(+)
 create mode 100644 lldb/bindings/interface/SBAddressRangeDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeExtensions.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListDocstrings.i
 create mode 100644 lldb/bindings/interface/SBAddressRangeListExtensions.i
 create mode 100644 lldb/include/lldb/API/SBAddressRange.h
 create mode 100644 lldb/include/lldb/API/SBAddressRangeList.h
 create mode 100644 lldb/source/API/SBAddressRange.cpp
 create mode 100644 lldb/source/API/SBAddressRangeList.cpp
 create mode 100644 lldb/test/API/python_api/address_range/Makefile
 create mode 100644 lldb/test/API/python_api/address_range/TestAddressRange.py
 create mode 100644 lldb/test/API/python_api/address_range/main.cpp

diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..2b53eefc8568b 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -8,6 +8,8 @@
 %{
 #include "lldb/lldb-public.h"
 #include "lldb/API/SBAddress.h"
+#include "lldb/API/SBAddressRange.h"
+#include "lldb/API/SBAddressRangeList.h"
 #include "lldb/API/SBAttachInfo.h"
 #include "lldb/API/SBBlock.h"
 #include "lldb/API/SBBreakpoint.h"
diff --git a/lldb/bindings/interface/SBAddressRangeDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeDocstrings.i
new file mode 100644
index 0..650195704d73e
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"API clients can get address range information."
+) lldb::SBAddressRange;
diff --git a/lldb/bindings/interface/SBAddressRangeExtensions.i 
b/lldb/bindings/interface/SBAddressRangeExtensions.i
new file mode 100644
index 0..bca359868232d
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeExtensions.i
@@ -0,0 +1 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRange)
diff --git a/lldb/bindings/interface/SBAddressRangeListDocstrings.i 
b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
new file mode 100644
index 0..e4b96b9ca5931
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListDocstrings.i
@@ -0,0 +1,3 @@
+%feature("docstring",
+"Represents a list of :py:class:`SBAddressRange`."
+) lldb::SBAddressRangeList;
diff --git a/lldb/bindings/interface/SBAddressRangeListExtensions.i 
b/lldb/bindings/interface/SBAddressRangeListExtensions.i
new file mode 100644
index 0..08bfa6d9aef60
--- /dev/null
+++ b/lldb/bindings/interface/SBAddressRangeListExtensions.i
@@ -0,0 +1,25 @@
+STRING_EXTENSION_OUTSIDE(SBAddressRangeList)
+
+%extend lldb::SBAddressRangeList {
+#ifdef SWIGPYTHON
+%pythoncode%{
+def __len__(self):
+  '''Return the number of address ranges in a lldb.SBAddressRangeList 
object.'''
+  return self.GetSize()
+
+def __iter__(self):
+  '''Iterate over all the address ranges in a lldb.SBAddressRangeList 
obj

[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Alex Langford via lldb-commits


@@ -242,6 +244,12 @@ class AddressRange {
   lldb::addr_t m_byte_size = 0; ///< The size in bytes of this address range.
 };
 
+// Forward-declarable wrapper.
+class AddressRanges : public std::vector {
+public:
+  using std::vector::vector;
+};

bulbazord wrote:

Sorry, "above" was the wrong word. I meant "below", but to be even more 
specific, I'm referring to this: 
https://github.com/llvm/llvm-project/pull/92014#discussion_r1602020217

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Alex Langford via lldb-commits


@@ -0,0 +1,58 @@
+//===-- SBAddressRangeList.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 LLDB_API_SBADDRESSRANGELIST_H
+#define LLDB_API_SBADDRESSRANGELIST_H
+
+#include 
+
+#include "lldb/API/SBDefines.h"
+
+class AddressRangeListImpl;
+
+namespace lldb {
+
+class LLDB_API SBAddressRangeList {
+public:
+  SBAddressRangeList();
+
+  SBAddressRangeList(const lldb::SBAddressRangeList &rhs);
+
+  ~SBAddressRangeList();
+
+  const lldb::SBAddressRangeList &
+  operator=(const lldb::SBAddressRangeList &rhs);
+
+  uint32_t GetSize() const;
+
+  void Clear();
+
+  bool GetAddressRangeAtIndex(uint64_t idx, SBAddressRange &addr_range);
+
+  void Append(const lldb::SBAddressRange &addr_range);
+
+  void Append(const lldb::SBAddressRangeList &addr_range_list);
+
+protected:
+  const AddressRangeListImpl *operator->() const;
+
+  const AddressRangeListImpl &operator*() const;
+
+private:
+  friend class SBProcess;
+
+  lldb_private::AddressRanges &ref();
+
+  const lldb_private::AddressRanges &ref() const;

bulbazord wrote:

To be clear, I'm objecting to these methods existing at all. I re-read the code 
and my comment and realized my argument didn't actually make a ton of sense, so 
allow me to clarify:
I don't think we should be exposing `ref` at all here. I can understand having 
private methods to access the underlying `AddressRangeListImpl` (so that other 
classes can access it and mess with it, we do this all the time). What I don't 
think is a good idea is having a method to access implementation details of 
`AddressRangeListImpl` (namely, `AddressRanges`).

Instead, I'm suggesting that we shuffle some code around to avoid exposing 
these at all. The problem that these solve is that other classes may want to 
privately modify the underlying `AddressRangeListImpl`, but don't have access 
to the class. All they have is a forward declaration (because they include this 
header and the implementation is in the cpp file). My suggestion would be to 
create a private header `AddressRangeListImpl.h` in `source/API`. Then any 
class that wants to modify the underlying `AddressRangeListImpl` can do so 
without needing to know that `AddressRangeListImpl` is implemented with 
`AddressRanges`.

Normally I try not to push back against things here, but you cannot change or 
remove things from the SBAPI ever. Not even private methods like these (as I 
found out when I broke the ABI on Windows last year).

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)

2024-05-16 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/92002

>From 2d192f640b332c2f1381cf96b75be60ad18de3ac Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 10 May 2024 09:35:11 -0700
Subject: [PATCH 1/5] change core dump stacks to only include up to the stack
 pointer (+ red zone) Add python tests to verify we can read up to sp +
 redzone - 1.

---
 lldb/source/Target/Process.cpp | 14 +++---
 .../TestProcessSaveCoreMinidump.py | 12 
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 25afade9a8275..a11e45909202f 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -3857,8 +3857,8 @@ thread_result_t Process::RunPrivateStateThread(bool 
is_secondary_thread) {
 // case we should tell it to stop doing that.  Normally, we don't NEED
 // to do that because we will next close the communication to the stub
 // and that will get it to shut down.  But there are remote debugging
-// cases where relying on that side-effect causes the shutdown to be 
-// flakey, so we should send a positive signal to interrupt the wait. 
+// cases where relying on that side-effect causes the shutdown to be
+// flakey, so we should send a positive signal to interrupt the wait.
 Status error = HaltPrivate();
 BroadcastEvent(eBroadcastBitInterrupt, nullptr);
   } else if (StateIsRunningState(m_last_broadcast_state)) {
@@ -6410,12 +6410,20 @@ GetCoreFileSaveRangesStackOnly(Process &process,
 if (!reg_ctx_sp)
   continue;
 const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();
 lldb_private::MemoryRegionInfo sp_region;
 if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
   // Only add this region if not already added above. If our stack pointer
   // is pointing off in the weeds, we will want this range.
-  if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0)
+  if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0) {
+// Take only the start of the stack to the stack pointer and include 
the redzone.
+// Because stacks grow 'down' to include the red_zone we have to 
subtract it from the sp.
+const size_t stack_head = (sp - red_zone);
+const size_t stack_size = sp_region.GetRange().GetRangeEnd() - 
(stack_head);
+sp_region.GetRange().SetRangeBase(stack_head);
+sp_region.GetRange().SetByteSize(stack_size);
 AddRegion(sp_region, try_dirty_pages, ranges);
+  }
 }
   }
 }
diff --git 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
index 9fe5e89142987..123bbd472be05 100644
--- 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
+++ 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -14,6 +14,7 @@ class ProcessSaveCoreMinidumpTestCase(TestBase):
 def verify_core_file(
 self, core_path, expected_pid, expected_modules, expected_threads
 ):
+breakpoint()
 # To verify, we'll launch with the mini dump
 target = self.dbg.CreateTarget(None)
 process = target.LoadCore(core_path)
@@ -36,11 +37,22 @@ def verify_core_file(
 self.assertEqual(module_file_name, expected_file_name)
 self.assertEqual(module.GetUUIDString(), expected.GetUUIDString())
 
+red_zone = process.GetTarget().GetStackRedZoneSize()
 for thread_idx in range(process.GetNumThreads()):
 thread = process.GetThreadAtIndex(thread_idx)
 self.assertTrue(thread.IsValid())
 thread_id = thread.GetThreadID()
 self.assertIn(thread_id, expected_threads)
+oldest_frame = thread.GetFrameAtIndex(thread.GetNumFrames() - 1)
+stack_start = 
oldest_frame.GetSymbol().GetStartAddress().GetFileAddress()
+frame = thread.GetFrameAtIndex(0)
+sp = frame.GetSP()
+stack_size = stack_start - (sp - red_zone)
+byte_array = process.ReadMemory(sp - red_zone + 1, stack_size, 
error)
+self.assertTrue(error.Success(), "Failed to read stack")
+self.assertEqual(stack_size - 1, len(byte_array), "Incorrect stack 
size read"),
+
+
 self.dbg.DeleteTarget(target)
 
 @skipUnlessArch("x86_64")

>From aa6d0a24b64816c328c7c4c3d00c7563407a3deb Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 10 May 2024 14:51:12 -0700
Subject: [PATCH 2/5] Refactor test to read the top and bottom stack frame's
 respective pointers instead of trying to take the entire range

---
 .../TestProcessSaveCoreMinidump.py | 14 +++---

[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Jacob Lalonde via lldb-commits


@@ -6335,16 +6335,51 @@ static void AddRegion(const MemoryRegionInfo ®ion, 
bool try_dirty_pages,
   ranges.push_back(CreateCoreFileMemoryRange(region));
 }
 
+static void
+SaveOffRegionsWithStackPointers(Process &process,
+   const MemoryRegionInfos ®ions,
+   Process::CoreFileMemoryRanges &ranges,
+   std::set &stack_ends) {
+  const bool try_dirty_pages = true;
+
+  // Before we take any dump, we want to save off the used portions of the 
stacks
+  // and mark those memory regions as saved. This prevents us from saving the 
unused portion
+  // of the stack below the stack pointer. Saving space on the dump.
+  for (lldb::ThreadSP thread_sp : process.GetThreadList().Threads()) {
+if (!thread_sp)
+  continue;
+StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
+if (!frame_sp)
+  continue;
+RegisterContextSP reg_ctx_sp = frame_sp->GetRegisterContext();
+if (!reg_ctx_sp)
+  continue;
+const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();
+lldb_private::MemoryRegionInfo sp_region;
+if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
+const size_t stack_head = (sp - red_zone);
+const size_t stack_size = sp_region.GetRange().GetRangeEnd() - 
stack_head;
+sp_region.GetRange().SetRangeBase(stack_head);
+sp_region.GetRange().SetByteSize(stack_size);
+stack_ends.insert(sp_region.GetRange().GetRangeEnd());
+AddRegion(sp_region, try_dirty_pages, ranges);
+}

Jlalond wrote:

Done, also made sure we do this in `MinidumpFileBuilder`

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


[Lldb-commits] [lldb] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-05-16 Thread via lldb-commits


@@ -0,0 +1,93 @@
+//===-- ThreadPlanSingleThreadTimeout.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 LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include 
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and got reset by each internal
+// stops to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan  can be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by
+// issuing a thread specific async interrupt to enter stop state, then all
+// threads execution are resumed to resolve the potential deadlock.
+//
+class ThreadPlanSingleThreadTimeout : public ThreadPlan {
+public:
+  ~ThreadPlanSingleThreadTimeout() override;
+
+  // Create a new instance from fresh new state.
+  static void CreateNew(Thread &thread);
+  // Reset and create a new instance from the previous state.
+  static void ResetFromPrevState(Thread &thread);
+
+  void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
+  bool ValidatePlan(Stream *error) override { return true; }
+  bool WillStop() override;
+  void DidPop() override;
+
+  bool DoPlanExplainsStop(Event *event_ptr) override;
+
+  lldb::StateType GetPlanRunState() override;
+  static void TimeoutThreadFunc(ThreadPlanSingleThreadTimeout *self);
+
+  bool MischiefManaged() override;
+
+  bool ShouldStop(Event *event_ptr) override;
+  void SetStopOthers(bool new_value) override;
+  bool StopOthers() override;
+
+private:
+  ThreadPlanSingleThreadTimeout(Thread &thread);
+
+  static bool IsAlive();
+
+  enum class State {
+WaitTimeout,// Waiting for timeout.
+AsyncInterrupt, // Async interrupt has been issued.
+Done,   // Finished resume all threads.
+  };
+
+  static std::mutex s_mutex;

jeffreytan81 wrote:

This is a good point. I was storing some static states so that we can ensure: 
1. Singleton (only one ThreadPlanSingleThreadTimeout is alive/used anytime). 
2. If there is ever a race that, the `ThreadPlanSingleThreadTimeout` is in 
`State::AsyncInterrupt` but it got popped by another internal stop before async 
interrupt received. I want to remember the previous/last state, and the newly 
created `ThreadPlanSingleThreadTimeout` can be re-created from previous state.

Instead, I will look into storing these static states into parent controlling 
ThreadPlan (ThreadPlanStepOverRange in this case).

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


[Lldb-commits] [lldb] [lldb][breakpoint] Grey out disabled breakpoints (PR #91404)

2024-05-16 Thread Chelsea Cassanova via lldb-commits

chelcassanova wrote:

Cool, sorry for the delay but I made changes to `Stream` and `SBStream` to add 
a `GetUseColor()` accessor and to change the bool it uses in initialization to 
a `std::optional` and I'm gonna put them up in a separate PR. 

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Zequan Wu via lldb-commits


@@ -2306,6 +2345,11 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const 
DWARFDIE &die,
 
   if (!die)
 return false;
+  ParsedDWARFTypeAttributes attrs(die);

ZequanWu wrote:

This extra check was added in https://github.com/llvm/llvm-project/pull/91799 
to ensure we don't accidentally parse declaration DIE, which was reported at 
https://github.com/llvm/llvm-project/pull/90663#issuecomment-2105164917.

By checking `ParsedDWARFTypeAttributes`'s constructor, looks like it just 
parses the DIE's attributes, iterates through them, and updates its fields 
accordingly. 

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Zequan Wu via lldb-commits


@@ -321,6 +326,10 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
   std::vector m_func_indexes; // Sorted by address
   std::vector m_glob_indexes;
   std::map>, OSOInfoSP> 
m_oso_map;
+  // A map from CompilerType to the struct/class/union/enum DIE (might be a
+  // declaration or a definition) that is used to construct it.
+  llvm::DenseMap
+  m_forward_decl_compiler_type_to_die;

ZequanWu wrote:

TL;DR: This is because this change let `UniqueDWARFASTTypeMap` to cache created 
Type from declaration DIE. Before this, it was only used for caching Type 
created from definition DIE. And `UniqueDWARFASTTypeMap` is shared among all 
`SymbolFileDWARF`s belongs to one `SymbolFileDWARFDebugMap`, so should 
`m_forward_decl_compiler_type_to_die` which interacts with it.

Here's an example with debug map used:
The declaration DIE for `bar` is in foo.o and the definition DIE is in main.o. 
`ParseStructureLikeDIE` was firstly asked to parse the declaration DIE.

Before, it will always find the definition DIE in main.o and insert the 
CompilerType to definition DIE to `m_forward_decl_compiler_type_to_die` which 
belongs to SymbolFileDWARF(main.o). When `TypeSystemClang::CompleteTagDecl` 
wants to complete `bar`, it asks `SymbolFileDWARFDebugMap::CompleteType` to 
complete, which iterates all its SymbolFileDWARF(main.o, foo.o) and check if 
the any of them has the compiler type in their maps: 
https://github.com/llvm/llvm-project/blob/9144553207052a868efc5a8ce61a0afbb0eaf236/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp#L808-L812.
 If exists, then it assumes that symbol file should have the definition DIE and 
able to complete it. Since `bar`'s compiler type exists in symbol 
file(main.o)'s map which also has the definition DIE as value, the type 
completion will success. 

If I don't add the fix, we have [bar's compiler type -> bar's declaration DIE] 
in foo.o's map. When searching for definition DIE, we found that in main.o. 
Because we have already created its Type from declaration, the 
`UniqueDWARFASTTypeMap` will find the entry. Then it updates the entry to 
points to the definition DIE. It updates main.o's 
`m_forward_decl_compiler_type_to_die` to pointing to the definition DIE, which 
is **wrong**, since there's no such entry in main.o's map. It should update 
foo.o's map. The result is that `SymbolFileDWARFDebugMap::CompleteType` find 
bar's compiler type exists in foo.o and ask foo.o's symbol file to complete it, 
but it only has declaration DIE.

The fix is to share one `m_forward_decl_compiler_type_to_die` among one 
`SymbolFileDWARFDebugMap`. With this, when creating compiler type to 
declaration DIE in the map or updating an entry to point to a definition DIE, 
we are operating in the same map.

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Jacob Lalonde via lldb-commits


@@ -3857,8 +3857,8 @@ thread_result_t Process::RunPrivateStateThread(bool 
is_secondary_thread) {
 // case we should tell it to stop doing that.  Normally, we don't NEED
 // to do that because we will next close the communication to the stub
 // and that will get it to shut down.  But there are remote debugging
-// cases where relying on that side-effect causes the shutdown to be 
-// flakey, so we should send a positive signal to interrupt the wait. 
+// cases where relying on that side-effect causes the shutdown to be
+// flakey, so we should send a positive signal to interrupt the wait.

Jlalond wrote:

This got pulled back in by running clang-formatter on this file. Several 
different places were reformatted, do you want me to manually revert this still?

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Zequan Wu via lldb-commits


@@ -2306,6 +2345,11 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const 
DWARFDIE &die,
 
   if (!die)
 return false;
+  ParsedDWARFTypeAttributes attrs(die);

ZequanWu wrote:

The parsing happens every time when constructing this object, which makes it a 
bit expensive, should we add a new field `DWARFAttributes m_attributes` in 
`DWARFBaseDIE`, so that we only parse it once? From a glance at calls to 
`DWARFBaseDIE::GetAttributes`, there are more than 10 calls to it. The 
attribute parsing is repetitive. 

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-05-16 Thread Zequan Wu via lldb-commits

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] 47d80ec - [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (#92002)

2024-05-16 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2024-05-16T14:17:19-07:00
New Revision: 47d80ec1802d70082c8fd32b4396c98db2c4dba2

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

LOG: [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer 
+ red_zone (#92002)

Currently in Core dumps, the entire pthread is copied, including the
unused space beyond the stack pointer. This causes large amounts of core
dump inflation when the number of threads is high, but the stack usage
is low. Such as when an application is using a thread pool.

This change will optimize for these situations in addition to generally
improving the core dump performance for all of lldb.

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Target/Process.cpp

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index 601f11d51d428..7231433619ffb 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/Section.h"
+#include "lldb/Target/ABI.h"
 #include "lldb/Target/MemoryRegionInfo.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
@@ -491,6 +492,17 @@ findStackHelper(const lldb::ProcessSP &process_sp, 
uint64_t rsp) {
 std::errc::not_supported,
 "unable to load stack segment of the process");
 
+  // This is a duplicate of the logic in
+  // Process::SaveOffRegionsWithStackPointers but ultimately, we need to only
+  // save up from the start of the stack down to the stack pointer
+  const addr_t range_end = range_info.GetRange().GetRangeEnd();
+  const addr_t red_zone = process_sp->GetABI()->GetRedZoneSize();
+  const addr_t stack_head = rsp - red_zone;
+  if (stack_head > range_info.GetRange().GetRangeEnd()) {
+range_info.GetRange().SetRangeBase(stack_head);
+range_info.GetRange().SetByteSize(range_end - stack_head);
+  }
+
   const addr_t addr = range_info.GetRange().GetRangeBase();
   const addr_t size = range_info.GetRange().GetByteSize();
 

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 25afade9a8275..216d2f21abfef 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -3857,8 +3857,8 @@ thread_result_t Process::RunPrivateStateThread(bool 
is_secondary_thread) {
 // case we should tell it to stop doing that.  Normally, we don't NEED
 // to do that because we will next close the communication to the stub
 // and that will get it to shut down.  But there are remote debugging
-// cases where relying on that side-effect causes the shutdown to be 
-// flakey, so we should send a positive signal to interrupt the wait. 
+// cases where relying on that side-effect causes the shutdown to be
+// flakey, so we should send a positive signal to interrupt the wait.
 Status error = HaltPrivate();
 BroadcastEvent(eBroadcastBitInterrupt, nullptr);
   } else if (StateIsRunningState(m_last_broadcast_state)) {
@@ -6335,30 +6335,65 @@ static void AddRegion(const MemoryRegionInfo ®ion, 
bool try_dirty_pages,
   ranges.push_back(CreateCoreFileMemoryRange(region));
 }
 
+static void SaveOffRegionsWithStackPointers(
+Process &process, const MemoryRegionInfos ®ions,
+Process::CoreFileMemoryRanges &ranges, std::set &stack_ends) {
+  const bool try_dirty_pages = true;
+
+  // Before we take any dump, we want to save off the used portions of the
+  // stacks and mark those memory regions as saved. This prevents us from 
saving
+  // the unused portion of the stack below the stack pointer. Saving space on
+  // the dump.
+  for (lldb::ThreadSP thread_sp : process.GetThreadList().Threads()) {
+if (!thread_sp)
+  continue;
+StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
+if (!frame_sp)
+  continue;
+RegisterContextSP reg_ctx_sp = frame_sp->GetRegisterContext();
+if (!reg_ctx_sp)
+  continue;
+const addr_t sp = reg_ctx_sp->GetSP();
+const size_t red_zone = process.GetABI()->GetRedZoneSize();
+lldb_private::MemoryRegionInfo sp_region;
+if (process.GetMemoryRegionInfo(sp, sp_region).Success()) {
+  const size_t stack_head = (sp - red_zone);
+  const size_t stack_size = sp_region.GetRange().GetRangeEnd() - 
stack_head;
+  sp_region.GetRange().SetRangeBase(stack_head);
+  sp_region.GetRange().SetByteSize(stack_size);
+  stack_ends.i

[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread Greg Clayton via lldb-commits

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


[Lldb-commits] [lldb] [LLDB/Coredump] Only take the Pthread from stack start to the stackpointer + red_zone (PR #92002)

2024-05-16 Thread via lldb-commits

github-actions[bot] wrote:



@Jlalond 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/92002
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][breakpoint] Grey out disabled breakpoints (PR #91404)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

The stream already knows whether color support is enabled, but it looks like 
we're only storing that in the underlying llvm stream, which is commonly used 
in combination with `WithColor`. I think we could add a member to check if the 
stream has colors enabled. It's already a property of `m_forwarder` so we don't 
need to create a new member. 

```
SBStream::HasColor() {
  return m_forwarded.has_color();
}
```

Alternatively, we could add a helper that does that under the hood. 

```
SBStream::FormatAnsiTerminalCodes(llvm::StringRef format) {
  if (m_forwarded.has_color()) 
print(FormatAnsiTerminalCodes(format));
}
```

So instead of having to write:

```
if(s->HasColor())
 s->Printf("%s", ansi::FormatAnsiTerminalCodes("${ansi.faint}").c_str());
```

You can just write:

```
s-> FormatAnsiTerminalCodes("${ansi.faint}") 
```

and have it do the right thing.
```

I think I understand Jim's concern. Most places that we use colors, we do that 
through `WithColor` which checks the color property of the underlying LLVM 
stream. Chelsea is not going through WithColor, so in her case she would indeed 
need to check 

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


[Lldb-commits] [lldb] SBDebugger: Add new APIs `AddDestroyCallback` and `RemoveDestroyCallback` (PR #89868)

2024-05-16 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/92470

None

>From 3bd3650ad624c1d45b118eb1d5bebc2732371b9d Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 16 May 2024 15:46:36 -0700
Subject: [PATCH] [lldb] Include SBLanguages in the SWIG bindings

---
 lldb/bindings/CMakeLists.txt  | 2 ++
 lldb/bindings/headers.swig| 1 +
 lldb/bindings/interfaces.swig | 1 +
 3 files changed, 4 insertions(+)

diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
index 296eae1ae77f8..438643004c3fa 100644
--- a/lldb/bindings/CMakeLists.txt
+++ b/lldb/bindings/CMakeLists.txt
@@ -2,6 +2,7 @@ file(GLOB SWIG_INTERFACES interface/*.i)
 file(GLOB_RECURSE SWIG_SOURCES *.swig)
 file(GLOB SWIG_HEADERS
   ${LLDB_SOURCE_DIR}/include/lldb/API/*.h
+  ${LLDB_BINARY_DIR}/include/lldb/API/*.h
   ${LLDB_SOURCE_DIR}/include/lldb/*.h
 )
 file(GLOB SWIG_PRIVATE_HEADERS
@@ -30,6 +31,7 @@ set(SWIG_COMMON_FLAGS
   -w361,362,509
   -features autodoc
   -I${LLDB_SOURCE_DIR}/include
+  -I${LLDB_BINARY_DIR}/include
   -I${CMAKE_CURRENT_SOURCE_DIR}
   ${DARWIN_EXTRAS}
 )
diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..ffdc3c31ec883 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -36,6 +36,7 @@
 #include "lldb/API/SBHostOS.h"
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBInstructionList.h"
+#include "lldb/API/SBLanguages.h"
 #include "lldb/API/SBLanguageRuntime.h"
 #include "lldb/API/SBLaunchInfo.h"
 #include "lldb/API/SBLineEntry.h"
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index a31a0b4af1eb6..2a29a8dd7ef0b 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -114,6 +114,7 @@
 %include "lldb/API/SBHostOS.h"
 %include "lldb/API/SBInstruction.h"
 %include "lldb/API/SBInstructionList.h"
+%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLanguageRuntime.h"
 %include "lldb/API/SBLaunchInfo.h"
 %include "lldb/API/SBLineEntry.h"

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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes



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


3 Files Affected:

- (modified) lldb/bindings/CMakeLists.txt (+2) 
- (modified) lldb/bindings/headers.swig (+1) 
- (modified) lldb/bindings/interfaces.swig (+1) 


``diff
diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
index 296eae1ae77f8..438643004c3fa 100644
--- a/lldb/bindings/CMakeLists.txt
+++ b/lldb/bindings/CMakeLists.txt
@@ -2,6 +2,7 @@ file(GLOB SWIG_INTERFACES interface/*.i)
 file(GLOB_RECURSE SWIG_SOURCES *.swig)
 file(GLOB SWIG_HEADERS
   ${LLDB_SOURCE_DIR}/include/lldb/API/*.h
+  ${LLDB_BINARY_DIR}/include/lldb/API/*.h
   ${LLDB_SOURCE_DIR}/include/lldb/*.h
 )
 file(GLOB SWIG_PRIVATE_HEADERS
@@ -30,6 +31,7 @@ set(SWIG_COMMON_FLAGS
   -w361,362,509
   -features autodoc
   -I${LLDB_SOURCE_DIR}/include
+  -I${LLDB_BINARY_DIR}/include
   -I${CMAKE_CURRENT_SOURCE_DIR}
   ${DARWIN_EXTRAS}
 )
diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..ffdc3c31ec883 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -36,6 +36,7 @@
 #include "lldb/API/SBHostOS.h"
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBInstructionList.h"
+#include "lldb/API/SBLanguages.h"
 #include "lldb/API/SBLanguageRuntime.h"
 #include "lldb/API/SBLaunchInfo.h"
 #include "lldb/API/SBLineEntry.h"
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index a31a0b4af1eb6..2a29a8dd7ef0b 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -114,6 +114,7 @@
 %include "lldb/API/SBHostOS.h"
 %include "lldb/API/SBInstruction.h"
 %include "lldb/API/SBInstructionList.h"
+%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLanguageRuntime.h"
 %include "lldb/API/SBLaunchInfo.h"
 %include "lldb/API/SBLineEntry.h"

``




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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread Alex Langford via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread Alex Langford via lldb-commits

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

Actually, this has no dependency tracking. You'll need to add that for this to 
work every time.

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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> Actually, this has no dependency tracking. You'll need to add that for this 
> to work every time.

It does actually, that's what the `SWIG_HEADERS` glob is used for. 

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


[Lldb-commits] [lldb] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)

2024-05-16 Thread via lldb-commits


@@ -0,0 +1,93 @@
+//===-- ThreadPlanSingleThreadTimeout.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 LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+#define LLDB_TARGET_THREADPLANSINGLETHREADTIMEOUT_H
+
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlan.h"
+#include "lldb/Utility/Event.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/State.h"
+
+#include 
+
+namespace lldb_private {
+
+//
+// Thread plan used by single thread execution to issue timeout. This is useful
+// to detect potential deadlock in single thread execution. The timeout 
measures
+// the elapsed time from the last internal stop and got reset by each internal
+// stops to ensure we are accurately detecting execution not moving forward.
+// This means this thread plan  can be created/destroyed multiple times by the
+// parent execution plan.
+//
+// When timeout happens, the thread plan resolves the potential deadlock by
+// issuing a thread specific async interrupt to enter stop state, then all
+// threads execution are resumed to resolve the potential deadlock.
+//
+class ThreadPlanSingleThreadTimeout : public ThreadPlan {
+public:
+  ~ThreadPlanSingleThreadTimeout() override;
+
+  // Create a new instance from fresh new state.
+  static void CreateNew(Thread &thread);
+  // Reset and create a new instance from the previous state.
+  static void ResetFromPrevState(Thread &thread);
+
+  void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
+  bool ValidatePlan(Stream *error) override { return true; }
+  bool WillStop() override;
+  void DidPop() override;
+
+  bool DoPlanExplainsStop(Event *event_ptr) override;
+
+  lldb::StateType GetPlanRunState() override;
+  static void TimeoutThreadFunc(ThreadPlanSingleThreadTimeout *self);
+
+  bool MischiefManaged() override;
+
+  bool ShouldStop(Event *event_ptr) override;
+  void SetStopOthers(bool new_value) override;
+  bool StopOthers() override;
+
+private:
+  ThreadPlanSingleThreadTimeout(Thread &thread);
+
+  static bool IsAlive();
+
+  enum class State {
+WaitTimeout,// Waiting for timeout.
+AsyncInterrupt, // Async interrupt has been issued.
+Done,   // Finished resume all threads.
+  };
+
+  static std::mutex s_mutex;

jimingham wrote:

That would be better, but if you find you do need a singleton, you could also 
store that either in the Thread or the Process, depending on the scope at which 
you need them.

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


[Lldb-commits] [lldb] [lldb-dap] Correctly detect alias commands with arguments in repl (PR #92137)

2024-05-16 Thread John Harrison via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/92470

>From 3bd3650ad624c1d45b118eb1d5bebc2732371b9d Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 16 May 2024 15:46:36 -0700
Subject: [PATCH 1/2] [lldb] Include SBLanguages in the SWIG bindings

---
 lldb/bindings/CMakeLists.txt  | 2 ++
 lldb/bindings/headers.swig| 1 +
 lldb/bindings/interfaces.swig | 1 +
 3 files changed, 4 insertions(+)

diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
index 296eae1ae77f8..438643004c3fa 100644
--- a/lldb/bindings/CMakeLists.txt
+++ b/lldb/bindings/CMakeLists.txt
@@ -2,6 +2,7 @@ file(GLOB SWIG_INTERFACES interface/*.i)
 file(GLOB_RECURSE SWIG_SOURCES *.swig)
 file(GLOB SWIG_HEADERS
   ${LLDB_SOURCE_DIR}/include/lldb/API/*.h
+  ${LLDB_BINARY_DIR}/include/lldb/API/*.h
   ${LLDB_SOURCE_DIR}/include/lldb/*.h
 )
 file(GLOB SWIG_PRIVATE_HEADERS
@@ -30,6 +31,7 @@ set(SWIG_COMMON_FLAGS
   -w361,362,509
   -features autodoc
   -I${LLDB_SOURCE_DIR}/include
+  -I${LLDB_BINARY_DIR}/include
   -I${CMAKE_CURRENT_SOURCE_DIR}
   ${DARWIN_EXTRAS}
 )
diff --git a/lldb/bindings/headers.swig b/lldb/bindings/headers.swig
index e8d0cda288141..ffdc3c31ec883 100644
--- a/lldb/bindings/headers.swig
+++ b/lldb/bindings/headers.swig
@@ -36,6 +36,7 @@
 #include "lldb/API/SBHostOS.h"
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBInstructionList.h"
+#include "lldb/API/SBLanguages.h"
 #include "lldb/API/SBLanguageRuntime.h"
 #include "lldb/API/SBLaunchInfo.h"
 #include "lldb/API/SBLineEntry.h"
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index a31a0b4af1eb6..2a29a8dd7ef0b 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -114,6 +114,7 @@
 %include "lldb/API/SBHostOS.h"
 %include "lldb/API/SBInstruction.h"
 %include "lldb/API/SBInstructionList.h"
+%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLanguageRuntime.h"
 %include "lldb/API/SBLaunchInfo.h"
 %include "lldb/API/SBLineEntry.h"

>From 3bb203846499f5530266c0fb7cd2779e03c0bb0a Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 16 May 2024 16:37:40 -0700
Subject: [PATCH 2/2] Don't glob for SBLanguages.h as it may not exist yet

---
 lldb/bindings/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
index 438643004c3fa..bec694e43bd7b 100644
--- a/lldb/bindings/CMakeLists.txt
+++ b/lldb/bindings/CMakeLists.txt
@@ -2,8 +2,8 @@ file(GLOB SWIG_INTERFACES interface/*.i)
 file(GLOB_RECURSE SWIG_SOURCES *.swig)
 file(GLOB SWIG_HEADERS
   ${LLDB_SOURCE_DIR}/include/lldb/API/*.h
-  ${LLDB_BINARY_DIR}/include/lldb/API/*.h
   ${LLDB_SOURCE_DIR}/include/lldb/*.h
+  ${LLDB_BINARY_DIR}/include/lldb/API/SBLanguages.h
 )
 file(GLOB SWIG_PRIVATE_HEADERS
   ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h

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


[Lldb-commits] [lldb] [lldb] Include SBLanguages in the SWIG bindings (PR #92470)

2024-05-16 Thread Alex Langford via lldb-commits

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

Ok, that should work. CMake knows about SBLanguages.h since there are rules to 
generate it.

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


[Lldb-commits] [lldb] [lldb-dap] Updating VariableDescription to use GetDescription() as a fallback. (PR #77026)

2024-05-16 Thread John Harrison via lldb-commits

ashgti wrote:

I just checked and I'm not seeing the hover's in the same format as they were 
when I made the pull request. The expression context should still have the 
expanded forms though for example:

https://github.com/llvm/llvm-project/assets/22535/28db4adc-d488-44ff-8d99-78966e0e0e05";>

I think the VSCode team is working on making the Debug view more extensible for 
visualizations, see 
https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.debugVisualization.d.ts
 and https://github.com/microsoft/vscode/issues/197287

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


[Lldb-commits] [lldb] SBDebugger: Add new APIs `AddDestroyCallback` and `RemoveDestroyCallback` (PR #89868)

2024-05-16 Thread via lldb-commits

https://github.com/royitaqi updated 
https://github.com/llvm/llvm-project/pull/89868

>From 079a550481d4cdcb69ad01c376b5e1f0632a07d6 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Tue, 23 Apr 2024 18:10:21 -0700
Subject: [PATCH 01/18] Allow multiple destroy callbacks in
 `SBDebugger::SetDestroyCallback()`

---
 lldb/include/lldb/Core/Debugger.h |  4 ++--
 lldb/source/Core/Debugger.cpp | 10 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 418c2403d020f..20884f954ec7d 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -731,8 +731,8 @@ class Debugger : public 
std::enable_shared_from_this,
   lldb::TargetSP m_dummy_target_sp;
   Diagnostics::CallbackID m_diagnostics_callback_id;
 
-  lldb_private::DebuggerDestroyCallback m_destroy_callback = nullptr;
-  void *m_destroy_callback_baton = nullptr;
+  std::vector>
+   m_destroy_callback_and_baton;
 
   uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
   std::mutex m_interrupt_mutex;
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 19b3cf3bbf46b..0ebdf2b0a0f97 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -743,10 +743,11 @@ DebuggerSP 
Debugger::CreateInstance(lldb::LogOutputCallback log_callback,
 }
 
 void Debugger::HandleDestroyCallback() {
-  if (m_destroy_callback) {
-m_destroy_callback(GetID(), m_destroy_callback_baton);
-m_destroy_callback = nullptr;
+  const lldb::user_id_t user_id = GetID();
+  for (const auto &callback_and_baton : m_destroy_callback_and_baton) {
+callback_and_baton.first(user_id, callback_and_baton.second);
   }
+  m_destroy_callback_and_baton.clear();
 }
 
 void Debugger::Destroy(DebuggerSP &debugger_sp) {
@@ -1427,8 +1428,7 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback 
log_callback,
 
 void Debugger::SetDestroyCallback(
 lldb_private::DebuggerDestroyCallback destroy_callback, void *baton) {
-  m_destroy_callback = destroy_callback;
-  m_destroy_callback_baton = baton;
+  m_destroy_callback_and_baton.emplace_back(destroy_callback, baton);
 }
 
 static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,

>From 771b52723be8d0ffecaf8f0818105cfdb82ba332 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Tue, 23 Apr 2024 21:05:58 -0700
Subject: [PATCH 02/18] Fix code format

---
 lldb/include/lldb/Core/Debugger.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 20884f954ec7d..af025219b0bc1 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -732,7 +732,7 @@ class Debugger : public 
std::enable_shared_from_this,
   Diagnostics::CallbackID m_diagnostics_callback_id;
 
   std::vector>
-   m_destroy_callback_and_baton;
+  m_destroy_callback_and_baton;
 
   uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
   std::mutex m_interrupt_mutex;

>From d1f13cad8a3789a994572459893b32a225ba3e1b Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Wed, 24 Apr 2024 11:55:16 -0700
Subject: [PATCH 03/18] Add `AddDestroyCallback()` and `ClearDestroyCallback()`

---
 lldb/include/lldb/Core/Debugger.h | 11 +++
 lldb/source/Core/Debugger.cpp | 12 +++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index af025219b0bc1..5b3e433f09c68 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -568,10 +568,21 @@ class Debugger : public 
std::enable_shared_from_this,
 
   static void ReportSymbolChange(const ModuleSpec &module_spec);
 
+  /// Add a callback for when the debugger is destroyed. A list is maintained
+  /// internally.
+  void
+  AddDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback,
+ void *baton);
+
+  /// Clear the list of callbacks, then add the callback.
   void
   SetDestroyCallback(lldb_private::DebuggerDestroyCallback destroy_callback,
  void *baton);
 
+  /// Clear the list of callbacks.
+  void
+  ClearDestroyCallback();
+
   /// Manually start the global event handler thread. It is useful to plugins
   /// that directly use the \a lldb_private namespace and want to use the
   /// debugger's default event handler thread instead of defining their own.
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 0ebdf2b0a0f97..159913642f253 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1426,11 +1426,21 @@ void 
Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
   std::make_shared(log_callback, baton);
 }
 
-void Debugger::SetDestroyCallback(
+void Debugger::AddDestroyCallback(
 lldb_private::DebuggerDestroyCallback destroy_callback, void *b

  1   2   >