[Lldb-commits] [lldb] 3af6c9f - [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (#131544)
Author: Ebuka Ezike Date: 2025-03-17T07:58:55Z New Revision: 3af6c9fa832ac29125cad76acb397d6235c371e9 URL: https://github.com/llvm/llvm-project/commit/3af6c9fa832ac29125cad76acb397d6235c371e9 DIFF: https://github.com/llvm/llvm-project/commit/3af6c9fa832ac29125cad76acb397d6235c371e9.diff LOG: [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (#131544) The logging markers for incoming ("<--") and outgoing ("-->") messages were incorrectly reversed. from #7790d69 Added: Modified: lldb/tools/lldb-dap/Transport.cpp Removed: diff --git a/lldb/tools/lldb-dap/Transport.cpp b/lldb/tools/lldb-dap/Transport.cpp index db2d7228d3fb7..a721662a345eb 100644 --- a/lldb/tools/lldb-dap/Transport.cpp +++ b/lldb/tools/lldb-dap/Transport.cpp @@ -103,7 +103,7 @@ Expected> Transport::Read() { if (raw_json->length() != length) return createStringError("unexpected EOF parse DAP message body"); - DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, *raw_json); + DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, *raw_json); return json::parse(*raw_json); } @@ -114,7 +114,7 @@ Error Transport::Write(const Message &message) { std::string json = formatv("{0}", toJSON(message)).str(); - DAP_LOG(m_log, "--> ({0}) {1}", m_client_name, json); + DAP_LOG(m_log, "<-- ({0}) {1}", m_client_name, json); std::string Output; raw_string_ostream OS(Output); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
@@ -0,0 +1,64 @@ +//===-- SBLockTest.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/SBLock.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBTarget.h" +#include "gtest/gtest.h" +#include +#include +#include + +TEST(SBLockTest, LockTest) { + lldb::SBDebugger debugger = lldb::SBDebugger::Create(); + lldb::SBTarget target = debugger.GetDummyTarget(); + + std::mutex m; + std::condition_variable cv; + bool wakeup = false; + std::atomic locked = false; + + std::thread test_thread([&]() { +{ + { +std::unique_lock lk(m); +cv.wait(lk, [&] { return wakeup; }); + } labath wrote: maybe use `std::future` instead? https://github.com/llvm/llvm-project/pull/131404 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
@@ -0,0 +1,35 @@ +//===-- SBLock.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/SBLock.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/Instrumentation.h" +#include "lldb/lldb-forward.h" + +#include +#include + +using namespace lldb; +using namespace lldb_private; + +#ifndef SWIG labath wrote: I'm pretty sure these are only needed in headers. https://github.com/llvm/llvm-project/pull/131404 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
yuvald-sweet-security wrote: > I'm wondering if the right fix isn't to call > `FileSystem::ResolveExecutableLocation` on `argv[0]`. That should should give > us more-or-less the same algorithm that the shell used when starting > lldb-server. Perhaps, but note that technically argv[0] doesn't really have to be related to the name of the executable at all - the user can pretty much pass whatever value they want as argv[0] when calling execve (although I agree that it would be a very peculiar workflow for someone to run lldb-server with an argv[0] that isn't the name of the binary). On another note, I am currently debugging few other regressions introduced in LLDB 20 that relate to the way the platform mode server executes another server internally. For example, while this patch makes `lldb-server` work as intended if e.g. installed to `/usr/local/bin/lldb-server`, if I install it as `/usr/local/bin/not-lldb-server`, then it functions right when invoked as `not-lldb-server` but does *not* function right if invoked with an absolute path because LLDB does not correctly deduce the support exe directory, which is very curious behaviour indeed: ``` $ sudo ln -s /home/user/random/llvm-project/build/bin/lldb-server /usr/local/bin/not-lldb-server $ not-lldb-server platform --server --listen '*:1338' --log-channels "lldb all" Listen to [*]:1338 Listen to [*]:0 Connection established. started monitoring child process. lldb-platform launched '/home/user/random/llvm-project/build/bin/lldb-server platform --child-platform-fd 8 --gdbserver-port 37663 --log-channels lldb all', pid=49632 thread created 0x587b5409a160 Socket::Close (fd = 8) pid = 49632 ::waitpid(49632, &status, 0)... Launching debugserver url='', fd=8... shlib dir -> `(empty)` support exe dir -> `/home/user/random/llvm-project/build/bin/` started monitoring child process. thread created GDBRemoteCommunicationServerPlatform::LaunchGDBServer() debugserver launched successfully as pid 49672 pid = 49672 ::waitpid(49672, &status, 0)... 0x7FFE94504A88 Communication::Disconnect () 0x587b5409d900 Socket::Close (fd = 8) ::waitpid(49672, &status, 0) => pid = 49672, status = 0x0 pid = 49672 thread exiting... ^C $ /usr/local/bin/not-lldb-server platform --server --listen '*:1338' --log-channels "lldb all" Listen to [*]:1338 Listen to [*]:0 Connection established. started monitoring child process. lldb-platform launched '/home/user/random/llvm-project/build/bin/lldb-server platform --child-platform-fd 8 --gdbserver-port 40461 --log-channels lldb all', pid=49799 0x5d0837133160 Socket::Close (fd = 8) thread created pid = 49799 ::waitpid(49799, &status, 0)... Launching debugserver url='', fd=8... shlib dir -> `/usr/local/bin/` Attempting to derive the path /bin relative to liblldb install path: /usr/local/bin Derived the path as: /usr/local/bin support exe dir -> `/usr/local/bin/` GDBRemoteCommunicationServerPlatform::LaunchGDBServer() debugserver launch failed: unable to locate lldb-server 0x7FFE655B2738 Communication::Disconnect () 0x5d0837136900 Socket::Close (fd = 8) Launching debugserver url='', fd=8... GDBRemoteCommunicationServerPlatform::LaunchGDBServer() debugserver launch failed: unable to locate lldb-server 0x7FFE655B2738 Communication::Disconnect () 0x5d083716e340 Socket::Close (fd = 8) ``` (This is an important workflow because that is precisely the way that lldb-server gets installed in distro packaging, e.g. `lldb-server-20` links to the `lldb-server` binary in the LLVM installation directory) https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Fix tests windows (PR #131600)
https://github.com/AlexK0 created https://github.com/llvm/llvm-project/pull/131600 Hello, I'm working on LLDB on Windows and have encountered some issues with the tests. 1) Many tests fail to start on Windows due to an import exception: ``` Traceback (most recent call last): File "D:\Projects\github\llvm-project-fork\lldb\test\API\dotest.py", line 8, in lldbsuite.test.run_suite() File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\dotest.py", line 1042, in run_suite checkLibcxxSupport() File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\dotest.py", line 799, in checkLibcxxSupport result, reason = canRunLibcxxTests() File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\dotest.py", line 770, in canRunLibcxxTests from lldbsuite.test import lldbplatformutil File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\lldbplatformutil.py", line 11, in from packaging import version ModuleNotFoundError: No module named 'packaging' ``` I think this exception occurs due to missing environment variables. I fixed the test setup to use the original environment variables. 2) `file` utility is not available on Windows, so I fixed the test to use `test -d` instead. 3) There is a minor difference in the watchpoint error message on Windows. Please take a look. Thanks! >From 9734adfcca5d1d5cfdba85dc0bfe76d230106c11 Mon Sep 17 00:00:00 2001 From: Aleksandr Korepanov Date: Mon, 17 Mar 2025 11:03:57 +0100 Subject: [PATCH 1/2] [LLDB][tests] Use original env for running tests On Windows without the original environment, the test framework cannot import the 'packaging' module. --- lldb/test/API/lldbtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/lldbtest.py b/lldb/test/API/lldbtest.py index d6b79ebc2c434..f32c2ac61537f 100644 --- a/lldb/test/API/lldbtest.py +++ b/lldb/test/API/lldbtest.py @@ -63,7 +63,7 @@ def execute(self, test, litConfig): try: out, err, exitCode = lit.util.executeCommand( cmd, -env=test.config.environment, +env={**os.environ, **test.config.environment}, timeout=litConfig.maxIndividualTestTime, ) except lit.util.ExecuteCommandTimeoutException as e: >From 959c86f9cee6bedadc32bb99574b4fdfac37f0fd Mon Sep 17 00:00:00 2001 From: Aleksandr Korepanov Date: Mon, 17 Mar 2025 11:06:46 +0100 Subject: [PATCH 2/2] [LLDB][tests] Fix tests for Windows - On Windows there is different error message on setting watchpoint. - Use 'test -d' to check for a directory instead of 'file' because Windows does not have the 'file' utility. --- .../watchlocation/TestTargetWatchAddress.py | 17 - lldb/test/Shell/Diagnostics/TestDump.test | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py index 7a0e42a4fc278..5f7be87322b02 100644 --- a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py +++ b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py @@ -201,8 +201,15 @@ def test_watch_address_with_invalid_watch_size(self): value.GetValueAsUnsigned(), 365, wp_opts, error ) self.assertFalse(watchpoint) -self.expect( -error.GetCString(), -exe=False, -substrs=["Setting one of the watchpoint resources failed"], -) +if self.getPlatform() == 'windows': +self.expect( +error.GetCString(), +exe=False, +substrs=["Can't enable watchpoint"], +) +else: +self.expect( +error.GetCString(), +exe=False, +substrs=["Setting one of the watchpoint resources failed"], +) diff --git a/lldb/test/Shell/Diagnostics/TestDump.test b/lldb/test/Shell/Diagnostics/TestDump.test index 2adde6b86d35a..ae298eeb4 100644 --- a/lldb/test/Shell/Diagnostics/TestDump.test +++ b/lldb/test/Shell/Diagnostics/TestDump.test @@ -5,11 +5,11 @@ # RUN: rm -rf %t.existing # RUN: mkdir -p %t.existing # RUN: %lldb -o 'diagnostics dump -d %t.existing' -# RUN: file %t.existing | FileCheck %s +# RUN: test -d %t.existing && echo "directory" | FileCheck %s # Dump to a non-existing directory. # RUN: rm -rf %t.nonexisting # RUN: %lldb -o 'diagnostics dump -d %t.nonexisting' -# RUN: file %t.nonexisting | FileCheck %s +# RUN: test -d %t.nonexisting && echo "directory" | FileCheck %s # CHECK: directory ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.ll
[Lldb-commits] [lldb] [LLDB] Fix tests windows (PR #131600)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Aleksandr Korepanov (AlexK0) Changes Hello, I'm working on LLDB on Windows and have encountered some issues with the tests. 1) Many tests fail to start on Windows due to an import exception: ``` Traceback (most recent call last): File "D:\Projects\github\llvm-project-fork\lldb\test\API\dotest.py", line 8, inlldbsuite.test.run_suite() File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\dotest.py", line 1042, in run_suite checkLibcxxSupport() File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\dotest.py", line 799, in checkLibcxxSupport result, reason = canRunLibcxxTests() File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\dotest.py", line 770, in canRunLibcxxTests from lldbsuite.test import lldbplatformutil File "D:\Projects\github\llvm-project-fork\lldb\packages\Python\lldbsuite\test\lldbplatformutil.py", line 11, in from packaging import version ModuleNotFoundError: No module named 'packaging' ``` I think this exception occurs due to missing environment variables. I fixed the test setup to use the original environment variables. 2) `file` utility is not available on Windows, so I fixed the test to use `test -d` instead. 3) There is a minor difference in the watchpoint error message on Windows. Please take a look. Thanks! --- Full diff: https://github.com/llvm/llvm-project/pull/131600.diff 3 Files Affected: - (modified) lldb/test/API/lldbtest.py (+1-1) - (modified) lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py (+12-5) - (modified) lldb/test/Shell/Diagnostics/TestDump.test (+2-2) ``diff diff --git a/lldb/test/API/lldbtest.py b/lldb/test/API/lldbtest.py index d6b79ebc2c434..f32c2ac61537f 100644 --- a/lldb/test/API/lldbtest.py +++ b/lldb/test/API/lldbtest.py @@ -63,7 +63,7 @@ def execute(self, test, litConfig): try: out, err, exitCode = lit.util.executeCommand( cmd, -env=test.config.environment, +env={**os.environ, **test.config.environment}, timeout=litConfig.maxIndividualTestTime, ) except lit.util.ExecuteCommandTimeoutException as e: diff --git a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py index 7a0e42a4fc278..5f7be87322b02 100644 --- a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py +++ b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py @@ -201,8 +201,15 @@ def test_watch_address_with_invalid_watch_size(self): value.GetValueAsUnsigned(), 365, wp_opts, error ) self.assertFalse(watchpoint) -self.expect( -error.GetCString(), -exe=False, -substrs=["Setting one of the watchpoint resources failed"], -) +if self.getPlatform() == 'windows': +self.expect( +error.GetCString(), +exe=False, +substrs=["Can't enable watchpoint"], +) +else: +self.expect( +error.GetCString(), +exe=False, +substrs=["Setting one of the watchpoint resources failed"], +) diff --git a/lldb/test/Shell/Diagnostics/TestDump.test b/lldb/test/Shell/Diagnostics/TestDump.test index 2adde6b86d35a..ae298eeb4 100644 --- a/lldb/test/Shell/Diagnostics/TestDump.test +++ b/lldb/test/Shell/Diagnostics/TestDump.test @@ -5,11 +5,11 @@ # RUN: rm -rf %t.existing # RUN: mkdir -p %t.existing # RUN: %lldb -o 'diagnostics dump -d %t.existing' -# RUN: file %t.existing | FileCheck %s +# RUN: test -d %t.existing && echo "directory" | FileCheck %s # Dump to a non-existing directory. # RUN: rm -rf %t.nonexisting # RUN: %lldb -o 'diagnostics dump -d %t.nonexisting' -# RUN: file %t.nonexisting | FileCheck %s +# RUN: test -d %t.nonexisting && echo "directory" | FileCheck %s # CHECK: directory `` https://github.com/llvm/llvm-project/pull/131600 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)
https://github.com/AlexK0 edited https://github.com/llvm/llvm-project/pull/131600 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 7dcea28bf92e49737fa285e93621cfa814323524...959c86f9cee6bedadc32bb99574b4fdfac37f0fd lldb/test/API/lldbtest.py lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py `` View the diff from darker here. ``diff --- python_api/watchpoint/watchlocation/TestTargetWatchAddress.py 2025-03-17 10:35:10.00 + +++ python_api/watchpoint/watchlocation/TestTargetWatchAddress.py 2025-03-17 10:43:04.544698 + @@ -199,11 +199,11 @@ wp_opts.SetWatchpointTypeWrite(lldb.eWatchpointWriteTypeOnModify) watchpoint = target.WatchpointCreateByAddress( value.GetValueAsUnsigned(), 365, wp_opts, error ) self.assertFalse(watchpoint) -if self.getPlatform() == 'windows': +if self.getPlatform() == "windows": self.expect( error.GetCString(), exe=False, substrs=["Can't enable watchpoint"], ) `` https://github.com/llvm/llvm-project/pull/131600 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)
https://github.com/AlexK0 updated https://github.com/llvm/llvm-project/pull/131600 >From 9734adfcca5d1d5cfdba85dc0bfe76d230106c11 Mon Sep 17 00:00:00 2001 From: Aleksandr Korepanov Date: Mon, 17 Mar 2025 11:03:57 +0100 Subject: [PATCH 1/2] [LLDB][tests] Use original env for running tests On Windows without the original environment, the test framework cannot import the 'packaging' module. --- lldb/test/API/lldbtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/lldbtest.py b/lldb/test/API/lldbtest.py index d6b79ebc2c434..f32c2ac61537f 100644 --- a/lldb/test/API/lldbtest.py +++ b/lldb/test/API/lldbtest.py @@ -63,7 +63,7 @@ def execute(self, test, litConfig): try: out, err, exitCode = lit.util.executeCommand( cmd, -env=test.config.environment, +env={**os.environ, **test.config.environment}, timeout=litConfig.maxIndividualTestTime, ) except lit.util.ExecuteCommandTimeoutException as e: >From 8f265ddd0a164455931c9ea4cec5b9664b15a304 Mon Sep 17 00:00:00 2001 From: Aleksandr Korepanov Date: Mon, 17 Mar 2025 11:06:46 +0100 Subject: [PATCH 2/2] [LLDB][tests] Fix tests for Windows - On Windows there is different error message on setting watchpoint. - Use 'test -d' to check for a directory instead of 'file' because Windows does not have the 'file' utility. --- .../watchlocation/TestTargetWatchAddress.py | 17 - lldb/test/Shell/Diagnostics/TestDump.test | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py index 7a0e42a4fc278..ba62daa01fb51 100644 --- a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py +++ b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py @@ -201,8 +201,15 @@ def test_watch_address_with_invalid_watch_size(self): value.GetValueAsUnsigned(), 365, wp_opts, error ) self.assertFalse(watchpoint) -self.expect( -error.GetCString(), -exe=False, -substrs=["Setting one of the watchpoint resources failed"], -) +if self.getPlatform() == "windows": +self.expect( +error.GetCString(), +exe=False, +substrs=["Can't enable watchpoint"], +) +else: +self.expect( +error.GetCString(), +exe=False, +substrs=["Setting one of the watchpoint resources failed"], +) diff --git a/lldb/test/Shell/Diagnostics/TestDump.test b/lldb/test/Shell/Diagnostics/TestDump.test index 2adde6b86d35a..ae298eeb4 100644 --- a/lldb/test/Shell/Diagnostics/TestDump.test +++ b/lldb/test/Shell/Diagnostics/TestDump.test @@ -5,11 +5,11 @@ # RUN: rm -rf %t.existing # RUN: mkdir -p %t.existing # RUN: %lldb -o 'diagnostics dump -d %t.existing' -# RUN: file %t.existing | FileCheck %s +# RUN: test -d %t.existing && echo "directory" | FileCheck %s # Dump to a non-existing directory. # RUN: rm -rf %t.nonexisting # RUN: %lldb -o 'diagnostics dump -d %t.nonexisting' -# RUN: file %t.nonexisting | FileCheck %s +# RUN: test -d %t.nonexisting && echo "directory" | FileCheck %s # CHECK: directory ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC]Refactor common test setup into SetUp method (PR #131203)
@@ -81,6 +81,20 @@ using namespace lldb_private::telemetry; class TelemetryTest : public testing::Test { public: lldb_private::SubsystemRAII subsystems; + std::vector> + received_entries; + + void SetUp() override { +// This would have been called by the plugin reg in a "real" pluging +// For tests, we just call it directly. +lldb_private::FakePlugin::Initialize(); oontvoo wrote: done https://github.com/llvm/llvm-project/pull/131203 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131609 >From a4e2c9f4fca115cc52ee69abfa584795b7102716 Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Mon, 17 Mar 2025 14:37:26 +0200 Subject: [PATCH] [lldb] Use correct path for debugserver --- lldb/tools/lldb-server/SystemInitializerLLGS.h | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-server/SystemInitializerLLGS.h b/lldb/tools/lldb-server/SystemInitializerLLGS.h index 4469a8ba5f60a..c6020b0dd37da 100644 --- a/lldb/tools/lldb-server/SystemInitializerLLGS.h +++ b/lldb/tools/lldb-server/SystemInitializerLLGS.h @@ -11,10 +11,17 @@ #include "lldb/Initialization/SystemInitializer.h" #include "lldb/Initialization/SystemInitializerCommon.h" +#include "lldb/Utility/FileSpec.h" class SystemInitializerLLGS : public lldb_private::SystemInitializerCommon { public: - SystemInitializerLLGS() : SystemInitializerCommon(nullptr) {} + SystemInitializerLLGS() + : SystemInitializerCommon( +// Finding the shared libraries directory on lldb-server is broken +// since lldb-server isn't dynamically linked with liblldb.so. +// Clearing the filespec here causes GetShlibDir to fail and +// GetSupportExeDir to fall-back to using the binary path instead. +[](lldb_private::FileSpec &file) { file.Clear(); }) {} llvm::Error Initialize() override; void Terminate() override; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
yuvald-sweet-security wrote: Well, looks like the tests really do check a case where lldb and lldb-server are not in the same directory. Should we just try both paths? maybe make `GetShlibDir` return false if it is linked statically? https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Added the interface DWARFUnitInterface to break dependencies and reduce lldb-server size (PR #131645)
https://github.com/slydiman created https://github.com/llvm/llvm-project/pull/131645 This patch addresses the issue #129543. After this patch DWARFExpression does not call DWARFUnit directly and does not depend on lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp and a lot of clang code. After this patch the size of lldb-server binary (Linux Aarch64) is reduced from 42MB to 13MB with LLVM 20.0.0 and from 47MB to 17MB with LLVM 21.0.0. >From 464460db7550673bac788ad11e3ed4d45946cd71 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilyev Date: Mon, 17 Mar 2025 19:13:20 +0400 Subject: [PATCH] [LLDB][NFC] Added the interface DWARFUnitInterface to break dependencies and reduce lldb-server size This patch addresses the issue #129543. After this patch DWARFExpression does not call DWARFUnit directly and does not depend on lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp and a lot of clang code. After this patch the size of lldb-server binary (Linux Aarch64) is reduced from 42MB to 13MB with LLVM 20.0.0 and from 47MB to 17MB with LLVM 21.0.0. --- .../include/lldb/Expression/DWARFExpression.h | 23 lldb/source/Expression/DWARFExpression.cpp| 55 ++- .../SymbolFile/DWARF/DWARFFormValue.cpp | 6 +- .../Plugins/SymbolFile/DWARF/DWARFUnit.cpp| 39 ++--- .../Plugins/SymbolFile/DWARF/DWARFUnit.h | 50 + 5 files changed, 101 insertions(+), 72 deletions(-) diff --git a/lldb/include/lldb/Expression/DWARFExpression.h b/lldb/include/lldb/Expression/DWARFExpression.h index 2c1e717ee32eb..cf4098f2acc51 100644 --- a/lldb/include/lldb/Expression/DWARFExpression.h +++ b/lldb/include/lldb/Expression/DWARFExpression.h @@ -23,7 +23,7 @@ namespace lldb_private { namespace plugin { namespace dwarf { -class DWARFUnit; +class DWARFUnitInterface; } // namespace dwarf } // namespace plugin @@ -65,20 +65,20 @@ class DWARFExpression { /// \return /// The address specified by the operation, if the operation exists, or /// an llvm::Error otherwise. - llvm::Expected - GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu) const; + llvm::Expected GetLocation_DW_OP_addr( + const plugin::dwarf::DWARFUnitInterface *dwarf_cu) const; - bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu, + bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnitInterface *dwarf_cu, lldb::addr_t file_addr); void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size); - bool - ContainsThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu) const; + bool ContainsThreadLocalStorage( + const plugin::dwarf::DWARFUnitInterface *dwarf_cu) const; bool LinkThreadLocalStorage( - const plugin::dwarf::DWARFUnit *dwarf_cu, + const plugin::dwarf::DWARFUnitInterface *dwarf_cu, std::function const &link_address_callback); @@ -132,13 +132,14 @@ class DWARFExpression { static llvm::Expected Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, - const plugin::dwarf::DWARFUnit *dwarf_cu, + const plugin::dwarf::DWARFUnitInterface *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr); - static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu, - const DataExtractor &data, - DWARFExpressionList *loc_list); + static bool + ParseDWARFLocationList(const plugin::dwarf::DWARFUnitInterface *dwarf_cu, + const DataExtractor &data, + DWARFExpressionList *loc_list); bool GetExpressionData(DataExtractor &data) const { data = m_data; diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index f48f3ab9307dd..41fbca59db60f 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -133,7 +133,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const LocationAtom op, -const DWARFUnit *dwarf_cu) { +const DWARFUnitInterface *dwarf_cu) { lldb::offset_t offset = data_offset; switch (op) { // Only used in LLVM metadata. @@ -362,7 +362,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, // + LEB128 { data.Skip_LEB128(&offset); -return DWARFUnit::GetAddressByteSize(dwarf_cu) + offset - data_offset; +return DWARFUnitInterface::GetAdd
[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)
rocallahan wrote: The logs show the problem here: ``` AssertionError: Ran command: "thread list" Got output: Process 79916 stopped * thread #1: tid = 0x4870aa, 0x000100e0ff94 a.out`trigger_watchpoint at main.c:7:60, stop reason = instruction step into Expecting sub string: "stopped" (was found) Expecting sub string: "trigger_watchpoint" (was found) Expecting sub string: "stop reason = watchpoint 1" (was not found) ``` Basically we reverse-continue, hit a watchpoint, and that is correctly reported to the user as "stop reason = watchpoint 1". Then we singlestep forward, which on x86(-64) triggers the watchpoint, but on Arm here LLDB is reporting it to the user as "instruction step into", i.e. not reporting the watchpoint being hit. Maybe this is an x86 vs ARM issue and previous testing on ARM did not show it because we didn't run the watchpoint tests on ARM or for some other reason? https://github.com/llvm/llvm-project/pull/128156 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)
rocallahan wrote: My reverse-execution proxy code implements watchpoints during reverse execution more or less by reversing the x86 behavior: if we execute a sequence of instructions and instruction #N in the sequence modifies a watched memory location, then when reverse-executing, we stop when the PC is at the address of instruction N, i.e. with instruction N being the next instruction to be executed, and report that that watchpoint fired. (On x86 executing in the forward direction, normal debugger behavior is that execution stops with the PC set to the address of instruction N+1, i.e. after instruction N has been executed, because this is what the hardware does). This all works the same whether you're using continue or a sequence of single-steps (in either direction). As I understand it, when ARM hardware hits a watchpoint, it stops with the PC at the address of instruction #N that did the memory access, i.e. the next instruction to be executed is #N again. So that's different from x86 and maybe that's the root of our problems here. I will start an ARM64 VM and do some experiments ... maybe tomorrow. https://github.com/llvm/llvm-project/pull/128156 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
@@ -540,9 +537,9 @@ class EntityVariableBase : public Materializer::Entity { return; } -if (data.GetByteSize() < +if (data_or_err->GetByteSize() < adrian-prantl wrote: I like to add a ``` auto data = *data_or_err; ``` than there is no question about whether we forgot to check the error when accessing data. Makes to code easier to read. https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
https://github.com/adrian-prantl edited https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
@@ -207,15 +207,13 @@ lldb::ValueObjectSP lldb_private::formatters:: return lldb::ValueObjectSP(); StreamString stream; stream.Printf("[%" PRIu64 "]", (uint64_t)idx); - DataExtractor data; - Status error; - val_hash.first->GetData(data, error); - if (error.Fail()) + auto data_or_err = val_hash.first->GetData(); + if (!data_or_err) adrian-prantl wrote: same here https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
@@ -523,13 +522,11 @@ class EntityVariableBase : public Materializer::Entity { return; } } else { -DataExtractor data; -Status extract_error; -valobj_sp->GetData(data, extract_error); -if (!extract_error.Success()) { +auto data_or_err = valobj_sp->GetData(); +if (auto error = data_or_err.takeError()) { err = Status::FromErrorStringWithFormat( "couldn't get the value of %s: %s", GetName().AsCString(), - extract_error.AsCString()); + llvm::toString(std::move(error)).c_str()); adrian-prantl wrote: even nicer: ``` llvm::joinErrors(llvm::createStringError("couldn't get the value of %s:", GetName()), std::move(error)) ``` https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
@@ -1205,13 +1205,11 @@ bool lldb_private::formatters::ObjCSELSummaryProvider( valobj_sp = ValueObject::CreateValueObjectFromAddress("text", data_address, exe_ctx, charstar); } else { -DataExtractor data; -Status error; -valobj.GetData(data, error); -if (error.Fail()) +auto data_or_err = valobj.GetData(); +if (!data_or_err) return false; -valobj_sp = -ValueObject::CreateValueObjectFromData("text", data, exe_ctx, charstar); +valobj_sp = ValueObject::CreateValueObjectFromData("text", *data_or_err, adrian-prantl wrote: and here https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/130104 >From ab4e9d8a6f7146a5f9cee519f4d9787194b12b31 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Thu, 6 Mar 2025 14:13:58 +0100 Subject: [PATCH] [lldb-dap] Adding support for well typed events. This adds a mechanism for registering well typed events with the DAP. For a proof of concept, this updates the 'exited' and the 'process' event to use the new protocol serialization handlers and updates the call sites to use the new helper. --- lldb/tools/lldb-dap/CMakeLists.txt| 6 +- lldb/tools/lldb-dap/DAP.cpp | 5 +- lldb/tools/lldb-dap/DAP.h | 14 +++ lldb/tools/lldb-dap/EventHelper.cpp | 90 --- lldb/tools/lldb-dap/EventHelper.h | 6 -- lldb/tools/lldb-dap/Events/EventHandler.h | 57 .../lldb-dap/Events/ExitedEventHandler.cpp| 20 + .../lldb-dap/Events/ProcessEventHandler.cpp | 34 +++ .../lldb-dap/Handler/AttachRequestHandler.cpp | 2 +- .../Handler/InitializeRequestHandler.cpp | 2 +- .../lldb-dap/Handler/LaunchRequestHandler.cpp | 5 +- lldb/tools/lldb-dap/Protocol/ProtocolBase.h | 4 +- .../lldb-dap/Protocol/ProtocolEvents.cpp | 46 ++ lldb/tools/lldb-dap/Protocol/ProtocolEvents.h | 76 lldb/tools/lldb-dap/lldb-dap.cpp | 1 + 15 files changed, 262 insertions(+), 106 deletions(-) create mode 100644 lldb/tools/lldb-dap/Events/EventHandler.h create mode 100644 lldb/tools/lldb-dap/Events/ExitedEventHandler.cpp create mode 100644 lldb/tools/lldb-dap/Events/ProcessEventHandler.cpp create mode 100644 lldb/tools/lldb-dap/Protocol/ProtocolEvents.cpp create mode 100644 lldb/tools/lldb-dap/Protocol/ProtocolEvents.h diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt index adad75a79fa7a..54e6f3ead2695 100644 --- a/lldb/tools/lldb-dap/CMakeLists.txt +++ b/lldb/tools/lldb-dap/CMakeLists.txt @@ -37,6 +37,9 @@ add_lldb_tool(lldb-dap Transport.cpp Watchpoint.cpp + Events/ExitedEventHandler.cpp + Events/ProcessEventHandler.cpp + Handler/ResponseHandler.cpp Handler/AttachRequestHandler.cpp Handler/BreakpointLocationsHandler.cpp @@ -75,8 +78,9 @@ add_lldb_tool(lldb-dap Handler/VariablesRequestHandler.cpp Protocol/ProtocolBase.cpp - Protocol/ProtocolTypes.cpp + Protocol/ProtocolEvents.cpp Protocol/ProtocolRequests.cpp + Protocol/ProtocolTypes.cpp LINK_LIBS liblldb diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index a1e2187288768..a2ae96eb5d967 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -8,6 +8,7 @@ #include "DAP.h" #include "DAPLog.h" +#include "Events/EventHandler.h" #include "Handler/RequestHandler.h" #include "Handler/ResponseHandler.h" #include "JSONUtils.h" @@ -82,7 +83,9 @@ DAP::DAP(llvm::StringRef path, std::ofstream *log, configuration_done_sent(false), waiting_for_run_in_terminal(false), progress_event_reporter( [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }), - reverse_request_seq(0), repl_mode(default_repl_mode) {} + reverse_request_seq(0), repl_mode(default_repl_mode), + onExited(ExitedEventHandler(*this)), + onProcess(ProcessEventHandler(*this)) {} DAP::~DAP() = default; diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index 4c57f9fef3d89..fe902e670cf04 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -58,6 +58,9 @@ typedef llvm::StringMap FunctionBreakpointMap; typedef llvm::DenseMap InstructionBreakpointMap; +/// A debug adapter initiated event. +template using OutgoingEvent = std::function; + enum class OutputType { Console, Stdout, Stderr, Telemetry }; /// Buffer size for handling output events. @@ -230,6 +233,17 @@ struct DAP { void operator=(const DAP &rhs) = delete; /// @} + /// Typed Events Handlers + /// @{ + + /// onExited sends an event that the debuggee has exited. + OutgoingEvent<> onExited; + /// onProcess sends an event that indicates that the debugger has begun + /// debugging a new process. + OutgoingEvent<> onProcess; + + /// @} + ExceptionBreakpoint *GetExceptionBreakpoint(const std::string &filter); ExceptionBreakpoint *GetExceptionBreakpoint(const lldb::break_id_t bp_id); diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index 705eb0a457d9c..7908674eb4642 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -32,87 +32,6 @@ static void SendThreadExitedEvent(DAP &dap, lldb::tid_t tid) { dap.SendJSON(llvm::json::Value(std::move(event))); } -// "ProcessEvent": { -// "allOf": [ -// { "$ref": "#/definitions/Event" }, -// { -// "type": "object", -// "description": "Event message for 'process' event type. The event -//
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
adrian-prantl wrote: >I was also curious to know if I'd have to change any test code too, I've tried >to unit test but got error relating to "expected" values. Would I need to >change something in DumpValueObjectOptionsTests.cpp? Usually wrapping calls in `llvm::expectedToOptional()` is the cheapest way to just adapt the API in places where the error handling doesn't matter. You could even write a wrapper for that test that creates a Status from the error and imitates the old API, just inside the unit tests. https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)
https://github.com/ashgti edited https://github.com/llvm/llvm-project/pull/130104 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
https://github.com/adrian-prantl commented: Looks like a great start! I made a couple of suggestions inline. https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb/platform-gdb] Do not assume a persistent connection (PR #131736)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Igor Kudrin (igorkudrin) Changes After https://reviews.llvm.org/D116539, when `m_gdb_client_up` in `PlatformRemoteGDBServer` is not null, the connection to a server is expected to exist. However, `PlatformRemoteGDBServer::DisconnectRemote()` is not the only way to close the connection; `GDBRemoteCommunication::WaitForPacketNoLock()` can disconnect if the server stops responding, and in this case `m_gdb_client_up` is not cleared. The patch removes this assumption and checks the connection status directly. --- Full diff: https://github.com/llvm/llvm-project/pull/131736.diff 4 Files Affected: - (modified) lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (+1-5) - (modified) lldb/unittests/Platform/CMakeLists.txt (+1) - (added) lldb/unittests/Platform/gdb-server/CMakeLists.txt (+7) - (added) lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp (+68) ``diff diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 58d2ecd94836d..26ca6ed128972 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -206,11 +206,7 @@ bool PlatformRemoteGDBServer::SetRemoteWorkingDirectory( } bool PlatformRemoteGDBServer::IsConnected() const { - if (m_gdb_client_up) { -assert(m_gdb_client_up->IsConnected()); -return true; - } - return false; + return m_gdb_client_up && m_gdb_client_up->IsConnected(); } Status PlatformRemoteGDBServer::ConnectRemote(Args &args) { diff --git a/lldb/unittests/Platform/CMakeLists.txt b/lldb/unittests/Platform/CMakeLists.txt index 963975602d671..5c0ef5ca6ef22 100644 --- a/lldb/unittests/Platform/CMakeLists.txt +++ b/lldb/unittests/Platform/CMakeLists.txt @@ -15,3 +15,4 @@ add_lldb_unittest(LLDBPlatformTests ) add_subdirectory(Android) +add_subdirectory(gdb-server) diff --git a/lldb/unittests/Platform/gdb-server/CMakeLists.txt b/lldb/unittests/Platform/gdb-server/CMakeLists.txt new file mode 100644 index 0..41f94b06f6f2c --- /dev/null +++ b/lldb/unittests/Platform/gdb-server/CMakeLists.txt @@ -0,0 +1,7 @@ +add_lldb_unittest(PlatformGdbRemoteTests + PlatformRemoteGDBServerTest.cpp + + LINK_LIBS +lldbPluginPlatformGDB +LLVMTestingSupport + ) diff --git a/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp b/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp new file mode 100644 index 0..2ea4dac006cd8 --- /dev/null +++ b/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp @@ -0,0 +1,68 @@ +//===-- PlatformRemoteGDBServerTest.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 "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h" +#include "lldb/Utility/Connection.h" +#include "gmock/gmock.h" + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::platform_gdb_server; +using namespace lldb_private::process_gdb_remote; +using namespace testing; + +namespace { + +class PlatformRemoteGDBServerHack : public PlatformRemoteGDBServer { +public: + void + SetGDBClient(std::unique_ptr gdb_client_up) { +m_gdb_client_up = std::move(gdb_client_up); + } +}; + +class MockConnection : public lldb_private::Connection { +public: + MOCK_METHOD(lldb::ConnectionStatus, Connect, + (llvm::StringRef url, Status *error_ptr), (override)); + MOCK_METHOD(lldb::ConnectionStatus, Disconnect, (Status * error_ptr), + (override)); + MOCK_METHOD(bool, IsConnected, (), (const, override)); + MOCK_METHOD(size_t, Read, + (void *dst, size_t dst_len, const Timeout &timeout, + lldb::ConnectionStatus &status, Status *error_ptr), + (override)); + MOCK_METHOD(size_t, Write, + (const void *dst, size_t dst_len, lldb::ConnectionStatus &status, + Status *error_ptr), + (override)); + MOCK_METHOD(std::string, GetURI, (), (override)); + MOCK_METHOD(bool, InterruptRead, (), (override)); +}; + +} // namespace + +TEST(PlatformRemoteGDBServerTest, IsConnected) { + bool is_connected = true; + + auto connection = std::make_unique>(); + ON_CALL(*connection, IsConnected()) + .WillByDefault(ReturnPointee(&is_connected)); + + auto client = std::make_unique(); + client->SetConnection(std::move(connection)); + + PlatformRemoteGDBServerHack server; + EXPECT_FALSE(server.IsConnected()); + + server.SetGDBClient(std::move(client)); + EXPECT_TRUE(server.IsConnected()); + + is_connected = false;
[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)
@@ -273,15 +273,13 @@ ValueObjectSP ForwardListFrontEnd::GetChildAtIndex(uint32_t idx) { // we need to copy current_sp into a new object otherwise we will end up with // all items named __value_ - DataExtractor data; - Status error; - current_sp->GetData(data, error); - if (error.Fail()) + auto data_or_err = current_sp->GetData(); + if (!data_or_err) return nullptr; adrian-prantl wrote: missing taking the error here. This would be a good use for `llvm::expectedToOptional()` since we're just dropping the error here. https://github.com/llvm/llvm-project/pull/130516 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
yuvald-sweet-security wrote: Ah, turns out there's a `HostInfo::GetProgramFileSpec()` function which solves both these issues. https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131519 >From bf755daf57a0255157f0b8ccec2372d2ef9e2ef3 Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Sun, 16 Mar 2025 14:08:57 + Subject: [PATCH] [lldb] Use correct path for lldb-server executable --- lldb/tools/lldb-server/lldb-platform.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..351a840851f36 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -31,6 +31,7 @@ #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/HostGetOpt.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Host/MainLoop.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/Socket.h" @@ -256,7 +257,7 @@ static void client_handle(GDBRemoteCommunicationServerPlatform &platform, printf("Disconnected.\n"); } -static Status spawn_process(const char *progname, const Socket *conn_socket, +static Status spawn_process(const FileSpec &prog, const Socket *conn_socket, uint16_t gdb_port, const lldb_private::Args &args, const std::string &log_file, const StringRef log_channels, MainLoop &main_loop) { @@ -267,8 +268,7 @@ static Status spawn_process(const char *progname, const Socket *conn_socket, ProcessLaunchInfo launch_info; - FileSpec self_spec(progname, FileSpec::Style::native); - launch_info.SetExecutableFile(self_spec, true); + launch_info.SetExecutableFile(prog, true); Args &self_args = launch_info.GetArguments(); self_args.AppendArgument(llvm::StringRef("platform")); self_args.AppendArgument(llvm::StringRef("--child-platform-fd")); @@ -547,11 +547,11 @@ int main_platform(int argc, char *argv[]) { { llvm::Expected> platform_handles = platform_sock->Accept( -main_loop, [progname, gdbserver_port, &inferior_arguments, log_file, +main_loop, [gdbserver_port, &inferior_arguments, log_file, log_channels, &main_loop, &platform_handles](std::unique_ptr sock_up) { printf("Connection established.\n"); - Status error = spawn_process(progname, sock_up.get(), + Status error = spawn_process(HostInfo::GetProgramFileSpec(), sock_up.get(), gdbserver_port, inferior_arguments, log_file, log_channels, main_loop); if (error.Fail()) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security edited https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Fix typo in docs (PR #131388)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/131388 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix prologue size calculation for discontinuous functions (PR #131597)
https://github.com/labath created https://github.com/llvm/llvm-project/pull/131597 When searching for the end of prologue, I'm only iterating through the address range (~basic block) which contains the function entry point. The reason for that is that even if some other range somehow contained the end-of-prologue marker, the fact that it's in a different range would imply it's reachable through some form of control flow, and that's usually not a good place to set an function entry breakpoint. >From 9874a78efa086dfc3168a514051a521964ad55f3 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 17 Mar 2025 11:12:44 +0100 Subject: [PATCH] [lldb] Fix prologue size calculation for discontinuous functions When searching for the end of prologue, I'm only iterating through the address range (~basic block) which contains the function entry point. The reason for that is that even if some other range somehow contained the end-of-prologue marker, the fact that it's in a different range would imply it's reachable through some form of control flow, and that's usually not a good place to set an function entry breakpoint. --- lldb/source/Symbol/Function.cpp | 20 --- .../DWARF/x86/discontinuous-function.s| 25 +-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp index c80f37ae68d9d..61e788da0e50b 100644 --- a/lldb/source/Symbol/Function.cpp +++ b/lldb/source/Symbol/Function.cpp @@ -662,10 +662,12 @@ uint32_t Function::GetPrologueByteSize() { } } -const addr_t func_start_file_addr = -m_range.GetBaseAddress().GetFileAddress(); -const addr_t func_end_file_addr = -func_start_file_addr + m_range.GetByteSize(); +AddressRange entry_range; +m_block.GetRangeContainingAddress(m_address, entry_range); +const addr_t range_start_file_addr = m_address.GetFileAddress(); +const addr_t range_end_file_addr = +entry_range.GetBaseAddress().GetFileAddress() + +entry_range.GetByteSize(); // Now calculate the offset to pass the subsequent line 0 entries. uint32_t first_non_zero_line = prologue_end_line_idx; @@ -677,7 +679,7 @@ uint32_t Function::GetPrologueByteSize() { break; } if (line_entry.range.GetBaseAddress().GetFileAddress() >= - func_end_file_addr) + range_end_file_addr) break; first_non_zero_line++; @@ -694,13 +696,13 @@ uint32_t Function::GetPrologueByteSize() { // Verify that this prologue end file address in the function's address // range just to be sure -if (func_start_file_addr < prologue_end_file_addr && -prologue_end_file_addr < func_end_file_addr) { - m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr; +if (range_start_file_addr < prologue_end_file_addr && +prologue_end_file_addr < range_end_file_addr) { + m_prologue_byte_size = prologue_end_file_addr - range_start_file_addr; } if (prologue_end_file_addr < line_zero_end_file_addr && -line_zero_end_file_addr < func_end_file_addr) { +line_zero_end_file_addr < range_end_file_addr) { m_prologue_byte_size += line_zero_end_file_addr - prologue_end_file_addr; } diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s b/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s index 197ab9aa14910..06934c2bfe9c4 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s @@ -16,22 +16,32 @@ image lookup -v -n foo # CHECK-LABEL: image lookup -v -n foo # CHECK: 1 match found in {{.*}} # CHECK: Summary: input.o`foo -# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000e)[0x0014-0x001c) +# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000f)[0x0015-0x001d) image lookup -v --regex -n '^foo$' # CHECK-LABEL: image lookup -v --regex -n '^foo$' # CHECK: 1 match found in {{.*}} # CHECK: Summary: input.o`foo -# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000e)[0x0014-0x001c) +# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000f)[0x0015-0x001d) expr -- &foo # CHECK-LABEL: expr -- &foo # CHECK: (void (*)()) $0 = 0x0007 +breakpoint set --name foo --skip-prologue false +# CHECK-LABEL: breakpoint set --name foo --skip-prologue false +# CHECK: Breakpoint 1: where = input.o`foo at -:1, address = 0x0007 + +breakpoint set --name foo --skip-prologue true +# CHECK-LABE
[Lldb-commits] [lldb] [lldb] Fix prologue size calculation for discontinuous functions (PR #131597)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Pavel Labath (labath) Changes When searching for the end of prologue, I'm only iterating through the address range (~basic block) which contains the function entry point. The reason for that is that even if some other range somehow contained the end-of-prologue marker, the fact that it's in a different range would imply it's reachable through some form of control flow, and that's usually not a good place to set an function entry breakpoint. --- Full diff: https://github.com/llvm/llvm-project/pull/131597.diff 2 Files Affected: - (modified) lldb/source/Symbol/Function.cpp (+11-9) - (modified) lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s (+23-2) ``diff diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp index c80f37ae68d9d..61e788da0e50b 100644 --- a/lldb/source/Symbol/Function.cpp +++ b/lldb/source/Symbol/Function.cpp @@ -662,10 +662,12 @@ uint32_t Function::GetPrologueByteSize() { } } -const addr_t func_start_file_addr = -m_range.GetBaseAddress().GetFileAddress(); -const addr_t func_end_file_addr = -func_start_file_addr + m_range.GetByteSize(); +AddressRange entry_range; +m_block.GetRangeContainingAddress(m_address, entry_range); +const addr_t range_start_file_addr = m_address.GetFileAddress(); +const addr_t range_end_file_addr = +entry_range.GetBaseAddress().GetFileAddress() + +entry_range.GetByteSize(); // Now calculate the offset to pass the subsequent line 0 entries. uint32_t first_non_zero_line = prologue_end_line_idx; @@ -677,7 +679,7 @@ uint32_t Function::GetPrologueByteSize() { break; } if (line_entry.range.GetBaseAddress().GetFileAddress() >= - func_end_file_addr) + range_end_file_addr) break; first_non_zero_line++; @@ -694,13 +696,13 @@ uint32_t Function::GetPrologueByteSize() { // Verify that this prologue end file address in the function's address // range just to be sure -if (func_start_file_addr < prologue_end_file_addr && -prologue_end_file_addr < func_end_file_addr) { - m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr; +if (range_start_file_addr < prologue_end_file_addr && +prologue_end_file_addr < range_end_file_addr) { + m_prologue_byte_size = prologue_end_file_addr - range_start_file_addr; } if (prologue_end_file_addr < line_zero_end_file_addr && -line_zero_end_file_addr < func_end_file_addr) { +line_zero_end_file_addr < range_end_file_addr) { m_prologue_byte_size += line_zero_end_file_addr - prologue_end_file_addr; } diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s b/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s index 197ab9aa14910..06934c2bfe9c4 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s @@ -16,22 +16,32 @@ image lookup -v -n foo # CHECK-LABEL: image lookup -v -n foo # CHECK: 1 match found in {{.*}} # CHECK: Summary: input.o`foo -# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000e)[0x0014-0x001c) +# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000f)[0x0015-0x001d) image lookup -v --regex -n '^foo$' # CHECK-LABEL: image lookup -v --regex -n '^foo$' # CHECK: 1 match found in {{.*}} # CHECK: Summary: input.o`foo -# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000e)[0x0014-0x001c) +# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x-0x000f)[0x0015-0x001d) expr -- &foo # CHECK-LABEL: expr -- &foo # CHECK: (void (*)()) $0 = 0x0007 +breakpoint set --name foo --skip-prologue false +# CHECK-LABEL: breakpoint set --name foo --skip-prologue false +# CHECK: Breakpoint 1: where = input.o`foo at -:1, address = 0x0007 + +breakpoint set --name foo --skip-prologue true +# CHECK-LABEL: breakpoint set --name foo --skip-prologue true +# CHECK: Breakpoint 2: where = input.o`foo + 1 at -:2, address = 0x0008 + #--- input.s .text +.file 0 "." "-" foo.__part.1: +.loc0 10 .cfi_startproc callq bar jmp foo.__part.3 @@ -41,7 +51,10 @@ foo.__part.1: .type foo,@function foo: +.loc0 1 .cfi_startproc +nop +.loc0 2 prologue_end cmpl$0, %edi je foo.__part.2 jmp foo.__part.1 @@ -51,6 +64,7 @@ fo
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
@@ -0,0 +1,47 @@ +//===-- SBLock.h --===// +// +// 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_SBLOCK_H +#define LLDB_API_SBLOCK_H + +#include "lldb/API/SBDefines.h" +#include "lldb/lldb-forward.h" + +#include labath wrote: ```suggestion #include "lldb/API/SBDefines.h" #include "lldb/lldb-forward.h" #include ``` https://github.com/llvm/llvm-project/pull/131404 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
@@ -0,0 +1,35 @@ +//===-- SBLock.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/SBLock.h" +#include "lldb/Target/Target.h" +#include "lldb/Utility/Instrumentation.h" +#include "lldb/lldb-forward.h" + +#include labath wrote: ```suggestion #include "lldb/Utility/Instrumentation.h" #include "lldb/lldb-forward.h" #include ``` https://github.com/llvm/llvm-project/pull/131404 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
@@ -1692,6 +1692,20 @@ class Target : public std::enable_shared_from_this, } }; +/// The private implementation backing SBLock. +struct APILock { + APILock(std::recursive_mutex &mutex) : lock(mutex) {} + std::lock_guard lock; +}; + +/// The private implementation used by SBLock to hand out the target API mutex. +/// It has a TargetSP to ensure the lock cannot outlive the target. +struct TargetAPILock : public APILock { labath wrote: So, if all you want to do with this is to hold a shared pointer, then this can be done in a simpler way. You can have the class take a `std::shared_ptr` and call this using the shared_ptr [aliasing constructor](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr) from the shared pointer of your choice (e.g. `TargetAPILock(std::shared_ptr(target_sp, target_sp->m_mutex))`) https://github.com/llvm/llvm-project/pull/131404 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (PR #131544)
https://github.com/da-viper closed https://github.com/llvm/llvm-project/pull/131544 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
labath wrote: I'm wondering if the right fix isn't to call `FileSystem::ResolveExecutableLocation` on `argv[0]`. That should should give us more-or-less the same algorithm that the shell used when starting lldb-server. https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
https://github.com/yuvald-sweet-security created https://github.com/llvm/llvm-project/pull/131609 Hello, This solves an issue that arises when running lldb-server through a symlink which is not named exactly `lldb-server`. For example, in many distros lldb-server is packaged as e.g. `/usr/lib/llvm-19/bin/lldb-server` which is then accessed through a symlink such as `/usr/bin/lldb-server-19`. In such a scenario, running `lldb-server-19 platform --server --listen '*:1338' --log-channels "lldb all"` works as intended, but running the absolute path of the symlink (`/usr/bin/lldb-server-19 platform --server --listen '*:1338' --log-channels "lldb all"`) fails with: ``` shlib dir -> `/usr/bin/` Attempting to derive the path /bin relative to liblldb install path: /usr/bin Derived the path as: /usr/bin support exe dir -> `/usr/bin/` GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer() debugserver launch failed: unable to locate lldb-server-19.1.7 ``` It turns out that there is a cascade of bugs here: * `GetShlibDir` attempts to locate the LLVM library directory by calling `GetModuleFileSpecForHostAddress` on the address of the function `ComputeSharedLibraryDirectory`, assuming that it is inside `liblldb.so`. However, in every packaging I've seen of lldb-server the function `ComputeSharedLibraryDirectory` is statically linked into the `lldb-server` binary and is not in `liblldb.so`. * When run through a symlink, `GetModuleFileSpecForHostAddress` on an address that is in `lldb-server` returns the path of the symlink, not the path of the binary itself. So we get e.g. `/usr/bin/` and not `/usr/lib/llvm-19/bin/`. * `GetDebugserverPath` attempts to concat `"lldb-server"` to the directory we obtained, and thus fails when the symlink is not named exactly `lldb-server`. * Ironically, the reason that this works in the first place is precisely because `GetModuleFileSpecForHostAddress` returns an incorrect path - when the server is run as `lldb-server-19 ...` it returns `"lldb-server-19"` which then causes `ComputePathRelativeToLibrary` to fail and then `ComputeSupportExeDirectory` falls back to just using `GetProgramFileSpec` instead (which is the only option that actually yields a correct path). Given the above information, the most logical solution seems to be just ditching `GetSupportExeDir` in favor of `GetProgramFileSpec`, but I'm not sure what are the potential implications of this on different packaging of LLDB - perhaps there are situations where the `lldb` binary is not located in the same directory with `lldb-server`, and so we still want to use the follow-the-path-to-liblldb logic there? Please advise on how to proceed with this. >From f47298e0f29a2a73d656ba5270557ca139688499 Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Mon, 17 Mar 2025 14:37:26 +0200 Subject: [PATCH] [lldb] Use correct path for debugserver --- .../Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index dad72a176b5fa..e754d01be3629 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -906,7 +906,7 @@ FileSpec GDBRemoteCommunication::GetDebugserverPath(Platform *platform) { FileSystem::Instance().Exists(debugserver_file_spec); if (!debugserver_exists) { // The debugserver binary is in the LLDB.framework/Resources directory. -debugserver_file_spec = HostInfo::GetSupportExeDir(); + debugserver_file_spec.SetDirectory(HostInfo::GetProgramFileSpec().GetDirectory()); if (debugserver_file_spec) { debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME); debugserver_exists = FileSystem::Instance().Exists(debugserver_file_spec); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Yuval Deutscher (yuvald-sweet-security) Changes Hello, This solves an issue that arises when running lldb-server through a symlink which is not named exactly `lldb-server`. For example, in many distros lldb-server is packaged as e.g. `/usr/lib/llvm-19/bin/lldb-server` which is then accessed through a symlink such as `/usr/bin/lldb-server-19`. In such a scenario, running `lldb-server-19 platform --server --listen '*:1338' --log-channels "lldb all"` works as intended, but running the absolute path of the symlink (`/usr/bin/lldb-server-19 platform --server --listen '*:1338' --log-channels "lldb all"`) fails with: ``` shlib dir -> `/usr/bin/` Attempting to derive the path /bin relative to liblldb install path: /usr/bin Derived the path as: /usr/bin support exe dir -> `/usr/bin/` GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer() debugserver launch failed: unable to locate lldb-server-19.1.7 ``` It turns out that there is a cascade of bugs here: * `GetShlibDir` attempts to locate the LLVM library directory by calling `GetModuleFileSpecForHostAddress` on the address of the function `ComputeSharedLibraryDirectory`, assuming that it is inside `liblldb.so`. However, in every packaging I've seen of lldb-server the function `ComputeSharedLibraryDirectory` is statically linked into the `lldb-server` binary and is not in `liblldb.so`. * When run through a symlink, `GetModuleFileSpecForHostAddress` on an address that is in `lldb-server` returns the path of the symlink, not the path of the binary itself. So we get e.g. `/usr/bin/` and not `/usr/lib/llvm-19/bin/`. * `GetDebugserverPath` attempts to concat `"lldb-server"` to the directory we obtained, and thus fails when the symlink is not named exactly `lldb-server`. * Ironically, the reason that this works in the first place is precisely because `GetModuleFileSpecForHostAddress` returns an incorrect path - when the server is run as `lldb-server-19 ...` it returns `"lldb-server-19"` which then causes `ComputePathRelativeToLibrary` to fail and then `ComputeSupportExeDirectory` falls back to just using `GetProgramFileSpec` instead (which is the only option that actually yields a correct path). Given the above information, the most logical solution seems to be just ditching `GetSupportExeDir` in favor of `GetProgramFileSpec`, but I'm not sure what are the potential implications of this on different packaging of LLDB - perhaps there are situations where the `lldb` binary is not located in the same directory with `lldb-server`, and so we still want to use the follow-the-path-to-liblldb logic there? Please advise on how to proceed with this. --- Full diff: https://github.com/llvm/llvm-project/pull/131609.diff 1 Files Affected: - (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (+1-1) ``diff diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index dad72a176b5fa..e754d01be3629 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -906,7 +906,7 @@ FileSpec GDBRemoteCommunication::GetDebugserverPath(Platform *platform) { FileSystem::Instance().Exists(debugserver_file_spec); if (!debugserver_exists) { // The debugserver binary is in the LLDB.framework/Resources directory. -debugserver_file_spec = HostInfo::GetSupportExeDir(); + debugserver_file_spec.SetDirectory(HostInfo::GetProgramFileSpec().GetDirectory()); if (debugserver_file_spec) { debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME); debugserver_exists = FileSystem::Instance().Exists(debugserver_file_spec); `` https://github.com/llvm/llvm-project/pull/131609 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC]Refactor common test setup into SetUp method (PR #131203)
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/131203 >From cff4bbc4ff68e77e3093a880f55d2e17116e6f37 Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Thu, 13 Mar 2025 15:57:48 -0400 Subject: [PATCH 1/2] [LLDB][NFC]Refactor common test setup into SetUp method --- lldb/unittests/Core/TelemetryTest.cpp | 35 --- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index 72db8c17f09ea..f7dab948faba1 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -81,6 +81,20 @@ using namespace lldb_private::telemetry; class TelemetryTest : public testing::Test { public: lldb_private::SubsystemRAII subsystems; + std::vector> + received_entries; + + void SetUp() override { +// This would have been called by the plugin reg in a "real" pluging +// For tests, we just call it directly. +lldb_private::FakePlugin::Initialize(); + +auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance(); +ASSERT_NE(ins, nullptr); + +ins->addDestination( +std::make_unique(&received_entries)); + } }; #if LLVM_ENABLE_TELEMETRY @@ -90,17 +104,8 @@ class TelemetryTest : public testing::Test { #endif TELEMETRY_TEST(TelemetryTest, PluginTest) { - // This would have been called by the plugin reg in a "real" plugin - // For tests, we just call it directly. - lldb_private::FakePlugin::Initialize(); - - auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance(); - ASSERT_NE(ins, nullptr); - - std::vector> - received_entries; - ins->addDestination( - std::make_unique(&received_entries)); + lldb_private::telemetry::TelemetryManager *ins = + lldb_private::telemetry::TelemetryManager::GetInstance(); lldb_private::FakeTelemetryInfo entry; entry.msg = ""; @@ -115,14 +120,6 @@ TELEMETRY_TEST(TelemetryTest, PluginTest) { } TELEMETRY_TEST(TelemetryTest, ScopedDispatcherTest) { - lldb_private::FakePlugin::Initialize(); - auto *ins = TelemetryManager::GetInstance(); - ASSERT_NE(ins, nullptr); - std::vector> - received_entries; - ins->addDestination( - std::make_unique(&received_entries)); - { ScopedDispatcher helper( [](lldb_private::FakeTelemetryInfo *info) { info->num = 0; }); >From 8106df8a72759b4ecc11d3d01edab4555fa6660a Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Mon, 17 Mar 2025 09:41:20 -0400 Subject: [PATCH 2/2] remove call to Init --- lldb/unittests/Core/TelemetryTest.cpp | 4 1 file changed, 4 deletions(-) diff --git a/lldb/unittests/Core/TelemetryTest.cpp b/lldb/unittests/Core/TelemetryTest.cpp index f7dab948faba1..1e41424bac3ce 100644 --- a/lldb/unittests/Core/TelemetryTest.cpp +++ b/lldb/unittests/Core/TelemetryTest.cpp @@ -85,10 +85,6 @@ class TelemetryTest : public testing::Test { received_entries; void SetUp() override { -// This would have been called by the plugin reg in a "real" pluging -// For tests, we just call it directly. -lldb_private::FakePlugin::Initialize(); - auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance(); ASSERT_NE(ins, nullptr); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)
https://github.com/Jlalond approved this pull request. Left one comment on the unused template. Otherwise LGTM, I'd wait for Jeffrey to give you a final sign off https://github.com/llvm/llvm-project/pull/130841 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r a6463f41135d7d96e92cefeeffa84d0955f934f9...23a710ff81fbd9ab9d5c96b086d96b9300567625 lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py lldb/test/API/tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py `` View the diff from darker here. ``diff --- test/API/tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py 2025-03-16 06:22:41.00 + +++ test/API/tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py 2025-03-17 16:37:48.719841 + @@ -182,11 +182,11 @@ source = "main.cpp" first_loop_break_line = line_number(source, "// first loop breakpoint") self.set_source_breakpoints(source, [first_loop_break_line]) self.continue_to_next_stop() self.dap_server.get_local_variables() - # Test write watchpoints on x +# Test write watchpoints on x response_x = self.dap_server.request_dataBreakpointInfo(1, "x") # Test response from dataBreakpointInfo request. self.assertEqual(response_x["body"]["dataId"].split("/")[1], "4") self.assertEqual(response_x["body"]["accessTypes"], self.accessTypes) dataBreakpoints = [ `` https://github.com/llvm/llvm-project/pull/130841 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Implement a statusline in LLDB (PR #121860)
JDevlieghere wrote: @DavidSpickett does this LGTY? https://github.com/llvm/llvm-project/pull/121860 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support ordered patterns in lldbtest.expect (PR #131475)
https://github.com/jimingham approved this pull request. LGTM. I wondered for a second whether there now should be separate flags for substrings & patterns, but I can't think of a reason why you would want to provide both substrings and patterns and for one to be ordered and the other not. https://github.com/llvm/llvm-project/pull/131475 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Support ordered patterns in lldbtest.expect (PR #131475)
https://github.com/kastiglione edited https://github.com/llvm/llvm-project/pull/131475 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
@@ -1692,6 +1692,20 @@ class Target : public std::enable_shared_from_this, } }; +/// The private implementation backing SBLock. +struct APILock { + APILock(std::recursive_mutex &mutex) : lock(mutex) {} + std::lock_guard lock; +}; + +/// The private implementation used by SBLock to hand out the target API mutex. +/// It has a TargetSP to ensure the lock cannot outlive the target. +struct TargetAPILock : public APILock { JDevlieghere wrote: TIL https://github.com/llvm/llvm-project/pull/131404 ___ 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 RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -1,12 +1,12 @@ -//===-- Protocol.cpp --===// +//===-- ProtocolBase.cpp --===// JDevlieghere wrote: Oh right, I didn't make the connection. Sounds good. https://github.com/llvm/llvm-project/pull/130090 ___ 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 RequestHandler to encode/decode arguments and response. (PR #130090)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/130090 ___ 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 RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -1,12 +1,12 @@ -//===-- Protocol.cpp --===// +//===-- ProtocolBase.cpp --===// ashgti wrote: I used the names of the categories from the spec for the files, https://microsoft.github.io/debug-adapter-protocol/specification if you look at the navigation on the left its grouped into 'Base Protocol', 'Events', 'Requests', 'Reverse Requests' and 'Types'. https://github.com/llvm/llvm-project/pull/130090 ___ 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 RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -162,4 +162,13 @@ GetEnvironmentFromArguments(const llvm::json::Object &arguments) { return envs; } +llvm::Error takeError(const lldb::SBError &error) { ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/130090 ___ 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 RequestHandler to encode/decode arguments and response. (PR #130090)
@@ -663,58 +671,64 @@ void DAP::SetTarget(const lldb::SBTarget target) { } bool DAP::HandleObject(const protocol::Message &M) { - // FIXME: Directly handle `Message` instead of serializing to JSON. - llvm::json::Value v = toJSON(M); - llvm::json::Object object = *v.getAsObject(); - const auto packet_type = GetString(object, "type"); - if (packet_type == "request") { -const auto command = GetString(object, "command"); - -auto new_handler_pos = request_handlers.find(command); -if (new_handler_pos != request_handlers.end()) { - (*new_handler_pos->second)(object); + if (const auto *req = std::get_if(&M)) { +auto handler_pos = request_handlers.find(req->command); +if (handler_pos != request_handlers.end()) { + (*handler_pos->second)(*req); return true; // Success } DAP_LOG(log, "({0}) error: unhandled command '{1}'", -transport.GetClientName(), command); +transport.GetClientName(), req->command); return false; // Fail } - if (packet_type == "response") { -auto id = GetInteger(object, "request_seq").value_or(0); - + if (const auto *resp = std::get_if(&M)) { std::unique_ptr response_handler; { std::lock_guard locker(call_mutex); - auto inflight = inflight_reverse_requests.find(id); + auto inflight = inflight_reverse_requests.find(resp->request_seq); if (inflight != inflight_reverse_requests.end()) { response_handler = std::move(inflight->second); inflight_reverse_requests.erase(inflight); } } if (!response_handler) - response_handler = std::make_unique("", id); + response_handler = + std::make_unique("", resp->request_seq); // Result should be given, use null if not. -if (GetBoolean(object, "success").value_or(false)) { - llvm::json::Value Result = nullptr; - if (auto *B = object.get("body")) -Result = std::move(*B); - (*response_handler)(Result); +if (resp->success) { + (*response_handler)(resp->body); } else { - llvm::StringRef message = GetString(object, "message"); - if (message.empty()) { -message = "Unknown error, response failed"; + std::string message = "Unknown error, response failed"; + if (resp->message) { +message = std::visit( +llvm::makeVisitor( +[](const std::string &message) -> std::string { + return message; +}, +[](const protocol::Response::Message &message) -> std::string { ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix TestGdbRemoteForkNonStop.py test (PR #131293)
sga-sc wrote: @labath Addressed https://github.com/llvm/llvm-project/pull/131293 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)
Michael137 wrote: Can confirm that the arm64 bots are failing again: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/22265 ``` TestReverseContinueWatchpoints.py -- Exit Code: 1 Command Output (stdout): -- lldb version 21.0.99git (https://github.com/llvm/llvm-project.git revision 52e7ca9279b4cbe30cacca67548347ef5f96b120) clang revision 52e7ca9279b4cbe30cacca67548347ef5f96b120 llvm revision 52e7ca9279b4cbe30cacca67548347ef5f96b120 Watchpoint 1 hit: old value: 2 new value: 1 Watchpoint 1 hit: old value: 2 new value: 1 ``` Attached the log file: [test-failure.txt](https://github.com/user-attachments/files/19291190/test-failure.txt) Let me know what other info might be useful https://github.com/llvm/llvm-project/pull/128156 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)
@@ -392,9 +391,57 @@ struct DAP { void SetThreadFormat(llvm::StringRef format); - InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); + template + BreakpointType *GetBreakpointFromStopReason(lldb::SBThread &thread) { +// Check to see if have hit the breakpoint and change the +// reason accordingly, but only do so if all breakpoints that were +// hit are of . +const auto num = thread.GetStopReasonDataCount(); +BreakpointType *bp = nullptr; +for (size_t i = 0; i < num; i += 2) { + lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(i); + // If any breakpoint is not the , then stop and + // report this as a normal breakpoint + bp = GetBreakpoint(bp_id); + if (bp == nullptr) +return nullptr; +} +return bp; + } + + template BreakpointType *GetBreakpointCollection(); Jlalond wrote: We can remove this as unused https://github.com/llvm/llvm-project/pull/130841 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/131404 >From 5ea2ad6ecb388818b009fa89c4aebe1e0e4213df Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 14 Mar 2025 15:19:58 -0700 Subject: [PATCH 1/3] [lldb] Expose the Target API lock through the SB API --- lldb/include/lldb/API/SBDefines.h | 1 + lldb/include/lldb/API/SBLock.h| 45 ++ lldb/include/lldb/API/SBTarget.h | 6 ++- lldb/include/lldb/Target/Target.h | 16 +++- lldb/source/API/CMakeLists.txt| 1 + lldb/source/API/SBLock.cpp| 40 +++ lldb/source/API/SBTarget.cpp | 36 + lldb/unittests/API/CMakeLists.txt | 1 + lldb/unittests/API/SBLockTest.cpp | 64 +++ 9 files changed, 193 insertions(+), 17 deletions(-) create mode 100644 lldb/include/lldb/API/SBLock.h create mode 100644 lldb/source/API/SBLock.cpp create mode 100644 lldb/unittests/API/SBLockTest.cpp diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h index ed5a80da117a5..7fa5150d69d8a 100644 --- a/lldb/include/lldb/API/SBDefines.h +++ b/lldb/include/lldb/API/SBDefines.h @@ -84,6 +84,7 @@ class LLDB_API SBLanguageRuntime; class LLDB_API SBLaunchInfo; class LLDB_API SBLineEntry; class LLDB_API SBListener; +class LLDB_API SBLock; class LLDB_API SBMemoryRegionInfo; class LLDB_API SBMemoryRegionInfoList; class LLDB_API SBModule; diff --git a/lldb/include/lldb/API/SBLock.h b/lldb/include/lldb/API/SBLock.h new file mode 100644 index 0..8d6fdfb959dfb --- /dev/null +++ b/lldb/include/lldb/API/SBLock.h @@ -0,0 +1,45 @@ +//===-- SBLock.h --===// +// +// 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_SBLOCK_H +#define LLDB_API_SBLOCK_H + +#include "lldb/API/SBDefines.h" +#include "lldb/lldb-forward.h" + +#include + +namespace lldb_private { +struct APILock; +} + +namespace lldb { + +#ifndef SWIG +class LLDB_API SBLock { +public: + ~SBLock(); + + bool IsValid() const; + +private: + friend class SBTarget; + + SBLock() = default; + SBLock(std::recursive_mutex &mutex); + SBLock(std::recursive_mutex &mutex, lldb::TargetSP target_sp); + SBLock(const SBLock &rhs) = delete; + const SBLock &operator=(const SBLock &rhs) = delete; + + std::unique_ptr m_opaque_up; +}; +#endif + +} // namespace lldb + +#endif diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index bb912ab41d0fe..6120c289743e3 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -342,7 +342,7 @@ class LLDB_API SBTarget { uint32_t GetAddressByteSize(); const char *GetTriple(); - + const char *GetABIName(); const char *GetLabel() const; @@ -946,6 +946,10 @@ class LLDB_API SBTarget { /// An error if a Trace already exists or the trace couldn't be created. lldb::SBTrace CreateTrace(SBError &error); +#ifndef SWIG + lldb::SBLock GetAPILock() const; +#endif + protected: friend class SBAddress; friend class SBAddressRange; diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 80ce5f013344c..8321a963d4c5b 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -1327,7 +1327,7 @@ class Target : public std::enable_shared_from_this, StopHook(const StopHook &rhs); virtual ~StopHook() = default; -enum class StopHookKind : uint32_t { CommandBased = 0, ScriptBased }; +enum class StopHookKind : uint32_t { CommandBased = 0, ScriptBased }; enum class StopHookResult : uint32_t { KeepStopped = 0, RequestContinue, @@ -1692,6 +1692,20 @@ class Target : public std::enable_shared_from_this, } }; +/// The private implementation backing SBLock. +struct APILock { + APILock(std::recursive_mutex &mutex) : lock(mutex) {} + std::lock_guard lock; +}; + +/// The private implementation used by SBLock to hand out the target API mutex. +/// It has a TargetSP to ensure the lock cannot outlive the target. +struct TargetAPILock : public APILock { + TargetAPILock(std::recursive_mutex &mutex, lldb::TargetSP target_sp) + : APILock(mutex), target_sp(target_sp) {} + lldb::TargetSP target_sp; +}; + } // namespace lldb_private #endif // LLDB_TARGET_TARGET_H diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index 48d5cde5bf592..c9a9433b2329d 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -77,6 +77,7 @@ add_lldb_library(liblldb SHARED ${option_framework} SBLaunchInfo.cpp SBLineEntry.cpp SBListener.cpp + SBLock.cpp SBMemoryRegionInfo.cpp SBMemoryRegionInfoList.cpp
[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)
JDevlieghere wrote: The unit tests are crashing because the new test correctly initializes and terminates the debugger and there's a double free in the `SBCommandInterpreterTest` (which conveniently wasn't doing that). I'll put up a separate PR to fix that. https://github.com/llvm/llvm-project/pull/131404 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131519 >From df4b4e2a0361eaeaace3f8578f4f30d95fee059a Mon Sep 17 00:00:00 2001 From: Yuval Deutscher Date: Sun, 16 Mar 2025 14:08:57 + Subject: [PATCH] [lldb] Use correct path for lldb-server executable --- lldb/tools/lldb-server/lldb-platform.cpp | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..54650a8890325 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -31,6 +31,7 @@ #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/HostGetOpt.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Host/MainLoop.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/Socket.h" @@ -256,7 +257,7 @@ static void client_handle(GDBRemoteCommunicationServerPlatform &platform, printf("Disconnected.\n"); } -static Status spawn_process(const char *progname, const Socket *conn_socket, +static Status spawn_process(const FileSpec &prog, const Socket *conn_socket, uint16_t gdb_port, const lldb_private::Args &args, const std::string &log_file, const StringRef log_channels, MainLoop &main_loop) { @@ -267,8 +268,7 @@ static Status spawn_process(const char *progname, const Socket *conn_socket, ProcessLaunchInfo launch_info; - FileSpec self_spec(progname, FileSpec::Style::native); - launch_info.SetExecutableFile(self_spec, true); + launch_info.SetExecutableFile(prog, true); Args &self_args = launch_info.GetArguments(); self_args.AppendArgument(llvm::StringRef("platform")); self_args.AppendArgument(llvm::StringRef("--child-platform-fd")); @@ -547,13 +547,13 @@ int main_platform(int argc, char *argv[]) { { llvm::Expected> platform_handles = platform_sock->Accept( -main_loop, [progname, gdbserver_port, &inferior_arguments, log_file, -log_channels, &main_loop, -&platform_handles](std::unique_ptr sock_up) { +main_loop, +[gdbserver_port, &inferior_arguments, log_file, log_channels, + &main_loop, &platform_handles](std::unique_ptr sock_up) { printf("Connection established.\n"); - Status error = spawn_process(progname, sock_up.get(), - gdbserver_port, inferior_arguments, - log_file, log_channels, main_loop); + Status error = spawn_process( + HostInfo::GetProgramFileSpec(), sock_up.get(), gdbserver_port, + inferior_arguments, log_file, log_channels, main_loop); if (error.Fail()) { Log *log = GetLog(LLDBLog::Platform); LLDB_LOGF(log, "spawn_process failed: %s", error.AsCString()); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)
labath wrote: Submitting per https://github.com/llvm/llvm-project/pull/123945#issuecomment-2672913953 https://github.com/llvm/llvm-project/pull/128156 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 1b23719 - Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (#128156)
Author: Pavel Labath Date: 2025-03-17T16:06:25+01:00 New Revision: 1b237198dc9d308c6d589e01637ec7496b48b3e0 URL: https://github.com/llvm/llvm-project/commit/1b237198dc9d308c6d589e01637ec7496b48b3e0 DIFF: https://github.com/llvm/llvm-project/commit/1b237198dc9d308c6d589e01637ec7496b48b3e0.diff LOG: Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (#128156) This reverts commit https://github.com/llvm/llvm-project/commit/87b7f63a117c340a6d9ca47959335fd7ef6c7ad2, reapplying https://github.com/llvm/llvm-project/commit/7e66cf74fb4e6a103f923e34700a7b6f20ac2a9b with a small (and probably temporary) change to generate more debug info to help with diagnosing buildbot issues. Added: lldb/packages/Python/lldbsuite/test/lldbgdbproxy.py lldb/packages/Python/lldbsuite/test/lldbreverse.py lldb/test/API/functionalities/reverse-execution/Makefile lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py lldb/test/API/functionalities/reverse-execution/main.c Modified: lldb/include/lldb/API/SBProcess.h lldb/include/lldb/Target/Process.h lldb/include/lldb/Target/StopInfo.h lldb/include/lldb/Target/Thread.h lldb/include/lldb/Target/ThreadList.h lldb/include/lldb/Target/ThreadPlan.h lldb/include/lldb/Target/ThreadPlanBase.h lldb/include/lldb/lldb-enumerations.h lldb/packages/Python/lldbsuite/test/gdbclientutils.py lldb/packages/Python/lldbsuite/test/lldbtest.py lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py lldb/source/API/SBProcess.cpp lldb/source/API/SBThread.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp lldb/source/Plugins/Process/scripted/ScriptedProcess.h lldb/source/Target/Process.cpp lldb/source/Target/StopInfo.cpp lldb/source/Target/Thread.cpp lldb/source/Target/ThreadList.cpp lldb/source/Target/ThreadPlanBase.cpp lldb/tools/lldb-dap/JSONUtils.cpp lldb/tools/lldb-dap/LLDBUtils.cpp Removed: diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 1624e02070b1b..882b8bd837131 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -159,6 +159,7 @@ class LLDB_API SBProcess { lldb::SBError Destroy(); lldb::SBError Continue(); + lldb::SBError ContinueInDirection(lldb::RunDirection direction); lldb::SBError Stop(); diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index c3622a29bc772..2e827d4c5cb74 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -1089,6 +1089,13 @@ class Process : public std::enable_shared_from_this, /// Returns an error object. virtual Status WillResume() { return Status(); } + /// Reports whether this process supports reverse execution. + /// + /// \return + /// Returns true if the process supports reverse execution (at least + /// under some circumstances). + virtual bool SupportsReverseDirection() { return false; } + /// Resumes all of a process's threads as configured using the Thread run /// control functions. /// @@ -1104,9 +,13 @@ class Process : public std::enable_shared_from_this, /// \see Thread:Resume() /// \see Thread:Step() /// \see Thread:Suspend() - virtual Status DoResume() { + virtual Status DoResume(lldb::RunDirection direction) { +if (direction == lldb::RunDirection::eRunForward) + return Status::FromErrorStringWithFormatv( + "error: {0} does not support resuming processes", GetPluginName()); return Status::FromErrorStringWithFormatv( -"error: {0} does not support resuming processes", GetPluginName()); +"error: {0} does not support reverse execution of processes", +GetPluginName()); } /// Called after resuming a process. @@ -2677,6 +2688,18 @@ void PruneThreadPlans(); const AddressRange &range, size_t alignment,
[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)
https://github.com/labath closed https://github.com/llvm/llvm-project/pull/128156 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC] Added the interface DWARFUnitInterface to break dependencies and reduce lldb-server size (PR #131645)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Dmitry Vasilyev (slydiman) Changes This patch addresses the issue #129543. After this patch DWARFExpression does not call DWARFUnit directly and does not depend on lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp and a lot of clang code. After this patch the size of lldb-server binary (Linux Aarch64) is reduced from 42MB to 13MB with LLVM 20.0.0 and from 47MB to 17MB with LLVM 21.0.0. --- Full diff: https://github.com/llvm/llvm-project/pull/131645.diff 5 Files Affected: - (modified) lldb/include/lldb/Expression/DWARFExpression.h (+12-11) - (modified) lldb/source/Expression/DWARFExpression.cpp (+16-39) - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp (+3-3) - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (+31-8) - (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h (+39-11) ``diff diff --git a/lldb/include/lldb/Expression/DWARFExpression.h b/lldb/include/lldb/Expression/DWARFExpression.h index 2c1e717ee32eb..cf4098f2acc51 100644 --- a/lldb/include/lldb/Expression/DWARFExpression.h +++ b/lldb/include/lldb/Expression/DWARFExpression.h @@ -23,7 +23,7 @@ namespace lldb_private { namespace plugin { namespace dwarf { -class DWARFUnit; +class DWARFUnitInterface; } // namespace dwarf } // namespace plugin @@ -65,20 +65,20 @@ class DWARFExpression { /// \return /// The address specified by the operation, if the operation exists, or /// an llvm::Error otherwise. - llvm::Expected - GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu) const; + llvm::Expected GetLocation_DW_OP_addr( + const plugin::dwarf::DWARFUnitInterface *dwarf_cu) const; - bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu, + bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnitInterface *dwarf_cu, lldb::addr_t file_addr); void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size); - bool - ContainsThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu) const; + bool ContainsThreadLocalStorage( + const plugin::dwarf::DWARFUnitInterface *dwarf_cu) const; bool LinkThreadLocalStorage( - const plugin::dwarf::DWARFUnit *dwarf_cu, + const plugin::dwarf::DWARFUnitInterface *dwarf_cu, std::function const &link_address_callback); @@ -132,13 +132,14 @@ class DWARFExpression { static llvm::Expected Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, - const plugin::dwarf::DWARFUnit *dwarf_cu, + const plugin::dwarf::DWARFUnitInterface *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr); - static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu, - const DataExtractor &data, - DWARFExpressionList *loc_list); + static bool + ParseDWARFLocationList(const plugin::dwarf::DWARFUnitInterface *dwarf_cu, + const DataExtractor &data, + DWARFExpressionList *loc_list); bool GetExpressionData(DataExtractor &data) const { data = m_data; diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index f48f3ab9307dd..41fbca59db60f 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -133,7 +133,7 @@ static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const LocationAtom op, -const DWARFUnit *dwarf_cu) { +const DWARFUnitInterface *dwarf_cu) { lldb::offset_t offset = data_offset; switch (op) { // Only used in LLVM metadata. @@ -362,7 +362,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, // + LEB128 { data.Skip_LEB128(&offset); -return DWARFUnit::GetAddressByteSize(dwarf_cu) + offset - data_offset; +return DWARFUnitInterface::GetAddressByteSize(dwarf_cu) + offset - + data_offset; } case DW_OP_GNU_entry_value: @@ -393,8 +394,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, return LLDB_INVALID_OFFSET; } -llvm::Expected -DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu) const { +llvm::Expected DWARFExpression::GetLocation_DW_OP_addr( +const DWARFUnitInterface *dwarf_cu) const { lldb::offset_t offset = 0; while (m_data.ValidOffset(offset)) { const LocationAtom op = static_cast(m_da
[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)
https://github.com/satyajanga updated https://github.com/llvm/llvm-project/pull/130841 >From e949d2ee19408c43d9067075d2436f8549132830 Mon Sep 17 00:00:00 2001 From: satya janga Date: Tue, 11 Mar 2025 13:39:08 -0700 Subject: [PATCH 1/4] Make breakpoint stop reason more accurate --- .../test/tools/lldb-dap/lldbdap_testcase.py | 3 ++- lldb/tools/lldb-dap/DAP.cpp | 26 +++ lldb/tools/lldb-dap/DAP.h | 14 +- lldb/tools/lldb-dap/JSONUtils.cpp | 12 ++--- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 70b04b051e0ec..5faf83ca826a0 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -86,6 +86,7 @@ def verify_breakpoint_hit(self, breakpoint_ids): if ( body["reason"] != "breakpoint" and body["reason"] != "instruction breakpoint" +and body["reason"] != "function breakpoint" ): continue if "description" not in body: @@ -100,7 +101,7 @@ def verify_breakpoint_hit(self, breakpoint_ids): # location. description = body["description"] for breakpoint_id in breakpoint_ids: -match_desc = "breakpoint %s." % (breakpoint_id) +match_desc = "%s %s." % (body["reason"], breakpoint_id) if match_desc in description: return self.assertTrue(False, "breakpoint not hit") diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 4080e2c211035..7baf858011362 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -1074,6 +1074,32 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread &thread) { return inst_bp; } +FunctionBreakpoint *DAP::GetFunctionBPFromStopReason(lldb::SBThread &thread) { + const auto num = thread.GetStopReasonDataCount(); + FunctionBreakpoint *func_bp = nullptr; + for (size_t i = 0; i < num; i += 2) { +// thread.GetStopReasonDataAtIndex(i) will return the bp ID and +// thread.GetStopReasonDataAtIndex(i+1) will return the location +// within that breakpoint. We only care about the bp ID so we can +// see if this is an function breakpoint that is getting hit. +lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(i); +func_bp = GetFunctionBreakPoint(bp_id); +// If any breakpoint is not an function breakpoint, then stop and +// report this as a normal breakpoint +if (func_bp == nullptr) + return nullptr; + } + return func_bp; +} + +FunctionBreakpoint *DAP::GetFunctionBreakPoint(const lldb::break_id_t bp_id) { + for (auto &bp : function_breakpoints) { +if (bp.second.bp.GetID() == bp_id) + return &bp.second; + } + return nullptr; +} + lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) { switch (variablesReference) { case VARREF_LOCALS: diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index db3473b7c7027..3913d7bc40978 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -125,21 +125,21 @@ struct Variables { struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface { DAP &dap; - explicit StartDebuggingRequestHandler(DAP &d) : dap(d) {}; + explicit StartDebuggingRequestHandler(DAP &d) : dap(d){}; bool DoExecute(lldb::SBDebugger debugger, char **command, lldb::SBCommandReturnObject &result) override; }; struct ReplModeRequestHandler : public lldb::SBCommandPluginInterface { DAP &dap; - explicit ReplModeRequestHandler(DAP &d) : dap(d) {}; + explicit ReplModeRequestHandler(DAP &d) : dap(d){}; bool DoExecute(lldb::SBDebugger debugger, char **command, lldb::SBCommandReturnObject &result) override; }; struct SendEventRequestHandler : public lldb::SBCommandPluginInterface { DAP &dap; - explicit SendEventRequestHandler(DAP &d) : dap(d) {}; + explicit SendEventRequestHandler(DAP &d) : dap(d){}; bool DoExecute(lldb::SBDebugger debugger, char **command, lldb::SBCommandReturnObject &result) override; }; @@ -392,9 +392,11 @@ struct DAP { void SetThreadFormat(llvm::StringRef format); - InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); - - InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread); +private: + // Send the JSON in "json_str" to the "out" stream. Correctly send the + // "Content-Length:" field followed by the length, followed by the raw + // JSON bytes. + void SendJSON(const std::string &json_str); }; } // namespace lldb_dap diff --git a/lldb/too
[Lldb-commits] [lldb] fbb8929 - [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (#130090)
Author: John Harrison Date: 2025-03-17T10:13:11-07:00 New Revision: fbb8929c9d15fdc0001205ee4a7b42a78edc5213 URL: https://github.com/llvm/llvm-project/commit/fbb8929c9d15fdc0001205ee4a7b42a78edc5213 DIFF: https://github.com/llvm/llvm-project/commit/fbb8929c9d15fdc0001205ee4a7b42a78edc5213.diff LOG: [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (#130090) This is a work in progress refactor to add explicit types instead of generic 'llvm::json::Value' types to the DAP protocol. This updates RequestHandler to have take the type of the arguments and response body for serialization for requests. The 'source' and 'disconnect' request is updated to show how the new flow works and includes serialization handling for optional arguments and 'void' responses. This is built on top of #130026 - Co-authored-by: Adrian Vogelsgesang Added: lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp lldb/tools/lldb-dap/Protocol/ProtocolBase.h lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp lldb/tools/lldb-dap/Protocol/ProtocolRequests.h lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp lldb/tools/lldb-dap/Protocol/ProtocolTypes.h Modified: lldb/tools/lldb-dap/CMakeLists.txt lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/DAP.h lldb/tools/lldb-dap/DAPForward.h lldb/tools/lldb-dap/Handler/DisconnectRequestHandler.cpp lldb/tools/lldb-dap/Handler/RequestHandler.cpp lldb/tools/lldb-dap/Handler/RequestHandler.h lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp lldb/tools/lldb-dap/LLDBUtils.cpp lldb/tools/lldb-dap/LLDBUtils.h lldb/tools/lldb-dap/Transport.cpp lldb/tools/lldb-dap/Transport.h lldb/tools/lldb-dap/lldb-dap.cpp Removed: lldb/tools/lldb-dap/Protocol.cpp lldb/tools/lldb-dap/Protocol.h diff --git a/lldb/tools/lldb-dap/CMakeLists.txt b/lldb/tools/lldb-dap/CMakeLists.txt index 8a76cb58dbcab..adad75a79fa7a 100644 --- a/lldb/tools/lldb-dap/CMakeLists.txt +++ b/lldb/tools/lldb-dap/CMakeLists.txt @@ -32,7 +32,6 @@ add_lldb_tool(lldb-dap LLDBUtils.cpp OutputRedirector.cpp ProgressEvent.cpp - Protocol.cpp RunInTerminal.cpp SourceBreakpoint.cpp Transport.cpp @@ -74,6 +73,10 @@ add_lldb_tool(lldb-dap Handler/TestGetTargetBreakpointsRequestHandler.cpp Handler/ThreadsRequestHandler.cpp Handler/VariablesRequestHandler.cpp + + Protocol/ProtocolBase.cpp + Protocol/ProtocolTypes.cpp + Protocol/ProtocolRequests.cpp LINK_LIBS liblldb diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 2a8fe8e24c242..a1e2187288768 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -8,10 +8,12 @@ #include "DAP.h" #include "DAPLog.h" +#include "Handler/RequestHandler.h" #include "Handler/ResponseHandler.h" #include "JSONUtils.h" #include "LLDBUtils.h" #include "OutputRedirector.h" +#include "Protocol/ProtocolBase.h" #include "Transport.h" #include "lldb/API/SBBreakpoint.h" #include "lldb/API/SBCommandInterpreter.h" @@ -25,6 +27,7 @@ #include "lldb/lldb-defines.h" #include "lldb/lldb-enumerations.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -41,6 +44,7 @@ #include #include #include +#include #include #if defined(_WIN32) @@ -233,6 +237,10 @@ void DAP::SendJSON(const llvm::json::Value &json) { transport.GetClientName()); return; } + Send(message); +} + +void DAP::Send(const protocol::Message &message) { if (llvm::Error err = transport.Write(message)) DAP_LOG_ERROR(log, std::move(err), "({1}) write failed: {0}", transport.GetClientName()); @@ -665,31 +673,23 @@ void DAP::SetTarget(const lldb::SBTarget target) { } bool DAP::HandleObject(const protocol::Message &M) { - // FIXME: Directly handle `Message` instead of serializing to JSON. - llvm::json::Value v = toJSON(M); - llvm::json::Object object = *v.getAsObject(); - const auto packet_type = GetString(object, "type"); - if (packet_type == "request") { -const auto command = GetString(object, "command").value_or(""); - -auto new_handler_pos = request_handlers.find(command); -if (new_handler_pos != request_handlers.end()) { - (*new_handler_pos->second)(object); + if (const auto *req = std::get_if(&M)) { +auto handler_pos = request_handlers.find(req->command); +if (handler_pos != request_handlers.end()) { + (*handler_pos->second)(*req); return true; // Success } DAP_LOG(log, "({0}) error: unhandled command '{1}'", -transport.GetClientName(), command); +transport.GetClientName(), req->command); return false; // Fail } - if (packet_type == "response") { -auto id = GetInteger(object, "request_seq").value_or(0); - +
[Lldb-commits] [lldb] [lldb] Fix double free in CommandPluginInterfaceImplementation (PR #131658)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/131658 The class was taking ownership of the SBCommandPluginInterface pointer it was passed in, by wrapping it in a shared pointer. This causes a double free in the unit test when the object is destroyed and the same pointer gets freed once when the SBCommandPluginInterface goes away and then again when the shared pointer hits a zero refcount. >From 3123d7ef4146b7caaf20ede083479692f6f324c7 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 17 Mar 2025 11:46:32 -0700 Subject: [PATCH] [lldb] Fix double free in CommandPluginInterfaceImplementation The class was taking ownership of the SBCommandPluginInterface pointer it was passed in, by wrapping it in a shared pointer. This causes a double free in the unit test when the object is destroyed and the same pointer gets freed once when the SBCommandPluginInterface goes away and then again when the shared pointer hits a zero refcount. --- lldb/source/API/SBCommandInterpreter.cpp | 2 +- .../unittests/API/SBCommandInterpreterTest.cpp | 18 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp index d153e2acdf853..de22a9dd96bd8 100644 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -77,7 +77,7 @@ class CommandPluginInterfaceImplementation : public CommandObjectParsed { SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); m_backend->DoExecute(debugger_sb, command.GetArgumentVector(), sb_return); } - std::shared_ptr m_backend; + lldb::SBCommandPluginInterface *m_backend; std::optional m_auto_repeat_command; }; } // namespace lldb_private diff --git a/lldb/unittests/API/SBCommandInterpreterTest.cpp b/lldb/unittests/API/SBCommandInterpreterTest.cpp index 941b738e84ac8..5651e1c3dc63f 100644 --- a/lldb/unittests/API/SBCommandInterpreterTest.cpp +++ b/lldb/unittests/API/SBCommandInterpreterTest.cpp @@ -6,24 +6,28 @@ // //===--===/ -#include "gtest/gtest.h" - // Use the umbrella header for -Wdocumentation. #include "lldb/API/LLDB.h" +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/API/SBDebugger.h" +#include "gtest/gtest.h" #include #include using namespace lldb; +using namespace lldb_private; class SBCommandInterpreterTest : public testing::Test { protected: void SetUp() override { -SBDebugger::Initialize(); -m_dbg = SBDebugger::Create(/*source_init_files=*/false); +debugger = SBDebugger::Create(/*source_init_files=*/false); } - SBDebugger m_dbg; + void TearDown() override { SBDebugger::Destroy(debugger); } + + SubsystemRAII subsystems; + SBDebugger debugger; }; class DummyCommand : public SBCommandPluginInterface { @@ -44,7 +48,7 @@ class DummyCommand : public SBCommandPluginInterface { TEST_F(SBCommandInterpreterTest, SingleWordCommand) { // We first test a command without autorepeat DummyCommand dummy("It worked"); - SBCommandInterpreter interp = m_dbg.GetCommandInterpreter(); + SBCommandInterpreter interp = debugger.GetCommandInterpreter(); interp.AddCommand("dummy", &dummy, /*help=*/nullptr); { SBCommandReturnObject result; @@ -78,7 +82,7 @@ TEST_F(SBCommandInterpreterTest, SingleWordCommand) { } TEST_F(SBCommandInterpreterTest, MultiWordCommand) { - SBCommandInterpreter interp = m_dbg.GetCommandInterpreter(); + SBCommandInterpreter interp = debugger.GetCommandInterpreter(); auto command = interp.AddMultiwordCommand("multicommand", /*help=*/nullptr); // We first test a subcommand without autorepeat DummyCommand subcommand("It worked again"); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix double free in CommandPluginInterfaceImplementation (PR #131658)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes The class was taking ownership of the SBCommandPluginInterface pointer it was passed in, by wrapping it in a shared pointer. This causes a double free in the unit test when the object is destroyed and the same pointer gets freed once when the SBCommandPluginInterface goes away and then again when the shared pointer hits a zero refcount. --- Full diff: https://github.com/llvm/llvm-project/pull/131658.diff 2 Files Affected: - (modified) lldb/source/API/SBCommandInterpreter.cpp (+1-1) - (modified) lldb/unittests/API/SBCommandInterpreterTest.cpp (+11-7) ``diff diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp index d153e2acdf853..de22a9dd96bd8 100644 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -77,7 +77,7 @@ class CommandPluginInterfaceImplementation : public CommandObjectParsed { SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); m_backend->DoExecute(debugger_sb, command.GetArgumentVector(), sb_return); } - std::shared_ptr m_backend; + lldb::SBCommandPluginInterface *m_backend; std::optional m_auto_repeat_command; }; } // namespace lldb_private diff --git a/lldb/unittests/API/SBCommandInterpreterTest.cpp b/lldb/unittests/API/SBCommandInterpreterTest.cpp index 941b738e84ac8..5651e1c3dc63f 100644 --- a/lldb/unittests/API/SBCommandInterpreterTest.cpp +++ b/lldb/unittests/API/SBCommandInterpreterTest.cpp @@ -6,24 +6,28 @@ // //===--===/ -#include "gtest/gtest.h" - // Use the umbrella header for -Wdocumentation. #include "lldb/API/LLDB.h" +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/API/SBDebugger.h" +#include "gtest/gtest.h" #include #include using namespace lldb; +using namespace lldb_private; class SBCommandInterpreterTest : public testing::Test { protected: void SetUp() override { -SBDebugger::Initialize(); -m_dbg = SBDebugger::Create(/*source_init_files=*/false); +debugger = SBDebugger::Create(/*source_init_files=*/false); } - SBDebugger m_dbg; + void TearDown() override { SBDebugger::Destroy(debugger); } + + SubsystemRAII subsystems; + SBDebugger debugger; }; class DummyCommand : public SBCommandPluginInterface { @@ -44,7 +48,7 @@ class DummyCommand : public SBCommandPluginInterface { TEST_F(SBCommandInterpreterTest, SingleWordCommand) { // We first test a command without autorepeat DummyCommand dummy("It worked"); - SBCommandInterpreter interp = m_dbg.GetCommandInterpreter(); + SBCommandInterpreter interp = debugger.GetCommandInterpreter(); interp.AddCommand("dummy", &dummy, /*help=*/nullptr); { SBCommandReturnObject result; @@ -78,7 +82,7 @@ TEST_F(SBCommandInterpreterTest, SingleWordCommand) { } TEST_F(SBCommandInterpreterTest, MultiWordCommand) { - SBCommandInterpreter interp = m_dbg.GetCommandInterpreter(); + SBCommandInterpreter interp = debugger.GetCommandInterpreter(); auto command = interp.AddMultiwordCommand("multicommand", /*help=*/nullptr); // We first test a subcommand without autorepeat DummyCommand subcommand("It worked again"); `` https://github.com/llvm/llvm-project/pull/131658 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/131200 >From 1283ba24387e01aafcfc99e5db3f16c91deb5ac0 Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Thu, 13 Mar 2025 15:52:23 -0400 Subject: [PATCH 1/9] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | 2 +- compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 4 ++-- compiler-rt/cmake/base-config-ix.cmake | 4 ++-- libcxx/CMakeLists.txt | 2 +- libcxxabi/CMakeLists.txt| 2 +- libunwind/CMakeLists.txt| 2 +- lldb/test/CMakeLists.txt| 2 +- lldb/utils/lldb-dotest/CMakeLists.txt | 2 +- llvm-libgcc/CMakeLists.txt | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index c3e734f72392f..cb80cf84ac6b6 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -118,7 +118,7 @@ function(add_compiler_rt_component name) endfunction() macro(set_output_name output name arch) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(${output} ${name}) else() if(ANDROID AND ${arch} STREQUAL "i386") diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index 379e2c25949cb..21e384da03a3c 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -510,7 +510,7 @@ function(get_compiler_rt_target arch variable) endfunction() function(get_compiler_rt_install_dir arch install_dir) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") get_compiler_rt_target(${arch} target) set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE) else() @@ -519,7 +519,7 @@ function(get_compiler_rt_install_dir arch install_dir) endfunction() function(get_compiler_rt_output_dir arch output_dir) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") get_compiler_rt_target(${arch} target) set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE) else() diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake index d92bc0e71fa1a..4224def96e948 100644 --- a/compiler-rt/cmake/base-config-ix.cmake +++ b/compiler-rt/cmake/base-config-ix.cmake @@ -103,13 +103,13 @@ if(NOT DEFINED COMPILER_RT_OS_DIR) string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR) endif() endif() -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib) extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH "Path where built compiler-rt libraries should be installed.") -else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +else() set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index abe12c2805a7c..6273f1c141292 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -414,7 +414,7 @@ set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.") set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.") -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) if(LIBCXX_LIBDIR_SUBDIR) string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR}) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 6dcfc51e55321..ab11a15707533 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -182,7 +182,7 @@ set(CMAKE_MODULE_PATH set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Path where built libc++abi runtime libraries should be installed.") -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(LIBCXXABI_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) if(LIBCXXABI_LIBDIR_SUBDIR)
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
DanielCChen wrote: @arichardson I found the way to override the cache file. Thanks for the suggestion! https://github.com/llvm/llvm-project/pull/131200 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/131200 >From 1283ba24387e01aafcfc99e5db3f16c91deb5ac0 Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Thu, 13 Mar 2025 15:52:23 -0400 Subject: [PATCH 1/8] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | 2 +- compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 4 ++-- compiler-rt/cmake/base-config-ix.cmake | 4 ++-- libcxx/CMakeLists.txt | 2 +- libcxxabi/CMakeLists.txt| 2 +- libunwind/CMakeLists.txt| 2 +- lldb/test/CMakeLists.txt| 2 +- lldb/utils/lldb-dotest/CMakeLists.txt | 2 +- llvm-libgcc/CMakeLists.txt | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index c3e734f72392f..cb80cf84ac6b6 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -118,7 +118,7 @@ function(add_compiler_rt_component name) endfunction() macro(set_output_name output name arch) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(${output} ${name}) else() if(ANDROID AND ${arch} STREQUAL "i386") diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index 379e2c25949cb..21e384da03a3c 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -510,7 +510,7 @@ function(get_compiler_rt_target arch variable) endfunction() function(get_compiler_rt_install_dir arch install_dir) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") get_compiler_rt_target(${arch} target) set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE) else() @@ -519,7 +519,7 @@ function(get_compiler_rt_install_dir arch install_dir) endfunction() function(get_compiler_rt_output_dir arch output_dir) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") get_compiler_rt_target(${arch} target) set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE) else() diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake index d92bc0e71fa1a..4224def96e948 100644 --- a/compiler-rt/cmake/base-config-ix.cmake +++ b/compiler-rt/cmake/base-config-ix.cmake @@ -103,13 +103,13 @@ if(NOT DEFINED COMPILER_RT_OS_DIR) string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR) endif() endif() -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib) extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH "Path where built compiler-rt libraries should be installed.") -else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +else() set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index abe12c2805a7c..6273f1c141292 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -414,7 +414,7 @@ set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.") set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.") -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) if(LIBCXX_LIBDIR_SUBDIR) string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR}) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 6dcfc51e55321..ab11a15707533 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -182,7 +182,7 @@ set(CMAKE_MODULE_PATH set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Path where built libc++abi runtime libraries should be installed.") -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(LIBCXXABI_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) if(LIBCXXABI_LIBDIR_SUBDIR)
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
@@ -1187,16 +1187,19 @@ endif() # Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to # break things. In this case we need to enable the large-file API as well. if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") - add_compile_definitions(_XOPEN_SOURCE=700) - add_compile_definitions(_LARGE_FILE_API) - add_compile_options(-pthread) + add_compile_definitions(_XOPEN_SOURCE=700) + add_compile_definitions(_LARGE_FILE_API) + add_compile_options(-pthread) # Modules should be built with -shared -Wl,-G, so we can use runtime linking # with plugins. string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G") # Also set the correct flags for building shared libraries. string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared") + + # Set LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF as AIX doesn't support it + set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL "" FORCE) DanielCChen wrote: Good point. Let me take a look. https://github.com/llvm/llvm-project/pull/131200 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/131200 >From 1283ba24387e01aafcfc99e5db3f16c91deb5ac0 Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Thu, 13 Mar 2025 15:52:23 -0400 Subject: [PATCH 1/7] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | 2 +- compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 4 ++-- compiler-rt/cmake/base-config-ix.cmake | 4 ++-- libcxx/CMakeLists.txt | 2 +- libcxxabi/CMakeLists.txt| 2 +- libunwind/CMakeLists.txt| 2 +- lldb/test/CMakeLists.txt| 2 +- lldb/utils/lldb-dotest/CMakeLists.txt | 2 +- llvm-libgcc/CMakeLists.txt | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index c3e734f72392f..cb80cf84ac6b6 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -118,7 +118,7 @@ function(add_compiler_rt_component name) endfunction() macro(set_output_name output name arch) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(${output} ${name}) else() if(ANDROID AND ${arch} STREQUAL "i386") diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index 379e2c25949cb..21e384da03a3c 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -510,7 +510,7 @@ function(get_compiler_rt_target arch variable) endfunction() function(get_compiler_rt_install_dir arch install_dir) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") get_compiler_rt_target(${arch} target) set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} PARENT_SCOPE) else() @@ -519,7 +519,7 @@ function(get_compiler_rt_install_dir arch install_dir) endfunction() function(get_compiler_rt_output_dir arch output_dir) - if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") get_compiler_rt_target(${arch} target) set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE) else() diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake index d92bc0e71fa1a..4224def96e948 100644 --- a/compiler-rt/cmake/base-config-ix.cmake +++ b/compiler-rt/cmake/base-config-ix.cmake @@ -103,13 +103,13 @@ if(NOT DEFINED COMPILER_RT_OS_DIR) string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR) endif() endif() -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib) extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH "Path where built compiler-rt libraries should be installed.") -else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +else() set(COMPILER_RT_OUTPUT_LIBRARY_DIR ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index abe12c2805a7c..6273f1c141292 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -414,7 +414,7 @@ set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library.") set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library.") -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) if(LIBCXX_LIBDIR_SUBDIR) string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR}) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index 6dcfc51e55321..ab11a15707533 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -182,7 +182,7 @@ set(CMAKE_MODULE_PATH set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Path where built libc++abi runtime libraries should be installed.") -if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) +if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(LIBCXXABI_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE}) if(LIBCXXABI_LIBDIR_SUBDIR)
[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)
https://github.com/satyajanga updated https://github.com/llvm/llvm-project/pull/130841 >From e949d2ee19408c43d9067075d2436f8549132830 Mon Sep 17 00:00:00 2001 From: satya janga Date: Tue, 11 Mar 2025 13:39:08 -0700 Subject: [PATCH 1/4] Make breakpoint stop reason more accurate --- .../test/tools/lldb-dap/lldbdap_testcase.py | 3 ++- lldb/tools/lldb-dap/DAP.cpp | 26 +++ lldb/tools/lldb-dap/DAP.h | 14 +- lldb/tools/lldb-dap/JSONUtils.cpp | 12 ++--- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 70b04b051e0ec..5faf83ca826a0 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -86,6 +86,7 @@ def verify_breakpoint_hit(self, breakpoint_ids): if ( body["reason"] != "breakpoint" and body["reason"] != "instruction breakpoint" +and body["reason"] != "function breakpoint" ): continue if "description" not in body: @@ -100,7 +101,7 @@ def verify_breakpoint_hit(self, breakpoint_ids): # location. description = body["description"] for breakpoint_id in breakpoint_ids: -match_desc = "breakpoint %s." % (breakpoint_id) +match_desc = "%s %s." % (body["reason"], breakpoint_id) if match_desc in description: return self.assertTrue(False, "breakpoint not hit") diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 4080e2c211035..7baf858011362 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -1074,6 +1074,32 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread &thread) { return inst_bp; } +FunctionBreakpoint *DAP::GetFunctionBPFromStopReason(lldb::SBThread &thread) { + const auto num = thread.GetStopReasonDataCount(); + FunctionBreakpoint *func_bp = nullptr; + for (size_t i = 0; i < num; i += 2) { +// thread.GetStopReasonDataAtIndex(i) will return the bp ID and +// thread.GetStopReasonDataAtIndex(i+1) will return the location +// within that breakpoint. We only care about the bp ID so we can +// see if this is an function breakpoint that is getting hit. +lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(i); +func_bp = GetFunctionBreakPoint(bp_id); +// If any breakpoint is not an function breakpoint, then stop and +// report this as a normal breakpoint +if (func_bp == nullptr) + return nullptr; + } + return func_bp; +} + +FunctionBreakpoint *DAP::GetFunctionBreakPoint(const lldb::break_id_t bp_id) { + for (auto &bp : function_breakpoints) { +if (bp.second.bp.GetID() == bp_id) + return &bp.second; + } + return nullptr; +} + lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) { switch (variablesReference) { case VARREF_LOCALS: diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h index db3473b7c7027..3913d7bc40978 100644 --- a/lldb/tools/lldb-dap/DAP.h +++ b/lldb/tools/lldb-dap/DAP.h @@ -125,21 +125,21 @@ struct Variables { struct StartDebuggingRequestHandler : public lldb::SBCommandPluginInterface { DAP &dap; - explicit StartDebuggingRequestHandler(DAP &d) : dap(d) {}; + explicit StartDebuggingRequestHandler(DAP &d) : dap(d){}; bool DoExecute(lldb::SBDebugger debugger, char **command, lldb::SBCommandReturnObject &result) override; }; struct ReplModeRequestHandler : public lldb::SBCommandPluginInterface { DAP &dap; - explicit ReplModeRequestHandler(DAP &d) : dap(d) {}; + explicit ReplModeRequestHandler(DAP &d) : dap(d){}; bool DoExecute(lldb::SBDebugger debugger, char **command, lldb::SBCommandReturnObject &result) override; }; struct SendEventRequestHandler : public lldb::SBCommandPluginInterface { DAP &dap; - explicit SendEventRequestHandler(DAP &d) : dap(d) {}; + explicit SendEventRequestHandler(DAP &d) : dap(d){}; bool DoExecute(lldb::SBDebugger debugger, char **command, lldb::SBCommandReturnObject &result) override; }; @@ -392,9 +392,11 @@ struct DAP { void SetThreadFormat(llvm::StringRef format); - InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); - - InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread); +private: + // Send the JSON in "json_str" to the "out" stream. Correctly send the + // "Content-Length:" field followed by the length, followed by the raw + // JSON bytes. + void SendJSON(const std::string &json_str); }; } // namespace lldb_dap diff --git a/lldb/too
[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)
https://github.com/ashgti closed https://github.com/llvm/llvm-project/pull/130090 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
https://github.com/arichardson approved this pull request. https://github.com/llvm/llvm-project/pull/131200 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
arichardson wrote: > @arichardson I found the way to override the cache file. Thanks for the > suggestion! Thanks this looks good to me. https://github.com/llvm/llvm-project/pull/131200 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)
@@ -1187,16 +1187,19 @@ endif() # Build with _XOPEN_SOURCE on AIX, as stray macros in _ALL_SOURCE mode tend to # break things. In this case we need to enable the large-file API as well. if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX") - add_compile_definitions(_XOPEN_SOURCE=700) - add_compile_definitions(_LARGE_FILE_API) - add_compile_options(-pthread) + add_compile_definitions(_XOPEN_SOURCE=700) + add_compile_definitions(_LARGE_FILE_API) + add_compile_options(-pthread) # Modules should be built with -shared -Wl,-G, so we can use runtime linking # with plugins. string(APPEND CMAKE_MODULE_LINKER_FLAGS " -shared -Wl,-G") # Also set the correct flags for building shared libraries. string(APPEND CMAKE_SHARED_LINKER_FLAGS " -shared") + + # Set LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF as AIX doesn't support it + set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL "" FORCE) arichardson wrote: Do we also need to set this in runtimes/CMakeLists.txt for standalone runtimes builds without bootstrapping LLVM? https://github.com/llvm/llvm-project/pull/131200 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits