[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)

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


@@ -316,6 +316,36 @@ struct Source {
 bool fromJSON(const llvm::json::Value &, Source &, llvm::json::Path);
 llvm::json::Value toJSON(const Source &);
 
+// MARK: Events
+
+// "ExitedEvent": {
+//   "allOf": [ { "$ref": "#/definitions/Event" }, {
+// "type": "object",
+// "description": "The event indicates that the debuggee has exited and
+// returns its exit code.", "properties": {
+//   "event": {
+// "type": "string",
+// "enum": [ "exited" ]
+//   },
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "exitCode": {
+// "type": "integer",
+// "description": "The exit code returned from the debuggee."
+//   }
+// },
+// "required": [ "exitCode" ]
+//   }
+// },
+// "required": [ "event", "body" ]
+//   }]
+// }
+struct ExitedEventBody {
+  int exitCode;

JDevlieghere wrote:

@vogelsgesang Apologies, I think I might have misunderstood your original 
concern. I thought the thing that worried you was that for the RequestHandlers, 
once you did the lookup in the map, you don't know the dynamic type of the 
object and so your IDE takes you to function (`operator()`) in the base class. 
I was arguing that if you know the dynamic type, like what this patch currently 
does, that's not actually a concern, because your IDE will do the right thing. 
But upon re-reading your message, I think you're still concerned about that. 
Especially if events share common logic, implementing them as classes provides 
a nice level of abstraction. 

As you pointed out, the RequestHandlers are trickier, but I think it can be 
done, although it would make the code more verbose and probably less performant 
than the current hash lookup + indirect call. Anyway, what I had in mind for 
that was a string lookup to enum and a switch. Something like this:

```
CommandType type = GetType(command_string);
switch (type) {
  case FooRequest:
return dap.request_handlers.foo_request_handler(); 
  case BarRequest:
[...]
}
```

Instead of registering all the request handlers (and putting them in a map), 
you'd have a `struct` with an instance for each handler. As I'm writing this, 
I'm realizing I prefer the current approach and I think the indirection is 
worth it. 
```

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


[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)

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

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


[Lldb-commits] [lldb] [lldb-dap] Ensure logging statements are written as a single chunk. (PR #131916)

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

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

I noticed this while debugging some unit tests that the logs occasionally would 
intersperse two log statements.

Previously, it was possible for a log statement to have two messages 
interspersed since the timestamp and log statement were two different writes to 
the log stream.

Instead, combine the logging into a single buffer first before printing.

>From 6aa311afe9832bbd4a4118874e411243b05e490d Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Tue, 18 Mar 2025 14:03:12 -0700
Subject: [PATCH] [lldb-dap] Ensure logging statements are written as a single
 atomic chunk.

Previously, it was possible for a log statement to have two messages 
interspersed since the timestamp and log statement were two different writes to 
the log stream.

Instead, combine the logging into a single buffer first before printing.
---
 lldb/tools/lldb-dap/DAPLog.h | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAPLog.h b/lldb/tools/lldb-dap/DAPLog.h
index 75a0a7d63a4f1..2574506739fea 100644
--- a/lldb/tools/lldb-dap/DAPLog.h
+++ b/lldb/tools/lldb-dap/DAPLog.h
@@ -23,8 +23,12 @@
 if (log_private) { 
\
   ::std::chrono::duration now{ 
\
   ::std::chrono::system_clock::now().time_since_epoch()};  
\
-  *log_private << ::llvm::formatv("{0:f9} ", now.count()).str()
\
-   << ::llvm::formatv(__VA_ARGS__).str() << std::endl; 
\
+  ::std::string out;   
\
+  ::llvm::raw_string_ostream os(out);  
\
+  os << ::llvm::formatv("{0:f9} ", now.count()).str()  
\
+ << ::llvm::formatv(__VA_ARGS__).str() << "\n";
\
+  *log_private << out; 
\
+  log_private->flush();
\
 }  
\
   } while (0)
 
@@ -37,10 +41,13 @@
 if (log_private && error_private) {
\
   ::std::chrono::duration now{ 
\
   std::chrono::system_clock::now().time_since_epoch()};
\
-  *log_private << ::llvm::formatv("{0:f9} ", now.count()).str()
\
-   << ::lldb_dap::FormatError(::std::move(error_private),  
\
-  __VA_ARGS__) 
\
-   << std::endl;   
\
+  ::std::string out;   
\
+  ::llvm::raw_string_ostream os(out);  
\
+  os << ::llvm::formatv("{0:f9} ", now.count()).str()  
\
+ << ::lldb_dap::FormatError(::std::move(error_private), __VA_ARGS__)   
\
+ << "\n";  
\
+  *log_private << out; 
\
+  log_private->flush();
\
 } else 
\
   ::llvm::consumeError(::std::move(error_private));
\
   } while (0)

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


[Lldb-commits] [clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)

2025-03-18 Thread Izzy Muerte via lldb-commits

bruxisma wrote:

> I think it change the meaning completely. I read "Coverage Sanitizer" as a 
> tool which finds bugs in Coverage. When "Sanitizer Coverage" as a coverage 
> used by sanitizers.
> 
> This component is not sanitizer at all, and the current name is more 
> appropriate.

The documentation for this component literally reads

> LLVM has a simple code coverage instrumentation built in (SanitizerCoverage). 
> It inserts calls to user-defined functions on function-, basic-block-, and 
> edge- levels. 

Neither definition you've given fits what this feature does! It calls user 
defined instrumentation functions, it doesn't find bugs in coverage and it 
doesn't provide coverage used by sanitizers!

This is just like how instrumentation based command line arguments start with 
`-fprofile-` even if they *can't be used for profiling*, and how tools like 
*control flow integrity* use `-fsanitize`. This entire thing is a mess, and 
it's made even worse with the addition of 
[SanitizerStats](https://clang.llvm.org/docs/SanitizerStats.html) which relies 
on CFI and doesn't collect sanitizer statistics, even though CFI is only a 
sanitizer because it uses `-fsanitize` as a flag!

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


[Lldb-commits] [lldb] [lldb-dap] Waiting for the test binary to exit prior to dumping logs. (PR #131917)

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

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

This should ensure we have the full logs prior to dumping the logs. 
Additionally, printing log dumps to stderr so they are adjacent to assertion 
failures.



>From ca59812b9b23c96354982b6c696fb2b129bf117d Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Tue, 18 Mar 2025 14:01:44 -0700
Subject: [PATCH] [lldb-dap] Waiting for the test binary to exit prior to
 dumping logs.

This should ensure we have the full logs prior to dumping the logs. 
Additionally, printing log dumps to stderr so they are interspersed with 
assertion failures.
---
 .../lldbsuite/test/tools/lldb-dap/dap_server.py  | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 0fea3419d9725..a9a47e281e829 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -88,13 +88,13 @@ def packet_type_is(packet, packet_type):
 
 
 def dump_dap_log(log_file):
-print("= DEBUG ADAPTER PROTOCOL LOGS =")
+print("= DEBUG ADAPTER PROTOCOL LOGS =", file=sys.stderr)
 if log_file is None:
-print("no log file available")
+print("no log file available", file=sys.stderr)
 else:
 with open(log_file, "r") as file:
-print(file.read())
-print("= END =")
+print(file.read(), file=sys.stderr)
+print("= END =", file=sys.stderr)
 
 
 def read_packet_thread(vs_comm, log_file):
@@ -107,6 +107,10 @@ def read_packet_thread(vs_comm, log_file):
 # termination of lldb-dap and stop waiting for new packets.
 done = not vs_comm.handle_recv_packet(packet)
 finally:
+# Wait for the process to fully exit before dumping the log file to
+# ensure we have the entire log contents.
+if vs_comm.process is not None:
+vs_comm.process.wait()
 dump_dap_log(log_file)
 
 

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


[Lldb-commits] [lldb] [lldb-dap] Waiting for the test binary to exit prior to dumping logs. (PR #131917)

2025-03-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)


Changes

This should ensure we have the full logs prior to dumping the logs. 
Additionally, printing log dumps to stderr so they are adjacent to assertion 
failures.



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


1 Files Affected:

- (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
(+8-4) 


``diff
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 0fea3419d9725..a9a47e281e829 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -88,13 +88,13 @@ def packet_type_is(packet, packet_type):
 
 
 def dump_dap_log(log_file):
-print("= DEBUG ADAPTER PROTOCOL LOGS =")
+print("= DEBUG ADAPTER PROTOCOL LOGS =", file=sys.stderr)
 if log_file is None:
-print("no log file available")
+print("no log file available", file=sys.stderr)
 else:
 with open(log_file, "r") as file:
-print(file.read())
-print("= END =")
+print(file.read(), file=sys.stderr)
+print("= END =", file=sys.stderr)
 
 
 def read_packet_thread(vs_comm, log_file):
@@ -107,6 +107,10 @@ def read_packet_thread(vs_comm, log_file):
 # termination of lldb-dap and stop waiting for new packets.
 done = not vs_comm.handle_recv_packet(packet)
 finally:
+# Wait for the process to fully exit before dumping the log file to
+# ensure we have the entire log contents.
+if vs_comm.process is not None:
+vs_comm.process.wait()
 dump_dap_log(log_file)
 
 

``




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


[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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

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

>From 8b71292a70deeab65799c0d88072e17366a594ce Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Tue, 18 Mar 2025 14:05:38 -0700
Subject: [PATCH] [lldb-dap] Adding support for cancelling a request.

Adding support for cancelling requests.

There are two forms of request cancellation.

* Preemptively cancelling a request that is in the queue.
* Actively cancelling the in progress request as a best effort attempt using 
`SBDebugger.RequestInterrupt()`.
---
 lldb/test/API/tools/lldb-dap/cancel/Makefile  |   3 +
 .../tools/lldb-dap/cancel/TestDAP_cancel.py   | 101 
 lldb/test/API/tools/lldb-dap/cancel/main.c|   6 +
 .../tools/lldb-dap/launch/TestDAP_launch.py   |   1 +
 lldb/tools/lldb-dap/CMakeLists.txt|   1 +
 lldb/tools/lldb-dap/DAP.cpp   | 145 --
 lldb/tools/lldb-dap/DAP.h |   3 +
 .../lldb-dap/Handler/CancelRequestHandler.cpp |  55 +++
 .../Handler/InitializeRequestHandler.cpp  |   2 +
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  10 ++
 .../lldb-dap/Protocol/ProtocolRequests.cpp|   7 +
 .../lldb-dap/Protocol/ProtocolRequests.h  |  20 +++
 lldb/tools/lldb-dap/Transport.cpp |  37 +++--
 lldb/tools/lldb-dap/Transport.h   |   3 +-
 lldb/tools/lldb-dap/lldb-dap.cpp  |   5 +-
 15 files changed, 379 insertions(+), 20 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/cancel/Makefile
 create mode 100644 lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
 create mode 100644 lldb/test/API/tools/lldb-dap/cancel/main.c
 create mode 100644 lldb/tools/lldb-dap/Handler/CancelRequestHandler.cpp

diff --git a/lldb/test/API/tools/lldb-dap/cancel/Makefile 
b/lldb/test/API/tools/lldb-dap/cancel/Makefile
new file mode 100644
index 0..10495940055b6
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/cancel/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py 
b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
new file mode 100644
index 0..f3b2f9fcb7a92
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
@@ -0,0 +1,101 @@
+"""
+Test lldb-dap cancel request
+"""
+
+import time
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbdap_testcase
+
+
+class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase):
+def send_async_req(self, command: str, arguments={}) -> int:
+seq = self.dap_server.sequence
+self.dap_server.send_packet(
+{
+"type": "request",
+"command": command,
+"arguments": arguments,
+}
+)
+return seq
+
+def async_blocking_request(self, duration: float) -> int:
+"""
+Sends an evaluate request that will sleep for the specified duration to
+block the request handling thread.
+"""
+return self.send_async_req(
+command="evaluate",
+arguments={
+"expression": '`script import time; print("starting sleep", 
file=lldb.debugger.GetOutputFileHandle()); time.sleep({})'.format(
+duration
+),
+"context": "repl",
+},
+)
+
+def async_cancel(self, requestId: int) -> int:
+return self.send_async_req(command="cancel", arguments={"requestId": 
requestId})
+
+def test_pending_request(self):
+"""
+Tests cancelling a pending request.
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, stopOnEntry=True)
+self.continue_to_next_stop()
+
+# Use a relatively short timeout since this is only to ensure the
+# following request is queued.
+blocking_seq = self.async_blocking_request(duration=1.0)
+# Use a longer timeout to ensure we catch if the request was 
interrupted
+# properly.
+pending_seq = self.async_blocking_request(duration=self.timeoutval)
+cancel_seq = self.async_cancel(requestId=pending_seq)
+
+blocking_resp = self.dap_server.recv_packet(filter_type=["response"])
+self.assertEqual(blocking_resp["request_seq"], blocking_seq)
+self.assertEqual(blocking_resp["command"], "evaluate")
+self.assertEqual(blocking_resp["success"], True)
+
+pending_resp = self.dap_server.recv_packet(filter_type=["response"])
+self.assertEqual(pending_resp["request_seq"], pending_seq)
+self.assertEqual(pending_resp["command"], "evaluate")
+self.assertEqual(pending_resp["success"], False)
+self.assertEqual(pending_resp["message"], "cancelled")
+
+cancel_resp = self.dap_server.recv_packet(filter_type=["response"])
+self.assertEqual(cancel_resp["request_seq"], cancel_seq)
+ 

[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

2025-03-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)


Changes

Adding support for cancelling requests.

There are two forms of request cancellation.

* Preemptively cancelling a request that is in the queue.
* Actively cancelling the in progress request as a best effort attempt using 
`SBDebugger.RequestInterrupt()`.


---

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


15 Files Affected:

- (added) lldb/test/API/tools/lldb-dap/cancel/Makefile (+3) 
- (added) lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py (+101) 
- (added) lldb/test/API/tools/lldb-dap/cancel/main.c (+6) 
- (modified) lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py (+1) 
- (modified) lldb/tools/lldb-dap/CMakeLists.txt (+1) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (+136-9) 
- (modified) lldb/tools/lldb-dap/DAP.h (+3) 
- (added) lldb/tools/lldb-dap/Handler/CancelRequestHandler.cpp (+55) 
- (modified) lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp (+2) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+10) 
- (modified) lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp (+7) 
- (modified) lldb/tools/lldb-dap/Protocol/ProtocolRequests.h (+20) 
- (modified) lldb/tools/lldb-dap/Transport.cpp (+28-9) 
- (modified) lldb/tools/lldb-dap/Transport.h (+2-1) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+4-1) 


``diff
diff --git a/lldb/test/API/tools/lldb-dap/cancel/Makefile 
b/lldb/test/API/tools/lldb-dap/cancel/Makefile
new file mode 100644
index 0..10495940055b6
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/cancel/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py 
b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
new file mode 100644
index 0..f3b2f9fcb7a92
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
@@ -0,0 +1,101 @@
+"""
+Test lldb-dap cancel request
+"""
+
+import time
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbdap_testcase
+
+
+class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase):
+def send_async_req(self, command: str, arguments={}) -> int:
+seq = self.dap_server.sequence
+self.dap_server.send_packet(
+{
+"type": "request",
+"command": command,
+"arguments": arguments,
+}
+)
+return seq
+
+def async_blocking_request(self, duration: float) -> int:
+"""
+Sends an evaluate request that will sleep for the specified duration to
+block the request handling thread.
+"""
+return self.send_async_req(
+command="evaluate",
+arguments={
+"expression": '`script import time; print("starting sleep", 
file=lldb.debugger.GetOutputFileHandle()); time.sleep({})'.format(
+duration
+),
+"context": "repl",
+},
+)
+
+def async_cancel(self, requestId: int) -> int:
+return self.send_async_req(command="cancel", arguments={"requestId": 
requestId})
+
+def test_pending_request(self):
+"""
+Tests cancelling a pending request.
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program, stopOnEntry=True)
+self.continue_to_next_stop()
+
+# Use a relatively short timeout since this is only to ensure the
+# following request is queued.
+blocking_seq = self.async_blocking_request(duration=1.0)
+# Use a longer timeout to ensure we catch if the request was 
interrupted
+# properly.
+pending_seq = self.async_blocking_request(duration=self.timeoutval)
+cancel_seq = self.async_cancel(requestId=pending_seq)
+
+blocking_resp = self.dap_server.recv_packet(filter_type=["response"])
+self.assertEqual(blocking_resp["request_seq"], blocking_seq)
+self.assertEqual(blocking_resp["command"], "evaluate")
+self.assertEqual(blocking_resp["success"], True)
+
+pending_resp = self.dap_server.recv_packet(filter_type=["response"])
+self.assertEqual(pending_resp["request_seq"], pending_seq)
+self.assertEqual(pending_resp["command"], "evaluate")
+self.assertEqual(pending_resp["success"], False)
+self.assertEqual(pending_resp["message"], "cancelled")
+
+cancel_resp = self.dap_server.recv_packet(filter_type=["response"])
+self.assertEqual(cancel_resp["request_seq"], cancel_seq)
+self.assertEqual(cancel_resp["command"], "cancel")
+self.assertEqual(cancel_resp["success"], True)
+self.continue_to_exit()
+
+def test_inflight_request(self):
+"""
+Tests cancelling an inflight request.
+"""
+program = self.getBuildArtifact("a.out")

