[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
@@ -52,14 +37,33 @@ struct SourceBreakpoint : public Breakpoint { static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location); -}; -inline bool operator<(const SourceBreakpoint &lhs, - const SourceBreakpoint &rhs) { - if (lhs.line == rhs.line) -return lhs.column < rhs.column; - return lhs.line < rhs.line; -} + inline bool operator<(const SourceBreakpoint &rhs) { +if (line == rhs.line) + return column < rhs.column; +return line < rhs.line; + } + + uint32_t GetLine() const { return line; } + uint32_t GetColumn() const { return column; } + +protected: + // logMessage part can be either a raw text or an expression. + struct LogMessagePart { +LogMessagePart(llvm::StringRef text, bool is_expr) +: text(text), is_expr(is_expr) {} +std::string text; +bool is_expr; + }; + // If this attribute exists and is non-empty, the backend must not 'break' + // (stop) but log the message instead. Expressions within {} are + // interpolated. + std::string logMessage; + std::vector logMessageParts; + + uint32_t line; ///< The source line of the breakpoint or logpoint + uint32_t column; ///< An optional source column of the breakpoint ashgti wrote: Nit: `m_`? https://github.com/llvm/llvm-project/pull/133780 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Make the DAP server resilient against broken pipes (PR #133791)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes This makes the DAP test server resilient against broken pipes. I'm not sure what is causing the broken pipe, but IIRC this isn't the first time we've seen an issues related to that. I worry about sweeping it under the rug, but on the other hand having the test suite hangup isn't great either. Based this on https://bugs.python.org/issue21619: > The best way to clean up a subprocess that I have come up with to > close the pipe(s) and call wait() in two separate steps, such as: ``` try: proc.stdin.close() except BrokenPipeError: pass proc.wait() ``` Fixes #133782 (or rather: works around it) --- Full diff: https://github.com/llvm/llvm-project/pull/133791.diff 1 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py (+4-2) ``diff diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 01ef4b68f2653..57907b1d2f19b 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -1174,8 +1174,10 @@ def request_testGetTargetBreakpoints(self): return self.send_recv(command_dict) def terminate(self): -self.send.close() -# self.recv.close() +try: +self.send.close() +except BrokenPipeError: +pass def request_setInstructionBreakpoints(self, memory_reference=[]): breakpoints = [] `` https://github.com/llvm/llvm-project/pull/133791 ___ 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 cancelling a request. (PR #130169)
@@ -397,6 +402,23 @@ struct DAP { InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread); + + /// Checks if the request is cancelled. + bool IsCancelled(const protocol::Request &); + + /// Clears the cancel request from the set of tracked cancel requests. + void ClearCancelRequest(const protocol::CancelArguments &); + +private: + std::mutex m_queue_mutex; + std::deque m_queue; + std::condition_variable m_queue_cv; + + std::mutex m_cancelled_requests_mutex; + std::set m_cancelled_requests; ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
https://github.com/ashgti closed https://github.com/llvm/llvm-project/pull/133811 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix use-after-free in SBMutexTest (PR #133840)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/133840 The `locked` variable can be accessed from the asynchronous thread until the call to f.wait() completes. However, the variable is scoped in a lexical block that ends before that, leading to a use-after-free. >From 1891a00e3c0fe05313053ca5ca898854d2e63c00 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 31 Mar 2025 19:33:12 -0700 Subject: [PATCH] [lldb] Fix use-after-free in SBMutexTest The `locked` variable can be accessed from the asynchronous thread until the call to f.wait() completes. However, the variable is scoped in a lexical block that ends before that, leading to a use-after-free. --- lldb/unittests/API/SBMutexTest.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/unittests/API/SBMutexTest.cpp b/lldb/unittests/API/SBMutexTest.cpp index 0b888c2725aa9..aafad59d58c17 100644 --- a/lldb/unittests/API/SBMutexTest.cpp +++ b/lldb/unittests/API/SBMutexTest.cpp @@ -32,10 +32,9 @@ class SBMutexTest : public testing::Test { TEST_F(SBMutexTest, LockTest) { lldb::SBTarget target = debugger.GetDummyTarget(); - + std::atomic locked = false; std::future f; { -std::atomic locked = false; lldb::SBMutex lock = target.GetAPIMutex(); std::lock_guard lock_guard(lock); ASSERT_FALSE(locked.exchange(true)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 0b8c8ed - [lldb] Fix use-after-free in SBMutexTest (#133840)
Author: Jonas Devlieghere Date: 2025-03-31T19:36:05-07:00 New Revision: 0b8c8ed04211dae629811f24e6033e5c2185508f URL: https://github.com/llvm/llvm-project/commit/0b8c8ed04211dae629811f24e6033e5c2185508f DIFF: https://github.com/llvm/llvm-project/commit/0b8c8ed04211dae629811f24e6033e5c2185508f.diff LOG: [lldb] Fix use-after-free in SBMutexTest (#133840) The `locked` variable can be accessed from the asynchronous thread until the call to f.wait() completes. However, the variable is scoped in a lexical block that ends before that, leading to a use-after-free. Added: Modified: lldb/unittests/API/SBMutexTest.cpp Removed: diff --git a/lldb/unittests/API/SBMutexTest.cpp b/lldb/unittests/API/SBMutexTest.cpp index 0b888c2725aa9..aafad59d58c17 100644 --- a/lldb/unittests/API/SBMutexTest.cpp +++ b/lldb/unittests/API/SBMutexTest.cpp @@ -32,10 +32,9 @@ class SBMutexTest : public testing::Test { TEST_F(SBMutexTest, LockTest) { lldb::SBTarget target = debugger.GetDummyTarget(); - + std::atomic locked = false; std::future f; { -std::atomic locked = false; lldb::SBMutex lock = target.GetAPIMutex(); std::lock_guard lock_guard(lock); ASSERT_FALSE(locked.exchange(true)); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Enable runInTerminal tests on macOS. (PR #133824)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/133824 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target (PR #132688)
https://github.com/yingopq updated https://github.com/llvm/llvm-project/pull/132688 >From 4cd95bb97c04fa26dc12c64ab3b6ccf9a911cc33 Mon Sep 17 00:00:00 2001 From: Ying Huang Date: Mon, 24 Mar 2025 03:44:41 -0400 Subject: [PATCH] [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target Now, because we do not support mips debugging, if we compile LLVM on mips target, would report error `static assertion failed:Value mismatch for signal number SIGBUS`, so add this condition to avoid error. --- lldb/source/Plugins/Process/Utility/LinuxSignals.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp index eaecc84df15d4..580b801a7ece2 100644 --- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp +++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp @@ -8,7 +8,10 @@ #include "LinuxSignals.h" -#ifdef __linux__ +// mips-linux debugging is not supported and mips uses different numbers for some +// signals (e.g. SIGBUS) on linux, so we skip the static checks below. The definitions +// here can be used for debugging non-mips targets on a mips-hosted lldb. +#if defined(__linux__) && !defined(__mips__) #include #ifndef SEGV_BNDERR @@ -33,7 +36,7 @@ #else #define ADD_SIGCODE(signal_name, signal_value, code_name, code_value, ...) \ AddSignalCode(signal_value, code_value, __VA_ARGS__) -#endif /* ifdef __linux__ */ +#endif /* if defined(__linux__) && !defined(__mips__) */ using namespace lldb_private; ___ 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 mutex through the SB API (PR #133295)
@@ -0,0 +1,57 @@ +//===-- SBMutexTest.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 +// +//===--===// + +// Use the umbrella header for -Wdocumentation. +#include "lldb/API/LLDB.h" + +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBTarget.h" +#include "gtest/gtest.h" +#include +#include +#include +#include + +using namespace lldb; +using namespace lldb_private; + +class SBMutexTest : public testing::Test { +protected: + void SetUp() override { debugger = SBDebugger::Create(); } + void TearDown() override { SBDebugger::Destroy(debugger); } + + SubsystemRAII subsystems; + SBDebugger debugger; +}; + +TEST_F(SBMutexTest, LockTest) { + lldb::SBTarget target = debugger.GetDummyTarget(); + + std::future f; + { +std::atomic locked = false; +lldb::SBMutex lock = target.GetAPIMutex(); +std::lock_guard lock_guard(lock); +ASSERT_FALSE(locked.exchange(true)); + +f = std::async(std::launch::async, [&]() { + ASSERT_TRUE(locked); + target.BreakpointCreateByName("foo", "bar"); + ASSERT_FALSE(locked); +}); +ASSERT_TRUE(f.valid()); + +// Wait 500ms to confirm the thread is blocked. +auto status = f.wait_for(std::chrono::milliseconds(500)); +ASSERT_EQ(status, std::future_status::timeout); + +ASSERT_TRUE(locked.exchange(false)); + } JDevlieghere wrote: https://github.com/llvm/llvm-project/pull/133840 https://github.com/llvm/llvm-project/pull/133295 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Prefer PointerType::get with LLVMContext over Type (NFC) (PR #133869)
https://github.com/junlarsen created https://github.com/llvm/llvm-project/pull/133869 Part of #123569 >From 84298350a0cab997d4d98ae16f6203a07cfcbb13 Mon Sep 17 00:00:00 2001 From: Mats Jun Larsen Date: Mon, 31 Mar 2025 18:57:35 +0200 Subject: [PATCH] [lldb] Prefer PointerType::get with LLVMContext over Type (NFC) Part of #123569 --- .../Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp | 4 ++-- lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp index ae0682d717948..c7c292a8a7e42 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp @@ -240,7 +240,7 @@ class Instrumenter { FunctionType *fun_ty = FunctionType::get( llvm::Type::getVoidTy(m_module.getContext()), params, true); -PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); +PointerType *fun_ptr_ty = PointerType::getUnqual(m_module.getContext()); Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false); return {fun_ty, ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty)}; @@ -264,7 +264,7 @@ class Instrumenter { FunctionType *fun_ty = FunctionType::get( llvm::Type::getVoidTy(m_module.getContext()), params, true); -PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty); +PointerType *fun_ptr_ty = PointerType::getUnqual(m_module.getContext()); Constant *fun_addr_int = ConstantInt::get(GetIntptrTy(), start_address, false); return {fun_ty, ConstantExpr::getIntToPtr(fun_addr_int, fun_ptr_ty)}; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index 879f006336ba5..a343766ce9c4f 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -462,7 +462,7 @@ bool IRForTarget::RewriteObjCConstString(llvm::GlobalVariable *ns_str, FunctionType::get(ns_str_ty, CFSCWB_arg_types, false); // Build the constant containing the pointer to the function -PointerType *CFSCWB_ptr_ty = PointerType::getUnqual(CFSCWB_ty); +PointerType *CFSCWB_ptr_ty = PointerType::getUnqual(m_module->getContext()); Constant *CFSCWB_addr_int = ConstantInt::get(m_intptr_ty, CFStringCreateWithBytes_addr, false); m_CFStringCreateWithBytes = { @@ -814,7 +814,7 @@ bool IRForTarget::RewriteObjCSelector(Instruction *selector_load) { FunctionType::get(sel_ptr_type, srN_arg_types, false); // Build the constant containing the pointer to the function -PointerType *srN_ptr_ty = PointerType::getUnqual(srN_type); +PointerType *srN_ptr_ty = PointerType::getUnqual(m_module->getContext()); Constant *srN_addr_int = ConstantInt::get(m_intptr_ty, sel_registerName_addr, false); m_sel_registerName = {srN_type, @@ -1031,7 +1031,7 @@ bool IRForTarget::MaybeHandleVariable(Value *llvm_value_ptr) { // // We also do this for any user-declared persistent variables. compiler_type = compiler_type.GetPointerType(); - value_type = PointerType::get(global_variable->getType(), 0); + value_type = PointerType::getUnqual(global_variable->getContext()); } else { value_type = global_variable->getType(); } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Prefer PointerType::get with LLVMContext over Type (NFC) (PR #133869)
junlarsen wrote: * **#133869** https://app.graphite.dev/github/pr/llvm/llvm-project/133869?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/133869?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/133869 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][NFC]Move fields that might be referenced in scope-exit to beginning (PR #133785)
https://github.com/oontvoo created https://github.com/llvm/llvm-project/pull/133785 Details: The ScopedDiscpatcher's dtor may reference these fields so we need the fields' dtor to be be invoked *after* the dispatcher's. >From 55d20dc85389bdeacf806b18ff132030e2626d9a Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Mon, 31 Mar 2025 15:47:06 -0400 Subject: [PATCH] [LLDB][NFC]Move fields that might be referenced in scope-exit to beginning of functions so they are still valid when referenced. --- lldb/source/Interpreter/CommandInterpreter.cpp | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 8e70922b9bb8d..7fbdf7fe70223 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1886,6 +1886,13 @@ bool CommandInterpreter::HandleCommand(const char *command_line, LazyBool lazy_add_to_history, CommandReturnObject &result, bool force_repeat_command) { + // These are assigned later in the function but they must be declared before + // the ScopedDispatcher object because we need their destructions to occur + // after the dispatcher's dtor call, which may reference them. + // TODO: This function could be refactored? + std::string parsed_command_args; + CommandObject *cmd_obj = nullptr; + telemetry::ScopedDispatcher helper(&m_debugger); const bool detailed_command_telemetry = telemetry::TelemetryManager::GetInstance() @@ -1896,8 +1903,6 @@ bool CommandInterpreter::HandleCommand(const char *command_line, std::string command_string(command_line); std::string original_command_string(command_string); std::string real_original_command_string(command_string); - std::string parsed_command_args; - CommandObject *cmd_obj = nullptr; helper.DispatchNow([&](lldb_private::telemetry::CommandInfo *info) { info->command_id = command_id; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/133780 >From 2f22b24840ec0f3cb650da97ad0bd2caea0a8cef Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 31 Mar 2025 11:47:02 -0700 Subject: [PATCH 1/2] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) Convert Breakpoint & Watchpoints structs to classes to provide proper access control. This is in preparation for adopting SBMutex to protect the underlying SBBreakpoint and SBWatchpoint. --- lldb/tools/lldb-dap/Breakpoint.cpp| 24 + lldb/tools/lldb-dap/Breakpoint.h | 14 +++-- lldb/tools/lldb-dap/BreakpointBase.h | 23 lldb/tools/lldb-dap/DAP.cpp | 8 +-- lldb/tools/lldb-dap/DAP.h | 2 +- lldb/tools/lldb-dap/DAPForward.h | 16 +++--- lldb/tools/lldb-dap/ExceptionBreakpoint.cpp | 18 +++ lldb/tools/lldb-dap/ExceptionBreakpoint.h | 28 ++ lldb/tools/lldb-dap/FunctionBreakpoint.cpp| 6 +-- lldb/tools/lldb-dap/FunctionBreakpoint.h | 12 +++-- .../Handler/ExceptionInfoRequestHandler.cpp | 4 +- .../Handler/SetBreakpointsRequestHandler.cpp | 7 +-- .../SetDataBreakpointsRequestHandler.cpp | 4 +- .../SetExceptionBreakpointsRequestHandler.cpp | 4 +- .../SetFunctionBreakpointsRequestHandler.cpp | 8 +-- ...etInstructionBreakpointsRequestHandler.cpp | 6 +-- lldb/tools/lldb-dap/InstructionBreakpoint.cpp | 11 ++-- lldb/tools/lldb-dap/InstructionBreakpoint.h | 19 --- lldb/tools/lldb-dap/JSONUtils.cpp | 8 +-- lldb/tools/lldb-dap/SourceBreakpoint.cpp | 6 +-- lldb/tools/lldb-dap/SourceBreakpoint.h| 52 ++- lldb/tools/lldb-dap/Watchpoint.cpp| 21 lldb/tools/lldb-dap/Watchpoint.h | 22 23 files changed, 180 insertions(+), 143 deletions(-) diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp index eba534dcc51c7..188a51909f111 100644 --- a/lldb/tools/lldb-dap/Breakpoint.cpp +++ b/lldb/tools/lldb-dap/Breakpoint.cpp @@ -19,21 +19,21 @@ using namespace lldb_dap; -void Breakpoint::SetCondition() { bp.SetCondition(condition.c_str()); } +void Breakpoint::SetCondition() { m_bp.SetCondition(condition.c_str()); } void Breakpoint::SetHitCondition() { uint64_t hitCount = 0; if (llvm::to_integer(hitCondition, hitCount)) -bp.SetIgnoreCount(hitCount - 1); +m_bp.SetIgnoreCount(hitCount - 1); } void Breakpoint::CreateJsonObject(llvm::json::Object &object) { // Each breakpoint location is treated as a separate breakpoint for VS code. // They don't have the notion of a single breakpoint with multiple locations. - if (!bp.IsValid()) + if (!m_bp.IsValid()) return; - object.try_emplace("verified", bp.GetNumResolvedLocations() > 0); - object.try_emplace("id", bp.GetID()); + object.try_emplace("verified", m_bp.GetNumResolvedLocations() > 0); + object.try_emplace("id", m_bp.GetID()); // VS Code DAP doesn't currently allow one breakpoint to have multiple // locations so we just report the first one. If we report all locations // then the IDE starts showing the wrong line numbers and locations for @@ -43,20 +43,20 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { // this as the breakpoint location since it will have a complete location // that is at least loaded in the current process. lldb::SBBreakpointLocation bp_loc; - const auto num_locs = bp.GetNumLocations(); + const auto num_locs = m_bp.GetNumLocations(); for (size_t i = 0; i < num_locs; ++i) { -bp_loc = bp.GetLocationAtIndex(i); +bp_loc = m_bp.GetLocationAtIndex(i); if (bp_loc.IsResolved()) break; } // If not locations are resolved, use the first location. if (!bp_loc.IsResolved()) -bp_loc = bp.GetLocationAtIndex(0); +bp_loc = m_bp.GetLocationAtIndex(0); auto bp_addr = bp_loc.GetAddress(); if (bp_addr.IsValid()) { std::string formatted_addr = -"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(bp.GetTarget())); +"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget())); object.try_emplace("instructionReference", formatted_addr); auto line_entry = bp_addr.GetLineEntry(); const auto line = line_entry.GetLine(); @@ -69,10 +69,12 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { } } -bool Breakpoint::MatchesName(const char *name) { return bp.MatchesName(name); } +bool Breakpoint::MatchesName(const char *name) { + return m_bp.MatchesName(name); +} void Breakpoint::SetBreakpoint() { - bp.AddName(kDAPBreakpointLabel); + m_bp.AddName(kDAPBreakpointLabel); if (!condition.empty()) SetCondition(); if (!hitCondition.empty()) diff --git a/lldb/tools/lldb-dap/Breakpoint.h b/lldb/tools/lldb-dap/Breakpoint.h index a726f27e59ee0..580017125af44 100644 --- a/lldb/tools/lldb-dap/Breakpoint.h +++ b/lldb/tools/lldb-dap/Breakpo
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
@@ -12,25 +12,35 @@ #include "DAPForward.h" #include "lldb/API/SBBreakpoint.h" #include "lldb/lldb-enumerations.h" +#include "llvm/ADT/StringRef.h" #include #include namespace lldb_dap { -struct ExceptionBreakpoint { - DAP &dap; - std::string filter; - std::string label; - lldb::LanguageType language; - bool default_value = false; - lldb::SBBreakpoint bp; +class ExceptionBreakpoint { +public: ExceptionBreakpoint(DAP &d, std::string f, std::string l, lldb::LanguageType lang) - : dap(d), filter(std::move(f)), label(std::move(l)), language(lang), -bp() {} + : m_dap(d), m_filter(std::move(f)), m_label(std::move(l)), +m_language(lang), m_bp() {} void SetBreakpoint(); void ClearBreakpoint(); + void CreateJsonObject(llvm::json::Object &object); ashgti wrote: I don't think `CreateJsonObject` is used for ExceptionBreakpoint, but I may be wrong. https://github.com/llvm/llvm-project/pull/133780 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix intel trace plugin tests (PR #133826)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: David Peixotto (dmpots) Changes The tests for the [intel-pt](https://github.com/llvm/llvm-project/blob/348374028970c956f2e49ab7553b495d7408ccd9/lldb/docs/use/intel_pt.rst) trace plugin were failing for multiple reasons. On machines where tracing is supported many of the tests were crashing because of a nullptr dereference. It looks like the `core_file` parameter in `ProcessTrace::CreateInstance` was once ignored, but was changed to always being dereferenced. This caused the tests to fail even when tracing was supported. On machines where tracing is not supported we would still run tests that attempt to take a trace. These would obviously fail because the required hardware is not present. Note that some of the tests simply read serialized json as trace files which does not require any special hardware. This PR fixes these two issues by guarding the pointer dereference and then skipping unsupported tests on machines. With these changes the trace tests pass on both types of machines. We also add a new unit test to validate that a process can be created with a nullptr core_file through the generic process trace plugin path. --- Full diff: https://github.com/llvm/llvm-project/pull/133826.diff 10 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py (+7) - (modified) lldb/source/Target/ProcessTrace.cpp (+2-1) - (modified) lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py (+2) - (modified) lldb/test/API/commands/trace/TestTraceEvents.py (+1) - (modified) lldb/test/API/commands/trace/TestTraceSave.py (+2) - (modified) lldb/test/API/commands/trace/TestTraceStartStop.py (+1) - (modified) lldb/test/API/commands/trace/TestTraceTSC.py (+1) - (modified) lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py (+1) - (modified) lldb/unittests/Process/CMakeLists.txt (+3-1) - (added) lldb/unittests/Process/ProcessTraceTest.cpp (+63) ``diff diff --git a/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py index f1b7d7c33bf07..176dce6a435f7 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/intelpt/intelpt_testcase.py @@ -18,6 +18,13 @@ def wrapper(*args, **kwargs): return wrapper +def skipIfCpuDoesNotSupportIntelPT(func): +"""Skip tests if the system does not support tracing.""" + +supported = os.path.exists("/sys/bus/event_source/devices/intel_pt/type") +return unittest.skipIf(not supported, "intel-pt tracing is unsupported")(func) + + # Class that should be used by all python Intel PT tests. # # It has a handy check that skips the test if the intel-pt plugin is not enabled. diff --git a/lldb/source/Target/ProcessTrace.cpp b/lldb/source/Target/ProcessTrace.cpp index f131339905474..02272b1651da5 100644 --- a/lldb/source/Target/ProcessTrace.cpp +++ b/lldb/source/Target/ProcessTrace.cpp @@ -36,7 +36,8 @@ ProcessSP ProcessTrace::CreateInstance(TargetSP target_sp, bool can_connect) { if (can_connect) return nullptr; - return std::make_shared(target_sp, listener_sp, *crash_file); + return std::make_shared(target_sp, listener_sp, +crash_file ? *crash_file : FileSpec()); } bool ProcessTrace::CanDebug(TargetSP target_sp, bool plugin_specified_by_name) { diff --git a/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py b/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py index 761c262ae4de0..8b30414953d7d 100644 --- a/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py +++ b/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py @@ -133,6 +133,7 @@ def testFunctionCallsWithErrors(self): ], ) +@skipIfCpuDoesNotSupportIntelPT def testInlineFunctionCalls(self): self.expect( "file " + os.path.join(self.getSourceDir(), "inline-function", "a.out") @@ -194,6 +195,7 @@ def testInlineFunctionCalls(self): ], ) +@skipIfCpuDoesNotSupportIntelPT def testIncompleteInlineFunctionCalls(self): self.expect( "file " + os.path.join(self.getSourceDir(), "inline-function", "a.out") diff --git a/lldb/test/API/commands/trace/TestTraceEvents.py b/lldb/test/API/commands/trace/TestTraceEvents.py index c20bcc247105b..7e6e07db0c1dd 100644 --- a/lldb/test/API/commands/trace/TestTraceEvents.py +++ b/lldb/test/API/commands/trace/TestTraceEvents.py @@ -45,6 +45,7 @@ def testCPUEvents(self): ], ) +@skipIfCpuDoesNotSupportIntelPT @testSBAPIAndCommands def testPauseEvents(self): """ diff --git a/lldb/test/API/commands/trace/TestTraceSave.py b/lldb/test/API/commands/trace/TestTraceSave.py index af38669cb4fce..d8f39a1f3fa2
[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/133290 >From effad9525461611ed47598b53a77ee5aabb0e4cf Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Thu, 27 Mar 2025 11:04:26 -0700 Subject: [PATCH 1/3] Add a new affordance that the Python module in a dSYM can be told what target it has been loaded into. When lldb is loading modules, while creating a target, it will run "command script import" on any Python modules in Resources/Python in the dSYM. However, this happens WHILE the target is being created, so it is not yet in the target list. That means that these scripts can't act on the target that they a part of when they get loaded. This patch adds a new python API that lldb will call: __lldb_module_added_to_target if it is defined in the module, passing in the Target the module was being added to, so that code in these dSYM's don't have to guess. --- lldb/bindings/python/python-wrapper.swig | 22 ++ .../lldb/Interpreter/ScriptInterpreter.h | 3 +- lldb/source/Core/Module.cpp | 4 +- lldb/source/Interpreter/ScriptInterpreter.cpp | 3 +- .../Python/SWIGPythonBridge.h | 4 ++ .../Python/ScriptInterpreterPython.cpp| 9 ++- .../Python/ScriptInterpreterPythonImpl.h | 3 +- lldb/test/API/macosx/dsym_modules/Makefile| 4 ++ .../macosx/dsym_modules/TestdSYMModuleInit.py | 68 +++ lldb/test/API/macosx/dsym_modules/has_dsym.py | 21 ++ lldb/test/API/macosx/dsym_modules/main.c | 15 .../Python/PythonTestSuite.cpp| 7 ++ 12 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 lldb/test/API/macosx/dsym_modules/Makefile create mode 100644 lldb/test/API/macosx/dsym_modules/TestdSYMModuleInit.py create mode 100644 lldb/test/API/macosx/dsym_modules/has_dsym.py create mode 100644 lldb/test/API/macosx/dsym_modules/main.c diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig index 57c7ac387145e..3d1d04e47e70b 100644 --- a/lldb/bindings/python/python-wrapper.swig +++ b/lldb/bindings/python/python-wrapper.swig @@ -966,6 +966,28 @@ bool lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue( return true; } +bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget( +const char *python_module_name, const char *session_dictionary_name, +lldb::TargetSP target_sp) { + std::string python_function_name_string = python_module_name; + python_function_name_string += ".__lldb_module_added_to_target"; + const char *python_function_name = python_function_name_string.c_str(); + + PyErr_Cleaner py_err_cleaner(true); + + auto dict = PythonModule::MainModule().ResolveName( + session_dictionary_name); + auto pfunc = PythonObject::ResolveNameWithDictionary( + python_function_name, dict); + + if (!pfunc.IsAllocated()) +return true; + + pfunc(SWIGBridge::ToSWIGWrapper(std::move(target_sp)), dict); + + return true; +} + bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit( const char *python_module_name, const char *session_dictionary_name, lldb::DebuggerSP debugger) { diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index c5aa19959aa61..25e82779f05c6 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h @@ -522,7 +522,8 @@ class ScriptInterpreter : public PluginInterface { LoadScriptingModule(const char *filename, const LoadScriptOptions &options, lldb_private::Status &error, StructuredData::ObjectSP *module_sp = nullptr, - FileSpec extra_search_dir = {}); + FileSpec extra_search_dir = {}, + lldb::TargetSP loaded_into_target_sp = {}); virtual bool IsReservedWord(const char *word) { return false; } diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index d70f292abaea4..7b52ba08cd379 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1485,7 +1485,9 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error, scripting_fspec.Dump(scripting_stream.AsRawOstream()); LoadScriptOptions options; bool did_load = script_interpreter->LoadScriptingModule( -scripting_stream.GetData(), options, error); +scripting_stream.GetData(), options, error, +/*module_sp*/ nullptr, /*extra_path*/ {}, +target->shared_from_this()); if (!did_load) return false; } diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index 4424b6c894356..8d9655a07e7e9 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
[Lldb-commits] [lldb] [lldb] Use DenseMap::insert_range (NFC) (PR #133846)
https://github.com/kuhar approved this pull request. https://github.com/llvm/llvm-project/pull/133846 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 4d68cf3 - [lldb] Use DenseMap::insert_range (NFC) (#133846)
Author: Kazu Hirata Date: 2025-03-31T22:11:22-07:00 New Revision: 4d68cf384df6be405598ec23be0e23e0837db3a3 URL: https://github.com/llvm/llvm-project/commit/4d68cf384df6be405598ec23be0e23e0837db3a3 DIFF: https://github.com/llvm/llvm-project/commit/4d68cf384df6be405598ec23be0e23e0837db3a3.diff LOG: [lldb] Use DenseMap::insert_range (NFC) (#133846) Added: Modified: lldb/source/Plugins/ABI/X86/ABIX86.cpp Removed: diff --git a/lldb/source/Plugins/ABI/X86/ABIX86.cpp b/lldb/source/Plugins/ABI/X86/ABIX86.cpp index 3c55a6ea17e8f..db170700d3f65 100644 --- a/lldb/source/Plugins/ABI/X86/ABIX86.cpp +++ b/lldb/source/Plugins/ABI/X86/ABIX86.cpp @@ -191,7 +191,7 @@ BaseRegToRegsMap makeBaseRegMap(bool is64bit) { // higher YMM registers (specific to amd64) YMM(8), YMM(9), YMM(10), YMM(11), YMM(12), YMM(13), YMM(14), YMM(15)}}; -out.insert(amd64_regs.begin(), amd64_regs.end()); +out.insert_range(amd64_regs); } return out; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use DenseMap::insert_range (NFC) (PR #133846)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/133846 ___ 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 mutex through the SB API (PR #133295)
@@ -0,0 +1,57 @@ +//===-- SBMutexTest.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 +// +//===--===// + +// Use the umbrella header for -Wdocumentation. +#include "lldb/API/LLDB.h" + +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBTarget.h" +#include "gtest/gtest.h" +#include +#include +#include +#include + +using namespace lldb; +using namespace lldb_private; + +class SBMutexTest : public testing::Test { +protected: + void SetUp() override { debugger = SBDebugger::Create(); } + void TearDown() override { SBDebugger::Destroy(debugger); } + + SubsystemRAII subsystems; + SBDebugger debugger; +}; + +TEST_F(SBMutexTest, LockTest) { + lldb::SBTarget target = debugger.GetDummyTarget(); + + std::future f; + { +std::atomic locked = false; +lldb::SBMutex lock = target.GetAPIMutex(); +std::lock_guard lock_guard(lock); +ASSERT_FALSE(locked.exchange(true)); + +f = std::async(std::launch::async, [&]() { + ASSERT_TRUE(locked); + target.BreakpointCreateByName("foo", "bar"); + ASSERT_FALSE(locked); +}); +ASSERT_TRUE(f.valid()); + +// Wait 500ms to confirm the thread is blocked. +auto status = f.wait_for(std::chrono::milliseconds(500)); +ASSERT_EQ(status, std::future_status::timeout); + +ASSERT_TRUE(locked.exchange(false)); + } slackito wrote: I'm seeing use-after-scope asan failures with this test. I think the problem is that `locked` can be accessed asynchronously at any time up util the point where `f.wait()` is called, but `locked` is declared inside these braces so it can be destroyed at the closing brace before the call to `f.wait()`. `locked` should outlive the wait operation. https://github.com/llvm/llvm-project/pull/133295 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/133780 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add enable/disable api for SystemRuntime plugins (PR #133794)
dmpots wrote: This PR modifies the PluginManager to support enable/disable. A following [commit](https://github.com/dmpots/llvm-project/commit/aaa3ab3d063580747bb106f39e6792232cc0af00) will expose the commands to the user. This is currently only working for the SystemRuntime plugins. Once these first commits land I plan to do the same for the other plugin types. https://github.com/llvm/llvm-project/pull/133794 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target (PR #132688)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/132688 ___ 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 cancelling a request. (PR #130169)
@@ -19,10 +19,39 @@ #include "lldb/lldb-forward.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include +#include +#include namespace lldb_dap { +class EndOfFileError : public llvm::ErrorInfo { +public: + static char ID; + + EndOfFileError() = default; + + void log(llvm::raw_ostream &OS) const override { +OS << "End of file reached."; JDevlieghere wrote: Errors needs to be able to be concatenated, so no capitalization/period. ```suggestion OS << "end of file reached"; ``` https://github.com/llvm/llvm-project/pull/130169 ___ 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 cancelling a request. (PR #130169)
@@ -19,10 +19,39 @@ #include "lldb/lldb-forward.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include +#include +#include namespace lldb_dap { +class EndOfFileError : public llvm::ErrorInfo { +public: + static char ID; + + EndOfFileError() = default; + + void log(llvm::raw_ostream &OS) const override { +OS << "End of file reached."; + } + std::error_code convertToErrorCode() const override { +return llvm::inconvertibleErrorCode(); + } +}; + +class TimeoutError : public llvm::ErrorInfo { +public: + static char ID; + + TimeoutError() = default; + + void log(llvm::raw_ostream &OS) const override { +OS << "Operation timed out."; + } ashgti wrote: Done. https://github.com/llvm/llvm-project/pull/130169 ___ 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 cancelling a request. (PR #130169)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/130169 >From c183231db80d6c97bdd5e9bd0b21d041189146e8 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Tue, 18 Mar 2025 14:05:38 -0700 Subject: [PATCH 01/12] [lldb-dap] Adding support for cancelling a request. Adding support for cancelling requests. There are two forms of request cancellation. * Preemptively cancelling a request that is in the queue. * Actively cancelling the in progress request as a best effort attempt using `SBDebugger.RequestInterrupt()`. --- lldb/test/API/tools/lldb-dap/cancel/Makefile | 3 + .../tools/lldb-dap/cancel/TestDAP_cancel.py | 101 lldb/test/API/tools/lldb-dap/cancel/main.c| 6 + .../tools/lldb-dap/launch/TestDAP_launch.py | 1 + lldb/tools/lldb-dap/CMakeLists.txt| 1 + lldb/tools/lldb-dap/DAP.cpp | 145 -- lldb/tools/lldb-dap/DAP.h | 3 + .../lldb-dap/Handler/CancelRequestHandler.cpp | 55 +++ lldb/tools/lldb-dap/Handler/RequestHandler.h | 10 ++ .../lldb-dap/Protocol/ProtocolRequests.cpp| 7 + .../lldb-dap/Protocol/ProtocolRequests.h | 20 +++ lldb/tools/lldb-dap/Transport.cpp | 37 +++-- lldb/tools/lldb-dap/Transport.h | 3 +- lldb/tools/lldb-dap/lldb-dap.cpp | 5 +- 14 files changed, 377 insertions(+), 20 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/cancel/Makefile create mode 100644 lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py create mode 100644 lldb/test/API/tools/lldb-dap/cancel/main.c create mode 100644 lldb/tools/lldb-dap/Handler/CancelRequestHandler.cpp diff --git a/lldb/test/API/tools/lldb-dap/cancel/Makefile b/lldb/test/API/tools/lldb-dap/cancel/Makefile new file mode 100644 index 0..10495940055b6 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/cancel/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py new file mode 100644 index 0..f3b2f9fcb7a92 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py @@ -0,0 +1,101 @@ +""" +Test lldb-dap cancel request +""" + +import time + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +import lldbdap_testcase + + +class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase): +def send_async_req(self, command: str, arguments={}) -> int: +seq = self.dap_server.sequence +self.dap_server.send_packet( +{ +"type": "request", +"command": command, +"arguments": arguments, +} +) +return seq + +def async_blocking_request(self, duration: float) -> int: +""" +Sends an evaluate request that will sleep for the specified duration to +block the request handling thread. +""" +return self.send_async_req( +command="evaluate", +arguments={ +"expression": '`script import time; print("starting sleep", file=lldb.debugger.GetOutputFileHandle()); time.sleep({})'.format( +duration +), +"context": "repl", +}, +) + +def async_cancel(self, requestId: int) -> int: +return self.send_async_req(command="cancel", arguments={"requestId": requestId}) + +def test_pending_request(self): +""" +Tests cancelling a pending request. +""" +program = self.getBuildArtifact("a.out") +self.build_and_launch(program, stopOnEntry=True) +self.continue_to_next_stop() + +# Use a relatively short timeout since this is only to ensure the +# following request is queued. +blocking_seq = self.async_blocking_request(duration=1.0) +# Use a longer timeout to ensure we catch if the request was interrupted +# properly. +pending_seq = self.async_blocking_request(duration=self.timeoutval) +cancel_seq = self.async_cancel(requestId=pending_seq) + +blocking_resp = self.dap_server.recv_packet(filter_type=["response"]) +self.assertEqual(blocking_resp["request_seq"], blocking_seq) +self.assertEqual(blocking_resp["command"], "evaluate") +self.assertEqual(blocking_resp["success"], True) + +pending_resp = self.dap_server.recv_packet(filter_type=["response"]) +self.assertEqual(pending_resp["request_seq"], pending_seq) +self.assertEqual(pending_resp["command"], "evaluate") +self.assertEqual(pending_resp["success"], False) +self.assertEqual(pending_resp["message"], "cancelled") + +cancel_resp = self.dap_server.recv_packet(filter_type=["response"]) +self.assertEqual(cancel_resp["request_seq"], cancel_seq) +self.assertEqual(cancel_resp["command"], "
[Lldb-commits] [lldb] [LLDB][NFC]Move fields that might be referenced in scope-exit to beginning (PR #133785)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Vy Nguyen (oontvoo) Changes Details: The ScopedDiscpatcher's dtor may reference these fields so we need the fields' dtor to be be invoked *after* the dispatcher's. --- Full diff: https://github.com/llvm/llvm-project/pull/133785.diff 1 Files Affected: - (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+7-2) ``diff diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 8e70922b9bb8d..7fbdf7fe70223 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1886,6 +1886,13 @@ bool CommandInterpreter::HandleCommand(const char *command_line, LazyBool lazy_add_to_history, CommandReturnObject &result, bool force_repeat_command) { + // These are assigned later in the function but they must be declared before + // the ScopedDispatcher object because we need their destructions to occur + // after the dispatcher's dtor call, which may reference them. + // TODO: This function could be refactored? + std::string parsed_command_args; + CommandObject *cmd_obj = nullptr; + telemetry::ScopedDispatcher helper(&m_debugger); const bool detailed_command_telemetry = telemetry::TelemetryManager::GetInstance() @@ -1896,8 +1903,6 @@ bool CommandInterpreter::HandleCommand(const char *command_line, std::string command_string(command_line); std::string original_command_string(command_string); std::string real_original_command_string(command_string); - std::string parsed_command_args; - CommandObject *cmd_obj = nullptr; helper.DispatchNow([&](lldb_private::telemetry::CommandInfo *info) { info->command_id = command_id; `` https://github.com/llvm/llvm-project/pull/133785 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] a8d2d16 - Parallelize module loading in POSIX dyld code (#130912)
Author: Tom Yang Date: 2025-03-31T13:29:31-07:00 New Revision: a8d2d169c7add4b0106ae76e186cf815c0b84825 URL: https://github.com/llvm/llvm-project/commit/a8d2d169c7add4b0106ae76e186cf815c0b84825 DIFF: https://github.com/llvm/llvm-project/commit/a8d2d169c7add4b0106ae76e186cf815c0b84825.diff LOG: Parallelize module loading in POSIX dyld code (#130912) This patch improves LLDB launch time on Linux machines for **preload scenarios**, particularly for executables with a lot of shared library dependencies (or modules). Specifically: * Launching a binary with `target.preload-symbols = true` * Attaching to a process with `target.preload-symbols = true`. It's completely controlled by a new flag added in the first commit `plugin.dynamic-loader.posix-dyld.parallel-module-load`, which *defaults to false*. This was inspired by similar work on Darwin #110646. Some rough numbers to showcase perf improvement, run on a very beefy machine: * Executable with ~5600 modules: baseline 45s, improvement 15s * Executable with ~3800 modules: baseline 25s, improvement 10s * Executable with ~6650 modules: baseline 67s, improvement 20s * Executable with ~12500 modules: baseline 185s, improvement 85s * Executable with ~14700 modules: baseline 235s, improvement 120s A lot of targets we deal with have a *ton* of modules, and unfortunately we're unable to convince other folks to reduce the number of modules, so performance improvements like this can be very impactful for user experience. This patch achieves the performance improvement by parallelizing `DynamicLoaderPOSIXDYLD::RefreshModules` for the launch scenario, and `DynamicLoaderPOSIXDYLD::LoadAllCurrentModules` for the attach scenario. The commits have some context on their specific changes as well -- hopefully this helps the review. # More context on implementation We discovered the bottlenecks by via `perf record -g -p ` on a Linux machine. With an executable known to have 1000s of shared library dependencies, I ran ``` (lldb) b main (lldb) r # taking a while ``` and showed the resulting perf trace (snippet shown) ``` Samples: 85K of event 'cycles:P', Event count (approx.): 54615855812 Children Self Command Shared Object Symbol - 93.54% 0.00% intern-state libc.so.6 [.] clone3 clone3 start_thread lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) r std::_Function_handler::_M_invoke(std::_Any_data const&) lldb_private::Process::RunPrivateStateThread(bool) n - lldb_private::Process::HandlePrivateEvent(std::shared_ptr&) - 93.54% lldb_private::Process::ShouldBroadcastEvent(lldb_private::Event*) - 93.54% lldb_private::ThreadList::ShouldStop(lldb_private::Event*) - lldb_private::Thread::ShouldStop(lldb_private::Event*) * - 93.53% lldb_private::StopInfoBreakpoint::ShouldStopSynchronous(lldb_private::Event*) t - 93.52% lldb_private::BreakpointSite::ShouldStop(lldb_private::StoppointCallbackContext*) i lldb_private::BreakpointLocationCollection::ShouldStop(lldb_private::StoppointCallbackContext*) k lldb_private::BreakpointLocation::ShouldStop(lldb_private::StoppointCallbackContext*) b lldb_private::BreakpointOptions::InvokeCallback(lldb_private::StoppointCallbackContext*, unsigned long, unsigned long)i DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(void*, lldb_private::StoppointCallbackContext*, unsigned long, unsigned lo - DynamicLoaderPOSIXDYLD::RefreshModules() O - 93.42% DynamicLoaderPOSIXDYLD::RefreshModules()::$_0::operator()(DYLDRendezvous::SOEntry const&) const u - 93.40% DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(lldb_private::FileSpec const&, unsigned long, unsigned long, bools - lldb_private::DynamicLoader::LoadModuleAtAddress(lldb_private::FileSpec const&, unsigned long, unsigned long, boos - 83.90% lldb_private::DynamicLoader::FindModuleViaTarget(lldb_private::FileSpec const&) o - 83.01% lldb_private::Target::GetOrCreateModule(lldb_private::ModuleSpec const&, bool, lldb_private::Status* - 77.89% lldb_private::Module::PreloadSymbols() - 44.06% lldb
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
@@ -49,6 +41,17 @@ struct BreakpointBase { /// breakpoint in one of the DAP breakpoints that we should report changes /// for. static constexpr const char *kDAPBreakpointLabel = "dap"; + +protected: + /// Associated DAP session. + DAP &dap; + + /// An optional expression for conditional breakpoints. + std::string condition; + + /// An optional expression that controls how many hits of the breakpoint are + /// ignored. The backend is expected to interpret the expression as needed + std::string hitCondition; ashgti wrote: nit: Should we use a `m_` prefix on any of these protected variables? https://github.com/llvm/llvm-project/pull/133780 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
@@ -52,14 +37,33 @@ struct SourceBreakpoint : public Breakpoint { static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location); -}; -inline bool operator<(const SourceBreakpoint &lhs, - const SourceBreakpoint &rhs) { - if (lhs.line == rhs.line) -return lhs.column < rhs.column; - return lhs.line < rhs.line; -} + inline bool operator<(const SourceBreakpoint &rhs) { +if (line == rhs.line) + return column < rhs.column; +return line < rhs.line; + } + + uint32_t GetLine() const { return line; } + uint32_t GetColumn() const { return column; } + +protected: + // logMessage part can be either a raw text or an expression. + struct LogMessagePart { +LogMessagePart(llvm::StringRef text, bool is_expr) +: text(text), is_expr(is_expr) {} +std::string text; +bool is_expr; + }; ashgti wrote: Ah, my bad, I'm thinking of `condition` and `hitCondition` that are supported by multiple types of breakpoints. https://github.com/llvm/llvm-project/pull/133780 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Make the DAP server resilient against broken pipes (PR #133791)
ashgti wrote: A `SIGPIPE` is raised if your process writes a pipe that is closed on the other end. If the python script is getting that then `lldb-dap` must have closed stdin. The Transport `input` does take ownership of stdin (https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/lldb-dap.cpp#L574) so that will be closed once `Transport` is dealloced, but I don't think that would happen unless `main` had already exited. I think its probably fine to catch this, but the `SIGPIPE` can also happen if you try to write to the FD as well. https://github.com/llvm/llvm-project/pull/133791 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
@@ -52,14 +37,33 @@ struct SourceBreakpoint : public Breakpoint { static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process, lldb::SBThread &thread, lldb::SBBreakpointLocation &location); -}; -inline bool operator<(const SourceBreakpoint &lhs, - const SourceBreakpoint &rhs) { - if (lhs.line == rhs.line) -return lhs.column < rhs.column; - return lhs.line < rhs.line; -} + inline bool operator<(const SourceBreakpoint &rhs) { +if (line == rhs.line) + return column < rhs.column; +return line < rhs.line; + } + + uint32_t GetLine() const { return line; } + uint32_t GetColumn() const { return column; } + +protected: + // logMessage part can be either a raw text or an expression. + struct LogMessagePart { +LogMessagePart(llvm::StringRef text, bool is_expr) +: text(text), is_expr(is_expr) {} +std::string text; +bool is_expr; + }; JDevlieghere wrote: Looking at the spec, seems like this is limited to SourceBreakpoints: ``` /** * The debug adapter supports log points by interpreting the `logMessage` * attribute of the `SourceBreakpoint`. */ supportsLogPoints?: boolean; ``` https://github.com/llvm/llvm-project/pull/133780 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Add enable/disable api for SystemRuntime plugins (PR #133794)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: David Peixotto (dmpots) Changes This commit adds support for enabling and disabling plugins by name. The changes are made generically in the `PluginInstances` class, but currently we only expose the ability to SystemRuntime plugins. Other plugins types can be added easily. We had a few design goals for how disabled plugins should work 1. Plugins that are disabled should still be visible to the system. This allows us to dynamically enable and disable plugins and report their state to the user. 2. Plugin order should be stable across disable and enable changes. We want avoid changing the order of plugin lookup. When a plugin is re-enabled it should return to its original slot in the creation order. 3. Disabled plugins should not appear in PluginManager operations. Clients should be able to assume that only enabled plugins will be returned from the PluginManager. For the implementation we modify the plugin instance to maintain a bool of its enabled state. Existing clients external to the Instances class expect to iterate over only enabled instance so we skip over disabed instances in the query and snapshot apis. This way the client does not have to manually check which instances are enabled. --- Patch is 21.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133794.diff 4 Files Affected: - (modified) lldb/include/lldb/Core/PluginManager.h (+13) - (modified) lldb/source/Core/PluginManager.cpp (+52-3) - (modified) lldb/unittests/Core/CMakeLists.txt (+1) - (added) lldb/unittests/Core/PluginManagerTest.cpp (+367) ``diff diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index e4e0c3eea67f8..a6dab045adf27 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -22,6 +22,7 @@ #include #include +#include #define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName) \ namespace lldb_private { \ @@ -47,6 +48,12 @@ class CommandInterpreter; class Debugger; class StringList; +struct RegisteredPluginInfo { + llvm::StringRef name = ""; + llvm::StringRef description = ""; + bool enabled = false; +}; + class PluginManager { public: static void Initialize(); @@ -168,6 +175,12 @@ class PluginManager { static SystemRuntimeCreateInstance GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx); + static std::vector GetSystemRuntimePluginInfo(); + + // Modify the enabled state of a SystemRuntime plugin. + // Returns false if the plugin name is not found. + static bool SetSystemRuntimePluginEnabled(llvm::StringRef name, bool enabled); + // ObjectFile static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 95eb940efcef2..e6cb248ef31ce 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -188,11 +188,13 @@ template struct PluginInstance { PluginInstance(llvm::StringRef name, llvm::StringRef description, Callback create_callback, DebuggerInitializeCallback debugger_init_callback = nullptr) - : name(name), description(description), create_callback(create_callback), + : name(name), description(description), enabled(true), +create_callback(create_callback), debugger_init_callback(debugger_init_callback) {} llvm::StringRef name; llvm::StringRef description; + bool enabled; Callback create_callback; DebuggerInitializeCallback debugger_init_callback; }; @@ -250,7 +252,9 @@ template class PluginInstances { } void PerformDebuggerCallback(Debugger &debugger) { -for (auto &instance : m_instances) { +for (const auto &instance : m_instances) { + if (!instance.enabled) +continue; if (instance.debugger_init_callback) instance.debugger_init_callback(debugger); } @@ -260,7 +264,14 @@ template class PluginInstances { // Note that this is a copy of the internal state so modifications // to the returned instances will not be reflected back to instances // stored by the PluginInstances object. - std::vector GetSnapshot() { return m_instances; } + std::vector GetSnapshot() { +std::vector enabled_instances; +for (const auto &instance : m_instances) { + if (instance.enabled) +enabled_instances.push_back(instance); +} +return enabled_instances; + } const Instance *GetInstanceAtIndex(uint32_t idx) { uint32_t count = 0; @@ -280,12 +291,41 @@ template class PluginInstances { const Instance * FindEnabledInstance(std::function predicate) const { for (const auto &instance : m_instances) { + if (!instance.enabled) +continue; if (predicate(instance)) retu
[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)
ashgti wrote: Wanted to also double check with @labath as well, any additional thoughts? https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] a417a86 - [lldb-dap] Enable runInTerminal tests on macOS. (#133824)
Author: John Harrison Date: 2025-03-31T19:50:36-07:00 New Revision: a417a868cd2dad41765e43715379a54289f7da67 URL: https://github.com/llvm/llvm-project/commit/a417a868cd2dad41765e43715379a54289f7da67 DIFF: https://github.com/llvm/llvm-project/commit/a417a868cd2dad41765e43715379a54289f7da67.diff LOG: [lldb-dap] Enable runInTerminal tests on macOS. (#133824) These tests are currently filtered on macOS if your on an M1 (or newer) device. These tests do work on macOS, for me at least on M1 Max with macOS 15.3.2 and Xcode 16.2. Enabling them again, but if we have CI problems with them we can keep them disabled. Added: Modified: lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py Removed: diff --git a/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py b/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py index 5a9938c25c2c8..a94c9860c1508 100644 --- a/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py +++ b/lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py @@ -21,7 +21,7 @@ def isTestSupported(self): return False @skipIfWindows -@skipIf(archs=["arm"]) # Always times out on buildbot +@skipIf(oslist=["linux"], archs=["arm"]) # Always times out on buildbot def test_basic_functionality(self): """ Test basic restarting functionality when the process is running in @@ -61,7 +61,7 @@ def test_basic_functionality(self): ) @skipIfWindows -@skipIf(archs=["arm"]) # Always times out on buildbot +@skipIf(oslist=["linux"], archs=["arm"]) # Always times out on buildbot def test_stopOnEntry(self): """ Check that stopOnEntry works correctly when using runInTerminal. diff --git a/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py b/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py index 9141565ac1b9b..9aab7ca3293db 100644 --- a/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py +++ b/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py @@ -44,7 +44,7 @@ def isTestSupported(self): return False @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_runInTerminal(self): if not self.isTestSupported(): return @@ -90,7 +90,7 @@ def test_runInTerminal(self): env = self.dap_server.request_evaluate("foo")["body"]["result"] self.assertIn("bar", env) -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_runInTerminalWithObjectEnv(self): if not self.isTestSupported(): return @@ -114,7 +114,7 @@ def test_runInTerminalWithObjectEnv(self): self.assertEqual("BAR", request_envs["FOO"]) @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_runInTerminalInvalidTarget(self): if not self.isTestSupported(): return @@ -133,7 +133,7 @@ def test_runInTerminalInvalidTarget(self): ) @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_missingArgInRunInTerminalLauncher(self): if not self.isTestSupported(): return @@ -148,7 +148,7 @@ def test_missingArgInRunInTerminalLauncher(self): ) @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_FakeAttachedRunInTerminalLauncherWithInvalidProgram(self): if not self.isTestSupported(): return @@ -175,7 +175,7 @@ def test_FakeAttachedRunInTerminalLauncherWithInvalidProgram(self): self.assertIn("No such file or directory", stderr) @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_FakeAttachedRunInTerminalLauncherWithValidProgram(self): if not self.isTestSupported(): return @@ -202,7 +202,7 @@ def test_FakeAttachedRunInTerminalLauncherWithValidProgram(self): self.assertIn("foo", stdout) @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_FakeAttachedRunInTerminalLauncherAndCheckEnvironment(self): if not self.isTestSupported(): return @@ -223,7 +223,7 @@ def test_FakeAttachedRunInTerminalLauncherAndCheckEnvironment(self): self.assertIn("FOO=BAR", stdout) @skipIfWindows -@skipIf(archs=no_match(["x86_64"])) +@skipIf(oslist=["linux"], archs=no_match(["x86_64"])) def test_NonAtt
[Lldb-commits] [lldb] [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target (PR #132688)
@@ -8,7 +8,10 @@ #include "LinuxSignals.h" -#ifdef __linux__ +// Now, because we do not support mips debugging, if we compile LLVM on mips +// target, would report error `static assertion failed:Value mismatch for signal +// number SIGBUS`, so add this condition to avoid error. yingopq wrote: OK, thanks! https://github.com/llvm/llvm-project/pull/132688 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use DenseMap::insert_range (NFC) (PR #133846)
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/133846 None >From f40080fe8aad7233f6388d699b662a447703915d Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 30 Mar 2025 23:19:44 -0700 Subject: [PATCH] [lldb] Use DenseMap::insert_range (NFC) --- lldb/source/Plugins/ABI/X86/ABIX86.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/ABI/X86/ABIX86.cpp b/lldb/source/Plugins/ABI/X86/ABIX86.cpp index 3c55a6ea17e8f..db170700d3f65 100644 --- a/lldb/source/Plugins/ABI/X86/ABIX86.cpp +++ b/lldb/source/Plugins/ABI/X86/ABIX86.cpp @@ -191,7 +191,7 @@ BaseRegToRegsMap makeBaseRegMap(bool is64bit) { // higher YMM registers (specific to amd64) YMM(8), YMM(9), YMM(10), YMM(11), YMM(12), YMM(13), YMM(14), YMM(15)}}; -out.insert(amd64_regs.begin(), amd64_regs.end()); +out.insert_range(amd64_regs); } return out; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 46457ed - [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (#133780)
Author: Jonas Devlieghere Date: 2025-03-31T16:04:31-07:00 New Revision: 46457ed1dfbfaf4ccc9245813450ba3fd561f067 URL: https://github.com/llvm/llvm-project/commit/46457ed1dfbfaf4ccc9245813450ba3fd561f067 DIFF: https://github.com/llvm/llvm-project/commit/46457ed1dfbfaf4ccc9245813450ba3fd561f067.diff LOG: [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (#133780) Convert Breakpoint & Watchpoints structs to classes to provide proper access control. This is in preparation for adopting SBMutex to protect the underlying SBBreakpoint and SBWatchpoint. Added: Modified: lldb/tools/lldb-dap/Breakpoint.cpp lldb/tools/lldb-dap/Breakpoint.h lldb/tools/lldb-dap/BreakpointBase.cpp lldb/tools/lldb-dap/BreakpointBase.h lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/DAP.h lldb/tools/lldb-dap/DAPForward.h lldb/tools/lldb-dap/ExceptionBreakpoint.cpp lldb/tools/lldb-dap/ExceptionBreakpoint.h lldb/tools/lldb-dap/FunctionBreakpoint.cpp lldb/tools/lldb-dap/FunctionBreakpoint.h lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp lldb/tools/lldb-dap/InstructionBreakpoint.cpp lldb/tools/lldb-dap/InstructionBreakpoint.h lldb/tools/lldb-dap/JSONUtils.cpp lldb/tools/lldb-dap/SourceBreakpoint.cpp lldb/tools/lldb-dap/SourceBreakpoint.h lldb/tools/lldb-dap/Watchpoint.cpp lldb/tools/lldb-dap/Watchpoint.h Removed: diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp index eba534dcc51c7..e02f62076f935 100644 --- a/lldb/tools/lldb-dap/Breakpoint.cpp +++ b/lldb/tools/lldb-dap/Breakpoint.cpp @@ -19,21 +19,21 @@ using namespace lldb_dap; -void Breakpoint::SetCondition() { bp.SetCondition(condition.c_str()); } +void Breakpoint::SetCondition() { m_bp.SetCondition(m_condition.c_str()); } void Breakpoint::SetHitCondition() { uint64_t hitCount = 0; - if (llvm::to_integer(hitCondition, hitCount)) -bp.SetIgnoreCount(hitCount - 1); + if (llvm::to_integer(m_hit_condition, hitCount)) +m_bp.SetIgnoreCount(hitCount - 1); } void Breakpoint::CreateJsonObject(llvm::json::Object &object) { // Each breakpoint location is treated as a separate breakpoint for VS code. // They don't have the notion of a single breakpoint with multiple locations. - if (!bp.IsValid()) + if (!m_bp.IsValid()) return; - object.try_emplace("verified", bp.GetNumResolvedLocations() > 0); - object.try_emplace("id", bp.GetID()); + object.try_emplace("verified", m_bp.GetNumResolvedLocations() > 0); + object.try_emplace("id", m_bp.GetID()); // VS Code DAP doesn't currently allow one breakpoint to have multiple // locations so we just report the first one. If we report all locations // then the IDE starts showing the wrong line numbers and locations for @@ -43,20 +43,20 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { // this as the breakpoint location since it will have a complete location // that is at least loaded in the current process. lldb::SBBreakpointLocation bp_loc; - const auto num_locs = bp.GetNumLocations(); + const auto num_locs = m_bp.GetNumLocations(); for (size_t i = 0; i < num_locs; ++i) { -bp_loc = bp.GetLocationAtIndex(i); +bp_loc = m_bp.GetLocationAtIndex(i); if (bp_loc.IsResolved()) break; } // If not locations are resolved, use the first location. if (!bp_loc.IsResolved()) -bp_loc = bp.GetLocationAtIndex(0); +bp_loc = m_bp.GetLocationAtIndex(0); auto bp_addr = bp_loc.GetAddress(); if (bp_addr.IsValid()) { std::string formatted_addr = -"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(bp.GetTarget())); +"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget())); object.try_emplace("instructionReference", formatted_addr); auto line_entry = bp_addr.GetLineEntry(); const auto line = line_entry.GetLine(); @@ -69,12 +69,14 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { } } -bool Breakpoint::MatchesName(const char *name) { return bp.MatchesName(name); } +bool Breakpoint::MatchesName(const char *name) { + return m_bp.MatchesName(name); +} void Breakpoint::SetBreakpoint() { - bp.AddName(kDAPBreakpointLabel); - if (!condition.empty()) + m_bp.AddName(kDAPBreakpointLabel); + if (!m_condition.empty()) SetCondition(); - if (!hitCondition.empty()) + if (!m_hit_condition.empty()) SetHitCondition(); } diff --git a/lldb/tools/lldb-dap/Breakpoint.h b/lldb/tools/lldb-dap/Breakpoint.h index a726
[Lldb-commits] [lldb] [llvm] [lldb] Implement CLI support for reverse-continue (PR #132783)
https://github.com/rocallahan updated https://github.com/llvm/llvm-project/pull/132783 >From 87af424e911ac5b22ee75d801390d29b9b3f367a Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Fri, 19 Jul 2024 22:48:14 +1200 Subject: [PATCH] [lldb] Implement CLI support for reverse-continue This introduces the options "-F/--forward" and "-R/--reverse" to `process continue`. These only work if you're running with a gdbserver backend that supports reverse execution, such as rr. For testing we rely on the fake reverse- execution functionality in `lldbreverse.py`. --- lldb/source/Commands/CommandObjectProcess.cpp | 13 +++- lldb/source/Commands/Options.td | 8 ++- .../process/reverse-continue/Makefile | 3 + .../reverse-continue/TestReverseContinue.py | 66 +++ .../TestReverseContinueNotSupported.py| 51 ++ .../commands/process/reverse-continue/main.c | 12 llvm/docs/ReleaseNotes.md | 2 + 7 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/commands/process/reverse-continue/Makefile create mode 100644 lldb/test/API/commands/process/reverse-continue/TestReverseContinue.py create mode 100644 lldb/test/API/commands/process/reverse-continue/TestReverseContinueNotSupported.py create mode 100644 lldb/test/API/commands/process/reverse-continue/main.c diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 654dfa83ea444..ed80c854ed66e 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -468,7 +468,13 @@ class CommandObjectProcessContinue : public CommandObjectParsed { case 'b': m_run_to_bkpt_args.AppendArgument(option_arg); m_any_bkpts_specified = true; - break; +break; + case 'F': +m_base_direction = lldb::RunDirection::eRunForward; +break; + case 'R': +m_base_direction = lldb::RunDirection::eRunReverse; +break; default: llvm_unreachable("Unimplemented option"); } @@ -479,6 +485,7 @@ class CommandObjectProcessContinue : public CommandObjectParsed { m_ignore = 0; m_run_to_bkpt_args.Clear(); m_any_bkpts_specified = false; + m_base_direction = std::nullopt; } llvm::ArrayRef GetDefinitions() override { @@ -488,6 +495,7 @@ class CommandObjectProcessContinue : public CommandObjectParsed { uint32_t m_ignore = 0; Args m_run_to_bkpt_args; bool m_any_bkpts_specified = false; +std::optional m_base_direction; }; void DoExecute(Args &command, CommandReturnObject &result) override { @@ -654,6 +662,9 @@ class CommandObjectProcessContinue : public CommandObjectParsed { } } + if (m_options.m_base_direction.has_value()) +process->SetBaseDirection(*m_options.m_base_direction); + const uint32_t iohandler_id = process->GetIOHandlerID(); StreamString stream; diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index cc579d767eb06..53864ff29327d 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -737,13 +737,17 @@ let Command = "process attach" in { } let Command = "process continue" in { - def process_continue_ignore_count : Option<"ignore-count", "i">, Group<1>, + def process_continue_ignore_count : Option<"ignore-count", "i">, Groups<[1,2]>, Arg<"UnsignedInteger">, Desc<"Ignore crossings of the breakpoint (if it" " exists) for the currently selected thread.">; - def process_continue_run_to_bkpt : Option<"continue-to-bkpt", "b">, Group<2>, + def process_continue_run_to_bkpt : Option<"continue-to-bkpt", "b">, Groups<[3,4]>, Arg<"BreakpointIDRange">, Desc<"Specify a breakpoint to continue to, temporarily " "ignoring other breakpoints. Can be specified more than once. " "The continue action will be done synchronously if this option is specified.">; + def thread_continue_forward : Option<"forward", "F">, Groups<[1,3]>, +Desc<"Set the direction to forward before continuing.">; + def thread_continue_reverse : Option<"reverse", "R">, Groups<[2,4]>, +Desc<"Set the direction to reverse before continuing.">; } let Command = "process detach" in { diff --git a/lldb/test/API/commands/process/reverse-continue/Makefile b/lldb/test/API/commands/process/reverse-continue/Makefile new file mode 100644 index 0..10495940055b6 --- /dev/null +++ b/lldb/test/API/commands/process/reverse-continue/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/commands/process/reverse-continue/TestReverseContinue.py b/lldb/test/API/commands/process/reverse-continue/TestReverseContinue.py new file mode 100644 index 0..c04d2b9d4b5a5 --- /dev/null +++ b/lldb/test/API/commands/process/reverse-continue/TestReverseContinue.py @@ -0,0
[Lldb-commits] [lldb] [llvm] [lldb] Implement CLI support for reverse-continue (PR #132783)
@@ -468,7 +468,23 @@ class CommandObjectProcessContinue : public CommandObjectParsed { case 'b': m_run_to_bkpt_args.AppendArgument(option_arg); m_any_bkpts_specified = true; - break; +break; rocallahan wrote: Thanks. Actually it looks like we don't need to use `LLDB_OPT_SET` here. https://github.com/llvm/llvm-project/pull/132783 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use DenseMap::insert_range (NFC) (PR #133846)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Kazu Hirata (kazutakahirata) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/133846.diff 1 Files Affected: - (modified) lldb/source/Plugins/ABI/X86/ABIX86.cpp (+1-1) ``diff diff --git a/lldb/source/Plugins/ABI/X86/ABIX86.cpp b/lldb/source/Plugins/ABI/X86/ABIX86.cpp index 3c55a6ea17e8f..db170700d3f65 100644 --- a/lldb/source/Plugins/ABI/X86/ABIX86.cpp +++ b/lldb/source/Plugins/ABI/X86/ABIX86.cpp @@ -191,7 +191,7 @@ BaseRegToRegsMap makeBaseRegMap(bool is64bit) { // higher YMM registers (specific to amd64) YMM(8), YMM(9), YMM(10), YMM(11), YMM(12), YMM(13), YMM(14), YMM(15)}}; -out.insert(amd64_regs.begin(), amd64_regs.end()); +out.insert_range(amd64_regs); } return out; `` https://github.com/llvm/llvm-project/pull/133846 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/133811 >From 9053618204265ea71a6a30382937cff584f8c02d Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 31 Mar 2025 14:36:16 -0700 Subject: [PATCH 1/2] [lldb-dap] Do not take ownership of stdin. There isn't any benefit to taking ownership of stdin and it may cause issues if `Transport` is dealloced. --- lldb/tools/lldb-dap/lldb-dap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 062c3a5f989f3..a1d4f4f92e625 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -571,7 +571,7 @@ int main(int argc, char *argv[]) { } lldb::IOObjectSP input = std::make_shared( - fileno(stdin), File::eOpenOptionReadOnly, true); + fileno(stdin), File::eOpenOptionReadOnly, false); lldb::IOObjectSP output = std::make_shared( stdout_fd, File::eOpenOptionWriteOnly, false); >From c695e60634d42b58a169f3afc1a683d201f4c3b4 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 31 Mar 2025 15:42:06 -0700 Subject: [PATCH 2/2] Using `NativeFile::Unowned` instead of `false`. --- lldb/tools/lldb-dap/lldb-dap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index a1d4f4f92e625..b91c62e921428 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -571,9 +571,9 @@ int main(int argc, char *argv[]) { } lldb::IOObjectSP input = std::make_shared( - fileno(stdin), File::eOpenOptionReadOnly, false); + fileno(stdin), File::eOpenOptionReadOnly, NativeFile::Unowned); lldb::IOObjectSP output = std::make_shared( - stdout_fd, File::eOpenOptionWriteOnly, false); + stdout_fd, File::eOpenOptionWriteOnly, NativeFile::Unowned); constexpr llvm::StringLiteral client_name = "stdin/stdout"; Transport transport(client_name, log.get(), input, output); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
@@ -571,7 +571,7 @@ int main(int argc, char *argv[]) { } lldb::IOObjectSP input = std::make_shared( - fileno(stdin), File::eOpenOptionReadOnly, true); + fileno(stdin), File::eOpenOptionReadOnly, false); ashgti wrote: Applied. https://github.com/llvm/llvm-project/pull/133811 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
https://github.com/JDevlieghere approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/133811 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
@@ -571,7 +571,7 @@ int main(int argc, char *argv[]) { } lldb::IOObjectSP input = std::make_shared( - fileno(stdin), File::eOpenOptionReadOnly, true); + fileno(stdin), File::eOpenOptionReadOnly, false); JDevlieghere wrote: ```suggestion fileno(stdin), File::eOpenOptionReadOnly, NativeFile::Unowned); ``` https://github.com/llvm/llvm-project/pull/133811 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/133811 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: John Harrison (ashgti) Changes There isn't any benefit to taking ownership of stdin and it may cause issues if `Transport` is dealloced. --- Full diff: https://github.com/llvm/llvm-project/pull/133811.diff 1 Files Affected: - (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+1-1) ``diff diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 062c3a5f989f3..a1d4f4f92e625 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -571,7 +571,7 @@ int main(int argc, char *argv[]) { } lldb::IOObjectSP input = std::make_shared( - fileno(stdin), File::eOpenOptionReadOnly, true); + fileno(stdin), File::eOpenOptionReadOnly, false); lldb::IOObjectSP output = std::make_shared( stdout_fd, File::eOpenOptionWriteOnly, false); `` https://github.com/llvm/llvm-project/pull/133811 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not take ownership of stdin. (PR #133811)
https://github.com/ashgti created https://github.com/llvm/llvm-project/pull/133811 There isn't any benefit to taking ownership of stdin and it may cause issues if `Transport` is dealloced. >From 9053618204265ea71a6a30382937cff584f8c02d Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 31 Mar 2025 14:36:16 -0700 Subject: [PATCH] [lldb-dap] Do not take ownership of stdin. There isn't any benefit to taking ownership of stdin and it may cause issues if `Transport` is dealloced. --- lldb/tools/lldb-dap/lldb-dap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 062c3a5f989f3..a1d4f4f92e625 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -571,7 +571,7 @@ int main(int argc, char *argv[]) { } lldb::IOObjectSP input = std::make_shared( - fileno(stdin), File::eOpenOptionReadOnly, true); + fileno(stdin), File::eOpenOptionReadOnly, false); lldb::IOObjectSP output = std::make_shared( stdout_fd, File::eOpenOptionWriteOnly, false); ___ 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 mutex through the SB API (PR #133295)
@@ -0,0 +1,57 @@ +//===-- SBMutexTest.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 +// +//===--===// + +// Use the umbrella header for -Wdocumentation. +#include "lldb/API/LLDB.h" + +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBTarget.h" +#include "gtest/gtest.h" +#include +#include +#include +#include + +using namespace lldb; +using namespace lldb_private; + +class SBMutexTest : public testing::Test { +protected: + void SetUp() override { debugger = SBDebugger::Create(); } + void TearDown() override { SBDebugger::Destroy(debugger); } + + SubsystemRAII subsystems; + SBDebugger debugger; +}; + +TEST_F(SBMutexTest, LockTest) { + lldb::SBTarget target = debugger.GetDummyTarget(); + + std::future f; + { +std::atomic locked = false; +lldb::SBMutex lock = target.GetAPIMutex(); +std::lock_guard lock_guard(lock); +ASSERT_FALSE(locked.exchange(true)); + +f = std::async(std::launch::async, [&]() { + ASSERT_TRUE(locked); + target.BreakpointCreateByName("foo", "bar"); + ASSERT_FALSE(locked); +}); +ASSERT_TRUE(f.valid()); + +// Wait 500ms to confirm the thread is blocked. +auto status = f.wait_for(std::chrono::milliseconds(500)); +ASSERT_EQ(status, std::future_status::timeout); + +ASSERT_TRUE(locked.exchange(false)); + } slackito wrote: I tried that fix, and I agree it looks like the right fix to me. It seems to solve the issue. However after applying it I get some memory leaks reported by LeakSanitizer (our internal asan config enables it) that I haven't been able to debug yet. I'm working through the report and so far all the reported indirect leaks I've looked into seem to be owned by shared pointers, so it's weird and I haven't yet discarded the possibility that the leaks are a problem on my end. All this goes to say I don't have a fully successful run to prove the fix works, but I think the fix is right :) https://github.com/llvm/llvm-project/pull/133295 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Hoist UUID generation into the UUID class (PR #133662)
@@ -12,26 +12,28 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" #include #include #include +#include labath wrote: bad autocomplete? https://github.com/llvm/llvm-project/pull/133662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)
https://github.com/dlav-sc updated https://github.com/llvm/llvm-project/pull/112555 >From a9d02c8b0c22138d9337bf33883f7e6c937bd655 Mon Sep 17 00:00:00 2001 From: Daniil Avdeev Date: Mon, 14 Oct 2024 14:14:30 + Subject: [PATCH 1/3] [lldb] add --platform-available-ports option to the dotest.py This patch adds --platform-available-ports option to the dotest.py script to remove hardcoded gdb ports from lldb testsuite. Currently, this option could be helpful for GdbRemoteTestCases (e.g. TestLldbGdbServer, TestNonStop, TestGdbRemoteThreadsInStopReply, TestGdbRemotePlatformFile, TestGdbRemote_vCont) --- lldb/packages/Python/lldbsuite/test/configuration.py | 1 + lldb/packages/Python/lldbsuite/test/dotest.py | 2 ++ lldb/packages/Python/lldbsuite/test/dotest_args.py | 7 +++ lldb/packages/Python/lldbsuite/test/lldbtest.py| 4 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +++ 5 files changed, 17 insertions(+) diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py index bcc179346836d..18c1566176331 100644 --- a/lldb/packages/Python/lldbsuite/test/configuration.py +++ b/lldb/packages/Python/lldbsuite/test/configuration.py @@ -103,6 +103,7 @@ lldb_platform_name = None lldb_platform_url = None lldb_platform_working_dir = None +lldb_platform_available_ports = None # Apple SDK apple_sdk = None diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py index 681ea1638f2d6..7cc8f2985043e 100644 --- a/lldb/packages/Python/lldbsuite/test/dotest.py +++ b/lldb/packages/Python/lldbsuite/test/dotest.py @@ -419,6 +419,8 @@ def parseOptionsAndInitTestdirs(): configuration.lldb_platform_url = args.lldb_platform_url if args.lldb_platform_working_dir: configuration.lldb_platform_working_dir = args.lldb_platform_working_dir +if args.lldb_platform_available_ports: +configuration.lldb_platform_available_ports = args.lldb_platform_available_ports if platform_system == "Darwin" and args.apple_sdk: configuration.apple_sdk = args.apple_sdk if args.test_build_dir: diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py index a80428ebec589..18047fdca2a92 100644 --- a/lldb/packages/Python/lldbsuite/test/dotest_args.py +++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py @@ -292,6 +292,13 @@ def create_parser(): metavar="platform-working-dir", help="The directory to use on the remote platform.", ) +group.add_argument( +"--platform-available-ports", +dest="lldb_platform_available_ports", +type=lambda ports: [int(port.strip()) for port in ports.split(":")], +metavar="platform-available-ports", +help="Ports available for connection to a lldb server on the remote platform", +) # Test-suite behaviour group = parser.add_argument_group("Runtime behaviour options") diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 570c36b5f9622..2e370564939d8 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -749,6 +749,10 @@ def getSourcePath(self, name): """Return absolute path to a file in the test's source directory.""" return os.path.join(self.getSourceDir(), name) +def getPlatformAvailablePorts(self): +"""Return ports available for connection to a lldb server on the remote platform.""" +return configuration.lldb_platform_available_ports + @classmethod def setUpCommands(cls): commands = [ diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index 3d3ecb9aa8f95..029aaf3164697 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -185,6 +185,9 @@ def setUpServerLogging(self, is_llgs): ] def get_next_port(self): +available_ports = self.getPlatformAvailablePorts() +if available_ports: +return random.choice(available_ports) return 12000 + random.randint(0, 7999) def reset_test_sequence(self): >From bee43951764f20efac586c6b3cde55d8f36236da Mon Sep 17 00:00:00 2001 From: Daniil Avdeev Date: Thu, 27 Mar 2025 14:36:56 + Subject: [PATCH 2/3] NFC --- lldb/packages/Python/lldbsuite/test/dotest_args.py | 2 +- .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py index 18047fdca2a92..f6b3
[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/131836 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)
https://github.com/dlav-sc edited https://github.com/llvm/llvm-project/pull/112555 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Create a default rate limit constant in Progress (NFC) (PR #133506)
https://github.com/labath approved this pull request. I don't think this needs to be a setting as the goal here is to weed out truly egregious report frequencies (O(thousands) per second). I think the rest would be better handled at the receiving side. I guess making a constant for that is fine, though the name is somewhat unfortunate as this isn't really the default (the default is no rate limiting). It sort of makes sense if you tilt your head the right way, but it's not ideal that the tilting is required. How about `kDefaultHighFrequencyReportTime` (it's a mouthful, but I guess we won't use it often)? Two other random ideas: - maybe we could actually make this the default (for all progress reports)? The risk is that there's some reports get lost (e.g. if we send three reports, and the first two are finished very quickly, then the *last* two could be dropped, and the progress would show the first step as taking a long time, even though it has actually finished already), but maybe we're fine with that? - if we go with the above, and given what I've said the first paragraph, maybe this doesn't actually need to be settable, from anywhere? https://github.com/llvm/llvm-project/pull/133506 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [llvm] [lldb] Remove lldb-server min and max gdbserver port options (PR #133275)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/133275 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Make GetRowForFunctionOffset compatible with discontinuous functions (PR #133250)
https://github.com/labath closed https://github.com/llvm/llvm-project/pull/133250 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 9d61eaa - [lldb] Make GetRowForFunctionOffset compatible with discontinuous functions (#133250)
Author: Pavel Labath Date: 2025-03-31T11:45:11+02:00 New Revision: 9d61eaa9ecd9a46d22a8a4efc67d31b9abba3616 URL: https://github.com/llvm/llvm-project/commit/9d61eaa9ecd9a46d22a8a4efc67d31b9abba3616 DIFF: https://github.com/llvm/llvm-project/commit/9d61eaa9ecd9a46d22a8a4efc67d31b9abba3616.diff LOG: [lldb] Make GetRowForFunctionOffset compatible with discontinuous functions (#133250) The function had special handling for -1, but that is incompatible with functions whose entry point is not the first address. Use std::nullopt instead. Added: Modified: lldb/include/lldb/Symbol/UnwindPlan.h lldb/include/lldb/Target/RegisterContextUnwind.h lldb/source/Symbol/UnwindPlan.cpp lldb/source/Target/RegisterContextUnwind.cpp Removed: diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h b/lldb/include/lldb/Symbol/UnwindPlan.h index db9aade93b6ba..9adda27b8f928 100644 --- a/lldb/include/lldb/Symbol/UnwindPlan.h +++ b/lldb/include/lldb/Symbol/UnwindPlan.h @@ -467,11 +467,12 @@ class UnwindPlan { void InsertRow(Row row, bool replace_existing = false); // Returns a pointer to the best row for the given offset into the function's - // instructions. If offset is -1 it indicates that the function start is - // unknown - the final row in the UnwindPlan is returned. In practice, the - // UnwindPlan for a function with no known start address will be the - // architectural default UnwindPlan which will only have one row. - const UnwindPlan::Row *GetRowForFunctionOffset(int offset) const; + // instructions. If offset is std::nullopt it indicates that the function + // start is unknown - the final row in the UnwindPlan is returned. In + // practice, the UnwindPlan for a function with no known start address will be + // the architectural default UnwindPlan which will only have one row. + const UnwindPlan::Row * + GetRowForFunctionOffset(std::optional offset) const; lldb::RegisterKind GetRegisterKind() const { return m_register_kind; } diff --git a/lldb/include/lldb/Target/RegisterContextUnwind.h b/lldb/include/lldb/Target/RegisterContextUnwind.h index 6cd918fedc003..c4ae29e657bfb 100644 --- a/lldb/include/lldb/Target/RegisterContextUnwind.h +++ b/lldb/include/lldb/Target/RegisterContextUnwind.h @@ -228,18 +228,17 @@ class RegisterContextUnwind : public lldb_private::RegisterContext { lldb_private::Address m_start_pc; lldb_private::Address m_current_pc; - int m_current_offset; // how far into the function we've executed; -1 if -// unknown -// 0 if no instructions have been executed yet. - - // 0 if no instructions have been executed yet. - // On architectures where the return address on the stack points - // to the instruction after the CALL, this value will have 1 - // subtracted from it. Else a function that ends in a CALL will - // have an offset pointing into the next function's address range. + /// How far into the function we've executed. 0 if no instructions have been + /// executed yet, std::nullopt if unknown. + std::optional m_current_offset; + + // How far into the function we've executed. 0 if no instructions have been + // executed yet, std::nullopt if unknown. On architectures where the return + // address on the stack points to the instruction after the CALL, this value + // will have 1 subtracted from it. Otherwise, a function that ends in a CALL + // will have an offset pointing into the next function's address range. // m_current_pc has the actual address of the "current" pc. - int m_current_offset_backed_up_one; // how far into the function we've - // executed; -1 if unknown + std::optional m_current_offset_backed_up_one; bool m_behaves_like_zeroth_frame; // this frame behaves like frame zero diff --git a/lldb/source/Symbol/UnwindPlan.cpp b/lldb/source/Symbol/UnwindPlan.cpp index 48089cbdecd97..f2846eb927bf8 100644 --- a/lldb/source/Symbol/UnwindPlan.cpp +++ b/lldb/source/Symbol/UnwindPlan.cpp @@ -417,9 +417,10 @@ void UnwindPlan::InsertRow(Row row, bool replace_existing) { } } -const UnwindPlan::Row *UnwindPlan::GetRowForFunctionOffset(int offset) const { - auto it = offset == -1 ? m_row_list.end() - : llvm::upper_bound(m_row_list, offset, RowLess()); +const UnwindPlan::Row * +UnwindPlan::GetRowForFunctionOffset(std::optional offset) const { + auto it = offset ? llvm::upper_bound(m_row_list, *offset, RowLess()) + : m_row_list.end(); if (it == m_row_list.begin()) return nullptr; // upper_bound returns the row strictly greater than our desired offset, which diff --git a/lldb/source/Target/RegisterContextUnwind.cpp b/lldb/source/Target/RegisterContextUnwind.cpp index a035c57fbfc1c..cb3d7ee479890 100644 --- a/lldb/source/Target/RegisterContextUnwind.cpp +++ b/lldb/source/Target/Registe
[Lldb-commits] [lldb] [lldb] Return *const* UnwindPlan pointers from FuncUnwinders (PR #133247)
@@ -36,18 +36,19 @@ class FuncUnwinders { ~FuncUnwinders(); - lldb::UnwindPlanSP GetUnwindPlanAtCallSite(Target &target, Thread &thread); + std::shared_ptr GetUnwindPlanAtCallSite(Target &target, labath wrote: Currently we need them, because the unwind plans are (sometimes) stored in a shared pointer while they are being constructed. That could be avoided because we don't really need the shared ownership at that point (they could be a unique_ptr or a value). However, I'm not particularly thrilled with the idea of repurposing UnwindPlanSP for this, as I think that would be surprising -- there's nothing in that name that indicates this is a const pointer, and I think it's important to see that. One idea I have had that could solve this (but have never found the time to propose) is to replace the individual FoobarSP typedefs with a `SP = std::shared_ptr` template alias. That would let us write `SP` in exactly the places which need it; and it might also help with the hypothetical migration to the llvm naming convention (frees up `FoobarSP` as a member name) https://github.com/llvm/llvm-project/pull/133247 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 799e905 - [lldb] Create a default rate limit constant in Progress (NFC) (#133506)
Author: Jonas Devlieghere Date: 2025-03-31T08:29:20-07:00 New Revision: 799e9053641a6478d3144866a97737b37b87c260 URL: https://github.com/llvm/llvm-project/commit/799e9053641a6478d3144866a97737b37b87c260 DIFF: https://github.com/llvm/llvm-project/commit/799e9053641a6478d3144866a97737b37b87c260.diff LOG: [lldb] Create a default rate limit constant in Progress (NFC) (#133506) In #133211, Greg suggested making the rate limit configurable through a setting. Although adding the setting is easy, the two places where we currently use rate limiting aren't tied to a particular debugger. Although it'd be possible to hook up, given how few progress events currently implement rate limiting, I don't think it's worth threading this through, if that's even possible. I still think it's a good idea to be consistent and make it easy to pick the same rate limiting value, so I've moved it into a constant in the Progress class. Added: Modified: lldb/include/lldb/Core/Progress.h lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Removed: diff --git a/lldb/include/lldb/Core/Progress.h b/lldb/include/lldb/Core/Progress.h index 3003568e8946b..93e34084d7ec1 100644 --- a/lldb/include/lldb/Core/Progress.h +++ b/lldb/include/lldb/Core/Progress.h @@ -115,6 +115,10 @@ class Progress { /// Used to indicate a non-deterministic progress report static constexpr uint64_t kNonDeterministicTotal = UINT64_MAX; + /// The default report time for high frequency progress reports. + static constexpr std::chrono::milliseconds kDefaultHighFrequencyReportTime = + std::chrono::milliseconds(20); + private: void ReportProgress(); static std::atomic g_id; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index 6f2c45e74132c..047967a30d098 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -81,7 +81,7 @@ void ManualDWARFIndex::Index() { const uint64_t total_progress = units_to_index.size() * 2 + 8; Progress progress("Manually indexing DWARF", module_desc.GetData(), total_progress, /*debugger=*/nullptr, -/*minimum_report_time=*/std::chrono::milliseconds(20)); +Progress::kDefaultHighFrequencyReportTime); // Share one thread pool across operations to avoid the overhead of // recreating the threads. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index e346d588a449f..ce351274b4576 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -724,7 +724,7 @@ void SymbolFileDWARFDebugMap::ForEachSymbolFile( const size_t num_oso_idxs = m_compile_unit_infos.size(); Progress progress(std::move(description), "", num_oso_idxs, /*debugger=*/nullptr, -/*minimum_report_time=*/std::chrono::milliseconds(20)); +Progress::kDefaultHighFrequencyReportTime); for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) { if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) { progress.Increment(oso_idx, oso_dwarf->GetObjectFile() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Create a default rate limit constant in Progress (NFC) (PR #133506)
JDevlieghere wrote: > I don't think this needs to be a setting as the goal here is to weed out > truly egregious report frequencies (O(thousands) per second). I think the > rest would be better handled at the receiving side. 👍 > I guess making a constant for that is fine, though the name is somewhat > unfortunate as this isn't really the default (the default is no rate > limiting). It sort of makes sense if you tilt your head the right way, but > it's not ideal that the tilting is required. How about > `kDefaultHighFrequencyReportTime` (it's a mouthful, but I guess we won't use > it often)? Works for me. > Two other random ideas: > > * maybe we could actually make this the default (for all progress reports)? > The risk is that there's some reports get lost (e.g. if we send three > reports, and the first two are finished very quickly, then the _last_ two > could be dropped, and the progress would show the first step as taking a long > time, even though it has actually finished already), but maybe we're fine > with that? > * if we go with the above, and given what I've said the first paragraph, > maybe this doesn't actually need to be settable, from anywhere? I considered this too and decided against it for the same reason. Misattributing where time is spend really undermines the value of the progress reports. For now I believe it's best to rely on our expertise to categorize progress reports that should be rate limited. https://github.com/llvm/llvm-project/pull/133506 ___ 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/JDevlieghere closed 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] 945c494 - [lldb] Use correct path for lldb-server executable (#131519)
Author: Yuval Deutscher Date: 2025-03-31T08:20:40-07:00 New Revision: 945c494e2c3c078e26ff521ef3e9455e0ff764ac URL: https://github.com/llvm/llvm-project/commit/945c494e2c3c078e26ff521ef3e9455e0ff764ac DIFF: https://github.com/llvm/llvm-project/commit/945c494e2c3c078e26ff521ef3e9455e0ff764ac.diff LOG: [lldb] Use correct path for lldb-server executable (#131519) Hey, This solves an issue where running lldb-server-20 with a non-absolute path (for example, when it's installed into `/usr/bin` and the user runs it as `lldb-server-20 ...` and not `/usr/bin/lldb-server-20 ...`) fails with `error: spawn_process failed: execve failed: No such file or directory`. The underlying issue is that when run that way, it attempts to execute a binary named `lldb-server-20` from its current directory. This is also a mild security hazard because lldb-server is often being run as root in the directory /tmp, meaning that an unprivileged user can create the file /tmp/lldb-server-20 and lldb-server will execute it as root. (although, well, it's a debugging server we're talking about, so that may not be a real concern) I haven't previously contributed to this project; if you want me to change anything in the code please don't hesitate to let me know. Added: Modified: lldb/tools/lldb-server/lldb-platform.cpp Removed: diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 880b45b989b9c..51174a0f443c3 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,8 +257,9 @@ static void client_handle(GDBRemoteCommunicationServerPlatform &platform, printf("Disconnected.\n"); } -static Status spawn_process(const char *progname, const Socket *conn_socket, -uint16_t gdb_port, const lldb_private::Args &args, +static Status spawn_process(const char *progname, 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) { Status error; @@ -267,9 +269,10 @@ 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, false); + launch_info.SetArg0(progname); Args &self_args = launch_info.GetArguments(); + self_args.AppendArgument(progname); self_args.AppendArgument(llvm::StringRef("platform")); self_args.AppendArgument(llvm::StringRef("--child-platform-fd")); self_args.AppendArgument(llvm::to_string(shared_socket.GetSendableFD())); @@ -551,9 +554,10 @@ int main_platform(int argc, char *argv[]) { 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( + progname, 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] [lldb] Expose the Target API mutex through the SB API (PR #133295)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/133295 ___ 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)
github-actions[bot] wrote: @yuvald-sweet-security Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/131519 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] f0b3bdd - [lldb] Remove raw access to PluginInstances vector (#132884)
Author: David Peixotto Date: 2025-03-31T09:53:46-07:00 New Revision: f0b3bdd6dfa035653de5ead7b8d0582a8c0c158e URL: https://github.com/llvm/llvm-project/commit/f0b3bdd6dfa035653de5ead7b8d0582a8c0c158e DIFF: https://github.com/llvm/llvm-project/commit/f0b3bdd6dfa035653de5ead7b8d0582a8c0c158e.diff LOG: [lldb] Remove raw access to PluginInstances vector (#132884) Remove raw access to PluginInstances vector This commit modifies the PluginInstances class to remove direct access to the m_instances vector. Instead, we expose a new `GetSnapshot` method that returns a copy of the current state of the instances vector. All external iteration over the instances is updated to use the new method. The motivation for the change is to allow modifying the way we store instances without having to change all the clients. This is a preliminary change to allow enabling/disabling of plugins in which case we want to iterate over only enabled plugins. We also considered using a custom iterator that wraps the vector iterator and can skip over disabled instances. That works, but the iterator code is a bit messy with all template and typedefs to make a compliant iterator. Added: Modified: lldb/source/Core/PluginManager.cpp Removed: diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 80c9465f9af72..95eb940efcef2 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -226,30 +226,26 @@ template class PluginInstances { } typename Instance::CallbackType GetCallbackAtIndex(uint32_t idx) { -if (Instance *instance = GetInstanceAtIndex(idx)) +if (const Instance *instance = GetInstanceAtIndex(idx)) return instance->create_callback; return nullptr; } llvm::StringRef GetDescriptionAtIndex(uint32_t idx) { -if (Instance *instance = GetInstanceAtIndex(idx)) +if (const Instance *instance = GetInstanceAtIndex(idx)) return instance->description; return ""; } llvm::StringRef GetNameAtIndex(uint32_t idx) { -if (Instance *instance = GetInstanceAtIndex(idx)) +if (const Instance *instance = GetInstanceAtIndex(idx)) return instance->name; return ""; } typename Instance::CallbackType GetCallbackForName(llvm::StringRef name) { -if (name.empty()) - return nullptr; -for (auto &instance : m_instances) { - if (name == instance.name) -return instance.create_callback; -} +if (const Instance *instance = GetInstanceForName(name)) + return instance->create_callback; return nullptr; } @@ -260,12 +256,33 @@ template class PluginInstances { } } - const std::vector &GetInstances() const { return m_instances; } - std::vector &GetInstances() { return m_instances; } + // Return a copy of all the enabled instances. + // Note that this is a copy of the internal state so modifications + // to the returned instances will not be reflected back to instances + // stored by the PluginInstances object. + std::vector GetSnapshot() { return m_instances; } + + const Instance *GetInstanceAtIndex(uint32_t idx) { +uint32_t count = 0; + +return FindEnabledInstance( +[&](const Instance &instance) { return count++ == idx; }); + } + + const Instance *GetInstanceForName(llvm::StringRef name) { +if (name.empty()) + return nullptr; - Instance *GetInstanceAtIndex(uint32_t idx) { -if (idx < m_instances.size()) - return &m_instances[idx]; +return FindEnabledInstance( +[&](const Instance &instance) { return instance.name == name; }); + } + + const Instance * + FindEnabledInstance(std::function predicate) const { +for (const auto &instance : m_instances) { + if (predicate(instance)) +return &instance; +} return nullptr; } @@ -571,17 +588,15 @@ PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) { LanguageRuntimeGetCommandObject PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) { - const auto &instances = GetLanguageRuntimeInstances().GetInstances(); - if (idx < instances.size()) -return instances[idx].command_callback; + if (auto instance = GetLanguageRuntimeInstances().GetInstanceAtIndex(idx)) +return instance->command_callback; return nullptr; } LanguageRuntimeGetExceptionPrecondition PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx) { - const auto &instances = GetLanguageRuntimeInstances().GetInstances(); - if (idx < instances.size()) -return instances[idx].precondition_callback; + if (auto instance = GetLanguageRuntimeInstances().GetInstanceAtIndex(idx)) +return instance->precondition_callback; return nullptr; } @@ -643,12 +658,7 @@ bool PluginManager::IsRegisteredObjectFilePluginName(llvm::StringRef name) { if (name.empty()) return false; - const a
[Lldb-commits] [lldb] [llvm] [lldb] Implement CLI support for reverse-continue (PR #132783)
@@ -744,6 +744,10 @@ let Command = "process continue" in { Arg<"BreakpointIDRange">, Desc<"Specify a breakpoint to continue to, temporarily " "ignoring other breakpoints. Can be specified more than once. " "The continue action will be done synchronously if this option is specified.">; + def thread_continue_forward : Option<"forward", "F">, Group<3>, +Desc<"Execute in forward direction">; + def thread_continue_reverse : Option<"reverse", "R">, Group<3>, +Desc<"Execute in reverse direction">; jimingham wrote: Putting this in group 3 means that you can't BOTH say "go backwards" and "keep going till you hit this breakpoint", which seems unfortunate. Formally, there should be 4 sets (that the problem with this way of doing the sets...) `-i -F`, `-i -R`, `-b -F` and `-b -R`. I'm not at all sure why -b & -i are not compatible. Seems like there should really be two `-i -b -F` and `-i -b -R`... https://github.com/llvm/llvm-project/pull/132783 ___ 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 mutex through the SB API (PR #133295)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/133295 >From 79241d2f5701ab789f7fdbb5bd881c4494cb67eb Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 27 Mar 2025 11:24:50 -0700 Subject: [PATCH 1/4] [lldb] Expose the Target API mutex through the SB API Expose u target API mutex through the SB API. This is motivated by lldb-dap, which is built on top of the SB API and needs a way to execute a series of SB API calls in an atomic manner (see #131242). We can solve this problem by either introducing an additional layer of locking at the DAP level or by exposing the existing locking at the SB API level. This patch implements the second approach. This was discussed in an RFC on Discourse [0]. The original implementation exposed a move-only lock rather than a mutex [1] which doesn't work well with SWIG 4.0 [2]. This implement the alternative solution of exposing the mutex rather than the lock. The SBMutex conforms to the BasicLockable requirement [3] (which is why the methods are called `lock` and `unlock` rather than Lock and Unlock) so it can be used as `std::lock_guard` and `std::unique_lock`. [0]: https://discourse.llvm.org/t/rfc-exposing-the-target-api-lock-through-the-sb-api/85215/6 [1]: https://github.com/llvm/llvm-project/pull/131404 [2]: https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377/9 [3]: https://en.cppreference.com/w/cpp/named_req/BasicLockable --- lldb/bindings/interface/SBMutexExtensions.i | 12 lldb/bindings/interfaces.swig | 4 +- lldb/include/lldb/API/LLDB.h | 1 + lldb/include/lldb/API/SBDefines.h | 1 + lldb/include/lldb/API/SBMutex.h | 48 +++ lldb/include/lldb/API/SBTarget.h | 4 +- lldb/include/lldb/Target/Target.h | 16 + lldb/source/API/CMakeLists.txt| 1 + lldb/source/API/SBMutex.cpp | 59 ++ lldb/source/API/SBTarget.cpp | 16 +++-- .../API/python_api/target/TestTargetAPI.py| 24 lldb/unittests/API/CMakeLists.txt | 1 + lldb/unittests/API/SBMutexTest.cpp| 60 +++ 13 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 lldb/bindings/interface/SBMutexExtensions.i create mode 100644 lldb/include/lldb/API/SBMutex.h create mode 100644 lldb/source/API/SBMutex.cpp create mode 100644 lldb/unittests/API/SBMutexTest.cpp diff --git a/lldb/bindings/interface/SBMutexExtensions.i b/lldb/bindings/interface/SBMutexExtensions.i new file mode 100644 index 0..32d3fee468697 --- /dev/null +++ b/lldb/bindings/interface/SBMutexExtensions.i @@ -0,0 +1,12 @@ +%extend lldb::SBMutex { +#ifdef SWIGPYTHON +%pythoncode %{ +def __enter__(self): +self.lock() +return self + +def __exit__(self, exc_type, exc_value, traceback): +self.unlock() +%} +#endif +} diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig index 08df9a1a8d539..e36f2f9dd27c6 100644 --- a/lldb/bindings/interfaces.swig +++ b/lldb/bindings/interfaces.swig @@ -51,6 +51,7 @@ %include "./interface/SBMemoryRegionInfoListDocstrings.i" %include "./interface/SBModuleDocstrings.i" %include "./interface/SBModuleSpecDocstrings.i" +%include "./interface/SBMutexExtensions.i" %include "./interface/SBPlatformDocstrings.i" %include "./interface/SBProcessDocstrings.i" %include "./interface/SBProcessInfoDocstrings.i" @@ -121,8 +122,8 @@ %include "lldb/API/SBHostOS.h" %include "lldb/API/SBInstruction.h" %include "lldb/API/SBInstructionList.h" -%include "lldb/API/SBLanguages.h" %include "lldb/API/SBLanguageRuntime.h" +%include "lldb/API/SBLanguages.h" %include "lldb/API/SBLaunchInfo.h" %include "lldb/API/SBLineEntry.h" %include "lldb/API/SBListener.h" @@ -130,6 +131,7 @@ %include "lldb/API/SBMemoryRegionInfoList.h" %include "lldb/API/SBModule.h" %include "lldb/API/SBModuleSpec.h" +%include "lldb/API/SBMutex.h" %include "lldb/API/SBPlatform.h" %include "lldb/API/SBProcess.h" %include "lldb/API/SBProcessInfo.h" diff --git a/lldb/include/lldb/API/LLDB.h b/lldb/include/lldb/API/LLDB.h index 126fcef31b416..6485f35302a1c 100644 --- a/lldb/include/lldb/API/LLDB.h +++ b/lldb/include/lldb/API/LLDB.h @@ -50,6 +50,7 @@ #include "lldb/API/SBMemoryRegionInfoList.h" #include "lldb/API/SBModule.h" #include "lldb/API/SBModuleSpec.h" +#include "lldb/API/SBMutex.h" #include "lldb/API/SBPlatform.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBProcessInfo.h" diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h index ed5a80da117a5..85f6bbeea5bf9 100644 --- a/lldb/include/lldb/API/SBDefines.h +++ b/lldb/include/lldb/API/SBDefines.h @@ -89,6 +89,7 @@ class LLDB_API SBMemoryRegionInfoList; class LLDB_API SBModule; class LLDB_API SBModuleSpec; class LLDB_API SBModuleSpecList; +class LLDB_API SBMutex; cla
[Lldb-commits] [lldb] [LLDB][NFC] Move CPlusPlusLanguage methods used in Core/Module.cpp to a separated module to break lldb-server dependencies (PR #132274)
slydiman wrote: > I think there's something else happening here. Ok, it seems the dependency chain is longer: Module.cpp -> CPlusPlusLanguage::ExtractContextAndIdentifier() -> CPlusPlusLanguage.cpp -> BlockPointer.cpp -> TypeSystemClang.cpp - > ClangUserExpression.cpp -> ClangExpressionParser.cpp -> clang::CreateLLVMCodeGen() -> llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp -> ... Note the function clang::CreateLLVMCodeGen() is missing in the final binary (GC-ed). We still don't know for sure what the GC root is. It is somewhere in the middle of clang, and I think it is already out of scope. But we need to somehow break the dependency chain for lldb-server. We have 2 options: - this patch or such patch to break the dependency chain in some other place inside lldb plug-ins - somehow finish https://github.com/swiftlang/llvm-project/pull/3240 https://github.com/llvm/llvm-project/pull/132274 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (PR #133746)
JDevlieghere wrote: This is part of a few small cleanups I'm doing before adopting SBMutex in lldb-dap. https://github.com/llvm/llvm-project/pull/133746 ___ 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 mutex through the SB API (PR #133295)
@@ -0,0 +1,59 @@ +//===-- SBMutexTest.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 +// +//===--===// + +// Use the umbrella header for -Wdocumentation. +#include "lldb/API/LLDB.h" + +#include "TestingSupport/SubsystemRAII.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBTarget.h" +#include "gtest/gtest.h" +#include +#include +#include +#include + +using namespace lldb; +using namespace lldb_private; + +class SBMutexTest : public testing::Test { +protected: + void SetUp() override { debugger = SBDebugger::Create(); } + void TearDown() override { SBDebugger::Destroy(debugger); } + + SubsystemRAII subsystems; + SBDebugger debugger; +}; + +TEST_F(SBMutexTest, LockTest) { + lldb::SBTarget target = debugger.GetDummyTarget(); + + std::future f; + { +std::atomic locked = false; +lldb::SBMutex lock = target.GetAPIMutex(); +std::lock_guard lock_guard(lock); +ASSERT_FALSE(locked.exchange(true)); + +f = std::async(std::launch::async, [&]() { + { +ASSERT_TRUE(locked); +target.BreakpointCreateByName("foo", "bar"); +ASSERT_FALSE(locked); + } labath wrote: ```suggestion ASSERT_TRUE(locked); target.BreakpointCreateByName("foo", "bar"); ASSERT_FALSE(locked); ``` https://github.com/llvm/llvm-project/pull/133295 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Hoist UUID generation into the UUID class (PR #133662)
https://github.com/labath edited https://github.com/llvm/llvm-project/pull/133662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Hoist UUID generation into the UUID class (PR #133662)
https://github.com/labath commented: I'm wondering how badly do we need this to be "secure". I'm asking because basically the only reason this can fail is if it fails to open /dev/random or something. So, like if we're fine with falling back to a lower entropy source (some c++11 RNG initialized by the timestamp?), then we could make this always return /something/. I don't know if we have other uses for this, but it seems that the telemetry should be fine with that since it just effectively falls back to an empty UUID. https://github.com/llvm/llvm-project/pull/133662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target (PR #132688)
@@ -8,7 +8,10 @@ #include "LinuxSignals.h" -#ifdef __linux__ +// Now, because we do not support mips debugging, if we compile LLVM on mips +// target, would report error `static assertion failed:Value mismatch for signal +// number SIGBUS`, so add this condition to avoid error. labath wrote: ```suggestion // mips-linux debugging is not supported and mips uses different numbers for some signals (e.g. SIGBUS) on linux, so we skip the static checks below. The definitions here can be used for debugging non-mips targets on a mips-hosted lldb. ``` https://github.com/llvm/llvm-project/pull/132688 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target (PR #132688)
https://github.com/labath approved this pull request. LGTM, I just tweaked the comment a bit. Please also update the endif comment on line 39. https://github.com/llvm/llvm-project/pull/132688 ___ 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 mutex through the SB API (PR #133295)
https://github.com/labath approved this pull request. https://github.com/llvm/llvm-project/pull/133295 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Hoist UUID generation into the UUID class (PR #133662)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/133662 >From f0a4b9bc2f20a812f7f37e5f5a2417dbbb4d45e0 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Sun, 30 Mar 2025 16:10:05 -0700 Subject: [PATCH 1/2] [lldb] Hoist UUID generation into the UUID class Hoist UUID generation into the UUID class and add a trivial unit test. This also changes the telemetry code to drop the double underscore if we failed to generate a UUID and subsequently logs to the Host instead of Object log channel. --- lldb/include/lldb/Utility/UUID.h| 28 lldb/source/Core/Telemetry.cpp | 21 +++-- lldb/source/Utility/UUID.cpp| 9 + lldb/unittests/Utility/UUIDTest.cpp | 14 -- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/lldb/include/lldb/Utility/UUID.h b/lldb/include/lldb/Utility/UUID.h index bc4b4acd5a7d8..05731ea4dc090 100644 --- a/lldb/include/lldb/Utility/UUID.h +++ b/lldb/include/lldb/Utility/UUID.h @@ -12,26 +12,28 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Endian.h" +#include "llvm/Support/Error.h" #include #include #include +#include namespace lldb_private { - class Stream; +class Stream; +/// Represents UUID's of various sizes. In all cases, a uuid of all zeros is +/// treated as an "Invalid UUID" marker, and the UUID created from such data +/// will return false for IsValid. class UUID { - // Represents UUID's of various sizes. In all cases, a uuid of all zeros is - // treated as an "Invalid UUID" marker, and the UUID created from such data - // will return false for IsValid. public: UUID() = default; - - /// Creates a uuid from the data pointed to by the bytes argument. + + /// Create a uuid from the data pointed to by the bytes argument. UUID(llvm::ArrayRef bytes) : m_bytes(bytes) { if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) { Clear(); - } +} } // Reference: @@ -50,13 +52,12 @@ class UUID { /// Create a UUID from CvRecordPdb70. UUID(CvRecordPdb70 debug_info); - /// Creates a UUID from the data pointed to by the bytes argument. + /// Create a UUID from the data pointed to by the bytes argument. UUID(const void *bytes, uint32_t num_bytes) { if (!bytes) return; -*this -= UUID(llvm::ArrayRef(reinterpret_cast(bytes), - num_bytes)); +*this = UUID(llvm::ArrayRef( +reinterpret_cast(bytes), num_bytes)); } void Clear() { m_bytes.clear(); } @@ -67,7 +68,7 @@ class UUID { explicit operator bool() const { return IsValid(); } bool IsValid() const { return !m_bytes.empty(); } - + std::string GetAsString(llvm::StringRef separator = "-") const; bool SetFromStringRef(llvm::StringRef str); @@ -88,6 +89,9 @@ class UUID { DecodeUUIDBytesFromString(llvm::StringRef str, llvm::SmallVectorImpl &uuid_bytes); + /// Create a random UUID. + static llvm::Expected Generate(uint32_t num_bytes = 16); + private: // GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations // for this case. diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp index c7789d43c7899..e9ba7d1845bb4 100644 --- a/lldb/source/Core/Telemetry.cpp +++ b/lldb/source/Core/Telemetry.cpp @@ -9,15 +9,18 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/Telemetry.h" #include "lldb/Utility/LLDBLog.h" +#include "lldb/Utility/Log.h" #include "lldb/Utility/UUID.h" #include "lldb/lldb-enumerations.h" #include "lldb/lldb-forward.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" +#include "llvm/Support/Format.h" #include "llvm/Support/RandomNumberGenerator.h" #include "llvm/Telemetry/Telemetry.h" #include #include +#include #include #include #include @@ -37,18 +40,16 @@ static uint64_t ToNanosec(const SteadyTimePoint Point) { // This reduces the chances of getting the same UUID, even when the same // user runs the two copies of binary at the same time. static std::string MakeUUID() { - uint8_t random_bytes[16]; - std::string randomString = "_"; - if (auto ec = llvm::getRandomBytes(random_bytes, 16)) { -LLDB_LOG(GetLog(LLDBLog::Object), - "Failed to generate random bytes for UUID: {0}", ec.message()); - } else { -randomString = UUID(random_bytes).GetAsString(); + auto timestmap = std::chrono::steady_clock::now().time_since_epoch().count(); + + llvm::Expected maybe_uuid = UUID::Generate(); + if (!maybe_uuid) { +LLDB_LOG_ERROR(GetLog(LLDBLog::Host), maybe_uuid.takeError(), + "Failed to generate random bytes for UUID: {0}"); +return llvm::formatv("{0}", timestmap); } - return llvm::formatv( - "{0}_{1}", randomString, - std::chrono::steady_clock::now().time_since_epoch().count()); + return llvm::formatv("{0}_{1}", maybe_uuid->GetAsString(), timestmap)
[Lldb-commits] [lldb] [lldb] Include the version in the lldbassert error message (PR #133740)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/133740 Include the LLDB version in the lldbassert error message, and prompt users to include it in the bug report. The majority of users that bother filing a bug report just copy past the stack trace and often forget to include this important detail. By putting it after the backtrace and before the prompt, I'm hoping it'll get copy-pasted in. >From 851c0cc789441b1967b83e8cdc7d4c2ce5aa7e0d Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 31 Mar 2025 08:39:40 -0700 Subject: [PATCH] [lldb] Include the version in the lldbassert error message Include the LLDB version in the lldbassert error message, and prompt users to include it in the bug report. The majority of users that bother filing a bug report just copy past the stack trace and often forget to include this important detail. By putting it after the backtrace and before the prompt, I'm hoping it'll get copy-pasted in. --- lldb/source/Core/CMakeLists.txt| 1 + lldb/source/Core/Debugger.cpp | 5 +++-- lldb/source/Utility/LLDBAssert.cpp | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index e8bdb0613b3ff..0a08da0fec230 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -70,6 +70,7 @@ add_lldb_library(lldbCore lldbTarget lldbUtility lldbValueObject +lldbVersion lldbPluginCPlusPlusLanguage lldbPluginObjCLanguage ${LLDB_CURSES_LIBS} diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index ec7f841320217..51029f91eb12d 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1525,8 +1525,9 @@ bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format, void Debugger::AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt) { - Debugger::ReportError( - llvm::formatv("{0}\n{1}{2}", message, backtrace, prompt).str()); + Debugger::ReportError(llvm::formatv("{0}\n{1}{2}\n{3}", message, backtrace, + GetVersion(), prompt) +.str()); } void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback, diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp index d7adb52f95fa4..b84c581ccf822 100644 --- a/lldb/source/Utility/LLDBAssert.cpp +++ b/lldb/source/Utility/LLDBAssert.cpp @@ -54,8 +54,8 @@ void _lldb_assert(bool expression, const char *expr_text, const char *func, expr_text, func, file, line) .str(), buffer, - "Please file a bug report against lldb reporting this failure log, and " - "as many details as possible"); + "Please file a bug report against lldb and include the backtrace, the " + "version and as many details as possible."); } void SetLLDBAssertCallback(LLDBAssertCallback callback) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Include the version in the lldbassert error message (PR #133740)
https://github.com/adrian-prantl approved this pull request. https://github.com/llvm/llvm-project/pull/133740 ___ 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 cancelling a request. (PR #130169)
ashgti wrote: Anyone have any other comments on supporting 'cancel'? https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 94b04b4 - [lldb] Include the version in the lldbassert error message (#133740)
Author: Jonas Devlieghere Date: 2025-03-31T09:40:33-07:00 New Revision: 94b04b411903e97bd228c6bdbdb845c29f6de6a1 URL: https://github.com/llvm/llvm-project/commit/94b04b411903e97bd228c6bdbdb845c29f6de6a1 DIFF: https://github.com/llvm/llvm-project/commit/94b04b411903e97bd228c6bdbdb845c29f6de6a1.diff LOG: [lldb] Include the version in the lldbassert error message (#133740) Include the LLDB version in the lldbassert error message, and prompt users to include it in the bug report. The majority of users that bother filing a bug report just copy past the stack trace and often forget to include this important detail. By putting it after the backtrace and before the prompt, I'm hoping it'll get copy-pasted in. rdar://146793016 Added: Modified: lldb/source/Core/CMakeLists.txt lldb/source/Core/Debugger.cpp lldb/source/Utility/LLDBAssert.cpp Removed: diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index e8bdb0613b3ff..0a08da0fec230 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -70,6 +70,7 @@ add_lldb_library(lldbCore lldbTarget lldbUtility lldbValueObject +lldbVersion lldbPluginCPlusPlusLanguage lldbPluginObjCLanguage ${LLDB_CURSES_LIBS} diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index ec7f841320217..51029f91eb12d 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -1525,8 +1525,9 @@ bool Debugger::FormatDisassemblerAddress(const FormatEntity::Entry *format, void Debugger::AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt) { - Debugger::ReportError( - llvm::formatv("{0}\n{1}{2}", message, backtrace, prompt).str()); + Debugger::ReportError(llvm::formatv("{0}\n{1}{2}\n{3}", message, backtrace, + GetVersion(), prompt) +.str()); } void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback, diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp index d7adb52f95fa4..b84c581ccf822 100644 --- a/lldb/source/Utility/LLDBAssert.cpp +++ b/lldb/source/Utility/LLDBAssert.cpp @@ -54,8 +54,8 @@ void _lldb_assert(bool expression, const char *expr_text, const char *func, expr_text, func, file, line) .str(), buffer, - "Please file a bug report against lldb reporting this failure log, and " - "as many details as possible"); + "Please file a bug report against lldb and include the backtrace, the " + "version and as many details as possible."); } void SetLLDBAssertCallback(LLDBAssertCallback callback) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Include the version in the lldbassert error message (PR #133740)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/133740 ___ 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 cancelling a request. (PR #130169)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/130169 ___ 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 cancelling a request. (PR #130169)
@@ -397,6 +402,23 @@ struct DAP { InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id); InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread); + + /// Checks if the request is cancelled. + bool IsCancelled(const protocol::Request &); + + /// Clears the cancel request from the set of tracked cancel requests. + void ClearCancelRequest(const protocol::CancelArguments &); + +private: + std::mutex m_queue_mutex; + std::deque m_queue; + std::condition_variable m_queue_cv; + + std::mutex m_cancelled_requests_mutex; + std::set m_cancelled_requests; JDevlieghere wrote: ```suggestion llvm::SmallSet m_cancelled_requests; ``` https://github.com/llvm/llvm-project/pull/130169 ___ 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 cancelling a request. (PR #130169)
@@ -19,10 +19,39 @@ #include "lldb/lldb-forward.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include +#include +#include namespace lldb_dap { +class EndOfFileError : public llvm::ErrorInfo { +public: + static char ID; + + EndOfFileError() = default; + + void log(llvm::raw_ostream &OS) const override { +OS << "End of file reached."; + } + std::error_code convertToErrorCode() const override { +return llvm::inconvertibleErrorCode(); + } +}; + +class TimeoutError : public llvm::ErrorInfo { +public: + static char ID; + + TimeoutError() = default; + + void log(llvm::raw_ostream &OS) const override { +OS << "Operation timed out."; + } JDevlieghere wrote: ```suggestion void log(llvm::raw_ostream &OS) const override { OS << "operation timed out"; } ``` https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (PR #133746)
https://github.com/ashgti approved this pull request. https://github.com/llvm/llvm-project/pull/133746 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (PR #133746)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/133746 Replace GetBreakpointLabel with kDAPBreakpointLabel constant to avoid an unnecessary function call. >From 29a800b072d6841397ebe77db01b50d3db507748 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 31 Mar 2025 09:35:42 -0700 Subject: [PATCH] [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) Replace GetBreakpointLabel with kDAPBreakpointLabel constant to avoid an unnecessary function call. --- lldb/tools/lldb-dap/Breakpoint.cpp | 4 +--- lldb/tools/lldb-dap/BreakpointBase.cpp | 16 lldb/tools/lldb-dap/BreakpointBase.h | 16 +++- lldb/tools/lldb-dap/ExceptionBreakpoint.cpp | 4 +--- .../Handler/InitializeRequestHandler.cpp | 8 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp index b3bfa61595a82..eba534dcc51c7 100644 --- a/lldb/tools/lldb-dap/Breakpoint.cpp +++ b/lldb/tools/lldb-dap/Breakpoint.cpp @@ -72,9 +72,7 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { bool Breakpoint::MatchesName(const char *name) { return bp.MatchesName(name); } void Breakpoint::SetBreakpoint() { - // See comments in BreakpointBase::GetBreakpointLabel() for details of why - // we add a label to our breakpoints. - bp.AddName(GetBreakpointLabel()); + bp.AddName(kDAPBreakpointLabel); if (!condition.empty()) SetCondition(); if (!hitCondition.empty()) diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp b/lldb/tools/lldb-dap/BreakpointBase.cpp index 7979bac098766..15fecaf691199 100644 --- a/lldb/tools/lldb-dap/BreakpointBase.cpp +++ b/lldb/tools/lldb-dap/BreakpointBase.cpp @@ -26,19 +26,3 @@ void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) { SetHitCondition(); } } - -const char *BreakpointBase::GetBreakpointLabel() { - // Breakpoints in LLDB can have names added to them which are kind of like - // labels or categories. All breakpoints that are set through the IDE UI get - // sent through the various DAP set*Breakpoint packets, and these - // breakpoints will be labeled with this name so if breakpoint update events - // come in for breakpoints that the IDE doesn't know about, like if a - // breakpoint is set manually using the debugger console, we won't report any - // updates on them and confused the IDE. This function gets called by all of - // the breakpoint classes after they set breakpoints to mark a breakpoint as - // a UI breakpoint. We can later check a lldb::SBBreakpoint object that comes - // in via LLDB breakpoint changed events and check the breakpoint by calling - // "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a - // breakpoint in one of the UI breakpoints that we should report changes for. - return "dap"; -} diff --git a/lldb/tools/lldb-dap/BreakpointBase.h b/lldb/tools/lldb-dap/BreakpointBase.h index 3c248dd1736d0..0b036dd1985b3 100644 --- a/lldb/tools/lldb-dap/BreakpointBase.h +++ b/lldb/tools/lldb-dap/BreakpointBase.h @@ -10,6 +10,7 @@ #define LLDB_TOOLS_LLDB_DAP_BREAKPOINTBASE_H #include "DAPForward.h" +#include "llvm/ADT/StringRef.h" #include namespace lldb_dap { @@ -34,7 +35,20 @@ struct BreakpointBase { void UpdateBreakpoint(const BreakpointBase &request_bp); - static const char *GetBreakpointLabel(); + /// Breakpoints in LLDB can have names added to them which are kind of like + /// labels or categories. All breakpoints that are set through DAP get sent + /// through the various DAP set*Breakpoint packets, and these breakpoints will + /// be labeled with this name so if breakpoint update events come in for + /// breakpoints that the client doesn't know about, like if a breakpoint is + /// set manually using the debugger console, we won't report any updates on + /// them and confused the client. This label gets added by all of the + /// breakpoint classes after they set breakpoints to mark a breakpoint as a + /// DAP breakpoint. We can later check a lldb::SBBreakpoint object that comes + /// in via LLDB breakpoint changed events and check the breakpoint by calling + /// "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a + /// breakpoint in one of the DAP breakpoints that we should report changes + /// for. + static constexpr const char *kDAPBreakpointLabel = "dap"; }; } // namespace lldb_dap diff --git a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp index 0fb865c19e574..15aee55ad923e 100644 --- a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp +++ b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp @@ -20,9 +20,7 @@ void ExceptionBreakpoint::SetBreakpoint() { bool throw_value = filter.find("_throw") != std::string::npos; bp = dap.target.BreakpointCreateForException(language, catch_value,
[Lldb-commits] [lldb] [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (PR #133746)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/133746 ___ 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 cancelling a request. (PR #130169)
@@ -671,11 +693,25 @@ void DAP::SetTarget(const lldb::SBTarget target) { } } -bool DAP::HandleObject(const protocol::Message &M) { - if (const auto *req = std::get_if(&M)) { +bool DAP::HandleObject(const Message &M) { + if (const auto *req = std::get_if(&M)) { +{ + std::lock_guard lock(m_active_request_mutex); + m_active_request = req; + + // Clear interrupt marker prior to handling the next request. + if (debugger.InterruptRequested()) +debugger.CancelInterruptRequest(); JDevlieghere wrote: I think we should clear the interrupt flag as soon as possible. Why not do this in DAP send and checkhere that the flag is taken down before we start the next request. https://github.com/llvm/llvm-project/pull/130169 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][RISCV] fix LR/SC atomic sequence handling in lldb-server (PR #127505)
dlav-sc wrote: I'm going to land this by the end of the week. If you have any concerns, please let me know. https://github.com/llvm/llvm-project/pull/127505 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes Convert Breakpoint & Watchpoints structs to classes to provide proper access control. This is in preparation for adopting SBMutex to protect the underlying SBBreakpoint and SBWatchpoint. --- Patch is 28.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133780.diff 23 Files Affected: - (modified) lldb/tools/lldb-dap/Breakpoint.cpp (+13-11) - (modified) lldb/tools/lldb-dap/Breakpoint.h (+9-5) - (modified) lldb/tools/lldb-dap/BreakpointBase.h (+13-10) - (modified) lldb/tools/lldb-dap/DAP.cpp (+4-4) - (modified) lldb/tools/lldb-dap/DAP.h (+1-1) - (modified) lldb/tools/lldb-dap/DAPForward.h (+8-8) - (modified) lldb/tools/lldb-dap/ExceptionBreakpoint.cpp (+9-9) - (modified) lldb/tools/lldb-dap/ExceptionBreakpoint.h (+19-9) - (modified) lldb/tools/lldb-dap/FunctionBreakpoint.cpp (+3-3) - (modified) lldb/tools/lldb-dap/FunctionBreakpoint.h (+8-4) - (modified) lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp (+2-2) - (modified) lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp (+4-3) - (modified) lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp (+2-2) - (modified) lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp (+2-2) - (modified) lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp (+4-4) - (modified) lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp (+3-3) - (modified) lldb/tools/lldb-dap/InstructionBreakpoint.cpp (+5-6) - (modified) lldb/tools/lldb-dap/InstructionBreakpoint.h (+12-7) - (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+4-4) - (modified) lldb/tools/lldb-dap/SourceBreakpoint.cpp (+3-3) - (modified) lldb/tools/lldb-dap/SourceBreakpoint.h (+28-24) - (modified) lldb/tools/lldb-dap/Watchpoint.cpp (+11-10) - (modified) lldb/tools/lldb-dap/Watchpoint.h (+13-9) ``diff diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp index eba534dcc51c7..188a51909f111 100644 --- a/lldb/tools/lldb-dap/Breakpoint.cpp +++ b/lldb/tools/lldb-dap/Breakpoint.cpp @@ -19,21 +19,21 @@ using namespace lldb_dap; -void Breakpoint::SetCondition() { bp.SetCondition(condition.c_str()); } +void Breakpoint::SetCondition() { m_bp.SetCondition(condition.c_str()); } void Breakpoint::SetHitCondition() { uint64_t hitCount = 0; if (llvm::to_integer(hitCondition, hitCount)) -bp.SetIgnoreCount(hitCount - 1); +m_bp.SetIgnoreCount(hitCount - 1); } void Breakpoint::CreateJsonObject(llvm::json::Object &object) { // Each breakpoint location is treated as a separate breakpoint for VS code. // They don't have the notion of a single breakpoint with multiple locations. - if (!bp.IsValid()) + if (!m_bp.IsValid()) return; - object.try_emplace("verified", bp.GetNumResolvedLocations() > 0); - object.try_emplace("id", bp.GetID()); + object.try_emplace("verified", m_bp.GetNumResolvedLocations() > 0); + object.try_emplace("id", m_bp.GetID()); // VS Code DAP doesn't currently allow one breakpoint to have multiple // locations so we just report the first one. If we report all locations // then the IDE starts showing the wrong line numbers and locations for @@ -43,20 +43,20 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { // this as the breakpoint location since it will have a complete location // that is at least loaded in the current process. lldb::SBBreakpointLocation bp_loc; - const auto num_locs = bp.GetNumLocations(); + const auto num_locs = m_bp.GetNumLocations(); for (size_t i = 0; i < num_locs; ++i) { -bp_loc = bp.GetLocationAtIndex(i); +bp_loc = m_bp.GetLocationAtIndex(i); if (bp_loc.IsResolved()) break; } // If not locations are resolved, use the first location. if (!bp_loc.IsResolved()) -bp_loc = bp.GetLocationAtIndex(0); +bp_loc = m_bp.GetLocationAtIndex(0); auto bp_addr = bp_loc.GetAddress(); if (bp_addr.IsValid()) { std::string formatted_addr = -"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(bp.GetTarget())); +"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget())); object.try_emplace("instructionReference", formatted_addr); auto line_entry = bp_addr.GetLineEntry(); const auto line = line_entry.GetLine(); @@ -69,10 +69,12 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { } } -bool Breakpoint::MatchesName(const char *name) { return bp.MatchesName(name); } +bool Breakpoint::MatchesName(const char *name) { + return m_bp.MatchesName(name); +} void Breakpoint::SetBreakpoint() { - bp.AddName(kDAPBreakpointLabel); + m_bp.AddName(kDAPBreakpointLabel); if (!condition.empty()) SetCondition(); if (!hitCondition.empty()) diff --git a/lldb/tools/lldb-dap/Breakpoint.h b/lldb/tools/lldb-dap/Breakpoint.h index a726f27e59ee0..580017125af44 100
[Lldb-commits] [lldb] 0bdc9e6 - [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (#133746)
Author: Jonas Devlieghere Date: 2025-03-31T11:46:23-07:00 New Revision: 0bdc9e6d080009dc87b9458181c5a41cc13f26ae URL: https://github.com/llvm/llvm-project/commit/0bdc9e6d080009dc87b9458181c5a41cc13f26ae DIFF: https://github.com/llvm/llvm-project/commit/0bdc9e6d080009dc87b9458181c5a41cc13f26ae.diff LOG: [lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (#133746) Replace GetBreakpointLabel with kDAPBreakpointLabel constant to avoid an unnecessary function call. Added: Modified: lldb/tools/lldb-dap/Breakpoint.cpp lldb/tools/lldb-dap/BreakpointBase.cpp lldb/tools/lldb-dap/BreakpointBase.h lldb/tools/lldb-dap/ExceptionBreakpoint.cpp lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp Removed: diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp index b3bfa61595a82..eba534dcc51c7 100644 --- a/lldb/tools/lldb-dap/Breakpoint.cpp +++ b/lldb/tools/lldb-dap/Breakpoint.cpp @@ -72,9 +72,7 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) { bool Breakpoint::MatchesName(const char *name) { return bp.MatchesName(name); } void Breakpoint::SetBreakpoint() { - // See comments in BreakpointBase::GetBreakpointLabel() for details of why - // we add a label to our breakpoints. - bp.AddName(GetBreakpointLabel()); + bp.AddName(kDAPBreakpointLabel); if (!condition.empty()) SetCondition(); if (!hitCondition.empty()) diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp b/lldb/tools/lldb-dap/BreakpointBase.cpp index 7979bac098766..15fecaf691199 100644 --- a/lldb/tools/lldb-dap/BreakpointBase.cpp +++ b/lldb/tools/lldb-dap/BreakpointBase.cpp @@ -26,19 +26,3 @@ void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) { SetHitCondition(); } } - -const char *BreakpointBase::GetBreakpointLabel() { - // Breakpoints in LLDB can have names added to them which are kind of like - // labels or categories. All breakpoints that are set through the IDE UI get - // sent through the various DAP set*Breakpoint packets, and these - // breakpoints will be labeled with this name so if breakpoint update events - // come in for breakpoints that the IDE doesn't know about, like if a - // breakpoint is set manually using the debugger console, we won't report any - // updates on them and confused the IDE. This function gets called by all of - // the breakpoint classes after they set breakpoints to mark a breakpoint as - // a UI breakpoint. We can later check a lldb::SBBreakpoint object that comes - // in via LLDB breakpoint changed events and check the breakpoint by calling - // "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a - // breakpoint in one of the UI breakpoints that we should report changes for. - return "dap"; -} diff --git a/lldb/tools/lldb-dap/BreakpointBase.h b/lldb/tools/lldb-dap/BreakpointBase.h index 3c248dd1736d0..0b036dd1985b3 100644 --- a/lldb/tools/lldb-dap/BreakpointBase.h +++ b/lldb/tools/lldb-dap/BreakpointBase.h @@ -10,6 +10,7 @@ #define LLDB_TOOLS_LLDB_DAP_BREAKPOINTBASE_H #include "DAPForward.h" +#include "llvm/ADT/StringRef.h" #include namespace lldb_dap { @@ -34,7 +35,20 @@ struct BreakpointBase { void UpdateBreakpoint(const BreakpointBase &request_bp); - static const char *GetBreakpointLabel(); + /// Breakpoints in LLDB can have names added to them which are kind of like + /// labels or categories. All breakpoints that are set through DAP get sent + /// through the various DAP set*Breakpoint packets, and these breakpoints will + /// be labeled with this name so if breakpoint update events come in for + /// breakpoints that the client doesn't know about, like if a breakpoint is + /// set manually using the debugger console, we won't report any updates on + /// them and confused the client. This label gets added by all of the + /// breakpoint classes after they set breakpoints to mark a breakpoint as a + /// DAP breakpoint. We can later check a lldb::SBBreakpoint object that comes + /// in via LLDB breakpoint changed events and check the breakpoint by calling + /// "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a + /// breakpoint in one of the DAP breakpoints that we should report changes + /// for. + static constexpr const char *kDAPBreakpointLabel = "dap"; }; } // namespace lldb_dap diff --git a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp index 0fb865c19e574..15aee55ad923e 100644 --- a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp +++ b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp @@ -20,9 +20,7 @@ void ExceptionBreakpoint::SetBreakpoint() { bool throw_value = filter.find("_throw") != std::string::npos; bp = dap.target.BreakpointCreateForException(language, catch_value, throw_value); - // See co