[Lldb-commits] [lldb] f5d80c3 - [lldb] Avoid Function::GetAddressRange in SymbolFileCTF (#128517)

2025-02-24 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-02-25T08:57:55+01:00
New Revision: f5d80c335d79d0b35741bfc762f8157a24f5491a

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

LOG: [lldb] Avoid Function::GetAddressRange in SymbolFileCTF (#128517)

SymbolFileCTF never creates discontinuous functions, so this is
technically NFC, but it takes us one step closer to removing the
deprecated API.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp 
b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
index 0feb927c5c948..0b8862f64ceb8 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -946,8 +946,10 @@ uint32_t SymbolFileCTF::ResolveSymbolContext(const Address 
&so_addr,
   // Resolve functions.
   if (resolve_scope & eSymbolContextFunction) {
 for (FunctionSP function_sp : m_functions) {
-  if (function_sp->GetAddressRange().ContainsFileAddress(
-  so_addr.GetFileAddress())) {
+  if (llvm::any_of(
+  function_sp->GetAddressRanges(), [&](const AddressRange range) {
+return range.ContainsFileAddress(so_addr.GetFileAddress());
+  })) {
 sc.function = function_sp.get();
 resolved_flags |= eSymbolContextFunction;
 break;



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


[Lldb-commits] [lldb] [lldb] Avoid Function::GetAddressRange in SymbolFileCTF (PR #128517)

2025-02-24 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Don't hand out UnwindPlan::Row shared_ptrs (PR #128181)

2025-02-24 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Refactor custom & testing related request handlers (NFC) (PR #128549)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

Continuation of the work started in 
https://github.com/llvm/llvm-project/pull/128262. Builds on top of #128453.

>From 0bf14ccd21f06ee3c53d64b5139760072d6405b1 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sun, 23 Feb 2025 21:07:55 -0600
Subject: [PATCH 1/2] [lldb-dap] Refactor stepping related request handlers
 (NFC)

Continuation of the work started in #128262.
---
 lldb/tools/lldb-dap/CMakeLists.txt|   4 +
 .../lldb-dap/Handler/NextRequestHandler.cpp   |  79 
 .../tools/lldb-dap/Handler/RequestHandler.cpp |   7 +
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  33 +-
 .../lldb-dap/Handler/StepInRequestHandler.cpp |  96 +
 .../Handler/StepInTargetsRequestHandler.cpp   | 149 
 .../Handler/StepOutRequestHandler.cpp |  68 
 lldb/tools/lldb-dap/lldb-dap.cpp  | 344 +-
 8 files changed, 440 insertions(+), 340 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..61271e1a9f2a6 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -47,8 +47,12 @@ add_lldb_tool(lldb-dap
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
new file mode 100644
index 0..695703fe301b3
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
@@ -0,0 +1,79 @@
+//===-- NextRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "NextRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Next request; value of command field is 'next'. The
+// request starts the debuggee to run again for one step.
+// The debug adapter first sends the NextResponse and then
+// a StoppedEvent (event type 'step') after the step has
+// completed.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "next" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/NextArguments"
+//   }
+// },
+// "required": [ "command", "arguments"  ]
+//   }]
+// },
+// "NextArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'next' request.",
+//   "properties": {
+// "threadId": {
+//   "type": "integer",
+//   "description": "Execute 'next' for this thread."
+// },
+// "granularity": {
+//   "$ref": "#/definitions/SteppingGranularity",
+//   "description": "Stepping granularity. If no granularity is specified, 
a
+//   granularity of `statement` is assumed."
+// }
+//   },
+//   "required": [ "threadId" ]
+// },
+// "NextResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'next' request. This is just an
+// acknowledgement, so no body field is required."
+//   }]
+// }
+void NextRequestHandler::operator()(const llvm::json::Object &request) {
+  llvm::json::Object response;
+  FillResponse(request, response);
+  const auto *arguments = request.getObject("arguments");
+  lldb::SBThread thread = dap.GetLLDBThread(*arguments);
+  if (thread.IsValid()) {
+// Remember the thread ID that caused the resume so we can set the
+// "threadCausedFocus" boolean value in the "stopped" events.
+dap.focus_tid = thread.GetThreadID();
+if (HasInstructionGranularity(*arguments)) {
+  thread.StepInstruction(/*step_over=*/true);
+} else {
+  thread.StepOver();
+}
+  } else {
+response["success"] = llvm::json::Value(false);
+  }
+  dap.SendJSON(llvm::json::Value(std::move(response)));
+}
+
+} // namespace lldb_dap
diff --git a/lld

[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Continuation of the work started in 
https://github.com/llvm/llvm-project/pull/128262. Builds on top of 
https://github.com/llvm/llvm-project/pull/128549.

---

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


17 Files Affected:

- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+12) 
- (added) lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp (+80) 
- (added) lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp 
(+190) 
- (added) lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp (+58) 
- (added) lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp (+79) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+62) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+106-1) 
- (added) lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp (+182) 
- (added) lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp 
(+114) 
- (added) lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp 
(+93) 
- (added) lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp 
(+139) 
- (added) 
lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp (+249) 
- (added) lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp (+96) 
- (added) lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp (+149) 
- (added) lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp (+68) 
- (added) 
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp (+31) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+49-1375) 


``diff
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..c04b10861a4c5 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -39,16 +39,28 @@ add_lldb_tool(lldb-dap
 
   Handler/AttachRequestHandler.cpp
   Handler/BreakpointLocationsHandler.cpp
+  Handler/CompileUnitsRequestHandler.cpp
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
+  Handler/DataBreakpointInfoRequestHandler.cpp
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/ModulesRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/SetBreakpointsRequestHandler.cpp
+  Handler/SetDataBreakpointsRequestHandler.cpp
+  Handler/SetExceptionBreakpointsRequestHandler.cpp
+  Handler/SetFunctionBreakpointsRequestHandler.cpp
+  Handler/SetInstructionBreakpointsRequestHandler.cpp 
Handler/StepOutRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
new file mode 100644
index 0..c541d1cd039c8
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -0,0 +1,80 @@
+//===-- CompileUnitsRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "compileUnitsRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Compile Unit request; value of command field is
+// 'compileUnits'.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "compileUnits" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/compileUnitRequestArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "compileUnitsRequestArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'compileUnits' request.",
+//   "properties": {
+// "moduleId": {
+//   "type": "string",
+//   "description": "The ID of the module."
+// }
+//   },
+//   "required": [ "moduleId" ]
+// },
+// "compileUnitsResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'compileUnits' request.",
+// "properties": {
+//   "body": {
+// "description": "Response to 'compileUnits' request. Array of
+// paths of compile units."
+//

[Lldb-commits] [lldb] [lldb-dap] Refactor remaining request handlers (NFC)Remaining request handlers (PR #128551)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Continuation of the work started in 
https://github.com/llvm/llvm-project/pull/128262. Builds on top of 
https://github.com/llvm/llvm-project/pull/128550.

---

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


27 Files Affected:

- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+23) 
- (added) lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp (+80) 
- (added) lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp 
(+190) 
- (added) lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp (+222) 
- (added) lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp (+160) 
- (added) lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp (+58) 
- (added) lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp (+79) 
- (added) lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp (+60) 
- (added) lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp (+139) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+62) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+176-1) 
- (added) lldb/tools/lldb-dap/Handler/ScopesRequestHandler.cpp (+106) 
- (added) lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp (+182) 
- (added) lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp 
(+114) 
- (added) lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp 
(+93) 
- (added) lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp 
(+139) 
- (added) 
lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp (+249) 
- (added) lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp (+177) 
- (added) lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp (+82) 
- (added) lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp (+197) 
- (added) lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp (+96) 
- (added) lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp (+149) 
- (added) lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp (+68) 
- (added) 
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp (+31) 
- (added) lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp (+71) 
- (added) lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp (+217) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+29-2676) 


``diff
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..804dd8e4cc2a0 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -39,16 +39,39 @@ add_lldb_tool(lldb-dap
 
   Handler/AttachRequestHandler.cpp
   Handler/BreakpointLocationsHandler.cpp
+  Handler/CompileUnitsRequestHandler.cpp
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
+  Handler/DataBreakpointInfoRequestHandler.cpp
+  Handler/DisassembleRequestHandler.cpp
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/LocationsRequestHandler.cpp
+  Handler/ModulesRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
+  Handler/PauseRequestHandler.cpp
+  Handler/ReadMemoryRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/ScopesRequestHandler.cpp
+  Handler/SetBreakpointsRequestHandler.cpp
+  Handler/SetDataBreakpointsRequestHandler.cpp
+  Handler/SetExceptionBreakpointsRequestHandler.cpp
+  Handler/SetFunctionBreakpointsRequestHandler.cpp
+  Handler/SetInstructionBreakpointsRequestHandler.cpp
+  Handler/SetVariableRequestHandler.cpp
+  Handler/SourceRequestHandler.cpp
+  Handler/StackTraceRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/StepOutRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
+  Handler/ThreadsRequestHandler.cpp
+  Handler/VariablesRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
new file mode 100644
index 0..c541d1cd039c8
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -0,0 +1,80 @@
+//===-- CompileUnitsRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "compileUnitsRequest": {
+//   "allOf": [ { "$ref": "#/defin

[Lldb-commits] [lldb] [lldb] Avoid Function::GetAddressRange in SymbolFileCTF (PR #128517)

2025-02-24 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/128517

SymbolFileCTF never creates discontinuous functions, so this is technically 
NFC, but it takes us one step closer to removing the deprecated API.

>From 01ee867cca41202c2a87f8216b75aa5d6d9603cd Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 24 Feb 2025 15:20:46 +0100
Subject: [PATCH] [lldb] Avoid Function::GetAddressRange in SymbolFileCTF

SymbolFileCTF never creates discontinuous functions, so this is
technically NFC, but it takes us one step closer to removing the
deprecated API.
---
 lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp 
b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
index 0feb927c5c948..0b8862f64ceb8 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -946,8 +946,10 @@ uint32_t SymbolFileCTF::ResolveSymbolContext(const Address 
&so_addr,
   // Resolve functions.
   if (resolve_scope & eSymbolContextFunction) {
 for (FunctionSP function_sp : m_functions) {
-  if (function_sp->GetAddressRange().ContainsFileAddress(
-  so_addr.GetFileAddress())) {
+  if (llvm::any_of(
+  function_sp->GetAddressRanges(), [&](const AddressRange range) {
+return range.ContainsFileAddress(so_addr.GetFileAddress());
+  })) {
 sc.function = function_sp.get();
 resolved_flags |= eSymbolContextFunction;
 break;

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


[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Completes the work started in https://github.com/llvm/llvm-project/pull/128262. 
This PR removes the old way of register request handlers with callbacks. Builds 
on top of https://github.com/llvm/llvm-project/pull/128551. 

---

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


29 Files Affected:

- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+23) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (+2-15) 
- (modified) lldb/tools/lldb-dap/DAP.h (+2-17) 
- (added) lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp (+80) 
- (added) lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp 
(+190) 
- (added) lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp (+222) 
- (added) lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp (+160) 
- (added) lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp (+58) 
- (added) lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp (+79) 
- (added) lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp (+60) 
- (added) lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp (+139) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+62) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+176-1) 
- (added) lldb/tools/lldb-dap/Handler/ScopesRequestHandler.cpp (+106) 
- (added) lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp (+182) 
- (added) lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp 
(+114) 
- (added) lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp 
(+93) 
- (added) lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp 
(+139) 
- (added) 
lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp (+249) 
- (added) lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp (+177) 
- (added) lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp (+82) 
- (added) lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp (+197) 
- (added) lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp (+96) 
- (added) lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp (+149) 
- (added) lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp (+68) 
- (added) 
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp (+31) 
- (added) lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp (+71) 
- (added) lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp (+217) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+25-2678) 


``diff
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..804dd8e4cc2a0 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -39,16 +39,39 @@ add_lldb_tool(lldb-dap
 
   Handler/AttachRequestHandler.cpp
   Handler/BreakpointLocationsHandler.cpp
+  Handler/CompileUnitsRequestHandler.cpp
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
+  Handler/DataBreakpointInfoRequestHandler.cpp
+  Handler/DisassembleRequestHandler.cpp
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/LocationsRequestHandler.cpp
+  Handler/ModulesRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
+  Handler/PauseRequestHandler.cpp
+  Handler/ReadMemoryRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/ScopesRequestHandler.cpp
+  Handler/SetBreakpointsRequestHandler.cpp
+  Handler/SetDataBreakpointsRequestHandler.cpp
+  Handler/SetExceptionBreakpointsRequestHandler.cpp
+  Handler/SetFunctionBreakpointsRequestHandler.cpp
+  Handler/SetInstructionBreakpointsRequestHandler.cpp
+  Handler/SetVariableRequestHandler.cpp
+  Handler/SourceRequestHandler.cpp
+  Handler/StackTraceRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/StepOutRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
+  Handler/ThreadsRequestHandler.cpp
+  Handler/VariablesRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 9b22b60a68d94..d5dd0304f7221 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -758,20 +758,12 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
   if (packet_type == "request") {
 const auto command = GetString(object, "command");
 
-// Try the new request handler first.
-auto new_handler_pos = new_request_handlers.find(command);
-if (new_handler_pos != new_request_handlers.end()) {
+auto new_handler_pos = request_handlers.find(command);
+if (new_handler_pos != request_handlers.end()) {
   (*new_handler_pos->second)(object);
   ret

[Lldb-commits] [lldb] [lldb-dap] Refactor custom & testing related request handlers (NFC) (PR #128549)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Continuation of the work started in 
https://github.com/llvm/llvm-project/pull/128262. Builds on top of #128453.

---

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


11 Files Affected:

- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+7) 
- (added) lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp (+80) 
- (added) lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp (+58) 
- (added) lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp (+79) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.cpp (+7) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+59-1) 
- (added) lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp (+96) 
- (added) lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp (+149) 
- (added) lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp (+68) 
- (added) 
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp (+31) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+12-470) 


``diff
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..688a2e448f71d 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -39,6 +39,7 @@ add_lldb_tool(lldb-dap
 
   Handler/AttachRequestHandler.cpp
   Handler/BreakpointLocationsHandler.cpp
+  Handler/CompileUnitsRequestHandler.cpp
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
@@ -47,8 +48,14 @@ add_lldb_tool(lldb-dap
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/ModulesRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
+  Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
new file mode 100644
index 0..c541d1cd039c8
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -0,0 +1,80 @@
+//===-- CompileUnitsRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "compileUnitsRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Compile Unit request; value of command field is
+// 'compileUnits'.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "compileUnits" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/compileUnitRequestArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "compileUnitsRequestArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'compileUnits' request.",
+//   "properties": {
+// "moduleId": {
+//   "type": "string",
+//   "description": "The ID of the module."
+// }
+//   },
+//   "required": [ "moduleId" ]
+// },
+// "compileUnitsResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'compileUnits' request.",
+// "properties": {
+//   "body": {
+// "description": "Response to 'compileUnits' request. Array of
+// paths of compile units."
+//   }
+// }
+//   }]
+// }
+void CompileUnitsRequestHandler::operator()(const llvm::json::Object &request) 
{
+  llvm::json::Object response;
+  FillResponse(request, response);
+  llvm::json::Object body;
+  llvm::json::Array units;
+  const auto *arguments = request.getObject("arguments");
+  std::string module_id = std::string(GetString(arguments, "moduleId"));
+  int num_modules = dap.target.GetNumModules();
+  for (int i = 0; i < num_modules; i++) {
+auto curr_module = dap.target.GetModuleAtIndex(i);
+if (module_id == curr_module.GetUUIDString()) {
+  int num_units = curr_module.GetNumCompileUnits();
+  for (int j = 0; j < num_units; j++) {
+auto curr_unit = curr_module.GetCompileUnitAtIndex(j);
+units.emplace_back(CreateCompileUnit(curr_unit));
+  }
+  body.try_emplace("compileUnits", std::move(units));
+  break;
+}
+  }
+  

[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 51ce6c437fec1fe0170d077424e1cbc141d05c2b 
76c1fd886868c1f330e79997a499330ee308dee2 --extensions h,cpp -- 
lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/ScopesRequestHandler.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/Handler/SetVariableRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp 
lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/DAP.h 
lldb/tools/lldb-dap/Handler/RequestHandler.cpp 
lldb/tools/lldb-dap/Handler/RequestHandler.h lldb/tools/lldb-dap/lldb-dap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index ddda8603c1..2335ebd312 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -332,8 +332,7 @@ struct DAP {
 
   /// Registers a request handler.
   template  void RegisterRequest() {
-request_handlers[Handler::getCommand()] =
-std::make_unique(*this);
+request_handlers[Handler::getCommand()] = std::make_unique(*this);
   }
 
   /// Debuggee will continue from stopped state.

``




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


[Lldb-commits] [lldb] 51ce6c4 - [lldb-dap] Fix error C2065: 'PATH_MAX': undeclared identifier

2025-02-24 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2025-02-24T12:16:05-06:00
New Revision: 51ce6c437fec1fe0170d077424e1cbc141d05c2b

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

LOG: [lldb-dap] Fix error C2065: 'PATH_MAX': undeclared identifier

This should fix the Windows build.

Added: 


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

Removed: 




diff  --git a/lldb/tools/lldb-dap/EventHelper.cpp 
b/lldb/tools/lldb-dap/EventHelper.cpp
index 20845fbc5b916..705eb0a457d9c 100644
--- a/lldb/tools/lldb-dap/EventHelper.cpp
+++ b/lldb/tools/lldb-dap/EventHelper.cpp
@@ -12,6 +12,15 @@
 #include "LLDBUtils.h"
 #include "lldb/API/SBFileSpec.h"
 
+#if defined(_WIN32)
+#define NOMINMAX
+#include 
+
+#ifndef PATH_MAX
+#define PATH_MAX MAX_PATH
+#endif
+#endif
+
 namespace lldb_dap {
 
 static void SendThreadExitedEvent(DAP &dap, lldb::tid_t tid) {

diff  --git a/lldb/tools/lldb-dap/lldb-dap.cpp 
b/lldb/tools/lldb-dap/lldb-dap.cpp
index fcefb4137f227..7935e88dba71a 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -80,6 +80,7 @@
 #include 
 #undef GetObject
 #include 
+typedef int socklen_t;
 #else
 #include 
 #include 
@@ -91,13 +92,6 @@
 #include 
 #endif
 
-#if defined(_WIN32)
-#ifndef PATH_MAX
-#define PATH_MAX MAX_PATH
-#endif
-typedef int socklen_t;
-#endif
-
 using namespace lldb_dap;
 using lldb_private::NativeSocket;
 using lldb_private::Socket;



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


[Lldb-commits] [lldb] [lldb-dap] Refactor request handlers (NFC) (PR #128262)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

> LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-win` 
> running on `as-builder-10` while building `lldb` at step 8 "build-default".
Should be fixed by 51ce6c437fec1fe0170d077424e1cbc141d05c2b



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


[Lldb-commits] [lldb] 82264d2 - [lldb-dap] Refactor stepping related request handlers (NFC) (#128453)

2025-02-24 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-02-24T13:50:11-06:00
New Revision: 82264d23a1cc2ad9334f9a277cb92043a8bac446

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

LOG: [lldb-dap] Refactor stepping related request handlers (NFC) (#128453)

Continuation of the work started in #128262.

Added: 
lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp

Modified: 
lldb/tools/lldb-dap/CMakeLists.txt
lldb/tools/lldb-dap/Handler/RequestHandler.cpp
lldb/tools/lldb-dap/Handler/RequestHandler.h
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..61271e1a9f2a6 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -47,8 +47,12 @@ add_lldb_tool(lldb-dap
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
 liblldb

diff  --git a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
new file mode 100644
index 0..695703fe301b3
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
@@ -0,0 +1,79 @@
+//===-- NextRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "NextRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Next request; value of command field is 'next'. The
+// request starts the debuggee to run again for one step.
+// The debug adapter first sends the NextResponse and then
+// a StoppedEvent (event type 'step') after the step has
+// completed.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "next" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/NextArguments"
+//   }
+// },
+// "required": [ "command", "arguments"  ]
+//   }]
+// },
+// "NextArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'next' request.",
+//   "properties": {
+// "threadId": {
+//   "type": "integer",
+//   "description": "Execute 'next' for this thread."
+// },
+// "granularity": {
+//   "$ref": "#/definitions/SteppingGranularity",
+//   "description": "Stepping granularity. If no granularity is specified, 
a
+//   granularity of `statement` is assumed."
+// }
+//   },
+//   "required": [ "threadId" ]
+// },
+// "NextResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'next' request. This is just an
+// acknowledgement, so no body field is required."
+//   }]
+// }
+void NextRequestHandler::operator()(const llvm::json::Object &request) {
+  llvm::json::Object response;
+  FillResponse(request, response);
+  const auto *arguments = request.getObject("arguments");
+  lldb::SBThread thread = dap.GetLLDBThread(*arguments);
+  if (thread.IsValid()) {
+// Remember the thread ID that caused the resume so we can set the
+// "threadCausedFocus" boolean value in the "stopped" events.
+dap.focus_tid = thread.GetThreadID();
+if (HasInstructionGranularity(*arguments)) {
+  thread.StepInstruction(/*step_over=*/true);
+} else {
+  thread.StepOver();
+}
+  } else {
+response["success"] = llvm::json::Value(false);
+  }
+  dap.SendJSON(llvm::json::Value(std::move(response)));
+}
+
+} // namespace lldb_dap

diff  --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
index c09ddf55dd5e9..f9502e09846d4 100644
--- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
@@ -225,4 +225,11 @@ void RequestHandler::PrintWelcomeMessage() {
 #endif
 }
 
+bool RequestHandler

[Lldb-commits] [lldb] [lldb-dap] Refactor stepping related request handlers (NFC) (PR #128453)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

>From d6a556acb94c334c24308743aeedfaa7da51f872 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 12:50:21 -0600
Subject: [PATCH 1/2] [lldb-dap] Finish refactoring the request handlers (NFC)

This removes the old way of register request handlers with callbacks.
---
 lldb/tools/lldb-dap/DAP.cpp  | 17 ++---
 lldb/tools/lldb-dap/DAP.h| 19 ++-
 lldb/tools/lldb-dap/lldb-dap.cpp |  2 --
 3 files changed, 4 insertions(+), 34 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index c9487dd89b5dc..74af181931fc1 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -758,20 +758,12 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
   if (packet_type == "request") {
 const auto command = GetString(object, "command");
 
-// Try the new request handler first.
-auto new_handler_pos = new_request_handlers.find(command);
-if (new_handler_pos != new_request_handlers.end()) {
+auto new_handler_pos = request_handlers.find(command);
+if (new_handler_pos != request_handlers.end()) {
   (*new_handler_pos->second)(object);
   return true; // Success
 }
 
-// FIXME: Remove request_handlers once everything has been migrated.
-auto handler_pos = request_handlers.find(command);
-if (handler_pos != request_handlers.end()) {
-  handler_pos->second(*this, object);
-  return true; // Success
-}
-
 if (log)
   *log << "error: unhandled command \"" << command.data() << "\""
<< std::endl;
@@ -900,11 +892,6 @@ void DAP::SendReverseRequest(llvm::StringRef command,
   });
 }
 
-void DAP::RegisterRequestCallback(std::string request,
-  RequestCallback callback) {
-  request_handlers[request] = callback;
-}
-
 lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
   lldb::SBError error;
   lldb::SBProcess process = target.GetProcess();
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index ca26ea1b9a5de..c3cc3c3184ffb 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -68,7 +68,6 @@ enum DAPBroadcasterBits {
   eBroadcastBitStopProgressThread = 1u << 1
 };
 
-typedef void (*RequestCallback)(DAP &dap, const llvm::json::Object &command);
 typedef void (*ResponseCallback)(llvm::Expected value);
 
 enum class PacketStatus {
@@ -190,8 +189,7 @@ struct DAP {
   // the old process here so we can detect this case and keep running.
   lldb::pid_t restarting_process_id;
   bool configuration_done_sent;
-  std::map> request_handlers;
-  llvm::StringMap> new_request_handlers;
+  llvm::StringMap> request_handlers;
   bool waiting_for_run_in_terminal;
   ProgressEventReporter progress_event_reporter;
   // Keep track of the last stop thread index IDs as threads won't go away
@@ -309,8 +307,6 @@ struct DAP {
   /// listeing for its breakpoint events.
   void SetTarget(const lldb::SBTarget target);
 
-  const std::map &GetRequestHandlers();
-
   PacketStatus GetNextObject(llvm::json::Object &object);
   bool HandleObject(const llvm::json::Object &object);
 
@@ -338,20 +334,9 @@ struct DAP {
   void SendReverseRequest(llvm::StringRef command, llvm::json::Value arguments,
   ResponseCallback callback);
 
-  /// Registers a callback handler for a Debug Adapter Protocol request
-  ///
-  /// \param[in] request
-  /// The name of the request following the Debug Adapter Protocol
-  /// specification.
-  ///
-  /// \param[in] callback
-  /// The callback to execute when the given request is triggered by the
-  /// IDE.
-  void RegisterRequestCallback(std::string request, RequestCallback callback);
-
   /// Registers a request handler.
   template  void RegisterRequest() {
-new_request_handlers[Handler::getCommand()] =
+request_handlers[Handler::getCommand()] =
 std::make_unique(*this);
   }
 
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7f196a958654c..5345d57a0b910 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -123,8 +123,6 @@ class LLDBDAPOptTable : public llvm::opt::GenericOptTable {
InfoTable, true) {}
 };
 
-typedef void (*RequestCallback)(const llvm::json::Object &command);
-
 void RegisterRequestCallbacks(DAP &dap) {
   dap.RegisterRequest();
   dap.RegisterRequest();

>From 611d0c958f731060038211db47d9d1fe25af9244 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 16:06:25 -0600
Subject: [PATCH 2/2] Make RequestHandler methods const

---
 .../lldb-dap/Handler/AttachRequestHandler.cpp |  2 +-
 .../Handler/BreakpointLocationsHandler.cpp|  2 +-
 .../Handler/CompileUnitsRequestHandler.cpp|  3 +-
 .../lldb-dap/Handler/CompletionsHandler.cpp   |  3 +-
 .../ConfigurationDoneRequestHandler.c

[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

>From d6a556acb94c334c24308743aeedfaa7da51f872 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 12:50:21 -0600
Subject: [PATCH 1/3] [lldb-dap] Finish refactoring the request handlers (NFC)

This removes the old way of register request handlers with callbacks.
---
 lldb/tools/lldb-dap/DAP.cpp  | 17 ++---
 lldb/tools/lldb-dap/DAP.h| 19 ++-
 lldb/tools/lldb-dap/lldb-dap.cpp |  2 --
 3 files changed, 4 insertions(+), 34 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index c9487dd89b5dc..74af181931fc1 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -758,20 +758,12 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
   if (packet_type == "request") {
 const auto command = GetString(object, "command");
 
-// Try the new request handler first.
-auto new_handler_pos = new_request_handlers.find(command);
-if (new_handler_pos != new_request_handlers.end()) {
+auto new_handler_pos = request_handlers.find(command);
+if (new_handler_pos != request_handlers.end()) {
   (*new_handler_pos->second)(object);
   return true; // Success
 }
 
-// FIXME: Remove request_handlers once everything has been migrated.
-auto handler_pos = request_handlers.find(command);
-if (handler_pos != request_handlers.end()) {
-  handler_pos->second(*this, object);
-  return true; // Success
-}
-
 if (log)
   *log << "error: unhandled command \"" << command.data() << "\""
<< std::endl;
@@ -900,11 +892,6 @@ void DAP::SendReverseRequest(llvm::StringRef command,
   });
 }
 
-void DAP::RegisterRequestCallback(std::string request,
-  RequestCallback callback) {
-  request_handlers[request] = callback;
-}
-
 lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
   lldb::SBError error;
   lldb::SBProcess process = target.GetProcess();
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index ca26ea1b9a5de..c3cc3c3184ffb 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -68,7 +68,6 @@ enum DAPBroadcasterBits {
   eBroadcastBitStopProgressThread = 1u << 1
 };
 
-typedef void (*RequestCallback)(DAP &dap, const llvm::json::Object &command);
 typedef void (*ResponseCallback)(llvm::Expected value);
 
 enum class PacketStatus {
@@ -190,8 +189,7 @@ struct DAP {
   // the old process here so we can detect this case and keep running.
   lldb::pid_t restarting_process_id;
   bool configuration_done_sent;
-  std::map> request_handlers;
-  llvm::StringMap> new_request_handlers;
+  llvm::StringMap> request_handlers;
   bool waiting_for_run_in_terminal;
   ProgressEventReporter progress_event_reporter;
   // Keep track of the last stop thread index IDs as threads won't go away
@@ -309,8 +307,6 @@ struct DAP {
   /// listeing for its breakpoint events.
   void SetTarget(const lldb::SBTarget target);
 
-  const std::map &GetRequestHandlers();
-
   PacketStatus GetNextObject(llvm::json::Object &object);
   bool HandleObject(const llvm::json::Object &object);
 
@@ -338,20 +334,9 @@ struct DAP {
   void SendReverseRequest(llvm::StringRef command, llvm::json::Value arguments,
   ResponseCallback callback);
 
-  /// Registers a callback handler for a Debug Adapter Protocol request
-  ///
-  /// \param[in] request
-  /// The name of the request following the Debug Adapter Protocol
-  /// specification.
-  ///
-  /// \param[in] callback
-  /// The callback to execute when the given request is triggered by the
-  /// IDE.
-  void RegisterRequestCallback(std::string request, RequestCallback callback);
-
   /// Registers a request handler.
   template  void RegisterRequest() {
-new_request_handlers[Handler::getCommand()] =
+request_handlers[Handler::getCommand()] =
 std::make_unique(*this);
   }
 
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7f196a958654c..5345d57a0b910 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -123,8 +123,6 @@ class LLDBDAPOptTable : public llvm::opt::GenericOptTable {
InfoTable, true) {}
 };
 
-typedef void (*RequestCallback)(const llvm::json::Object &command);
-
 void RegisterRequestCallbacks(DAP &dap) {
   dap.RegisterRequest();
   dap.RegisterRequest();

>From 611d0c958f731060038211db47d9d1fe25af9244 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 16:06:25 -0600
Subject: [PATCH 2/3] Make RequestHandler methods const

---
 .../lldb-dap/Handler/AttachRequestHandler.cpp |  2 +-
 .../Handler/BreakpointLocationsHandler.cpp|  2 +-
 .../Handler/CompileUnitsRequestHandler.cpp|  3 +-
 .../lldb-dap/Handler/CompletionsHandler.cpp   |  3 +-
 .../ConfigurationDoneRequestHandler.c

[Lldb-commits] [lldb] [lldb-dap] Refactor custom & testing related request handlers (NFC) (PR #128549)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] 9884803 - [lldb-dap] Refactor custom & testing related request handlers (NFC) (#128549)

2025-02-24 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-02-24T14:06:00-06:00
New Revision: 988480323d5ef9bb658f13ac598d4ce2aa23c782

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

LOG: [lldb-dap] Refactor custom & testing related request handlers (NFC) 
(#128549)

Continuation of the work started in
https://github.com/llvm/llvm-project/pull/128262. Builds on top of
#128453.

Added: 
lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp

Modified: 
lldb/tools/lldb-dap/CMakeLists.txt
lldb/tools/lldb-dap/Handler/RequestHandler.h
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 61271e1a9f2a6..688a2e448f71d 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -39,6 +39,7 @@ add_lldb_tool(lldb-dap
 
   Handler/AttachRequestHandler.cpp
   Handler/BreakpointLocationsHandler.cpp
+  Handler/CompileUnitsRequestHandler.cpp
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
@@ -47,11 +48,13 @@ add_lldb_tool(lldb-dap
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/ModulesRequestHandler.cpp
   Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
   Handler/StepInRequestHandler.cpp
   Handler/StepInTargetsRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
   Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS

diff  --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
new file mode 100644
index 0..c541d1cd039c8
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -0,0 +1,80 @@
+//===-- CompileUnitsRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "compileUnitsRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Compile Unit request; value of command field is
+// 'compileUnits'.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "compileUnits" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/compileUnitRequestArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "compileUnitsRequestArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'compileUnits' request.",
+//   "properties": {
+// "moduleId": {
+//   "type": "string",
+//   "description": "The ID of the module."
+// }
+//   },
+//   "required": [ "moduleId" ]
+// },
+// "compileUnitsResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'compileUnits' request.",
+// "properties": {
+//   "body": {
+// "description": "Response to 'compileUnits' request. Array of
+// paths of compile units."
+//   }
+// }
+//   }]
+// }
+void CompileUnitsRequestHandler::operator()(const llvm::json::Object &request) 
{
+  llvm::json::Object response;
+  FillResponse(request, response);
+  llvm::json::Object body;
+  llvm::json::Array units;
+  const auto *arguments = request.getObject("arguments");
+  std::string module_id = std::string(GetString(arguments, "moduleId"));
+  int num_modules = dap.target.GetNumModules();
+  for (int i = 0; i < num_modules; i++) {
+auto curr_module = dap.target.GetModuleAtIndex(i);
+if (module_id == curr_module.GetUUIDString()) {
+  int num_units = curr_module.GetNumCompileUnits();
+  for (int j = 0; j < num_units; j++) {
+auto curr_unit = curr_module.GetCompileUnitAtIndex(j);
+units.emplace_back(CreateCompileUnit(curr_unit));
+  }
+  body.try_emplace("compileUnits", std::move(units));
+  break;
+}
+  }
+  response.try_emplace("body", std::move(body));
+  dap.SendJSON(llvm::json::Value(std::move(response)));
+}
+
+} // namespace lldb_dap

diff  --git a/lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp 
b/lldb

[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

>From 95f575e5f58a4d4285377f9f6d0807573da90e44 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 11:51:28 -0600
Subject: [PATCH 1/3] [lldb-dap] Refactor breakpoint related request handlers
 (NFC)

---
 lldb/tools/lldb-dap/CMakeLists.txt|   7 +-
 .../DataBreakpointInfoRequestHandler.cpp  | 190 
 .../tools/lldb-dap/Handler/RequestHandler.cpp |  55 ++
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  47 +
 .../Handler/SetBreakpointsRequestHandler.cpp  | 182 
 .../SetDataBreakpointsRequestHandler.cpp  | 114 +++
 .../SetExceptionBreakpointsRequestHandler.cpp |  93 ++
 .../SetFunctionBreakpointsRequestHandler.cpp  | 139 +++
 ...etInstructionBreakpointsRequestHandler.cpp | 249 +
 lldb/tools/lldb-dap/lldb-dap.cpp  | 880 +-
 10 files changed, 1081 insertions(+), 875 deletions(-)
 create mode 100644 
lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 688a2e448f71d..c04b10861a4c5 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -43,6 +43,7 @@ add_lldb_tool(lldb-dap
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
+  Handler/DataBreakpointInfoRequestHandler.cpp
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
@@ -52,10 +53,14 @@ add_lldb_tool(lldb-dap
   Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/SetBreakpointsRequestHandler.cpp
+  Handler/SetDataBreakpointsRequestHandler.cpp
+  Handler/SetExceptionBreakpointsRequestHandler.cpp
+  Handler/SetFunctionBreakpointsRequestHandler.cpp
+  Handler/SetInstructionBreakpointsRequestHandler.cpp 
Handler/StepOutRequestHandler.cpp
   Handler/StepInRequestHandler.cpp
   Handler/StepInTargetsRequestHandler.cpp
   Handler/TestGetTargetBreakpointsRequestHandler.cpp
-  Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
new file mode 100644
index 0..519a9c728e4b3
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
@@ -0,0 +1,190 @@
+//===-- DataBreakpointInfoRequestHandler.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+
+namespace lldb_dap {
+
+// "DataBreakpointInfoRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Obtains information on a possible data breakpoint that
+// could be set on an expression or variable.\nClients should only call 
this
+// request if the corresponding capability `supportsDataBreakpoints` is
+// true.", "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "dataBreakpointInfo" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/DataBreakpointInfoArguments"
+//   }
+// },
+// "required": [ "command", "arguments"  ]
+//   }]
+// },
+// "DataBreakpointInfoArguments": {
+//   "type": "object",
+//   "description": "Arguments for `dataBreakpointInfo` request.",
+//   "properties": {
+// "variablesReference": {
+//   "type": "integer",
+//   "description": "Reference to the variable container if the data
+//   breakpoint is requested for a child of the container. The
+//   `variablesReference` must have been obtained in the current suspended
+//   state. See 'Lifetime of Object References' in the Overview section for
+//   details."
+// },
+// "name": {
+//   "type": "string",
+//   "description": "The name of the variable's child to obtain data
+//   breakpoint information for.\nIf `variablesReference` isn't specified,
+//   this can be an expression."
+/

[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

>From 95f575e5f58a4d4285377f9f6d0807573da90e44 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 11:51:28 -0600
Subject: [PATCH 1/2] [lldb-dap] Refactor breakpoint related request handlers
 (NFC)

---
 lldb/tools/lldb-dap/CMakeLists.txt|   7 +-
 .../DataBreakpointInfoRequestHandler.cpp  | 190 
 .../tools/lldb-dap/Handler/RequestHandler.cpp |  55 ++
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  47 +
 .../Handler/SetBreakpointsRequestHandler.cpp  | 182 
 .../SetDataBreakpointsRequestHandler.cpp  | 114 +++
 .../SetExceptionBreakpointsRequestHandler.cpp |  93 ++
 .../SetFunctionBreakpointsRequestHandler.cpp  | 139 +++
 ...etInstructionBreakpointsRequestHandler.cpp | 249 +
 lldb/tools/lldb-dap/lldb-dap.cpp  | 880 +-
 10 files changed, 1081 insertions(+), 875 deletions(-)
 create mode 100644 
lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 688a2e448f71d..c04b10861a4c5 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -43,6 +43,7 @@ add_lldb_tool(lldb-dap
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
+  Handler/DataBreakpointInfoRequestHandler.cpp
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
@@ -52,10 +53,14 @@ add_lldb_tool(lldb-dap
   Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/SetBreakpointsRequestHandler.cpp
+  Handler/SetDataBreakpointsRequestHandler.cpp
+  Handler/SetExceptionBreakpointsRequestHandler.cpp
+  Handler/SetFunctionBreakpointsRequestHandler.cpp
+  Handler/SetInstructionBreakpointsRequestHandler.cpp 
Handler/StepOutRequestHandler.cpp
   Handler/StepInRequestHandler.cpp
   Handler/StepInTargetsRequestHandler.cpp
   Handler/TestGetTargetBreakpointsRequestHandler.cpp
-  Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
new file mode 100644
index 0..519a9c728e4b3
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
@@ -0,0 +1,190 @@
+//===-- DataBreakpointInfoRequestHandler.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+
+namespace lldb_dap {
+
+// "DataBreakpointInfoRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Obtains information on a possible data breakpoint that
+// could be set on an expression or variable.\nClients should only call 
this
+// request if the corresponding capability `supportsDataBreakpoints` is
+// true.", "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "dataBreakpointInfo" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/DataBreakpointInfoArguments"
+//   }
+// },
+// "required": [ "command", "arguments"  ]
+//   }]
+// },
+// "DataBreakpointInfoArguments": {
+//   "type": "object",
+//   "description": "Arguments for `dataBreakpointInfo` request.",
+//   "properties": {
+// "variablesReference": {
+//   "type": "integer",
+//   "description": "Reference to the variable container if the data
+//   breakpoint is requested for a child of the container. The
+//   `variablesReference` must have been obtained in the current suspended
+//   state. See 'Lifetime of Object References' in the Overview section for
+//   details."
+// },
+// "name": {
+//   "type": "string",
+//   "description": "The name of the variable's child to obtain data
+//   breakpoint information for.\nIf `variablesReference` isn't specified,
+//   this can be an expression."
+/

[Lldb-commits] [lldb] [LLDB][Telemetry]Define TargetInfo for collecting data about a target (PR #127834)

2025-02-24 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Refactor remaining request handlers (NFC)Remaining request handlers (PR #128551)

2025-02-24 Thread John Harrison via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread John Harrison via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread John Harrison via lldb-commits


@@ -30,6 +30,7 @@ class RequestHandler {
 
   virtual void operator()(const llvm::json::Object &request) = 0;

ashgti wrote:

Should we also mark this `const`? I don't think any of the request handlers are 
using any state at the moment.

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


[Lldb-commits] [lldb] [llvm] [llvm][telemetry]Change Telemetry-disabling mechanism. (PR #128534)

2025-02-24 Thread Vy Nguyen via lldb-commits

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

>From 236ab76b7c9433f8fed6586a4ee18351779cc191 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 24 Feb 2025 11:32:03 -0500
Subject: [PATCH 1/2] [llvm][telemetr]Change Telemetry-disabling mechanism.

Details:
- Previously, we used the LLVM_BUILD_TELEMETRY flag to control whether any 
Telemetry code will be built.
This has proven to cause more nuisance to both users of the Telemetry and any 
further extension of it.
(Eg., we needed to put #ifdef around caller/user code)

- So the new approach is to:
 + Remove this flag and introduce LLVM_ENABLE_TELEMETRY which would be true by 
default.
 + If LLVM_ENABLE_TELEMETRY is set to FALSE (at buildtime), the library would 
still be built BUT Telemetry cannot be enabled.
   And no data can be collected.

The benefit of this is that it simplifies user (and extension) code since we 
just need to put the check on Config::EnableTelemetry.
Besides, the Telemetry library itself is very small, hence the additional code 
to be built would not cause any difference in build performance.
---
 lldb/source/Core/CMakeLists.txt  |  4 +---
 lldb/source/Core/Telemetry.cpp   |  7 ++-
 lldb/unittests/Core/CMakeLists.txt   |  6 +++---
 llvm/CMakeLists.txt  |  3 ++-
 llvm/cmake/modules/LLVMConfig.cmake.in   |  1 +
 llvm/include/llvm/Config/llvm-config.h.cmake |  2 ++
 llvm/include/llvm/Telemetry/Telemetry.h  | 12 ++--
 llvm/lib/CMakeLists.txt  |  5 ++---
 llvm/unittests/CMakeLists.txt|  4 +---
 .../gn/secondary/llvm/include/llvm/Config/BUILD.gn   |  1 +
 utils/bazel/llvm_configs/llvm-config.h.cmake |  2 ++
 11 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 82fb5f42f9f4b..a3c12e4c1bdbc 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -16,9 +16,7 @@ if (LLDB_ENABLE_CURSES)
   endif()
 endif()
 
-if (LLVM_BUILD_TELEMETRY)
-   set(TELEMETRY_DEPS Telemetry)
-endif()
+set(TELEMETRY_DEPS Telemetry)
 
 # TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
 add_lldb_library(lldbCore
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..51a860ea5313b 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -8,8 +8,6 @@
 
 #include "llvm/Config/llvm-config.h"
 
-#ifdef LLVM_BUILD_TELEMETRY
-
 #include "lldb/Core/Telemetry.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -57,7 +55,8 @@ void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) 
const {
 }
 
 TelemetryManager::TelemetryManager(std::unique_ptr config)
-: m_config(std::move(config)) {}
+: m_config(std::move(config))
+}
 
 llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
   // Do nothing for now.
@@ -75,5 +74,3 @@ void 
TelemetryManager::setInstance(std::unique_ptr manager) {
 
 } // namespace telemetry
 } // namespace lldb_private
-
-#endif // LLVM_BUILD_TELEMETRY
diff --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index d4d3764b67ae3..e8df299631e2e 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -1,6 +1,6 @@
-if (LLVM_BUILD_TELEMETRY)
-  set(TELEMETRY_DEPS Telemetry)
-endif()
+
+set(TELEMETRY_DEPS Telemetry)
+
 
 add_lldb_unittest(LLDBCoreTests
   CommunicationTest.cpp
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 88512d0f1dd96..9188fb93b7846 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -835,7 +835,8 @@ option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm 
API documentation." OF
 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
 option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
 option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
-option (LLVM_BUILD_TELEMETRY "Build the telemetry library. This does not 
enable telemetry." ON)
+option (LLVM_BUILD_TELEMETRY "[DEPRECATED - use LLVM_ENABLE_TELEMTRY]Enable 
the telemetry library. If set to OFF, library cannot be enabled after build 
(eg., at runtime)" ON)
+option (LLVM_ENABLE_TELEMETRY "Enable the telemetry library. If set to OFF, 
library cannot be enabled after build (eg., at runtime)" ON)
 
 set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html"
 CACHE STRING "Doxygen-generated HTML documentation install directory")
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in 
b/llvm/cmake/modules/LLVMConfig.cmake.in
index 28655ee3ab87d..134d107ce79ba 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -101,6 +101,7 @@ set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
 set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@)
 
 set(LLVM_BUILD_TELEMETRY @LLVM_B

[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread Jonas Devlieghere via lldb-commits


@@ -799,21 +788,40 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
 
   EmplaceSafeString(object, "name", frame_name);
 
-  auto source = CreateSource(frame);
-
-  if (source) {
-object.try_emplace("source", *source);
-auto line_entry = frame.GetLineEntry();
-auto line = line_entry.GetLine();
-if (line && line != LLDB_INVALID_LINE_NUMBER)
-  object.try_emplace("line", line);
-else
-  object.try_emplace("line", 0);
+  auto line_entry = frame.GetLineEntry();
+  // A line entry of 0 indicates the line is compiler generated i.e. no source
+  // file is associated with the frame.
+  if (line_entry.GetFileSpec().IsValid() &&
+  (line_entry.GetLine() != 0 ||
+   line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) {
+object.try_emplace("source", CreateSource(line_entry));
+object.try_emplace("line", line_entry.GetLine());
 auto column = line_entry.GetColumn();
 object.try_emplace("column", column);
-  } else {
-object.try_emplace("line", 0);
-object.try_emplace("column", 0);
+  } else if (frame.GetSymbol().IsValid()) {
+// If no source is associated with the frame, use the DAPFrameID to track
+// the 'source' and generate assembly.
+llvm::json::Object source;
+EmplaceSafeString(source, "name", frame_name);
+char buf[PATH_MAX] = {0};
+size_t size = frame.GetModule().GetFileSpec().GetPath(buf, PATH_MAX);
+EmplaceSafeString(source, "path",
+  std::string(buf, size) + '`' + frame_name);
+source.try_emplace("sourceReference", MakeDAPFrameID(frame));
+// Markthe source as deemphasized since users will only be able to view
+// assembly for these frames.

JDevlieghere wrote:

```suggestion
// Mark the source as deemphasized since users will only be able to view
// assembly for these frames.
```

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


[Lldb-commits] [lldb] [llvm] [llvm][telemetry]Change Telemetry-disabling mechanism. (PR #128534)

2025-02-24 Thread Vy Nguyen via lldb-commits

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

>From 236ab76b7c9433f8fed6586a4ee18351779cc191 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 24 Feb 2025 11:32:03 -0500
Subject: [PATCH 1/3] [llvm][telemetr]Change Telemetry-disabling mechanism.

Details:
- Previously, we used the LLVM_BUILD_TELEMETRY flag to control whether any 
Telemetry code will be built.
This has proven to cause more nuisance to both users of the Telemetry and any 
further extension of it.
(Eg., we needed to put #ifdef around caller/user code)

- So the new approach is to:
 + Remove this flag and introduce LLVM_ENABLE_TELEMETRY which would be true by 
default.
 + If LLVM_ENABLE_TELEMETRY is set to FALSE (at buildtime), the library would 
still be built BUT Telemetry cannot be enabled.
   And no data can be collected.

The benefit of this is that it simplifies user (and extension) code since we 
just need to put the check on Config::EnableTelemetry.
Besides, the Telemetry library itself is very small, hence the additional code 
to be built would not cause any difference in build performance.
---
 lldb/source/Core/CMakeLists.txt  |  4 +---
 lldb/source/Core/Telemetry.cpp   |  7 ++-
 lldb/unittests/Core/CMakeLists.txt   |  6 +++---
 llvm/CMakeLists.txt  |  3 ++-
 llvm/cmake/modules/LLVMConfig.cmake.in   |  1 +
 llvm/include/llvm/Config/llvm-config.h.cmake |  2 ++
 llvm/include/llvm/Telemetry/Telemetry.h  | 12 ++--
 llvm/lib/CMakeLists.txt  |  5 ++---
 llvm/unittests/CMakeLists.txt|  4 +---
 .../gn/secondary/llvm/include/llvm/Config/BUILD.gn   |  1 +
 utils/bazel/llvm_configs/llvm-config.h.cmake |  2 ++
 11 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 82fb5f42f9f4b..a3c12e4c1bdbc 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -16,9 +16,7 @@ if (LLDB_ENABLE_CURSES)
   endif()
 endif()
 
-if (LLVM_BUILD_TELEMETRY)
-   set(TELEMETRY_DEPS Telemetry)
-endif()
+set(TELEMETRY_DEPS Telemetry)
 
 # TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
 add_lldb_library(lldbCore
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..51a860ea5313b 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -8,8 +8,6 @@
 
 #include "llvm/Config/llvm-config.h"
 
-#ifdef LLVM_BUILD_TELEMETRY
-
 #include "lldb/Core/Telemetry.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Utility/LLDBLog.h"
@@ -57,7 +55,8 @@ void LLDBBaseTelemetryInfo::serialize(Serializer &serializer) 
const {
 }
 
 TelemetryManager::TelemetryManager(std::unique_ptr config)
-: m_config(std::move(config)) {}
+: m_config(std::move(config))
+}
 
 llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
   // Do nothing for now.
@@ -75,5 +74,3 @@ void 
TelemetryManager::setInstance(std::unique_ptr manager) {
 
 } // namespace telemetry
 } // namespace lldb_private
-
-#endif // LLVM_BUILD_TELEMETRY
diff --git a/lldb/unittests/Core/CMakeLists.txt 
b/lldb/unittests/Core/CMakeLists.txt
index d4d3764b67ae3..e8df299631e2e 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -1,6 +1,6 @@
-if (LLVM_BUILD_TELEMETRY)
-  set(TELEMETRY_DEPS Telemetry)
-endif()
+
+set(TELEMETRY_DEPS Telemetry)
+
 
 add_lldb_unittest(LLDBCoreTests
   CommunicationTest.cpp
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 88512d0f1dd96..9188fb93b7846 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -835,7 +835,8 @@ option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm 
API documentation." OF
 option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
 option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
 option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
-option (LLVM_BUILD_TELEMETRY "Build the telemetry library. This does not 
enable telemetry." ON)
+option (LLVM_BUILD_TELEMETRY "[DEPRECATED - use LLVM_ENABLE_TELEMTRY]Enable 
the telemetry library. If set to OFF, library cannot be enabled after build 
(eg., at runtime)" ON)
+option (LLVM_ENABLE_TELEMETRY "Enable the telemetry library. If set to OFF, 
library cannot be enabled after build (eg., at runtime)" ON)
 
 set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html"
 CACHE STRING "Doxygen-generated HTML documentation install directory")
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in 
b/llvm/cmake/modules/LLVMConfig.cmake.in
index 28655ee3ab87d..134d107ce79ba 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -101,6 +101,7 @@ set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
 set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@)
 
 set(LLVM_BUILD_TELEMETRY @LLVM_B

[Lldb-commits] [lldb] [lldb] Avoid Function::GetAddressRange in ThreadPlanStepRange::InSymbol (PR #128515)

2025-02-24 Thread via lldb-commits

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

LGMT

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

2025-02-24 Thread Vy Nguyen via lldb-commits

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

>From 24e9f78744f98ecf3ac01f1f719f1eac9b3479f0 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 18 Feb 2025 15:58:08 -0500
Subject: [PATCH 1/5] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related
 methods

- This type of entry is used to collect data about the debugger startup/exit
- Tests will be added (They may need to be shell test with a "test-only" 
TelemetryManager plugin defined. I'm trying to figure out how to get that 
linked only when tests are running and not to the LLDB binary all the time.
---
 lldb/include/lldb/Core/Telemetry.h |  78 +++
 lldb/source/Core/Debugger.cpp  |  40 ++
 lldb/source/Core/Telemetry.cpp | 115 +
 3 files changed, 220 insertions(+), 13 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..d6eec5dc687be 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -13,6 +13,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
@@ -29,6 +30,9 @@ namespace telemetry {
 
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b11000;
+  static const llvm::telemetry::KindType DebuggerInfo = 0b11001;
+  // There are other entries in between (added in separate PRs)
+  static const llvm::telemetry::KindType MiscInfo = 0b0;
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -56,6 +60,71 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {
+  std::string username;
+  std::string lldb_git_sha;
+  std::string lldb_path;
+  std::string cwd;
+  std::optional exit_desc;
+
+  DebuggerTelemetryInfo() = default;
+
+  // Provide a copy ctor because we may need to make a copy before
+  // sanitizing the data.
+  // (The sanitization might differ between different Destination classes).
+  DebuggerTelemetryInfo(const DebuggerTelemetryInfo &other) {
+username = other.username;
+lldb_git_sha = other.lldb_git_sha;
+lldb_path = other.lldb_path;
+cwd = other.cwd;
+  };
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::DebuggerInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::DebuggerInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// The "catch-all" entry to store a set of non-standard data, such as
+/// error-messages, etc.
+struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo {
+  /// If the event is/can be associated with a target entry,
+  /// this field contains that target's UUID.
+  ///  otherwise.
+  std::string target_uuid;
+
+  /// Set of key-value pairs for any optional (or impl-specific) data
+  std::map meta_data;
+
+  MiscTelemetryInfo() = default;
+
+  MiscTelemetryInfo(const MiscTelemetryInfo &other) {
+target_uuid = other.target_uuid;
+meta_data = other.meta_data;
+  }
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::MiscInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::MiscInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
 /// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
@@ -63,6 +132,11 @@ class TelemetryManager : public llvm::telemetry::Manager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
+  const llvm::telemetry::Config *getConfig();
+
+  void atDebuggerStartup(DebuggerTelemetryInfo *entry);
+  void atDebuggerExit(DebuggerTelemetryInfo *entry);
+
   virtual llvm::StringRef GetInstanceName() const = 0;
   static TelemetryManager *getInstance();
 
@@ -73,6 +147,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;
   static std::unique_ptr g_instance;
 };
 
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 18569e155b517..b458abc798a9e 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -62,6 +62,7 @@
 

[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

LGTM!

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

https://github.com/kastiglione created 
https://github.com/llvm/llvm-project/pull/128571

None

>From 57638e91c97486ad7739f9658fe88f7fb4d61fb2 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:48:17 -0800
Subject: [PATCH] [lldb] Add fzf_history command to examples

---
 lldb/examples/python/fzf_history.py | 99 +
 1 file changed, 99 insertions(+)
 create mode 100644 lldb/examples/python/fzf_history.py

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
new file mode 100644
index 0..4647a3532b0df
--- /dev/null
+++ b/lldb/examples/python/fzf_history.py
@@ -0,0 +1,99 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+if sys.platform != 'darwin':
+result.SetError("fzf_history supports macOS only")
+return
+
+# Capture the current pasteboard contents to restore after overwriting.
+paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+
+# On enter, copy the selected history entry into the pasteboard.
+fzf_command = (
+"fzf",
+"--no-sort",
+f"--query={cmdstr}",
+"--bind=enter:execute-silent(echo -n {} | pbcopy)+close",
+)
+
+history_file = os.path.expanduser("~/.lldb/lldb-widehistory")
+if not os.path.exists(history_file):
+result.SetError("history file does not exist")
+return
+
+history_commands = _load_history(history_file)
+fzf_input = "\n".join(history_commands)
+completed = subprocess.run(fzf_command, input=fzf_input, text=True)
+# 130 is used for CTRL-C or ESC.
+if completed.returncode not in (0, 130):
+result.SetError(f"fzf failed: {completed.stderr}")
+return
+
+# Get the user's selected history entry.
+selected_command = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+if selected_command == paste_snapshot:
+# Nothing was selected, no cleanup needed.
+return
+
+_handle_command(debugger, selected_command)
+
+# Restore the pasteboard's contents.
+subprocess.run("pbcopy", input=paste_snapshot, text=True)
+
+
+def _handle_command(debugger, command):
+"""Try pasting the command, and failing that, run it directly."""
+if not command:
+return
+
+# Use applescript to paste the selected result into lldb's console.
+paste_command = (
+"osascript",
+"-e",
+'tell application "System Events" to keystroke "v" using command down',
+)
+completed = subprocess.run(paste_command, capture_output=True)
+
+if completed.returncode != 0:
+# The above applescript requires the "control your computer" 
permission.
+# Settings > Private & Security > Accessibility
+# If not enabled, fallback to running the command.
+debugger.HandleCommand(command)
+
+
+def _load_history(history_file):
+"""Load, decode, and parse an lldb history file."""
+with open(history_file) as f:
+history_contents = f.read()
+
+history_decoded = re.sub(r"\\0([0-7][0-7])", _decode_char, 
history_contents)
+history_lines = history_decoded.splitlines()
+
+# Skip the header line (_HiStOrY_V2_)
+del history_lines[0]
+# Reverse to show latest first.
+history_lines.reverse()
+
+history_commands = []
+history_seen = set()
+for line in history_lines:
+line = line.strip()
+# Skip empty lines, single character commands, and duplicates.
+if line and len(line) > 1 and line not in history_seen:
+history_commands.append(line)
+history_seen.add(line)
+
+return history_commands
+
+
+def _decode_char(match):
+"""Decode octal strings ('\0NN') into a single character string."""
+code = int(match.group(1), base=8)
+return chr(code)

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dave Lee (kastiglione)


Changes



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


1 Files Affected:

- (added) lldb/examples/python/fzf_history.py (+99) 


``diff
diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
new file mode 100644
index 0..4647a3532b0df
--- /dev/null
+++ b/lldb/examples/python/fzf_history.py
@@ -0,0 +1,99 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+if sys.platform != 'darwin':
+result.SetError("fzf_history supports macOS only")
+return
+
+# Capture the current pasteboard contents to restore after overwriting.
+paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+
+# On enter, copy the selected history entry into the pasteboard.
+fzf_command = (
+"fzf",
+"--no-sort",
+f"--query={cmdstr}",
+"--bind=enter:execute-silent(echo -n {} | pbcopy)+close",
+)
+
+history_file = os.path.expanduser("~/.lldb/lldb-widehistory")
+if not os.path.exists(history_file):
+result.SetError("history file does not exist")
+return
+
+history_commands = _load_history(history_file)
+fzf_input = "\n".join(history_commands)
+completed = subprocess.run(fzf_command, input=fzf_input, text=True)
+# 130 is used for CTRL-C or ESC.
+if completed.returncode not in (0, 130):
+result.SetError(f"fzf failed: {completed.stderr}")
+return
+
+# Get the user's selected history entry.
+selected_command = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+if selected_command == paste_snapshot:
+# Nothing was selected, no cleanup needed.
+return
+
+_handle_command(debugger, selected_command)
+
+# Restore the pasteboard's contents.
+subprocess.run("pbcopy", input=paste_snapshot, text=True)
+
+
+def _handle_command(debugger, command):
+"""Try pasting the command, and failing that, run it directly."""
+if not command:
+return
+
+# Use applescript to paste the selected result into lldb's console.
+paste_command = (
+"osascript",
+"-e",
+'tell application "System Events" to keystroke "v" using command down',
+)
+completed = subprocess.run(paste_command, capture_output=True)
+
+if completed.returncode != 0:
+# The above applescript requires the "control your computer" 
permission.
+# Settings > Private & Security > Accessibility
+# If not enabled, fallback to running the command.
+debugger.HandleCommand(command)
+
+
+def _load_history(history_file):
+"""Load, decode, and parse an lldb history file."""
+with open(history_file) as f:
+history_contents = f.read()
+
+history_decoded = re.sub(r"\\0([0-7][0-7])", _decode_char, 
history_contents)
+history_lines = history_decoded.splitlines()
+
+# Skip the header line (_HiStOrY_V2_)
+del history_lines[0]
+# Reverse to show latest first.
+history_lines.reverse()
+
+history_commands = []
+history_seen = set()
+for line in history_lines:
+line = line.strip()
+# Skip empty lines, single character commands, and duplicates.
+if line and len(line) > 1 and line not in history_seen:
+history_commands.append(line)
+history_seen.add(line)
+
+return history_commands
+
+
+def _decode_char(match):
+"""Decode octal strings ('\0NN') into a single character string."""
+code = int(match.group(1), base=8)
+return chr(code)

``




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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
b335d5a8303250cb49901ecae7570adf61abbd3c...57638e91c97486ad7739f9658fe88f7fb4d61fb2
 lldb/examples/python/fzf_history.py
``





View the diff from darker here.


``diff
--- fzf_history.py  2025-02-24 20:48:36.00 +
+++ fzf_history.py  2025-02-24 20:51:35.934110 +
@@ -6,11 +6,11 @@
 import lldb
 
 
 @lldb.command()
 def fzf_history(debugger, cmdstr, ctx, result, _):
-if sys.platform != 'darwin':
+if sys.platform != "darwin":
 result.SetError("fzf_history supports macOS only")
 return
 
 # Capture the current pasteboard contents to restore after overwriting.
 paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout

``




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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][NFC]Renaming functions to be consistent with LLDB naming style (PR #128574)

2025-02-24 Thread Vy Nguyen via lldb-commits

https://github.com/oontvoo created 
https://github.com/llvm/llvm-project/pull/128574

None

>From a6ce60e61271aa2b57b8bc51bb1b0e0cd5896f68 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Mon, 24 Feb 2025 15:53:36 -0500
Subject: [PATCH] [LLDB][NFC]Renaming functions to be consistent with LLDB
 naming style

---
 lldb/include/lldb/Core/Telemetry.h| 4 ++--
 lldb/source/Core/Telemetry.cpp| 4 ++--
 lldb/unittests/Core/TelemetryTest.cpp | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..3bf38dac04c3d 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -64,12 +64,12 @@ class TelemetryManager : public llvm::telemetry::Manager {
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
   virtual llvm::StringRef GetInstanceName() const = 0;
-  static TelemetryManager *getInstance();
+  static TelemetryManager *GetInstance();
 
 protected:
   TelemetryManager(std::unique_ptr config);
 
-  static void setInstance(std::unique_ptr manger);
+  static void SetInstance(std::unique_ptr manger);
 
 private:
   std::unique_ptr m_config;
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..a0c9fb83e3a6b 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -67,9 +67,9 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo 
*entry) {
 }
 
 std::unique_ptr TelemetryManager::g_instance = nullptr;
-TelemetryManager *TelemetryManager::getInstance() { return g_instance.get(); }
+TelemetryManager *TelemetryManager::GetInstance() { return g_instance.get(); }
 
-void TelemetryManager::setInstance(std::unique_ptr manager) {
+void TelemetryManager::SetInstance(std::unique_ptr manager) {
   g_instance = std::move(manager);
 }
 
diff --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
index 0f2eaccb21a2c..3ee6451429619 100644
--- a/lldb/unittests/Core/TelemetryTest.cpp
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -63,10 +63,10 @@ class FakePlugin : public telemetry::TelemetryManager {
   }
 
   static void Initialize() {
-telemetry::TelemetryManager::setInstance(std::make_unique());
+telemetry::TelemetryManager::SetInstance(std::make_unique());
   }
 
-  static void Terminate() { telemetry::TelemetryManager::setInstance(nullptr); 
}
+  static void Terminate() { telemetry::TelemetryManager::SetInstance(nullptr); 
}
 };
 
 } // namespace lldb_private
@@ -76,7 +76,7 @@ TEST(TelemetryTest, PluginTest) {
   // For tests, we just call it directly.
   lldb_private::FakePlugin::Initialize();
 
-  auto *ins = lldb_private::telemetry::TelemetryManager::getInstance();
+  auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance();
   ASSERT_NE(ins, nullptr);
 
   std::vector expected_entries;

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


[Lldb-commits] [lldb] [LLDB][NFC]Renaming functions to be consistent with LLDB naming style (PR #128574)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vy Nguyen (oontvoo)


Changes



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


3 Files Affected:

- (modified) lldb/include/lldb/Core/Telemetry.h (+2-2) 
- (modified) lldb/source/Core/Telemetry.cpp (+2-2) 
- (modified) lldb/unittests/Core/TelemetryTest.cpp (+3-3) 


``diff
diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..3bf38dac04c3d 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -64,12 +64,12 @@ class TelemetryManager : public llvm::telemetry::Manager {
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
   virtual llvm::StringRef GetInstanceName() const = 0;
-  static TelemetryManager *getInstance();
+  static TelemetryManager *GetInstance();
 
 protected:
   TelemetryManager(std::unique_ptr config);
 
-  static void setInstance(std::unique_ptr manger);
+  static void SetInstance(std::unique_ptr manger);
 
 private:
   std::unique_ptr m_config;
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..a0c9fb83e3a6b 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -67,9 +67,9 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo 
*entry) {
 }
 
 std::unique_ptr TelemetryManager::g_instance = nullptr;
-TelemetryManager *TelemetryManager::getInstance() { return g_instance.get(); }
+TelemetryManager *TelemetryManager::GetInstance() { return g_instance.get(); }
 
-void TelemetryManager::setInstance(std::unique_ptr manager) {
+void TelemetryManager::SetInstance(std::unique_ptr manager) {
   g_instance = std::move(manager);
 }
 
diff --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
index 0f2eaccb21a2c..3ee6451429619 100644
--- a/lldb/unittests/Core/TelemetryTest.cpp
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -63,10 +63,10 @@ class FakePlugin : public telemetry::TelemetryManager {
   }
 
   static void Initialize() {
-telemetry::TelemetryManager::setInstance(std::make_unique());
+telemetry::TelemetryManager::SetInstance(std::make_unique());
   }
 
-  static void Terminate() { telemetry::TelemetryManager::setInstance(nullptr); 
}
+  static void Terminate() { telemetry::TelemetryManager::SetInstance(nullptr); 
}
 };
 
 } // namespace lldb_private
@@ -76,7 +76,7 @@ TEST(TelemetryTest, PluginTest) {
   // For tests, we just call it directly.
   lldb_private::FakePlugin::Initialize();
 
-  auto *ins = lldb_private::telemetry::TelemetryManager::getInstance();
+  auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance();
   ASSERT_NE(ins, nullptr);
 
   std::vector expected_entries;

``




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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/128571

>From 57638e91c97486ad7739f9658fe88f7fb4d61fb2 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:48:17 -0800
Subject: [PATCH 1/2] [lldb] Add fzf_history command to examples

---
 lldb/examples/python/fzf_history.py | 99 +
 1 file changed, 99 insertions(+)
 create mode 100644 lldb/examples/python/fzf_history.py

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
new file mode 100644
index 0..4647a3532b0df
--- /dev/null
+++ b/lldb/examples/python/fzf_history.py
@@ -0,0 +1,99 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+if sys.platform != 'darwin':
+result.SetError("fzf_history supports macOS only")
+return
+
+# Capture the current pasteboard contents to restore after overwriting.
+paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+
+# On enter, copy the selected history entry into the pasteboard.
+fzf_command = (
+"fzf",
+"--no-sort",
+f"--query={cmdstr}",
+"--bind=enter:execute-silent(echo -n {} | pbcopy)+close",
+)
+
+history_file = os.path.expanduser("~/.lldb/lldb-widehistory")
+if not os.path.exists(history_file):
+result.SetError("history file does not exist")
+return
+
+history_commands = _load_history(history_file)
+fzf_input = "\n".join(history_commands)
+completed = subprocess.run(fzf_command, input=fzf_input, text=True)
+# 130 is used for CTRL-C or ESC.
+if completed.returncode not in (0, 130):
+result.SetError(f"fzf failed: {completed.stderr}")
+return
+
+# Get the user's selected history entry.
+selected_command = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+if selected_command == paste_snapshot:
+# Nothing was selected, no cleanup needed.
+return
+
+_handle_command(debugger, selected_command)
+
+# Restore the pasteboard's contents.
+subprocess.run("pbcopy", input=paste_snapshot, text=True)
+
+
+def _handle_command(debugger, command):
+"""Try pasting the command, and failing that, run it directly."""
+if not command:
+return
+
+# Use applescript to paste the selected result into lldb's console.
+paste_command = (
+"osascript",
+"-e",
+'tell application "System Events" to keystroke "v" using command down',
+)
+completed = subprocess.run(paste_command, capture_output=True)
+
+if completed.returncode != 0:
+# The above applescript requires the "control your computer" 
permission.
+# Settings > Private & Security > Accessibility
+# If not enabled, fallback to running the command.
+debugger.HandleCommand(command)
+
+
+def _load_history(history_file):
+"""Load, decode, and parse an lldb history file."""
+with open(history_file) as f:
+history_contents = f.read()
+
+history_decoded = re.sub(r"\\0([0-7][0-7])", _decode_char, 
history_contents)
+history_lines = history_decoded.splitlines()
+
+# Skip the header line (_HiStOrY_V2_)
+del history_lines[0]
+# Reverse to show latest first.
+history_lines.reverse()
+
+history_commands = []
+history_seen = set()
+for line in history_lines:
+line = line.strip()
+# Skip empty lines, single character commands, and duplicates.
+if line and len(line) > 1 and line not in history_seen:
+history_commands.append(line)
+history_seen.add(line)
+
+return history_commands
+
+
+def _decode_char(match):
+"""Decode octal strings ('\0NN') into a single character string."""
+code = int(match.group(1), base=8)
+return chr(code)

>From d1106bc7165d8a62a1805ec09afdf62e5b7f09ff Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:56:35 -0800
Subject: [PATCH 2/2] Fix code formatting

---
 lldb/examples/python/fzf_history.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index 4647a3532b0df..b683078465985 100644
--- a/lldb/examples/python/fzf_history.py
+++ b/lldb/examples/python/fzf_history.py
@@ -8,7 +8,7 @@
 
 @lldb.command()
 def fzf_history(debugger, cmdstr, ctx, result, _):
-if sys.platform != 'darwin':
+if sys.platform != "darwin":
 result.SetError("fzf_history supports macOS only")
 return
 

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/128571

>From 57638e91c97486ad7739f9658fe88f7fb4d61fb2 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:48:17 -0800
Subject: [PATCH 1/3] [lldb] Add fzf_history command to examples

---
 lldb/examples/python/fzf_history.py | 99 +
 1 file changed, 99 insertions(+)
 create mode 100644 lldb/examples/python/fzf_history.py

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
new file mode 100644
index 0..4647a3532b0df
--- /dev/null
+++ b/lldb/examples/python/fzf_history.py
@@ -0,0 +1,99 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+if sys.platform != 'darwin':
+result.SetError("fzf_history supports macOS only")
+return
+
+# Capture the current pasteboard contents to restore after overwriting.
+paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+
+# On enter, copy the selected history entry into the pasteboard.
+fzf_command = (
+"fzf",
+"--no-sort",
+f"--query={cmdstr}",
+"--bind=enter:execute-silent(echo -n {} | pbcopy)+close",
+)
+
+history_file = os.path.expanduser("~/.lldb/lldb-widehistory")
+if not os.path.exists(history_file):
+result.SetError("history file does not exist")
+return
+
+history_commands = _load_history(history_file)
+fzf_input = "\n".join(history_commands)
+completed = subprocess.run(fzf_command, input=fzf_input, text=True)
+# 130 is used for CTRL-C or ESC.
+if completed.returncode not in (0, 130):
+result.SetError(f"fzf failed: {completed.stderr}")
+return
+
+# Get the user's selected history entry.
+selected_command = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+if selected_command == paste_snapshot:
+# Nothing was selected, no cleanup needed.
+return
+
+_handle_command(debugger, selected_command)
+
+# Restore the pasteboard's contents.
+subprocess.run("pbcopy", input=paste_snapshot, text=True)
+
+
+def _handle_command(debugger, command):
+"""Try pasting the command, and failing that, run it directly."""
+if not command:
+return
+
+# Use applescript to paste the selected result into lldb's console.
+paste_command = (
+"osascript",
+"-e",
+'tell application "System Events" to keystroke "v" using command down',
+)
+completed = subprocess.run(paste_command, capture_output=True)
+
+if completed.returncode != 0:
+# The above applescript requires the "control your computer" 
permission.
+# Settings > Private & Security > Accessibility
+# If not enabled, fallback to running the command.
+debugger.HandleCommand(command)
+
+
+def _load_history(history_file):
+"""Load, decode, and parse an lldb history file."""
+with open(history_file) as f:
+history_contents = f.read()
+
+history_decoded = re.sub(r"\\0([0-7][0-7])", _decode_char, 
history_contents)
+history_lines = history_decoded.splitlines()
+
+# Skip the header line (_HiStOrY_V2_)
+del history_lines[0]
+# Reverse to show latest first.
+history_lines.reverse()
+
+history_commands = []
+history_seen = set()
+for line in history_lines:
+line = line.strip()
+# Skip empty lines, single character commands, and duplicates.
+if line and len(line) > 1 and line not in history_seen:
+history_commands.append(line)
+history_seen.add(line)
+
+return history_commands
+
+
+def _decode_char(match):
+"""Decode octal strings ('\0NN') into a single character string."""
+code = int(match.group(1), base=8)
+return chr(code)

>From d1106bc7165d8a62a1805ec09afdf62e5b7f09ff Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:56:35 -0800
Subject: [PATCH 2/3] Fix code formatting

---
 lldb/examples/python/fzf_history.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index 4647a3532b0df..b683078465985 100644
--- a/lldb/examples/python/fzf_history.py
+++ b/lldb/examples/python/fzf_history.py
@@ -8,7 +8,7 @@
 
 @lldb.command()
 def fzf_history(debugger, cmdstr, ctx, result, _):
-if sys.platform != 'darwin':
+if sys.platform != "darwin":
 result.SetError("fzf_history supports macOS only")
 return
 

>From 7fb2bfc015e1550dde6f3d54e932e8bc6ccbe0f7 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:59:08 -0800
Subject: [PATCH 3/3] Add docstring for fzf_history

---
 lldb/examples/python/fzf_history.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index

[Lldb-commits] [lldb] [LLDB][Telemetry]Define TargetInfo for collecting data about a target (PR #127834)

2025-02-24 Thread Vy Nguyen via lldb-commits

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

>From 0d6a36d84df50ccb9eef9ef3dd6f59d4299edeac Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Wed, 19 Feb 2025 12:47:57 -0500
Subject: [PATCH 1/2] [LLDB][Telemetry]Define TargetInfo for collecting data
 about a target

---
 lldb/include/lldb/Core/Telemetry.h | 86 +-
 lldb/source/Core/Telemetry.cpp | 99 ++
 2 files changed, 170 insertions(+), 15 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..4be81951254de 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -13,6 +13,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
@@ -29,6 +30,9 @@ namespace telemetry {
 
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b11000;
+  static const KindType TargetInfo = 0b11010;
+  // There are other entries in between (added in separate PRs)
+  static const llvm::telemetry::KindType MiscInfo = 0b0;
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -56,14 +60,88 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct TargetTelemetryInfo : public LldbBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+  Target *target_ptr;
+
+  // The same as the executable-module's UUID.
+  std::string target_uuid;
+  std::string file_format;
+
+  std::string binary_path;
+  size_t binary_size;
+
+  std::optional exit_desc;
+  TargetTelemetryInfo() = default;
+
+  TargetTelemetryInfo(const TargetTelemetryInfo &other) {
+exec_mod = other.exec_mod;
+target_uuid = other.target_uuid;
+file_format = other.file_format;
+binary_path = other.binary_path;
+binary_size = other.binary_size;
+exit_desc = other.exit_desc;
+  }
+
+  KindType getKind() const override { return LldbEntryKind::TargetInfo; }
+
+  static bool classof(const TelemetryInfo *T) {
+if (T == nullptr)
+  return false;
+return T->getKind() == LldbEntryKind::TargetInfo;
+  }
+
+  void serialize(Serializer &serializer) const override;
+};
+
+/// The "catch-all" entry to store a set of non-standard data, such as
+/// error-messages, etc.
+struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo {
+  /// If the event is/can be associated with a target entry,
+  /// this field contains that target's UUID.
+  ///  otherwise.
+  std::string target_uuid;
+
+  /// Set of key-value pairs for any optional (or impl-specific) data
+  std::map meta_data;
+
+  MiscTelemetryInfo() = default;
+
+  MiscTelemetryInfo(const MiscTelemetryInfo &other) {
+target_uuid = other.target_uuid;
+meta_data = other.meta_data;
+  }
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::MiscInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::MiscInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
 /// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
-class TelemetryManager : public llvm::telemetry::Manager {
+class TelemetryMager : public llvm::telemetry::Manager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
-  virtual llvm::StringRef GetInstanceName() const = 0;
+  const llvm::telemetry::Config *getConfig();
+
+  virtual void AtMainExecutableLoadStart(TargetInfo * entry);
+  virtual void AtMainExecutableLoadEnd(TargetInfo *entry);
+
+  virtual llvm::StringRef GetInstanceName() const = 0;
   static TelemetryManager *getInstance();
 
 protected:
@@ -73,6 +151,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;
   static std::unique_ptr g_instance;
 };
 
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..da7aee01680fc 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -10,14 +10,20 @@
 
 #ifdef LLVM_BUILD_TELEMETRY
 
-#include "lldb/Core/Telemetry.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/Telemetry.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/Process.h"
+#include "lld

[Lldb-commits] [lldb] [LLDB][Telemetry]Define TargetInfo for collecting data about a target (PR #127834)

2025-02-24 Thread Vy Nguyen via lldb-commits

oontvoo wrote:

(This PR assumes that we can rely on PR/128534 - that is, we always build the 
telemetry library. Whether it is enabled is dictated by Config::EnableTelemetry)

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


[Lldb-commits] [lldb] [lldb-dap] Refactor stepping related request handlers (NFC) (PR #128453)

2025-02-24 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Refactor stepping related request handlers (NFC) (PR #128453)

2025-02-24 Thread John Harrison via lldb-commits


@@ -225,4 +225,11 @@ void RequestHandler::PrintWelcomeMessage() {
 #endif
 }
 
+bool RequestHandler::HasInstructionGranularity(
+const llvm::json::Object &request) {
+  if (std::optional value = request.getString("granularity"))
+return value == "instruction";
+  return false;
+}

ashgti wrote:

Can we change the name of the parameter to `arguments`?

We shouldn't check the request itself, but the arguments, e.g. the request 
would be formatted like:
```json
{
  "type": "request",
  "command": "next",
  "seq": 1,
  "arguments": {
"granularity": "instruction"
  }
}
```

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


[Lldb-commits] [lldb] [lldb-dap] Refactor stepping related request handlers (NFC) (PR #128453)

2025-02-24 Thread John Harrison via lldb-commits

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

LGTM, one change for clairty

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


[Lldb-commits] [lldb] [lldb-dap] Refactor stepping related request handlers (NFC) (PR #128453)

2025-02-24 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define TargetInfo for collecting data about a target (PR #127834)

2025-02-24 Thread Vy Nguyen via lldb-commits

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

>From 0d6a36d84df50ccb9eef9ef3dd6f59d4299edeac Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Wed, 19 Feb 2025 12:47:57 -0500
Subject: [PATCH] [LLDB][Telemetry]Define TargetInfo for collecting data about
 a target

---
 lldb/include/lldb/Core/Telemetry.h | 86 +-
 lldb/source/Core/Telemetry.cpp | 99 ++
 2 files changed, 170 insertions(+), 15 deletions(-)

diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..4be81951254de 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -13,6 +13,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Utility/StructuredData.h"
 #include "lldb/lldb-forward.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
@@ -29,6 +30,9 @@ namespace telemetry {
 
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b11000;
+  static const KindType TargetInfo = 0b11010;
+  // There are other entries in between (added in separate PRs)
+  static const llvm::telemetry::KindType MiscInfo = 0b0;
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -56,14 +60,88 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct TargetTelemetryInfo : public LldbBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+  Target *target_ptr;
+
+  // The same as the executable-module's UUID.
+  std::string target_uuid;
+  std::string file_format;
+
+  std::string binary_path;
+  size_t binary_size;
+
+  std::optional exit_desc;
+  TargetTelemetryInfo() = default;
+
+  TargetTelemetryInfo(const TargetTelemetryInfo &other) {
+exec_mod = other.exec_mod;
+target_uuid = other.target_uuid;
+file_format = other.file_format;
+binary_path = other.binary_path;
+binary_size = other.binary_size;
+exit_desc = other.exit_desc;
+  }
+
+  KindType getKind() const override { return LldbEntryKind::TargetInfo; }
+
+  static bool classof(const TelemetryInfo *T) {
+if (T == nullptr)
+  return false;
+return T->getKind() == LldbEntryKind::TargetInfo;
+  }
+
+  void serialize(Serializer &serializer) const override;
+};
+
+/// The "catch-all" entry to store a set of non-standard data, such as
+/// error-messages, etc.
+struct MiscTelemetryInfo : public LLDBBaseTelemetryInfo {
+  /// If the event is/can be associated with a target entry,
+  /// this field contains that target's UUID.
+  ///  otherwise.
+  std::string target_uuid;
+
+  /// Set of key-value pairs for any optional (or impl-specific) data
+  std::map meta_data;
+
+  MiscTelemetryInfo() = default;
+
+  MiscTelemetryInfo(const MiscTelemetryInfo &other) {
+target_uuid = other.target_uuid;
+meta_data = other.meta_data;
+  }
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::MiscInfo;
+  }
+
+  static bool classof(const llvm::telemetry::TelemetryInfo *T) {
+return T->getKind() == LLDBEntryKind::MiscInfo;
+  }
+
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
 /// The base Telemetry manager instance in LLDB.
 /// This class declares additional instrumentation points
 /// applicable to LLDB.
-class TelemetryManager : public llvm::telemetry::Manager {
+class TelemetryMager : public llvm::telemetry::Manager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
-  virtual llvm::StringRef GetInstanceName() const = 0;
+  const llvm::telemetry::Config *getConfig();
+
+  virtual void AtMainExecutableLoadStart(TargetInfo * entry);
+  virtual void AtMainExecutableLoadEnd(TargetInfo *entry);
+
+  virtual llvm::StringRef GetInstanceName() const = 0;
   static TelemetryManager *getInstance();
 
 protected:
@@ -73,6 +151,10 @@ class TelemetryManager : public llvm::telemetry::Manager {
 
 private:
   std::unique_ptr m_config;
+  // Each debugger is assigned a unique ID (session_id).
+  // All TelemetryInfo entries emitted for the same debugger instance
+  // will get the same session_id.
+  llvm::DenseMap session_ids;
   static std::unique_ptr g_instance;
 };
 
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..da7aee01680fc 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -10,14 +10,20 @@
 
 #ifdef LLVM_BUILD_TELEMETRY
 
-#include "lldb/Core/Telemetry.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/Telemetry.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Ta

[Lldb-commits] [lldb] [lldb-dap] Refactor request handlers (NFC) (PR #128262)

2025-02-24 Thread John Harrison via lldb-commits

ashgti wrote:

I think making the `operator ()` const makes sense, to help ensure we don't add 
any state accidentally. I can't think of any requests that have state at the 
moment. All the state is stored in the DAP object. Create an instance for each 
request might be helpful if we have more complex request handlers but I can't 
think of any uses for that at the moment, so maybe we keep it simple and just 
make them const.

> Should the request know they're interrupted before they complete?

Thats definitely an interesting question. I think its possible for request to 
check this if they're about to perform an expensive operation and bail out 
early. I think it may be possible to check this with the other changes I had 
prototyped. I can try out trying to strategically check 
`SBDebugger.InterruptRequested` to see how that works with my prototype.

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


[Lldb-commits] [lldb] [lldb-dap] Refactor custom & testing related request handlers (NFC) (PR #128549)

2025-02-24 Thread John Harrison via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb-dap] Refactor stepping related request handlers (NFC) (PR #128453)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

>From 34bd7c56ad67145501217464ef3e6b87a48d587a Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sun, 23 Feb 2025 21:07:55 -0600
Subject: [PATCH 1/2] [lldb-dap] Refactor stepping related request handlers
 (NFC)

Continuation of the work started in #128262.
---
 lldb/tools/lldb-dap/CMakeLists.txt|   4 +
 .../lldb-dap/Handler/NextRequestHandler.cpp   |  79 
 .../tools/lldb-dap/Handler/RequestHandler.cpp |   7 +
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  33 +-
 .../lldb-dap/Handler/StepInRequestHandler.cpp |  96 +
 .../Handler/StepInTargetsRequestHandler.cpp   | 149 
 .../Handler/StepOutRequestHandler.cpp |  68 
 lldb/tools/lldb-dap/lldb-dap.cpp  | 344 +-
 8 files changed, 440 insertions(+), 340 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 73762af5c2fd7..61271e1a9f2a6 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -47,8 +47,12 @@ add_lldb_tool(lldb-dap
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/StepInRequestHandler.cpp
+  Handler/StepInTargetsRequestHandler.cpp
+  Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
 liblldb
diff --git a/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
new file mode 100644
index 0..695703fe301b3
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
@@ -0,0 +1,79 @@
+//===-- NextRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "NextRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Next request; value of command field is 'next'. The
+// request starts the debuggee to run again for one step.
+// The debug adapter first sends the NextResponse and then
+// a StoppedEvent (event type 'step') after the step has
+// completed.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "next" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/NextArguments"
+//   }
+// },
+// "required": [ "command", "arguments"  ]
+//   }]
+// },
+// "NextArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'next' request.",
+//   "properties": {
+// "threadId": {
+//   "type": "integer",
+//   "description": "Execute 'next' for this thread."
+// },
+// "granularity": {
+//   "$ref": "#/definitions/SteppingGranularity",
+//   "description": "Stepping granularity. If no granularity is specified, 
a
+//   granularity of `statement` is assumed."
+// }
+//   },
+//   "required": [ "threadId" ]
+// },
+// "NextResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'next' request. This is just an
+// acknowledgement, so no body field is required."
+//   }]
+// }
+void NextRequestHandler::operator()(const llvm::json::Object &request) {
+  llvm::json::Object response;
+  FillResponse(request, response);
+  const auto *arguments = request.getObject("arguments");
+  lldb::SBThread thread = dap.GetLLDBThread(*arguments);
+  if (thread.IsValid()) {
+// Remember the thread ID that caused the resume so we can set the
+// "threadCausedFocus" boolean value in the "stopped" events.
+dap.focus_tid = thread.GetThreadID();
+if (HasInstructionGranularity(*arguments)) {
+  thread.StepInstruction(/*step_over=*/true);
+} else {
+  thread.StepOver();
+}
+  } else {
+response["success"] = llvm::json::Value(false);
+  }
+  dap.SendJSON(llvm::json::Value(std::move(response)));
+}
+
+} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp
index c09ddf55dd5e9.

[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread John Harrison via lldb-commits

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

LGTM, one question about some helpers.

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


[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread John Harrison via lldb-commits


@@ -52,6 +52,9 @@ class RequestHandler {
   // Check if the step-granularity is `instruction`.
   bool HasInstructionGranularity(const llvm::json::Object &request);
 
+  lldb::SBValueList *GetTopLevelScope(int64_t variablesReference);
+  lldb::SBValue FindVariable(uint64_t variablesReference, llvm::StringRef 
name);

ashgti wrote:

Should these be moved to the `lldb_dap::DAP` or `lldb_dap::Variables`?

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


[Lldb-commits] [lldb] [lldb-dap] Refactor custom & testing related request handlers (NFC) (PR #128549)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

>From 16bb4bd6d5f100dceb139474b29cbfd3de6dce06 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 24 Feb 2025 11:28:17 -0600
Subject: [PATCH] [lldb-dap] Refactor custom & testing related request handlers
 (NFC)

---
 lldb/tools/lldb-dap/CMakeLists.txt|   3 +
 .../Handler/CompileUnitsRequestHandler.cpp|  80 ++
 .../Handler/ModulesRequestHandler.cpp |  58 
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  27 
 ...TestGetTargetBreakpointsRequestHandler.cpp |  31 
 lldb/tools/lldb-dap/lldb-dap.cpp  | 138 +-
 6 files changed, 206 insertions(+), 131 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp
 create mode 100644 
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 61271e1a9f2a6..688a2e448f71d 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -39,6 +39,7 @@ add_lldb_tool(lldb-dap
 
   Handler/AttachRequestHandler.cpp
   Handler/BreakpointLocationsHandler.cpp
+  Handler/CompileUnitsRequestHandler.cpp
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
@@ -47,11 +48,13 @@ add_lldb_tool(lldb-dap
   Handler/ExceptionInfoRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
+  Handler/ModulesRequestHandler.cpp
   Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
   Handler/StepInRequestHandler.cpp
   Handler/StepInTargetsRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
   Handler/StepOutRequestHandler.cpp
 
   LINK_LIBS
diff --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
new file mode 100644
index 0..c541d1cd039c8
--- /dev/null
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -0,0 +1,80 @@
+//===-- CompileUnitsRequestHandler.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+#include "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.h"
+
+namespace lldb_dap {
+
+// "compileUnitsRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Compile Unit request; value of command field is
+// 'compileUnits'.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "compileUnits" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/compileUnitRequestArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "compileUnitsRequestArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'compileUnits' request.",
+//   "properties": {
+// "moduleId": {
+//   "type": "string",
+//   "description": "The ID of the module."
+// }
+//   },
+//   "required": [ "moduleId" ]
+// },
+// "compileUnitsResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'compileUnits' request.",
+// "properties": {
+//   "body": {
+// "description": "Response to 'compileUnits' request. Array of
+// paths of compile units."
+//   }
+// }
+//   }]
+// }
+void CompileUnitsRequestHandler::operator()(const llvm::json::Object &request) 
{
+  llvm::json::Object response;
+  FillResponse(request, response);
+  llvm::json::Object body;
+  llvm::json::Array units;
+  const auto *arguments = request.getObject("arguments");
+  std::string module_id = std::string(GetString(arguments, "moduleId"));
+  int num_modules = dap.target.GetNumModules();
+  for (int i = 0; i < num_modules; i++) {
+auto curr_module = dap.target.GetModuleAtIndex(i);
+if (module_id == curr_module.GetUUIDString()) {
+  int num_units = curr_module.GetNumCompileUnits();
+  for (int j = 0; j < num_units; j++) {
+auto curr_unit = curr_module.GetCompileUnitAtIndex(j);
+units.emplace_back(CreateCompileUnit(curr_unit));
+  }
+  body.try_emplace("compileUnits", std::move(units));
+  break;
+}
+  }
+  response.try_emplace("body", std::move(body));
+  dap.SendJSON(llvm::json::Value(std::move(response)));
+}
+
+} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/H

[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread John Harrison via lldb-commits

https://github.com/ashgti created 
https://github.com/llvm/llvm-project/pull/128583

The TestDAP_ouput test is flaky due to the order of events during shutdown.  We 
were stopping the output and error handle redirection after we finished the 
disconnect request, which can cause us to miss output events due to timing. 
Moving when we stop the redirection to ensure we have consistent output prior 
to disconnect responding.

Fixes #128567

>From 176eae365226716a2a2ead2f6de21d801238cf1b Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Mon, 24 Feb 2025 13:35:29 -0800
Subject: [PATCH] [lldb-dap] Addressing the order of events during disconnect
 to ensure we shutdown the debugger output handle and error handle redirection
 before disconnect completes.

The TestDAP_ouput test is flaky due to the order of events during shutdown.  We 
were stopping the output and error handle redirection after we finished the 
disconnect request, which can cause us to miss output events due to timing. 
Moving when we stop the redirection to ensure we have consistent output prior 
to disconnect responding.
---
 lldb/test/API/tools/lldb-dap/output/TestDAP_output.py |  4 
 lldb/tools/lldb-dap/DAP.cpp   | 11 ++-
 lldb/tools/lldb-dap/DAP.h |  4 ++--
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py 
b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
index eae7629409844..fe54511d1e21f 100644
--- a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
+++ b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
@@ -16,6 +16,7 @@ def test_output(self):
 program = self.getBuildArtifact("a.out")
 self.build_and_launch(
 program,
+disconnectAutomatically=False,
 exitCommands=[
 # Ensure that output produced by lldb itself is not consumed 
by the OutputRedirector.
 "?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
@@ -33,6 +34,9 @@ def test_output(self):
 
 self.continue_to_exit()
 
+# Disconnecting from the server to ensure any pending IO is flushed.
+self.dap_server.request_disconnect()
+
 output += 
self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
 self.assertTrue(output and len(output) > 0, "expect program stdout")
 self.assertIn(
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 9b22b60a68d94..0bc570e61916c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -223,10 +223,7 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, 
std::FILE *overrideErr) {
   return llvm::Error::success();
 }
 
-void DAP::StopIO() {
-  out.Stop();
-  err.Stop();
-
+void DAP::StopEventHandlers() {
   if (event_thread.joinable()) {
 broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
 event_thread.join();
@@ -853,13 +850,17 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 
   SendTerminatedEvent();
 
+  // Stop forward the debugger output and error file handle.
+  out.Stop();
+  err.Stop();
+
   disconnecting = true;
 
   return error;
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
+  auto stop_io = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 18de39838f218..d0e1217aaeb8e 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -224,8 +224,8 @@ struct DAP {
   llvm::Error ConfigureIO(std::FILE *overrideOut = nullptr,
   std::FILE *overrideErr = nullptr);
 
-  /// Stop the redirected IO threads and associated pipes.
-  void StopIO();
+  /// Stop event handler threads.
+  void StopEventHandlers();
 
   // Serialize the JSON value into a string and send the JSON packet to
   // the "out" stream.

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


[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread John Harrison via lldb-commits

https://github.com/ashgti updated 
https://github.com/llvm/llvm-project/pull/128583

>From 176eae365226716a2a2ead2f6de21d801238cf1b Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Mon, 24 Feb 2025 13:35:29 -0800
Subject: [PATCH 1/2] [lldb-dap] Addressing the order of events during
 disconnect to ensure we shutdown the debugger output handle and error handle
 redirection before disconnect completes.

The TestDAP_ouput test is flaky due to the order of events during shutdown.  We 
were stopping the output and error handle redirection after we finished the 
disconnect request, which can cause us to miss output events due to timing. 
Moving when we stop the redirection to ensure we have consistent output prior 
to disconnect responding.
---
 lldb/test/API/tools/lldb-dap/output/TestDAP_output.py |  4 
 lldb/tools/lldb-dap/DAP.cpp   | 11 ++-
 lldb/tools/lldb-dap/DAP.h |  4 ++--
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py 
b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
index eae7629409844..fe54511d1e21f 100644
--- a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
+++ b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
@@ -16,6 +16,7 @@ def test_output(self):
 program = self.getBuildArtifact("a.out")
 self.build_and_launch(
 program,
+disconnectAutomatically=False,
 exitCommands=[
 # Ensure that output produced by lldb itself is not consumed 
by the OutputRedirector.
 "?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
@@ -33,6 +34,9 @@ def test_output(self):
 
 self.continue_to_exit()
 
+# Disconnecting from the server to ensure any pending IO is flushed.
+self.dap_server.request_disconnect()
+
 output += 
self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
 self.assertTrue(output and len(output) > 0, "expect program stdout")
 self.assertIn(
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 9b22b60a68d94..0bc570e61916c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -223,10 +223,7 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, 
std::FILE *overrideErr) {
   return llvm::Error::success();
 }
 
-void DAP::StopIO() {
-  out.Stop();
-  err.Stop();
-
+void DAP::StopEventHandlers() {
   if (event_thread.joinable()) {
 broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
 event_thread.join();
@@ -853,13 +850,17 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 
   SendTerminatedEvent();
 
+  // Stop forward the debugger output and error file handle.
+  out.Stop();
+  err.Stop();
+
   disconnecting = true;
 
   return error;
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
+  auto stop_io = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 18de39838f218..d0e1217aaeb8e 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -224,8 +224,8 @@ struct DAP {
   llvm::Error ConfigureIO(std::FILE *overrideOut = nullptr,
   std::FILE *overrideErr = nullptr);
 
-  /// Stop the redirected IO threads and associated pipes.
-  void StopIO();
+  /// Stop event handler threads.
+  void StopEventHandlers();
 
   // Serialize the JSON value into a string and send the JSON packet to
   // the "out" stream.

>From 72360fc70861247754531bff1799f46132f4c575 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Mon, 24 Feb 2025 13:42:59 -0800
Subject: [PATCH 2/2] Adjusting a variable name.

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

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0bc570e61916c..81de6e526547a 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -860,7 +860,7 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopEventHandlers(); });
+  auto cleanup = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);

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


[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread John Harrison via lldb-commits

https://github.com/ashgti updated 
https://github.com/llvm/llvm-project/pull/128583

>From 176eae365226716a2a2ead2f6de21d801238cf1b Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Mon, 24 Feb 2025 13:35:29 -0800
Subject: [PATCH 1/3] [lldb-dap] Addressing the order of events during
 disconnect to ensure we shutdown the debugger output handle and error handle
 redirection before disconnect completes.

The TestDAP_ouput test is flaky due to the order of events during shutdown.  We 
were stopping the output and error handle redirection after we finished the 
disconnect request, which can cause us to miss output events due to timing. 
Moving when we stop the redirection to ensure we have consistent output prior 
to disconnect responding.
---
 lldb/test/API/tools/lldb-dap/output/TestDAP_output.py |  4 
 lldb/tools/lldb-dap/DAP.cpp   | 11 ++-
 lldb/tools/lldb-dap/DAP.h |  4 ++--
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py 
b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
index eae7629409844..fe54511d1e21f 100644
--- a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
+++ b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
@@ -16,6 +16,7 @@ def test_output(self):
 program = self.getBuildArtifact("a.out")
 self.build_and_launch(
 program,
+disconnectAutomatically=False,
 exitCommands=[
 # Ensure that output produced by lldb itself is not consumed 
by the OutputRedirector.
 "?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
@@ -33,6 +34,9 @@ def test_output(self):
 
 self.continue_to_exit()
 
+# Disconnecting from the server to ensure any pending IO is flushed.
+self.dap_server.request_disconnect()
+
 output += 
self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
 self.assertTrue(output and len(output) > 0, "expect program stdout")
 self.assertIn(
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 9b22b60a68d94..0bc570e61916c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -223,10 +223,7 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, 
std::FILE *overrideErr) {
   return llvm::Error::success();
 }
 
-void DAP::StopIO() {
-  out.Stop();
-  err.Stop();
-
+void DAP::StopEventHandlers() {
   if (event_thread.joinable()) {
 broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
 event_thread.join();
@@ -853,13 +850,17 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 
   SendTerminatedEvent();
 
+  // Stop forward the debugger output and error file handle.
+  out.Stop();
+  err.Stop();
+
   disconnecting = true;
 
   return error;
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
+  auto stop_io = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 18de39838f218..d0e1217aaeb8e 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -224,8 +224,8 @@ struct DAP {
   llvm::Error ConfigureIO(std::FILE *overrideOut = nullptr,
   std::FILE *overrideErr = nullptr);
 
-  /// Stop the redirected IO threads and associated pipes.
-  void StopIO();
+  /// Stop event handler threads.
+  void StopEventHandlers();
 
   // Serialize the JSON value into a string and send the JSON packet to
   // the "out" stream.

>From 72360fc70861247754531bff1799f46132f4c575 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Mon, 24 Feb 2025 13:42:59 -0800
Subject: [PATCH 2/3] Adjusting a variable name.

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

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0bc570e61916c..81de6e526547a 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -860,7 +860,7 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopEventHandlers(); });
+  auto cleanup = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);

>From 06d683d15b6ef5734359ec3a3b23757dbdedb465 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Mon, 24 Feb 2025 13:48:38 -0800
Subject: [PATCH 3/3] Tweaking a comment to be more clear.

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

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 81de6e526547a..7a5cd39535617 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lld

[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Chelsea Cassanova via lldb-commits


@@ -0,0 +1,100 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+"""Use fzf to search and select from lldb command history."""
+if sys.platform != "darwin":
+result.SetError("fzf_history supports macOS only")

chelcassanova wrote:

I know that fzf_history here is using `pbcopy/pbpaste` and `applescript` here 
for the clipboard operations but is it possible to just say that "clipboard 
operations are only supported on macOS" and still run the script?

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere commented:

Instead of using `pbcopy/pbpaste`, which makes this macOS only, could you use a 
Python temp file and read/write from that? 

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


[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)


Changes

The TestDAP_ouput test is flaky due to the order of events during shutdown.  We 
were stopping the output and error handle redirection after we finished the 
disconnect request, which can cause us to miss output events due to timing. 
Moving when we stop the redirection to ensure we have consistent output prior 
to disconnect responding.

Fixes #128567

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


3 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/output/TestDAP_output.py (+4) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (+6-5) 
- (modified) lldb/tools/lldb-dap/DAP.h (+2-2) 


``diff
diff --git a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py 
b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
index eae7629409844..fe54511d1e21f 100644
--- a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
+++ b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
@@ -16,6 +16,7 @@ def test_output(self):
 program = self.getBuildArtifact("a.out")
 self.build_and_launch(
 program,
+disconnectAutomatically=False,
 exitCommands=[
 # Ensure that output produced by lldb itself is not consumed 
by the OutputRedirector.
 "?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
@@ -33,6 +34,9 @@ def test_output(self):
 
 self.continue_to_exit()
 
+# Disconnecting from the server to ensure any pending IO is flushed.
+self.dap_server.request_disconnect()
+
 output += 
self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
 self.assertTrue(output and len(output) > 0, "expect program stdout")
 self.assertIn(
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 9b22b60a68d94..7a5cd39535617 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -223,10 +223,7 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, 
std::FILE *overrideErr) {
   return llvm::Error::success();
 }
 
-void DAP::StopIO() {
-  out.Stop();
-  err.Stop();
-
+void DAP::StopEventHandlers() {
   if (event_thread.joinable()) {
 broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
 event_thread.join();
@@ -853,13 +850,17 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 
   SendTerminatedEvent();
 
+  // Stop forwarding the debugger output and error handles.
+  out.Stop();
+  err.Stop();
+
   disconnecting = true;
 
   return error;
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
+  auto cleanup = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 18de39838f218..d0e1217aaeb8e 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -224,8 +224,8 @@ struct DAP {
   llvm::Error ConfigureIO(std::FILE *overrideOut = nullptr,
   std::FILE *overrideErr = nullptr);
 
-  /// Stop the redirected IO threads and associated pipes.
-  void StopIO();
+  /// Stop event handler threads.
+  void StopEventHandlers();
 
   // Serialize the JSON value into a string and send the JSON packet to
   // the "out" stream.

``




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


[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] d362319 - [lldb-dap] Refactor breakpoint related request handlers (NFC) (#128550)

2025-02-24 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-02-24T15:40:31-06:00
New Revision: d3623194044452e2f1b4e81c213bc8cbbe49c2a8

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

LOG: [lldb-dap] Refactor breakpoint related request handlers (NFC) (#128550)

Continuation of the work started in #128262. Builds on top of #128549.

Added: 
lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.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

Modified: 
lldb/tools/lldb-dap/CMakeLists.txt
lldb/tools/lldb-dap/DAP.cpp
lldb/tools/lldb-dap/DAP.h
lldb/tools/lldb-dap/Handler/RequestHandler.h
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 688a2e448f71d..49809ec1c2592 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -43,6 +43,7 @@ add_lldb_tool(lldb-dap
   Handler/CompletionsHandler.cpp
   Handler/ConfigurationDoneRequestHandler.cpp
   Handler/ContinueRequestHandler.cpp
+  Handler/DataBreakpointInfoRequestHandler.cpp
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
@@ -52,10 +53,15 @@ add_lldb_tool(lldb-dap
   Handler/NextRequestHandler.cpp
   Handler/RequestHandler.cpp
   Handler/RestartRequestHandler.cpp
+  Handler/SetBreakpointsRequestHandler.cpp
+  Handler/SetDataBreakpointsRequestHandler.cpp
+  Handler/SetExceptionBreakpointsRequestHandler.cpp
+  Handler/SetFunctionBreakpointsRequestHandler.cpp
+  Handler/SetInstructionBreakpointsRequestHandler.cpp
   Handler/StepInRequestHandler.cpp
   Handler/StepInTargetsRequestHandler.cpp
-  Handler/TestGetTargetBreakpointsRequestHandler.cpp
   Handler/StepOutRequestHandler.cpp
+  Handler/TestGetTargetBreakpointsRequestHandler.cpp
 
   LINK_LIBS
 liblldb

diff  --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 9b22b60a68d94..c9487dd89b5dc 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1201,4 +1201,58 @@ DAP::GetInstructionBPFromStopReason(lldb::SBThread 
&thread) {
   return inst_bp;
 }
 
+lldb::SBValueList *Variables::GetTopLevelScope(int64_t variablesReference) {
+  switch (variablesReference) {
+  case VARREF_LOCALS:
+return &locals;
+  case VARREF_GLOBALS:
+return &globals;
+  case VARREF_REGS:
+return ®isters;
+  default:
+return nullptr;
+  }
+}
+
+lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
+  llvm::StringRef name) {
+  lldb::SBValue variable;
+  if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) {
+bool is_duplicated_variable_name = name.contains(" @");
+// variablesReference is one of our scopes, not an actual variable it is
+// asking for a variable in locals or globals or registers
+int64_t end_idx = top_scope->GetSize();
+// Searching backward so that we choose the variable in closest scope
+// among variables of the same name.
+for (int64_t i = end_idx - 1; i >= 0; --i) {
+  lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i);
+  std::string variable_name = CreateUniqueVariableNameForDisplay(
+  curr_variable, is_duplicated_variable_name);
+  if (variable_name == name) {
+variable = curr_variable;
+break;
+  }
+}
+  } else {
+// This is not under the globals or locals scope, so there are no 
duplicated
+// names.
+
+// We have a named item within an actual variable so we need to find it
+// withing the container variable by name.
+lldb::SBValue container = GetVariable(variablesReference);
+variable = container.GetChildMemberWithName(name.data());
+if (!variable.IsValid()) {
+  if (name.starts_with("[")) {
+llvm::StringRef index_str(name.drop_front(1));
+uint64_t index = 0;
+if (!index_str.consumeInteger(0, index)) {
+  if (index_str == "]")
+variable = container.GetChildAtIndex(index);
+}
+  }
+}
+  }
+  return variable;
+}
+
 } // namespace lldb_dap

diff  --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 18de39838f218..ca26ea1b9a5de 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -116,6 +116,10 @@ struct Variables {
   /// \return variableReference assigned to this expandable variable.
   int64_t InsertVariable(lldb::SBValue variable, bool is_permanent);

[Lldb-commits] [lldb] [lldb-dap] Refactor remaining request handlers (NFC)Remaining request handlers (PR #128551)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread Jonas Devlieghere via lldb-commits


@@ -30,6 +30,7 @@ class RequestHandler {
 
   virtual void operator()(const llvm::json::Object &request) = 0;

JDevlieghere wrote:

Yup, I was going to it in a separate commit, but I can include it here. 

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


[Lldb-commits] [lldb] [lldb-dap] Refactor request handlers (NFC) (PR #128262)

2025-02-24 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-win` 
running on `as-builder-10` while building `lldb` at step 8 "build-default".

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


Here is the relevant piece of the build log for the reference

```
Step 8 (build-default) failure: cmake (failure)
...
63.647 [206/37/5085]Building CXX object 
tools\lldb\source\Plugins\ExpressionParser\Clang\CMakeFiles\lldbPluginExpressionParserClang.dir\ASTResultSynthesizer.cpp.obj
63.650 [206/36/5086]Building CXX object 
tools\clang\tools\clang-check\CMakeFiles\clang-check.dir\ClangCheck.cpp.obj
63.922 [206/35/5087]Building CXX object 
tools\lldb\source\Plugins\ExpressionParser\Clang\CMakeFiles\lldbPluginExpressionParserClang.dir\ClangModulesDeclVendor.cpp.obj
64.033 [206/34/5088]Building CXX object 
tools\lldb\source\Plugins\ExpressionParser\Clang\CMakeFiles\lldbPluginExpressionParserClang.dir\ClangFunctionCaller.cpp.obj
64.045 [206/33/5089]Building CXX object 
tools\clang\tools\clang-installapi\CMakeFiles\clang-installapi.dir\ClangInstallAPI.cpp.obj
64.228 [206/32/5090]Building CXX object 
tools\lldb\source\Plugins\ExpressionParser\Clang\CMakeFiles\lldbPluginExpressionParserClang.dir\ClangExpressionParser.cpp.obj
64.286 [206/31/5091]Linking CXX executable bin\llc.exe
65.531 [205/31/5092]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\FunctionBreakpoint.cpp.obj
65.621 [205/30/5093]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\CompletionsHandler.cpp.obj
65.681 [205/29/5094]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\EventHelper.cpp.obj
FAILED: tools/lldb/tools/lldb-dap/CMakeFiles/lldb-dap.dir/EventHelper.cpp.obj 
ccache 
C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1441~1.341\bin\Hostx64\x64\cl.exe
  /nologo /TP -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -DUNICODE 
-D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS 
-D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 
-D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\build\tools\lldb\tools\lldb-dap 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\tools\lldb-dap 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\include 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\build\tools\lldb\include 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\build\include 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\llvm\include 
-IC:\Python312\include 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\llvm\..\clang\include 
-IC:\buildbot\as-builder-10\lldb-x-aarch64\build\tools\lldb\..\clang\include 
-D__OPTIMIZE__ /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj 
/permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 
-wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 
-wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 
-wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 
-wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD   -wd4018 -wd4068 -wd4150 -wd4201 
-wd4251 -wd4521 -wd4530 -wd4589  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes 
/Fotools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\EventHelper.cpp.obj 
/Fdtools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\ /FS -c 
C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\tools\lldb-dap\EventHelper.cpp
C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\tools\lldb-dap\EventHelper.cpp(82):
 error C2065: 'PATH_MAX': undeclared identifier
C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\tools\lldb-dap\EventHelper.cpp(83):
 fatal error C1903: unable to recover from previous error(s); stopping 
compilation
66.135 [205/28/5095]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\EvaluateRequestHandler.cpp.obj
66.191 [205/27/5096]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\InitializeRequestHandler.cpp.obj
66.447 [205/26/5097]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Watchpoint.cpp.obj
66.502 [205/25/5098]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\ConfigurationDoneRequestHandler.cpp.obj
66.509 [205/24/5099]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\RestartRequestHandler.cpp.obj
66.511 [205/23/5100]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\LaunchRequestHandler.cpp.obj
66.537 [205/22/5101]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\ExceptionInfoRequestHandler.cpp.obj
66.618 [205/21/5102]Building CXX object 
tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Handler\BreakpointLocationsHandler.cpp.obj
66

[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread John Harrison via lldb-commits

https://github.com/ashgti updated 
https://github.com/llvm/llvm-project/pull/128268

>From c54157f43966c2d9d62134110026f3fed02de379 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Fri, 21 Feb 2025 17:45:17 -0800
Subject: [PATCH 1/9] [lldb-dap] Add 'source' references to stack frames
 without source files.

This adds 'source' references to all stack frames. When opening a stack frame 
users will see the disassembly of the frame if the source is not available.

This works around the odd behavior of navigating frames without the VSCode 
disassembly view open, which causes 'step' to step in the first frame with a 
source instead of the active frame.
---
 lldb/tools/lldb-dap/JSONUtils.cpp | 38 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  | 24 +++
 2 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 6ca4dfb4711a1..ee8fcef6f2503 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -45,7 +45,6 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -698,14 +697,22 @@ llvm::json::Value CreateSource(llvm::StringRef 
source_path) {
   return llvm::json::Value(std::move(source));
 }
 
-static std::optional CreateSource(lldb::SBFrame &frame) {
+static llvm::json::Value CreateSource(lldb::SBFrame &frame,
+  llvm::StringRef frame_name) {
   auto line_entry = frame.GetLineEntry();
   // A line entry of 0 indicates the line is compiler generated i.e. no source
   // file is associated with the frame.
   if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
-  return {};
+  llvm::json::Object source;
+  EmplaceSafeString(source, "name", frame_name);
+  source.try_emplace("sourceReference", MakeDAPFrameID(frame));
+  // If we don't have a filespec then we don't have the original source. Mark
+  // the source as deemphasized since users will only be able to view assembly
+  // for these frames.
+  EmplaceSafeString(source, "presentationHint", "deemphasize");
+  return std::move(source);
 }
 
 // "StackFrame": {
@@ -799,21 +806,22 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
 
   EmplaceSafeString(object, "name", frame_name);
 
-  auto source = CreateSource(frame);
-
-  if (source) {
-object.try_emplace("source", *source);
-auto line_entry = frame.GetLineEntry();
-auto line = line_entry.GetLine();
-if (line && line != LLDB_INVALID_LINE_NUMBER)
-  object.try_emplace("line", line);
-else
-  object.try_emplace("line", 0);
+  object.try_emplace("source", CreateSource(frame, frame_name));
+  auto line_entry = frame.GetLineEntry();
+  if (line_entry.IsValid() &&
+  (line_entry.GetLine() != 0 ||
+   line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) {
+object.try_emplace("line", line_entry.GetLine());
 auto column = line_entry.GetColumn();
 object.try_emplace("column", column);
   } else {
-object.try_emplace("line", 0);
-object.try_emplace("column", 0);
+lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() -
+   frame.GetSymbol().GetStartAddress().GetOffset();
+lldb::addr_t inst_line =
+inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 
2);
+// lines are base-1 indexed
+object.try_emplace("line", inst_line + 1);
+object.try_emplace("column", 1);
   }
 
   const auto pc = frame.GetPC();
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 5f2758e9fa8d0..df5621424c607 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -13,6 +13,7 @@
 #include "RunInTerminal.h"
 #include "Watchpoint.h"
 #include "lldb/API/SBDeclaration.h"
+#include "lldb/API/SBDefines.h"
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBFile.h"
 #include "lldb/API/SBInstruction.h"
@@ -3431,6 +3432,29 @@ void request_source(DAP &dap, const llvm::json::Object 
&request) {
   llvm::json::Object response;
   FillResponse(request, response);
   llvm::json::Object body{{"content", ""}};
+
+  const auto *arguments = request.getObject("arguments");
+  const auto *source = arguments->getObject("source");
+  int64_t source_ref = GetUnsigned(
+  source, "sourceReference", GetUnsigned(arguments, "sourceReference", 0));
+
+  lldb::SBProcess process = dap.target.GetProcess();
+  // Upper 32 bits is the thread index ID
+  lldb::SBThread thread =
+  process.GetThreadByIndexID(GetLLDBThreadIndexID(source_ref));
+  // Lower 32 bits is the frame index
+  lldb::SBFrame frame = thread.GetFrameAtIndex(GetLLDBFrameID(source_ref));
+  if (!frame.IsValid()) {
+response["success"] = false;
+response["message"] = "source not found";
+  } else {
+lldb::SBInstructionList insts = 
frame.GetSymbol().GetInstructions(da

[Lldb-commits] [lldb] 664cbd1 - [lldb-dap] skip TestDAP_server on windows to unblock CI. (#128278)

2025-02-24 Thread via lldb-commits

Author: John Harrison
Date: 2025-02-24T09:45:51-08:00
New Revision: 664cbd1b5db190724ceea498d1f520eb66d78d69

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

LOG: [lldb-dap] skip TestDAP_server on windows to unblock CI. (#128278)

This should fix the tests running on windows.

https://lab.llvm.org/buildbot/#/builders/141/builds/6506 is the failure,
the error message does not clearly indicate why the connection failed,
but they are passing for me locally on macOS and passed on linux in the
CI.

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/server/TestDAP_server.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py 
b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
index e78fdceed1bbd..1f562e989533a 100644
--- a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
+++ b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
@@ -48,6 +48,7 @@ def run_debug_session(self, connection, name):
 self.assertEqual(output, f"Hello {name}!\r\n")
 self.dap_server.request_disconnect()
 
+@skipIfWindows
 def test_server_port(self):
 """
 Test launching a binary with a lldb-dap in server mode on a specific 
port.



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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits


@@ -0,0 +1,100 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+"""Use fzf to search and select from lldb command history."""
+if sys.platform != "darwin":
+result.SetError("fzf_history supports macOS only")

kastiglione wrote:

https://github.com/llvm/llvm-project/pull/128571#issuecomment-2679790655

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


[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread John Harrison via lldb-commits

https://github.com/ashgti updated 
https://github.com/llvm/llvm-project/pull/128268

>From 4378be2df5da154420306bc65d95a4b714b05fae Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Fri, 21 Feb 2025 17:45:17 -0800
Subject: [PATCH 1/8] [lldb-dap] Add 'source' references to stack frames
 without source files.

This adds 'source' references to all stack frames. When opening a stack frame 
users will see the disassembly of the frame if the source is not available.

This works around the odd behavior of navigating frames without the VSCode 
disassembly view open, which causes 'step' to step in the first frame with a 
source instead of the active frame.
---
 .../lldb-dap/Handler/SourceRequestHandler.cpp | 41 ++-
 lldb/tools/lldb-dap/JSONUtils.cpp | 38 ++---
 2 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
index 03561c9e64922..7a1ef7f33b6fb 100644
--- a/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
@@ -9,7 +9,15 @@
 #include "DAP.h"
 #include "EventHelper.h"
 #include "JSONUtils.h"
+#include "LLDBUtils.h"
 #include "RequestHandler.h"
+#include "lldb/API/SBFrame.h"
+#include "lldb/API/SBInstructionList.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBStream.h"
+#include "lldb/API/SBTarget.h"
+#include "lldb/API/SBThread.h"
+#include "llvm/Support/JSON.h"
 
 namespace lldb_dap {
 
@@ -74,8 +82,37 @@ namespace lldb_dap {
 void SourceRequestHandler::operator()(const llvm::json::Object &request) {
   llvm::json::Object response;
   FillResponse(request, response);
-  llvm::json::Object body{{"content", ""}};
-  response.try_emplace("body", std::move(body));
+  const auto *arguments = request.getObject("arguments");
+  const auto *source = arguments->getObject("source");
+  llvm::json::Object body;
+  int64_t source_ref = GetUnsigned(
+  source, "sourceReference", GetUnsigned(arguments, "sourceReference", 0));
+
+  if (source_ref) {
+lldb::SBProcess process = dap.target.GetProcess();
+// Upper 32 bits is the thread index ID
+lldb::SBThread thread =
+process.GetThreadByIndexID(GetLLDBThreadIndexID(source_ref));
+// Lower 32 bits is the frame index
+lldb::SBFrame frame = thread.GetFrameAtIndex(GetLLDBFrameID(source_ref));
+if (!frame.IsValid()) {
+  response["success"] = false;
+  response["message"] = "source not found";
+} else {
+  lldb::SBInstructionList insts =
+  frame.GetSymbol().GetInstructions(dap.target);
+  lldb::SBStream stream;
+  insts.GetDescription(stream);
+  body["content"] = stream.GetData();
+  body["mimeType"] = "text/x-lldb.disassembly";
+  response.try_emplace("body", std::move(body));
+}
+  } else {
+response["success"] = false;
+response["message"] =
+"invalid arguments, expected source.sourceReference to be set";
+  }
+
   dap.SendJSON(llvm::json::Value(std::move(response)));
 }
 
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 6ca4dfb4711a1..ee8fcef6f2503 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -45,7 +45,6 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -698,14 +697,22 @@ llvm::json::Value CreateSource(llvm::StringRef 
source_path) {
   return llvm::json::Value(std::move(source));
 }
 
-static std::optional CreateSource(lldb::SBFrame &frame) {
+static llvm::json::Value CreateSource(lldb::SBFrame &frame,
+  llvm::StringRef frame_name) {
   auto line_entry = frame.GetLineEntry();
   // A line entry of 0 indicates the line is compiler generated i.e. no source
   // file is associated with the frame.
   if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
-  return {};
+  llvm::json::Object source;
+  EmplaceSafeString(source, "name", frame_name);
+  source.try_emplace("sourceReference", MakeDAPFrameID(frame));
+  // If we don't have a filespec then we don't have the original source. Mark
+  // the source as deemphasized since users will only be able to view assembly
+  // for these frames.
+  EmplaceSafeString(source, "presentationHint", "deemphasize");
+  return std::move(source);
 }
 
 // "StackFrame": {
@@ -799,21 +806,22 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
 
   EmplaceSafeString(object, "name", frame_name);
 
-  auto source = CreateSource(frame);
-
-  if (source) {
-object.try_emplace("source", *source);
-auto line_entry = frame.GetLineEntry();
-auto line = line_entry.GetLine();
-if (line && line != LLDB_INVALID_LINE_NUMBER)
-  object.try_emplace("line", line);
-else
-  object.try_emplace("line", 0);
+  object.try_emplace("source", C

[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread John Harrison via lldb-commits

ashgti wrote:

Pulled and rebased my changes on the request handler refactor.

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

kastiglione wrote:

> Instead of using `pbcopy/pbpaste`, which makes this macOS only, could you use 
> a Python temp file and read/write from that?

@JDevlieghere I didn't do that because it would be an implementation I wouldn't 
even want to use, for platforms I don't use.

Without a way to do copy and paste, the command could skip writing to write to 
a temp file, since fzf's default behavior is to print the selected line to 
stdout.

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


[Lldb-commits] [lldb] [lldb-dap] Addressing the order of events during disconnect to flush output. (PR #128583)

2025-02-24 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] e8f1623 - [lldb-dap] Addressing the order of events during disconnect to flush output. (#128583)

2025-02-24 Thread via lldb-commits

Author: John Harrison
Date: 2025-02-24T14:41:19-08:00
New Revision: e8f1623a223adf5446e403aa6ce827a9b6dc

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

LOG: [lldb-dap] Addressing the order of events during disconnect to flush 
output. (#128583)

The TestDAP_ouput test is flaky due to the order of events during
shutdown. We were stopping the output and error handle redirection after
we finished the disconnect request, which can cause us to miss output
events due to timing. Moving when we stop the redirection to ensure we
have consistent output prior to disconnect responding.

Fixes #128567

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
lldb/tools/lldb-dap/DAP.cpp
lldb/tools/lldb-dap/DAP.h

Removed: 




diff  --git a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py 
b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
index eae7629409844..fe54511d1e21f 100644
--- a/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
+++ b/lldb/test/API/tools/lldb-dap/output/TestDAP_output.py
@@ -16,6 +16,7 @@ def test_output(self):
 program = self.getBuildArtifact("a.out")
 self.build_and_launch(
 program,
+disconnectAutomatically=False,
 exitCommands=[
 # Ensure that output produced by lldb itself is not consumed 
by the OutputRedirector.
 "?script print('out\\0\\0', end='\\r\\n', file=sys.stdout)",
@@ -33,6 +34,9 @@ def test_output(self):
 
 self.continue_to_exit()
 
+# Disconnecting from the server to ensure any pending IO is flushed.
+self.dap_server.request_disconnect()
+
 output += 
self.get_stdout(timeout=lldbdap_testcase.DAPTestCaseBase.timeoutval)
 self.assertTrue(output and len(output) > 0, "expect program stdout")
 self.assertIn(

diff  --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index c9487dd89b5dc..c966f4cfae027 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -223,10 +223,7 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, 
std::FILE *overrideErr) {
   return llvm::Error::success();
 }
 
-void DAP::StopIO() {
-  out.Stop();
-  err.Stop();
-
+void DAP::StopEventHandlers() {
   if (event_thread.joinable()) {
 broadcaster.BroadcastEventByType(eBroadcastBitStopEventThread);
 event_thread.join();
@@ -853,13 +850,17 @@ lldb::SBError DAP::Disconnect(bool terminateDebuggee) {
 
   SendTerminatedEvent();
 
+  // Stop forwarding the debugger output and error handles.
+  out.Stop();
+  err.Stop();
+
   disconnecting = true;
 
   return error;
 }
 
 llvm::Error DAP::Loop() {
-  auto stop_io = llvm::make_scope_exit([this]() { StopIO(); });
+  auto cleanup = llvm::make_scope_exit([this]() { StopEventHandlers(); });
   while (!disconnecting) {
 llvm::json::Object object;
 lldb_dap::PacketStatus status = GetNextObject(object);

diff  --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index ca26ea1b9a5de..1cc0170637c15 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -228,8 +228,8 @@ struct DAP {
   llvm::Error ConfigureIO(std::FILE *overrideOut = nullptr,
   std::FILE *overrideErr = nullptr);
 
-  /// Stop the redirected IO threads and associated pipes.
-  void StopIO();
+  /// Stop event handler threads.
+  void StopEventHandlers();
 
   // Serialize the JSON value into a string and send the JSON packet to
   // the "out" stream.



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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/128571

>From 57638e91c97486ad7739f9658fe88f7fb4d61fb2 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:48:17 -0800
Subject: [PATCH 1/4] [lldb] Add fzf_history command to examples

---
 lldb/examples/python/fzf_history.py | 99 +
 1 file changed, 99 insertions(+)
 create mode 100644 lldb/examples/python/fzf_history.py

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
new file mode 100644
index 0..4647a3532b0df
--- /dev/null
+++ b/lldb/examples/python/fzf_history.py
@@ -0,0 +1,99 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+if sys.platform != 'darwin':
+result.SetError("fzf_history supports macOS only")
+return
+
+# Capture the current pasteboard contents to restore after overwriting.
+paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+
+# On enter, copy the selected history entry into the pasteboard.
+fzf_command = (
+"fzf",
+"--no-sort",
+f"--query={cmdstr}",
+"--bind=enter:execute-silent(echo -n {} | pbcopy)+close",
+)
+
+history_file = os.path.expanduser("~/.lldb/lldb-widehistory")
+if not os.path.exists(history_file):
+result.SetError("history file does not exist")
+return
+
+history_commands = _load_history(history_file)
+fzf_input = "\n".join(history_commands)
+completed = subprocess.run(fzf_command, input=fzf_input, text=True)
+# 130 is used for CTRL-C or ESC.
+if completed.returncode not in (0, 130):
+result.SetError(f"fzf failed: {completed.stderr}")
+return
+
+# Get the user's selected history entry.
+selected_command = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+if selected_command == paste_snapshot:
+# Nothing was selected, no cleanup needed.
+return
+
+_handle_command(debugger, selected_command)
+
+# Restore the pasteboard's contents.
+subprocess.run("pbcopy", input=paste_snapshot, text=True)
+
+
+def _handle_command(debugger, command):
+"""Try pasting the command, and failing that, run it directly."""
+if not command:
+return
+
+# Use applescript to paste the selected result into lldb's console.
+paste_command = (
+"osascript",
+"-e",
+'tell application "System Events" to keystroke "v" using command down',
+)
+completed = subprocess.run(paste_command, capture_output=True)
+
+if completed.returncode != 0:
+# The above applescript requires the "control your computer" 
permission.
+# Settings > Private & Security > Accessibility
+# If not enabled, fallback to running the command.
+debugger.HandleCommand(command)
+
+
+def _load_history(history_file):
+"""Load, decode, and parse an lldb history file."""
+with open(history_file) as f:
+history_contents = f.read()
+
+history_decoded = re.sub(r"\\0([0-7][0-7])", _decode_char, 
history_contents)
+history_lines = history_decoded.splitlines()
+
+# Skip the header line (_HiStOrY_V2_)
+del history_lines[0]
+# Reverse to show latest first.
+history_lines.reverse()
+
+history_commands = []
+history_seen = set()
+for line in history_lines:
+line = line.strip()
+# Skip empty lines, single character commands, and duplicates.
+if line and len(line) > 1 and line not in history_seen:
+history_commands.append(line)
+history_seen.add(line)
+
+return history_commands
+
+
+def _decode_char(match):
+"""Decode octal strings ('\0NN') into a single character string."""
+code = int(match.group(1), base=8)
+return chr(code)

>From d1106bc7165d8a62a1805ec09afdf62e5b7f09ff Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:56:35 -0800
Subject: [PATCH 2/4] Fix code formatting

---
 lldb/examples/python/fzf_history.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index 4647a3532b0df..b683078465985 100644
--- a/lldb/examples/python/fzf_history.py
+++ b/lldb/examples/python/fzf_history.py
@@ -8,7 +8,7 @@
 
 @lldb.command()
 def fzf_history(debugger, cmdstr, ctx, result, _):
-if sys.platform != 'darwin':
+if sys.platform != "darwin":
 result.SetError("fzf_history supports macOS only")
 return
 

>From 7fb2bfc015e1550dde6f3d54e932e8bc6ccbe0f7 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:59:08 -0800
Subject: [PATCH 3/4] Add docstring for fzf_history

---
 lldb/examples/python/fzf_history.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index

[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

kastiglione wrote:

I added a featureless invocation of fzf for when copy and paste support isn't 
available.

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


[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

Totally optional & I didn't think about it earlier, but this seems like 
something you might want to advertise through a release note.

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


[Lldb-commits] [lldb] [LLDB][NFC]Renaming functions to be consistent with LLDB naming style (PR #128574)

2025-02-24 Thread Vy Nguyen via lldb-commits

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


[Lldb-commits] [lldb] 62ec7b8 - [LLDB][NFC]Renaming functions to be consistent with LLDB naming style (#128574)

2025-02-24 Thread via lldb-commits

Author: Vy Nguyen
Date: 2025-02-24T20:21:16-05:00
New Revision: 62ec7b8de97a197c2522177a52bdc78205579930

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

LOG: [LLDB][NFC]Renaming functions to be consistent with LLDB naming style 
(#128574)

Added: 


Modified: 
lldb/include/lldb/Core/Telemetry.h
lldb/source/Core/Telemetry.cpp
lldb/unittests/Core/TelemetryTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index b72556ecaf3c9..3bf38dac04c3d 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -64,12 +64,12 @@ class TelemetryManager : public llvm::telemetry::Manager {
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override;
 
   virtual llvm::StringRef GetInstanceName() const = 0;
-  static TelemetryManager *getInstance();
+  static TelemetryManager *GetInstance();
 
 protected:
   TelemetryManager(std::unique_ptr config);
 
-  static void setInstance(std::unique_ptr manger);
+  static void SetInstance(std::unique_ptr manger);
 
 private:
   std::unique_ptr m_config;

diff  --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 5222f76704f91..a0c9fb83e3a6b 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -67,9 +67,9 @@ llvm::Error TelemetryManager::preDispatch(TelemetryInfo 
*entry) {
 }
 
 std::unique_ptr TelemetryManager::g_instance = nullptr;
-TelemetryManager *TelemetryManager::getInstance() { return g_instance.get(); }
+TelemetryManager *TelemetryManager::GetInstance() { return g_instance.get(); }
 
-void TelemetryManager::setInstance(std::unique_ptr manager) {
+void TelemetryManager::SetInstance(std::unique_ptr manager) {
   g_instance = std::move(manager);
 }
 

diff  --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
index 0f2eaccb21a2c..3ee6451429619 100644
--- a/lldb/unittests/Core/TelemetryTest.cpp
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -63,10 +63,10 @@ class FakePlugin : public telemetry::TelemetryManager {
   }
 
   static void Initialize() {
-telemetry::TelemetryManager::setInstance(std::make_unique());
+telemetry::TelemetryManager::SetInstance(std::make_unique());
   }
 
-  static void Terminate() { telemetry::TelemetryManager::setInstance(nullptr); 
}
+  static void Terminate() { telemetry::TelemetryManager::SetInstance(nullptr); 
}
 };
 
 } // namespace lldb_private
@@ -76,7 +76,7 @@ TEST(TelemetryTest, PluginTest) {
   // For tests, we just call it directly.
   lldb_private::FakePlugin::Initialize();
 
-  auto *ins = lldb_private::telemetry::TelemetryManager::getInstance();
+  auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance();
   ASSERT_NE(ins, nullptr);
 
   std::vector expected_entries;



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


[Lldb-commits] [lldb] 911e94c - [lldb-dap] Finish refactoring the request handlers (NFC) (#128553)

2025-02-24 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-02-24T16:46:12-06:00
New Revision: 911e94c6516926b462bc6d1d4a77dcc701b7e3db

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

LOG: [lldb-dap] Finish refactoring the request handlers (NFC) (#128553)

Completes the work started in #128262. This PR removes the
old way of register request handlers with callbacks and makes
the operator const.

Added: 


Modified: 
lldb/tools/lldb-dap/DAP.cpp
lldb/tools/lldb-dap/DAP.h
lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp
lldb/tools/lldb-dap/Handler/BreakpointLocationsHandler.cpp
lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/CompletionsHandler.cpp
lldb/tools/lldb-dap/Handler/ConfigurationDoneRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ContinueRequestHandler.cpp
lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp
lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp
lldb/tools/lldb-dap/Handler/DisconnectRequestHandler.cpp
lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp
lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
lldb/tools/lldb-dap/Handler/LaunchRequestHandler.cpp
lldb/tools/lldb-dap/Handler/LocationsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ModulesRequestHandler.cpp
lldb/tools/lldb-dap/Handler/NextRequestHandler.cpp
lldb/tools/lldb-dap/Handler/PauseRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ReadMemoryRequestHandler.cpp
lldb/tools/lldb-dap/Handler/RequestHandler.cpp
lldb/tools/lldb-dap/Handler/RequestHandler.h
lldb/tools/lldb-dap/Handler/RestartRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ScopesRequestHandler.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/Handler/SetVariableRequestHandler.cpp
lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StackTraceRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StepInRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StepInTargetsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/StepOutRequestHandler.cpp
lldb/tools/lldb-dap/Handler/TestGetTargetBreakpointsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp
lldb/tools/lldb-dap/Handler/VariablesRequestHandler.cpp
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index c966f4cfae027..01f294e14de6a 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -755,20 +755,12 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
   if (packet_type == "request") {
 const auto command = GetString(object, "command");
 
-// Try the new request handler first.
-auto new_handler_pos = new_request_handlers.find(command);
-if (new_handler_pos != new_request_handlers.end()) {
+auto new_handler_pos = request_handlers.find(command);
+if (new_handler_pos != request_handlers.end()) {
   (*new_handler_pos->second)(object);
   return true; // Success
 }
 
-// FIXME: Remove request_handlers once everything has been migrated.
-auto handler_pos = request_handlers.find(command);
-if (handler_pos != request_handlers.end()) {
-  handler_pos->second(*this, object);
-  return true; // Success
-}
-
 if (log)
   *log << "error: unhandled command \"" << command.data() << "\""
<< std::endl;
@@ -901,11 +893,6 @@ void DAP::SendReverseRequest(llvm::StringRef command,
   });
 }
 
-void DAP::RegisterRequestCallback(std::string request,
-  RequestCallback callback) {
-  request_handlers[request] = callback;
-}
-
 lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
   lldb::SBError error;
   lldb::SBProcess process = target.GetProcess();

diff  --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 1cc0170637c15..f87841a56f4d3 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -68,7 +68,6 @@ enum DAPBroadcasterBits {
   eBroadcastBitStopProgressThread = 1u << 1
 };
 
-typedef void (*RequestCallback)(DAP &dap, const llvm::json::Object &command);
 typedef void (*ResponseCallback)(llvm::Expected value);
 
 enum class PacketStatus {
@@ -190,8 +189,7 @@ struct DAP {
   // the old process here so we can detect this case and keep running.
   lldb::pid_t restarting_

[Lldb-commits] [lldb] [lldb-dap] Refactor breakpoint related request handlers (NFC) (PR #128550)

2025-02-24 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-remote-linux-ubuntu` 
running on `as-builder-9` while building `lldb` at step 16 
"test-check-lldb-api".

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


Here is the relevant piece of the build log for the reference

```
Step 16 (test-check-lldb-api) failure: Test just built components: 
check-lldb-api completed (failure)
...
PASS: lldb-api :: python_api/watchpoint/watchlocation/TestTargetWatchAddress.py 
(1224 of 1233)
PASS: lldb-api :: types/TestCharTypeExpr.py (1225 of 1233)
PASS: lldb-api :: types/TestIntegerType.py (1226 of 1233)
PASS: lldb-api :: types/TestRecursiveTypes.py (1227 of 1233)
PASS: lldb-api :: types/TestIntegerTypeExpr.py (1228 of 1233)
PASS: lldb-api :: types/TestShortType.py (1229 of 1233)
PASS: lldb-api :: types/TestShortTypeExpr.py (1230 of 1233)
PASS: lldb-api :: types/TestLongTypes.py (1231 of 1233)
PASS: lldb-api :: types/TestLongTypesExpr.py (1232 of 1233)
TIMEOUT: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py (1233 
of 1233)
 TEST 'lldb-api :: 
python_api/process/cancel_attach/TestCancelAttach.py' FAILED 

Script:
--
/usr/bin/python3.12 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib
 --env 
LLVM_INCLUDE_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include
 --env 
LLVM_TOOLS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin
 --libcxx-include-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/c++/v1
 --libcxx-include-target-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/aarch64-unknown-linux-gnu/c++/v1
 --libcxx-library-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib/aarch64-unknown-linux-gnu
 --arch aarch64 --build-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex
 --lldb-module-cache-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/lldb 
--compiler 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang 
--dsymutil 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/dsymutil
 --make /usr/bin/gmake --llvm-tools-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin 
--lldb-obj-root 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb 
--lldb-libs-dir 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib 
--platform-url connect://jetson-agx-2198.lab.llvm.org:1234 
--platform-working-dir /home/ubuntu/lldb-tests --sysroot 
/mnt/fs/jetson-agx-ubuntu --env ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name 
remote-linux --skip-category=lldb-server 
/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/python_api/process/cancel_attach
 -p TestCancelAttach.py
--
Exit Code: -9
Timeout: Reached timeout of 600 seconds

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
d3623194044452e2f1b4e81c213bc8cbbe49c2a8)
  clang revision d3623194044452e2f1b4e81c213bc8cbbe49c2a8
  llvm revision d3623194044452e2f1b4e81c213bc8cbbe49c2a8

--
Command Output (stderr):
--
WARNING:root:Custom libc++ is not supported for remote runs: ignoring --libcxx 
arguments
FAIL: LLDB 
(/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang-aarch64)
 :: test_scripted_implementation 
(TestCancelAttach.AttachCancelTestCase.test_scripted_implementation)

--


Slowest Tests:
--
600.04s: lldb-api :: python_api/process/cancel_attach/TestCancelAttach.py
180.96s: lldb-api :: commands/command/script_alias/TestCommandScriptAlias.py
70.50s: lldb-api :: commands/process/attach/TestProcessAttach.py
40.85s: lldb-api :: 
functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
34.60s: lldb-api :: functionalities/completion/TestCompletion.py
34.07s: lldb-api :: 
functionalities/single-thread-step/TestSingleThreadStepTimeout.py
21.69s: lldb-api :: 
python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
20.67s: lldb-api :: functionalities/gdb_remote_client/TestPlatformClient.py
20.43s: lldb-api :: commands/statistics/basic/TestStats.py
19.10s: lldb-api :: functionalities/thread/state/TestThreadStates.py
18.26s: lldb-api :: commands/dwim-print/TestDWIMPrint.py
1

[Lldb-commits] [lldb] [lldb-dap] Finish refactoring the request handlers (NFC) (PR #128553)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] ccbb888 - [lldb] do not show misleading error when there is no frame (#119103)

2025-02-24 Thread via lldb-commits

Author: oltolm
Date: 2025-02-24T17:52:09-06:00
New Revision: ccbb8882ac75e73e23f31ad60588a2914ebeef04

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

LOG: [lldb] do not show misleading error when there is no frame (#119103)

I am using VSCode with the official vscode-lldb extension. When I try to
list the breakpoints in the debug console get the message:

```
br list
can't evaluate expressions when the process is running.
```

I know that this is wrong and you need to use
```
`br list
(lldb) br list
No breakpoints currently set.
```
but the error message is misleading. I cleaned up the code and now the
error message is

```
br list
sbframe object is not valid.
```
which is still not perfect, but at least it's not misleading.

Added: 


Modified: 
lldb/source/API/SBFrame.cpp
lldb/test/API/python_api/run_locker/TestRunLocker.py

Removed: 




diff  --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 2300bec4d685d..5b69cf1ee2641 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1012,33 +1012,26 @@ bool SBFrame::GetDescription(SBStream &description) {
 SBValue SBFrame::EvaluateExpression(const char *expr) {
   LLDB_INSTRUMENT_VA(this, expr);
 
-  SBValue result;
   std::unique_lock lock;
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
 
   StackFrame *frame = exe_ctx.GetFramePtr();
   Target *target = exe_ctx.GetTargetPtr();
+  SBExpressionOptions options;
   if (frame && target) {
-SBExpressionOptions options;
 lldb::DynamicValueType fetch_dynamic_value =
 frame->CalculateTarget()->GetPreferDynamicValue();
 options.SetFetchDynamicValue(fetch_dynamic_value);
-options.SetUnwindOnError(true);
-options.SetIgnoreBreakpoints(true);
-SourceLanguage language = target->GetLanguage();
-if (!language)
-  language = frame->GetLanguage();
-options.SetLanguage((SBSourceLanguageName)language.name, language.version);
-return EvaluateExpression(expr, options);
-  } else {
-Status error;
-error = Status::FromErrorString("can't evaluate expressions when the "
-"process is running.");
-ValueObjectSP error_val_sp =
-ValueObjectConstResult::Create(nullptr, std::move(error));
-result.SetSP(error_val_sp, false);
   }
-  return result;
+  options.SetUnwindOnError(true);
+  options.SetIgnoreBreakpoints(true);
+  SourceLanguage language;
+  if (target)
+language = target->GetLanguage();
+  if (!language && frame)
+language = frame->GetLanguage();
+  options.SetLanguage((SBSourceLanguageName)language.name, language.version);
+  return EvaluateExpression(expr, options);
 }
 
 SBValue

diff  --git a/lldb/test/API/python_api/run_locker/TestRunLocker.py 
b/lldb/test/API/python_api/run_locker/TestRunLocker.py
index d525bbf6b406f..b7b4941214e86 100644
--- a/lldb/test/API/python_api/run_locker/TestRunLocker.py
+++ b/lldb/test/API/python_api/run_locker/TestRunLocker.py
@@ -107,6 +107,4 @@ def runlocker_test(self, stop_at_entry):
 "script var = lldb.frame.EvaluateExpression('SomethingToCall()'); 
var.GetError().GetCString()",
 result,
 )
-self.assertIn(
-"can't evaluate expressions when the process is running", 
result.GetOutput()
-)
+self.assertIn("sbframe object is not valid", result.GetOutput())



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


[Lldb-commits] [lldb] [lldb][NFC] Fix comment in lldb/Core/ModuleList.h (PR #128602)

2025-02-24 Thread Julian Lettner via lldb-commits

https://github.com/yln created https://github.com/llvm/llvm-project/pull/128602

None

>From 7df56dcd54371b95baf607efb583ccd420b0570e Mon Sep 17 00:00:00 2001
From: Julian Lettner 
Date: Mon, 24 Feb 2025 15:55:11 -0800
Subject: [PATCH] [lldb][NFC] Fix comment in lldb/Core/ModuleList.h

---
 lldb/include/lldb/Core/ModuleList.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index 29b87de88520d..909ee08f9ba62 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -326,11 +326,11 @@ class ModuleList {
   void FindGlobalVariables(const RegularExpression ®ex, size_t max_matches,
VariableList &variable_list) const;
 
-  /// Finds the first module whose file specification matches \a file_spec.
+  /// Finds modules whose file specification matches \a module_spec.
   ///
   /// \param[in] module_spec
   /// A file specification object to match against the Module's
-  /// file specifications. If \a file_spec does not have
+  /// file specifications. If \a module_spec does not have
   /// directory information, matches will occur by matching only
   /// the basename of any modules in this list. If this value is
   /// NULL, then file specifications won't be compared when
@@ -351,6 +351,7 @@ class ModuleList {
   // UUID values is very efficient and accurate.
   lldb::ModuleSP FindModule(const UUID &uuid) const;
 
+  /// Finds the first module whose file specification matches \a module_spec.
   lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const;
 
   void FindSymbolsWithNameAndType(ConstString name,

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


[Lldb-commits] [lldb] [WIP] [lldb][TypeSystemClang] Create clang::SourceLocation from DWARF and attach to AST (PR #127829)

2025-02-24 Thread Adrian Prantl via lldb-commits

adrian-prantl wrote:

Do we only pay the cost when a diagnostic is generated, or every time a 
DW_AT_file is parsed?

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


[Lldb-commits] [lldb] [lldb] Add fzf_history command to examples (PR #128571)

2025-02-24 Thread Dave Lee via lldb-commits

https://github.com/kastiglione updated 
https://github.com/llvm/llvm-project/pull/128571

>From 57638e91c97486ad7739f9658fe88f7fb4d61fb2 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:48:17 -0800
Subject: [PATCH 1/5] [lldb] Add fzf_history command to examples

---
 lldb/examples/python/fzf_history.py | 99 +
 1 file changed, 99 insertions(+)
 create mode 100644 lldb/examples/python/fzf_history.py

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
new file mode 100644
index 0..4647a3532b0df
--- /dev/null
+++ b/lldb/examples/python/fzf_history.py
@@ -0,0 +1,99 @@
+import os
+import re
+import sys
+import subprocess
+
+import lldb
+
+
+@lldb.command()
+def fzf_history(debugger, cmdstr, ctx, result, _):
+if sys.platform != 'darwin':
+result.SetError("fzf_history supports macOS only")
+return
+
+# Capture the current pasteboard contents to restore after overwriting.
+paste_snapshot = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+
+# On enter, copy the selected history entry into the pasteboard.
+fzf_command = (
+"fzf",
+"--no-sort",
+f"--query={cmdstr}",
+"--bind=enter:execute-silent(echo -n {} | pbcopy)+close",
+)
+
+history_file = os.path.expanduser("~/.lldb/lldb-widehistory")
+if not os.path.exists(history_file):
+result.SetError("history file does not exist")
+return
+
+history_commands = _load_history(history_file)
+fzf_input = "\n".join(history_commands)
+completed = subprocess.run(fzf_command, input=fzf_input, text=True)
+# 130 is used for CTRL-C or ESC.
+if completed.returncode not in (0, 130):
+result.SetError(f"fzf failed: {completed.stderr}")
+return
+
+# Get the user's selected history entry.
+selected_command = subprocess.run("pbpaste", text=True, 
capture_output=True).stdout
+if selected_command == paste_snapshot:
+# Nothing was selected, no cleanup needed.
+return
+
+_handle_command(debugger, selected_command)
+
+# Restore the pasteboard's contents.
+subprocess.run("pbcopy", input=paste_snapshot, text=True)
+
+
+def _handle_command(debugger, command):
+"""Try pasting the command, and failing that, run it directly."""
+if not command:
+return
+
+# Use applescript to paste the selected result into lldb's console.
+paste_command = (
+"osascript",
+"-e",
+'tell application "System Events" to keystroke "v" using command down',
+)
+completed = subprocess.run(paste_command, capture_output=True)
+
+if completed.returncode != 0:
+# The above applescript requires the "control your computer" 
permission.
+# Settings > Private & Security > Accessibility
+# If not enabled, fallback to running the command.
+debugger.HandleCommand(command)
+
+
+def _load_history(history_file):
+"""Load, decode, and parse an lldb history file."""
+with open(history_file) as f:
+history_contents = f.read()
+
+history_decoded = re.sub(r"\\0([0-7][0-7])", _decode_char, 
history_contents)
+history_lines = history_decoded.splitlines()
+
+# Skip the header line (_HiStOrY_V2_)
+del history_lines[0]
+# Reverse to show latest first.
+history_lines.reverse()
+
+history_commands = []
+history_seen = set()
+for line in history_lines:
+line = line.strip()
+# Skip empty lines, single character commands, and duplicates.
+if line and len(line) > 1 and line not in history_seen:
+history_commands.append(line)
+history_seen.add(line)
+
+return history_commands
+
+
+def _decode_char(match):
+"""Decode octal strings ('\0NN') into a single character string."""
+code = int(match.group(1), base=8)
+return chr(code)

>From d1106bc7165d8a62a1805ec09afdf62e5b7f09ff Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:56:35 -0800
Subject: [PATCH 2/5] Fix code formatting

---
 lldb/examples/python/fzf_history.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index 4647a3532b0df..b683078465985 100644
--- a/lldb/examples/python/fzf_history.py
+++ b/lldb/examples/python/fzf_history.py
@@ -8,7 +8,7 @@
 
 @lldb.command()
 def fzf_history(debugger, cmdstr, ctx, result, _):
-if sys.platform != 'darwin':
+if sys.platform != "darwin":
 result.SetError("fzf_history supports macOS only")
 return
 

>From 7fb2bfc015e1550dde6f3d54e932e8bc6ccbe0f7 Mon Sep 17 00:00:00 2001
From: Dave Lee 
Date: Mon, 24 Feb 2025 12:59:08 -0800
Subject: [PATCH 3/5] Add docstring for fzf_history

---
 lldb/examples/python/fzf_history.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/examples/python/fzf_history.py 
b/lldb/examples/python/fzf_history.py
index

[Lldb-commits] [lldb] [lldb] do not show misleading error when there is no frame (PR #119103)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][NFC]Renaming functions to be consistent with LLDB naming style (PR #128574)

2025-02-24 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb-dap] Refactor request handlers (NFC) (PR #128262)

2025-02-24 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

I am thinking about how would this new approach work if we started executing 
requests in parallel (I know we're not planning to do that now, but this sort 
of started out from that), and it seems to me that the this design (a 
"singleton" object with a non-const member) isn't the best design for that. I 
think this could be improved in at least two ways, but the choice  depends on 
which way we'd like to take this:
- option one is to make operator() `const`. This guarantees the implementation 
doesn't store any information about the currently processed request in the 
object itself. This prevents "leaking" of data from one request into another 
and as a consequence, makes the object safe to use concurrently
- option two is to create a new handler object for request. This takes the 
opposite approach and actually encourages to (transiently) store information 
about the current request in the handler object (but then makes it safe by 
making sure the information is compartmentalized)

I don't want to make a choice here, since it depends on where you (the people 
who are actually going to be working on this) want to take this, but I think it 
would good to make a choice here, even if it gets changed later. The first 
approach (make the method const) would be most similar to status quo (because a 
free function doesn't even have an object to store information to), so maybe 
that could be the default?

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-24 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,308 @@
+//===-- DILParser.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
+//
+// This implements the recursive descent parser for the Data Inspection
+// Language (DIL), and its helper functions, which will eventually underlie the
+// 'frame variable' command. The language that this parser recognizes is
+// described in lldb/docs/dil-expr-lang.ebnf
+//
+//===--===//
+
+#include "lldb/ValueObject/DILParser.h"
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILEval.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k) {
+  os << "'" << Token::GetTokenName(k).str() << "'";
+}
+
+template 
+inline void TokenKindsJoinImpl(std::ostringstream &os, Token::Kind k,
+   Ts... ks) {
+  TokenKindsJoinImpl(os, k);
+  os << ", ";
+  TokenKindsJoinImpl(os, ks...);
+}
+
+template 
+inline std::string TokenKindsJoin(Token::Kind k, Ts... ks) {
+  std::ostringstream os;
+  TokenKindsJoinImpl(os, k, ks...);
+
+  return os.str();
+}
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc) {
+  // Get the source buffer and the location of the current token.
+  size_t loc_offset = (size_t)loc;
+
+  // Look for the start of the line.
+  size_t line_start = text.rfind('\n', loc_offset);
+  line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
+
+  // Look for the end of the line.
+  size_t line_end = text.find('\n', loc_offset);
+  line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
+
+  // Get a view of the current line in the source code and the position of the
+  // diagnostics pointer.
+  llvm::StringRef line = text.slice(line_start, line_end);
+  int32_t arrow = loc + 1; // Column offset starts at 1, not 0.
+
+  // Calculate the padding in case we point outside of the expression (this can
+  // happen if the parser expected something, but got EOF).˚
+  size_t expr_rpad = std::max(0, arrow - static_cast(line.size()));
+  size_t arrow_rpad = std::max(0, static_cast(line.size()) - arrow);
+
+  return llvm::formatv(": {1}\n{2}\n{3}", loc, message,
+   llvm::fmt_pad(line, 0, expr_rpad),
+   llvm::fmt_pad("^", arrow - 1, arrow_rpad));
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr exe_ctx_scope,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member)
+: m_ctx_scope(exe_ctx_scope), m_input_expr(dil_input_expr),
+  m_dil_lexer(lexer), m_dil_token(lexer.GetCurrentToken()),
+  m_use_dynamic(use_dynamic), m_use_synthetic(use_synthetic),
+  m_fragile_ivar(fragile_ivar), m_check_ptr_vs_member(check_ptr_vs_member) 
{
+}
+
+llvm::Expected DILParser::Run() {
+  DILASTNodeUP expr;
+
+  expr = ParseExpression();
+
+  Expect(Token::Kind::eof);
+
+  if (m_error.Fail())
+return m_error.ToError();
+
+  return expr;
+}
+
+// Parse an expression.
+//
+//  expression:
+//primary_expression
+//
+DILASTNodeUP DILParser::ParseExpression() { return ParsePrimaryExpression(); }
+
+// Parse a primary_expression.
+//
+//  primary_expression:
+//id_expression
+//"this"
+//"(" expression ")"
+//
+DILASTNodeUP DILParser::ParsePrimaryExpression() {
+  if (m_dil_token.IsOneOf(Token::coloncolon, Token::identifier)) {
+// Save the source location for the diagnostics message.
+uint32_t loc = m_dil_token.GetLocation();
+auto identifier = ParseIdExpression();
+
+return std::make_unique(loc, identifier, m_use_dynamic,
+m_ctx_scope);
+  } else if (m_dil_token.Is(Token::l_paren)) {
+ConsumeToken();
+auto expr = ParseExpression();
+Expect(Token::r_paren);
+ConsumeToken();
+return expr;
+  }
+
+  BailOut(ErrorCode::kInvalidExpressionSyntax,
+  llvm::formatv("Unexpected token: {0}", 
TokenDescription(m_dil_token)),
+  m_dil_token.GetLocation());
+  return std::make_unique();
+}
+
+// Parse nested_name_specifier.
+//
+//  nested_name_specifier:
+//type_name "::"
+//namespace_name "::"
+//nested_name_specifier identifier "::"
+//
+std::string DILParser::ParseNestedNameSpecifier() {
+  // The first token in nested_name_specifier is always an identifier, or
+  // '(anonymous namespace)'.
+  if (m_dil_token.IsNot(Token::identifier) &&
+  m_dil_toke

[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-24 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,244 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(VariableList &variable_list,
+   std::shared_ptr exe_scope,
+   llvm::StringRef name_ref,
+   llvm::StringRef unqualified_name) {
+  // First look for an exact match to the (possibly) qualified name.
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope.get(), var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  // If the qualified name is the same as the unqualfied name, there's nothing
+  // more to be done.
+  if (name_ref == unqualified_name)
+return nullptr;
+
+  // We didn't match the qualified name; try to match the unqualified name.
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope.get(), var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(ConstString(unqualified_name
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  str_ref_name.consume_front("::");
+  if (str_ref_name == name.GetStringRef()) {
+exact_match = var_sp;
+break;
+  }
+}
+
+  if (!exact_match && possible_matches.size() == 1)
+exact_match = possible_matches[0];
+
+  return exact_match;
+}
+
+std::unique_ptr
+LookupIdentifier(llvm::StringRef name_ref,
+ std::shared_ptr ctx_scope,
+ lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic,
+ CompilerType *scope_ptr) {
+  // Support $rax as a special syntax for accessing registers.
+  // Will return an invalid value in case the requested register doesn't exist.
+  if (name_ref.consume_front("$")) {
+lldb::ValueObjectSP value_sp;
+Process *process = ctx_scope->CalculateProcess().get();
+if (!target_sp || !process)
+  return nullptr;
+
+StackFrame *stack_frame = (StackFrame *)ctx_scope.get();
+if (!stack_frame)
+  return nullptr;
+
+lldb::RegisterContextSP reg_ctx(stack_frame->GetRegisterContext());
+if (!reg_ctx)
+  return nullptr;
+
+if (const RegisterInfo *reg_info = 
reg_ctx->GetRegisterInfoByName(name_ref))
+  value_sp = ValueObjectRegister::Create(stack_frame, reg_ctx, reg_info);
+
+if (value_sp)
+  return IdentifierInfo::FromValue(*value_sp);
+
+return nullptr;
+  }
+
+  lldb::StackFrameSP frame = ctx_scope->CalculateStackFrame();
+  lldb::VariableListSP var_list_sp(frame->GetInScopeVariableList(true));
+  VariableList *variable_list = var_list_sp.get();

labath wrote:

you don't need the extra variable `*var_list_sp` and `var_list_sp->foo()` works 
just fine.

https://github.com/llvm/llvm-project/pull/120971
___
l

[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-24 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-24 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

I think I can live with looking up global variables in the current compile 
unit, as it's pretty clear these are the variables that should be looked at 
before any other CUs/modules. We will probably want to look up those as well 
(bring back the FindGlobalVariables call), but I think it's much more important 
to reach a point where we can replace/delete the current `frame variable` 
implementation (and we don't need globals for that).

That said I think it would be better to fetch globals separately instead of 
bunching them all in one list and then filtering it out. What 
`GetInScopeVariableList` does when the `get_file_globals` argument is set is 
basically to call `CompileUnit::GetVariableList())` and append that to the 
result. So, I think we could just set that argument to false, and then 
separately call that function to get just the globals.

This will also make sure we only construct the global variables when they are 
actually needed. (This is an optimization that I think makes sense, since 
parsing a global variable is a much more complicated operation than parsing a 
string)


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


[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)

2025-02-24 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,244 @@
+//===-- DILEval.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/ValueObject/DILEval.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/ValueObject/ValueObjectRegister.h"
+#include "lldb/ValueObject/ValueObjectVariable.h"
+#include "llvm/Support/FormatAdapters.h"
+#include 
+
+namespace lldb_private::dil {
+
+static lldb::ValueObjectSP
+LookupStaticIdentifier(VariableList &variable_list,
+   std::shared_ptr exe_scope,
+   llvm::StringRef name_ref,
+   llvm::StringRef unqualified_name) {
+  // First look for an exact match to the (possibly) qualified name.
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope.get(), var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(ConstString(name_ref
+  return valobj_sp;
+  }
+
+  // If the qualified name is the same as the unqualfied name, there's nothing
+  // more to be done.
+  if (name_ref == unqualified_name)
+return nullptr;
+
+  // We didn't match the qualified name; try to match the unqualified name.
+  for (const lldb::VariableSP &var_sp : variable_list) {
+lldb::ValueObjectSP valobj_sp(
+ValueObjectVariable::Create(exe_scope.get(), var_sp));
+if (valobj_sp && valobj_sp->GetVariable() &&
+(valobj_sp->GetVariable()->NameMatches(ConstString(unqualified_name
+  return valobj_sp;
+  }
+
+  return nullptr;
+}
+
+static lldb::VariableSP DILFindVariable(ConstString name,
+VariableList *variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  typedef std::vector collection;
+  typedef collection::iterator iterator;
+
+  iterator pos, end = variable_list->end();
+  for (pos = variable_list->begin(); pos != end; ++pos) {
+llvm::StringRef str_ref_name = pos->get()->GetName().GetStringRef();
+// Check for global vars, which might start with '::'.
+str_ref_name.consume_front("::");
+
+if (str_ref_name == name.GetStringRef())
+  possible_matches.push_back(*pos);
+else if (pos->get()->NameMatches(name))
+  possible_matches.push_back(*pos);
+  }
+
+  // Look for exact matches (favors local vars over global vars)
+  auto exact_match_it =
+  llvm::find_if(possible_matches, [&](lldb::VariableSP var_sp) {
+return var_sp->GetName() == name;
+  });
+
+  if (exact_match_it != llvm::adl_end(possible_matches))
+exact_match = *exact_match_it;
+
+  if (!exact_match)
+// Look for a global var exact match.
+for (auto var_sp : possible_matches) {
+  llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
+  str_ref_name.consume_front("::");
+  if (str_ref_name == name.GetStringRef()) {
+exact_match = var_sp;
+break;
+  }
+}
+
+  if (!exact_match && possible_matches.size() == 1)
+exact_match = possible_matches[0];
+
+  return exact_match;
+}
+
+std::unique_ptr
+LookupIdentifier(llvm::StringRef name_ref,
+ std::shared_ptr ctx_scope,
+ lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic,
+ CompilerType *scope_ptr) {
+  // Support $rax as a special syntax for accessing registers.
+  // Will return an invalid value in case the requested register doesn't exist.
+  if (name_ref.consume_front("$")) {
+lldb::ValueObjectSP value_sp;
+Process *process = ctx_scope->CalculateProcess().get();
+if (!target_sp || !process)
+  return nullptr;

labath wrote:

I think these aren't used now.

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


  1   2   >