[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

2025-03-18 Thread Robert O'Callahan via lldb-commits

rocallahan wrote:

Maybe disabling tests for macOS < 15 would be OK even in the long term? There 
isn't any looming plan to actually use this code on macOS < 15. The main reason 
to run these tests on non-Linux is so to help developers catch it early if they 
break these tests. I guess most developers on Mac will be doing most of their 
testing on 15 or later?

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


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

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


@@ -77,6 +77,7 @@ add_lldb_tool(lldb-dap
   Protocol/ProtocolBase.cpp
   Protocol/ProtocolTypes.cpp
   Protocol/ProtocolRequests.cpp
+  Handler/WriteMemoryRequestHandler.cpp

JDevlieghere wrote:

This should go between the other `Handler/` files (which are sorted 
alphabetically) 

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] Support ordered patterns in lldbtest.expect (PR #131475)

2025-03-18 Thread Leandro Lupori via lldb-commits

luporl wrote:

This change broke https://lab.llvm.org/buildbot/#/builders/141/builds/7116.

`functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py` 
passes when I revert this change.
Can you please take a look?


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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

labath wrote:

> Let me know what other info might be useful

It would be useful to know if you can reproduce this problem locally (because I 
can't -- the test passes on my mac). If you can't then it would be useful to 
get as much information about this buildbot as possible (what kind of 
debugserver it uses, OS versions and such), as it means there's something 
different about it.


> On Linux ARM64 both gdb and lldb seem to adjust the hardware behavior so that 
> single-stepping an instruction that fires a watchpoint leaves the PC pointing 
> to the next instruction.
> 
> Maybe this is not true on Mac? I can't test that myself.

It works the same way on a mac. And the behavior is implemented on the client 
(it disables the watchpoint, single-steps, and then re-enables the watchpoint). 
I'm not entirely sure what happens (or what should happen) when running 
backwards to the watchpoint. 

One more (possibly irrelevant) note: On lldb, this behavior is actually 
controlled by the `watchpoint_exceptions_received:before/after` response to the 
`qHostInfo` packet, which allows to to work with an "x86" machine which has the 
"arm" exception behavior (and vice versa). While somewhat weird, this is very 
handy when working with emulators, as it avoids the need to simulate the arm 
exception behavior on x86 (which is quite hard).

> So I wonder whether, in normal operation on the test system, singlestepping 
> an instruction which triggers a watchpoint actually reports the watchpoint 
> being hit.

This definitely works (on my machine). Here's the relevant part of the log:
```
  <  18> send packet: $vCont;s:2d3138#57
  <1093> read packet: 
$T00thread:2d3138;threads:2d3138;thread-pcs:13f88;00:0100;01:20f8df6f0100;02:30f8df6f0100;03:18f9df6f0100;04:0100;05:;06:;07:200d;08:0600;09:50c149f70100;0a:10f5de6f0100;0b:60f5df6f0100;0c:b011;0d:00400100;0e:0040;0f:55af9a9b0100;10:a4bfdf8d0100;11:e0afd7ff0100;12:;13:50c049f70100;14:a0c049f70100;15:50c049f70100;16:b8f6df6f0100;17:b8f6df6f0100;18:0020a48d0100;19:;1a:;1b:;1c:;1d:00f8df6f0100;1e:7482a48d0100;1f:c0f5df6f0100;20:883f0100;21:00102060;a1:c8f5df6f0100;a2:62d2;a3:;reason:watchpoint;description:3631373139313537323020302036313731393135373230;watch_addr:16fdff5c8;me_watch_addr:16fdff5c8;wp_hw_idx:0;wp_esr_iss:62;wp_esr_wpt:0;wp_esr_wptv:0;wp_esr_wpf:0;wp_esr_fnp:0;wp_esr_vncr:0;wp_esr_fnv:0;wp_esr_cm:1;wp_esr_wnr:1;wp_esr_dfsc:22;memory:0x16fdff800=;#00
 <  18> send packet: 
$z2,16fdff5c8,4#05
 <   6> read packet: $OK#00
  <  18> send packet: $vCont;s:2d3138#57
  < 862> read packet: 
$T05thread:2d3138;threads:2d3138;thread-pcs:13f8c;00:0100;01:20f8df6f0100;02:30f8df6f0100;03:18f9df6f0100;04:0100;05:;06:;07:200d;08:0600;09:50c149f70100;0a:10f5de6f0100;0b:60f5df6f0100;0c:b011;0d:00400100;0e:0040;0f:55af9a9b0100;10:a4bfdf8d0100;11:e0afd7ff0100;12:;13:50c049f70100;14:a0c049f70100;15:50c049f70100;16:b8f6df6f0100;17:b8f6df6f0100;18:0020a48d0100;19:;1a:;1b:;1c:;1d:00f8df6f0100;1e:7482a48d0100;1f:c0f5df6f0100;20:8c3f0100;21:00100060;a1:;a2:22cb;a3:;metype:6;mecount:2;medata:1;medata:0;memory:0x16fdff800=;#00
 <  18> send packet: 
$Z2,16fdff5c8,4#e5
 <   6> read packet: $OK#00
lldb.debugger.event-handler  <  16> send packet: $jThreadsInfo#c1
lldb.debugger.event-handler  <> read packet: 
$[{"tid":2961720,"metype":6,"medata":[1,0],"reason":"exception","qaddr":8446511552,"associated_with_dispatch_queue":true,"dispatch_queue_t":8446526400,"qname":"com.apple.main-thread","qkind":"serial","qserialnum":1,"registers":{"0":"0100","1":"20f8df6f0100","2":"30f8df6f0100","3":"18f9df6f0100","4":"0100","5":"","6":"","7":"200d","8":"0600","9":"50c149f70100","10":"10f5de6f0100","11":"60f5df6f0100","12":"b011","13":"00400100","14":"0040","15":"55af9a9b0100","16":"a4bfdf8d0100","17":"e0afd7ff0100","18":"","19":"50c049f70100","20":"a0c049f70100","21":"50c049f70100","22":"b8f6df6f0100","23":"b8f6df6f0100","24":"0020a48d0100","25":"","26":"","27":"","28":"","29":"00f8df6f0100","30":"7482a48d0100","31":"c0f5df6f0100","32":"8c3f0100","33":"00100

[Lldb-commits] [lldb] [lldb][AIX] Support for XCOFF Sections (PR #131304)

2025-03-18 Thread Dhruv Srivastava via lldb-commits

DhruvSrivastavaX wrote:

Hi @labath @DavidSpickett, 
So please let me know if I should add more apis in this PR or this much 
granularity is enough. 
Also, we are working on 32-bit implementation as well, so I am thinking of 
extending the xcoff for the 32 bit as well as it should not take much 
additional effort.
What are your thoughts?

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


[Lldb-commits] [lldb] [lldb][AIX] Support for XCOFF Sections (PR #131304)

2025-03-18 Thread Dhruv Srivastava via lldb-commits

DhruvSrivastavaX wrote:

These are the previous reference commits for the xcoff support:
[ca4cd08](https://github.com/llvm/llvm-project/commit/ca4cd08fb9d7a03fbd00bca05d5dbfa87cd6db4e),
 
[0c68606](https://github.com/llvm/llvm-project/commit/0c6860622c249ae7adc784c66a8d0b1335a9e7df)

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


[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)

2025-03-18 Thread Aleksandr Korepanov via lldb-commits


@@ -5,11 +5,11 @@
 # RUN: rm -rf %t.existing
 # RUN: mkdir -p %t.existing
 # RUN: %lldb -o 'diagnostics dump -d %t.existing'
-# RUN: file %t.existing | FileCheck %s
+# RUN: test -d %t.existing && echo "directory" | FileCheck %s

AlexK0 wrote:

Fixed

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/131836

>From 03a4172a3a4dae7d1ed45570fff66a89e792ca71 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 11 Mar 2025 08:57:13 +
Subject: [PATCH 1/4] [llvm][ItaniumDemangle] Add function name location
 tracking

---
 libcxxabi/src/demangle/ItaniumDemangle.h  |  20 +++
 libcxxabi/src/demangle/Utility.h  | 163 --
 llvm/include/llvm/Demangle/ItaniumDemangle.h  |  20 +++
 llvm/include/llvm/Demangle/Utility.h  | 163 --
 .../Demangle/ItaniumDemangleTest.cpp  | 105 +++
 5 files changed, 439 insertions(+), 32 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h 
b/libcxxabi/src/demangle/ItaniumDemangle.h
index 3df41b5f4d7d0..d3cd1e4a405a6 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -851,11 +851,13 @@ class FunctionType final : public Node {
   // by printing out the return types's left, then print our parameters, then
   // finally print right of the return type.
   void printLeft(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
 Ret->printLeft(OB);
 OB += " ";
   }
 
   void printRight(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
 OB.printOpen();
 Params.printWithComma(OB);
 OB.printClose();
@@ -976,13 +978,26 @@ class FunctionEncoding final : public Node {
   if (!Ret->hasRHSComponent(OB))
 OB += " ";
 }
+
+// Nested FunctionEncoding parsing can happen with following productions:
+// * 
+// * 
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
+OB.FunctionInfo.updateScopeStart(OB);
+
 Name->print(OB);
   }
 
   void printRight(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
+OB.FunctionInfo.finalizeStart(OB);
+
 OB.printOpen();
 Params.printWithComma(OB);
 OB.printClose();
+
+OB.FunctionInfo.finalizeArgumentEnd(OB);
+
 if (Ret)
   Ret->printRight(OB);
 
@@ -1005,6 +1020,8 @@ class FunctionEncoding final : public Node {
   OB += " requires ";
   Requires->print(OB);
 }
+
+OB.FunctionInfo.finalizeEnd(OB);
   }
 };
 
@@ -1072,7 +1089,9 @@ struct NestedName : Node {
   void printLeft(OutputBuffer &OB) const override {
 Qual->print(OB);
 OB += "::";
+OB.FunctionInfo.updateScopeEnd(OB);
 Name->print(OB);
+OB.FunctionInfo.updateBasenameEnd(OB);
   }
 };
 
@@ -1633,6 +1652,7 @@ struct NameWithTemplateArgs : Node {
 
   void printLeft(OutputBuffer &OB) const override {
 Name->print(OB);
+OB.FunctionInfo.updateBasenameEnd(OB);
 TemplateArgs->print(OB);
   }
 };
diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index f1fad35d60d98..3bfdf8dff4526 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -27,6 +27,22 @@
 
 DEMANGLE_NAMESPACE_BEGIN
 
+template  class ScopedOverride {
+  T &Loc;
+  T Original;
+
+public:
+  ScopedOverride(T &Loc_) : ScopedOverride(Loc_, Loc_) {}
+
+  ScopedOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) {
+Loc_ = std::move(NewVal);
+  }
+  ~ScopedOverride() { Loc = std::move(Original); }
+
+  ScopedOverride(const ScopedOverride &) = delete;
+  ScopedOverride &operator=(const ScopedOverride &) = delete;
+};
+
 // Stream that AST nodes write their string representation into after the AST
 // has been parsed.
 class OutputBuffer {
@@ -83,6 +99,127 @@ class OutputBuffer {
 return std::string_view(Buffer, CurrentPosition);
   }
 
+  // Stores information about parts of a demangled function name.
+  struct FunctionNameInfo {
+///< A [start, end) pair for the function basename.
+///< The basename is the name without scope qualifiers
+///< and without template parameters. E.g.,
+///< \code{.cpp}
+/// 0; }
+
+bool shouldTrack(OutputBuffer &OB) const {
+  if (OB.isPrintingNestedFunctionType())
+return false;
+
+  if (OB.isGtInsideTempla

[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

adrian-prantl wrote:

> It would be useful to know if you can reproduce this problem locally (because 
> I can't -- the test passes on my mac). If you can't then it would be useful 
> to get as much information about this buildbot as possible (what kind of 
> debugserver it uses, OS versions and such), as it means there's something 
> different about it.

We are now hosting them on the same infrastructure that also hosts 
ci.swift.org, so I no longer have direct access to them either. What anyone can 
always do is land a temporary patch that adds more logging to the test.

Couple of questions I _can_ answer:
- green dragon uses the just-built debugserver (according to the make log 
output and my memory)
- based on the CMake output, I think the machines run macOS 14.1

```
-- LLVM host triple: arm64-apple-darwin23.1.0
...
-- LLDB tests use just-built debug server
```

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

adrian-prantl wrote:

May I recommend we add a skip for macOS < 15 to get the bot green again?

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

2025-03-18 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 0a21ef9536e0f591d334b230bd388bcb503e27ec 
5656cdd65048c0af5482aef7de1e163dd078d437 --extensions h,cpp -- 
libcxxabi/src/demangle/ItaniumDemangle.h libcxxabi/src/demangle/Utility.h 
lldb/include/lldb/Core/FormatEntity.h lldb/include/lldb/Core/Mangled.h 
lldb/include/lldb/Symbol/Function.h lldb/include/lldb/Target/Language.h 
lldb/source/Core/FormatEntity.cpp lldb/source/Core/Mangled.cpp 
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h 
lldb/source/Symbol/Function.cpp lldb/source/Target/Language.cpp 
llvm/include/llvm/Demangle/Demangle.h 
llvm/include/llvm/Demangle/ItaniumDemangle.h 
llvm/include/llvm/Demangle/Utility.h llvm/lib/Demangle/ItaniumDemangle.cpp 
llvm/unittests/Demangle/ItaniumDemangleTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index ef4400e73d..cf0f632912 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -230,7 +230,8 @@ static bool PrettyPrintFunctionNameWithArgs(
 
   // Dump anything between the basename and the argument list.
   if (demangled_info.ArgumentLocs.first > base_end)
-out_stream.PutCString(full_name.substr(base_end, 
demangled_info.ArgumentLocs.first - base_end));
+out_stream.PutCString(full_name.substr(
+base_end, demangled_info.ArgumentLocs.first - base_end));
 
   // Dump arguments.
   out_stream.PutChar('(');

``




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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

Michael137 wrote:

> It would be useful to know if you can reproduce this problem locally (because 
> I can't -- the test passes on my mac). If you can't then it would be useful 
> to get as much information about this buildbot as possible (what kind of 
> debugserver it uses, OS versions and such), as it means there's something 
> different about it.

Yup can confirm it doesn't reproduce locally for me either. I don't have access 
to the buildbot machine but @adrian-prantl might?

Perhaps we can just dump this info as part of the test?

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


[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)

2025-03-18 Thread Aleksandr Korepanov via lldb-commits


@@ -63,7 +63,7 @@ def execute(self, test, litConfig):
 try:
 out, err, exitCode = lit.util.executeCommand(
 cmd,
-env=test.config.environment,
+env={**os.environ, **test.config.environment},

AlexK0 wrote:

Fixed

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

Michael137 wrote:

FYI, these are also failing on x86_64 on macOS: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/10678/
```
Failed Tests (3):
  lldb-api :: 
functionalities/reverse-execution/TestReverseContinueBreakpoints.py
  lldb-api :: 
functionalities/reverse-execution/TestReverseContinueWatchpoints.py
```
Log file: 
[x86-failures.txt](https://github.com/user-attachments/files/19317456/x86-failures.txt)

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


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

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

https://github.com/labath commented:

I think something like this makes sense, but if we're doing this, I think we 
should do it properly and actually remove the DWARFExpression->SymbolFileDWARF 
dependency. We can't do that if `DWARFUnitInterface` is defined in the symbol 
file plugin, nor while it contains methods like `GetSymbolFileDWARF()`. Moving 
the interface definition elsewhere is easy. The second part requires some 
thought. It looks like the main use for that method is to provide vendor 
extensibility for dwarf parsing, so I think we should expose *that* as an 
interface (i.e., have methods like ParseVendorDWARFOpcodeSize and 
GetVendorDWARFOpcodeSize) instead of the raw DWARF symbol file.

For this reason, I also think the interface shouldn't be called 
DWARFUnitInterface, but rather something centred on DWARFExpression and the 
things it needs from its users. For lack of imagination, I'm going to suggest 
DWARFExpression::Delegate (because we already use that term in some places), 
but maybe we'll come up with something more specific in the process. (This 
means it may not make sense to DWARFUnit to inherit from 
DWARFExpression::Delegate, but that's okay -- we can always use composition 
instead)

I also want to look at each function in that interface and see if it's really 
necessary. Two examples:
- GetLocationTable is only used from ParseDWARFLocationList and *that* is only 
used from DWARF plugin code. Instead of adding this to the interface, I think 
we should move ParseDWARFLocationList into the DWARF plugin. (This can/should 
be a separate patch)
- I'm not sure that `GetAddressByteSize` is necessary since the DataExtractor 
member (`m_data`) already has a method with the same name (and it's even used 
in some places). Before adding that to the interface, I'd like to see if we can 
make everything use the value in m_data instead.

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] Fix double free in CommandPluginInterfaceImplementation (PR #131658)

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

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


[Lldb-commits] [lldb] 7b3455e - [lldb] Fix double free in CommandPluginInterfaceImplementation (#131658)

2025-03-18 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-03-18T09:48:34-07:00
New Revision: 7b3455e24ab5aa090e5b2b9ce50c249843c45754

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

LOG: [lldb] Fix double free in CommandPluginInterfaceImplementation (#131658)

The class was taking ownership of the SBCommandPluginInterface pointer
it was passed in, by wrapping it in a shared pointer. This causes a
double free in the unit test when the object is destroyed and the same
pointer gets freed once when the SBCommandPluginInterface goes away and
then again when the shared pointer hits a zero refcount.

Added: 


Modified: 
lldb/source/API/SBCommandInterpreter.cpp
lldb/unittests/API/SBCommandInterpreterTest.cpp

Removed: 




diff  --git a/lldb/source/API/SBCommandInterpreter.cpp 
b/lldb/source/API/SBCommandInterpreter.cpp
index d153e2acdf853..de22a9dd96bd8 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -77,7 +77,7 @@ class CommandPluginInterfaceImplementation : public 
CommandObjectParsed {
 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
 m_backend->DoExecute(debugger_sb, command.GetArgumentVector(), sb_return);
   }
-  std::shared_ptr m_backend;
+  lldb::SBCommandPluginInterface *m_backend;
   std::optional m_auto_repeat_command;
 };
 } // namespace lldb_private

diff  --git a/lldb/unittests/API/SBCommandInterpreterTest.cpp 
b/lldb/unittests/API/SBCommandInterpreterTest.cpp
index 941b738e84ac8..5651e1c3dc63f 100644
--- a/lldb/unittests/API/SBCommandInterpreterTest.cpp
+++ b/lldb/unittests/API/SBCommandInterpreterTest.cpp
@@ -6,24 +6,28 @@
 //
 //===--===/
 
-#include "gtest/gtest.h"
-
 // Use the umbrella header for -Wdocumentation.
 #include "lldb/API/LLDB.h"
 
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/API/SBDebugger.h"
+#include "gtest/gtest.h"
 #include 
 #include 
 
 using namespace lldb;
+using namespace lldb_private;
 
 class SBCommandInterpreterTest : public testing::Test {
 protected:
   void SetUp() override {
-SBDebugger::Initialize();
-m_dbg = SBDebugger::Create(/*source_init_files=*/false);
+debugger = SBDebugger::Create(/*source_init_files=*/false);
   }
 
-  SBDebugger m_dbg;
+  void TearDown() override { SBDebugger::Destroy(debugger); }
+
+  SubsystemRAII subsystems;
+  SBDebugger debugger;
 };
 
 class DummyCommand : public SBCommandPluginInterface {
@@ -44,7 +48,7 @@ class DummyCommand : public SBCommandPluginInterface {
 TEST_F(SBCommandInterpreterTest, SingleWordCommand) {
   // We first test a command without autorepeat
   DummyCommand dummy("It worked");
-  SBCommandInterpreter interp = m_dbg.GetCommandInterpreter();
+  SBCommandInterpreter interp = debugger.GetCommandInterpreter();
   interp.AddCommand("dummy", &dummy, /*help=*/nullptr);
   {
 SBCommandReturnObject result;
@@ -78,7 +82,7 @@ TEST_F(SBCommandInterpreterTest, SingleWordCommand) {
 }
 
 TEST_F(SBCommandInterpreterTest, MultiWordCommand) {
-  SBCommandInterpreter interp = m_dbg.GetCommandInterpreter();
+  SBCommandInterpreter interp = debugger.GetCommandInterpreter();
   auto command = interp.AddMultiwordCommand("multicommand", /*help=*/nullptr);
   // We first test a subcommand without autorepeat
   DummyCommand subcommand("It worked again");



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


[Lldb-commits] [lldb] 6d38dbf - [lldb] Skip reverse continue tests on macos<15.0

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

Author: Pavel Labath
Date: 2025-03-18T17:52:36+01:00
New Revision: 6d38dbf6eb56fd2b3399565af455de96a99ffa0f

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

LOG: [lldb] Skip reverse continue tests on macos<15.0

They're failing for unknown reasons.

Added: 


Modified: 

lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py

lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
 
b/lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
index 0a5f2d88fb917..a159e0f716dbe 100644
--- 
a/lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
+++ 
b/lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
@@ -10,10 +10,12 @@
 
 class TestReverseContinueBreakpoints(ReverseTestBase):
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue(self):
 self.reverse_continue_internal(async_mode=False)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_async(self):
 self.reverse_continue_internal(async_mode=True)
 
@@ -42,10 +44,12 @@ def reverse_continue_internal(self, async_mode):
 self.assertEqual(process.GetExitStatus(), 0)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_breakpoint(self):
 self.reverse_continue_breakpoint_internal(async_mode=False)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_breakpoint_async(self):
 self.reverse_continue_breakpoint_internal(async_mode=True)
 
@@ -63,10 +67,12 @@ def reverse_continue_breakpoint_internal(self, async_mode):
 self.assertEqual(threads_now, initial_threads)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_skip_breakpoint(self):
 self.reverse_continue_skip_breakpoint_internal(async_mode=False)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_skip_breakpoint_async(self):
 self.reverse_continue_skip_breakpoint_internal(async_mode=True)
 
@@ -91,10 +97,12 @@ def reverse_continue_skip_breakpoint_internal(self, 
async_mode):
 )
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_continue_preserves_direction(self):
 self.continue_preserves_direction_internal(async_mode=False)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_continue_preserves_direction_asyhc(self):
 self.continue_preserves_direction_internal(async_mode=True)
 

diff  --git 
a/lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
 
b/lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
index 2c4875d1cd3ea..c942f2a0386e5 100644
--- 
a/lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
+++ 
b/lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
@@ -10,10 +10,12 @@
 
 class TestReverseContinueWatchpoints(ReverseTestBase):
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_watchpoint(self):
 self.reverse_continue_watchpoint_internal(async_mode=False)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_watchpoint_async(self):
 self.reverse_continue_watchpoint_internal(async_mode=True)
 
@@ -58,10 +60,12 @@ def reverse_continue_watchpoint_internal(self, async_mode):
 )
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_skip_watchpoint(self):
 self.reverse_continue_skip_watchpoint_internal(async_mode=False)
 
 @skipIfRemote
+@skipIf(macos_version=["<", "15.0"])
 def test_reverse_continue_skip_watchpoint_async(self):
 self.reverse_continue_skip_watchpoint_internal(async_mode=True)
 



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


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

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

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

>From 464460db7550673bac788ad11e3ed4d45946cd71 Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Mon, 17 Mar 2025 19:13:20 +0400
Subject: [PATCH 1/2] [LLDB][NFC] Added the interface DWARFUnitInterface to
 break dependencies and reduce lldb-server size

This patch addresses the issue #129543.

After this patch DWARFExpression does not call DWARFUnit directly and does not 
depend on lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp and a 
lot of clang code.

After this patch the size of lldb-server binary (Linux Aarch64)
is reduced from 42MB to 13MB with LLVM 20.0.0
and from 47MB to 17MB with LLVM 21.0.0.
---
 .../include/lldb/Expression/DWARFExpression.h | 23 
 lldb/source/Expression/DWARFExpression.cpp| 55 ++-
 .../SymbolFile/DWARF/DWARFFormValue.cpp   |  6 +-
 .../Plugins/SymbolFile/DWARF/DWARFUnit.cpp| 39 ++---
 .../Plugins/SymbolFile/DWARF/DWARFUnit.h  | 50 +
 5 files changed, 101 insertions(+), 72 deletions(-)

diff --git a/lldb/include/lldb/Expression/DWARFExpression.h 
b/lldb/include/lldb/Expression/DWARFExpression.h
index 2c1e717ee32eb..cf4098f2acc51 100644
--- a/lldb/include/lldb/Expression/DWARFExpression.h
+++ b/lldb/include/lldb/Expression/DWARFExpression.h
@@ -23,7 +23,7 @@ namespace lldb_private {
 
 namespace plugin {
 namespace dwarf {
-class DWARFUnit;
+class DWARFUnitInterface;
 } // namespace dwarf
 } // namespace plugin
 
@@ -65,20 +65,20 @@ class DWARFExpression {
   /// \return
   /// The address specified by the operation, if the operation exists, or
   /// an llvm::Error otherwise.
-  llvm::Expected
-  GetLocation_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu) const;
+  llvm::Expected GetLocation_DW_OP_addr(
+  const plugin::dwarf::DWARFUnitInterface *dwarf_cu) const;
 
-  bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnit *dwarf_cu,
+  bool Update_DW_OP_addr(const plugin::dwarf::DWARFUnitInterface *dwarf_cu,
  lldb::addr_t file_addr);
 
   void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size,
uint8_t addr_byte_size);
 
-  bool
-  ContainsThreadLocalStorage(const plugin::dwarf::DWARFUnit *dwarf_cu) const;
+  bool ContainsThreadLocalStorage(
+  const plugin::dwarf::DWARFUnitInterface *dwarf_cu) const;
 
   bool LinkThreadLocalStorage(
-  const plugin::dwarf::DWARFUnit *dwarf_cu,
+  const plugin::dwarf::DWARFUnitInterface *dwarf_cu,
   std::function const
   &link_address_callback);
 
@@ -132,13 +132,14 @@ class DWARFExpression {
   static llvm::Expected
   Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
lldb::ModuleSP module_sp, const DataExtractor &opcodes,
-   const plugin::dwarf::DWARFUnit *dwarf_cu,
+   const plugin::dwarf::DWARFUnitInterface *dwarf_cu,
const lldb::RegisterKind reg_set, const Value *initial_value_ptr,
const Value *object_address_ptr);
 
-  static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu,
- const DataExtractor &data,
- DWARFExpressionList *loc_list);
+  static bool
+  ParseDWARFLocationList(const plugin::dwarf::DWARFUnitInterface *dwarf_cu,
+ const DataExtractor &data,
+ DWARFExpressionList *loc_list);
 
   bool GetExpressionData(DataExtractor &data) const {
 data = m_data;
diff --git a/lldb/source/Expression/DWARFExpression.cpp 
b/lldb/source/Expression/DWARFExpression.cpp
index f48f3ab9307dd..41fbca59db60f 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -133,7 +133,7 @@ static llvm::Error 
ReadRegisterValueAsScalar(RegisterContext *reg_ctx,
 static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data,
 const lldb::offset_t data_offset,
 const LocationAtom op,
-const DWARFUnit *dwarf_cu) {
+const DWARFUnitInterface *dwarf_cu) {
   lldb::offset_t offset = data_offset;
   switch (op) {
   // Only used in LLVM metadata.
@@ -362,7 +362,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor 
&data,
// + LEB128
   {
 data.Skip_LEB128(&offset);
-return DWARFUnit::GetAddressByteSize(dwarf_cu) + offset - data_offset;
+return DWARFUnitInterface::GetAddressByteSize(dwarf_cu) + offset -
+   data_offset;
   }
 
   case DW_OP_GNU_entry_value:
@@ -393,8 +394,8 @@ static lldb::offset_t GetOpcodeDataSize(const DataExtractor 
&data,
   return LLDB_INVALID_OFFSET;
 }
 
-llvm::Expected
-DWARFExpression::GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu) const {
+llvm::Expected DWARFExpression::GetLocation_DW_OP_add

[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)

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

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

Thanks.

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

labath wrote:

This is what I've got at 23743f5bf974ed1171fd8123f8d2af0f43be3596:

[success.log](https://github.com/user-attachments/files/19319458/success.log)


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


[Lldb-commits] [lldb] [lldb/platform-gdb] Do not assume a persistent connection (PR #131736)

2025-03-18 Thread Igor Kudrin via lldb-commits

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] (PR #131836)

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

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/131836

This is a prototype of highlighting function basenames in LLDB's backtraces. 
This is done by tracking information about components of a demangled function 
name and plumbing that from the demangler through to LLDB.

Example:
https://github.com/user-attachments/assets/4ec56a05-650b-4f56-b035-7691b34c3cc0";
 />


>From 03a4172a3a4dae7d1ed45570fff66a89e792ca71 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 11 Mar 2025 08:57:13 +
Subject: [PATCH 1/4] [llvm][ItaniumDemangle] Add function name location
 tracking

---
 libcxxabi/src/demangle/ItaniumDemangle.h  |  20 +++
 libcxxabi/src/demangle/Utility.h  | 163 --
 llvm/include/llvm/Demangle/ItaniumDemangle.h  |  20 +++
 llvm/include/llvm/Demangle/Utility.h  | 163 --
 .../Demangle/ItaniumDemangleTest.cpp  | 105 +++
 5 files changed, 439 insertions(+), 32 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h 
b/libcxxabi/src/demangle/ItaniumDemangle.h
index 3df41b5f4d7d0..d3cd1e4a405a6 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -851,11 +851,13 @@ class FunctionType final : public Node {
   // by printing out the return types's left, then print our parameters, then
   // finally print right of the return type.
   void printLeft(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
 Ret->printLeft(OB);
 OB += " ";
   }
 
   void printRight(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
 OB.printOpen();
 Params.printWithComma(OB);
 OB.printClose();
@@ -976,13 +978,26 @@ class FunctionEncoding final : public Node {
   if (!Ret->hasRHSComponent(OB))
 OB += " ";
 }
+
+// Nested FunctionEncoding parsing can happen with following productions:
+// * 
+// * 
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
+OB.FunctionInfo.updateScopeStart(OB);
+
 Name->print(OB);
   }
 
   void printRight(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
+OB.FunctionInfo.finalizeStart(OB);
+
 OB.printOpen();
 Params.printWithComma(OB);
 OB.printClose();
+
+OB.FunctionInfo.finalizeArgumentEnd(OB);
+
 if (Ret)
   Ret->printRight(OB);
 
@@ -1005,6 +1020,8 @@ class FunctionEncoding final : public Node {
   OB += " requires ";
   Requires->print(OB);
 }
+
+OB.FunctionInfo.finalizeEnd(OB);
   }
 };
 
@@ -1072,7 +1089,9 @@ struct NestedName : Node {
   void printLeft(OutputBuffer &OB) const override {
 Qual->print(OB);
 OB += "::";
+OB.FunctionInfo.updateScopeEnd(OB);
 Name->print(OB);
+OB.FunctionInfo.updateBasenameEnd(OB);
   }
 };
 
@@ -1633,6 +1652,7 @@ struct NameWithTemplateArgs : Node {
 
   void printLeft(OutputBuffer &OB) const override {
 Name->print(OB);
+OB.FunctionInfo.updateBasenameEnd(OB);
 TemplateArgs->print(OB);
   }
 };
diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index f1fad35d60d98..3bfdf8dff4526 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -27,6 +27,22 @@
 
 DEMANGLE_NAMESPACE_BEGIN
 
+template  class ScopedOverride {
+  T &Loc;
+  T Original;
+
+public:
+  ScopedOverride(T &Loc_) : ScopedOverride(Loc_, Loc_) {}
+
+  ScopedOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) {
+Loc_ = std::move(NewVal);
+  }
+  ~ScopedOverride() { Loc = std::move(Original); }
+
+  ScopedOverride(const ScopedOverride &) = delete;
+  ScopedOverride &operator=(const ScopedOverride &) = delete;
+};
+
 // Stream that AST nodes write their string representation into after the AST
 // has been parsed.
 class OutputBuffer {
@@ -83,6 +99,127 @@ class OutputBuffer {
 return std::string_view(Buffer, CurrentPosition);
   }
 
+  // Stores information about parts of a demangled function name.
+  struct FunctionNameInfo {
+///< A [start, end) pair for the function basename.
+///< The basename is the name without scope qualifiers
+///< and without template parameters. E.g.,
+///< \code{.cpp}
+///

[Lldb-commits] [lldb] [lldb/platform-gdb] Do not assume a persistent connection (PR #131736)

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

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


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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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


@@ -83,6 +99,127 @@ class OutputBuffer {
 return std::string_view(Buffer, CurrentPosition);
   }
 
+  // Stores information about parts of a demangled function name.
+  struct FunctionNameInfo {
+///< A [start, end) pair for the function basename.

adrian-prantl wrote:

```suggestion
/// A [start, end) pair for the function basename.
```

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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


@@ -83,6 +99,127 @@ class OutputBuffer {
 return std::string_view(Buffer, CurrentPosition);
   }
 
+  // Stores information about parts of a demangled function name.

adrian-prantl wrote:

```suggestion
  /// Stores information about parts of a demangled function name.
```

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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


@@ -138,10 +139,10 @@ class CPlusPlusLanguage : public Language {
   ConstString
   GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override;
 
-  bool GetFunctionDisplayName(const SymbolContext *sc,
-  const ExecutionContext *exe_ctx,
-  FunctionNameRepresentation representation,
-  Stream &s) override;
+  bool GetFunctionDisplayName(
+  const SymbolContext *sc, const ExecutionContext *exe_ctx,
+  FunctionNameRepresentation representation, Stream &s,
+  const FormatEntity::Entry::HighlightSettings &) override;

adrian-prantl wrote:

I feel like the idea here was to have the "out" parameters come last?

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


[Lldb-commits] [lldb] 6542cf1 - [lldb/platform-gdb] Do not assume a persistent connection (#131736)

2025-03-18 Thread via lldb-commits

Author: Igor Kudrin
Date: 2025-03-18T09:25:35-07:00
New Revision: 6542cf1973208a83b2f883f2143464c4fdbac9eb

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

LOG: [lldb/platform-gdb] Do not assume a persistent connection (#131736)

After https://reviews.llvm.org/D116539, when `m_gdb_client_up` in
`PlatformRemoteGDBServer` is not null, the connection to a server is
expected to exist. However,
`PlatformRemoteGDBServer::DisconnectRemote()` is not the only way to
close the connection;
`GDBRemoteCommunication::WaitForPacketNoLock()` can disconnect if the
server stops responding, and in this case `m_gdb_client_up` is not
cleared. The patch removes this assumption and checks the connection
status directly.

Added: 
lldb/unittests/Platform/gdb-server/CMakeLists.txt
lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp

Modified: 
lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/unittests/Platform/CMakeLists.txt

Removed: 




diff  --git 
a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp 
b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 58d2ecd94836d..26ca6ed128972 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -206,11 +206,7 @@ bool PlatformRemoteGDBServer::SetRemoteWorkingDirectory(
 }
 
 bool PlatformRemoteGDBServer::IsConnected() const {
-  if (m_gdb_client_up) {
-assert(m_gdb_client_up->IsConnected());
-return true;
-  }
-  return false;
+  return m_gdb_client_up && m_gdb_client_up->IsConnected();
 }
 
 Status PlatformRemoteGDBServer::ConnectRemote(Args &args) {

diff  --git a/lldb/unittests/Platform/CMakeLists.txt 
b/lldb/unittests/Platform/CMakeLists.txt
index 963975602d671..5c0ef5ca6ef22 100644
--- a/lldb/unittests/Platform/CMakeLists.txt
+++ b/lldb/unittests/Platform/CMakeLists.txt
@@ -15,3 +15,4 @@ add_lldb_unittest(LLDBPlatformTests
   )
 
 add_subdirectory(Android)
+add_subdirectory(gdb-server)

diff  --git a/lldb/unittests/Platform/gdb-server/CMakeLists.txt 
b/lldb/unittests/Platform/gdb-server/CMakeLists.txt
new file mode 100644
index 0..41f94b06f6f2c
--- /dev/null
+++ b/lldb/unittests/Platform/gdb-server/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_lldb_unittest(PlatformGdbRemoteTests
+  PlatformRemoteGDBServerTest.cpp
+
+  LINK_LIBS
+lldbPluginPlatformGDB
+LLVMTestingSupport
+  )

diff  --git 
a/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp 
b/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp
new file mode 100644
index 0..2ea4dac006cd8
--- /dev/null
+++ b/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp
@@ -0,0 +1,68 @@
+//===-- PlatformRemoteGDBServerTest.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_gdb_server;
+using namespace lldb_private::process_gdb_remote;
+using namespace testing;
+
+namespace {
+
+class PlatformRemoteGDBServerHack : public PlatformRemoteGDBServer {
+public:
+  void
+  SetGDBClient(std::unique_ptr gdb_client_up) {
+m_gdb_client_up = std::move(gdb_client_up);
+  }
+};
+
+class MockConnection : public lldb_private::Connection {
+public:
+  MOCK_METHOD(lldb::ConnectionStatus, Connect,
+  (llvm::StringRef url, Status *error_ptr), (override));
+  MOCK_METHOD(lldb::ConnectionStatus, Disconnect, (Status * error_ptr),
+  (override));
+  MOCK_METHOD(bool, IsConnected, (), (const, override));
+  MOCK_METHOD(size_t, Read,
+  (void *dst, size_t dst_len, const Timeout &timeout,
+   lldb::ConnectionStatus &status, Status *error_ptr),
+  (override));
+  MOCK_METHOD(size_t, Write,
+  (const void *dst, size_t dst_len, lldb::ConnectionStatus &status,
+   Status *error_ptr),
+  (override));
+  MOCK_METHOD(std::string, GetURI, (), (override));
+  MOCK_METHOD(bool, InterruptRead, (), (override));
+};
+
+} // namespace
+
+TEST(PlatformRemoteGDBServerTest, IsConnected) {
+  bool is_connected = true;
+
+  auto connection = std::make_unique>();
+  ON_CALL(*connection, IsConnected())
+  .WillByDefault(ReturnPointee(&is_connected));
+
+  auto client = std::make_unique();
+ 

[Lldb-commits] [lldb] [llvm] [lldb][lldb-dap] Implement jump to cursor (PR #130503)

2025-03-18 Thread Ebuka Ezike via lldb-commits

https://github.com/da-viper updated 
https://github.com/llvm/llvm-project/pull/130503

>From 63c0d5071146893b485dd4d2665e55fc697e1352 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 9 Mar 2025 12:46:54 +
Subject: [PATCH 01/19] [lldb-dap] implement jump to cursor.

---
 lldb/cmake/modules/LLDBConfig.cmake   |   2 +-
 lldb/tools/lldb-dap/CMakeLists.txt|   2 +
 lldb/tools/lldb-dap/DAP.cpp   |  23 +++-
 lldb/tools/lldb-dap/DAP.h |  27 +++-
 .../lldb-dap/Handler/GoToRequestHandler.cpp   | 103 +++
 .../Handler/GoToTargetsRequestHandler.cpp | 120 ++
 .../Handler/InitializeRequestHandler.cpp  |   2 +-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  14 ++
 lldb/tools/lldb-dap/lldb-dap.cpp  |   2 +
 9 files changed, 291 insertions(+), 4 deletions(-)
 create mode 100644 lldb/tools/lldb-dap/Handler/GoToRequestHandler.cpp
 create mode 100644 lldb/tools/lldb-dap/Handler/GoToTargetsRequestHandler.cpp

diff --git a/lldb/cmake/modules/LLDBConfig.cmake 
b/lldb/cmake/modules/LLDBConfig.cmake
index 747f7e6038181..8d02088548634 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -57,7 +57,7 @@ add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses 
support in LLDB" Curse
 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in 
LLDB" LibLZMA LIBLZMA_FOUND)
 add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" 
LuaAndSwig LUAANDSWIG_FOUND)
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in 
LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
-add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION 2.8)
+add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" 
LibXml2 LIBXML2_FOUND VERSION)
 add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support 
in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)
 
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" 
ON)
diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 9a2d604f4d573..ff7e413c4bb1c 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -50,6 +50,8 @@ add_lldb_tool(lldb-dap
   Handler/DisconnectRequestHandler.cpp
   Handler/EvaluateRequestHandler.cpp
   Handler/ExceptionInfoRequestHandler.cpp
+Handler/GoToRequestHandler.cpp
+Handler/GoToTargetsRequestHandler.cpp
   Handler/InitializeRequestHandler.cpp
   Handler/LaunchRequestHandler.cpp
   Handler/LocationsRequestHandler.cpp
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 1f7b25e7c5bcc..f72bc34d52b53 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -76,7 +76,7 @@ DAP::DAP(std::string name, llvm::StringRef path, 
std::ofstream *log,
   configuration_done_sent(false), waiting_for_run_in_terminal(false),
   progress_event_reporter(
   [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }),
-  reverse_request_seq(0), repl_mode(repl_mode) {}
+  reverse_request_seq(0), repl_mode(repl_mode), goto_id_map() {}
 
 DAP::~DAP() = default;
 
@@ -899,6 +899,27 @@ lldb::SBError DAP::WaitForProcessToStop(uint32_t seconds) {
   return error;
 }
 
+std::optional Gotos::GetLineEntry(uint64_t id) const {
+  const auto iter = line_entries.find(id);
+  if (iter != line_entries.end())
+return iter->second;
+
+  return std::nullopt;
+}
+
+uint64_t Gotos::InsertLineEntry(lldb::SBLineEntry line_entry) {
+  const auto spec_id = this->NewSpecId();
+  line_entries.insert(std::make_pair(spec_id, line_entry));
+  return spec_id;
+}
+
+void Gotos::Clear() {
+  new_id = 0UL;
+  line_entries.clear();
+}
+
+uint64_t Gotos::NewSpecId() { return new_id++; }
+
 void Variables::Clear() {
   locals.Clear();
   globals.Clear();
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 8b2e498a28c95..693908016fdc9 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -79,6 +79,27 @@ enum class PacketStatus {
 
 enum class ReplMode { Variable = 0, Command, Auto };
 
+class Gotos {
+public:
+  /// \return the line_entry corresponding with \p id
+  ///
+  /// If \p id is invalid std::nullopt is returned.
+  std::optional GetLineEntry(uint64_t id) const;
+
+  /// Insert a new \p line_entry.
+  /// \return id assigned to this line_entry.
+  uint64_t InsertLineEntry(lldb::SBLineEntry line_entry);
+
+  /// clears all line entries and reset the generated ids.
+  void Clear();
+
+private:
+  uint64_t NewSpecId();
+
+  llvm::DenseMap line_entries;
+  uint64_t new_id = 0ul;
+};
+
 struct Variables {
   /// Variable_reference start index of permanent expandable variable.
   static constexpr int64_t PermanentVariableStartIndex = (1ll << 32);
@@ -209,6 +230,7 @@ struct DAP {
   // empty; if the previous expression was a varia

[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)

2025-03-18 Thread Adrian Vogelsgesang via lldb-commits


@@ -0,0 +1,76 @@
+//===-- ProtocolEvents.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
+//
+//===--===//
+//
+// This file contains POD structs based on the DAP specification at
+// https://microsoft.github.io/debug-adapter-protocol/specification
+//
+// This is not meant to be a complete implementation, new interfaces are added
+// when they're needed.
+//
+// Each struct has a toJSON and fromJSON function, that converts between
+// the struct and a JSON representation. (See JSON.h)
+//
+//===--===//
+
+#ifndef LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_EVENTS_H
+#define LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_EVENTS_H
+
+#include "lldb/lldb-types.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+
+namespace lldb_dap::protocol {
+
+// MARK: Events
+
+/// The event indicates that the debuggee has exited and returns its exit code.
+struct ExitedEventBody {
+  static llvm::StringLiteral getEvent() { return "exited"; }

vogelsgesang wrote:

seems to be unused? who calls this?

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


[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)

2025-03-18 Thread Adrian Vogelsgesang via lldb-commits


@@ -0,0 +1,57 @@
+//===-- EventHandler.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_TOOLS_LLDB_DAP_EVENTS_EVENT_HANDLER
+#define LLDB_TOOLS_LLDB_DAP_EVENTS_EVENT_HANDLER
+
+#include "DAP.h"
+#include "Protocol/ProtocolBase.h"
+#include "Protocol/ProtocolEvents.h"
+#include "lldb/API/SBProcess.h"
+
+namespace lldb_dap {
+
+template  class BaseEventHandler {
+public:
+  BaseEventHandler(DAP &dap) : dap(dap) {}
+
+  virtual ~BaseEventHandler() = default;
+
+  virtual llvm::StringLiteral getEvent() const = 0;
+  virtual Body Handler(Args...) const = 0;
+
+  void operator()(Args... args) const {
+Body body = Handler(args...);
+protocol::Event event{/*event=*/getEvent().str(), 
/*body=*/std::move(body)};

vogelsgesang wrote:

should this be using `Body.getEvent()` instead? Afaict, we then wouldn't need a 
virtual call to `getEvent` then

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


[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)

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

https://github.com/clayborg commented:

Pretty good start. There can be more than one breakpoint at a location and we 
need to be sure we test these cases. Like we can have an exception breakpoint 
(which might be at `cxa_throw`) and we can have a function breakpoint for this 
as well. We need to make sure we document how we are doing to display this. If 
we must pick one, then lets be clear about:
- exception breakpoints take precedence
- then function breakpoints
- then source file and line breakpoints

If we have a free form text we can attach to the stop notification it might be 
nice to see "function breakpoint & exception breakpoint", but if we have to 
pick just one, then we need to be clear about what we are going to do.

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


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

2025-03-18 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 351bcd9fe229121fac58e051f9a83dce2d3066ae 
9a6d64373f45921c5b23460b12544869355ddd15 --extensions h,cpp -- 
lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/RequestHandler.h lldb/tools/lldb-dap/lldb-dap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
index 44e8355d67..dadee602f6 100644
--- a/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/WriteMemoryRequestHandler.cpp
@@ -122,7 +122,7 @@ void WriteMemoryRequestHandler::operator()(
   int64_t countWrite = 0;
 
   output = llvm::encodeBase64(data64);
-  
+
   // write the memory
   if (!output.empty()) {
 lldb::SBProcess process = dap.target.GetProcess();

``




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][Telemetry] Collect telemetry from client when allowed. (PR #129728)

2025-03-18 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 1/2] [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 LLDB

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

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

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

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

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

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

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

2025-03-18 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 d85a81b4e4cfc0fdc7c259d64f847e7bbeee56d2 
4b134946c5f3aa315f5f4cb7cddfa571ff110a6d --extensions cpp,h -- 
lldb/include/lldb/API/SBDebugger.h lldb/include/lldb/Core/Debugger.h 
lldb/include/lldb/Core/Telemetry.h lldb/source/API/SBDebugger.cpp 
lldb/source/Core/Debugger.cpp lldb/source/Core/Telemetry.cpp 
lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/LLDBUtils.h 
lldb/unittests/Core/TelemetryTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index aadf15bd01..26eaba6538 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -36,15 +36,16 @@ struct LLDBConfig : public ::llvm::telemetry::Config {
   // the vendor while creating the Manager.
   const bool detailed_command_telemetry;
 
-// If true, we will collect telemetry from LLDB's clients (eg., lldb-dap) 
via
+  // 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 enable_client_telemetry;
-  
-  explicit LLDBConfig(bool enable_telemetry, bool detailed_command_telemetry, 
bool enable_client_telemetry)
+
+  explicit LLDBConfig(bool enable_telemetry, bool detailed_command_telemetry,
+  bool enable_client_telemetry)
   : ::llvm::telemetry::Config(enable_telemetry),
 detailed_command_telemetry(detailed_command_telemetry),
-enable_client_telemetry(enable_client_telemetry){}
+enable_client_telemetry(enable_client_telemetry) {}
 };
 
 // We expect each (direct) subclass of LLDBTelemetryInfo to
@@ -90,7 +91,7 @@ struct ClientInfo : public LLDBBaseTelemetryInfo {
   std::string request_name;
   std::optional error_msg;
 };
-  
+
 struct CommandInfo : public LLDBBaseTelemetryInfo {
   /// If the command is/can be associated with a target entry this field
   /// contains that target's UUID.  otherwise.
diff --git a/lldb/source/Core/Telemetry.cpp b/lldb/source/Core/Telemetry.cpp
index 51df8826e7..1a4d1bce95 100644
--- a/lldb/source/Core/Telemetry.cpp
+++ b/lldb/source/Core/Telemetry.cpp
@@ -148,7 +148,6 @@ void TelemetryManager::DispatchClientTelemetry(
"Failed to dispatch client telemetry");
 }
 
-
 class NoOpTelemetryManager : public TelemetryManager {
 public:
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override {
@@ -164,11 +163,11 @@ public:
 return "NoOpTelemetryManager";
   }
 
-  DispatchClientTelemetry(
-const lldb_private::StructuredDataImpl &entry, Debugger *debugger) 
override {
+  DispatchClientTelemetry(const lldb_private::StructuredDataImpl &entry,
+  Debugger *debugger) override {
 // Does nothing.
   }
-  
+
   llvm::Error dispatch(llvm::telemetry::TelemetryInfo *entry) override {
 // Does nothing.
 return llvm::Error::success();
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 0e7a1a1d08..141edd8dbd 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -673,7 +673,7 @@ void DAP::SetTarget(const lldb::SBTarget target) {
 }
 
 bool DAP::HandleObject(const protocol::Message &M) {
- TelemetryDispatcher dispatcher;
+  TelemetryDispatcher dispatcher;
   if (const auto *req = std::get_if(&M)) {
 auto handler_pos = request_handlers.find(req->command);
 dispatcher.set("request_name", req->command);
@@ -682,7 +682,8 @@ bool DAP::HandleObject(const protocol::Message &M) {
   return true; // Success
 }
 
-dispatcher.set("error", llvm::Twine("unhandled-command:" + 
req->command).str());
+dispatcher.set("error",
+   llvm::Twine("unhandled-command:" + req->command).str());
 DAP_LOG(log, "({0}) error: unhandled command '{1}'",
 transport.GetClientName(), req->command);
 return false; // Fail
diff --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
index 2c5e0a8c82..2d9c30b63c 100644
--- a/lldb/unittests/Core/TelemetryTest.cpp
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -53,7 +53,8 @@ class FakePlugin : public telemetry::TelemetryManager {
 public:
   FakePlugin()
   : telemetry::TelemetryManager(std::make_unique(
-/*enable_telemetry=*/true, /*detailed_command_telemetry=*/true, 
/*enable_client_telemetry*/true)) {}
+/*enable_telemetry=*/true, /*detailed_command_telemetry=*/true,
+/*enable_client_telemetry*/ true)) {}
 
   // TelemetryManager interface
   llvm::Error preDispatch(llvm::telemetry::TelemetryInfo *entry) override {

``




https://github.com/llvm/llvm-project/pull/129728
___
lldb-commits mailing

[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)

2025-03-18 Thread Aleksandr Korepanov via lldb-commits

https://github.com/AlexK0 updated 
https://github.com/llvm/llvm-project/pull/131600

>From 2186582c6113033a7adf2c3ac7fb1a6fcde5726c Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Mon, 17 Mar 2025 11:03:57 +0100
Subject: [PATCH 1/2] [LLDB][tests] Transfer APPDATA env for running tests

On Windows without APPDATA environment variable,
the test framework cannot import the 'packaging' module.
---
 lldb/test/API/lit.cfg.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py
index 08cf11c8a68db..4336a89d57c5f 100644
--- a/lldb/test/API/lit.cfg.py
+++ b/lldb/test/API/lit.cfg.py
@@ -343,6 +343,6 @@ def delete_module_cache(path):
 
 # Transfer some environment variables into the tests on Windows build host.
 if platform.system() == "Windows":
-for v in ["SystemDrive"]:
+for v in ["SystemDrive", "APPDATA"]:
 if v in os.environ:
 config.environment[v] = os.environ[v]

>From cc68d4a639d7cd3bdd783f91ce51824fc1c03ab6 Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Mon, 17 Mar 2025 11:06:46 +0100
Subject: [PATCH 2/2] [LLDB][tests] Fix tests for Windows

- On Windows there is different error message on setting watchpoint.

- Use 'test -d' to check for a directory instead of 'file' because
  Windows does not have the 'file' utility.
---
 .../watchpoint/watchlocation/TestTargetWatchAddress.py  | 6 +++---
 lldb/test/Shell/Diagnostics/TestDump.test   | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git 
a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py 
b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
index 7a0e42a4fc278..bc9680583a29c 100644
--- 
a/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
+++ 
b/lldb/test/API/python_api/watchpoint/watchlocation/TestTargetWatchAddress.py
@@ -201,8 +201,8 @@ def test_watch_address_with_invalid_watch_size(self):
 value.GetValueAsUnsigned(), 365, wp_opts, error
 )
 self.assertFalse(watchpoint)
-self.expect(
+# The message depends on whether the lldb-server implementation or 
the in-process implementation is used.
+self.assertRegex(
 error.GetCString(),
-exe=False,
-substrs=["Setting one of the watchpoint resources failed"],
+"Can't enable watchpoint|Setting one of the watchpoint 
resources failed",
 )
diff --git a/lldb/test/Shell/Diagnostics/TestDump.test 
b/lldb/test/Shell/Diagnostics/TestDump.test
index 2adde6b86d35a..cf10991d51c35 100644
--- a/lldb/test/Shell/Diagnostics/TestDump.test
+++ b/lldb/test/Shell/Diagnostics/TestDump.test
@@ -5,11 +5,11 @@
 # RUN: rm -rf %t.existing
 # RUN: mkdir -p %t.existing
 # RUN: %lldb -o 'diagnostics dump -d %t.existing'
-# RUN: file %t.existing | FileCheck %s
+# RUN: test -d %t.existing
 
 # Dump to a non-existing directory.
 # RUN: rm -rf %t.nonexisting
 # RUN: %lldb -o 'diagnostics dump -d %t.nonexisting'
-# RUN: file %t.nonexisting | FileCheck %s
+# RUN: test -d %t.nonexisting
 
 # CHECK: directory

___
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-18 Thread Daniel Chen via lldb-commits

https://github.com/DanielCChen updated 
https://github.com/llvm/llvm-project/pull/131200

>From 95377273d069e76023edf7ecc2df473e4e2f4aaa Mon Sep 17 00:00:00 2001
From: Daniel Chen 
Date: Thu, 13 Mar 2025 15:52:23 -0400
Subject: [PATCH 01/10] [compiler-rt] Disable
 LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX.

---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake   | 2 +-
 compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 4 ++--
 compiler-rt/cmake/base-config-ix.cmake  | 4 ++--
 libcxx/CMakeLists.txt   | 2 +-
 libcxxabi/CMakeLists.txt| 2 +-
 libunwind/CMakeLists.txt| 2 +-
 lldb/test/CMakeLists.txt| 2 +-
 lldb/utils/lldb-dotest/CMakeLists.txt   | 2 +-
 llvm-libgcc/CMakeLists.txt  | 2 +-
 9 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..cb80cf84ac6b6 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -118,7 +118,7 @@ function(add_compiler_rt_component name)
 endfunction()
 
 macro(set_output_name output name arch)
-  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT CMAKE_SYSTEM_NAME MATCHES 
"AIX")
 set(${output} ${name})
   else()
 if(ANDROID AND ${arch} STREQUAL "i386")
diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake 
b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 379e2c25949cb..21e384da03a3c 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -510,7 +510,7 @@ function(get_compiler_rt_target arch variable)
 endfunction()
 
 function(get_compiler_rt_install_dir arch install_dir)
-  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT 
CMAKE_SYSTEM_NAME MATCHES "AIX")
 get_compiler_rt_target(${arch} target)
 set(${install_dir} ${COMPILER_RT_INSTALL_LIBRARY_DIR}/${target} 
PARENT_SCOPE)
   else()
@@ -519,7 +519,7 @@ function(get_compiler_rt_install_dir arch install_dir)
 endfunction()
 
 function(get_compiler_rt_output_dir arch output_dir)
-  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT 
CMAKE_SYSTEM_NAME MATCHES "AIX")
 get_compiler_rt_target(${arch} target)
 set(${output_dir} ${COMPILER_RT_OUTPUT_LIBRARY_DIR}/${target} PARENT_SCOPE)
   else()
diff --git a/compiler-rt/cmake/base-config-ix.cmake 
b/compiler-rt/cmake/base-config-ix.cmake
index d92bc0e71fa1a..4224def96e948 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -103,13 +103,13 @@ if(NOT DEFINED COMPILER_RT_OS_DIR)
 string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
   endif()
 endif()
-if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME 
MATCHES "AIX")
   set(COMPILER_RT_OUTPUT_LIBRARY_DIR
 ${COMPILER_RT_OUTPUT_DIR}/lib)
   extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib)
   set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
 "Path where built compiler-rt libraries should be installed.")
-else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+else()
   set(COMPILER_RT_OUTPUT_LIBRARY_DIR
 ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
   extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" 
"lib/${COMPILER_RT_OS_DIR}")
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index abe12c2805a7c..6273f1c141292 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -414,7 +414,7 @@ set(LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE 
STRING
 set(LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared 
libc++ runtime library.")
 set(LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static 
libc++ runtime library.")
 
-if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME 
MATCHES "AIX")
   set(LIBCXX_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
   if(LIBCXX_LIBDIR_SUBDIR)
 string(APPEND LIBCXX_TARGET_SUBDIR /${LIBCXX_LIBDIR_SUBDIR})
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 6dcfc51e55321..ab11a15707533 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -182,7 +182,7 @@ set(CMAKE_MODULE_PATH
 set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
 "Path where built libc++abi runtime libraries should be installed.")
 
-if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME 
MATCHES "AIX")
   set(LIBCXXABI_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
   if(LIBCXXABI_LIBDIR_SUBDIR

[Lldb-commits] [lldb] [lldb] Fix TestGdbRemoteForkNonStop.py test (PR #131293)

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


@@ -743,6 +743,20 @@ def getBuildArtifact(self, name="a.out"):
 """Return absolute path to an artifact in the test's build 
directory."""
 return os.path.join(self.getBuildDir(), name)
 
+def get_process_working_directory(self):
+"""Get the working directory that should be used when launching 
processes for local or remote processes."""
+if lldb.remote_platform:
+# Remote tests set the platform working directory up in
+# TestBase.setUp()

labath wrote:

```suggestion
# Base.setUp()
```

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


[Lldb-commits] [lldb] [lldb] Fix TestGdbRemoteForkNonStop.py test (PR #131293)

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


@@ -743,6 +743,20 @@ def getBuildArtifact(self, name="a.out"):
 """Return absolute path to an artifact in the test's build 
directory."""
 return os.path.join(self.getBuildDir(), name)
 
+def get_process_working_directory(self):
+"""Get the working directory that should be used when launching 
processes for local or remote processes."""
+if lldb.remote_platform:
+# Remote tests set the platform working directory up in
+# TestBase.setUp()
+return lldb.remote_platform.GetWorkingDirectory()
+else:
+# local tests change directory into each test subdirectory
+return self.getBuildDir()
+
+def getWorkingDirArtifact(self, name="a.out"):
+"""Return absolute path to an artifact in the test's working 
directory."""
+return os.path.join(self.get_process_working_directory(), name)

labath wrote:

for this we have `lldbutil.append_to_process_working_directory`.

I actually like your api more, so I wouldn't be opposed to using this instead. 
However I don't think we should have two methods for the same thing, so if you 
want to go down that path, you should also port the other usages of 
`append_to_process_working_directory` to this.

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


[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)

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


@@ -5,11 +5,11 @@
 # RUN: rm -rf %t.existing
 # RUN: mkdir -p %t.existing
 # RUN: %lldb -o 'diagnostics dump -d %t.existing'
-# RUN: file %t.existing | FileCheck %s
+# RUN: test -d %t.existing && echo "directory" | FileCheck %s

labath wrote:

I don't think you actually need this as the test should fail if `test` returns 
nonzero (you can try it out my testing for a different directory name).

```suggestion
# RUN: test -d %t.existing
```

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


[Lldb-commits] [lldb] [lldb/platform-gdb] Do not assume a persistent connection (PR #131736)

2025-03-18 Thread Igor Kudrin via lldb-commits

https://github.com/igorkudrin created 
https://github.com/llvm/llvm-project/pull/131736

After https://reviews.llvm.org/D116539, when `m_gdb_client_up` in 
`PlatformRemoteGDBServer` is not null, the connection to a server is expected 
to exist. However, `PlatformRemoteGDBServer::DisconnectRemote()` is not the 
only way to close the connection;
`GDBRemoteCommunication::WaitForPacketNoLock()` can disconnect if the server 
stops responding, and in this case `m_gdb_client_up` is not cleared. The patch 
removes this assumption and checks the connection status directly.

>From 3de79119222a87709709934702d1de51ab805994 Mon Sep 17 00:00:00 2001
From: Igor Kudrin 
Date: Mon, 17 Mar 2025 23:02:07 -0700
Subject: [PATCH] [lldb/platform-gdb] Avoid an assertion failure when the
 connection is severed

After https://reviews.llvm.org/D116539, when `m_gdb_client_up` in
`PlatformRemoteGDBServer` is not null, the connection to a server is
expected to exist. However, `PlatformRemoteGDBServer::DisconnectRemote()`
is not the only way to close the connection;
`GDBRemoteCommunication::WaitForPacketNoLock()` can disconnect if the
server stops responding, and in this case `m_gdb_client_up` is not
cleared. The patch removes this assumption and checks the connection
status directly.
---
 .../gdb-server/PlatformRemoteGDBServer.cpp|  6 +-
 lldb/unittests/Platform/CMakeLists.txt|  1 +
 .../Platform/gdb-server/CMakeLists.txt|  7 ++
 .../PlatformRemoteGDBServerTest.cpp   | 68 +++
 4 files changed, 77 insertions(+), 5 deletions(-)
 create mode 100644 lldb/unittests/Platform/gdb-server/CMakeLists.txt
 create mode 100644 
lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp

diff --git 
a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp 
b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 58d2ecd94836d..26ca6ed128972 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -206,11 +206,7 @@ bool PlatformRemoteGDBServer::SetRemoteWorkingDirectory(
 }
 
 bool PlatformRemoteGDBServer::IsConnected() const {
-  if (m_gdb_client_up) {
-assert(m_gdb_client_up->IsConnected());
-return true;
-  }
-  return false;
+  return m_gdb_client_up && m_gdb_client_up->IsConnected();
 }
 
 Status PlatformRemoteGDBServer::ConnectRemote(Args &args) {
diff --git a/lldb/unittests/Platform/CMakeLists.txt 
b/lldb/unittests/Platform/CMakeLists.txt
index 963975602d671..5c0ef5ca6ef22 100644
--- a/lldb/unittests/Platform/CMakeLists.txt
+++ b/lldb/unittests/Platform/CMakeLists.txt
@@ -15,3 +15,4 @@ add_lldb_unittest(LLDBPlatformTests
   )
 
 add_subdirectory(Android)
+add_subdirectory(gdb-server)
diff --git a/lldb/unittests/Platform/gdb-server/CMakeLists.txt 
b/lldb/unittests/Platform/gdb-server/CMakeLists.txt
new file mode 100644
index 0..41f94b06f6f2c
--- /dev/null
+++ b/lldb/unittests/Platform/gdb-server/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_lldb_unittest(PlatformGdbRemoteTests
+  PlatformRemoteGDBServerTest.cpp
+
+  LINK_LIBS
+lldbPluginPlatformGDB
+LLVMTestingSupport
+  )
diff --git a/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp 
b/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp
new file mode 100644
index 0..2ea4dac006cd8
--- /dev/null
+++ b/lldb/unittests/Platform/gdb-server/PlatformRemoteGDBServerTest.cpp
@@ -0,0 +1,68 @@
+//===-- PlatformRemoteGDBServerTest.cpp 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
+#include "lldb/Utility/Connection.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_gdb_server;
+using namespace lldb_private::process_gdb_remote;
+using namespace testing;
+
+namespace {
+
+class PlatformRemoteGDBServerHack : public PlatformRemoteGDBServer {
+public:
+  void
+  SetGDBClient(std::unique_ptr gdb_client_up) {
+m_gdb_client_up = std::move(gdb_client_up);
+  }
+};
+
+class MockConnection : public lldb_private::Connection {
+public:
+  MOCK_METHOD(lldb::ConnectionStatus, Connect,
+  (llvm::StringRef url, Status *error_ptr), (override));
+  MOCK_METHOD(lldb::ConnectionStatus, Disconnect, (Status * error_ptr),
+  (override));
+  MOCK_METHOD(bool, IsConnected, (), (const, override));
+  MOCK_METHOD(size_t, Read,
+  (void *dst, size_t dst_len, const Timeout &timeout,
+   lldb::ConnectionStatus &status, Status *error_ptr),
+  (override));
+  MOCK_METHOD(size_t, Write,
+  (const 

[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

2025-03-18 Thread Robert O'Callahan via lldb-commits

rocallahan wrote:

On Linux ARM64 both gdb and lldb seem to adjust the hardware behavior so that 
single-stepping an instruction that fires a watchpoint leaves the PC pointing 
to the next instruction.

Maybe this is not true on Mac? I can't test that myself.

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


[Lldb-commits] [lldb] [LLDB] Fix tests on Windows (PR #131600)

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


@@ -201,8 +201,15 @@ def test_watch_address_with_invalid_watch_size(self):
 value.GetValueAsUnsigned(), 365, wp_opts, error
 )
 self.assertFalse(watchpoint)
-self.expect(
-error.GetCString(),
-exe=False,
-substrs=["Setting one of the watchpoint resources failed"],
-)
+if self.getPlatform() == "windows":

labath wrote:

I suspect this depends on whether you're using the lldb-server implementation 
(optional on windows, and the only option elsewhere) or the in process 
implementation (the default on windows when running locally). Maybe just make 
it accept both (with a regex) and add a comment.

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

2025-03-18 Thread Robert O'Callahan via lldb-commits

rocallahan wrote:

These are the test log packets between the reverse-exec proxy to the 
debugserver for the forward singlestep operation:
```
2025-03-17 15:49:10,842 INFO Sending packet vCont;s:4870aa
2025-03-17 15:49:10,843 INFO Received reply 
T05thread:4870aa;threads:4870aa;thread-pcs:100e0ff94;00:0100;01:1037ff6e0100;02:2037ff6e0100;03:b037ff6e0100;04:7e810100;05:d87b80db0100;06:636570745f746162;07:a006;08:0200;09:b834ff6e0100;0a:3e196aff;0b:c002;0c:0080;0d:0010;0e:0400;0f:0080;10:e034ff6e0100;11:e034ff6e0100;12:;13:401c22010100;14:34ffe100;15:e034ff6e0100;16:101922010100;17:6035ff6e0100;18:a035ff6e0100;19:bb8553810100;1a:;1b:;1c:;1d:c034ff6e0100;1e:68ffe100;1f:b034ff6e0100;20:94ffe100;21:00100080;a1:;a2:22cb;a3:;metype:6;mecount:2;medata:1;medata:0;memory:0x16eff34c0=f036ff6e0100e0904b810100;memory:0x16eff36f0=008045ff;
```
That reports metype:6, i.e. EXC_BREAKPOINT. I'm not sure if that is the right 
code for a watchpoint firing on this system. Whether it is or not, LLDB is 
definitely interpreting this as "instruction step into" and is not reporting to 
the user that a watchpoint fired. The proxy code should not be modifying this T 
packet so it would be surprising if the reverse-exec test code is causing this 
problem.
So I wonder whether, in normal operation on the test system, singlestepping an 
instruction which triggers a watchpoint actually reports the watchpoint being 
hit.

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


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

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


@@ -0,0 +1,147 @@
+//===-- WriteMemoryRequestHandler.cpp
+//--===//

JDevlieghere wrote:

```suggestion
//===-- WriteMemoryRequestHandler.cpp -===//
```

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-18 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,147 @@
+//===-- 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 "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.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;
+  llvm::json::Array response_writeMemory;
+  llvm::json::Object body;
+  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("");
+
+  std::string output;
+  lldb::SBError writeError;
+  int64_t countWrite = 0;
+
+  output = llvm::encodeBase64(data64);

JDevlieghere wrote:

```suggestion
  std::string output = llvm::encodeBase64(data64);
```

https://github.com/llvm/llvm-project/pull/131820
___
lldb-comm

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

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


@@ -0,0 +1,147 @@
+//===-- 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 "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.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;
+  llvm::json::Array response_writeMemory;
+  llvm::json::Object body;
+  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("");
+
+  std::string output;
+  lldb::SBError writeError;
+  int64_t countWrite = 0;

JDevlieghere wrote:

Let's go with `bytes_written` to match the name of the field in the response. 
Also, this should be an unsigned presumably? 
```suggestion
  uint64_t bytes_written = 0;
```

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

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

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

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

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

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

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

[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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

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

>From 6bb322fd3ed0df56adcb2bc4687f89ee7f4cdf5f Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Thu, 27 Feb 2025 15:17:15 -0800
Subject: [PATCH] [lldb-dap] Adding support for cancelling a request.

Adding support for cancelling requests.

There are two forms of request cancellation.

* Preemptively cancelling a request that is in the queue.
* Actively cancelling the in progress request as a best effort attempt using 
`SBDebugger.RequestInterrupt()`.
---
 .../test/tools/lldb-dap/dap_server.py |  12 +-
 lldb/test/API/tools/lldb-dap/cancel/Makefile  |   3 +
 .../tools/lldb-dap/cancel/TestDAP_cancel.py   |  92 +
 lldb/test/API/tools/lldb-dap/cancel/main.c|   6 +
 .../tools/lldb-dap/launch/TestDAP_launch.py   |   1 +
 lldb/tools/lldb-dap/CMakeLists.txt|   1 +
 lldb/tools/lldb-dap/DAP.cpp   | 126 --
 lldb/tools/lldb-dap/DAP.h |   3 +
 .../lldb-dap/Handler/CancelRequestHandler.cpp |  56 
 .../Handler/InitializeRequestHandler.cpp  |   2 +
 lldb/tools/lldb-dap/Handler/RequestHandler.h  |  10 ++
 .../lldb-dap/Protocol/ProtocolRequests.cpp|   7 +
 .../lldb-dap/Protocol/ProtocolRequests.h  |  20 +++
 lldb/tools/lldb-dap/Transport.cpp |  37 +++--
 lldb/tools/lldb-dap/Transport.h   |   3 +-
 lldb/tools/lldb-dap/lldb-dap.cpp  |   5 +-
 16 files changed, 360 insertions(+), 24 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/cancel/Makefile
 create mode 100644 lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
 create mode 100644 lldb/test/API/tools/lldb-dap/cancel/main.c
 create mode 100644 lldb/tools/lldb-dap/Handler/CancelRequestHandler.cpp

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 0fea3419d9725..a9a47e281e829 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -88,13 +88,13 @@ def packet_type_is(packet, packet_type):
 
 
 def dump_dap_log(log_file):
-print("= DEBUG ADAPTER PROTOCOL LOGS =")
+print("= DEBUG ADAPTER PROTOCOL LOGS =", file=sys.stderr)
 if log_file is None:
-print("no log file available")
+print("no log file available", file=sys.stderr)
 else:
 with open(log_file, "r") as file:
-print(file.read())
-print("= END =")
+print(file.read(), file=sys.stderr)
+print("= END =", file=sys.stderr)
 
 
 def read_packet_thread(vs_comm, log_file):
@@ -107,6 +107,10 @@ def read_packet_thread(vs_comm, log_file):
 # termination of lldb-dap and stop waiting for new packets.
 done = not vs_comm.handle_recv_packet(packet)
 finally:
+# Wait for the process to fully exit before dumping the log file to
+# ensure we have the entire log contents.
+if vs_comm.process is not None:
+vs_comm.process.wait()
 dump_dap_log(log_file)
 
 
diff --git a/lldb/test/API/tools/lldb-dap/cancel/Makefile 
b/lldb/test/API/tools/lldb-dap/cancel/Makefile
new file mode 100644
index 0..10495940055b6
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/cancel/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py 
b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
new file mode 100644
index 0..d6e964fad3ddd
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/cancel/TestDAP_cancel.py
@@ -0,0 +1,92 @@
+"""
+Test lldb-dap cancel request
+"""
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbdap_testcase
+
+
+class TestDAP_launch(lldbdap_testcase.DAPTestCaseBase):
+def send_async_req(self, command: str, arguments={}) -> int:
+seq = self.dap_server.sequence
+self.dap_server.send_packet(
+{
+"type": "request",
+"command": command,
+"arguments": arguments,
+}
+)
+return seq
+
+def async_blocking_request(self, duration: float) -> int:
+"""
+Sends an evaluate request that will sleep for the specified duration to
+block the request handling thread.
+"""
+return self.send_async_req(
+command="evaluate",
+arguments={
+"expression": "`script import time; 
time.sleep({})".format(duration),
+"context": "repl",
+},
+)
+
+def async_cancel(self, requestId: int) -> int:
+return self.send_async_req(command="cancel", arguments={"requestId": 
requestId})
+
+def test_pending_request(self):
+"""
+Tests cancelling a pendin

[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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


@@ -67,7 +67,7 @@ static Status ReadExpected(IOObjectSP &descriptor, 
llvm::StringRef expected) {
   if (status.Fail())
 return status;
   if (expected != result) {
-return Status::FromErrorStringWithFormatv("expected %s, got %s", expected,
+return Status::FromErrorStringWithFormatv("expected {0}, got {1}", 
expected,
   result);

ashgti wrote:

Done.

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


[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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


@@ -348,6 +351,71 @@ llvm::json::Value toJSON(const ExitedEventBody &);
 
 // MARK: Requests
 
+// "CancelRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "The `cancel` request is used by the client in two
+// situations:\n- to indicate that it is no longer interested in the result
+// produced by a specific request issued earlier\n- to cancel a progress
+// sequence.\nClients should only call this request if the corresponding
+// capability `supportsCancelRequest` is true.\nThis request has a hint
+// characteristic: a debug adapter can only be expected to make a 'best
+// effort' in honoring this request but there are no guarantees.\nThe
+// `cancel` request may return an error if it could not cancel an operation
+// but a client should refrain from presenting this error to end 
users.\nThe
+// request that got cancelled still needs to send a response back. This can
+// either be a normal result (`success` attribute true) or an error 
response
+// (`success` attribute false and the `message` set to
+// `cancelled`).\nReturning partial results from a cancelled request is
+// possible but please note that a client has no generic way for detecting
+// that a response is partial or not.\nThe progress that got cancelled 
still
+// needs to send a `progressEnd` event back.\n A client should not assume
+// that progress just got cancelled after sending the `cancel` request.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "cancel" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/CancelArguments"
+//   }
+// },
+// "required": [ "command" ]
+//   }]
+// },
+// "CancelArguments": {
+//   "type": "object",
+//   "description": "Arguments for `cancel` request.",
+//   "properties": {
+// "requestId": {
+//   "type": "integer",
+//   "description": "The ID (attribute `seq`) of the request to cancel. If
+//   missing no request is cancelled.\nBoth a `requestId` and a 
`progressId`
+//   can be specified in one request."
+// },
+// "progressId": {
+//   "type": "string",
+//   "description": "The ID (attribute `progressId`) of the progress to
+//   cancel. If missing no progress is cancelled.\nBoth a `requestId` and a
+//   `progressId` can be specified in one request."
+// }
+//   }
+// },
+struct CancelArguments {
+  std::optional requestId;
+  std::optional progressId;
+};
+bool fromJSON(const llvm::json::Value &, CancelArguments &, llvm::json::Path);
+
+// "CancelResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `cancel` request. This is just an
+// acknowledgement, so no body field is required."
+//   }]
+// },
+using CancelResponseBody = VoidResponseBody;

ashgti wrote:

This was handled in an upstream patch.

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


[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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


@@ -152,6 +153,8 @@ struct Response {
 bool fromJSON(const llvm::json::Value &, Response &, llvm::json::Path);
 llvm::json::Value toJSON(const Response &);
 
+using VoidResponseBody = std::nullptr_t;

ashgti wrote:

Done.

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


[Lldb-commits] [lldb] [lldb-dap] Adding support for cancelling a request. (PR #130169)

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


@@ -0,0 +1,56 @@
+//===-- SourceRequestHandler.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 "Protocol.h"
+#include "RequestHandler.h"
+#include "llvm/Support/Error.h"
+
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+namespace lldb_dap {
+
+// "CancelRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "The `cancel` request is used by the client in two
+// situations:\n- to indicate that it is no longer interested in the result
+// produced by a specific request issued earlier\n- to cancel a progress
+// sequence.\nClients should only call this request if the corresponding
+// capability `supportsCancelRequest` is true.\nThis request has a hint
+// characteristic: a debug adapter can only be expected to make a 'best
+// effort' in honoring this request but there are no guarantees.\nThe
+// `cancel` request may return an error if it could not cancel an operation
+// but a client should refrain from presenting this error to end 
users.\nThe
+// request that got cancelled still needs to send a response back. This can
+// either be a normal result (`success` attribute true) or an error 
response
+// (`success` attribute false and the `message` set to
+// `cancelled`).\nReturning partial results from a cancelled request is
+// possible but please note that a client has no generic way for detecting
+// that a response is partial or not.\nThe progress that got cancelled 
still
+// needs to send a `progressEnd` event back.\n A client should not assume
+// that progress just got cancelled after sending the `cancel` request.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "cancel" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/CancelArguments"
+//   }
+// },
+// "required": [ "command" ]
+//   }]
+// },
+llvm::Expected
+CancelRequestHandler::Run(const CancelArguments &arguments) const {
+  /* no-op, simple ack of the request. */

ashgti wrote:

I updated the comment to explain that this is handled in the DAP::Loop instead.

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


[Lldb-commits] [lldb] [lldb] Support ordered patterns in lldbtest.expect (PR #131475)

2025-03-18 Thread Dave Lee via lldb-commits

kastiglione wrote:

@luporl I have a fix, I'll share the link soon.

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


[Lldb-commits] [lldb] [lldb-dap] Ensure logging statements are written as a single chunk. (PR #131916)

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


@@ -9,44 +9,66 @@
 #ifndef LLDB_TOOLS_LLDB_DAP_DAPLOG_H
 #define LLDB_TOOLS_LLDB_DAP_DAPLOG_H
 
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/FormatVariadic.h"
 #include 
 #include 
+#include 
 #include 
 
 // Write a message to log, if logging is enabled.
 #define DAP_LOG(log, ...)  
\
   do { 
\
-::std::ofstream *log_private = (log);  
\
+::lldb_dap::Log *log_private = (log);  
\
 if (log_private) { 
\
   ::std::chrono::duration now{ 
\
   ::std::chrono::system_clock::now().time_since_epoch()};  
\
-  *log_private << ::llvm::formatv("{0:f9} ", now.count()).str()
\
-   << ::llvm::formatv(__VA_ARGS__).str() << std::endl; 
\
+  ::std::string out;   
\
+  ::llvm::raw_string_ostream os(out);  
\
+  os << ::llvm::formatv("{0:f9} ", now.count()).str()  
\
+ << ::llvm::formatv(__VA_ARGS__).str() << "\n";
\
+  log_private->WriteMessage(out);  
\
 }  
\
   } while (0)
 
 // Write message to log, if error is set. In the log message refer to the error
 // with {0}. Error is cleared regardless of whether logging is enabled.
 #define DAP_LOG_ERROR(log, error, ...) 
\
   do { 
\
-::std::ofstream *log_private = (log);  
\
+::lldb_dap::Log *log_private = (log);  
\
 ::llvm::Error error_private = (error); 
\
 if (log_private && error_private) {
\
   ::std::chrono::duration now{ 
\
   std::chrono::system_clock::now().time_since_epoch()};
\
-  *log_private << ::llvm::formatv("{0:f9} ", now.count()).str()
\
-   << ::lldb_dap::FormatError(::std::move(error_private),  
\
-  __VA_ARGS__) 
\
-   << std::endl;   
\
+  ::std::string out;   
\
+  ::llvm::raw_string_ostream os(out);  
\
+  os << ::llvm::formatv("{0:f9} ", now.count()).str()  
\
+ << ::lldb_dap::FormatError(::std::move(error_private), __VA_ARGS__)   
\
+ << "\n";  
\
+  log_private->WriteMessage(out);  
\

JDevlieghere wrote:

I'd move all this out of the macro and into `Log::WriteMessage`.

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


[Lldb-commits] [lldb] 4088557 - [lldb-dap] Move request capabilities into request handlers (NFC) (#131943)

2025-03-18 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-03-18T19:56:04-07:00
New Revision: 40885572783b1b1d3fe5dc7bce119f08728dc11f

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

LOG: [lldb-dap] Move request capabilities into request handlers (NFC) (#131943)

This distributes the registration of request related capabilities to the
corresponding request handler. Global and unsupported capabilities are
registered at the DAP level.

Added: 


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

Removed: 




diff  --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index a1e2187288768..cab33c640b684 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;
+
+  // Unsupported capabilities.
+  capabilities["supportsGotoTargetsRequest"] = false;
+  capabilities["supportsLoadedSourcesRequest"] = false;
+  capabilities["supportsRestartFrame"] = false;
+  capabilities["supportsStepBack"] = false;
+
+  // Capabilities associated with specific requests.
+  for (auto &kv : request_handlers) {
+for (auto &request_kv : kv.second->GetCapabilities())
+  capabilities[request_kv.getKey()] = request_kv.getValue();
+  }
+
+  return capabilities;
+}
+
 } // namespace lldb_dap

diff  --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 4c57f9fef3d89..9a823c2d04fe7 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -364,6 +364,9 @@ struct DAP {
 request_handlers[Handler::getCommand()] = std::make_unique(*this);
   }
 
+  /// Return a key-value list of capabilities.
+  llvm::StringMap GetCapabilities();
+
   /// Debuggee will continue from stopped state.
   void WillContinue() { variables.Clear(); }
 

diff  --git a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
index 3262b70042a0e..a8fe0d6ffce8b 100644
--- a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
@@ -377,49 +377,15 @@ void InitializeRequestHandler::operator()(
   // process and more.
   dap.event_thread = std::thread(EventThreadFunction, std::ref(dap));
 
-  // The debug adapter supports the configurationDoneRequest.
-  body.try_emplace("supportsConfigurationDoneRequest", true);
-  // The debug adapter supports function breakpoints.
-  body.try_emplace("supportsFunctionBreakpoints", true);
-  // The debug adapter supports conditional breakpoints.
-  body.try_emplace("supportsConditionalBreakpoints", true);
-  // The debug adapter supports breakpoints that break execution after a
-  // specified number of hits.
-  body.try_emplace("supportsHitConditionalBreakpoints", true);
-  // The debug adapter supports a (side effect free) evaluate request for
-  // data hovers.
-  body.try_emplace("supportsEvaluateForHovers", true);
+  llvm::StringMap capabilities = dap.GetCapabilities();
+  for (auto &kv : capabilities)
+body.try_emplace(kv.getKey(), kv.getValue());
+
   // Available filters or options for the setExceptionBreakpoints request.
   llvm::json::Array filters;
-  for (const auto &exc_bp : *dap.exception_breakpoints) {
+  for (const auto &exc_bp : *dap.exception_breakpoints)
 filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
-  }
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
-  // The debug adapter supports launching a debugee in intergrated VSCode
-  // terminal.
-  body.try_emplace("supportsRunInTerminalRequest", true);
-  // The debug adapter supports stepping back via the stepBack and
-  // reverseContinue requests.
-  body.try_emplace("supportsStepBack", false);
-  // The debug adapter supports setting a variable to a value.
-  body.try_emplace("supportsSetVariable", true);
-  // The debug adapter supports restarting a frame.
-  body.try_emplace("supportsRestartFrame", false);
-  // The debug adapter supports the gotoTargetsRequest.
-  body.try_emplace("supportsGotoTargetsReq

[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

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

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


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

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

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


[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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

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


[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

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

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

>From c9770d124155beabcb133e47a5d798d22bcb7de2 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 18 Mar 2025 17:47:26 -0700
Subject: [PATCH 1/2] [lldb-dap] Move request capabilities into request
 handlers (NFC)

This distributes the registration of request related capabilities to the
corresponding request handler. Global and unsupported capabilities are
registered at the DAP level.
---
 lldb/tools/lldb-dap/DAP.cpp   | 29 +++
 lldb/tools/lldb-dap/DAP.h |  3 +
 .../Handler/InitializeRequestHandler.cpp  | 81 ++-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 42 ++
 4 files changed, 80 insertions(+), 75 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index a1e2187288768..cab33c640b684 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;
+
+  // Unsupported capabilities.
+  capabilities["supportsGotoTargetsRequest"] = false;
+  capabilities["supportsLoadedSourcesRequest"] = false;
+  capabilities["supportsRestartFrame"] = false;
+  capabilities["supportsStepBack"] = false;
+
+  // Capabilities associated with specific requests.
+  for (auto &kv : request_handlers) {
+for (auto &request_kv : kv.second->GetCapabilities())
+  capabilities[request_kv.getKey()] = request_kv.getValue();
+  }
+
+  return capabilities;
+}
+
 } // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 4c57f9fef3d89..9a823c2d04fe7 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -364,6 +364,9 @@ struct DAP {
 request_handlers[Handler::getCommand()] = std::make_unique(*this);
   }
 
+  /// Return a key-value list of capabilities.
+  llvm::StringMap GetCapabilities();
+
   /// Debuggee will continue from stopped state.
   void WillContinue() { variables.Clear(); }
 
diff --git a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
index 3262b70042a0e..64002945f94d5 100644
--- a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
@@ -13,6 +13,7 @@
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBStream.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace lldb;
 
@@ -377,49 +378,15 @@ void InitializeRequestHandler::operator()(
   // process and more.
   dap.event_thread = std::thread(EventThreadFunction, std::ref(dap));
 
-  // The debug adapter supports the configurationDoneRequest.
-  body.try_emplace("supportsConfigurationDoneRequest", true);
-  // The debug adapter supports function breakpoints.
-  body.try_emplace("supportsFunctionBreakpoints", true);
-  // The debug adapter supports conditional breakpoints.
-  body.try_emplace("supportsConditionalBreakpoints", true);
-  // The debug adapter supports breakpoints that break execution after a
-  // specified number of hits.
-  body.try_emplace("supportsHitConditionalBreakpoints", true);
-  // The debug adapter supports a (side effect free) evaluate request for
-  // data hovers.
-  body.try_emplace("supportsEvaluateForHovers", true);
+  llvm::StringMap capabilities = dap.GetCapabilities();
+  for (auto &kv : capabilities)
+body.try_emplace(kv.getKey(), kv.getValue());
+
   // Available filters or options for the setExceptionBreakpoints request.
   llvm::json::Array filters;
-  for (const auto &exc_bp : *dap.exception_breakpoints) {
+  for (const auto &exc_bp : *dap.exception_breakpoints)
 filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
-  }
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
-  // The debug adapter supports launching a debugee in intergrated VSCode
-  // terminal.
-  body.try_emplace("supportsRunInTerminalRequest", true);
-  // The debug adapter supports stepping back via the stepBack and
-  // reverseContinue requests.
-  body.try_emplace("supportsStepBack", false);
-  // The debug adapter supports setting a variable to a value.
-  body.try_emplace("supportsSetVariable", true);
-  // The debug adapter supports restarting a frame.
-  body.try_emplace("supportsRestartF

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

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

oontvoo wrote:

Thanks!

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


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

2025-03-18 Thread via lldb-commits

Author: Vy Nguyen
Date: 2025-03-18T22:54:08-04:00
New Revision: 04e39ce3fddaaec41d9c7babcca55133d7e49969

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

LOG: [LLDB][Telemetry]Define TargetInfo for collecting data about a target 
(#127834)

Co-authored-by: Pavel Labath 

Added: 


Modified: 
lldb/include/lldb/Core/Telemetry.h
lldb/source/Core/Telemetry.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/Target.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index 29ec36b2d64d1..28897f283dc55 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -23,9 +23,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 namespace lldb_private {
 namespace telemetry {
@@ -46,12 +49,18 @@ struct LLDBConfig : public ::llvm::telemetry::Config {
 // Specifically:
 //  - Length: 8 bits
 //  - First two bits (MSB) must be 11 - the common prefix
+//  - Last two bits (LSB) are reserved for grand-children of LLDBTelemetryInfo
 // If any of the subclass has descendents, those descendents
-// must have their LLDBEntryKind in the similar form (ie., share common prefix)
+// must have their LLDBEntryKind in the similar form (ie., share common prefix
+// and 
diff er by the last two bits)
 struct LLDBEntryKind : public ::llvm::telemetry::EntryKind {
-  static const llvm::telemetry::KindType BaseInfo = 0b1100;
-  static const llvm::telemetry::KindType CommandInfo = 0b1101;
-  static const llvm::telemetry::KindType DebuggerInfo = 0b11000100;
+  // clang-format off
+  static const llvm::telemetry::KindType BaseInfo= 0b1100;
+  static const llvm::telemetry::KindType CommandInfo = 0b1101;
+  static const llvm::telemetry::KindType DebuggerInfo= 0b11001000;
+  static const llvm::telemetry::KindType ExecModuleInfo  = 0b11000100;
+  static const llvm::telemetry::KindType ProcessExitInfo = 0b11001100;
+  // clang-format on
 };
 
 /// Defines a convenient type for timestamp of various events.
@@ -89,7 +98,7 @@ struct CommandInfo : public LLDBBaseTelemetryInfo {
   /// session. Necessary because we'd send off an entry right before a 
command's
   /// execution and another right after. This is to avoid losing telemetry if
   /// the command does not execute successfully.
-  uint64_t command_id;
+  uint64_t command_id = 0;
   /// The command name(eg., "breakpoint set")
   std::string command_name;
   /// These two fields are not collected by default due to PII risks.
@@ -116,7 +125,7 @@ struct CommandInfo : public LLDBBaseTelemetryInfo {
 
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 
-  static uint64_t GetNextId();
+  static uint64_t GetNextID();
 
 private:
   // We assign each command (in the same session) a unique id so that their
@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecutableModuleInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+  /// The same as the executable-module's UUID.
+  UUID uuid;
+  /// PID of the process owned by this target.
+  lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  /// The triple of this executable module.
+  std::string triple;
+
+  /// If true, this entry was emitted at the beginning of an event (eg., before
+  /// the executable is set). Otherwise, it was emitted at the end of an
+  /// event (eg., after the module and any dependency were loaded.)
+  bool is_start_entry = false;
+
+  ExecutableModuleInfo() = default;
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::ExecModuleInfo;
+  }
+
+  static bool classof(const TelemetryInfo *T) {
+// Subclasses of this is also acceptable
+return (T->getKind() & LLDBEntryKind::ExecModuleInfo) ==
+   LLDBEntryKind::ExecModuleInfo;
+  }
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct ProcessExitInfo : public LLDBBaseTelemetryInfo {
+  // The executable-module's UUID.
+  UUID module_uuid;
+  lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  bool is_start_entry = false;
+  std::optional exit_desc;
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::ProcessExitInfo;
+  }
+
+  static bool classof(const TelemetryInfo *T) {
+// Subclasses of this is also acceptable
+return (T->getKind() & LLDBEntryKind::ProcessExitInfo) ==
+   LLDBEntryKind::ProcessExitInfo;
+  }
+  void serialize(llvm::telemetry::Serial

[Lldb-commits] [libcxxabi] [lldb] [llvm] [WIP: DO NOT MERGE] [lldb][Format] Add option to highlight function names in backtraces (PR #131836)

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

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/131836

>From 03a4172a3a4dae7d1ed45570fff66a89e792ca71 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 11 Mar 2025 08:57:13 +
Subject: [PATCH 1/4] [llvm][ItaniumDemangle] Add function name location
 tracking

---
 libcxxabi/src/demangle/ItaniumDemangle.h  |  20 +++
 libcxxabi/src/demangle/Utility.h  | 163 --
 llvm/include/llvm/Demangle/ItaniumDemangle.h  |  20 +++
 llvm/include/llvm/Demangle/Utility.h  | 163 --
 .../Demangle/ItaniumDemangleTest.cpp  | 105 +++
 5 files changed, 439 insertions(+), 32 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h 
b/libcxxabi/src/demangle/ItaniumDemangle.h
index 3df41b5f4d7d0..d3cd1e4a405a6 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -851,11 +851,13 @@ class FunctionType final : public Node {
   // by printing out the return types's left, then print our parameters, then
   // finally print right of the return type.
   void printLeft(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
 Ret->printLeft(OB);
 OB += " ";
   }
 
   void printRight(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
 OB.printOpen();
 Params.printWithComma(OB);
 OB.printClose();
@@ -976,13 +978,26 @@ class FunctionEncoding final : public Node {
   if (!Ret->hasRHSComponent(OB))
 OB += " ";
 }
+
+// Nested FunctionEncoding parsing can happen with following productions:
+// * 
+// * 
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
+OB.FunctionInfo.updateScopeStart(OB);
+
 Name->print(OB);
   }
 
   void printRight(OutputBuffer &OB) const override {
+auto Scoped = OB.FunctionInfo.enterFunctionTypePrinting(OB);
+OB.FunctionInfo.finalizeStart(OB);
+
 OB.printOpen();
 Params.printWithComma(OB);
 OB.printClose();
+
+OB.FunctionInfo.finalizeArgumentEnd(OB);
+
 if (Ret)
   Ret->printRight(OB);
 
@@ -1005,6 +1020,8 @@ class FunctionEncoding final : public Node {
   OB += " requires ";
   Requires->print(OB);
 }
+
+OB.FunctionInfo.finalizeEnd(OB);
   }
 };
 
@@ -1072,7 +1089,9 @@ struct NestedName : Node {
   void printLeft(OutputBuffer &OB) const override {
 Qual->print(OB);
 OB += "::";
+OB.FunctionInfo.updateScopeEnd(OB);
 Name->print(OB);
+OB.FunctionInfo.updateBasenameEnd(OB);
   }
 };
 
@@ -1633,6 +1652,7 @@ struct NameWithTemplateArgs : Node {
 
   void printLeft(OutputBuffer &OB) const override {
 Name->print(OB);
+OB.FunctionInfo.updateBasenameEnd(OB);
 TemplateArgs->print(OB);
   }
 };
diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index f1fad35d60d98..3bfdf8dff4526 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -27,6 +27,22 @@
 
 DEMANGLE_NAMESPACE_BEGIN
 
+template  class ScopedOverride {
+  T &Loc;
+  T Original;
+
+public:
+  ScopedOverride(T &Loc_) : ScopedOverride(Loc_, Loc_) {}
+
+  ScopedOverride(T &Loc_, T NewVal) : Loc(Loc_), Original(Loc_) {
+Loc_ = std::move(NewVal);
+  }
+  ~ScopedOverride() { Loc = std::move(Original); }
+
+  ScopedOverride(const ScopedOverride &) = delete;
+  ScopedOverride &operator=(const ScopedOverride &) = delete;
+};
+
 // Stream that AST nodes write their string representation into after the AST
 // has been parsed.
 class OutputBuffer {
@@ -83,6 +99,127 @@ class OutputBuffer {
 return std::string_view(Buffer, CurrentPosition);
   }
 
+  // Stores information about parts of a demangled function name.
+  struct FunctionNameInfo {
+///< A [start, end) pair for the function basename.
+///< The basename is the name without scope qualifiers
+///< and without template parameters. E.g.,
+///< \code{.cpp}
+/// 0; }
+
+bool shouldTrack(OutputBuffer &OB) const {
+  if (OB.isPrintingNestedFunctionType())
+return false;
+
+  if (OB.isGtInsideTempla

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

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


@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecModuleInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  /// The same as the executable-module's UUID.
+  UUID exec_uuid;
+  /// PID of the process owned by this target.
+  lldb::pid_t pid;
+  /// The triple of this executable module.
+  std::string triple;
+
+  /// If true, this entry was emitted at the beginning of an event (eg., before
+  /// the executable is set). Otherwise, it was emitted at the end of an
+  /// event (eg., after the module and any dependency were loaded.)
+  bool is_start_entry;
+
+  ExecModuleInfo() = default;
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::ExecModuleInfo;
+  }
+
+  static bool classof(const TelemetryInfo *T) {
+// Subclasses of this is also acceptable
+return (T->getKind() & LLDBEntryKind::ExecModuleInfo) ==
+   LLDBEntryKind::ExecModuleInfo;
+  }
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct ProcessExitInfo : public LLDBBaseTelemetryInfo {
+  UUID exec_uuid;

JDevlieghere wrote:

```suggestion
  UUID uuid;
```

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


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

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


@@ -66,6 +75,40 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct TargetInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  // The same as the executable-module's UUID.
+  std::string target_uuid;
+  std::string arch_name;
+
+  // If true, this entry was emitted at the beginning of an event (eg., before
+  // the executable laod). Otherwise, it was emitted at the end of an event
+  // (eg., after the module and any dependency were loaded.)
+  bool is_start_entry;

JDevlieghere wrote:

```suggestion
  /// If true, this entry was emitted at the beginning of an event (eg., before
  /// the executable laod). Otherwise, it was emitted at the end of an event
  /// (eg., after the module and any dependency were loaded.)
  bool is_start_entry;
```

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


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

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


@@ -1066,6 +1067,26 @@ const char *Process::GetExitDescription() {
 bool Process::SetExitStatus(int status, llvm::StringRef exit_string) {
   // Use a mutex to protect setting the exit status.
   std::lock_guard guard(m_exit_status_mutex);
+  telemetry::ScopedDispatcher helper;
+
+  // Find the executable-module's UUID, if available.
+  Target &target = GetTarget();
+  helper.SetDebugger(&(target.GetDebugger()));

JDevlieghere wrote:

```suggestion
  helper.SetDebugger(&target.GetDebugger());
```

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


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

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

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


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

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


@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecModuleInfo : public LLDBBaseTelemetryInfo {

JDevlieghere wrote:

```suggestion
struct ExecutableModuleInfo : public LLDBBaseTelemetryInfo {
```

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


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

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


@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecModuleInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  /// The same as the executable-module's UUID.
+  UUID exec_uuid;
+  /// PID of the process owned by this target.
+  lldb::pid_t pid;
+  /// The triple of this executable module.
+  std::string triple;
+
+  /// If true, this entry was emitted at the beginning of an event (eg., before

JDevlieghere wrote:

```suggestion
  /// If true, this entry was emitted at the beginning of an event (e.g. before
```

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


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

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


@@ -66,6 +75,40 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct TargetInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  // The same as the executable-module's UUID.
+  std::string target_uuid;
+  std::string arch_name;

JDevlieghere wrote:

```suggestion
  UUID target_uuid;
  ArchSpec arch_name;
```

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


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

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


@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecModuleInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  /// The same as the executable-module's UUID.
+  UUID exec_uuid;
+  /// PID of the process owned by this target.
+  lldb::pid_t pid;
+  /// The triple of this executable module.
+  std::string triple;
+
+  /// If true, this entry was emitted at the beginning of an event (eg., before
+  /// the executable is set). Otherwise, it was emitted at the end of an
+  /// event (eg., after the module and any dependency were loaded.)
+  bool is_start_entry;
+
+  ExecModuleInfo() = default;
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::ExecModuleInfo;
+  }
+
+  static bool classof(const TelemetryInfo *T) {
+// Subclasses of this is also acceptable
+return (T->getKind() & LLDBEntryKind::ExecModuleInfo) ==
+   LLDBEntryKind::ExecModuleInfo;
+  }
+  void serialize(llvm::telemetry::Serializer &serializer) const override;
+};
+
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct ProcessExitInfo : public LLDBBaseTelemetryInfo {
+  UUID exec_uuid;
+  lldb::pid_t pid;
+  bool is_start_entry;
+  std::optional exit_desc;
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::ProcessExitInfo;
+  }
+
+  static bool classof(const TelemetryInfo *T) {
+// Subclasses of this is also acceptable

JDevlieghere wrote:

```suggestion
// Subclasses of this is also acceptable.
```

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


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

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


@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecModuleInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  /// The same as the executable-module's UUID.
+  UUID exec_uuid;
+  /// PID of the process owned by this target.
+  lldb::pid_t pid;
+  /// The triple of this executable module.
+  std::string triple;
+
+  /// If true, this entry was emitted at the beginning of an event (eg., before
+  /// the executable is set). Otherwise, it was emitted at the end of an
+  /// event (eg., after the module and any dependency were loaded.)
+  bool is_start_entry;
+
+  ExecModuleInfo() = default;
+
+  llvm::telemetry::KindType getKind() const override {
+return LLDBEntryKind::ExecModuleInfo;
+  }
+
+  static bool classof(const TelemetryInfo *T) {
+// Subclasses of this is also acceptable

JDevlieghere wrote:

```suggestion
// Subclasses of this is also acceptable.
```

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


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

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


@@ -146,6 +155,59 @@ struct DebuggerInfo : public LLDBBaseTelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+struct ExecModuleInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;

JDevlieghere wrote:

Let's drop the `exec_` prefix as this is relatively obvious from the class it 
belongs to and we don't consistently prefix all the members. 
```suggestion
  lldb::ModuleSP exec_mod;
```

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


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

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


@@ -66,6 +75,40 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes an exit status.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct TargetInfo : public LLDBBaseTelemetryInfo {
+  lldb::ModuleSP exec_mod;
+
+  // The same as the executable-module's UUID.

JDevlieghere wrote:

```suggestion
  /// The same as the executable-module's UUID.
```

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


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

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

oontvoo wrote:

Hi, friendly ping? @JDevlieghere  thanks!

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


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

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


@@ -76,15 +76,36 @@ void CommandInfo::serialize(Serializer &serializer) const {
 serializer.write("error_data", error_data.value());
 }
 
+std::atomic CommandInfo::g_command_id_seed = 0;
+uint64_t CommandInfo::GetNextId() { return g_command_id_seed.fetch_add(1); }

JDevlieghere wrote:

```suggestion
uint64_t CommandInfo::GetNextID() { return g_command_id_seed.fetch_add(1); }
```

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


[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)

2025-03-18 Thread via lldb-commits

satyajanga wrote:

> Pretty good start. There can be more than one breakpoint at a location and we 
> need to be sure we test these cases. Like we can have an exception breakpoint 
> (which might be at `cxa_throw`) and we can have a function breakpoint for 
> this as well. We need to make sure we document how we are doing to display 
> this. If we must pick one, then lets be clear about:
> 
> * exception breakpoints take precedence
> * then function breakpoints
> * then source file and line breakpoints
> 
> If we have a free form text we can attach to the stop notification it might 
> be nice to see "function breakpoint & exception breakpoint", but if we have 
> to pick just one, then we need to be clear about what we are going to do.


Agree that there can be more than one breakpoint at a location. 

but 'reason' field in StoppedEvent only takes one string from fixed set of 
strings. 
>reason: 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry' | 'goto' | 
> 'function breakpoint' | 'data breakpoint' | 'instruction breakpoint' | string;
https://microsoft.github.io/debug-adapter-protocol/specification#Events_Stopped

So the existing logic for instruction_breakpoint only sets the reason as 
'instruction breakpoint' if all the breakpoints are instruction_breakpoints. 
Current behavior
1. if all the breakpoints are exception breakpoints set reason = 'exception'
2. if all the breakpoints are function breakpoints set reason = 'function 
breakpoint'
3.  if all the breakpoints are instruction breakpoints set reason = 
'instruction breakpoint'
4. if there are combination of one more breakpoints , then the reason will be 
'breakpoint' 

I think this is a reasonable behavior, I will document this in the code. 
@clayborg  let me know what you think?



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


[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)

2025-03-18 Thread Adrian Vogelsgesang via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Adding support for well typed events. (PR #130104)

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


@@ -316,6 +316,36 @@ struct Source {
 bool fromJSON(const llvm::json::Value &, Source &, llvm::json::Path);
 llvm::json::Value toJSON(const Source &);
 
+// MARK: Events
+
+// "ExitedEvent": {
+//   "allOf": [ { "$ref": "#/definitions/Event" }, {
+// "type": "object",
+// "description": "The event indicates that the debuggee has exited and
+// returns its exit code.", "properties": {
+//   "event": {
+// "type": "string",
+// "enum": [ "exited" ]
+//   },
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "exitCode": {
+// "type": "integer",
+// "description": "The exit code returned from the debuggee."
+//   }
+// },
+// "required": [ "exitCode" ]
+//   }
+// },
+// "required": [ "event", "body" ]
+//   }]
+// }
+struct ExitedEventBody {
+  int exitCode;

JDevlieghere wrote:

I agree with @vogelsgesang regarding the downside of callbacks, and I pushed 
back against introducing more callbacks in the [cancellation 
RFC](https://discourse.llvm.org/t/rfc-lldb-dap-refactoring-to-support-async-operations-and-cancellation/84739).
 That said, I haven't found a reason that these things actually **need** to be 
callbacks (event the RequestHandlers). Unless we need to register them 
dynamically, there's really no need to do this at runtime, and we can easily 
have a string-switch that dispatches to the appropriate the handler. That 
doesn't mean those handles cannot be abstracted as classes. This is something I 
was planning on pursuing at some point, but I haven't had the time to get back 
to it. 

To summarize my position: I think having an EventHandler abstraction is 
perfectly fine (and even desirable from an abstraction point of view) but I 
would encourage implementing it through a direct call instead.

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


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

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


@@ -112,3 +112,23 @@ 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()
+
+ptr_deref = self.dap_server.request_evaluate("not_a_ptr")["body"]
+memref = ptr_deref["memoryReference"]
+
+mem = self.dap_server.request_writeMemory(memref, 0, "0x11")["body"]
+self.assertEqual(mem["bytesWritten"], 8)

ashgti wrote:

Should we also read the value written to make sure it took effect?

Also, are there cases where this is expected to fail? Like writing to memory 
that is readonly.

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-18 Thread John Harrison via lldb-commits


@@ -0,0 +1,147 @@
+//===-- 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 "EventHelper.h"
+#include "JSONUtils.h"
+#include "RequestHandler.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;
+  llvm::json::Array response_writeMemory;
+  llvm::json::Object body;
+  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("");
+
+  std::string output;
+  lldb::SBError writeError;
+  int64_t countWrite = 0;
+
+  output = llvm::encodeBase64(data64);
+
+  // write the memory
+  if (!output.empty()) {

ashgti wrote:

Can you use the writeMemory request to set something to null? What would that 
look like? I suppose the value might be `0x0`?

http

[Lldb-commits] [lldb] [lldb-dap] Ensure logging statements are written as a single chunk. (PR #131916)

2025-03-18 Thread Adrian Vogelsgesang via lldb-commits


@@ -14,11 +14,11 @@
 #ifndef LLDB_TOOLS_LLDB_DAP_TRANSPORT_H
 #define LLDB_TOOLS_LLDB_DAP_TRANSPORT_H
 
+#include "DAPLog.h"

vogelsgesang wrote:

is a forward declaration sufficient?

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


[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

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


@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;

JDevlieghere wrote:

I'm sure some of these could be associated with a specific request handler. Let 
me know if anyone feels strongly about moving any of these. 

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


[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

2025-03-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

This distributes the registration of request related capabilities to the 
corresponding request handler. Global and unsupported capabilities are 
registered at the DAP level.

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


4 Files Affected:

- (modified) lldb/tools/lldb-dap/DAP.cpp (+29) 
- (modified) lldb/tools/lldb-dap/DAP.h (+3) 
- (modified) lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp (+8-75) 
- (modified) lldb/tools/lldb-dap/Handler/RequestHandler.h (+42) 


``diff
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index a1e2187288768..cab33c640b684 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;
+
+  // Unsupported capabilities.
+  capabilities["supportsGotoTargetsRequest"] = false;
+  capabilities["supportsLoadedSourcesRequest"] = false;
+  capabilities["supportsRestartFrame"] = false;
+  capabilities["supportsStepBack"] = false;
+
+  // Capabilities associated with specific requests.
+  for (auto &kv : request_handlers) {
+for (auto &request_kv : kv.second->GetCapabilities())
+  capabilities[request_kv.getKey()] = request_kv.getValue();
+  }
+
+  return capabilities;
+}
+
 } // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 4c57f9fef3d89..9a823c2d04fe7 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -364,6 +364,9 @@ struct DAP {
 request_handlers[Handler::getCommand()] = std::make_unique(*this);
   }
 
+  /// Return a key-value list of capabilities.
+  llvm::StringMap GetCapabilities();
+
   /// Debuggee will continue from stopped state.
   void WillContinue() { variables.Clear(); }
 
diff --git a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
index 3262b70042a0e..442fad52d51e0 100644
--- a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
@@ -13,6 +13,7 @@
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBStream.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace lldb;
 
@@ -377,49 +378,17 @@ void InitializeRequestHandler::operator()(
   // process and more.
   dap.event_thread = std::thread(EventThreadFunction, std::ref(dap));
 
-  // The debug adapter supports the configurationDoneRequest.
-  body.try_emplace("supportsConfigurationDoneRequest", true);
-  // The debug adapter supports function breakpoints.
-  body.try_emplace("supportsFunctionBreakpoints", true);
-  // The debug adapter supports conditional breakpoints.
-  body.try_emplace("supportsConditionalBreakpoints", true);
-  // The debug adapter supports breakpoints that break execution after a
-  // specified number of hits.
-  body.try_emplace("supportsHitConditionalBreakpoints", true);
-  // The debug adapter supports a (side effect free) evaluate request for
-  // data hovers.
-  body.try_emplace("supportsEvaluateForHovers", true);
+  llvm::StringMap capabilities = dap.GetCapabilities();
+  for (auto &kv : capabilities) {
+llvm::outs() << kv.getKey() << ": " << kv.getValue() << '\n';
+body.try_emplace(kv.getKey(), kv.getValue());
+  }
+
   // Available filters or options for the setExceptionBreakpoints request.
   llvm::json::Array filters;
-  for (const auto &exc_bp : *dap.exception_breakpoints) {
+  for (const auto &exc_bp : *dap.exception_breakpoints)
 filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
-  }
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
-  // The debug adapter supports launching a debugee in intergrated VSCode
-  // terminal.
-  body.try_emplace("supportsRunInTerminalRequest", true);
-  // The debug adapter supports stepping back via the stepBack and
-  // reverseContinue requests.
-  body.try_emplace("supportsStepBack", false);
-  // The debug adapter supports setting a variable to a value.
-  body.try_emplace("supportsSetVariable", true);
-  // The debug adapter supports restarting a frame.
-  body.try_emplace("supportsRestartFrame", false);
-  // The debug adapter supports the gotoTargetsRequest.
-  body.try_emplace("supports

[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

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

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

This distributes the registration of request related capabilities to the 
corresponding request handler. Global and unsupported capabilities are 
registered at the DAP level.

>From f2d2cf931ab65612303178c579c565270c088d96 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 18 Mar 2025 17:47:26 -0700
Subject: [PATCH] [lldb-dap] Move request capabilities into request handlers
 (NFC)

This distributes the registration of request related capabilities to the
corresponding request handler. Global and unsupported capabilities are
registered at the DAP level.
---
 lldb/tools/lldb-dap/DAP.cpp   | 29 +++
 lldb/tools/lldb-dap/DAP.h |  3 +
 .../Handler/InitializeRequestHandler.cpp  | 83 ++-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 42 ++
 4 files changed, 82 insertions(+), 75 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index a1e2187288768..cab33c640b684 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;
+
+  // Unsupported capabilities.
+  capabilities["supportsGotoTargetsRequest"] = false;
+  capabilities["supportsLoadedSourcesRequest"] = false;
+  capabilities["supportsRestartFrame"] = false;
+  capabilities["supportsStepBack"] = false;
+
+  // Capabilities associated with specific requests.
+  for (auto &kv : request_handlers) {
+for (auto &request_kv : kv.second->GetCapabilities())
+  capabilities[request_kv.getKey()] = request_kv.getValue();
+  }
+
+  return capabilities;
+}
+
 } // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 4c57f9fef3d89..9a823c2d04fe7 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -364,6 +364,9 @@ struct DAP {
 request_handlers[Handler::getCommand()] = std::make_unique(*this);
   }
 
+  /// Return a key-value list of capabilities.
+  llvm::StringMap GetCapabilities();
+
   /// Debuggee will continue from stopped state.
   void WillContinue() { variables.Clear(); }
 
diff --git a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
index 3262b70042a0e..442fad52d51e0 100644
--- a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
@@ -13,6 +13,7 @@
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBStream.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace lldb;
 
@@ -377,49 +378,17 @@ void InitializeRequestHandler::operator()(
   // process and more.
   dap.event_thread = std::thread(EventThreadFunction, std::ref(dap));
 
-  // The debug adapter supports the configurationDoneRequest.
-  body.try_emplace("supportsConfigurationDoneRequest", true);
-  // The debug adapter supports function breakpoints.
-  body.try_emplace("supportsFunctionBreakpoints", true);
-  // The debug adapter supports conditional breakpoints.
-  body.try_emplace("supportsConditionalBreakpoints", true);
-  // The debug adapter supports breakpoints that break execution after a
-  // specified number of hits.
-  body.try_emplace("supportsHitConditionalBreakpoints", true);
-  // The debug adapter supports a (side effect free) evaluate request for
-  // data hovers.
-  body.try_emplace("supportsEvaluateForHovers", true);
+  llvm::StringMap capabilities = dap.GetCapabilities();
+  for (auto &kv : capabilities) {
+llvm::outs() << kv.getKey() << ": " << kv.getValue() << '\n';
+body.try_emplace(kv.getKey(), kv.getValue());
+  }
+
   // Available filters or options for the setExceptionBreakpoints request.
   llvm::json::Array filters;
-  for (const auto &exc_bp : *dap.exception_breakpoints) {
+  for (const auto &exc_bp : *dap.exception_breakpoints)
 filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
-  }
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
-  // The debug adapter supports launching a debugee in intergrated VSCode
-  // terminal.
-  body.try_emplace("supportsRunInTerminalRequest", true);
-  // The debug adapter supports stepping back via the stepBack and
-  // reverseContinue requests.
-  bod

[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

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

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

>From c9770d124155beabcb133e47a5d798d22bcb7de2 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 18 Mar 2025 17:47:26 -0700
Subject: [PATCH] [lldb-dap] Move request capabilities into request handlers
 (NFC)

This distributes the registration of request related capabilities to the
corresponding request handler. Global and unsupported capabilities are
registered at the DAP level.
---
 lldb/tools/lldb-dap/DAP.cpp   | 29 +++
 lldb/tools/lldb-dap/DAP.h |  3 +
 .../Handler/InitializeRequestHandler.cpp  | 81 ++-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 42 ++
 4 files changed, 80 insertions(+), 75 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index a1e2187288768..cab33c640b684 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;
+
+  // Unsupported capabilities.
+  capabilities["supportsGotoTargetsRequest"] = false;
+  capabilities["supportsLoadedSourcesRequest"] = false;
+  capabilities["supportsRestartFrame"] = false;
+  capabilities["supportsStepBack"] = false;
+
+  // Capabilities associated with specific requests.
+  for (auto &kv : request_handlers) {
+for (auto &request_kv : kv.second->GetCapabilities())
+  capabilities[request_kv.getKey()] = request_kv.getValue();
+  }
+
+  return capabilities;
+}
+
 } // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 4c57f9fef3d89..9a823c2d04fe7 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -364,6 +364,9 @@ struct DAP {
 request_handlers[Handler::getCommand()] = std::make_unique(*this);
   }
 
+  /// Return a key-value list of capabilities.
+  llvm::StringMap GetCapabilities();
+
   /// Debuggee will continue from stopped state.
   void WillContinue() { variables.Clear(); }
 
diff --git a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
index 3262b70042a0e..64002945f94d5 100644
--- a/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp
@@ -13,6 +13,7 @@
 #include "lldb/API/SBEvent.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBStream.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace lldb;
 
@@ -377,49 +378,15 @@ void InitializeRequestHandler::operator()(
   // process and more.
   dap.event_thread = std::thread(EventThreadFunction, std::ref(dap));
 
-  // The debug adapter supports the configurationDoneRequest.
-  body.try_emplace("supportsConfigurationDoneRequest", true);
-  // The debug adapter supports function breakpoints.
-  body.try_emplace("supportsFunctionBreakpoints", true);
-  // The debug adapter supports conditional breakpoints.
-  body.try_emplace("supportsConditionalBreakpoints", true);
-  // The debug adapter supports breakpoints that break execution after a
-  // specified number of hits.
-  body.try_emplace("supportsHitConditionalBreakpoints", true);
-  // The debug adapter supports a (side effect free) evaluate request for
-  // data hovers.
-  body.try_emplace("supportsEvaluateForHovers", true);
+  llvm::StringMap capabilities = dap.GetCapabilities();
+  for (auto &kv : capabilities)
+body.try_emplace(kv.getKey(), kv.getValue());
+
   // Available filters or options for the setExceptionBreakpoints request.
   llvm::json::Array filters;
-  for (const auto &exc_bp : *dap.exception_breakpoints) {
+  for (const auto &exc_bp : *dap.exception_breakpoints)
 filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
-  }
   body.try_emplace("exceptionBreakpointFilters", std::move(filters));
-  // The debug adapter supports launching a debugee in intergrated VSCode
-  // terminal.
-  body.try_emplace("supportsRunInTerminalRequest", true);
-  // The debug adapter supports stepping back via the stepBack and
-  // reverseContinue requests.
-  body.try_emplace("supportsStepBack", false);
-  // The debug adapter supports setting a variable to a value.
-  body.try_emplace("supportsSetVariable", true);
-  // The debug adapter supports restarting a frame.
-  body.try_emplace("supportsRestartFrame

[Lldb-commits] [lldb] [lldb-dap] Ensure logging statements are written as a single chunk. (PR #131916)

2025-03-18 Thread Adrian Vogelsgesang via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb-dap] Move request capabilities into request handlers (NFC) (PR #131943)

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


@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t 
variablesReference,
   return variable;
 }
 
+llvm::StringMap DAP::GetCapabilities() {
+  llvm::StringMap 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;

ashgti wrote:

I think a lot of those are general enough (like LogPoints that spans all the 
breakpoint types) that it makes sense to leave them as top level capabilities.

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


  1   2   >