[Lldb-commits] [lldb] [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI (PR #133309)

2025-03-27 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 fbf0276b6a7a7a4508c373cf87fc349569652659 
d5840447a35992530963ae910615b1908e2880d2 --extensions cpp -- 
lldb/source/Core/Debugger.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index cf247974ad..fbbe3d6293 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -2024,7 +2024,8 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
   }
 }
   } else if (broadcaster == &m_broadcaster) {
-if (event_type & lldb::eBroadcastBitProgress || event_type & 
lldb::eBroadcastBitExternalProgress)
+if (event_type & lldb::eBroadcastBitProgress ||
+event_type & lldb::eBroadcastBitExternalProgress)
   HandleProgressEvent(event_sp);
 else if (event_type & lldb::eBroadcastBitWarning)
   HandleDiagnosticEvent(event_sp);

``




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


[Lldb-commits] [lldb] [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI (PR #133309)

2025-03-27 Thread Jacob Lalonde via lldb-commits

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

>From d55d7e328300134c723cbc7d0f67ac8c1309ebbb Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Thu, 27 Mar 2025 13:15:46 -0700
Subject: [PATCH] Configure sbprogress events to be emitted for the CLI

---
 lldb/source/Core/Debugger.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 8c705f889983a..fbbe3d62937ba 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -2024,7 +2024,8 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
   }
 }
   } else if (broadcaster == &m_broadcaster) {
-if (event_type & lldb::eBroadcastBitProgress)
+if (event_type & lldb::eBroadcastBitProgress ||
+event_type & lldb::eBroadcastBitExternalProgress)
   HandleProgressEvent(event_sp);
 else if (event_type & lldb::eBroadcastBitWarning)
   HandleDiagnosticEvent(event_sp);

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


[Lldb-commits] [lldb] [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI (PR #133309)

2025-03-27 Thread Jacob Lalonde via lldb-commits

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


[Lldb-commits] [lldb] [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI (PR #133309)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

LGTM!

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


[Lldb-commits] [lldb] 0d4f12e - [lldb-dap] Allow providing debug adapter arguments in the extension (#129262)

2025-03-27 Thread via lldb-commits

Author: Matthew Bastien
Date: 2025-03-27T14:09:09-07:00
New Revision: 0d4f12ee0046b83d28dbf3a8aca07a0f27b77786

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

LOG: [lldb-dap] Allow providing debug adapter arguments in the extension 
(#129262)

Added a new setting called `lldb-dap.arguments` and a debug
configuration attribute called `debugAdapterArgs` that can be used to
set the arguments used to launch the debug adapter. Right now this is
mostly useful for debugging purposes to add the `--wait-for-debugger`
option to lldb-dap.

Additionally, the extension will now check for a changed lldb-dap
executable or arguments when launching a debug session in server mode. I
had to add a new `DebugConfigurationProvider` to do this because VSCode
will show an unhelpful error modal when the
`DebugAdapterDescriptorFactory` returns `undefined`.

In order to facilitate this, I had to add two new properties to the
launch configuration that are used by the
`DebugAdapterDescriptorFactory` to tell VS Code how to launch the debug
adapter:

- `debugAdapterHostname` - the hostname for an existing lldb-dap server
- `debugAdapterPort` - the port for an existing lldb-dap server

I've also removed the check for the `executable` argument in
`LLDBDapDescriptorFactory.createDebugAdapterDescriptor()`. This argument
is only set by VS Code when the debug adapter executable properties are
set in the `package.json`. The LLDB DAP extension does not currently do
this (and I don't think it ever will). So, this makes the debug adapter
descriptor factory a little easier to read.

The check for whether or not `lldb-dap` exists has been moved into the
new `DebugConfigurationProvider` as well. This way the extension won't
get in the user's way unless they actually try to start a debugging
session. The error will show up as a modal which will also make it more
obvious when something goes wrong, rather than popping up as a warning
at the bottom right of the screen.

Added: 
lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts
lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts
lldb/tools/lldb-dap/src-ts/ui/error-with-notification.ts
lldb/tools/lldb-dap/src-ts/ui/show-error-message.ts

Modified: 
lldb/tools/lldb-dap/package.json
lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
lldb/tools/lldb-dap/src-ts/extension.ts

Removed: 




diff  --git a/lldb/tools/lldb-dap/package.json 
b/lldb/tools/lldb-dap/package.json
index cb4b1f1aa22ce..289e07c12682c 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -76,6 +76,15 @@
   "type": "string",
   "description": "The path to the lldb-dap binary."
 },
+"lldb-dap.arguments": {
+  "scope": "resource",
+  "type": "array",
+  "default": [],
+  "items": {
+"type": "string"
+  },
+  "description": "The list of additional arguments used to launch the 
debug adapter executable."
+},
 "lldb-dap.log-path": {
   "scope": "resource",
   "type": "string",
@@ -149,19 +158,30 @@
   {
 "type": "lldb-dap",
 "label": "LLDB DAP Debugger",
-"program": "./bin/lldb-dap",
-"windows": {
-  "program": "./bin/lldb-dap.exe"
-},
 "configurationAttributes": {
   "launch": {
 "required": [
   "program"
 ],
 "properties": {
+  "debugAdapterHostname": {
+"type": "string",
+"markdownDescription": "The hostname that an existing lldb-dap 
executable is listening on."
+  },
+  "debugAdapterPort": {
+"type": "number",
+"markdownDescription": "The port that an existing lldb-dap 
executable is listening on."
+  },
   "debugAdapterExecutable": {
 "type": "string",
-"markdownDescription": "The absolute path to the LLDB debug 
adapter executable to use."
+"markdownDescription": "The absolute path to the LLDB debug 
adapter executable to use. Overrides any user or workspace settings."
+  },
+  "debugAdapterArgs": {
+"type": "array",
+"items": {
+  "type": "string"
+},
+"markdownDescription": "The list of additional arguments used 
to launch the debug adapter executable. Overrides any user or workspace 
settings."
   },
   "program": {
 "type": "string",
@@ -349,9 +369,24 @@
   },
   "attach": {
 "properties": {
+  "debugAdapterHostname": {
+"type": "string",
+  

[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Alex Langford via lldb-commits


@@ -0,0 +1,48 @@
+//===-- SBMutex.h
+//--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_API_SBLOCK_H
+#define LLDB_API_SBLOCK_H
+
+#include "lldb/API/SBDefines.h"
+#include "lldb/lldb-forward.h"
+#include 
+
+namespace lldb {
+
+/// A general-purpose lock in the SB API. The lock can be locked and unlocked.
+/// The default constructed lock is unlocked, but generally the lock is locked
+/// when it is returned from a class.

bulbazord wrote:

The documentation in this file probably needs to be rewritten.

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


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

2025-03-27 Thread via lldb-commits


@@ -0,0 +1,273 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc, uint16_t err_len) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string arrow_str = "^";
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, text);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  std::vector diagnostics;
+  diagnostics.push_back(detail);
+  StreamString diag_stream(true);
+  RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+  std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+  return ret_str;
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();

cmtice wrote:

(It looks like all the non-protected constructors for llvm::Error require an 
intializer).


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] 2a96bec - [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI (#133309)

2025-03-27 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2025-03-27T14:20:43-07:00
New Revision: 2a96beca9b502776d5e2a3be2da3f886135b056e

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

LOG: [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI 
(#133309)

In the original SBProgress patch, #123837, I didn't ensure the debugger
was broadcasting these events to the CLI as SBProgress has far been
focused on DAP. We had an internal ask to have SBProgress events
broadcasted to the CLI so this patch addresses that.

https://github.com/user-attachments/assets/5eb93a46-1db6-4d46-a6b7-2b2f9bbe71db";
/>

Added: 


Modified: 
lldb/source/Core/Debugger.cpp

Removed: 




diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 993aa2d970de6..ec7f841320217 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -2076,7 +2076,8 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
   }
 }
   } else if (broadcaster == &m_broadcaster) {
-if (event_type & lldb::eBroadcastBitProgress)
+if (event_type & lldb::eBroadcastBitProgress ||
+event_type & lldb::eBroadcastBitExternalProgress)
   HandleProgressEvent(event_sp);
 else if (event_type & lldb::eBroadcastBitWarning)
   HandleDiagnosticEvent(event_sp);



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


[Lldb-commits] [lldb] [lldb-dap] Migrating DAP 'initialize' to new typed RequestHandler. (PR #133007)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

Thanks, I'm happy with this! 

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


[Lldb-commits] [lldb] [SBProgress][CLI] Configure sbprogress events to be emitted for the CLI (PR #133309)

2025-03-27 Thread Greg Clayton via lldb-commits

https://github.com/clayborg commented:

I am fine with this being always enabled. I will defer to Jonas to make sure he 
is

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


[Lldb-commits] [lldb] [lldb] Improve default statusline colors to work with more color schemes (PR #133315)

2025-03-27 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Use the reverse video [1] font effect (`${ansi.negative}`) as the default for 
the statusline. Inverting the foreground and background color has a better 
change as looking reasonably good, compared to picking an arbitrary color.

[1] https://en.wikipedia.org/wiki/Reverse_video

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


1 Files Affected:

- (modified) lldb/source/Core/CoreProperties.td (+1-1) 


``diff
diff --git a/lldb/source/Core/CoreProperties.td 
b/lldb/source/Core/CoreProperties.td
index 01a04f9e79095..af9eb139f0921 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -178,7 +178,7 @@ let Definition = "debugger" in {
 Desc<"Whether to show a statusline at the bottom of the terminal.">;
   def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
 Global,
-
DefaultStringValue<"${ansi.bg.blue}${ansi.fg.black}{${target.file.basename}}{ | 
${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ 
| {${progress.count} }${progress.message}}">,
+DefaultStringValue<"${ansi.negative}{${target.file.basename}}{ | 
${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ 
| {${progress.count} }${progress.message}}">,
 Desc<"The default statusline format string.">;
   def UseSourceCache: Property<"use-source-cache", "Boolean">,
 Global,

``




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


[Lldb-commits] [lldb] [lldb] Improve default statusline colors to work with more color schemes (PR #133315)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

Use the reverse video [1] font effect (`${ansi.negative}`) as the default for 
the statusline. Inverting the foreground and background color has a better 
change as looking reasonably good, compared to picking an arbitrary color.

[1] https://en.wikipedia.org/wiki/Reverse_video

>From d8c28d82c8dd6ecf5ae93c81265b4e9cf144c2c4 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 27 Mar 2025 13:49:44 -0700
Subject: [PATCH] [lldb] Improve default statusline colors to work with more
 color schemes

Use the reverse video [1] font effect (`${ansi.negative}`) as the
default for the statusline. Inverting the foreground and background
color has a better change as looking reasonably good, compared to
picking an arbitrary color.

[1] https://en.wikipedia.org/wiki/Reverse_video
---
 lldb/source/Core/CoreProperties.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Core/CoreProperties.td 
b/lldb/source/Core/CoreProperties.td
index 01a04f9e79095..af9eb139f0921 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -178,7 +178,7 @@ let Definition = "debugger" in {
 Desc<"Whether to show a statusline at the bottom of the terminal.">;
   def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
 Global,
-
DefaultStringValue<"${ansi.bg.blue}${ansi.fg.black}{${target.file.basename}}{ | 
${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ 
| {${progress.count} }${progress.message}}">,
+DefaultStringValue<"${ansi.negative}{${target.file.basename}}{ | 
${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ 
| {${progress.count} }${progress.message}}">,
 Desc<"The default statusline format string.">;
   def UseSourceCache: Property<"use-source-cache", "Boolean">,
 Global,

___
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-03-27 Thread via lldb-commits


@@ -0,0 +1,273 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc, uint16_t err_len) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string arrow_str = "^";
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, text);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  std::vector diagnostics;
+  diagnostics.push_back(detail);
+  StreamString diag_stream(true);
+  RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+  std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+  return ret_str;
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();

cmtice wrote:

Your suggestion *almost* works, but I get one compiler error, on the 
declaration on line 53 ("llvm::Error error;"). The compiler says: 
```
usr/local/google3/cmtice/llvm-project/lldb/source/ValueObject/DILParser.cpp:57:15:
 error: ‘llvm::Error::Error()’ is protected within this context
   57 |   llvm::Error error;
  |   ^
```

I can fix this by doing: 
```
Status lldb_error;
llvm::Error error(lldb_error.takeError());
```

but that feels pretty hacky.  Is there a better way to do this?

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-03-27 Thread via lldb-commits


@@ -0,0 +1,131 @@
+//===-- DILParser.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_VALUEOBJECT_DILPARSER_H
+#define LLDB_VALUEOBJECT_DILPARSER_H
+
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/Utility/DiagnosticsRendering.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILLexer.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+enum class ErrorCode : unsigned char {
+  kOk = 0,
+  kInvalidExpressionSyntax,
+  kUndeclaredIdentifier,
+  kUnknown,
+};
+
+// The following is modeled on class OptionParseError.
+class DILDiagnosticError
+: public llvm::ErrorInfo {
+  std::vector m_details;
+
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  DILDiagnosticError(DiagnosticDetail detail)
+  : ErrorInfo(std::error_code(EINVAL, std::generic_category())),
+m_details({detail}) {}
+
+  DILDiagnosticError(ErrorCode ec, llvm::StringRef expr,

cmtice wrote:

Done.

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-03-27 Thread via lldb-commits


@@ -0,0 +1,238 @@
+//===-- 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,
+lldb::VariableListSP variable_list) {
+  lldb::VariableSP exact_match;
+  std::vector possible_matches;
+
+  for (lldb::VariableSP var_sp : *variable_list) {
+llvm::StringRef str_ref_name = var_sp->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(var_sp);
+else if (var_sp->NameMatches(name))
+  possible_matches.push_back(var_sp);
+  }
+
+  // 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 != possible_matches.end())
+return *exact_match_it;
+
+  // 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())
+  return var_sp;
+  }
+
+  // If there's a single non-exact match, take it.
+  if (possible_matches.size() == 1)
+return possible_matches[0];
+
+  return nullptr;
+}
+
+lldb::ValueObjectSP LookupGlobalIdentifier(
+llvm::StringRef name_ref, std::shared_ptr stack_frame,
+lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic,
+CompilerType *scope_ptr) {
+  // First look for match in "local" global variables.
+  lldb::VariableListSP 
variable_list(stack_frame->GetInScopeVariableList(true));
+  name_ref.consume_front("::");
+
+  lldb::ValueObjectSP value_sp;
+  if (variable_list) {
+lldb::VariableSP var_sp =
+DILFindVariable(ConstString(name_ref), variable_list);
+if (var_sp)
+  value_sp =
+  stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
+  }
+
+  if (value_sp)
+return value_sp;
+
+  // Also check for static global vars.
+  if (variable_list) {
+const char *type_name = "";
+if (scope_ptr)
+  type_name = scope_ptr->GetCanonicalType().GetTypeName().AsCString();
+std::string name_with_type_prefix =
+llvm::formatv("{0}::{1}", type_name, name_ref).str();
+value_sp = LookupStaticIdentifier(*variable_list, stack_frame,
+  name_with_type_prefix, name_ref);
+if (!value_sp)
+  value_sp = LookupStaticIdentifier(*variable_list, stack_frame, name_ref,
+name_ref);
+  }
+
+  if (value_sp)
+return value_sp;
+
+  // Check for match in modules global variables.
+  VariableList modules_var_list;
+  target_sp->GetImages().FindGlobalVariables(
+  ConstString(name_ref), std::numeric_limits::max(),
+  modules_var_list);
+  if (modules_var_list.Empty())
+return nullptr;
+
+  for (const lldb::VariableSP &var_sp : modules_var_list) {
+std::string qualified_name = llvm::formatv("::{0}", name

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

2025-03-27 Thread via lldb-commits


@@ -0,0 +1,273 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc, uint16_t err_len) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string arrow_str = "^";
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, text);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  std::vector diagnostics;
+  diagnostics.push_back(detail);
+  StreamString diag_stream(true);
+  RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+  std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+  return ret_str;
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member, Status 
&error)
+: m_ctx_scope(frame_sp), m_input_expr(dil_input_expr), m_dil_lexer(lexer),

cmtice wrote:

Done.

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-03-27 Thread via lldb-commits


@@ -0,0 +1,273 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc, uint16_t err_len) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string arrow_str = "^";
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, text);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  std::vector diagnostics;
+  diagnostics.push_back(detail);
+  StreamString diag_stream(true);
+  RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+  std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+  return ret_str;
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();

cmtice wrote:

Done, with my hack for 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


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

2025-03-27 Thread via lldb-commits


@@ -0,0 +1,273 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc, uint16_t err_len) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string arrow_str = "^";
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, text);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  std::vector diagnostics;
+  diagnostics.push_back(detail);
+  StreamString diag_stream(true);
+  RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+  std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+  return ret_str;
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member, Status 
&error)
+: m_ctx_scope(frame_sp), m_input_expr(dil_input_expr), m_dil_lexer(lexer),
+  m_error(error), 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() {
+  ASTNodeUP expr = ParseExpression();
+
+  Expect(Token::Kind::eof);
+
+  if (m_error.Fail())
+return m_error.ToError();
+
+  return expr;
+}

cmtice wrote:

Done.

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-03-27 Thread via lldb-commits


@@ -0,0 +1,131 @@
+//===-- DILParser.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_VALUEOBJECT_DILPARSER_H
+#define LLDB_VALUEOBJECT_DILPARSER_H
+
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/Utility/DiagnosticsRendering.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILLexer.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+enum class ErrorCode : unsigned char {
+  kOk = 0,
+  kInvalidExpressionSyntax,
+  kUndeclaredIdentifier,
+  kUnknown,
+};
+
+// The following is modeled on class OptionParseError.
+class DILDiagnosticError
+: public llvm::ErrorInfo {
+  std::vector m_details;
+
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  DILDiagnosticError(DiagnosticDetail detail)
+  : ErrorInfo(std::error_code(EINVAL, std::generic_category())),
+m_details({detail}) {}
+
+  DILDiagnosticError(ErrorCode ec, llvm::StringRef expr,
+ const std::string &message, uint32_t loc,
+ uint16_t err_len);
+
+  std::unique_ptr Clone() const override {
+return std::make_unique(m_details[0]);
+  }
+
+  llvm::ArrayRef GetDetails() const override {
+return m_details;

cmtice wrote:

Done.

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-03-27 Thread via lldb-commits


@@ -0,0 +1,273 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+  uint32_t loc, uint16_t err_len) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string arrow_str = "^";
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, text);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  std::vector diagnostics;
+  diagnostics.push_back(detail);
+  StreamString diag_stream(true);
+  RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+  std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+  return ret_str;
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member, Status 
&error)
+: m_ctx_scope(frame_sp), m_input_expr(dil_input_expr), m_dil_lexer(lexer),
+  m_error(error), 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() {
+  ASTNodeUP expr = ParseExpression();
+
+  Expect(Token::Kind::eof);
+
+  if (m_error.Fail())
+return m_error.ToError();
+
+  return expr;
+}
+
+// Parse an expression.
+//
+//  expression:
+//primary_expression
+//
+ASTNodeUP DILParser::ParseExpression() { return ParsePrimaryExpression(); }
+
+// Parse a primary_expression.
+//
+//  primary_expression:
+//id_expression
+//"(" expression ")"
+//
+ASTNodeUP DILParser::ParsePrimaryExpression() {
+  if (CurToken().IsOneOf({Token::coloncolon, Token::identifier})) {
+// Save the source location for the diagnostics message.
+uint32_t loc = CurToken().GetLocation();
+auto identifier = ParseIdExpression();
+
+return std::make_unique(loc, identifier, m_use_dynamic,
+m_ctx_scope);
+  } else if (CurToken().Is(Token::l_paren)) {

cmtice wrote:

Whoops; sorry I missed that. Done.

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-03-27 Thread via lldb-commits


@@ -0,0 +1,104 @@
+//===-- DILParser.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_VALUEOBJECT_DILPARSER_H
+#define LLDB_VALUEOBJECT_DILPARSER_H
+
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILLexer.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace lldb_private::dil {
+
+enum class ErrorCode : unsigned char {
+  kOk = 0,
+  kInvalidExpressionSyntax,
+  kUndeclaredIdentifier,
+  kUnknown,
+};
+
+std::string FormatDiagnostics(llvm::StringRef input_expr,
+  const std::string &message, uint32_t loc,
+  uint16_t err_len);
+
+/// Pure recursive descent parser for C++ like expressions.
+/// EBNF grammar for the parser is described in lldb/docs/dil-expr-lang.ebnf
+class DILParser {
+public:
+  static llvm::Expected Parse(llvm::StringRef dil_input_expr,
+ DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic,
+ bool use_synthetic, bool fragile_ivar,
+ bool check_ptr_vs_member);
+
+  ~DILParser() = default;
+
+  bool UseSynthetic() { return m_use_synthetic; }
+
+  lldb::DynamicValueType UseDynamic() { return m_use_dynamic; }
+
+  using PtrOperator = std::tuple;
+
+private:
+  explicit DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member,
+ Status &error);
+
+  llvm::Expected Run();
+
+  ASTNodeUP ParseExpression();
+  ASTNodeUP ParsePrimaryExpression();
+
+  std::string ParseNestedNameSpecifier();
+
+  std::string ParseIdExpression();
+  std::string ParseUnqualifiedId();
+
+  void BailOut(ErrorCode error_code, const std::string &error, uint32_t loc);
+
+  void BailOut(Status error);
+
+  void Expect(Token::Kind kind);
+
+  void TentativeParsingRollback(uint32_t saved_idx) {
+m_error.Clear();
+m_dil_lexer.ResetTokenIdx(saved_idx);
+  }
+
+  Token CurToken() { return m_dil_lexer.GetCurrentToken(); }
+
+  // Parser doesn't own the evaluation context. The produced AST may depend on
+  // it (for example, for source locations), so it's expected that expression
+  // context will outlive the parser.
+  std::shared_ptr m_ctx_scope;
+
+  llvm::StringRef m_input_expr;
+
+  DILLexer m_dil_lexer;
+
+  // Holds an error if it occures during parsing.
+  Status &m_error;

cmtice wrote:

Done.

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-03-27 Thread via lldb-commits


@@ -0,0 +1,276 @@
+//===-- 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/Utility/DiagnosticsRendering.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 {
+
+DILDiagnosticError::DILDiagnosticError(ErrorCode ec, llvm::StringRef expr,
+   const std::string &message, uint32_t 
loc,
+   uint16_t err_len)
+: // ErrorInfo(ec) {
+  ErrorInfo(std::error_code(EINVAL, std::generic_category())) {
+  DiagnosticDetail::SourceLocation sloc = {
+  FileSpec{}, /*line=*/1, static_cast(loc + 1),
+  err_len,false,  /*in_user_input=*/true};
+  std::string rendered_msg =
+  llvm::formatv(":1:{0}: {1}\n1 | {2}\n | ^",
+loc + 1, message, expr);
+  DiagnosticDetail detail;
+  detail.source_location = sloc;
+  detail.severity = lldb::eSeverityError;
+  detail.message = message;
+  detail.rendered = rendered_msg;
+  m_details.push_back(detail);
+}
+
+llvm::Expected
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+  Status error;
+  DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+   fragile_ivar, check_ptr_vs_member, error);
+  return parser.Run();
+}
+
+DILParser::DILParser(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member, Status 
&error)
+: m_ctx_scope(frame_sp), m_input_expr(dil_input_expr), m_dil_lexer(lexer),
+  m_error(error), 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() {
+  ASTNodeUP expr = ParseExpression();
+
+  Expect(Token::Kind::eof);
+
+  if (m_error.Fail())
+return m_error.ToError();
+
+  return expr;
+}
+
+// Parse an expression.
+//
+//  expression:
+//primary_expression
+//
+ASTNodeUP DILParser::ParseExpression() { return ParsePrimaryExpression(); }
+
+// Parse a primary_expression.
+//
+//  primary_expression:
+//id_expression
+//"(" expression ")"
+//
+ASTNodeUP DILParser::ParsePrimaryExpression() {
+  if (CurToken().IsOneOf({Token::coloncolon, Token::identifier})) {
+// Save the source location for the diagnostics message.
+uint32_t loc = CurToken().GetLocation();
+auto identifier = ParseIdExpression();
+
+return std::make_unique(loc, identifier, m_use_dynamic,
+m_ctx_scope);
+  } else if (CurToken().Is(Token::l_paren)) {
+m_dil_lexer.Advance();
+auto expr = ParseExpression();
+Expect(Token::r_paren);
+m_dil_lexer.Advance();
+return expr;
+  }
+
+  BailOut(ErrorCode::kInvalidExpressionSyntax,
+  llvm::formatv("Unexpected token: {0}", CurToken()),
+  CurToken().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 (CurToken().IsNot(Token::identifier) && CurToken().IsNot(Token::l_paren)) 
{
+return "";
+  }
+
+  // Anonymous namespaces need to be treated specially: They are represented
+  // the the string '(anonymous namespace)', which has a space in it (throwing
+  // off normal parsing) and is not actually proper C++> Check to see if we're
+  // looking at '(anonymous namespace)::...'
+  if (CurToken().Is(Token::l_paren)) {
+// Look for all the pieces, in order:
+// l_paren 'anonymous' 'namespace' r_paren coloncolon
+if (m_dil_lexer.LookAhead(1).Is(Token::identifier) 

[Lldb-commits] [lldb] [lldb-dap] Migrating DAP 'initialize' to new typed RequestHandler. (PR #133007)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -54,6 +54,79 @@ bool fromJSON(const llvm::json::Value &, DisconnectArguments 
&,
 /// body field is required.
 using DisconnectResponse = VoidResponse;
 
+/// Arguments for `initialize` request.
+struct InitializeRequestArguments {
+  /// The ID of the debug adapter.
+  std::string adatperID;
+
+  /// The ID of the client using this adapter.
+  std::optional clientID;
+
+  /// The human-readable name of the client using this adapter.
+  std::optional clientName;
+
+  /// The ISO-639 locale of the client using this adapter, e.g. en-US or de-CH.
+  std::optional locale;
+
+  enum class PathFormat { path, uri };
+
+  /// Determines in what format paths are specified. The default is `path`,
+  /// which is the native format.
+  std::optional pathFormat = PathFormat::path;
+
+  /// If true all line numbers are 1-based (default).
+  std::optional linesStartAt1;
+
+  /// If true all column numbers are 1-based (default).
+  std::optional columnsStartAt1;
+
+  enum class Feature {
+/// Client supports the `type` attribute for variables.
+supportsVariableType,
+/// Client supports the paging of variables.
+supportsVariablePaging,
+/// Client supports the `runInTerminal` request.
+supportsRunInTerminalRequest,
+/// Client supports memory references.
+supportsMemoryReferences,
+/// Client supports progress reporting.
+supportsProgressReporting,
+/// Client supports the `invalidated` event.
+supportsInvalidatedEvent,
+/// Client supports the `memory` event.
+supportsMemoryEvent,
+/// Client supports the `argsCanBeInterpretedByShell` attribute on the
+/// `runInTerminal` request.
+supportsArgsCanBeInterpretedByShell,
+/// Client supports the `startDebugging` request.
+supportsStartDebuggingRequest,
+/// The client will interpret ANSI escape sequences in the display of
+/// `OutputEvent.output` and `Variable.value` fields when
+/// `Capabilities.supportsANSIStyling` is also enabled.
+supportsANSIStyling,
+  };

JDevlieghere wrote:

I'm fine either way. Looking at the spec, all the boolean capabilities start 
with Supports so I think it's fine to drop that part. 

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


[Lldb-commits] [lldb] [lldb] Implement a statusline in LLDB (PR #121860)

2025-03-27 Thread David Spickett via lldb-commits

DavidSpickett wrote:

@JDevlieghere if I start lldb with no arguments:
```
david.spickett@tcwg-jade-03-dev:~/build-llvm-aarch64$ ./bin/lldb
<< cursor is here at the start of the line, but no (lldb) was printed
< the status bar>
```
Does not happen if I have a program file, but this is also strange:
```
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
(lldb) << the cursor is actually at the *start* of this line, instead of after 
the (lldb)
test.o << status bar
```
Typing overwrites the (lldb):
```
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
b)
test.o << status bar
```
AArch64 Ubuntu Linux, in case it matters.

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


[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

2025-03-27 Thread via lldb-commits

dlav-sc wrote:

> I don't know what else it was going to do :)

Yeah, me too, so I've decided to retain the old behavior if 
`--platform-available-ports` isn’t specified.

> Do you need a CMake variable for this too? I wonder how you are getting the 
> argument to dotest.

I don't think I really need a separate CMake flag here. Currently, the 
`--platform-name` option for `dotest.py` is passed in through the 
`LLDB_TEST_USER_ARGS` CMake variable, so I can also include 
`--platform-available-ports` there too.

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


[Lldb-commits] [lldb] [LLDB][Telemetry] Collect telemetry from client when allowed. (PR #129728)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -965,6 +965,22 @@ SBTarget SBDebugger::GetDummyTarget() {
   return sb_target;
 }
 
+void SBDebugger::DispatchClientTelemetry(const lldb::SBStructuredData &entry) {
+  LLDB_INSTRUMENT_VA(this);
+  // Disable client-telemetry for SWIG.
+  // This prevent arbitrary python client (pretty printers, whatnot) from 
sending
+  // telemetry without vendors knowing.
+#ifndef SWIG

JDevlieghere wrote:

I think the `ifndef` should go in the header and guard the whole function so 
it's not expose from SWIG. That said, downstream I will replace it with an `#if 
0` or just remove this method altogether because I don't want anyone external 
to LLDB to call this. 

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


[Lldb-commits] [lldb] Revert "[lldb] Remove UnwindPlan::Row shared_ptrs (#132370)" (PR #133299)

2025-03-27 Thread Jordan Rupprecht via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Remove UnwindPlan::Row shared_ptrs (PR #132370)

2025-03-27 Thread Jordan Rupprecht via lldb-commits

rupprecht wrote:

Saw the same thing running tests internally; reverted.

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


[Lldb-commits] [lldb] 48864a5 - Revert "[lldb] Remove UnwindPlan::Row shared_ptrs (#132370)" (#133299)

2025-03-27 Thread via lldb-commits

Author: Jordan Rupprecht
Date: 2025-03-27T14:20:07-05:00
New Revision: 48864a52ef547ac0477271127b510dd9e9798219

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

LOG: Revert "[lldb] Remove UnwindPlan::Row shared_ptrs (#132370)" (#133299)

This reverts commit d7cea2b18717f0cc31b7da4a03f772d89ee201db. It causes
crashes in API tests.

Added: 


Modified: 
lldb/include/lldb/Symbol/UnwindPlan.h
lldb/source/Symbol/UnwindPlan.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index ddc54a9fdc8ae..db9aade93b6ba 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -428,6 +428,8 @@ class UnwindPlan {
 bool m_unspecified_registers_are_undefined = false;
   }; // class Row
 
+  typedef std::shared_ptr RowSP;
+
   UnwindPlan(lldb::RegisterKind reg_kind)
   : m_register_kind(reg_kind), m_return_addr_register(LLDB_INVALID_REGNUM),
 m_plan_is_sourced_from_compiler(eLazyBoolCalculate),
@@ -435,10 +437,25 @@ class UnwindPlan {
 m_plan_is_for_signal_trap(eLazyBoolCalculate) {}
 
   // Performs a deep copy of the plan, including all the rows (expensive).
-  UnwindPlan(const UnwindPlan &rhs) = default;
-  UnwindPlan &operator=(const UnwindPlan &rhs) = default;
-
+  UnwindPlan(const UnwindPlan &rhs)
+  : m_plan_valid_ranges(rhs.m_plan_valid_ranges),
+m_register_kind(rhs.m_register_kind),
+m_return_addr_register(rhs.m_return_addr_register),
+m_source_name(rhs.m_source_name),
+m_plan_is_sourced_from_compiler(rhs.m_plan_is_sourced_from_compiler),
+m_plan_is_valid_at_all_instruction_locations(
+rhs.m_plan_is_valid_at_all_instruction_locations),
+m_plan_is_for_signal_trap(rhs.m_plan_is_for_signal_trap),
+m_lsda_address(rhs.m_lsda_address),
+m_personality_func_addr(rhs.m_personality_func_addr) {
+m_row_list.reserve(rhs.m_row_list.size());
+for (const RowSP &row_sp : rhs.m_row_list)
+  m_row_list.emplace_back(new Row(*row_sp));
+  }
   UnwindPlan(UnwindPlan &&rhs) = default;
+  UnwindPlan &operator=(const UnwindPlan &rhs) {
+return *this = UnwindPlan(rhs); // NB: moving from a temporary (deep) copy
+  }
   UnwindPlan &operator=(UnwindPlan &&) = default;
 
   ~UnwindPlan() = default;
@@ -469,7 +486,7 @@ class UnwindPlan {
   uint32_t GetInitialCFARegister() const {
 if (m_row_list.empty())
   return LLDB_INVALID_REGNUM;
-return m_row_list.front().GetCFAValue().GetRegisterNumber();
+return m_row_list.front()->GetCFAValue().GetRegisterNumber();
   }
 
   // This UnwindPlan may not be valid at every address of the function span.
@@ -552,7 +569,7 @@ class UnwindPlan {
   }
 
 private:
-  std::vector m_row_list;
+  std::vector m_row_list;
   std::vector m_plan_valid_ranges;
   lldb::RegisterKind m_register_kind; // The RegisterKind these register 
numbers
   // are in terms of - will need to be

diff  --git a/lldb/source/Symbol/UnwindPlan.cpp 
b/lldb/source/Symbol/UnwindPlan.cpp
index 92daf29630ab6..48089cbdecd97 100644
--- a/lldb/source/Symbol/UnwindPlan.cpp
+++ b/lldb/source/Symbol/UnwindPlan.cpp
@@ -391,29 +391,29 @@ bool UnwindPlan::Row::operator==(const UnwindPlan::Row 
&rhs) const {
 }
 
 void UnwindPlan::AppendRow(Row row) {
-  if (m_row_list.empty() || m_row_list.back().GetOffset() != row.GetOffset())
-m_row_list.push_back(std::move(row));
+  if (m_row_list.empty() || m_row_list.back()->GetOffset() != row.GetOffset())
+m_row_list.push_back(std::make_shared(std::move(row)));
   else
-m_row_list.back() = std::move(row);
+*m_row_list.back() = std::move(row);
 }
 
 struct RowLess {
-  bool operator()(addr_t a, const UnwindPlan::Row &b) const {
-return a < b.GetOffset();
+  bool operator()(addr_t a, const UnwindPlan::RowSP &b) const {
+return a < b->GetOffset();
   }
-  bool operator()(const UnwindPlan::Row &a, addr_t b) const {
-return a.GetOffset() < b;
+  bool operator()(const UnwindPlan::RowSP &a, addr_t b) const {
+return a->GetOffset() < b;
   }
 };
 
 void UnwindPlan::InsertRow(Row row, bool replace_existing) {
   auto it = llvm::lower_bound(m_row_list, row.GetOffset(), RowLess());
-  if (it == m_row_list.end() || it->GetOffset() > row.GetOffset())
-m_row_list.insert(it, std::move(row));
+  if (it == m_row_list.end() || it->get()->GetOffset() > row.GetOffset())
+m_row_list.insert(it, std::make_shared(std::move(row)));
   else {
-assert(it->GetOffset() == row.GetOffset());
+assert(it->get()->GetOffset() == row.GetOffset());
 if (replace_existing)
-  *it = std::move(row);
+  **it = std::move(row);
   }
 }
 
@@ -424,7 +424,7 @@ const UnwindPlan::Row 
*UnwindPlan::GetRow

[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

The pre-merge bot is using SWIG 4.0.2 which seems to have trouble with the 
move-only type. I'm going to build that SWIG and see if I can reproduce this.

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


[Lldb-commits] [lldb] [lldb] Use correct path for lldb-server executable (PR #131519)

2025-03-27 Thread Yuval Deutscher via lldb-commits

yuvald-sweet-security wrote:

> I think this #63468 is the same sort of issue. Not sure if it's the same 
> though.
> 
> As you can tell from me saying "I will get back to this" 2 years ago, the 
> knowledge of any of that has left my head by now, but thank you for looking 
> into this. I know it's not easy to unpick.

The issue you linked is probably the other issue which I encountered and fixed 
recently (https://github.com/llvm/llvm-project/pull/131609). The issue fixed in 
the PR we're currently writing in is a regression introduced in LLVM 20 due to 
a fundamental change in how lldb-server platform mode works, and so it doesn't 
make sense to me that it existed 2 years ago.

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


[Lldb-commits] [lldb] [lldb-dap] Adding a DAPError for showing users error messages. (PR #132255)

2025-03-27 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)

2025-03-27 Thread Yuval Deutscher via lldb-commits

yuvald-sweet-security wrote:

Solves https://github.com/llvm/llvm-project/issues/63468

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


[Lldb-commits] [lldb] [lldb] Respect LaunchInfo::SetExecutable in ProcessLauncherPosixFork (PR #133093)

2025-03-27 Thread Yuval Deutscher via lldb-commits

yuvald-sweet-security wrote:

> @yuvald-sweet-security

Thanks. This patch means we're still ignoring the arg0 set by `SetArg0`, right? 
and just using whatever was in the standard `GetArguments` vector. Maybe it's 
worth updating the comment I pointed at 
(https://github.com/llvm/llvm-project/blob/b231f6f86237fc1a15377b4aad6cf9be4808d727/lldb/include/lldb/Utility/ProcessInfo.h#L122-L125)
 so that this is less confusing?

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


[Lldb-commits] [lldb] [lldb-dap] Migrating DAP 'initialize' to new typed RequestHandler. (PR #133007)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -1144,31 +1145,45 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
-llvm::StringMap DAP::GetCapabilities() {
-  llvm::StringMap capabilities;
+bool DAP::isSupported(ClientFeature feature) {
+  return clientFeatures.find(feature) != clientFeatures.end();
+}
+
+protocol::Capabilities DAP::GetCapabilities() {
+  protocol::Capabilities capabilities;
 
-  // Supported capabilities.
-  capabilities["supportTerminateDebuggee"] = true;
-  capabilities["supportsDataBreakpoints"] = true;
-  capabilities["supportsDelayedStackTraceLoading"] = true;
-  capabilities["supportsEvaluateForHovers"] = true;
-  capabilities["supportsExceptionOptions"] = true;
-  capabilities["supportsLogPoints"] = true;
-  capabilities["supportsProgressReporting"] = true;
-  capabilities["supportsSteppingGranularity"] = true;
-  capabilities["supportsValueFormattingOptions"] = true;
+  // Supported capabilities that are not specific to a single request.
+  capabilities.supportedFeatures = {
+  AdapterFeature::supportsLogPoints,
+  AdapterFeature::supportsSteppingGranularity,
+  AdapterFeature::supportsValueFormattingOptions,
+  };
 
   // Unsupported capabilities.
-  capabilities["supportsGotoTargetsRequest"] = false;
-  capabilities["supportsLoadedSourcesRequest"] = false;
-  capabilities["supportsRestartFrame"] = false;
-  capabilities["supportsStepBack"] = false;
+  // supportsGotoTargetsRequest, supportsLoadedSourcesRequest,
+  // supportsRestartFrame, supportsStepBack

JDevlieghere wrote:

Looking at the spec, it seems like we can just omit unsupported capabilities. 
Should we just remove this then?

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


[Lldb-commits] [lldb] 618e8b9 - [lldb] Avoid unnecessary statusline redraw in HandleProgressEvent

2025-03-27 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2025-03-26T23:35:36-07:00
New Revision: 618e8b9a708ed037ec90c495890344046d78e5bf

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

LOG: [lldb] Avoid unnecessary statusline redraw in HandleProgressEvent

There's no need to call RedrawStatusline from HandleProgressEvent. The
statusline gets redraw after handling all events, including progress
events, in the default event handler loop.

Added: 


Modified: 
lldb/source/Core/Debugger.cpp

Removed: 




diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index f3e98b3ab2d39..993aa2d970de6 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -2178,8 +2178,6 @@ void Debugger::HandleProgressEvent(const lldb::EventSP 
&event_sp) {
   m_progress_reports.push_back(progress_report);
 }
   }
-
-  RedrawStatusline();
 }
 
 std::optional



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


[Lldb-commits] [lldb] 71d54cd - [lldb] Remove (deprecated) Function::GetAddressRange (#132923)

2025-03-27 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-03-27T11:27:56+01:00
New Revision: 71d54cd4f1cc5233437f25479166e4659fbe2e53

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

LOG: [lldb] Remove (deprecated) Function::GetAddressRange (#132923)

All uses have been replaced by GetAddressRange*s* or GetAddress.

Also fix two internal uses of the range member.

Added: 


Modified: 
lldb/include/lldb/Symbol/Function.h
lldb/source/Symbol/Function.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index ee3a8304fc5b3..21b3f9ab4a70c 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -445,9 +445,6 @@ class Function : public UserID, public SymbolContextScope {
 
   Function *CalculateSymbolContextFunction() override;
 
-  /// DEPRECATED: Use GetAddressRanges instead.
-  const AddressRange &GetAddressRange() { return m_range; }
-
   AddressRanges GetAddressRanges() { return m_block.GetRanges(); }
 
   /// Return the address of the function (its entry point). This address is 
also
@@ -658,11 +655,6 @@ class Function : public UserID, public SymbolContextScope {
   /// All lexical blocks contained in this function.
   Block m_block;
 
-  /// The function address range that covers the widest range needed to contain
-  /// all blocks. DEPRECATED: do not use this field in new code as the range 
may
-  /// include addresses belonging to other functions.
-  AddressRange m_range;
-
   /// The address (entry point) of the function.
   Address m_address;
 

diff  --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp
index 2c4467cc2e9c5..4fc793750f84f 100644
--- a/lldb/source/Symbol/Function.cpp
+++ b/lldb/source/Symbol/Function.cpp
@@ -254,33 +254,13 @@ Function *IndirectCallEdge::GetCallee(ModuleList &images,
 
 /// @}
 
-AddressRange CollapseRanges(llvm::ArrayRef ranges) {
-  if (ranges.empty())
-return AddressRange();
-  if (ranges.size() == 1)
-return ranges[0];
-
-  Address lowest_addr = ranges[0].GetBaseAddress();
-  addr_t highest_addr = lowest_addr.GetFileAddress() + ranges[0].GetByteSize();
-  for (const AddressRange &range : ranges.drop_front()) {
-Address range_begin = range.GetBaseAddress();
-addr_t range_end = range_begin.GetFileAddress() + range.GetByteSize();
-if (range_begin.GetFileAddress() < lowest_addr.GetFileAddress())
-  lowest_addr = range_begin;
-if (range_end > highest_addr)
-  highest_addr = range_end;
-  }
-  return AddressRange(lowest_addr, highest_addr - 
lowest_addr.GetFileAddress());
-}
-
 //
 Function::Function(CompileUnit *comp_unit, lldb::user_id_t func_uid,
lldb::user_id_t type_uid, const Mangled &mangled, Type 
*type,
Address address, AddressRanges ranges)
 : UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
   m_type(type), m_mangled(mangled), m_block(*this, func_uid),
-  m_range(CollapseRanges(ranges)), m_address(std::move(address)),
-  m_prologue_byte_size(0) {
+  m_address(std::move(address)), m_prologue_byte_size(0) {
   assert(comp_unit != nullptr);
   lldb::addr_t base_file_addr = m_address.GetFileAddress();
   for (const AddressRange &range : ranges)
@@ -464,8 +444,7 @@ void Function::Dump(Stream *s, bool show_context) const {
   s->EOL();
   // Dump the root object
   if (m_block.BlockInfoHasBeenParsed())
-m_block.Dump(s, m_range.GetBaseAddress().GetFileAddress(), INT_MAX,
- show_context);
+m_block.Dump(s, m_address.GetFileAddress(), INT_MAX, show_context);
 }
 
 void Function::CalculateSymbolContext(SymbolContext *sc) {
@@ -474,8 +453,7 @@ void Function::CalculateSymbolContext(SymbolContext *sc) {
 }
 
 ModuleSP Function::CalculateSymbolContextModule() {
-  SectionSP section_sp(m_range.GetBaseAddress().GetSection());
-  if (section_sp)
+  if (SectionSP section_sp = m_address.GetSection())
 return section_sp->GetModule();
 
   return this->GetCompileUnit()->GetModule();



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


[Lldb-commits] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)

2025-03-27 Thread Daniel Chen via lldb-commits


@@ -223,6 +223,13 @@ endif()
 # This can be used to detect whether we're in the runtimes build.
 set(LLVM_RUNTIMES_BUILD ON)
 
+if (LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND UNIX AND ${CMAKE_SYSTEM_NAME} 
MATCHES "AIX")
+  # Set LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF as AIX doesn't support it
+  message(WARNING
+  "LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON is not supported on AIX. 
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is set to OFF.")
+  set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR OFF CACHE BOOL "" FORCE)
+endif()

DanielCChen wrote:

Great! Thanks everyone for the input! I will post another PR to change it to 
using `FATAL_ERROR` instead of `WARNING`

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


[Lldb-commits] [lldb] [lldb] Emit progress events in SymbolFileDWARFDebugMap (PR #133211)

2025-03-27 Thread Adrian Prantl via lldb-commits


@@ -924,59 +947,63 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
   std::lock_guard guard(GetModuleMutex());
   uint32_t total_matches = 0;
 
-  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
-const uint32_t old_size = variables.GetSize();
-oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
-   variables);
-const uint32_t oso_matches = variables.GetSize() - old_size;
-if (oso_matches > 0) {
-  total_matches += oso_matches;
-
-  // Are we getting all matches?
-  if (max_matches == UINT32_MAX)
-return IterationAction::Continue; // Yep, continue getting everything
-
-  // If we have found enough matches, lets get out
-  if (max_matches >= total_matches)
-return IterationAction::Stop;
-
-  // Update the max matches for any subsequent calls to find globals in any
-  // other object files with DWARF
-  max_matches -= oso_matches;
-}
+  ForEachSymbolFile(
+  "Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
+const uint32_t old_size = variables.GetSize();
+oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
+   variables);
+const uint32_t oso_matches = variables.GetSize() - old_size;
+if (oso_matches > 0) {
+  total_matches += oso_matches;
+
+  // Are we getting all matches?
+  if (max_matches == UINT32_MAX)
+return IterationAction::Continue; // Yep, continue getting

adrian-prantl wrote:

```suggestion
 // Yep, continue getting everything.
return IterationAction::Continue;
```

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


[Lldb-commits] [lldb] [lldb] Emit progress events in SymbolFileDWARFDebugMap (PR #133211)

2025-03-27 Thread Adrian Prantl via lldb-commits


@@ -924,59 +947,63 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
   std::lock_guard guard(GetModuleMutex());
   uint32_t total_matches = 0;
 
-  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
-const uint32_t old_size = variables.GetSize();
-oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
-   variables);
-const uint32_t oso_matches = variables.GetSize() - old_size;
-if (oso_matches > 0) {
-  total_matches += oso_matches;
-
-  // Are we getting all matches?
-  if (max_matches == UINT32_MAX)
-return IterationAction::Continue; // Yep, continue getting everything
-
-  // If we have found enough matches, lets get out
-  if (max_matches >= total_matches)
-return IterationAction::Stop;
-
-  // Update the max matches for any subsequent calls to find globals in any
-  // other object files with DWARF
-  max_matches -= oso_matches;
-}
+  ForEachSymbolFile(
+  "Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
+const uint32_t old_size = variables.GetSize();
+oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
+   variables);
+const uint32_t oso_matches = variables.GetSize() - old_size;
+if (oso_matches > 0) {
+  total_matches += oso_matches;
+
+  // Are we getting all matches?
+  if (max_matches == UINT32_MAX)
+return IterationAction::Continue; // Yep, continue getting
+  // everything
+
+  // If we have found enough matches, lets get out
+  if (max_matches >= total_matches)
+return IterationAction::Stop;
+
+  // Update the max matches for any subsequent calls to find globals in
+  // any other object files with DWARF
+  max_matches -= oso_matches;
+}
 
-return IterationAction::Continue;
-  });
+return IterationAction::Continue;
+  });
 }
 
 void SymbolFileDWARFDebugMap::FindGlobalVariables(
 const RegularExpression ®ex, uint32_t max_matches,
 VariableList &variables) {
   std::lock_guard guard(GetModuleMutex());
   uint32_t total_matches = 0;
-  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
-const uint32_t old_size = variables.GetSize();
-oso_dwarf->FindGlobalVariables(regex, max_matches, variables);
-
-const uint32_t oso_matches = variables.GetSize() - old_size;
-if (oso_matches > 0) {
-  total_matches += oso_matches;
-
-  // Are we getting all matches?
-  if (max_matches == UINT32_MAX)
-return IterationAction::Continue; // Yep, continue getting everything
-
-  // If we have found enough matches, lets get out
-  if (max_matches >= total_matches)
-return IterationAction::Stop;
-
-  // Update the max matches for any subsequent calls to find globals in any
-  // other object files with DWARF
-  max_matches -= oso_matches;
-}
+  ForEachSymbolFile(
+  "Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
+const uint32_t old_size = variables.GetSize();
+oso_dwarf->FindGlobalVariables(regex, max_matches, variables);
+
+const uint32_t oso_matches = variables.GetSize() - old_size;
+if (oso_matches > 0) {
+  total_matches += oso_matches;
+
+  // Are we getting all matches?
+  if (max_matches == UINT32_MAX)
+return IterationAction::Continue; // Yep, continue getting

adrian-prantl wrote:

same here

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


[Lldb-commits] [lldb] [lldb] Emit progress events in SymbolFileDWARFDebugMap (PR #133211)

2025-03-27 Thread Adrian Prantl via lldb-commits


@@ -1148,16 +1175,16 @@ SymbolFileDWARFDebugMap::ParseCallEdgesInFunction(
 
 DWARFDIE SymbolFileDWARFDebugMap::FindDefinitionDIE(const DWARFDIE &die) {
   DWARFDIE result;
-  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
-result = oso_dwarf->FindDefinitionDIE(die);
-return result ? IterationAction::Stop : IterationAction::Continue;
-  });
+  ForEachSymbolFile(
+  "Looking up type definition", [&](SymbolFileDWARF *oso_dwarf) {

adrian-prantl wrote:

Not your code, but either we should pass a reference here or check for 
nullptr...

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


[Lldb-commits] [lldb] [LLDB][NFC] Added the interface DWARFExpression::Delegate to break dependencies and reduce lldb-server size (PR #131645)

2025-03-27 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

I actually very much like this result. It'd be nice to (try) get rid of the 
`GetAddressByteSize` method, as I outlined before, but that's better done 
separately. Just a couple of small changes/improvements inline.

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


[Lldb-commits] [lldb] [lldb] Adjust skips on reverse continue tests (PR #133240)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

LGTM, we discussed this yesterday with @rocallahan 

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


[Lldb-commits] [lldb] [lldb] Return *const* UnwindPlan pointers from FuncUnwinders (PR #133247)

2025-03-27 Thread Pavel Labath via lldb-commits

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/133247

>From f4f4d06e485b5d7d28ef2a45ae53d630df5da1c1 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Thu, 27 Mar 2025 13:53:57 +0100
Subject: [PATCH 1/2] [lldb] Return *const* UnwindPlan pointers from
 FuncUnwinders

These plans are cached and accessed from multiple threads. Modifying
them would be a Bad Idea(tm).
---
 lldb/include/lldb/Symbol/FuncUnwinders.h  |  78 +++
 lldb/include/lldb/Symbol/UnwindPlan.h |   4 +-
 .../lldb/Target/RegisterContextUnwind.h   |  16 +-
 lldb/source/Commands/CommandObjectTarget.cpp  | 106 +
 lldb/source/Symbol/FuncUnwinders.cpp  | 207 +-
 lldb/source/Symbol/UnwindPlan.cpp |   2 +-
 lldb/source/Target/RegisterContextUnwind.cpp  |  84 ---
 7 files changed, 247 insertions(+), 250 deletions(-)

diff --git a/lldb/include/lldb/Symbol/FuncUnwinders.h 
b/lldb/include/lldb/Symbol/FuncUnwinders.h
index 1d4c28324e90f..479ccf87b6e2c 100644
--- a/lldb/include/lldb/Symbol/FuncUnwinders.h
+++ b/lldb/include/lldb/Symbol/FuncUnwinders.h
@@ -36,18 +36,19 @@ class FuncUnwinders {
 
   ~FuncUnwinders();
 
-  lldb::UnwindPlanSP GetUnwindPlanAtCallSite(Target &target, Thread &thread);
+  std::shared_ptr GetUnwindPlanAtCallSite(Target &target,
+Thread &thread);
 
-  lldb::UnwindPlanSP GetUnwindPlanAtNonCallSite(Target &target,
-lldb_private::Thread &thread);
+  std::shared_ptr
+  GetUnwindPlanAtNonCallSite(Target &target, lldb_private::Thread &thread);
 
-  lldb::UnwindPlanSP GetUnwindPlanFastUnwind(Target &target,
- lldb_private::Thread &thread);
+  std::shared_ptr
+  GetUnwindPlanFastUnwind(Target &target, lldb_private::Thread &thread);
 
-  lldb::UnwindPlanSP
+  std::shared_ptr
   GetUnwindPlanArchitectureDefault(lldb_private::Thread &thread);
 
-  lldb::UnwindPlanSP
+  std::shared_ptr
   GetUnwindPlanArchitectureDefaultAtFunctionEntry(lldb_private::Thread 
&thread);
 
   Address &GetFirstNonPrologueInsn(Target &target);
@@ -77,32 +78,34 @@ class FuncUnwinders {
   // used. Instead, clients should ask for the *behavior* they are looking for,
   // using one of the above UnwindPlan retrieval methods.
 
-  lldb::UnwindPlanSP GetAssemblyUnwindPlan(Target &target, Thread &thread);
+  std::shared_ptr GetAssemblyUnwindPlan(Target &target,
+  Thread &thread);
 
-  lldb::UnwindPlanSP GetObjectFileUnwindPlan(Target &target);
+  std::shared_ptr GetObjectFileUnwindPlan(Target &target);
 
-  lldb::UnwindPlanSP GetObjectFileAugmentedUnwindPlan(Target &target,
-  Thread &thread);
+  std::shared_ptr
+  GetObjectFileAugmentedUnwindPlan(Target &target, Thread &thread);
 
-  lldb::UnwindPlanSP GetEHFrameUnwindPlan(Target &target);
+  std::shared_ptr GetEHFrameUnwindPlan(Target &target);
 
-  lldb::UnwindPlanSP GetEHFrameAugmentedUnwindPlan(Target &target,
-   Thread &thread);
+  std::shared_ptr
+  GetEHFrameAugmentedUnwindPlan(Target &target, Thread &thread);
 
-  lldb::UnwindPlanSP GetDebugFrameUnwindPlan(Target &target);
+  std::shared_ptr GetDebugFrameUnwindPlan(Target &target);
 
-  lldb::UnwindPlanSP GetDebugFrameAugmentedUnwindPlan(Target &target,
-  Thread &thread);
+  std::shared_ptr
+  GetDebugFrameAugmentedUnwindPlan(Target &target, Thread &thread);
 
-  lldb::UnwindPlanSP GetCompactUnwindUnwindPlan(Target &target);
+  std::shared_ptr GetCompactUnwindUnwindPlan(Target &target);
 
-  lldb::UnwindPlanSP GetArmUnwindUnwindPlan(Target &target);
+  std::shared_ptr GetArmUnwindUnwindPlan(Target &target);
 
-  lldb::UnwindPlanSP GetSymbolFileUnwindPlan(Thread &thread);
+  std::shared_ptr GetSymbolFileUnwindPlan(Thread &thread);
 
-  lldb::UnwindPlanSP GetArchDefaultUnwindPlan(Thread &thread);
+  std::shared_ptr GetArchDefaultUnwindPlan(Thread &thread);
 
-  lldb::UnwindPlanSP GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
+  std::shared_ptr
+  GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
 
 private:
   lldb::UnwindAssemblySP GetUnwindAssemblyProfiler(Target &target);
@@ -113,7 +116,8 @@ class FuncUnwinders {
   // unwind rule for the pc, and LazyBoolCalculate if it was unable to
   // determine this for some reason.
   lldb_private::LazyBool CompareUnwindPlansForIdenticalInitialPCLocation(
-  Thread &thread, const lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP 
&b);
+  Thread &thread, const std::shared_ptr &a,
+  const std::shared_ptr &b);
 
   UnwindTable &m_unwind_table;
 
@@ -129,22 +133,22 @@ class FuncUnwinders {
 
   std::recursive_mutex m_mutex;
 
-  lldb::UnwindPlanSP m_unwind_plan_assembly_sp;
-  lldb::UnwindPlanSP m_unwind_plan_object_file_sp;
-  lldb::UnwindPlanSP m_unwi

[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)

2025-03-27 Thread via lldb-commits

https://github.com/jimingham created 
https://github.com/llvm/llvm-project/pull/133290

So the dSYM can be told what target it has been loaded into.

When lldb is loading modules, while creating a target, it will run "command 
script import" on any Python modules in Resources/Python in the dSYM.  However, 
this happens WHILE the target is being created, so it is not yet in the target 
list.  That means that these scripts can't act on the target that they a part 
of when they get loaded.

This patch adds a new python API that lldb will call:

__lldb_module_added_to_target

if it is defined in the module, passing in the Target the module was being 
added to, so that code in these dSYM's don't have to guess.

>From effad9525461611ed47598b53a77ee5aabb0e4cf Mon Sep 17 00:00:00 2001
From: Jim Ingham 
Date: Thu, 27 Mar 2025 11:04:26 -0700
Subject: [PATCH] Add a new affordance that the Python module in a dSYM can be
 told what target it has been loaded into.

When lldb is loading modules, while creating a target, it will run
"command script import" on any Python modules in Resources/Python in the
dSYM.  However, this happens WHILE the target is being created, so it is
not yet in the target list.  That means that these scripts can't act on
the target that they a part of when they get loaded.

This patch adds a new python API that lldb will call:

__lldb_module_added_to_target

if it is defined in the module, passing in the Target the module was being
added to, so that code in these dSYM's don't have to guess.
---
 lldb/bindings/python/python-wrapper.swig  | 22 ++
 .../lldb/Interpreter/ScriptInterpreter.h  |  3 +-
 lldb/source/Core/Module.cpp   |  4 +-
 lldb/source/Interpreter/ScriptInterpreter.cpp |  3 +-
 .../Python/SWIGPythonBridge.h |  4 ++
 .../Python/ScriptInterpreterPython.cpp|  9 ++-
 .../Python/ScriptInterpreterPythonImpl.h  |  3 +-
 lldb/test/API/macosx/dsym_modules/Makefile|  4 ++
 .../macosx/dsym_modules/TestdSYMModuleInit.py | 68 +++
 lldb/test/API/macosx/dsym_modules/has_dsym.py | 21 ++
 lldb/test/API/macosx/dsym_modules/main.c  | 15 
 .../Python/PythonTestSuite.cpp|  7 ++
 12 files changed, 158 insertions(+), 5 deletions(-)
 create mode 100644 lldb/test/API/macosx/dsym_modules/Makefile
 create mode 100644 lldb/test/API/macosx/dsym_modules/TestdSYMModuleInit.py
 create mode 100644 lldb/test/API/macosx/dsym_modules/has_dsym.py
 create mode 100644 lldb/test/API/macosx/dsym_modules/main.c

diff --git a/lldb/bindings/python/python-wrapper.swig 
b/lldb/bindings/python/python-wrapper.swig
index 57c7ac387145e..3d1d04e47e70b 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -966,6 +966,28 @@ bool 
lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
   return true;
 }
 
+bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
+const char *python_module_name, const char *session_dictionary_name,
+lldb::TargetSP target_sp) {
+  std::string python_function_name_string = python_module_name;
+  python_function_name_string += ".__lldb_module_added_to_target";
+  const char *python_function_name = python_function_name_string.c_str();
+
+  PyErr_Cleaner py_err_cleaner(true);
+
+  auto dict = PythonModule::MainModule().ResolveName(
+  session_dictionary_name);
+  auto pfunc = PythonObject::ResolveNameWithDictionary(
+  python_function_name, dict);
+
+  if (!pfunc.IsAllocated())
+return true;
+
+  pfunc(SWIGBridge::ToSWIGWrapper(std::move(target_sp)), dict);
+
+  return true;
+}
+
 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
 const char *python_module_name, const char *session_dictionary_name,
 lldb::DebuggerSP debugger) {
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index c5aa19959aa61..25e82779f05c6 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -522,7 +522,8 @@ class ScriptInterpreter : public PluginInterface {
   LoadScriptingModule(const char *filename, const LoadScriptOptions &options,
   lldb_private::Status &error,
   StructuredData::ObjectSP *module_sp = nullptr,
-  FileSpec extra_search_dir = {});
+  FileSpec extra_search_dir = {},
+  lldb::TargetSP loaded_into_target_sp = {});
 
   virtual bool IsReservedWord(const char *word) { return false; }
 
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index d70f292abaea4..7b52ba08cd379 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1485,7 +1485,9 @@ bool Module::LoadScriptingResourceInTarget(Target 
*target, Status &error,
 scripting_fspec.Dump(scripting_stream.AsRawOstream());
 LoadScriptOptions options;

[Lldb-commits] [lldb] [lldb] Remove UnwindPlan::Row shared_ptrs (PR #132370)

2025-03-27 Thread Michael Buch via lldb-commits

Michael137 wrote:

Still double checking but i think this may have broken a couple of macOS x86_64 
tests: https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/10909/


```
TestTsanMultiple.test_dsym/a.out")

runCmd: env TSAN_OPTIONS=abort_on_error=0

output: 

runCmd: run

warning: libclang_rt.tsan_osx_dynamic.dylib was compiled with optimization - 
stepping may behave oddly; variables may not be available.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  liblldb.21.0.99git.dylib 0x00011c97b778 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1  liblldb.21.0.99git.dylib 0x00011c979789 llvm::sys::RunSignalHandlers() + 
233
2  liblldb.21.0.99git.dylib 0x00011c97bdd6 SignalHandler(int, __siginfo*, 
void*) + 278
3  libsystem_platform.dylib 0x7ff80b4d0e9d _sigtramp + 29
4  libsystem_platform.dylib 0x77db4860 _sigtramp + 18446726515825457632
5  liblldb.21.0.99git.dylib 0x000118618347 
lldb_private::x86AssemblyInspectionEngine::AugmentUnwindPlanFromCallSite(unsigned
 char*, unsigned long, lldb_private::AddressRange&, lldb_private::UnwindPlan&, 
std::__1::shared_ptr&) + 919
6  liblldb.21.0.99git.dylib 0x000118614045 
UnwindAssembly_x86::AugmentUnwindPlanFromCallSite(lldb_private::AddressRange&, 
lldb_private::Thread&, lldb_private::UnwindPlan&) + 997
7  liblldb.21.0.99git.dylib 0x000119819113 
lldb_private::FuncUnwinders::GetEHFrameAugmentedUnwindPlan(lldb_private::Target&,
 lldb_private::Thread&) + 387
8  liblldb.21.0.99git.dylib 0x000119819ace 
lldb_private::FuncUnwinders::GetUnwindPlanAtNonCallSite(lldb_private::Target&, 
lldb_private::Thread&) + 446
9  liblldb.21.0.99git.dylib 0x000119898102 
lldb_private::RegisterContextUnwind::GetFullUnwindPlanForFrame() + 2978
10 liblldb.21.0.99git.dylib 0x0001198952a7 
lldb_private::RegisterContextUnwind::InitializeZerothFrame() + 1383
11 liblldb.21.0.99git.dylib 0x000119896e23 
lldb_private::RegisterContextUnwind::RegisterContextUnwind(lldb_private::Thread&,
 std::__1::shared_ptr const&, 
lldb_private::SymbolContext&, unsigned int, lldb_private::UnwindLLDB&) + 243
12 liblldb.21.0.99git.dylib
...
```

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


[Lldb-commits] [lldb] [lldb] Make GetRowForFunctionOffset compatible with discontinuous functions (PR #133250)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [LLDB][NFC] Move CPlusPlusLanguage methods used in Core/Module.cpp to a separated module to break lldb-server dependencies (PR #132274)

2025-03-27 Thread Dmitry Vasilyev via lldb-commits

slydiman wrote:

@labath 
The repro above shows that CPlusPlusLanguage::GetHardcodedSummaries() causes to 
link TypeSystemClang  and other dependencies. But --print-gc-sections and 
`llvm-objdump --all-headers --demangle lldb-server` shows that 
GetHardcodedSummaries is missing in the final binary. The linker removes unused 
functions like GetHardcodedSummaries, but the dependencies are linked because 
of global variables like TypeSystemClang::ID.

So, this patch solves the specific issue by breaking the dependency chain. 
Or we should refactor all global variables in all dependencies (lldb, llvm, 
clang). 
Note we have found at least 90 extra gc roots.

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


[Lldb-commits] [lldb] [lldb] Remove raw access to PluginInstances vector (PR #132884)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

Alright, let's go with the copy. Unless you think the `enabled` property might 
change while we're iterating over the plugins, we should be able to store it in 
the PluginInstance. AFAIK, the instance itself is never stored away. 

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


[Lldb-commits] [lldb] [lldb] Remove raw access to PluginInstances vector (PR #132884)

2025-03-27 Thread David Peixotto via lldb-commits

dmpots wrote:

> Alright, let's go with the copy. Unless you think the `enabled` property 
> might change while we're iterating over the plugins, we should be able to 
> store it in the PluginInstance. AFAIK, the instance itself is never stored 
> away.

Sounds good. That seems to be the simplest solution and should work with the 
current use cases. We can always revisit later if needed.

I'll prepare a new patch and update this PR.

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


[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Santhosh Kumar Ellendula via lldb-commits


@@ -112,3 +112,48 @@ def test_readMemory(self):
 # Reads at offset 0x0 fail
 mem = self.dap_server.request_readMemory("0x0", 0, 6)
 self.assertEqual(mem["success"], False)
+
+def test_writeMemory(self):
+"""
+Tests the 'writeMemory' request
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+source = "main.cpp"
+self.source_path = os.path.join(os.getcwd(), source)
+self.set_source_breakpoints(
+source,
+[line_number(source, "// Breakpoint")],
+)
+self.continue_to_next_stop()
+
+# Get the 'not_a_ptr' writable variablle reference address.
+ptr_deref = self.dap_server.request_evaluate("not_a_ptr")["body"]
+memref = ptr_deref["memoryReference"]
+
+# Write the Base64-encoded string "Mg==", which decodes to binary 0x32

santhoshe447 wrote:

> Instead of a magic variable, you could add a helper to `lldbdap_testcase.py` 
> that uses the [base64](https://docs.python.org/3/library/base64.html) python 
> module to encode byte strings. E.g. your example is:
> 
> ```
> $ python3
> >>> import base64
> >>> base64.b64encode(b'2')
> b'Mg=='
> ```
> 
> And it might be a bit more clear to the reader whats happening.
> 
> Something along the lines of:
> 
> ```
> def writeMemory(self, memory_reference, data, offset=None, 
> allow_partial=None):
>encodedData = base64.b64encode
>resp = self.dap_server.request_writeMemory(memory_reference, 
> offset=offset, allow_partial=allow_partial, data=encodedData)
>self.assertTrue(resp['success'])
>self.assertEqual(resp['body']['bytesWritten'], len(data))
> ```

Thanks for your suggestion.
I will update accordingly.

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


[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)

2025-03-27 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (jimingham)


Changes

So the dSYM can be told what target it has been loaded into.

When lldb is loading modules, while creating a target, it will run "command 
script import" on any Python modules in Resources/Python in the dSYM.  However, 
this happens WHILE the target is being created, so it is not yet in the target 
list.  That means that these scripts can't act on the target that they a part 
of when they get loaded.

This patch adds a new python API that lldb will call:

__lldb_module_added_to_target

if it is defined in the module, passing in the Target the module was being 
added to, so that code in these dSYM's don't have to guess.

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


12 Files Affected:

- (modified) lldb/bindings/python/python-wrapper.swig (+22) 
- (modified) lldb/include/lldb/Interpreter/ScriptInterpreter.h (+2-1) 
- (modified) lldb/source/Core/Module.cpp (+3-1) 
- (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+2-1) 
- (modified) lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h 
(+4) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+8-1) 
- (modified) 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h 
(+2-1) 
- (added) lldb/test/API/macosx/dsym_modules/Makefile (+4) 
- (added) lldb/test/API/macosx/dsym_modules/TestdSYMModuleInit.py (+68) 
- (added) lldb/test/API/macosx/dsym_modules/has_dsym.py (+21) 
- (added) lldb/test/API/macosx/dsym_modules/main.c (+15) 
- (modified) lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (+7) 


``diff
diff --git a/lldb/bindings/python/python-wrapper.swig 
b/lldb/bindings/python/python-wrapper.swig
index 57c7ac387145e..3d1d04e47e70b 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -966,6 +966,28 @@ bool 
lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
   return true;
 }
 
+bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
+const char *python_module_name, const char *session_dictionary_name,
+lldb::TargetSP target_sp) {
+  std::string python_function_name_string = python_module_name;
+  python_function_name_string += ".__lldb_module_added_to_target";
+  const char *python_function_name = python_function_name_string.c_str();
+
+  PyErr_Cleaner py_err_cleaner(true);
+
+  auto dict = PythonModule::MainModule().ResolveName(
+  session_dictionary_name);
+  auto pfunc = PythonObject::ResolveNameWithDictionary(
+  python_function_name, dict);
+
+  if (!pfunc.IsAllocated())
+return true;
+
+  pfunc(SWIGBridge::ToSWIGWrapper(std::move(target_sp)), dict);
+
+  return true;
+}
+
 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
 const char *python_module_name, const char *session_dictionary_name,
 lldb::DebuggerSP debugger) {
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index c5aa19959aa61..25e82779f05c6 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -522,7 +522,8 @@ class ScriptInterpreter : public PluginInterface {
   LoadScriptingModule(const char *filename, const LoadScriptOptions &options,
   lldb_private::Status &error,
   StructuredData::ObjectSP *module_sp = nullptr,
-  FileSpec extra_search_dir = {});
+  FileSpec extra_search_dir = {},
+  lldb::TargetSP loaded_into_target_sp = {});
 
   virtual bool IsReservedWord(const char *word) { return false; }
 
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index d70f292abaea4..7b52ba08cd379 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1485,7 +1485,9 @@ bool Module::LoadScriptingResourceInTarget(Target 
*target, Status &error,
 scripting_fspec.Dump(scripting_stream.AsRawOstream());
 LoadScriptOptions options;
 bool did_load = script_interpreter->LoadScriptingModule(
-scripting_stream.GetData(), options, error);
+scripting_stream.GetData(), options, error,
+/*module_sp*/ nullptr, /*extra_path*/ {}, 
+target->shared_from_this());
 if (!did_load)
   return false;
   }
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 4424b6c894356..8d9655a07e7e9 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -52,7 +52,8 @@ bool ScriptInterpreter::LoadScriptingModule(const char 
*filename,
 const LoadScriptOptions &options,
 lldb_private::Status &error,
 

[Lldb-commits] [lldb] [lldb] Show target.debug-file-search-paths setting from python SBDebugger (PR #131683)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)

2025-03-27 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 960615954e4cb3150ae4a479fa7f9d0d17035eea 
effad9525461611ed47598b53a77ee5aabb0e4cf --extensions h,c,cpp -- 
lldb/test/API/macosx/dsym_modules/main.c 
lldb/include/lldb/Interpreter/ScriptInterpreter.h lldb/source/Core/Module.cpp 
lldb/source/Interpreter/ScriptInterpreter.cpp 
lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h 
lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 7b52ba08cd..53dc6fcde0 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1486,7 +1486,7 @@ bool Module::LoadScriptingResourceInTarget(Target 
*target, Status &error,
 LoadScriptOptions options;
 bool did_load = script_interpreter->LoadScriptingModule(
 scripting_stream.GetData(), options, error,
-/*module_sp*/ nullptr, /*extra_path*/ {}, 
+/*module_sp*/ nullptr, /*extra_path*/ {},
 target->shared_from_this());
 if (!did_load)
   return false;
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 8d9655a07e..63655cc5a5 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp
@@ -48,12 +48,10 @@ StructuredData::DictionarySP 
ScriptInterpreter::GetInterpreterInfo() {
   return nullptr;
 }
 
-bool ScriptInterpreter::LoadScriptingModule(const char *filename,
-const LoadScriptOptions &options,
-lldb_private::Status &error,
-StructuredData::ObjectSP 
*module_sp,
-FileSpec extra_search_dir,
-lldb::TargetSP 
loaded_into_target_sp) {
+bool ScriptInterpreter::LoadScriptingModule(
+const char *filename, const LoadScriptOptions &options,
+lldb_private::Status &error, StructuredData::ObjectSP *module_sp,
+FileSpec extra_search_dir, lldb::TargetSP loaded_into_target_sp) {
   error = Status::FromErrorString(
   "This script interpreter does not support importing modules.");
   return false;
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h 
b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
index 137d7c5363..504b3aa0a4 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -215,10 +215,11 @@ public:
const char *session_dictionary_name,
lldb::DebuggerSP debugger);
 
-  static bool LLDBSwigPythonCallModuleNewTarget(const char *python_module_name,
-   const char *session_dictionary_name,
-   lldb::TargetSP target);
-   
+  static bool
+  LLDBSwigPythonCallModuleNewTarget(const char *python_module_name,
+const char *session_dictionary_name,
+lldb::TargetSP target);
+
   static python::PythonObject
   LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
const char *session_dictionary_name,
diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index b4bde233d3..0ed5e2a655 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2316,8 +2316,7 @@ uint64_t replace_all(std::string &str, const std::string 
&oldStr,
 bool ScriptInterpreterPythonImpl::LoadScriptingModule(
 const char *pathname, const LoadScriptOptions &options,
 lldb_private::Status &error, StructuredData::ObjectSP *module_sp,
-FileSpec extra_search_dir,
-lldb::TargetSP target_sp) {
+FileSpec extra_search_dir, lldb::TargetSP target_sp) {
   namespace fs = llvm::sys::fs;
   namespace path = llvm::sys::path;
 
@@ -2499,8 +2498,8 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
   // Finally, if we got a target passed in, then we should tell the new module
   // about this target:
   if (target_sp) {
-return SWIGBridge::LLDBSwigPythonCallModuleNewTarget(module_name.c_str(),
-m_dictionary_na

[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)

2025-03-27 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 
960615954e4cb3150ae4a479fa7f9d0d17035eea...effad9525461611ed47598b53a77ee5aabb0e4cf
 lldb/test/API/macosx/dsym_modules/TestdSYMModuleInit.py 
lldb/test/API/macosx/dsym_modules/has_dsym.py
``





View the diff from darker here.


``diff
--- TestdSYMModuleInit.py   2025-03-27 18:04:26.00 +
+++ TestdSYMModuleInit.py   2025-03-27 18:15:57.132143 +
@@ -8,61 +8,56 @@
 import lldb
 import lldbsuite.test.lldbutil as lldbutil
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test.decorators import *
 
+
 @skipUnlessDarwin
 class TestdSYMModuleInit(TestBase):
-
 @no_debug_info_test
 def test_add_module(self):
 """This loads a file into a target and ensures that the python module 
was
-   correctly added and the two intialization functions are called."""
+correctly added and the two intialization functions are called."""
 self.exe_name = "has_dsym"
-self.py_name = self.exe_name+".py"
+self.py_name = self.exe_name + ".py"
 
 # Now load the target the first time into the debugger:
 self.runCmd("settings set target.load-script-from-symbol-file true")
 self.interp = self.dbg.GetCommandInterpreter()
 
-executable = self.build_dsym(self.exe_name+"_1")
+executable = self.build_dsym(self.exe_name + "_1")
 target = self.createTestTarget(file_path=executable)
-self.check_answers(executable, ['1', '1', "has_dsym_1"])
+self.check_answers(executable, ["1", "1", "has_dsym_1"])
 
 # Now make a second target and make sure both get called:
-executable_2 = self.build_dsym(self.exe_name+"_2")
+executable_2 = self.build_dsym(self.exe_name + "_2")
 target_2 = self.createTestTarget(file_path=executable_2)
-self.check_answers(executable_2, ['2', '2', "has_dsym_2"])
-
+self.check_answers(executable_2, ["2", "2", "has_dsym_2"])
+
 def check_answers(self, name, answers):
 result = lldb.SBCommandReturnObject()
 self.interp.HandleCommand("report_command", result)
-self.assertTrue(result.Succeeded(), f"report_command succeeded 
{result.GetError()}")
+self.assertTrue(
+result.Succeeded(), f"report_command succeeded {result.GetError()}"
+)
 
 cmd_results = result.GetOutput().split()
 self.assertEqual(answers[0], cmd_results[0], "Right number of module 
imports")
 self.assertEqual(answers[1], cmd_results[1], "Right number of target 
notices")
 self.assertIn(answers[2], name, "Right target name")
-
 
 def build_dsym(self, name):
-self.build(debug_info="dsym", dictionary={"EXE" : name})
+self.build(debug_info="dsym", dictionary={"EXE": name})
 executable = self.getBuildArtifact(name)
-dsym_path = self.getBuildArtifact(name+".dSYM")
+dsym_path = self.getBuildArtifact(name + ".dSYM")
 python_dir_path = dsym_path
-python_dir_path = os.path.join(
-dsym_path, "Contents", "Resources", "Python"
-)
+python_dir_path = os.path.join(dsym_path, "Contents", "Resources", 
"Python")
 if not os.path.exists(python_dir_path):
 os.mkdir(python_dir_path)
 
-python_file_name = name+".py"
-
-module_dest_path = os.path.join(
-python_dir_path, python_file_name 
-)
+python_file_name = name + ".py"
+
+module_dest_path = os.path.join(python_dir_path, python_file_name)
 module_origin_path = os.path.join(self.getSourceDir(), self.py_name)
 shutil.copy(module_origin_path, module_dest_path)
 
 return executable
-
-
--- has_dsym.py 2025-03-27 18:04:26.00 +
+++ has_dsym.py 2025-03-27 18:15:57.144762 +
@@ -1,21 +1,28 @@
 import lldb
 
+
 def report_command(debugger, command, exe_ctx, result, internal_dict):
-result.AppendMessage(f"{lldb.num_module_inits} {lldb.num_target_inits} 
\"{lldb.target_name}\"")
+result.AppendMessage(
+f'{lldb.num_module_inits} {lldb.num_target_inits} "{lldb.target_name}"'
+)
 result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
-
+
+
 def __lldb_init_module(debugger, internal_dict):
 # We only want to make one copy of the report command so it will be shared
 if "has_dsym_1" in __name__:
 # lldb is a convenient place to store our counters.
 lldb.num_module_inits = 0
 lldb.num_target_inits = 0
 lldb.target_name = ""
-
-debugger.HandleCommand(f"command script add -o -f 
'{__name__}.report_command' report_command")
+
+debugger.HandleCommand(
+f"command script add -o -f '{__name__}.report_command' 
report_command"
+)
 
 l

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =
+  address + GetInteger(arguments, "offset").value_or(0);
+
+  llvm::StringRef data64 = GetString(arguments, "data").value_or("");
+
+  // The VSCode IDE or other DAP clients send memory data as a Base64 string.
+  // This function decodes it into raw binary before writing it to the target
+  // process memory.
+  std::vector output;
+  auto decodeError = llvm::decodeBase64(data64, output);
+
+  if (decodeError) {
+response["success"] = false;
+EmplaceSafeString(response, "message",
+  llvm::t

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

Expose u target API mutex through the SB API. This is motivated by lldb-dap, 
which is built on top of the SB API and needs a way to execute a series of SB 
API calls in an atomic manner (see #131242).

We can solve this problem by either introducing an additional layer of locking 
at the DAP level or by exposing the existing locking at the SB API level. This 
patch implements the second approach.

This was discussed in an RFC on Discourse [0]. The original implementation 
exposed a move-only lock rather than a mutex [1] which doesn't work well with 
SWIG 4.0 [2]. This implement the alternative solution of exposing the mutex 
rather than the lock. The SBMutex conforms to the BasicLockable requirement [3] 
(which is why the methods are called `lock` and `unlock` rather than Lock and 
Unlock) so it can be used as `std::lock_guard` and
`std::unique_lock`.

[0]: 
https://discourse.llvm.org/t/rfc-exposing-the-target-api-lock-through-the-sb-api/85215/6
[1]: https://github.com/llvm/llvm-project/pull/131404
[2]: 
https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377/9
[3]: https://en.cppreference.com/w/cpp/named_req/BasicLockable

>From 79241d2f5701ab789f7fdbb5bd881c4494cb67eb Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 27 Mar 2025 11:24:50 -0700
Subject: [PATCH] [lldb] Expose the Target API mutex through the SB API

Expose u target API mutex through the SB API. This is motivated by
lldb-dap, which is built on top of the SB API and needs a way to execute
a series of SB API calls in an atomic manner (see #131242).

We can solve this problem by either introducing an additional layer of
locking at the DAP level or by exposing the existing locking at the SB
API level. This patch implements the second approach.

This was discussed in an RFC on Discourse [0]. The original
implementation exposed a move-only lock rather than a mutex [1] which
doesn't work well with SWIG 4.0 [2]. This implement the alternative
solution of exposing the mutex rather than the lock. The SBMutex
conforms to the BasicLockable requirement [3] (which is why the methods
are called `lock` and `unlock` rather than Lock and Unlock) so it can be
used as `std::lock_guard` and
`std::unique_lock`.

[0]: 
https://discourse.llvm.org/t/rfc-exposing-the-target-api-lock-through-the-sb-api/85215/6
[1]: https://github.com/llvm/llvm-project/pull/131404
[2]: 
https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377/9
[3]: https://en.cppreference.com/w/cpp/named_req/BasicLockable
---
 lldb/bindings/interface/SBMutexExtensions.i   | 12 
 lldb/bindings/interfaces.swig |  4 +-
 lldb/include/lldb/API/LLDB.h  |  1 +
 lldb/include/lldb/API/SBDefines.h |  1 +
 lldb/include/lldb/API/SBMutex.h   | 48 +++
 lldb/include/lldb/API/SBTarget.h  |  4 +-
 lldb/include/lldb/Target/Target.h | 16 +
 lldb/source/API/CMakeLists.txt|  1 +
 lldb/source/API/SBMutex.cpp   | 59 ++
 lldb/source/API/SBTarget.cpp  | 16 +++--
 .../API/python_api/target/TestTargetAPI.py| 24 
 lldb/unittests/API/CMakeLists.txt |  1 +
 lldb/unittests/API/SBMutexTest.cpp| 60 +++
 13 files changed, 241 insertions(+), 6 deletions(-)
 create mode 100644 lldb/bindings/interface/SBMutexExtensions.i
 create mode 100644 lldb/include/lldb/API/SBMutex.h
 create mode 100644 lldb/source/API/SBMutex.cpp
 create mode 100644 lldb/unittests/API/SBMutexTest.cpp

diff --git a/lldb/bindings/interface/SBMutexExtensions.i 
b/lldb/bindings/interface/SBMutexExtensions.i
new file mode 100644
index 0..32d3fee468697
--- /dev/null
+++ b/lldb/bindings/interface/SBMutexExtensions.i
@@ -0,0 +1,12 @@
+%extend lldb::SBMutex {
+#ifdef SWIGPYTHON
+%pythoncode %{
+def __enter__(self):
+self.lock()
+return self
+
+def __exit__(self, exc_type, exc_value, traceback):
+self.unlock()
+%}
+#endif
+}
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index 08df9a1a8d539..e36f2f9dd27c6 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -51,6 +51,7 @@
 %include "./interface/SBMemoryRegionInfoListDocstrings.i"
 %include "./interface/SBModuleDocstrings.i"
 %include "./interface/SBModuleSpecDocstrings.i"
+%include "./interface/SBMutexExtensions.i"
 %include "./interface/SBPlatformDocstrings.i"
 %include "./interface/SBProcessDocstrings.i"
 %include "./interface/SBProcessInfoDocstrings.i"
@@ -121,8 +122,8 @@
 %include "lldb/API/SBHostOS.h"
 %include "lldb/API/SBInstruction.h"
 %include "lldb/API/SBInstructionList.h"
-%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLanguageRuntime.h"
+%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLaunchInfo.h"
 %includ

[Lldb-commits] [lldb] Add a new affordance that the Python module in a dSYM (PR #133290)

2025-03-27 Thread via lldb-commits

https://github.com/jimingham updated 
https://github.com/llvm/llvm-project/pull/133290

>From effad9525461611ed47598b53a77ee5aabb0e4cf Mon Sep 17 00:00:00 2001
From: Jim Ingham 
Date: Thu, 27 Mar 2025 11:04:26 -0700
Subject: [PATCH 1/2] Add a new affordance that the Python module in a dSYM can
 be told what target it has been loaded into.

When lldb is loading modules, while creating a target, it will run
"command script import" on any Python modules in Resources/Python in the
dSYM.  However, this happens WHILE the target is being created, so it is
not yet in the target list.  That means that these scripts can't act on
the target that they a part of when they get loaded.

This patch adds a new python API that lldb will call:

__lldb_module_added_to_target

if it is defined in the module, passing in the Target the module was being
added to, so that code in these dSYM's don't have to guess.
---
 lldb/bindings/python/python-wrapper.swig  | 22 ++
 .../lldb/Interpreter/ScriptInterpreter.h  |  3 +-
 lldb/source/Core/Module.cpp   |  4 +-
 lldb/source/Interpreter/ScriptInterpreter.cpp |  3 +-
 .../Python/SWIGPythonBridge.h |  4 ++
 .../Python/ScriptInterpreterPython.cpp|  9 ++-
 .../Python/ScriptInterpreterPythonImpl.h  |  3 +-
 lldb/test/API/macosx/dsym_modules/Makefile|  4 ++
 .../macosx/dsym_modules/TestdSYMModuleInit.py | 68 +++
 lldb/test/API/macosx/dsym_modules/has_dsym.py | 21 ++
 lldb/test/API/macosx/dsym_modules/main.c  | 15 
 .../Python/PythonTestSuite.cpp|  7 ++
 12 files changed, 158 insertions(+), 5 deletions(-)
 create mode 100644 lldb/test/API/macosx/dsym_modules/Makefile
 create mode 100644 lldb/test/API/macosx/dsym_modules/TestdSYMModuleInit.py
 create mode 100644 lldb/test/API/macosx/dsym_modules/has_dsym.py
 create mode 100644 lldb/test/API/macosx/dsym_modules/main.c

diff --git a/lldb/bindings/python/python-wrapper.swig 
b/lldb/bindings/python/python-wrapper.swig
index 57c7ac387145e..3d1d04e47e70b 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -966,6 +966,28 @@ bool 
lldb_private::python::SWIGBridge::LLDBSWIGPythonRunScriptKeywordValue(
   return true;
 }
 
+bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleNewTarget(
+const char *python_module_name, const char *session_dictionary_name,
+lldb::TargetSP target_sp) {
+  std::string python_function_name_string = python_module_name;
+  python_function_name_string += ".__lldb_module_added_to_target";
+  const char *python_function_name = python_function_name_string.c_str();
+
+  PyErr_Cleaner py_err_cleaner(true);
+
+  auto dict = PythonModule::MainModule().ResolveName(
+  session_dictionary_name);
+  auto pfunc = PythonObject::ResolveNameWithDictionary(
+  python_function_name, dict);
+
+  if (!pfunc.IsAllocated())
+return true;
+
+  pfunc(SWIGBridge::ToSWIGWrapper(std::move(target_sp)), dict);
+
+  return true;
+}
+
 bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallModuleInit(
 const char *python_module_name, const char *session_dictionary_name,
 lldb::DebuggerSP debugger) {
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h 
b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index c5aa19959aa61..25e82779f05c6 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -522,7 +522,8 @@ class ScriptInterpreter : public PluginInterface {
   LoadScriptingModule(const char *filename, const LoadScriptOptions &options,
   lldb_private::Status &error,
   StructuredData::ObjectSP *module_sp = nullptr,
-  FileSpec extra_search_dir = {});
+  FileSpec extra_search_dir = {},
+  lldb::TargetSP loaded_into_target_sp = {});
 
   virtual bool IsReservedWord(const char *word) { return false; }
 
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index d70f292abaea4..7b52ba08cd379 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1485,7 +1485,9 @@ bool Module::LoadScriptingResourceInTarget(Target 
*target, Status &error,
 scripting_fspec.Dump(scripting_stream.AsRawOstream());
 LoadScriptOptions options;
 bool did_load = script_interpreter->LoadScriptingModule(
-scripting_stream.GetData(), options, error);
+scripting_stream.GetData(), options, error,
+/*module_sp*/ nullptr, /*extra_path*/ {}, 
+target->shared_from_this());
 if (!did_load)
   return false;
   }
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp 
b/lldb/source/Interpreter/ScriptInterpreter.cpp
index 4424b6c894356..8d9655a07e7e9 100644
--- a/lldb/source/Interpreter/ScriptInterpreter.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreter.cpp

[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

>From 79241d2f5701ab789f7fdbb5bd881c4494cb67eb Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 27 Mar 2025 11:24:50 -0700
Subject: [PATCH 1/2] [lldb] Expose the Target API mutex through the SB API

Expose u target API mutex through the SB API. This is motivated by
lldb-dap, which is built on top of the SB API and needs a way to execute
a series of SB API calls in an atomic manner (see #131242).

We can solve this problem by either introducing an additional layer of
locking at the DAP level or by exposing the existing locking at the SB
API level. This patch implements the second approach.

This was discussed in an RFC on Discourse [0]. The original
implementation exposed a move-only lock rather than a mutex [1] which
doesn't work well with SWIG 4.0 [2]. This implement the alternative
solution of exposing the mutex rather than the lock. The SBMutex
conforms to the BasicLockable requirement [3] (which is why the methods
are called `lock` and `unlock` rather than Lock and Unlock) so it can be
used as `std::lock_guard` and
`std::unique_lock`.

[0]: 
https://discourse.llvm.org/t/rfc-exposing-the-target-api-lock-through-the-sb-api/85215/6
[1]: https://github.com/llvm/llvm-project/pull/131404
[2]: 
https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377/9
[3]: https://en.cppreference.com/w/cpp/named_req/BasicLockable
---
 lldb/bindings/interface/SBMutexExtensions.i   | 12 
 lldb/bindings/interfaces.swig |  4 +-
 lldb/include/lldb/API/LLDB.h  |  1 +
 lldb/include/lldb/API/SBDefines.h |  1 +
 lldb/include/lldb/API/SBMutex.h   | 48 +++
 lldb/include/lldb/API/SBTarget.h  |  4 +-
 lldb/include/lldb/Target/Target.h | 16 +
 lldb/source/API/CMakeLists.txt|  1 +
 lldb/source/API/SBMutex.cpp   | 59 ++
 lldb/source/API/SBTarget.cpp  | 16 +++--
 .../API/python_api/target/TestTargetAPI.py| 24 
 lldb/unittests/API/CMakeLists.txt |  1 +
 lldb/unittests/API/SBMutexTest.cpp| 60 +++
 13 files changed, 241 insertions(+), 6 deletions(-)
 create mode 100644 lldb/bindings/interface/SBMutexExtensions.i
 create mode 100644 lldb/include/lldb/API/SBMutex.h
 create mode 100644 lldb/source/API/SBMutex.cpp
 create mode 100644 lldb/unittests/API/SBMutexTest.cpp

diff --git a/lldb/bindings/interface/SBMutexExtensions.i 
b/lldb/bindings/interface/SBMutexExtensions.i
new file mode 100644
index 0..32d3fee468697
--- /dev/null
+++ b/lldb/bindings/interface/SBMutexExtensions.i
@@ -0,0 +1,12 @@
+%extend lldb::SBMutex {
+#ifdef SWIGPYTHON
+%pythoncode %{
+def __enter__(self):
+self.lock()
+return self
+
+def __exit__(self, exc_type, exc_value, traceback):
+self.unlock()
+%}
+#endif
+}
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index 08df9a1a8d539..e36f2f9dd27c6 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -51,6 +51,7 @@
 %include "./interface/SBMemoryRegionInfoListDocstrings.i"
 %include "./interface/SBModuleDocstrings.i"
 %include "./interface/SBModuleSpecDocstrings.i"
+%include "./interface/SBMutexExtensions.i"
 %include "./interface/SBPlatformDocstrings.i"
 %include "./interface/SBProcessDocstrings.i"
 %include "./interface/SBProcessInfoDocstrings.i"
@@ -121,8 +122,8 @@
 %include "lldb/API/SBHostOS.h"
 %include "lldb/API/SBInstruction.h"
 %include "lldb/API/SBInstructionList.h"
-%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLanguageRuntime.h"
+%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLaunchInfo.h"
 %include "lldb/API/SBLineEntry.h"
 %include "lldb/API/SBListener.h"
@@ -130,6 +131,7 @@
 %include "lldb/API/SBMemoryRegionInfoList.h"
 %include "lldb/API/SBModule.h"
 %include "lldb/API/SBModuleSpec.h"
+%include "lldb/API/SBMutex.h"
 %include "lldb/API/SBPlatform.h"
 %include "lldb/API/SBProcess.h"
 %include "lldb/API/SBProcessInfo.h"
diff --git a/lldb/include/lldb/API/LLDB.h b/lldb/include/lldb/API/LLDB.h
index 126fcef31b416..6485f35302a1c 100644
--- a/lldb/include/lldb/API/LLDB.h
+++ b/lldb/include/lldb/API/LLDB.h
@@ -50,6 +50,7 @@
 #include "lldb/API/SBMemoryRegionInfoList.h"
 #include "lldb/API/SBModule.h"
 #include "lldb/API/SBModuleSpec.h"
+#include "lldb/API/SBMutex.h"
 #include "lldb/API/SBPlatform.h"
 #include "lldb/API/SBProcess.h"
 #include "lldb/API/SBProcessInfo.h"
diff --git a/lldb/include/lldb/API/SBDefines.h 
b/lldb/include/lldb/API/SBDefines.h
index ed5a80da117a5..85f6bbeea5bf9 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -89,6 +89,7 @@ class LLDB_API SBMemoryRegionInfoList;
 class LLDB_API SBModule;
 class LLDB_API SBModuleSpec;
 class LLDB_API SBModuleSpecList;
+class LLDB_API SBMutex;
 cla

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =
+  address + GetInteger(arguments, "offset").value_or(0);
+
+  llvm::StringRef data64 = GetString(arguments, "data").value_or("");
+
+  // The VSCode IDE or other DAP clients send memory data as a Base64 string.
+  // This function decodes it into raw binary before writing it to the target
+  // process memory.
+  std::vector output;
+  auto decodeError = llvm::decodeBase64(data64, output);

clayborg wrote:

s/decodeError/decode_error/

https://github.com/llvm/llvm-project/pull/131820

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =
+  address + GetInteger(arguments, "offset").value_or(0);
+
+  llvm::StringRef data64 = GetString(arguments, "data").value_or("");

clayborg wrote:

Do we want to return an error if data64 is empty here? Would be good to test no 
data or an empty data in the tests. Or will the `decodeError` error below catch 
this? If the "data" argument is not there or empty, we should return an 
appropriate error, otherwise we will fall through to below and we will return 
`writeError.GetCString()` as the error, but wri

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =

clayborg wrote:

`memory_reference`

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


[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =
+  address + GetInteger(arguments, "offset").value_or(0);
+
+  llvm::StringRef data64 = GetString(arguments, "data").value_or("");
+
+  // The VSCode IDE or other DAP clients send memory data as a Base64 string.
+  // This function decodes it into raw binary before writing it to the target
+  // process memory.
+  std::vector output;
+  auto decodeError = llvm::decodeBase64(data64, output);
+
+  if (decodeError) {
+response["success"] = false;
+EmplaceSafeString(response, "message",
+  llvm::t

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =
+  address + GetInteger(arguments, "offset").value_or(0);
+
+  llvm::StringRef data64 = GetString(arguments, "data").value_or("");
+
+  // The VSCode IDE or other DAP clients send memory data as a Base64 string.
+  // This function decodes it into raw binary before writing it to the target
+  // process memory.
+  std::vector output;
+  auto decodeError = llvm::decodeBase64(data64, output);
+
+  if (decodeError) {
+response["success"] = false;
+EmplaceSafeString(response, "message",
+  llvm::t

[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Expose u target API mutex through the SB API. This is motivated by lldb-dap, 
which is built on top of the SB API and needs a way to execute a series of SB 
API calls in an atomic manner (see #131242).

We can solve this problem by either introducing an additional layer of locking 
at the DAP level or by exposing the existing locking at the SB API level. This 
patch implements the second approach.

This was discussed in an RFC on Discourse [0]. The original implementation 
exposed a move-only lock rather than a mutex [1] which doesn't work well with 
SWIG 4.0 [2]. This implement the alternative solution of exposing the mutex 
rather than the lock. The SBMutex conforms to the BasicLockable requirement [3] 
(which is why the methods are called `lock` and `unlock` rather than Lock and 
Unlock) so it can be used as `std::lock_guard` and
`std::unique_lock`.

[0]: 
https://discourse.llvm.org/t/rfc-exposing-the-target-api-lock-through-the-sb-api/85215/6
[1]: https://github.com/llvm/llvm-project/pull/131404
[2]: 
https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377/9
[3]: https://en.cppreference.com/w/cpp/named_req/BasicLockable

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


13 Files Affected:

- (added) lldb/bindings/interface/SBMutexExtensions.i (+12) 
- (modified) lldb/bindings/interfaces.swig (+3-1) 
- (modified) lldb/include/lldb/API/LLDB.h (+1) 
- (modified) lldb/include/lldb/API/SBDefines.h (+1) 
- (added) lldb/include/lldb/API/SBMutex.h (+48) 
- (modified) lldb/include/lldb/API/SBTarget.h (+3-1) 
- (modified) lldb/include/lldb/Target/Target.h (+16) 
- (modified) lldb/source/API/CMakeLists.txt (+1) 
- (added) lldb/source/API/SBMutex.cpp (+59) 
- (modified) lldb/source/API/SBTarget.cpp (+12-4) 
- (modified) lldb/test/API/python_api/target/TestTargetAPI.py (+24) 
- (modified) lldb/unittests/API/CMakeLists.txt (+1) 
- (added) lldb/unittests/API/SBMutexTest.cpp (+60) 


``diff
diff --git a/lldb/bindings/interface/SBMutexExtensions.i 
b/lldb/bindings/interface/SBMutexExtensions.i
new file mode 100644
index 0..32d3fee468697
--- /dev/null
+++ b/lldb/bindings/interface/SBMutexExtensions.i
@@ -0,0 +1,12 @@
+%extend lldb::SBMutex {
+#ifdef SWIGPYTHON
+%pythoncode %{
+def __enter__(self):
+self.lock()
+return self
+
+def __exit__(self, exc_type, exc_value, traceback):
+self.unlock()
+%}
+#endif
+}
diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index 08df9a1a8d539..e36f2f9dd27c6 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -51,6 +51,7 @@
 %include "./interface/SBMemoryRegionInfoListDocstrings.i"
 %include "./interface/SBModuleDocstrings.i"
 %include "./interface/SBModuleSpecDocstrings.i"
+%include "./interface/SBMutexExtensions.i"
 %include "./interface/SBPlatformDocstrings.i"
 %include "./interface/SBProcessDocstrings.i"
 %include "./interface/SBProcessInfoDocstrings.i"
@@ -121,8 +122,8 @@
 %include "lldb/API/SBHostOS.h"
 %include "lldb/API/SBInstruction.h"
 %include "lldb/API/SBInstructionList.h"
-%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLanguageRuntime.h"
+%include "lldb/API/SBLanguages.h"
 %include "lldb/API/SBLaunchInfo.h"
 %include "lldb/API/SBLineEntry.h"
 %include "lldb/API/SBListener.h"
@@ -130,6 +131,7 @@
 %include "lldb/API/SBMemoryRegionInfoList.h"
 %include "lldb/API/SBModule.h"
 %include "lldb/API/SBModuleSpec.h"
+%include "lldb/API/SBMutex.h"
 %include "lldb/API/SBPlatform.h"
 %include "lldb/API/SBProcess.h"
 %include "lldb/API/SBProcessInfo.h"
diff --git a/lldb/include/lldb/API/LLDB.h b/lldb/include/lldb/API/LLDB.h
index 126fcef31b416..6485f35302a1c 100644
--- a/lldb/include/lldb/API/LLDB.h
+++ b/lldb/include/lldb/API/LLDB.h
@@ -50,6 +50,7 @@
 #include "lldb/API/SBMemoryRegionInfoList.h"
 #include "lldb/API/SBModule.h"
 #include "lldb/API/SBModuleSpec.h"
+#include "lldb/API/SBMutex.h"
 #include "lldb/API/SBPlatform.h"
 #include "lldb/API/SBProcess.h"
 #include "lldb/API/SBProcessInfo.h"
diff --git a/lldb/include/lldb/API/SBDefines.h 
b/lldb/include/lldb/API/SBDefines.h
index ed5a80da117a5..85f6bbeea5bf9 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -89,6 +89,7 @@ class LLDB_API SBMemoryRegionInfoList;
 class LLDB_API SBModule;
 class LLDB_API SBModuleSpec;
 class LLDB_API SBModuleSpecList;
+class LLDB_API SBMutex;
 class LLDB_API SBPlatform;
 class LLDB_API SBPlatformConnectOptions;
 class LLDB_API SBPlatformShellCommand;
diff --git a/lldb/include/lldb/API/SBMutex.h b/lldb/include/lldb/API/SBMutex.h
new file mode 100644
index 0..b2cd33a40a6de
--- /dev/null
+++ b/lldb/include/lldb/API/SBMutex.h
@@ -0,0 +1,48 @@
+//===-- SBMutex.h
+//--===//
+//
+// Part of th

[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

Superseded by https://github.com/llvm/llvm-project/pull/133295

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


[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =

clayborg wrote:

`address_offset` seems to indicate this is an offset. Maybe use 
`address_plus_offset`, or just use `address`:
```
lldb::addr_t address = *addr_opt + GetInteger(arguments, 
"offset").value_or(0);
```

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


[Lldb-commits] [lldb] [lldb] Expose the Target API lock through the SB API (PR #131404)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Migrating DAP 'initialize' to new typed RequestHandler. (PR #133007)

2025-03-27 Thread John Harrison via lldb-commits


@@ -54,6 +54,79 @@ bool fromJSON(const llvm::json::Value &, DisconnectArguments 
&,
 /// body field is required.
 using DisconnectResponse = VoidResponse;
 
+/// Arguments for `initialize` request.
+struct InitializeRequestArguments {
+  /// The ID of the debug adapter.
+  std::string adatperID;
+
+  /// The ID of the client using this adapter.
+  std::optional clientID;
+
+  /// The human-readable name of the client using this adapter.
+  std::optional clientName;
+
+  /// The ISO-639 locale of the client using this adapter, e.g. en-US or de-CH.
+  std::optional locale;
+
+  enum class PathFormat { path, uri };
+
+  /// Determines in what format paths are specified. The default is `path`,
+  /// which is the native format.
+  std::optional pathFormat = PathFormat::path;
+
+  /// If true all line numbers are 1-based (default).
+  std::optional linesStartAt1;
+
+  /// If true all column numbers are 1-based (default).
+  std::optional columnsStartAt1;
+
+  enum class Feature {
+/// Client supports the `type` attribute for variables.
+supportsVariableType,
+/// Client supports the paging of variables.
+supportsVariablePaging,
+/// Client supports the `runInTerminal` request.
+supportsRunInTerminalRequest,
+/// Client supports memory references.
+supportsMemoryReferences,
+/// Client supports progress reporting.
+supportsProgressReporting,
+/// Client supports the `invalidated` event.
+supportsInvalidatedEvent,
+/// Client supports the `memory` event.
+supportsMemoryEvent,
+/// Client supports the `argsCanBeInterpretedByShell` attribute on the
+/// `runInTerminal` request.
+supportsArgsCanBeInterpretedByShell,
+/// Client supports the `startDebugging` request.
+supportsStartDebuggingRequest,
+/// The client will interpret ANSI escape sequences in the display of
+/// `OutputEvent.output` and `Variable.value` fields when
+/// `Capabilities.supportsANSIStyling` is also enabled.
+supportsANSIStyling,
+  };

ashgti wrote:

I dropped 'support' from the name to shorten things slightly.

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


[Lldb-commits] [lldb] [lldb] Return *const* UnwindPlan pointers from FuncUnwinders (PR #133247)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

2025-03-27 Thread via lldb-commits

https://github.com/dlav-sc updated 
https://github.com/llvm/llvm-project/pull/112555

>From a9d02c8b0c22138d9337bf33883f7e6c937bd655 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Mon, 14 Oct 2024 14:14:30 +
Subject: [PATCH 1/2] [lldb] add --platform-available-ports option to the
 dotest.py

This patch adds --platform-available-ports option to the dotest.py script
to remove hardcoded gdb ports from lldb testsuite.

Currently, this option could be helpful for GdbRemoteTestCases (e.g.
TestLldbGdbServer, TestNonStop, TestGdbRemoteThreadsInStopReply,
TestGdbRemotePlatformFile, TestGdbRemote_vCont)
---
 lldb/packages/Python/lldbsuite/test/configuration.py   | 1 +
 lldb/packages/Python/lldbsuite/test/dotest.py  | 2 ++
 lldb/packages/Python/lldbsuite/test/dotest_args.py | 7 +++
 lldb/packages/Python/lldbsuite/test/lldbtest.py| 4 
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +++
 5 files changed, 17 insertions(+)

diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py 
b/lldb/packages/Python/lldbsuite/test/configuration.py
index bcc179346836d..18c1566176331 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -103,6 +103,7 @@
 lldb_platform_name = None
 lldb_platform_url = None
 lldb_platform_working_dir = None
+lldb_platform_available_ports = None
 
 # Apple SDK
 apple_sdk = None
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index 681ea1638f2d6..7cc8f2985043e 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -419,6 +419,8 @@ def parseOptionsAndInitTestdirs():
 configuration.lldb_platform_url = args.lldb_platform_url
 if args.lldb_platform_working_dir:
 configuration.lldb_platform_working_dir = 
args.lldb_platform_working_dir
+if args.lldb_platform_available_ports:
+configuration.lldb_platform_available_ports = 
args.lldb_platform_available_ports
 if platform_system == "Darwin" and args.apple_sdk:
 configuration.apple_sdk = args.apple_sdk
 if args.test_build_dir:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index a80428ebec589..18047fdca2a92 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -292,6 +292,13 @@ def create_parser():
 metavar="platform-working-dir",
 help="The directory to use on the remote platform.",
 )
+group.add_argument(
+"--platform-available-ports",
+dest="lldb_platform_available_ports",
+type=lambda ports: [int(port.strip()) for port in ports.split(":")],
+metavar="platform-available-ports",
+help="Ports available for connection to a lldb server on the remote 
platform",
+)
 
 # Test-suite behaviour
 group = parser.add_argument_group("Runtime behaviour options")
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 570c36b5f9622..2e370564939d8 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -749,6 +749,10 @@ def getSourcePath(self, name):
 """Return absolute path to a file in the test's source directory."""
 return os.path.join(self.getSourceDir(), name)
 
+def getPlatformAvailablePorts(self):
+"""Return ports available for connection to a lldb server on the 
remote platform."""
+return configuration.lldb_platform_available_ports
+
 @classmethod
 def setUpCommands(cls):
 commands = [
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 3d3ecb9aa8f95..029aaf3164697 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -185,6 +185,9 @@ def setUpServerLogging(self, is_llgs):
 ]
 
 def get_next_port(self):
+available_ports = self.getPlatformAvailablePorts()
+if available_ports:
+return random.choice(available_ports)
 return 12000 + random.randint(0, 7999)
 
 def reset_test_sequence(self):

>From 1148438286f603cd0934595a7d9c9cf25af54fc6 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Thu, 27 Mar 2025 14:36:56 +
Subject: [PATCH 2/2] NFC

---
 lldb/packages/Python/lldbsuite/test/dotest_args.py | 2 +-
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index 18047fdca2a92..11

[Lldb-commits] [lldb] [LLDB][Telemetry] Collect telemetry from client when allowed. (PR #129728)

2025-03-27 Thread Vy Nguyen via lldb-commits

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

>From 21103adacdf9c08cee4065f8a6b90ff812fefbb3 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Tue, 4 Mar 2025 11:01:46 -0500
Subject: [PATCH 01/19] [LLDB][Telemetry] Collect telemetry from client when
 allowed.

This patch is slightly different from other impl in that we dispatch 
client-telemetry via a different helper method.
This is to make it easier for vendor to opt-out (simply by overriding the 
method to do nothing).
There is also a configuration option to disallow collecting client telemetry.
---
 lldb/include/lldb/API/SBDebugger.h|  3 +
 lldb/include/lldb/Core/Debugger.h |  5 ++
 lldb/include/lldb/Core/Telemetry.h| 89 +---
 lldb/source/API/SBDebugger.cpp| 11 +++
 lldb/source/Core/Debugger.cpp |  6 ++
 lldb/source/Core/Telemetry.cpp| 99 +++
 lldb/tools/lldb-dap/DAP.cpp   |  5 +-
 lldb/tools/lldb-dap/LLDBUtils.h   | 34 +
 lldb/unittests/Core/TelemetryTest.cpp |  2 +-
 9 files changed, 214 insertions(+), 40 deletions(-)

diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index e0819f1684f8b..28f92f2095951 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -13,6 +13,7 @@
 
 #include "lldb/API/SBDefines.h"
 #include "lldb/API/SBPlatform.h"
+#include "lldb/API/SBStructuredData.h"
 
 namespace lldb_private {
 class CommandPluginInterfaceImplementation;
@@ -249,6 +250,8 @@ class LLDB_API SBDebugger {
 
   lldb::SBTarget GetDummyTarget();
 
+  void DispatchClientTelemetry(const lldb::SBStructuredData &data);
+
   // Return true if target is deleted from the target list of the debugger.
   bool DeleteTarget(lldb::SBTarget &target);
 
diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 6ebc6147800e1..e40666d5ceec7 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -19,6 +19,8 @@
 #include "lldb/Core/FormatEntity.h"
 #include "lldb/Core/IOHandler.h"
 #include "lldb/Core/SourceManager.h"
+#include "lldb/Core/StructuredDataImpl.h"
+#include "lldb/Core/Telemetry.h"
 #include "lldb/Core/UserSettingsController.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/StreamFile.h"
@@ -31,6 +33,7 @@
 #include "lldb/Utility/Diagnostics.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Status.h"
+#include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
@@ -127,6 +130,8 @@ class Debugger : public 
std::enable_shared_from_this,
 
   void Clear();
 
+  void DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry);
+
   bool GetAsyncExecution();
 
   void SetAsyncExecution(bool async);
diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index 7d8716f1659b5..cad4a4a6c9048 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Telemetry/Telemetry.h"
+#include 
 #include 
 #include 
 #include 
@@ -28,6 +29,23 @@
 namespace lldb_private {
 namespace telemetry {
 
+struct LLDBConfig : public ::llvm::telemetry::Config {
+  // If true, we will collect full details about a debug command (eg., args and
+  // original command). Note: This may contain PII, hence can only be enabled 
by
+  // the vendor while creating the Manager.
+  const bool m_detailed_command_telemetry;
+  // If true, we will collect telemetry from LLDB's clients (eg., lldb-dap) via
+  // the SB interface. Must also be enabled by the vendor while creating the
+  // manager.
+  const bool m_enable_client_telemetry;
+
+  explicit LLDBConfig(bool enable_telemetry, bool detailed_command_telemetry,
+  bool enable_client_telemetry)
+  : ::llvm::telemetry::Config(enable_telemetry),
+m_detailed_command_telemetry(detailed_command_telemetry),
+m_enable_client_telemetry(enable_client_telemetry) {}
+};
+
 // We expect each (direct) subclass of LLDBTelemetryInfo to
 // have an LLDBEntryKind in the form 0b11
 // Specifically:
@@ -37,6 +55,7 @@ namespace telemetry {
 // must have their LLDBEntryKind in the similar form (ie., share common prefix)
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
   static const llvm::telemetry::KindType BaseInfo = 0b1100;
+  static const llvm::telemetry::KindType ClientInfo = 0b1110;
   static const llvm::telemetry::KindType DebuggerInfo = 0b11000100;
 };
 
@@ -86,6 +105,11 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ClientInfo : public LLDBBaseTelemetryInfo {
+  std::string request_name;
+  std::optional error_msg;
+};
+
 /// The base Telemetry manager instance in LL

[Lldb-commits] [lldb] [lldb] Return *const* UnwindPlan pointers from FuncUnwinders (PR #133247)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -36,18 +36,19 @@ class FuncUnwinders {
 
   ~FuncUnwinders();
 
-  lldb::UnwindPlanSP GetUnwindPlanAtCallSite(Target &target, Thread &thread);
+  std::shared_ptr GetUnwindPlanAtCallSite(Target &target,

JDevlieghere wrote:

Can we change the `UnwindPlanSP` typedef? Do we ever need a non-const 
UnwindPlan shared pointer?

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


[Lldb-commits] [lldb] [lldb] Emit progress events in SymbolFileDWARFDebugMap (PR #133211)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

>From ed2905d3abc064476627863c9b9f1266fb6c5a55 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 26 Mar 2025 22:49:39 -0700
Subject: [PATCH 1/2] [lldb] Emit progress events in SymbolFileDWARFDebugMap

Emit progress events from SymbolFileDWARFDebugMap. Because we know the
number of OSOs, we can show determinate progress.

This is based on a patch from Adrian, and what prompted me to look into
improving how LLDB shows progress events. Before the statusline, all
these progress events would get shadowed.
---
 .../DWARF/SymbolFileDWARFDebugMap.cpp | 164 +++---
 .../DWARF/SymbolFileDWARFDebugMap.h   |  11 +-
 2 files changed, 99 insertions(+), 76 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 0ecf47a3c7869..f529a76f65c1f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Progress.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Utility/RangeMap.h"
@@ -31,6 +32,7 @@
 #include "lldb/Symbol/TypeMap.h"
 #include "lldb/Symbol/VariableList.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 
 #include "lldb/Target/StackFrame.h"
@@ -716,6 +718,27 @@ bool SymbolFileDWARFDebugMap::ParseDebugMacros(CompileUnit 
&comp_unit) {
   return false;
 }
 
+void SymbolFileDWARFDebugMap::ForEachSymbolFile(
+std::string description,
+std::function closure) {
+  const size_t num_oso_idxs = m_compile_unit_infos.size();
+  const size_t update_rate = std::max(1, num_oso_idxs / 100);
+  Progress progress(std::move(description), "", num_oso_idxs);
+  for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
+if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
+  if (oso_idx % update_rate == 0)
+progress.Increment(oso_idx, oso_dwarf->GetObjectFile()
+? oso_dwarf->GetObjectFile()
+  ->GetFileSpec()
+  .GetFilename()
+  .GetString()
+: std::string());
+  if (closure(oso_dwarf) == IterationAction::Stop)
+return;
+}
+  }
+}
+
 bool SymbolFileDWARFDebugMap::ForEachExternalModule(
 CompileUnit &comp_unit,
 llvm::DenseSet &visited_symbol_files,
@@ -804,7 +827,7 @@ SymbolFileDWARFDebugMap::GetDynamicArrayInfoForUID(
 bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) {
   bool success = false;
   if (compiler_type) {
-ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
+ForEachSymbolFile("Completing type", [&](SymbolFileDWARF *oso_dwarf) {
   if (oso_dwarf->HasForwardDeclForCompilerType(compiler_type)) {
 oso_dwarf->CompleteType(compiler_type);
 success = true;
@@ -924,29 +947,31 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
   std::lock_guard guard(GetModuleMutex());
   uint32_t total_matches = 0;
 
-  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
-const uint32_t old_size = variables.GetSize();
-oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
-   variables);
-const uint32_t oso_matches = variables.GetSize() - old_size;
-if (oso_matches > 0) {
-  total_matches += oso_matches;
-
-  // Are we getting all matches?
-  if (max_matches == UINT32_MAX)
-return IterationAction::Continue; // Yep, continue getting everything
-
-  // If we have found enough matches, lets get out
-  if (max_matches >= total_matches)
-return IterationAction::Stop;
-
-  // Update the max matches for any subsequent calls to find globals in any
-  // other object files with DWARF
-  max_matches -= oso_matches;
-}
+  ForEachSymbolFile(
+  "Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
+const uint32_t old_size = variables.GetSize();
+oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
+   variables);
+const uint32_t oso_matches = variables.GetSize() - old_size;
+if (oso_matches > 0) {
+  total_matches += oso_matches;
+
+  // Are we getting all matches?
+  if (max_matches == UINT32_MAX)
+return IterationAction::Continue; // Yep, continue getting
+  // everything
+
+  // If we have found enough matches, lets get out
+  if (max_matches >= total_matches)
+   

[Lldb-commits] [lldb] [lldb][Target] Clear selected frame index after a StopInfo::PerformAction (PR #133078)

2025-03-27 Thread via lldb-commits


@@ -936,3 +936,7 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t 
first_frame,
   strm.IndentLess();
   return num_frames_displayed;
 }
+
+void StackFrameList::ClearSelectedFrameIndex() {

jimingham wrote:

lldb really only should have an opinion about the selected frame index when a 
process stops, before control gets handed back to the user.  After that, it's 
up to them to change it whenever they feel like it.  So maybe we don't need to 
be as protective of this ivar?

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


[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread Santhosh Kumar Ellendula via lldb-commits


@@ -0,0 +1,175 @@
+//===-- WriteMemoryRequestHandler.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 "JSONUtils.h"
+#include "RequestHandler.h"
+#include "lldb/API/SBMemoryRegionInfo.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Base64.h"
+
+namespace lldb_dap {
+
+// "WriteMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Writes bytes to memory at the provided location.\n
+// Clients should only call this request if the corresponding
+// capability `supportsWriteMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "writeMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/WriteMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "WriteMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `writeMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location to which
+//   data should be written."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before writing data. Can be negative."
+// },
+// "allowPartial": {
+//   "type": "boolean",
+//   "description": "Property to control partial writes. If true, the
+//   debug adapter should attempt to write memory even if the entire
+//   memory region is not writable. In such a case the debug adapter
+//   should stop after hitting the first byte of memory that cannot be
+//   written and return the number of bytes written in the response
+//   via the `offset` and `bytesWritten` properties.\nIf false or
+//   missing, a debug adapter should attempt to verify the region is
+//   writable before writing, and fail the response if it is not."
+// },
+// "data": {
+//   "type": "string",
+//   "description": "Bytes to write, encoded using base64."
+// }
+//   },
+//   "required": [ "memoryReference", "data" ]
+// },
+// "WriteMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `writeMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "offset": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the offset of the first
+// byte of data successfully written. Can be negative."
+//   },
+//   "bytesWritten": {
+// "type": "integer",
+// "description": "Property that should be returned when
+// `allowPartial` is true to indicate the number of bytes
+// starting from address that were successfully written."
+//   }
+// }
+//   }
+// }
+//   }]
+// },
+void WriteMemoryRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference =
+  GetString(arguments, "memoryReference").value_or("");
+
+  auto addr_opt = DecodeMemoryReference(memoryReference);
+  if (!addr_opt.has_value()) {
+response["success"] = false;
+response["message"] =
+"Malformed memory reference: " + memoryReference.str();
+dap.SendJSON(llvm::json::Value(std::move(response)));
+return;
+  }
+
+  lldb::addr_t address = *addr_opt;
+  lldb::addr_t address_offset =
+  address + GetInteger(arguments, "offset").value_or(0);
+
+  llvm::StringRef data64 = GetString(arguments, "data").value_or("");
+
+  // The VSCode IDE or other DAP clients send memory data as a Base64 string.
+  // This function decodes it into raw binary before writing it to the target
+  // process memory.
+  std::vector output;
+  auto decodeError = llvm::decodeBase64(data64, output);
+
+  if (decodeError) {
+response["success"] = false;
+EmplaceSafeString(response, "message",
+  llvm::t

[Lldb-commits] [lldb] [lldb][lldb-dap] Added support for "WriteMemory" request. (PR #131820)

2025-03-27 Thread John Harrison via lldb-commits


@@ -112,3 +112,48 @@ def test_readMemory(self):
 # Reads at offset 0x0 fail
 mem = self.dap_server.request_readMemory("0x0", 0, 6)
 self.assertEqual(mem["success"], False)
+
+def test_writeMemory(self):
+"""
+Tests the 'writeMemory' request
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+source = "main.cpp"
+self.source_path = os.path.join(os.getcwd(), source)
+self.set_source_breakpoints(
+source,
+[line_number(source, "// Breakpoint")],
+)
+self.continue_to_next_stop()
+
+# Get the 'not_a_ptr' writable variablle reference address.
+ptr_deref = self.dap_server.request_evaluate("not_a_ptr")["body"]
+memref = ptr_deref["memoryReference"]
+
+# Write the Base64-encoded string "Mg==", which decodes to binary 0x32

ashgti wrote:

Or you can use `base64.b64encode((50).to_bytes())` to get the `Mg==` value

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


[Lldb-commits] [clang] [clang-tools-extra] [lldb] Reland: [clang] preserve class type sugar when taking pointer to member (PR #132401)

2025-03-27 Thread via lldb-commits

earnol wrote:

Could you please look into https://github.com/llvm/llvm-project/issues/133144? 
It looks like to be caused by your change.

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


[Lldb-commits] [lldb] 17aca79 - [lldb] Teach FuncUnwinders about discontinuous functions (#133072)

2025-03-27 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-03-27T12:51:20+01:00
New Revision: 17aca79d98d92510d131c4766a040b02adf6c4b8

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

LOG: [lldb] Teach FuncUnwinders about discontinuous functions (#133072)

The main change here is that we're now able to correctly look up plans
for these functions. Previously, due to caching, we could end up with
one entry covering most of the address space (because part of the
function was at the beginning and one at the end). Now, we can correctly
recognise that the part in between does not belong to that function, and
we can create a different FuncUnwinders instance for it. It doesn't help
the discontinuous function much (its plan will still be garbled), but
we can at least properly unwind out of the simple functions in between.

Fixing the unwind plans for discontinuous functions requires handling
each unwind source specially, and this setup allows us to make the
transition incrementally.

Added: 
lldb/test/Shell/Unwind/Inputs/basic-block-sections-with-dwarf.s
lldb/test/Shell/Unwind/Inputs/linux-x86_64.yaml
lldb/test/Shell/Unwind/basic-block-sections-with-dwarf-static.test
lldb/test/Shell/Unwind/basic-block-sections-with-dwarf.test

Modified: 
lldb/include/lldb/Symbol/FuncUnwinders.h
lldb/include/lldb/Symbol/UnwindTable.h
lldb/source/Symbol/FuncUnwinders.cpp
lldb/source/Symbol/UnwindTable.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/FuncUnwinders.h 
b/lldb/include/lldb/Symbol/FuncUnwinders.h
index 2e841b3b34bd6..1d4c28324e90f 100644
--- a/lldb/include/lldb/Symbol/FuncUnwinders.h
+++ b/lldb/include/lldb/Symbol/FuncUnwinders.h
@@ -13,9 +13,9 @@ class UnwindTable;
 class FuncUnwinders {
 public:
   // FuncUnwinders objects are used to track UnwindPlans for a function (named
-  // or not - really just an address range)
+  // or not - really just a set of address ranges)
 
-  // We'll record four 
diff erent UnwindPlans for each address range:
+  // We'll record four 
diff erent UnwindPlans for each function:
   //
   //   1. Unwinding from a call site (a valid exception throw location)
   //  This is often sourced from the eh_frame exception handling info
@@ -31,7 +31,8 @@ class FuncUnwinders {
   // instructions are finished for migrating breakpoints past the stack frame
   // setup instructions when we don't have line table information.
 
-  FuncUnwinders(lldb_private::UnwindTable &unwind_table, AddressRange range);
+  FuncUnwinders(lldb_private::UnwindTable &unwind_table, Address addr,
+AddressRanges ranges);
 
   ~FuncUnwinders();
 
@@ -54,7 +55,9 @@ class FuncUnwinders {
   const Address &GetFunctionStartAddress() const;
 
   bool ContainsAddress(const Address &addr) const {
-return m_range.ContainsFileAddress(addr);
+return llvm::any_of(m_ranges, [&](const AddressRange range) {
+  return range.ContainsFileAddress(addr);
+});
   }
 
   // A function may have a Language Specific Data Area specified -- a block of
@@ -113,6 +116,15 @@ class FuncUnwinders {
   Thread &thread, const lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP 
&b);
 
   UnwindTable &m_unwind_table;
+
+  /// Start address of the function described by this object.
+  Address m_addr;
+
+  /// The address ranges of the function.
+  AddressRanges m_ranges;
+
+  /// The smallest address range covering the entire function.
+  /// DEPRECATED: Use m_ranges instead.
   AddressRange m_range;
 
   std::recursive_mutex m_mutex;

diff  --git a/lldb/include/lldb/Symbol/UnwindTable.h 
b/lldb/include/lldb/Symbol/UnwindTable.h
index 3166fdec6ebaa..1cc718efb28d6 100644
--- a/lldb/include/lldb/Symbol/UnwindTable.h
+++ b/lldb/include/lldb/Symbol/UnwindTable.h
@@ -66,8 +66,7 @@ class UnwindTable {
   void Dump(Stream &s);
 
   void Initialize();
-  std::optional GetAddressRange(const Address &addr,
-  const SymbolContext &sc);
+  AddressRanges GetAddressRanges(const Address &addr, const SymbolContext &sc);
 
   typedef std::map collection;
   typedef collection::iterator iterator;

diff  --git a/lldb/source/Symbol/FuncUnwinders.cpp 
b/lldb/source/Symbol/FuncUnwinders.cpp
index 2449c82812696..a5ca7b094c949 100644
--- a/lldb/source/Symbol/FuncUnwinders.cpp
+++ b/lldb/source/Symbol/FuncUnwinders.cpp
@@ -31,15 +31,29 @@
 using namespace lldb;
 using namespace lldb_private;
 
-/// constructor
-
-FuncUnwinders::FuncUnwinders(UnwindTable &unwind_table, AddressRange range)
-: m_unwind_table(unwind_table), m_range(range), m_mutex(),
-  m_unwind_plan_assembly_sp(), m_unwind_plan_eh_frame_sp(),
-  m_unwind_plan_eh_frame_augmented_sp(), m_unwind_plan_compact_unwind(),
-  m_unwind_plan_arm_unwind_sp(), m_unwind_plan_fast_sp(),
-  m_unwind_plan_arc

[Lldb-commits] [lldb] [llvm] [lldb] Remove lldb-server min and max gdbserver port options (PR #133275)

2025-03-27 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)


Changes

Since lldb 20, these have had no effect:
https://releases.llvm.org/20.1.0/docs/ReleaseNotes.html#changes-to-lldb

> lldb-server now listens to a single port for gdbserver connections and
> provides that port to the connection handler processes. This means that
> only 2 ports need to be opened in the firewall (one for the lldb-server
> platform, one for gdbserver connections). In addition, due to this work,
lldb-server now works on Windows in the server mode.

Remove them.

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


2 Files Affected:

- (modified) lldb/tools/lldb-server/lldb-platform.cpp (-2) 
- (modified) llvm/docs/ReleaseNotes.md (+3) 


``diff
diff --git a/lldb/tools/lldb-server/lldb-platform.cpp 
b/lldb/tools/lldb-server/lldb-platform.cpp
index 880b45b989b9c..24a2ea12ae3f1 100644
--- a/lldb/tools/lldb-server/lldb-platform.cpp
+++ b/lldb/tools/lldb-server/lldb-platform.cpp
@@ -66,8 +66,6 @@ static struct option g_long_options[] = {
 {"log-channels", required_argument, nullptr, 'c'},
 {"listen", required_argument, nullptr, 'L'},
 {"gdbserver-port", required_argument, nullptr, 'P'},
-{"min-gdbserver-port", required_argument, nullptr, 'm'},
-{"max-gdbserver-port", required_argument, nullptr, 'M'},
 {"socket-file", required_argument, nullptr, 'f'},
 {"server", no_argument, &g_server, 1},
 {"child-platform-fd", required_argument, nullptr, 2},
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index bb75aec44ef8e..c633d9ca9bd52 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -214,6 +214,9 @@ Changes to LLDB
   Windows 11 on the Microsoft SQ2 and Snapdragon Elite X platforms.
 * LLDB now steps through C++ thunks. This fixes an issue where previously, it
   wouldn't step into multiple inheritance virtual functions.
+* The `min-gdbserver-port` and `max-gdbserver-port` options have been removed
+  from `lldb-server`'s platform mode. Since the changes to `lldb-server`'s port
+  handling in LLDB 20, these options have had no effect.
 
 ### Changes to lldb-dap
 

``




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


[Lldb-commits] [lldb] [lldb] Remove raw access to PluginInstances vector (PR #132884)

2025-03-27 Thread David Peixotto via lldb-commits

dmpots wrote:

> > We did consider this approach. There are some drawbacks beyond the 
> > performance issue, but the tradeoff may be worth it.
> > If we define the method like: `std::vector 
> > GetEnabledInstances()` then we are returning copies of the PluginInstance. 
> > Anything that modifies the internal state of the `PluginInstance` will be 
> > lost since it is operating on a copy (e.g. 
> > `GetEnabledInstances().front().DoSomethingToModifyInternalState()`).
> 
> Is that a theoretical concern or actually something that happens (or will 
> happen with your patches)? Looking at the existing code, it doesn't look like 
> anyone is modifying the instance and I can remove the non-const overload and 
> we still compile. If anything, we probably don't want anyone to change these 
> things as we're iterating over them.

More of a theoretical concern. I have a later patch that adds a `bool enabled` 
member to the PluginInstance. so updates to that would be ignored. But we could 
store the enabled state outside the PluginInstance by changing the vector to a 
pair of `{instance, enabled}`.

There were lots of plugins and I did not look in detail to see if they had 
internal state. But as you said if we remove the const overload and everything 
still works then we are a probably safe with the current set of instances.

As long as we are ok with a change from reference semantics to copy semantics 
for future use cases as well then I think we could go this route.

> > We could also return pointers to the plugin instances 
> > like`std::vector GetEnabledInstances()`. But these would 
> > be pointers to the locations in the vector stored in the `PluginInstance` 
> > class. So if a new plugin is added to the PluginInstances list the pointers 
> > could be invalidated. Probably not an issue with the current code, but 
> > could be unsafe to hand out those references in general.
> 
> While definitely unsafe an something I think we shouldn't do, that's a 
> problem today too if someone were to modify the instance list from another 
> thread or take the address of one of its elements.

In this sense returning a copy is safer (but we would need to protect access to 
the underlying vector while making the copy if we really think its a problem).
 
> > I suppose another way would be to keep a 
> > `std::vector>` and then creating a copy would 
> > not be an issue since any updates would also modify the original object.
> 
> I'd like to avoid shared_pointers if possible, but we could achieve the same 
> thing by storing unique pointers in the vector and handing out raw points 
> like you suggested above.

If you are ok with removing the reference semantics then we should probably 
just return a copy since that is the simplest solution.

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


[Lldb-commits] [lldb] [lldb][Target] Clear selected frame index after a StopInfo::PerformAction (PR #133078)

2025-03-27 Thread via lldb-commits


@@ -936,3 +936,7 @@ size_t StackFrameList::GetStatus(Stream &strm, uint32_t 
first_frame,
   strm.IndentLess();
   return num_frames_displayed;
 }
+
+void StackFrameList::ClearSelectedFrameIndex() {

jimingham wrote:

I'm not sure what we'd do if two parts of lldb decided they wanted to be in 
control of the selected frame index on stop.  That seems like a bad idea, but 
I'm not sure the right way to fix it would be just to lock the selected frame 
index just at the point of setting it.  There would need to be some explicit 
negotiation for who gets to control this.

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


[Lldb-commits] [lldb] [LLDB][Telemetry] Collect telemetry from client when allowed. (PR #129728)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

2025-03-27 Thread via lldb-commits


@@ -185,6 +185,9 @@ def setUpServerLogging(self, is_llgs):
 ]
 
 def get_next_port(self):
+available_ports = self.getPlatformAvailablePorts()
+if available_ports:

dlav-sc wrote:

addressed

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


[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

2025-03-27 Thread via lldb-commits


@@ -292,6 +292,13 @@ def create_parser():
 metavar="platform-working-dir",
 help="The directory to use on the remote platform.",
 )
+group.add_argument(
+"--platform-available-ports",
+dest="lldb_platform_available_ports",
+type=lambda ports: [int(port.strip()) for port in ports.split(":")],
+metavar="platform-available-ports",
+help="Ports available for connection to a lldb server on the remote 
platform",
+)

dlav-sc wrote:

addressed

> Does something prevent that here?

I'm just bad at python :3

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


[Lldb-commits] [lldb] [llvm] [lldb] Remove lldb-server min and max gdbserver port options (PR #133275)

2025-03-27 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][debugserver] Interrupt should reset outstanding SIGSTOP (PR #132128)

2025-03-27 Thread Jason Molenda via lldb-commits


@@ -1594,6 +1594,10 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
  m_sent_interrupt_signo);
   }
 } else {
+  // We've requested that the process stop anew; if we had recorded this
+  // requested stop as being in place when we resumed (& therefore would
+  // throw it away), clear that.
+  m_auto_resume_signo = 0;

jasonmolenda wrote:

Yeah, you added that lock when you were addressing TSAN issues, it's definitely 
required.

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


[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

2025-03-27 Thread via lldb-commits

https://github.com/dlav-sc updated 
https://github.com/llvm/llvm-project/pull/112555

>From a9d02c8b0c22138d9337bf33883f7e6c937bd655 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Mon, 14 Oct 2024 14:14:30 +
Subject: [PATCH 1/2] [lldb] add --platform-available-ports option to the
 dotest.py

This patch adds --platform-available-ports option to the dotest.py script
to remove hardcoded gdb ports from lldb testsuite.

Currently, this option could be helpful for GdbRemoteTestCases (e.g.
TestLldbGdbServer, TestNonStop, TestGdbRemoteThreadsInStopReply,
TestGdbRemotePlatformFile, TestGdbRemote_vCont)
---
 lldb/packages/Python/lldbsuite/test/configuration.py   | 1 +
 lldb/packages/Python/lldbsuite/test/dotest.py  | 2 ++
 lldb/packages/Python/lldbsuite/test/dotest_args.py | 7 +++
 lldb/packages/Python/lldbsuite/test/lldbtest.py| 4 
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +++
 5 files changed, 17 insertions(+)

diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py 
b/lldb/packages/Python/lldbsuite/test/configuration.py
index bcc179346836d..18c1566176331 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -103,6 +103,7 @@
 lldb_platform_name = None
 lldb_platform_url = None
 lldb_platform_working_dir = None
+lldb_platform_available_ports = None
 
 # Apple SDK
 apple_sdk = None
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index 681ea1638f2d6..7cc8f2985043e 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -419,6 +419,8 @@ def parseOptionsAndInitTestdirs():
 configuration.lldb_platform_url = args.lldb_platform_url
 if args.lldb_platform_working_dir:
 configuration.lldb_platform_working_dir = 
args.lldb_platform_working_dir
+if args.lldb_platform_available_ports:
+configuration.lldb_platform_available_ports = 
args.lldb_platform_available_ports
 if platform_system == "Darwin" and args.apple_sdk:
 configuration.apple_sdk = args.apple_sdk
 if args.test_build_dir:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index a80428ebec589..18047fdca2a92 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -292,6 +292,13 @@ def create_parser():
 metavar="platform-working-dir",
 help="The directory to use on the remote platform.",
 )
+group.add_argument(
+"--platform-available-ports",
+dest="lldb_platform_available_ports",
+type=lambda ports: [int(port.strip()) for port in ports.split(":")],
+metavar="platform-available-ports",
+help="Ports available for connection to a lldb server on the remote 
platform",
+)
 
 # Test-suite behaviour
 group = parser.add_argument_group("Runtime behaviour options")
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 570c36b5f9622..2e370564939d8 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -749,6 +749,10 @@ def getSourcePath(self, name):
 """Return absolute path to a file in the test's source directory."""
 return os.path.join(self.getSourceDir(), name)
 
+def getPlatformAvailablePorts(self):
+"""Return ports available for connection to a lldb server on the 
remote platform."""
+return configuration.lldb_platform_available_ports
+
 @classmethod
 def setUpCommands(cls):
 commands = [
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 3d3ecb9aa8f95..029aaf3164697 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -185,6 +185,9 @@ def setUpServerLogging(self, is_llgs):
 ]
 
 def get_next_port(self):
+available_ports = self.getPlatformAvailablePorts()
+if available_ports:
+return random.choice(available_ports)
 return 12000 + random.randint(0, 7999)
 
 def reset_test_sequence(self):

>From b38b96c0eb16e8fc48a3e9661ab5b6ca52d89efa Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Thu, 27 Mar 2025 14:36:56 +
Subject: [PATCH 2/2] NFC

---
 lldb/packages/Python/lldbsuite/test/dotest_args.py | 2 +-
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index 18047fdca2a92..f6

[Lldb-commits] [lldb] [lldb] Emit progress events in SymbolFileDWARFDebugMap (PR #133211)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

>From ed2905d3abc064476627863c9b9f1266fb6c5a55 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 26 Mar 2025 22:49:39 -0700
Subject: [PATCH 1/3] [lldb] Emit progress events in SymbolFileDWARFDebugMap

Emit progress events from SymbolFileDWARFDebugMap. Because we know the
number of OSOs, we can show determinate progress.

This is based on a patch from Adrian, and what prompted me to look into
improving how LLDB shows progress events. Before the statusline, all
these progress events would get shadowed.
---
 .../DWARF/SymbolFileDWARFDebugMap.cpp | 164 +++---
 .../DWARF/SymbolFileDWARFDebugMap.h   |  11 +-
 2 files changed, 99 insertions(+), 76 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 0ecf47a3c7869..f529a76f65c1f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Progress.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Utility/RangeMap.h"
@@ -31,6 +32,7 @@
 #include "lldb/Symbol/TypeMap.h"
 #include "lldb/Symbol/VariableList.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ScopedPrinter.h"
 
 #include "lldb/Target/StackFrame.h"
@@ -716,6 +718,27 @@ bool SymbolFileDWARFDebugMap::ParseDebugMacros(CompileUnit 
&comp_unit) {
   return false;
 }
 
+void SymbolFileDWARFDebugMap::ForEachSymbolFile(
+std::string description,
+std::function closure) {
+  const size_t num_oso_idxs = m_compile_unit_infos.size();
+  const size_t update_rate = std::max(1, num_oso_idxs / 100);
+  Progress progress(std::move(description), "", num_oso_idxs);
+  for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
+if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
+  if (oso_idx % update_rate == 0)
+progress.Increment(oso_idx, oso_dwarf->GetObjectFile()
+? oso_dwarf->GetObjectFile()
+  ->GetFileSpec()
+  .GetFilename()
+  .GetString()
+: std::string());
+  if (closure(oso_dwarf) == IterationAction::Stop)
+return;
+}
+  }
+}
+
 bool SymbolFileDWARFDebugMap::ForEachExternalModule(
 CompileUnit &comp_unit,
 llvm::DenseSet &visited_symbol_files,
@@ -804,7 +827,7 @@ SymbolFileDWARFDebugMap::GetDynamicArrayInfoForUID(
 bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) {
   bool success = false;
   if (compiler_type) {
-ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
+ForEachSymbolFile("Completing type", [&](SymbolFileDWARF *oso_dwarf) {
   if (oso_dwarf->HasForwardDeclForCompilerType(compiler_type)) {
 oso_dwarf->CompleteType(compiler_type);
 success = true;
@@ -924,29 +947,31 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
   std::lock_guard guard(GetModuleMutex());
   uint32_t total_matches = 0;
 
-  ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
-const uint32_t old_size = variables.GetSize();
-oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
-   variables);
-const uint32_t oso_matches = variables.GetSize() - old_size;
-if (oso_matches > 0) {
-  total_matches += oso_matches;
-
-  // Are we getting all matches?
-  if (max_matches == UINT32_MAX)
-return IterationAction::Continue; // Yep, continue getting everything
-
-  // If we have found enough matches, lets get out
-  if (max_matches >= total_matches)
-return IterationAction::Stop;
-
-  // Update the max matches for any subsequent calls to find globals in any
-  // other object files with DWARF
-  max_matches -= oso_matches;
-}
+  ForEachSymbolFile(
+  "Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
+const uint32_t old_size = variables.GetSize();
+oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
+   variables);
+const uint32_t oso_matches = variables.GetSize() - old_size;
+if (oso_matches > 0) {
+  total_matches += oso_matches;
+
+  // Are we getting all matches?
+  if (max_matches == UINT32_MAX)
+return IterationAction::Continue; // Yep, continue getting
+  // everything
+
+  // If we have found enough matches, lets get out
+  if (max_matches >= total_matches)
+   

[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

2025-03-27 Thread via lldb-commits

https://github.com/dlav-sc updated 
https://github.com/llvm/llvm-project/pull/112555

>From a9d02c8b0c22138d9337bf33883f7e6c937bd655 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Mon, 14 Oct 2024 14:14:30 +
Subject: [PATCH 1/2] [lldb] add --platform-available-ports option to the
 dotest.py

This patch adds --platform-available-ports option to the dotest.py script
to remove hardcoded gdb ports from lldb testsuite.

Currently, this option could be helpful for GdbRemoteTestCases (e.g.
TestLldbGdbServer, TestNonStop, TestGdbRemoteThreadsInStopReply,
TestGdbRemotePlatformFile, TestGdbRemote_vCont)
---
 lldb/packages/Python/lldbsuite/test/configuration.py   | 1 +
 lldb/packages/Python/lldbsuite/test/dotest.py  | 2 ++
 lldb/packages/Python/lldbsuite/test/dotest_args.py | 7 +++
 lldb/packages/Python/lldbsuite/test/lldbtest.py| 4 
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +++
 5 files changed, 17 insertions(+)

diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py 
b/lldb/packages/Python/lldbsuite/test/configuration.py
index bcc179346836d..18c1566176331 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -103,6 +103,7 @@
 lldb_platform_name = None
 lldb_platform_url = None
 lldb_platform_working_dir = None
+lldb_platform_available_ports = None
 
 # Apple SDK
 apple_sdk = None
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py 
b/lldb/packages/Python/lldbsuite/test/dotest.py
index 681ea1638f2d6..7cc8f2985043e 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -419,6 +419,8 @@ def parseOptionsAndInitTestdirs():
 configuration.lldb_platform_url = args.lldb_platform_url
 if args.lldb_platform_working_dir:
 configuration.lldb_platform_working_dir = 
args.lldb_platform_working_dir
+if args.lldb_platform_available_ports:
+configuration.lldb_platform_available_ports = 
args.lldb_platform_available_ports
 if platform_system == "Darwin" and args.apple_sdk:
 configuration.apple_sdk = args.apple_sdk
 if args.test_build_dir:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index a80428ebec589..18047fdca2a92 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -292,6 +292,13 @@ def create_parser():
 metavar="platform-working-dir",
 help="The directory to use on the remote platform.",
 )
+group.add_argument(
+"--platform-available-ports",
+dest="lldb_platform_available_ports",
+type=lambda ports: [int(port.strip()) for port in ports.split(":")],
+metavar="platform-available-ports",
+help="Ports available for connection to a lldb server on the remote 
platform",
+)
 
 # Test-suite behaviour
 group = parser.add_argument_group("Runtime behaviour options")
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 570c36b5f9622..2e370564939d8 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -749,6 +749,10 @@ def getSourcePath(self, name):
 """Return absolute path to a file in the test's source directory."""
 return os.path.join(self.getSourceDir(), name)
 
+def getPlatformAvailablePorts(self):
+"""Return ports available for connection to a lldb server on the 
remote platform."""
+return configuration.lldb_platform_available_ports
+
 @classmethod
 def setUpCommands(cls):
 commands = [
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 3d3ecb9aa8f95..029aaf3164697 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -185,6 +185,9 @@ def setUpServerLogging(self, is_llgs):
 ]
 
 def get_next_port(self):
+available_ports = self.getPlatformAvailablePorts()
+if available_ports:
+return random.choice(available_ports)
 return 12000 + random.randint(0, 7999)
 
 def reset_test_sequence(self):

>From bee43951764f20efac586c6b3cde55d8f36236da Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Thu, 27 Mar 2025 14:36:56 +
Subject: [PATCH 2/2] NFC

---
 lldb/packages/Python/lldbsuite/test/dotest_args.py   | 2 +-
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py   | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py 
b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index 18047fdca2a92..f6b3

[Lldb-commits] [lldb] [lldb] Return *const* UnwindPlan pointers from FuncUnwinders (PR #133247)

2025-03-27 Thread Jonas Devlieghere via lldb-commits

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

LGTM™ assuming the answer to my inline question is "no". 

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


[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,59 @@
+//===-- SBMutexTest.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Use the umbrella header for -Wdocumentation.
+#include "lldb/API/LLDB.h"
+
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBTarget.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+class SBMutexTest : public testing::Test {
+protected:
+  void SetUp() override { debugger = SBDebugger::Create(); }
+  void TearDown() override { SBDebugger::Destroy(debugger); }
+
+  SubsystemRAII subsystems;
+  SBDebugger debugger;
+};
+
+TEST_F(SBMutexTest, LockTest) {
+  lldb::SBTarget target = debugger.GetDummyTarget();
+
+  std::future f;
+  {
+std::atomic locked = false;
+lldb::SBMutex lock = target.GetAPIMutex();
+std::lock_guard lock_guard(lock);
+ASSERT_FALSE(locked.exchange(true));
+
+f = std::async(std::launch::async, [&]() {
+  {
+ASSERT_TRUE(locked);
+target.BreakpointCreateByName("foo", "bar");
+ASSERT_FALSE(locked);
+  }
+});
+ASSERT_TRUE(f.valid());
+
+// Wait 500ms to confirm the thread is blocked.
+auto status = f.wait_for(std::chrono::milliseconds(500));

JDevlieghere wrote:

The difference is the thread those things are happening on. The C++ unit test 
is doing the blocking call on another thread, while the Python test is doing 
all its work on a single thread (because Python doesn't really have "real 
multithreading" anyway with the GIL). Also the Python test's primarily purpose 
is to test the Python bindings. If SBMutex did nothing, it would still pass, 
because we can't check from Python that the lock is being held. The test was a 
little more useful for SBLock, which can query if it's actually locked. 

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


[Lldb-commits] [lldb] [lldb] Emit progress events in SymbolFileDWARFDebugMap (PR #133211)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -716,6 +718,27 @@ bool SymbolFileDWARFDebugMap::ParseDebugMacros(CompileUnit 
&comp_unit) {
   return false;
 }
 
+void SymbolFileDWARFDebugMap::ForEachSymbolFile(
+std::string description,
+std::function closure) {
+  const size_t num_oso_idxs = m_compile_unit_infos.size();
+  Progress progress(std::move(description), "", num_oso_idxs,
+/*debugger=*/nullptr,
+/*minimum_report_time=*/std::chrono::milliseconds(20));

JDevlieghere wrote:

I used 20ms because that's what Pavel used in the [manual DWARF 
index](https://github.com/llvm/llvm-project/blob/4485e25dd2a57be1ee504b4dd863a1e140f5084c/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp#L84).
 That's 50 times per second, which is still fast but not as bad as 500. That 
said, having a setting that both these things query doesn't sound like a bad 
idea. It could even be the default for all progress events. WDYT? 

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


[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,60 @@
+//===-- SBMutex.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/API/SBMutex.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/Instrumentation.h"
+#include "lldb/lldb-forward.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+SBMutex::SBMutex() : m_opaque_sp(std::make_shared()) {
+  LLDB_INSTRUMENT_VA(this);
+}
+
+SBMutex::SBMutex(const SBMutex &rhs) : m_opaque_sp(rhs.m_opaque_sp) {

JDevlieghere wrote:

Because SWIG 4.0 doesn't deal well with move-only types. That's how I initially 
implemented SBLock in https://github.com/llvm/llvm-project/pull/131404, which 
lead to another RFC to bump the SWIG version: 
https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377.
 There Pavel suggested exposing the mutex instead of the lock and making it 
copyable. 

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


[Lldb-commits] [lldb] Reapply LLDB-Telemetry TargetInfo branch (pr/127834) (PR #132043)

2025-03-27 Thread Vy Nguyen via lldb-commits

oontvoo wrote:

All checks ✅ passed so I'm going to merge this

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


[Lldb-commits] [lldb] Plugin toggle roadmap (PR #132876)

2025-03-27 Thread David Peixotto via lldb-commits

https://github.com/dmpots updated 
https://github.com/llvm/llvm-project/pull/132876

>From 21ac6ae78d53feba8322e3aca724ecb01ff7c847 Mon Sep 17 00:00:00 2001
From: David Peixotto 
Date: Thu, 13 Mar 2025 16:13:45 -0700
Subject: [PATCH 1/3] Remove raw access to PluginInstances vector

This commit modifies the PluginInstances class to remove direct access
to the m_instances vector. Instead, we expose a new `GetSnapshot` method
that returns a copy of the current state of the instances vector.  All
external iteration over the instances is updated to use the new method.

The motivation for the change is to allow modifying the way we store
instances without having to change all the clients. This is a
preliminary change to allow enabling/disabling of plugins in which case
we want to iterate over only enabled plugins.

We also considered using a custom iterator that wraps the vector
iterator and can skip over disabled instances. That works, but the
iterator code is a bit messy with all template and typedefs to make a
compliant iterator.
---
 lldb/source/Core/PluginManager.cpp | 168 ++---
 1 file changed, 84 insertions(+), 84 deletions(-)

diff --git a/lldb/source/Core/PluginManager.cpp 
b/lldb/source/Core/PluginManager.cpp
index 80c9465f9af72..95eb940efcef2 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -226,30 +226,26 @@ template  class PluginInstances {
   }
 
   typename Instance::CallbackType GetCallbackAtIndex(uint32_t idx) {
-if (Instance *instance = GetInstanceAtIndex(idx))
+if (const Instance *instance = GetInstanceAtIndex(idx))
   return instance->create_callback;
 return nullptr;
   }
 
   llvm::StringRef GetDescriptionAtIndex(uint32_t idx) {
-if (Instance *instance = GetInstanceAtIndex(idx))
+if (const Instance *instance = GetInstanceAtIndex(idx))
   return instance->description;
 return "";
   }
 
   llvm::StringRef GetNameAtIndex(uint32_t idx) {
-if (Instance *instance = GetInstanceAtIndex(idx))
+if (const Instance *instance = GetInstanceAtIndex(idx))
   return instance->name;
 return "";
   }
 
   typename Instance::CallbackType GetCallbackForName(llvm::StringRef name) {
-if (name.empty())
-  return nullptr;
-for (auto &instance : m_instances) {
-  if (name == instance.name)
-return instance.create_callback;
-}
+if (const Instance *instance = GetInstanceForName(name))
+  return instance->create_callback;
 return nullptr;
   }
 
@@ -260,12 +256,33 @@ template  class PluginInstances {
 }
   }
 
-  const std::vector &GetInstances() const { return m_instances; }
-  std::vector &GetInstances() { return m_instances; }
+  // Return a copy of all the enabled instances.
+  // Note that this is a copy of the internal state so modifications
+  // to the returned instances will not be reflected back to instances
+  // stored by the PluginInstances object.
+  std::vector GetSnapshot() { return m_instances; }
+
+  const Instance *GetInstanceAtIndex(uint32_t idx) {
+uint32_t count = 0;
+
+return FindEnabledInstance(
+[&](const Instance &instance) { return count++ == idx; });
+  }
+
+  const Instance *GetInstanceForName(llvm::StringRef name) {
+if (name.empty())
+  return nullptr;
 
-  Instance *GetInstanceAtIndex(uint32_t idx) {
-if (idx < m_instances.size())
-  return &m_instances[idx];
+return FindEnabledInstance(
+[&](const Instance &instance) { return instance.name == name; });
+  }
+
+  const Instance *
+  FindEnabledInstance(std::function predicate) const {
+for (const auto &instance : m_instances) {
+  if (predicate(instance))
+return &instance;
+}
 return nullptr;
   }
 
@@ -571,17 +588,15 @@ 
PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(uint32_t idx) {
 
 LanguageRuntimeGetCommandObject
 PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(uint32_t idx) {
-  const auto &instances = GetLanguageRuntimeInstances().GetInstances();
-  if (idx < instances.size())
-return instances[idx].command_callback;
+  if (auto instance = GetLanguageRuntimeInstances().GetInstanceAtIndex(idx))
+return instance->command_callback;
   return nullptr;
 }
 
 LanguageRuntimeGetExceptionPrecondition
 PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(uint32_t idx) 
{
-  const auto &instances = GetLanguageRuntimeInstances().GetInstances();
-  if (idx < instances.size())
-return instances[idx].precondition_callback;
+  if (auto instance = GetLanguageRuntimeInstances().GetInstanceAtIndex(idx))
+return instance->precondition_callback;
   return nullptr;
 }
 
@@ -643,12 +658,7 @@ bool 
PluginManager::IsRegisteredObjectFilePluginName(llvm::StringRef name) {
   if (name.empty())
 return false;
 
-  const auto &instances = GetObjectFileInstances().GetInstances();
-  for (auto &instance : instances) {
-if (instance.name == name)
-  return true;
-  }
-  return fal

[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Alex Langford via lldb-commits


@@ -0,0 +1,48 @@
+//===-- SBMutex.h
+//--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_API_SBLOCK_H
+#define LLDB_API_SBLOCK_H

bulbazord wrote:

SBBLOCK?

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


[Lldb-commits] [lldb] [lldb] Expose the Target API mutex through the SB API (PR #133295)

2025-03-27 Thread Alex Langford via lldb-commits


@@ -0,0 +1,48 @@
+//===-- SBMutex.h

bulbazord wrote:

Header messed up

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


  1   2   >