[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -57,235 +68,288 @@ class RequestHandler {
   DAP &dap;
 };
 
-class AttachRequestHandler : public RequestHandler {
-public:
-  using RequestHandler::RequestHandler;
+/// Base class for handling DAP requests. Handlers should declare their
+/// arguments and response body types like:
+///
+/// class MyRequestHandler : public RequestHandler {
+///   
+/// };
+template 
+class RequestHandler : public BaseRequestHandler {
+  using BaseRequestHandler::BaseRequestHandler;
+
+  void operator()(const llvm::json::Object &request) const override {
+/* no-op, the other overload handles json coding. */
+  }
+
+  void operator()(const protocol::Request &request) const override {
+protocol::Response response;
+response.request_seq = request.seq;
+response.command = request.command;
+Args arguments;
+llvm::json::Path::Root root;
+if (request.rawArguments &&
+!fromJSON(request.rawArguments, arguments, root)) {

vogelsgesang wrote:

> although all the existing request's require an argument today.

Afaict, the 
[BreakpointLocationsArguments](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_BreakpointLocations),
 
[ConfigurationDone](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_ConfigurationDone),
 
[Disconnect](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Disconnect),
 
[RestartRequest](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Restart)
 and a couple more all have an optional `arguments` parameter.

Initially, I thought we would some commands which always take arguments and 
some commands which never accept arguments. Apparently, I was wrong. Instead, 
we apparently have commands which *optionally* accept arguments, and commands 
which always expect arguments, but no commands which never accept arguments.

I think we should produce a clear error message for commands which miss their 
required arguments.
Not sure how we want to model the distinction between optional and required 
arguments? Maybe something like the following distinction?

```
/// Requires `arguments` to be provided
/// Not providing `arguments` is an error
class MyRequestHandler : public RequestHandler {

/// `arguments` are optional
class MyRequestHandler : public RequestHandler, 
ResponseBody> {
```

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -30,216 +30,170 @@ namespace lldb_dap::protocol {
 
 // MARK: Base Protocol
 
-// "Request": {
-//   "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, {
-// "type": "object",
-// "description": "A client or debug adapter initiated request.",
-// "properties": {
-//   "type": {
-// "type": "string",
-// "enum": [ "request" ]
-//   },
-//   "command": {
-// "type": "string",
-// "description": "The command to execute."
-//   },
-//   "arguments": {
-// "type": [ "array", "boolean", "integer", "null", "number" , 
"object",
-// "string" ], "description": "Object containing arguments for the
-// command."
-//   }
-// },
-// "required": [ "type", "command" ]
-//   }]
-// },
+/// A client or debug adapter initiated request.
 struct Request {
+  /// Sequence number of the message (also known as message ID). The `seq` for
+  /// the first message sent by a client or debug adapter is 1, and for each
+  /// subsequent message is 1 greater than the previous message sent by that
+  /// actor. `seq` can be used to order requests, responses, and events, and to
+  /// associate requests with their corresponding responses. For protocol
+  /// messages of type `request` the sequence number can be used to cancel the
+  /// request.
   int64_t seq;
+
+  /// The command to execute.
   std::string command;
+
+  /// Object containing arguments for the command.
   std::optional rawArguments;

ashgti wrote:

I used 'raw' as a prefix because we have the basic `json::Value` that we later 
make into the arguments type (e.g. when we convert this field into 
`SourceArguments`).

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


[Lldb-commits] [lldb] [lldb] Support discontinuous functions in another Disasembler overload (PR #130987)

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

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


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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -240,6 +240,137 @@ using Message = std::variant;
 bool fromJSON(const llvm::json::Value &, Message &, llvm::json::Path);
 llvm::json::Value toJSON(const Message &);
 
+// MARK: Types
+
+// "Source": {
+//   "type": "object",
+//   "description": "A `Source` is a descriptor for source code.\nIt is 
returned
+//   from the debug adapter as part of a `StackFrame` and it is used by clients
+//   when specifying breakpoints.", "properties": {
+// "name": {
+//   "type": "string",
+//   "description": "The short name of the source. Every source returned
+//   from the debug adapter has a name.\nWhen sending a source to the debug
+//   adapter this name is optional."
+// },
+// "path": {
+//   "type": "string",
+//   "description": "The path of the source to be shown in the UI.\nIt is
+//   only used to locate and load the content of the source if no
+//   `sourceReference` is specified (or its value is 0)."
+// },
+// "sourceReference": {
+//   "type": "integer",
+//   "description": "If the value > 0 the contents of the source must be
+//   retrieved through the `source` request (even if a path is
+//   specified).\nSince a `sourceReference` is only valid for a session, it
+//   can not be used to persist a source.\nThe value should be less than or
+//   equal to 2147483647 (2^31-1)."
+// },
+// "presentationHint": {
+//   "type": "string",
+//   "description": "A hint for how to present the source in the UI.\nA
+//   value of `deemphasize` can be used to indicate that the source is not
+//   available or that it is skipped on stepping.", "enum": [ "normal",
+//   "emphasize", "deemphasize" ]
+// },
+// "origin": {
+//   "type": "string",
+//   "description": "The origin of this source. For example, 'internal
+//   module', 'inlined content from source map', etc."
+// },
+// "sources": {
+//   "type": "array",
+//   "items": {
+// "$ref": "#/definitions/Source"
+//   },
+//   "description": "A list of sources that are related to this source.
+//   These may be the source that generated this source."
+// },
+// "adapterData": {
+//   "type": [ "array", "boolean", "integer", "null", "number", "object",
+//   "string" ], "description": "Additional data that a debug adapter might
+//   want to loop through the client.\nThe client should leave the data
+//   intact and persist it across sessions. The client should not interpret
+//   the data."
+// },
+// "checksums": {
+//   "type": "array",
+//   "items": {
+// "$ref": "#/definitions/Checksum"
+//   },
+//   "description": "The checksums associated with this file."
+// }
+//   }
+// },
+struct Source {
+  enum class PresentationHint { normal, emphasize, deemphasize };
+
+  std::optional name;
+  std::optional path;
+  std::optional sourceReference;
+  std::optional presentationHint;
+
+  // unsupproted keys origin, sources, adapterData, checksums
+};
+bool fromJSON(const llvm::json::Value &, Source &, llvm::json::Path);
+llvm::json::Value toJSON(const Source &);

vogelsgesang wrote:

I see that we will need both in the future.

However, in your commit, the `toJSON` function is not even implemented, it is 
only declared. Calling it would lead to a linker error.

I see no benefit in introducing just the declaration in this commit. Either 
introduce both the declaration and implementation as part of this commit, or 
remove the declaration and introduce both declaration and implementation in a 
follow-up commit

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


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

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


@@ -0,0 +1,138 @@
+"""
+Test lldb-dap gotoTarget request
+"""
+
+from typing import Dict, Any
+from unittest import SkipTest
+
+from lldbsuite.test.lldbtest import line_number
+import lldbdap_testcase
+import os
+
+
+class TestDAP_gotoTargets(lldbdap_testcase.DAPTestCaseBase):
+def verify_variable(
+self, actual_dict: Dict[str, Any], expected_dict: Dict[str, Any]
+):
+for key, value in expected_dict.items():
+actual_value = actual_dict[key]
+self.assertEqual(
+actual_value,
+value,
+f"values does not match for key: `{key}` expected_value: 
`{value}`, actual_value: `{actual_value}`",
+)
+
+def test_default(self):
+"""
+Tests the jump to cursor of a simple program. No arguments,
+environment, or anything else is specified.
+This does not run any statement between the current breakpoint
+and the jump line location.
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+
+source_file = "main.c"
+self.source_path = os.path.join(os.getcwd(), source_file)
+self.set_source_breakpoints(
+source_file, [line_number(source_file, "// breakpoint 1")]
+)
+self.continue_to_next_stop()
+
+first_var_1_object = self.dap_server.get_local_variable("var_1")
+self.assertEqual(first_var_1_object["value"], "10")
+
+goto_line = line_number(source_file, "// goto 1")
+goto_column = 1
+response = self.dap_server.request_gotoTargets(
+source_file, self.source_path, goto_line, goto_column
+)
+
+self.assertEqual(
+response["success"], True, "expects success when request for 
targets"
+)
+target = response["body"]["targets"][0]
+self.assertGreaterEqual(
+target["id"], 0, "targetId should be greater than or equal to zero"
+)
+
+target_id = target["id"]
+thread_id = self.dap_server.get_thread_id()
+self.assertIsNotNone(thread_id, "threadId should not be none")
+
+response = self.dap_server.request_goto(thread_id, target_id)
+self.assertEqual(response["success"], True, "expects success to go to 
targetId")
+
+stopped_events = self.dap_server.wait_for_stopped()
+is_goto = lambda event: event["body"]["reason"] == "goto"
+has_goto_event = any(map(is_goto, stopped_events))
+self.assertEqual(has_goto_event, True, "expects stopped event with 
reason goto")

vogelsgesang wrote:

```suggestion
self.assertEqual(has_goto_event, True, "expected a stopped event with 
reason `goto`")
```

https://github.com/llvm/llvm-project/pull/130503
___
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] Implement jump to cursor (PR #130503)

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


@@ -0,0 +1,138 @@
+"""
+Test lldb-dap gotoTarget request
+"""
+
+from typing import Dict, Any
+from unittest import SkipTest
+
+from lldbsuite.test.lldbtest import line_number
+import lldbdap_testcase
+import os
+
+
+class TestDAP_gotoTargets(lldbdap_testcase.DAPTestCaseBase):
+def verify_variable(
+self, actual_dict: Dict[str, Any], expected_dict: Dict[str, Any]
+):
+for key, value in expected_dict.items():
+actual_value = actual_dict[key]
+self.assertEqual(
+actual_value,
+value,
+f"values does not match for key: `{key}` expected_value: 
`{value}`, actual_value: `{actual_value}`",
+)
+
+def test_default(self):
+"""
+Tests the jump to cursor of a simple program. No arguments,
+environment, or anything else is specified.
+This does not run any statement between the current breakpoint
+and the jump line location.
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+
+source_file = "main.c"
+self.source_path = os.path.join(os.getcwd(), source_file)
+self.set_source_breakpoints(
+source_file, [line_number(source_file, "// breakpoint 1")]
+)
+self.continue_to_next_stop()
+
+first_var_1_object = self.dap_server.get_local_variable("var_1")
+self.assertEqual(first_var_1_object["value"], "10")
+
+goto_line = line_number(source_file, "// goto 1")
+goto_column = 1
+response = self.dap_server.request_gotoTargets(
+source_file, self.source_path, goto_line, goto_column
+)
+
+self.assertEqual(
+response["success"], True, "expects success when request for 
targets"
+)
+target = response["body"]["targets"][0]
+self.assertGreaterEqual(
+target["id"], 0, "targetId should be greater than or equal to zero"
+)
+
+target_id = target["id"]
+thread_id = self.dap_server.get_thread_id()
+self.assertIsNotNone(thread_id, "threadId should not be none")
+
+response = self.dap_server.request_goto(thread_id, target_id)
+self.assertEqual(response["success"], True, "expects success to go to 
targetId")

vogelsgesang wrote:

```suggestion
self.assertEqual(response["success"], True, "goto request with targetId 
should be successful")
```

https://github.com/llvm/llvm-project/pull/130503
___
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] Implement jump to cursor (PR #130503)

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


@@ -0,0 +1,138 @@
+"""
+Test lldb-dap gotoTarget request
+"""
+
+from typing import Dict, Any
+from unittest import SkipTest
+
+from lldbsuite.test.lldbtest import line_number
+import lldbdap_testcase
+import os
+
+
+class TestDAP_gotoTargets(lldbdap_testcase.DAPTestCaseBase):
+def verify_variable(
+self, actual_dict: Dict[str, Any], expected_dict: Dict[str, Any]
+):
+for key, value in expected_dict.items():
+actual_value = actual_dict[key]
+self.assertEqual(
+actual_value,
+value,
+f"values does not match for key: `{key}` expected_value: 
`{value}`, actual_value: `{actual_value}`",
+)
+
+def test_default(self):
+"""
+Tests the jump to cursor of a simple program. No arguments,
+environment, or anything else is specified.
+This does not run any statement between the current breakpoint
+and the jump line location.
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+
+source_file = "main.c"
+self.source_path = os.path.join(os.getcwd(), source_file)
+self.set_source_breakpoints(
+source_file, [line_number(source_file, "// breakpoint 1")]
+)
+self.continue_to_next_stop()
+
+first_var_1_object = self.dap_server.get_local_variable("var_1")
+self.assertEqual(first_var_1_object["value"], "10")
+
+goto_line = line_number(source_file, "// goto 1")
+goto_column = 1
+response = self.dap_server.request_gotoTargets(
+source_file, self.source_path, goto_line, goto_column
+)
+
+self.assertEqual(
+response["success"], True, "expects success when request for 
targets"
+)
+target = response["body"]["targets"][0]
+self.assertGreaterEqual(
+target["id"], 0, "targetId should be greater than or equal to zero"
+)
+
+target_id = target["id"]
+thread_id = self.dap_server.get_thread_id()
+self.assertIsNotNone(thread_id, "threadId should not be none")
+
+response = self.dap_server.request_goto(thread_id, target_id)
+self.assertEqual(response["success"], True, "expects success to go to 
targetId")
+
+stopped_events = self.dap_server.wait_for_stopped()
+is_goto = lambda event: event["body"]["reason"] == "goto"
+has_goto_event = any(map(is_goto, stopped_events))
+self.assertEqual(has_goto_event, True, "expects stopped event with 
reason goto")
+
+self.dap_server.request_next(thread_id)
+self.continue_to_next_stop()
+
+var1_variable = self.dap_server.get_local_variable("var_1")

vogelsgesang wrote:

```suggestion
# Verify that `var_1=10` and `var_2=40`. This combination is only 
possible by
# skipping execution of a line from the original program. Observing 
this combination
# hence proves that our `goto` request actually skipped execution of 
the code line.
var1_variable = self.dap_server.get_local_variable("var_1")
```

https://github.com/llvm/llvm-project/pull/130503
___
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] Implement jump to cursor (PR #130503)

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


@@ -0,0 +1,138 @@
+"""
+Test lldb-dap gotoTarget request
+"""
+
+from typing import Dict, Any
+from unittest import SkipTest
+
+from lldbsuite.test.lldbtest import line_number
+import lldbdap_testcase
+import os
+
+
+class TestDAP_gotoTargets(lldbdap_testcase.DAPTestCaseBase):
+def verify_variable(
+self, actual_dict: Dict[str, Any], expected_dict: Dict[str, Any]
+):
+for key, value in expected_dict.items():
+actual_value = actual_dict[key]
+self.assertEqual(
+actual_value,
+value,
+f"values does not match for key: `{key}` expected_value: 
`{value}`, actual_value: `{actual_value}`",
+)
+
+def test_default(self):
+"""
+Tests the jump to cursor of a simple program. No arguments,
+environment, or anything else is specified.
+This does not run any statement between the current breakpoint
+and the jump line location.
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+
+source_file = "main.c"
+self.source_path = os.path.join(os.getcwd(), source_file)
+self.set_source_breakpoints(
+source_file, [line_number(source_file, "// breakpoint 1")]
+)
+self.continue_to_next_stop()
+
+first_var_1_object = self.dap_server.get_local_variable("var_1")
+self.assertEqual(first_var_1_object["value"], "10")
+
+goto_line = line_number(source_file, "// goto 1")
+goto_column = 1
+response = self.dap_server.request_gotoTargets(
+source_file, self.source_path, goto_line, goto_column
+)
+
+self.assertEqual(
+response["success"], True, "expects success when request for 
targets"

vogelsgesang wrote:

```suggestion
response["success"], True, "request for gotoTargets should be 
successful"
```

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


[Lldb-commits] [lldb] [lldb] Use UnwindPlan::Row as values (PR #131150)

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

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

In most places, the rows are copied anyway (because they are generated by 
cumulating modifications) immediately after adding them to the unwind plans. In 
others, they can be moved into the unwind plan. This lets us remove some 
backflip copies and make `const UnwindPlan` actually mean something.

I've split this patch into two (and temporarily left both APIs) as this patch 
was getting a bit big. This patch covers all the interesting cases. Part two 
all about converting "architecture default" unwind plans from ABI and 
InstructionEmulation plugins.

>From 8f785e8c4e08cf4ca647cad548dfe692422edbf0 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Thu, 13 Mar 2025 15:35:25 +0100
Subject: [PATCH] [lldb] Use UnwindPlan::Row as values

In most places, the rows are copied anyway (because they are generated
by cumulating modifications) immediately after adding them to the unwind
plans. In others, they can be moved into the unwind plan. This lets us
remove some backflip copies and make `const UnwindPlan` actually mean
something.

I've split this patch into two (and temporarily left both APIs) as this
patch was getting a bit big. This patch covers all the interesting
cases. Part two all about converting "architecture default" unwind plans
from ABI and InstructionEmulation plugins.
---
 lldb/include/lldb/Symbol/UnwindPlan.h |   4 +
 .../ObjectFile/PECOFF/PECallFrameInfo.cpp |  26 +--
 .../Plugins/Platform/Linux/PlatformLinux.cpp  |  75 ---
 .../Breakpad/SymbolFileBreakpad.cpp   |  27 ++-
 .../UnwindAssemblyInstEmulation.cpp   |   5 +-
 .../x86/x86AssemblyInspectionEngine.cpp   | 155 ++-
 lldb/source/Symbol/ArmUnwindInfo.cpp  |  15 +-
 lldb/source/Symbol/CompactUnwindInfo.cpp  | 188 +-
 lldb/source/Symbol/DWARFCallFrameInfo.cpp |  50 ++---
 .../x86/Testx86AssemblyInspectionEngine.cpp   | 165 ++-
 10 files changed, 306 insertions(+), 404 deletions(-)

diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index 462c1a52b01db..e4199d5677035 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -463,8 +463,12 @@ class UnwindPlan {
   void Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const;
 
   void AppendRow(const RowSP &row_sp);
+  void AppendRow(Row row) { AppendRow(std::make_shared(std::move(row))); }
 
   void InsertRow(const RowSP &row_sp, bool replace_existing = false);
+  void InsertRow(Row row, bool replace_existing = false) {
+InsertRow(std::make_shared(std::move(row)), replace_existing);
+  }
 
   // Returns a pointer to the best row for the given offset into the function's
   // instructions. If offset is -1 it indicates that the function start is
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp 
b/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
index 9bd48f2b9f60f..459abe417035e 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
@@ -351,7 +351,7 @@ class EHProgramRange {
   EHProgramRange(EHProgram::const_iterator begin,
  EHProgram::const_iterator end);
 
-  std::unique_ptr BuildUnwindPlanRow() const;
+  UnwindPlan::Row BuildUnwindPlanRow() const;
 
 private:
   int32_t GetCFAFrameOffset() const;
@@ -364,11 +364,11 @@ EHProgramRange::EHProgramRange(EHProgram::const_iterator 
begin,
EHProgram::const_iterator end)
 : m_begin(begin), m_end(end) {}
 
-std::unique_ptr EHProgramRange::BuildUnwindPlanRow() const {
-  std::unique_ptr row = std::make_unique();
+UnwindPlan::Row EHProgramRange::BuildUnwindPlanRow() const {
+  UnwindPlan::Row row;
 
   if (m_begin != m_end)
-row->SetOffset(m_begin->offset);
+row.SetOffset(m_begin->offset);
 
   int32_t cfa_frame_offset = GetCFAFrameOffset();
 
@@ -376,8 +376,8 @@ std::unique_ptr 
EHProgramRange::BuildUnwindPlanRow() const {
   for (EHProgram::const_iterator it = m_begin; it != m_end; ++it) {
 switch (it->type) {
 case EHInstruction::Type::SET_FRAME_POINTER_REGISTER:
-  row->GetCFAValue().SetIsRegisterPlusOffset(it->reg, cfa_frame_offset -
-  
it->frame_offset);
+  row.GetCFAValue().SetIsRegisterPlusOffset(it->reg, cfa_frame_offset -
+ it->frame_offset);
   frame_pointer_found = true;
   break;
 default:
@@ -387,14 +387,14 @@ std::unique_ptr 
EHProgramRange::BuildUnwindPlanRow() const {
   break;
   }
   if (!frame_pointer_found)
-row->GetCFAValue().SetIsRegisterPlusOffset(lldb_rsp_x86_64,
-   cfa_frame_offset);
+row.GetCFAValue().SetIsRegisterPlusOffset(lldb_rsp_x86_64,
+  cfa_fra

[Lldb-commits] [lldb] [lldb] Use UnwindPlan::Row as values (PR #131150)

2025-03-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

In most places, the rows are copied anyway (because they are generated by 
cumulating modifications) immediately after adding them to the unwind plans. In 
others, they can be moved into the unwind plan. This lets us remove some 
backflip copies and make `const UnwindPlan` actually mean something.

I've split this patch into two (and temporarily left both APIs) as this patch 
was getting a bit big. This patch covers all the interesting cases. Part two 
all about converting "architecture default" unwind plans from ABI and 
InstructionEmulation plugins.

---

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


10 Files Affected:

- (modified) lldb/include/lldb/Symbol/UnwindPlan.h (+4) 
- (modified) lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp (+13-13) 
- (modified) lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp (+37-38) 
- (modified) lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp 
(+12-15) 
- (modified) 
lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
 (+2-3) 
- (modified) 
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp (+60-95) 
- (modified) lldb/source/Symbol/ArmUnwindInfo.cpp (+7-8) 
- (modified) lldb/source/Symbol/CompactUnwindInfo.cpp (+90-98) 
- (modified) lldb/source/Symbol/DWARFCallFrameInfo.cpp (+15-35) 
- (modified) 
lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp (+66-99) 


``diff
diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index 462c1a52b01db..e4199d5677035 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -463,8 +463,12 @@ class UnwindPlan {
   void Dump(Stream &s, Thread *thread, lldb::addr_t base_addr) const;
 
   void AppendRow(const RowSP &row_sp);
+  void AppendRow(Row row) { AppendRow(std::make_shared(std::move(row))); }
 
   void InsertRow(const RowSP &row_sp, bool replace_existing = false);
+  void InsertRow(Row row, bool replace_existing = false) {
+InsertRow(std::make_shared(std::move(row)), replace_existing);
+  }
 
   // Returns a pointer to the best row for the given offset into the function's
   // instructions. If offset is -1 it indicates that the function start is
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp 
b/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
index 9bd48f2b9f60f..459abe417035e 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/PECallFrameInfo.cpp
@@ -351,7 +351,7 @@ class EHProgramRange {
   EHProgramRange(EHProgram::const_iterator begin,
  EHProgram::const_iterator end);
 
-  std::unique_ptr BuildUnwindPlanRow() const;
+  UnwindPlan::Row BuildUnwindPlanRow() const;
 
 private:
   int32_t GetCFAFrameOffset() const;
@@ -364,11 +364,11 @@ EHProgramRange::EHProgramRange(EHProgram::const_iterator 
begin,
EHProgram::const_iterator end)
 : m_begin(begin), m_end(end) {}
 
-std::unique_ptr EHProgramRange::BuildUnwindPlanRow() const {
-  std::unique_ptr row = std::make_unique();
+UnwindPlan::Row EHProgramRange::BuildUnwindPlanRow() const {
+  UnwindPlan::Row row;
 
   if (m_begin != m_end)
-row->SetOffset(m_begin->offset);
+row.SetOffset(m_begin->offset);
 
   int32_t cfa_frame_offset = GetCFAFrameOffset();
 
@@ -376,8 +376,8 @@ std::unique_ptr 
EHProgramRange::BuildUnwindPlanRow() const {
   for (EHProgram::const_iterator it = m_begin; it != m_end; ++it) {
 switch (it->type) {
 case EHInstruction::Type::SET_FRAME_POINTER_REGISTER:
-  row->GetCFAValue().SetIsRegisterPlusOffset(it->reg, cfa_frame_offset -
-  
it->frame_offset);
+  row.GetCFAValue().SetIsRegisterPlusOffset(it->reg, cfa_frame_offset -
+ it->frame_offset);
   frame_pointer_found = true;
   break;
 default:
@@ -387,14 +387,14 @@ std::unique_ptr 
EHProgramRange::BuildUnwindPlanRow() const {
   break;
   }
   if (!frame_pointer_found)
-row->GetCFAValue().SetIsRegisterPlusOffset(lldb_rsp_x86_64,
-   cfa_frame_offset);
+row.GetCFAValue().SetIsRegisterPlusOffset(lldb_rsp_x86_64,
+  cfa_frame_offset);
 
   int32_t rsp_frame_offset = 0;
   for (EHProgram::const_iterator it = m_begin; it != m_end; ++it) {
 switch (it->type) {
 case EHInstruction::Type::PUSH_REGISTER:
-  row->SetRegisterLocationToAtCFAPlusOffset(
+  row.SetRegisterLocationToAtCFAPlusOffset(
   it->reg, rsp_frame_offset - cfa_frame_offset, false);
   rsp_frame_offset += it->frame_offset;
   break;
@@ -402,7 +402,7 @@ std::unique_ptr 
EHProgramRange:

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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

https://github.com/DhruvSrivastavaX updated 
https://github.com/llvm/llvm-project/pull/118160

>From 03a290e9c748540b69ca6df7fa9c4481f9cdd3d0 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Sat, 30 Nov 2024 01:14:15 -0600
Subject: [PATCH 01/12] Added base files for NativeProcess for AIX

---
 .../source/Plugins/Process/AIX/CMakeLists.txt |  14 +
 .../Plugins/Process/AIX/NativeProcessAIX.cpp  | 288 ++
 .../Plugins/Process/AIX/NativeProcessAIX.h| 134 
 lldb/source/Plugins/Process/CMakeLists.txt|   3 +
 4 files changed, 439 insertions(+)
 create mode 100644 lldb/source/Plugins/Process/AIX/CMakeLists.txt
 create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
 create mode 100644 lldb/source/Plugins/Process/AIX/NativeProcessAIX.h

diff --git a/lldb/source/Plugins/Process/AIX/CMakeLists.txt 
b/lldb/source/Plugins/Process/AIX/CMakeLists.txt
new file mode 100644
index 0..4fabbe9302287
--- /dev/null
+++ b/lldb/source/Plugins/Process/AIX/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_lldb_library(lldbPluginProcessAIX
+  NativeProcessAIX.cpp
+
+  LINK_LIBS
+lldbCore
+lldbHost
+lldbSymbol
+lldbTarget
+lldbUtility
+lldbPluginProcessPOSIX
+lldbPluginProcessUtility
+  LINK_COMPONENTS
+Support
+  )
diff --git a/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp 
b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
new file mode 100644
index 0..6661693b2fc02
--- /dev/null
+++ b/lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp
@@ -0,0 +1,288 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "NativeThreadAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/PseudoTerminal.h"
+#include "lldb/Host/ThreadLauncher.h"
+#include "lldb/Host/common/NativeRegisterContext.h"
+#include "lldb/Host/aix/Ptrace.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/LLDBAssert.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/RegisterValue.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StringExtractor.h"
+#include "llvm/ADT/ScopeExit.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#ifdef __aarch64__
+#include 
+#include 
+#endif
+
+// Support hardware breakpoints in case it has not been defined
+#ifndef TRAP_HWBKPT
+#define TRAP_HWBKPT 4
+#endif
+
+#ifndef HWCAP2_MTE
+#define HWCAP2_MTE (1 << 18)
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static Status EnsureFDFlags(int fd, int flags) {
+  Status error;
+
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1) {
+error = Status::FromErrno();
+return error;
+  }
+
+  if (fcntl(fd, F_SETFL, status | flags) == -1) {
+error = Status::FromErrno();
+return error;
+  }
+
+  return error;
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid

[Lldb-commits] [lldb] [lldb] Support discontinuous functions in another Disasembler overload (PR #130987)

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

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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

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

>From f26c9a79ca234bee77ec1a9694bf8be2d0e3745c Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Thu, 6 Mar 2025 13:21:10 +0100
Subject: [PATCH 1/5] [lldb-dap] Updating RequestHandler to encode/decode
 arguments and response.

This is a work in progress refactor to add explicit types instead of
generic 'llvm::json::Value' types to the DAP protocol.

This updates RequestHandler to have take the type of the arguments and
response body for serialization for requests.

The 'source' request is updated to show how the new flow works.
---
 lldb/tools/lldb-dap/DAP.cpp   |  57 +++--
 lldb/tools/lldb-dap/DAP.h |   4 +-
 lldb/tools/lldb-dap/DAPForward.h  |   2 +
 .../tools/lldb-dap/Handler/RequestHandler.cpp |  11 +-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 214 --
 .../lldb-dap/Handler/SourceRequestHandler.cpp | 104 ++---
 lldb/tools/lldb-dap/Protocol.cpp  |  44 
 lldb/tools/lldb-dap/Protocol.h| 131 +++
 8 files changed, 381 insertions(+), 186 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 4080e2c211035..9d42af2d7091f 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -8,10 +8,12 @@
 
 #include "DAP.h"
 #include "DAPLog.h"
+#include "Handler/RequestHandler.h"
 #include "Handler/ResponseHandler.h"
 #include "JSONUtils.h"
 #include "LLDBUtils.h"
 #include "OutputRedirector.h"
+#include "Protocol.h"
 #include "Transport.h"
 #include "lldb/API/SBBreakpoint.h"
 #include "lldb/API/SBCommandInterpreter.h"
@@ -25,6 +27,7 @@
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -41,6 +44,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if defined(_WIN32)
@@ -663,31 +667,23 @@ void DAP::SetTarget(const lldb::SBTarget target) {
 }
 
 bool DAP::HandleObject(const protocol::Message &M) {
-  // FIXME: Directly handle `Message` instead of serializing to JSON.
-  llvm::json::Value v = toJSON(M);
-  llvm::json::Object object = *v.getAsObject();
-  const auto packet_type = GetString(object, "type");
-  if (packet_type == "request") {
-const auto command = GetString(object, "command");
-
-auto new_handler_pos = request_handlers.find(command);
+  if (const auto *req = std::get_if(&M)) {
+auto new_handler_pos = request_handlers.find(req->command);
 if (new_handler_pos != request_handlers.end()) {
-  (*new_handler_pos->second)(object);
+  (*new_handler_pos->second)(*req);
   return true; // Success
 }
 
 DAP_LOG(log, "({0}) error: unhandled command '{1}'",
-transport.GetClientName(), command);
+transport.GetClientName(), req->command);
 return false; // Fail
   }
 
-  if (packet_type == "response") {
-auto id = GetInteger(object, "request_seq").value_or(0);
-
+  if (const auto *resp = std::get_if(&M)) {
 std::unique_ptr response_handler;
 {
   std::lock_guard locker(call_mutex);
-  auto inflight = inflight_reverse_requests.find(id);
+  auto inflight = inflight_reverse_requests.find(resp->request_seq);
   if (inflight != inflight_reverse_requests.end()) {
 response_handler = std::move(inflight->second);
 inflight_reverse_requests.erase(inflight);
@@ -695,19 +691,31 @@ bool DAP::HandleObject(const protocol::Message &M) {
 }
 
 if (!response_handler)
-  response_handler = std::make_unique("", id);
+  response_handler =
+  std::make_unique("", resp->request_seq);
 
 // Result should be given, use null if not.
-if (GetBoolean(object, "success").value_or(false)) {
-  llvm::json::Value Result = nullptr;
-  if (auto *B = object.get("body"))
-Result = std::move(*B);
-  (*response_handler)(Result);
+if (resp->success) {
+  (*response_handler)(resp->rawBody);
 } else {
-  llvm::StringRef message = GetString(object, "message");
-  if (message.empty()) {
-message = "Unknown error, response failed";
+  std::string message = "Unknown error, response failed";
+  if (resp->message) {
+message = std::visit(
+llvm::makeVisitor(
+[](const std::string &message) -> std::string {
+  return message;
+},
+[](const protocol::Response::Message &message) -> std::string {
+  switch (message) {
+  case protocol::Response::Message::cancelled:
+return "cancelled";
+  case protocol::Response::Message::notStopped:
+return "notStopped";
+  }
+}),
+*resp->message);
   }
+
   (*response_handler)(l

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -240,6 +240,137 @@ using Message = std::variant;
 bool fromJSON(const llvm::json::Value &, Message &, llvm::json::Path);
 llvm::json::Value toJSON(const Message &);
 
+// MARK: Types
+
+// "Source": {
+//   "type": "object",
+//   "description": "A `Source` is a descriptor for source code.\nIt is 
returned
+//   from the debug adapter as part of a `StackFrame` and it is used by clients
+//   when specifying breakpoints.", "properties": {
+// "name": {
+//   "type": "string",
+//   "description": "The short name of the source. Every source returned
+//   from the debug adapter has a name.\nWhen sending a source to the debug
+//   adapter this name is optional."
+// },
+// "path": {
+//   "type": "string",
+//   "description": "The path of the source to be shown in the UI.\nIt is
+//   only used to locate and load the content of the source if no
+//   `sourceReference` is specified (or its value is 0)."
+// },
+// "sourceReference": {
+//   "type": "integer",
+//   "description": "If the value > 0 the contents of the source must be
+//   retrieved through the `source` request (even if a path is
+//   specified).\nSince a `sourceReference` is only valid for a session, it
+//   can not be used to persist a source.\nThe value should be less than or
+//   equal to 2147483647 (2^31-1)."
+// },
+// "presentationHint": {
+//   "type": "string",
+//   "description": "A hint for how to present the source in the UI.\nA
+//   value of `deemphasize` can be used to indicate that the source is not
+//   available or that it is skipped on stepping.", "enum": [ "normal",
+//   "emphasize", "deemphasize" ]
+// },
+// "origin": {
+//   "type": "string",
+//   "description": "The origin of this source. For example, 'internal
+//   module', 'inlined content from source map', etc."
+// },
+// "sources": {
+//   "type": "array",
+//   "items": {
+// "$ref": "#/definitions/Source"
+//   },
+//   "description": "A list of sources that are related to this source.
+//   These may be the source that generated this source."
+// },
+// "adapterData": {
+//   "type": [ "array", "boolean", "integer", "null", "number", "object",
+//   "string" ], "description": "Additional data that a debug adapter might
+//   want to loop through the client.\nThe client should leave the data
+//   intact and persist it across sessions. The client should not interpret
+//   the data."
+// },
+// "checksums": {
+//   "type": "array",
+//   "items": {
+// "$ref": "#/definitions/Checksum"
+//   },
+//   "description": "The checksums associated with this file."
+// }
+//   }
+// },
+struct Source {
+  enum class PresentationHint { normal, emphasize, deemphasize };
+
+  std::optional name;
+  std::optional path;
+  std::optional sourceReference;
+  std::optional presentationHint;
+
+  // unsupproted keys origin, sources, adapterData, checksums
+};
+bool fromJSON(const llvm::json::Value &, Source &, llvm::json::Path);
+llvm::json::Value toJSON(const Source &);

ashgti wrote:

Oh, I see what you mean, removed the `toJSON` since its not implemented.

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -57,235 +68,288 @@ class RequestHandler {
   DAP &dap;
 };
 
-class AttachRequestHandler : public RequestHandler {
-public:
-  using RequestHandler::RequestHandler;
+/// Base class for handling DAP requests. Handlers should declare their
+/// arguments and response body types like:
+///
+/// class MyRequestHandler : public RequestHandler {
+///   
+/// };
+template 
+class RequestHandler : public BaseRequestHandler {
+  using BaseRequestHandler::BaseRequestHandler;
+
+  void operator()(const llvm::json::Object &request) const override {
+/* no-op, the other overload handles json coding. */
+  }
+
+  void operator()(const protocol::Request &request) const override {
+protocol::Response response;
+response.request_seq = request.seq;
+response.command = request.command;
+Args arguments;
+llvm::json::Path::Root root;
+if (request.rawArguments &&
+!fromJSON(request.rawArguments, arguments, root)) {

ashgti wrote:

I updated this to check if the `Args` are optional and fail the request if args 
are not provided.

I also added a `VoidResponse` helper that uses `std::monostate` to not return a 
response body.

This should help ensure we get arguments when we expect them and handle 
responses without a body.

LMKWYT

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


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

2025-03-13 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/14] [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][lldb-dap] Implement jump to cursor (PR #130503)

2025-03-13 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/17] [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][lldb-dap] Implement jump to cursor (PR #130503)

2025-03-13 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/16] [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] [compiler-rt] [libcxx] [libcxxabi] [libunwind] [lldb] [llvm] [compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #131200)

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

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

We don't plan to support it on AIX.
This change will make it as if it is set to OFF.

>From 37eb6964a176dd566b3600c0fb15a1d426551729 Mon Sep 17 00:00:00 2001
From: Daniel Chen 
Date: Thu, 13 Mar 2025 15:52:23 -0400
Subject: [PATCH] [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(LIBC

[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-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Daniel Chen (DanielCChen)


Changes

We don't plan to support it on AIX.
This change will make it as if it is set to OFF.

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


9 Files Affected:

- (modified) compiler-rt/cmake/Modules/AddCompilerRT.cmake (+1-1) 
- (modified) compiler-rt/cmake/Modules/CompilerRTUtils.cmake (+2-2) 
- (modified) compiler-rt/cmake/base-config-ix.cmake (+2-2) 
- (modified) libcxx/CMakeLists.txt (+1-1) 
- (modified) libcxxabi/CMakeLists.txt (+1-1) 
- (modified) libunwind/CMakeLists.txt (+1-1) 
- (modified) lldb/test/CMakeLists.txt (+1-1) 
- (modified) lldb/utils/lldb-dotest/CMakeLists.txt (+1-1) 
- (modified) llvm-libgcc/CMakeLists.txt (+1-1) 


``diff
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)
 string(APPEND LIBCXXABI_TARGET_SUBDIR /${LIBCXXABI_LIBDIR_SUBDIR})
diff --git a/libunwind/CMakeLi

[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-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxxabi

Author: Daniel Chen (DanielCChen)


Changes

We don't plan to support it on AIX.
This change will make it as if it is set to OFF.

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


9 Files Affected:

- (modified) compiler-rt/cmake/Modules/AddCompilerRT.cmake (+1-1) 
- (modified) compiler-rt/cmake/Modules/CompilerRTUtils.cmake (+2-2) 
- (modified) compiler-rt/cmake/base-config-ix.cmake (+2-2) 
- (modified) libcxx/CMakeLists.txt (+1-1) 
- (modified) libcxxabi/CMakeLists.txt (+1-1) 
- (modified) libunwind/CMakeLists.txt (+1-1) 
- (modified) lldb/test/CMakeLists.txt (+1-1) 
- (modified) lldb/utils/lldb-dotest/CMakeLists.txt (+1-1) 
- (modified) llvm-libgcc/CMakeLists.txt (+1-1) 


``diff
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)
 string(APPEND LIBCXXABI_TARGET_SUBDIR /${LIBCXXABI_LIBDIR_SUBDIR})
diff --git a/libunwind/CMakeLi

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

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


@@ -0,0 +1,121 @@
+//===-- GoToTargetsRequestHandler.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+
+#include "JSONUtils.h"
+
+#include 
+
+namespace lldb_dap {
+
+//  "GotoTargetsRequest": {
+//"allOf": [ { "$ref": "#/definitions/Request" }, {
+//  "type": "object",
+//  "description": "This request retrieves the possible goto targets for 
the
+//  specified source location.\nThese targets can be used in the `goto`
+//  request.\nClients should only call this request if the corresponding
+//  capability `supportsGotoTargetsRequest` is true.",
+//. "properties": {
+//"command": {
+//  "type": "string",
+//  "enum": [ "gotoTargets" ]
+//},
+//"arguments": {
+//  "$ref": "#/definitions/GotoTargetsArguments"
+//}
+//  },
+//  "required": [ "command", "arguments"  ]
+//}]
+//  },
+//  "GotoTargetsArguments": {
+//"type": "object",
+//"description": "Arguments for `gotoTargets` request.",
+//"properties": {
+//  "source": {
+//"$ref": "#/definitions/Source",
+//"description": "The source location for which the goto targets are
+//determined."
+//  },
+//  "line": {
+//"type": "integer",
+//"description": "The line location for which the goto targets are
+//determined."
+//  },
+//  "column": {
+//"type": "integer",
+//"description": "The position within `line` for which the goto targets
+//are determined. It is measured in UTF-16 code units and the client
+//capability `columnsStartAt1` determines whether it is 0- or 1-based."
+//  }
+//},
+//"required": [ "source", "line" ]
+//  },
+//  "GotoTargetsResponse": {
+//"allOf": [ { "$ref": "#/definitions/Response" }, {
+//  "type": "object",
+//  "description": "Response to `gotoTargets` request.",
+//  "properties": {
+//"body": {
+//  "type": "object",
+//  "properties": {
+//"targets": {
+//  "type": "array",
+//  "items": {
+//"$ref": "#/definitions/GotoTarget"
+//  },
+//  "description": "The possible goto targets of the specified
+//  location."
+//}
+//  },
+//  "required": [ "targets" ]
+//}
+//  },
+//  "required": [ "body" ]
+//}]
+//  },
+void GoToTargetsRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+  const auto *arguments = request.getObject("arguments");
+  const auto *source = arguments->getObject("source");
+  const std::string path = GetString(source, "path").str();
+
+  const auto goto_line = GetInteger(arguments, "line").value_or(0u);
+  const auto goto_column =
+  GetInteger(arguments, "column").value_or(0u);
+
+  lldb::SBLineEntry line_entry{};
+  const lldb::SBFileSpec file_spec(path.c_str(), true);
+  line_entry.SetFileSpec(file_spec);
+  line_entry.SetLine(goto_line);
+  line_entry.SetColumn(goto_column);
+
+  const auto target_id = dap.goto_id_map.InsertLineEntry(line_entry);
+  llvm::json::Array response_targets;
+  const auto target_line = line_entry.GetLine();
+  const auto target_column = line_entry.GetColumn();

da-viper wrote:

> Somehow I think we shouldn't support jump based on columns. You might find 
> yourself breaking the semantics of the code.

Makes sense since `SBThread::JumpToLine` takes a filespec and line number

https://github.com/llvm/llvm-project/pull/130503
___
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-13 Thread Alexander Richardson via lldb-commits

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

Wouldn't it be more maintainable to just set the value to off for AIX where the 
`option()` is defined?

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


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

2025-03-13 Thread Alexander Richardson via lldb-commits

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


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

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


@@ -1559,10 +1560,29 @@ void Target::DidExec() {
 
 void Target::SetExecutableModule(ModuleSP &executable_sp,
  LoadDependentFiles load_dependent_files) {
+  telemetry::ScopedDispatcher helper(&m_debugger);
   Log *log = GetLog(LLDBLog::Target);
   ClearModules(false);
 
   if (executable_sp) {
+m_current_exec_mod_uuid = executable_sp->GetUUID();
+lldb::pid_t pid;
+if (ProcessSP proc = GetProcessSP())
+  pid = proc->GetID();
+helper.DispatchNow([&](telemetry::ExecModuleInfo *info) {
+  info->exec_mod = executable_sp;
+  info->exec_uuid = m_current_exec_mod_uuid;
+  info->pid = pid;
+  info->arch_name = executable_sp->GetArchitecture().GetArchitectureName();

oontvoo wrote:

done

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][debugserver] Synchronize interrupt and resume signals (PR #131073)

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

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


[Lldb-commits] [lldb] e823449 - [lldb][debugserver] Synchronize interrupt and resume signals (#131073)

2025-03-13 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-03-13T13:54:13-07:00
New Revision: e823449f66acb39ce5a11dde6283ffd11731fe6a

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

LOG: [lldb][debugserver] Synchronize interrupt and resume signals (#131073)

This PR fixes a race condition in debugserver where the main thread
calls MachProcess::Interrupt, setting `m_sent_interrupt_signo` while the
exception monitoring thread is checking the value of the variable.

I was on the fence between introducing a new mutex and reusing the
existing exception mutex. With the notable exception of
MachProcess::Interrupt, all the other places where we were already
locking this mutex before accessing the variable. I renamed the mutex to
make it clear that it's now protecting more than the exception messages.

Jason, while investigating a real issue, had a suspicion there was race
condition related to interrupts and I was able to narrow it down by
building debugserver with TSan.

Added: 


Modified: 
lldb/tools/debugserver/source/MacOSX/MachProcess.h
lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Removed: 




diff  --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
index db673693a1b21..ec0a13b482267 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -427,7 +427,7 @@ class MachProcess {
   m_profile_data_mutex; // Multithreaded protection for profile info data
   std::vector
   m_profile_data; // Profile data, must be protected by 
m_profile_data_mutex
-  PThreadEvent m_profile_events; // Used for the profile thread cancellable 
wait  
+  PThreadEvent m_profile_events; // Used for the profile thread cancellable 
wait
   DNBThreadResumeActions m_thread_actions; // The thread actions for the 
current
// MachProcess::Resume() call
   MachException::Message::collection m_exception_messages; // A collection of
@@ -435,8 +435,8 @@ class MachProcess {
// caught when
// listening to the
// exception port
-  PThreadMutex m_exception_messages_mutex; // Multithreaded protection for
-   // m_exception_messages
+  PThreadMutex m_exception_and_signal_mutex; // Multithreaded protection for
+ // exceptions and signals.
 
   MachThreadList m_thread_list; // A list of threads that is maintained/updated
 // after each stop

diff  --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
index a2179bf2f91e5..4742beeb6a4a3 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -528,7 +528,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary 
*options,
   m_profile_data_mutex(PTHREAD_MUTEX_RECURSIVE), m_profile_data(),
   m_profile_events(0, eMachProcessProfileCancel), m_thread_actions(),
   m_exception_messages(),
-  m_exception_messages_mutex(PTHREAD_MUTEX_RECURSIVE), m_thread_list(),
+  m_exception_and_signal_mutex(PTHREAD_MUTEX_RECURSIVE), m_thread_list(),
   m_activities(), m_state(eStateUnloaded),
   m_state_mutex(PTHREAD_MUTEX_RECURSIVE), m_events(0, kAllEventsMask),
   m_private_events(0, kAllEventsMask), m_breakpoints(), m_watchpoints(),
@@ -1338,8 +1338,11 @@ static bool mach_header_validity_test(uint32_t magic, 
uint32_t cputype) {
   m_stop_count = 0;
   m_thread_list.Clear();
   {
-PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);
+PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
 m_exception_messages.clear();
+m_sent_interrupt_signo = 0;
+m_auto_resume_signo = 0;
+
   }
   m_activities.Clear();
   StopProfileThread();
@@ -1575,6 +1578,7 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 bool MachProcess::Interrupt() {
   nub_state_t state = GetState();
   if (IsRunning(state)) {
+PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
 if (m_sent_interrupt_signo == 0) {
   m_sent_interrupt_signo = SIGSTOP;
   if (Signal(m_sent_interrupt_signo)) {
@@ -1728,7 +1732,7 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 m_thread_actions.Append(thread_action);
 m_thread_actions.SetDefaultThreadActionIfNeeded(eStateRunning, 0);
 
-PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);
+PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
 
 R

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

2025-03-13 Thread Matthew Bastien via lldb-commits

https://github.com/matthewbastien updated 
https://github.com/llvm/llvm-project/pull/129262

>From f687fdfeda083587bd8f2a874d34c0f9dba1e31a Mon Sep 17 00:00:00 2001
From: Matthew Bastien 
Date: Fri, 28 Feb 2025 11:08:25 -0500
Subject: [PATCH 1/8] allow providing debug adapter arguments

---
 lldb/tools/lldb-dap/package.json  | 29 +--
 .../lldb-dap/src-ts/debug-adapter-factory.ts  | 78 ---
 2 files changed, 76 insertions(+), 31 deletions(-)

diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index cd450a614b3f7..a0c8847d72535 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -75,6 +75,15 @@
   "type": "string",
   "description": "The path to the lldb-dap binary."
 },
+"lldb-dap.arguments": {
+  "scope": "resource",
+  "type": "array",
+  "default": [],
+  "items": {
+"type": "string"
+  },
+  "description": "The arguments provided to the lldb-dap process."
+},
 "lldb-dap.log-path": {
   "scope": "resource",
   "type": "string",
@@ -148,10 +157,6 @@
   {
 "type": "lldb-dap",
 "label": "LLDB DAP Debugger",
-"program": "./bin/lldb-dap",
-"windows": {
-  "program": "./bin/lldb-dap.exe"
-},
 "configurationAttributes": {
   "launch": {
 "required": [
@@ -162,6 +167,13 @@
 "type": "string",
 "markdownDescription": "The absolute path to the LLDB debug 
adapter executable to use."
   },
+  "debugAdapterArgs": {
+"type": "array",
+"items": {
+  "type": "string"
+},
+"markdownDescription": "The list of arguments used to launch 
the debug adapter executable."
+  },
   "program": {
 "type": "string",
 "description": "Path to the program to debug."
@@ -352,6 +364,13 @@
 "type": "string",
 "markdownDescription": "The absolute path to the LLDB debug 
adapter executable to use."
   },
+  "debugAdapterArgs": {
+"type": "array",
+"items": {
+  "type": "string"
+},
+"markdownDescription": "The list of arguments used to launch 
the debug adapter executable."
+  },
   "program": {
 "type": "string",
 "description": "Path to the program to attach to."
@@ -549,4 +568,4 @@
   }
 ]
   }
-}
\ No newline at end of file
+}
diff --git a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts 
b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
index c2244dcbde8f2..85c34b773e047 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
@@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): 
Promise {
   if (stdout) {
 return stdout.toString().trimEnd();
   }
-} catch (error) { }
+} catch (error) {}
   }
   return undefined;
 }
@@ -93,8 +93,23 @@ async function getDAPExecutable(
   return undefined;
 }
 
+function getDAPArguments(session: vscode.DebugSession): string[] {
+  // Check the debug configuration for arguments first
+  const debugConfigArgs = session.configuration.debugAdapterArgs;
+  if (
+Array.isArray(debugConfigArgs) &&
+debugConfigArgs.findIndex((entry) => typeof entry !== "string") === -1
+  ) {
+return debugConfigArgs;
+  }
+  // Fall back on the workspace configuration
+  return vscode.workspace
+.getConfiguration("lldb-dap")
+.get("arguments", []);
+}
+
 async function isServerModeSupported(exe: string): Promise {
-  const { stdout } = await exec(exe, ['--help']);
+  const { stdout } = await exec(exe, ["--help"]);
   return /--connection/.test(stdout);
 }
 
@@ -103,8 +118,13 @@ async function isServerModeSupported(exe: string): 
Promise {
  * depending on the session configuration.
  */
 export class LLDBDapDescriptorFactory
-  implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable {
-  private server?: Promise<{ process: child_process.ChildProcess, host: 
string, port: number }>;
+  implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable
+{
+  private server?: Promise<{
+process: child_process.ChildProcess;
+host: string;
+port: number;
+  }>;
 
   dispose() {
 this.server?.then(({ process }) => {
@@ -114,7 +134,7 @@ export class LLDBDapDescriptorFactory
 
   async createDebugAdapterDescriptor(
 session: vscode.DebugSession,
-executable: vscode.DebugAdapterExecutable | undefined,
+_executable: vscode.DebugAdapterExecutable | undefined,
   ): Promise {
 const config = vscode.workspace.getConfiguration(
   "lldb-dap",
@@ -128,7 +148,7 @@ export class LLDBDapDesc

[Lldb-commits] [lldb] [lldb][debugserver] Synchronize interrupt and resume signals (PR #131073)

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

jasonmolenda wrote:

I was worried about the timing in `MachProcess::PrivateResume` versus 
`Interrupt` but I think it will be OK.  `PrivateResume` does

```
void MachProcess::PrivateResume() {
  PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);

  // Set our state accordingly
  if (m_thread_actions.NumActionsWithState(eStateStepping))
SetState(eStateStepping);
  else
SetState(eStateRunning);

  // Now resume our task.
  m_task.Resume();
}
```

and `SetState` acquires the `m_state_mutex` (which `GetState` also acquires), 
so it is possible for Interrupt to call `GetState()` while this is calling 
`m_task.Resume()` which actually resumes the process, but because 
`PrivateResume` is holding the `m_exception_messages_mutex` mutex still, our 
conditional block will wait until the `m_task.Resume()` has completed and this 
function exits.  Should be OK.

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


[Lldb-commits] [lldb] [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (PR #131077)

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

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

Yes looks correct to me.

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


[Lldb-commits] [lldb] Parallelize module loading in POSIX dyld code (PR #130912)

2025-03-13 Thread Tom Yang via lldb-commits

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


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

2025-03-13 Thread via lldb-commits

cmtice wrote:

> > > Didn't quite finish, but this is what I have so far. I am wondering about 
> > > the usefulness of the `IdentifierInfo`. It started out its existence in a 
> > > completely different world than what we have now -- where the operations 
> > > were mainly defined on types instead of values. Does it bring us anything 
> > > in the new setup or could we replace it by passing ValueObjects directly?
> > 
> > 
> > When doing straight variable name lookup, I agree that there's not much 
> > added benefit to using the IdentifierNodes, but they're needed more (at the 
> > moment) when we're looking up field member names. Unless you strongly 
> > object, I'd like to keep them for now, and maybe revisit their usefulness 
> > when looking at the PR that handles field/member name resolution.
> 
> I'm somewhat tempted to say we should do the opposite (remove it now, and 
> reintroduce it later if it is needed), but it would be nice to avoid doing 
> that work if it's going to be reintroduced anyway. Can you explain why you 
> think it is necessary for child member resolution (i.e., what does it tell 
> you that cannot be obtained from a ValueObject representing the child member)?
> 
> > > The error handling isn't quite as I imagined, but that's mostly a 
> > > cosmetic thing we can handle when I get back.
> > > And I think Adrian's question of whether this should be returning 
> > > structured error messages (diagnostics) isn't quite resolved (I think we 
> > > should do that).
> > 
> > 
> > I though you had said you weren't sure that using the DiagnosticsManager 
> > here made sense? We do have somewhat formatted errors:
> > (lldb) v (1.0+c)+(1.0+d) error: expr:1:5: invalid operands to binary 
> > expression ('double' and 'mynumber') (1.0+c)+(1.0+d) ^ (lldb)
> > But if you want me to try to use the DiagnosticManager for DIL errors, I 
> > will...
> 
> I said I'm not sure about using the DiagnosticManager, and that part is still 
> true. However, that's a different question from returning structured (not 
> just formatted) errors (i.e., instances of the 
> [DiagnosticError](https://github.com/llvm/llvm-project/blob/1ff10fa82fff83bb2f0a5c1ffde6203b52bc9619/lldb/include/lldb/Utility/DiagnosticsRendering.h#L67)
>  class), which I think we should do. In the "real" expression evaluator the 
> DiagnosticManager creates the `DiagnosticError`s (actually a subclass of 
> them) from the compiler diagnostics, but there's no reason why you cannot 
> create one manually (somewhere near the BailOut function). The question is 
> whether it's simpler to do that or to reuse the functionality in the 
> DiagnosticManager (I'm sort of leaning towards not using it)

I've tried this out: I updated the FormatDiagnostics function to use 
DiagnosticDetail and RenderDiagnosticDetails.  This does give nicely formatted 
error messages similar to the full expression parser (the old error messages 
were closer to what the current frame variable implementation does). But I'm 
not really sure this is worth it? It looks to me like the diagnostics 
infrastructure was really designed to handle multiple errors.  But a key design 
point in DIL is to fail fast, i.e. as soon as we encounter a definite error. So 
in our case we will only ever be processing a single error for any given input 
(the first one), no matter how many errors the input actually contains.

I've updated the code: The new stuff, using DiagnosticDetail, etc. is in 
NewFormatDiagnostics (in DILParser.cpp).  I've left the old code, just for 
comparison, in OldFormatDiagnostics, just below. PTAL a let me know which you 
think makes more sense for us (and also let me know if I've done something not 
quite right in the new code, if we decide to go that route).


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


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

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

https://github.com/labath 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-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -30,216 +30,170 @@ namespace lldb_dap::protocol {
 
 // MARK: Base Protocol
 
-// "Request": {
-//   "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, {
-// "type": "object",
-// "description": "A client or debug adapter initiated request.",
-// "properties": {
-//   "type": {
-// "type": "string",
-// "enum": [ "request" ]
-//   },
-//   "command": {
-// "type": "string",
-// "description": "The command to execute."
-//   },
-//   "arguments": {
-// "type": [ "array", "boolean", "integer", "null", "number" , 
"object",
-// "string" ], "description": "Object containing arguments for the
-// command."
-//   }
-// },
-// "required": [ "type", "command" ]
-//   }]
-// },
+/// A client or debug adapter initiated request.
 struct Request {
+  /// Sequence number of the message (also known as message ID). The `seq` for
+  /// the first message sent by a client or debug adapter is 1, and for each
+  /// subsequent message is 1 greater than the previous message sent by that
+  /// actor. `seq` can be used to order requests, responses, and events, and to
+  /// associate requests with their corresponding responses. For protocol
+  /// messages of type `request` the sequence number can be used to cancel the
+  /// request.
   int64_t seq;
+
+  /// The command to execute.
   std::string command;
+
+  /// Object containing arguments for the command.
   std::optional rawArguments;
 };
 llvm::json::Value toJSON(const Request &);
 bool fromJSON(const llvm::json::Value &, Request &, llvm::json::Path);
 
-// "Event": {
-//   "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, {
-// "type": "object",
-// "description": "A debug adapter initiated event.",
-// "properties": {
-//   "type": {
-// "type": "string",
-// "enum": [ "event" ]
-//   },
-//   "event": {
-// "type": "string",
-// "description": "Type of event."
-//   },
-//   "body": {
-// "type": [ "array", "boolean", "integer", "null", "number" , 
"object",
-// "string" ], "description": "Event-specific information."
-//   }
-// },
-// "required": [ "type", "event" ]
-//   }]
-// },
+/// A debug adapter initiated event.
 struct Event {
+  /// Type of event.
   std::string event;
+
+  /// Event-specific information.
   std::optional rawBody;
 };
 llvm::json::Value toJSON(const Event &);
 bool fromJSON(const llvm::json::Value &, Event &, llvm::json::Path);
 
-// "Response" : {
-//   "allOf" : [
-// {"$ref" : "#/definitions/ProtocolMessage"}, {
-//   "type" : "object",
-//   "description" : "Response for a request.",
-//   "properties" : {
-// "type" : {"type" : "string", "enum" : ["response"]},
-// "request_seq" : {
-//   "type" : "integer",
-//   "description" : "Sequence number of the corresponding request."
-// },
-// "success" : {
-//   "type" : "boolean",
-//   "description" :
-//   "Outcome of the request.\nIf true, the request was successful 
"
-//   "and the `body` attribute may contain the result of the "
-//   "request.\nIf the value is false, the attribute `message` "
-//   "contains the error in short form and the `body` may contain "
-//   "additional information (see `ErrorResponse.body.error`)."
-// },
-// "command" :
-// {"type" : "string", "description" : "The command requested."},
-// "message" : {
-//   "type" : "string",
-//   "description" :
-//   "Contains the raw error in short form if `success` is "
-//   "false.\nThis raw error might be interpreted by the client and
-//   " "is not shown in the UI.\nSome predefined values exist.",
-//   "_enum" : [ "cancelled", "notStopped" ],
-//   "enumDescriptions" : [
-// "the request was cancelled.",
-// "the request may be retried once the adapter is in a 'stopped'"
-// "state."
-//   ]
-// },
-// "body" : {
-//   "type" : [
-// "array", "boolean", "integer", "null", "number", "object",
-// "string"
-//   ],
-//   "description" : "Contains request result if success is true and "
-//   "error details if success is false."
-// }
-//   },
-//   "required" : [ "type", "request_seq", "success", "command" ]
-// }
-//   ]
-// }
+/// Response for a request.
 struct Response {
   enum class Message {
+/// the request was cancelled
 cancelled,
+/// the request may be retried once the adapter is in a 'stopped' state

vogelsgesang wrote:

```suggestion
/// The request was cancelled
cancelled,
/// The request may be retried once the adapter is in a 'stopped' state
```

h

[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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

vogelsgesang wrote:

What is your overall plan for this PR?

I assume the first step is to get buy-in from all reviewers into the new 
structure for our JSON types. But what comes after? Are you planning to update 
this PR to cover all JSON types / requests / responses? Are you planning to 
land this PR for the `Source*` types only (as currently in review) and do the 
remaining types in follow-up PRs?

(Both approaches would be fine by me. Just trying to understand the approach, 
so I know when it's time to hit the "Approve" button 😉)

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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


@@ -30,216 +30,170 @@ namespace lldb_dap::protocol {
 
 // MARK: Base Protocol
 
-// "Request": {
-//   "allOf": [ { "$ref": "#/definitions/ProtocolMessage" }, {
-// "type": "object",
-// "description": "A client or debug adapter initiated request.",
-// "properties": {
-//   "type": {
-// "type": "string",
-// "enum": [ "request" ]
-//   },
-//   "command": {
-// "type": "string",
-// "description": "The command to execute."
-//   },
-//   "arguments": {
-// "type": [ "array", "boolean", "integer", "null", "number" , 
"object",
-// "string" ], "description": "Object containing arguments for the
-// command."
-//   }
-// },
-// "required": [ "type", "command" ]
-//   }]
-// },
+/// A client or debug adapter initiated request.
 struct Request {
+  /// Sequence number of the message (also known as message ID). The `seq` for
+  /// the first message sent by a client or debug adapter is 1, and for each
+  /// subsequent message is 1 greater than the previous message sent by that
+  /// actor. `seq` can be used to order requests, responses, and events, and to
+  /// associate requests with their corresponding responses. For protocol
+  /// messages of type `request` the sequence number can be used to cancel the
+  /// request.
   int64_t seq;
+
+  /// The command to execute.
   std::string command;
+
+  /// Object containing arguments for the command.
   std::optional rawArguments;

vogelsgesang wrote:

should we name this `arguments` to be in line with the JSON-schema?

(no strong feelings either way; you decide)

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


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

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


@@ -1559,10 +1560,29 @@ void Target::DidExec() {
 
 void Target::SetExecutableModule(ModuleSP &executable_sp,
  LoadDependentFiles load_dependent_files) {
+  telemetry::ScopedDispatcher helper(&m_debugger);
   Log *log = GetLog(LLDBLog::Target);
   ClearModules(false);
 
   if (executable_sp) {
+m_current_exec_mod_uuid = executable_sp->GetUUID();
+lldb::pid_t pid;
+if (ProcessSP proc = GetProcessSP())
+  pid = proc->GetID();
+helper.DispatchNow([&](telemetry::ExecModuleInfo *info) {
+  info->exec_mod = executable_sp;
+  info->exec_uuid = m_current_exec_mod_uuid;
+  info->pid = pid;
+  info->arch_name = executable_sp->GetArchitecture().GetArchitectureName();

labath wrote:

I think this is unnecessarily depriving you of potentially useful information. 
With just the architecture name, you wouldn't be able to tell a (local?) x86_64 
linux debug session from a (remote) x86_64 darwin/freebsd/etc. session. 
Consider replacing this with 
`executable_sp->GetArchitecture()->GetTriple().getTriple()`

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] Support discontinuous functions in another Disasembler overload (PR #130987)

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

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


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


[Lldb-commits] [lldb] [LLDB][NFC]Refactor common test setup into SetUp method (PR #131203)

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

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

None

>From cff4bbc4ff68e77e3093a880f55d2e17116e6f37 Mon Sep 17 00:00:00 2001
From: Vy Nguyen 
Date: Thu, 13 Mar 2025 15:57:48 -0400
Subject: [PATCH] [LLDB][NFC]Refactor common test setup into SetUp method

---
 lldb/unittests/Core/TelemetryTest.cpp | 35 ---
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/lldb/unittests/Core/TelemetryTest.cpp 
b/lldb/unittests/Core/TelemetryTest.cpp
index 72db8c17f09ea..f7dab948faba1 100644
--- a/lldb/unittests/Core/TelemetryTest.cpp
+++ b/lldb/unittests/Core/TelemetryTest.cpp
@@ -81,6 +81,20 @@ using namespace lldb_private::telemetry;
 class TelemetryTest : public testing::Test {
 public:
   lldb_private::SubsystemRAII subsystems;
+  std::vector>
+  received_entries;
+
+  void SetUp() override {
+// This would have been called by the plugin reg in a "real" pluging
+// For tests, we just call it directly.
+lldb_private::FakePlugin::Initialize();
+
+auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance();
+ASSERT_NE(ins, nullptr);
+
+ins->addDestination(
+std::make_unique(&received_entries));
+  }
 };
 
 #if LLVM_ENABLE_TELEMETRY
@@ -90,17 +104,8 @@ class TelemetryTest : public testing::Test {
 #endif
 
 TELEMETRY_TEST(TelemetryTest, PluginTest) {
-  // This would have been called by the plugin reg in a "real" plugin
-  // For tests, we just call it directly.
-  lldb_private::FakePlugin::Initialize();
-
-  auto *ins = lldb_private::telemetry::TelemetryManager::GetInstance();
-  ASSERT_NE(ins, nullptr);
-
-  std::vector>
-  received_entries;
-  ins->addDestination(
-  std::make_unique(&received_entries));
+  lldb_private::telemetry::TelemetryManager *ins =
+  lldb_private::telemetry::TelemetryManager::GetInstance();
 
   lldb_private::FakeTelemetryInfo entry;
   entry.msg = "";
@@ -115,14 +120,6 @@ TELEMETRY_TEST(TelemetryTest, PluginTest) {
 }
 
 TELEMETRY_TEST(TelemetryTest, ScopedDispatcherTest) {
-  lldb_private::FakePlugin::Initialize();
-  auto *ins = TelemetryManager::GetInstance();
-  ASSERT_NE(ins, nullptr);
-  std::vector>
-  received_entries;
-  ins->addDestination(
-  std::make_unique(&received_entries));
-
   {
 ScopedDispatcher helper(
 [](lldb_private::FakeTelemetryInfo *info) { info->num = 0; });

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Init field to nullptr. (PR #131191)

2025-03-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vy Nguyen (oontvoo)


Changes

The field is currently un-initialised and can cause a crash in some build 
configs (where it got random values)

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


1 Files Affected:

- (modified) lldb/include/lldb/Core/Telemetry.h (+1-1) 


``diff
diff --git a/lldb/include/lldb/Core/Telemetry.h 
b/lldb/include/lldb/Core/Telemetry.h
index 56259e4a673bf..29ec36b2d64d1 100644
--- a/lldb/include/lldb/Core/Telemetry.h
+++ b/lldb/include/lldb/Core/Telemetry.h
@@ -65,7 +65,7 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   // TBD: could add some memory stats here too?
 
   lldb::user_id_t debugger_id = LLDB_INVALID_UID;
-  Debugger *debugger;
+  Debugger *debugger = nullptr;
 
   // For dyn_cast, isa, etc operations.
   llvm::telemetry::KindType getKind() const override {

``




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


[Lldb-commits] [lldb] [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (PR #131077)

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

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

>From 4d27dc4928cfd57b2c2bc8b3059d2cb773cfc7ca Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 12 Mar 2025 22:25:09 -0700
Subject: [PATCH 1/2] [debugserver] Fix mutex scope in
 RNBRemote::CommDataReceived

The mutex in RNBRemote::CommDataReceived protects m_rx_packets and
should extend to the end of the function to cover the read where we
check if the list is empty.
---
 lldb/tools/debugserver/source/RNBRemote.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index 8a53094429aba..dd6da3db11814 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -1054,7 +1054,7 @@ rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum 
*type) {
 void RNBRemote::CommDataReceived(const std::string &new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
-  {
+
 // Put the packet data into the buffer in a thread safe fashion
 PThreadMutex::Locker locker(m_mutex);
 
@@ -1132,7 +1132,6 @@ void RNBRemote::CommDataReceived(const std::string 
&new_data) {
  __FUNCTION__, data[idx]);
 idx = idx + 1;
   }
-}
   }
 
   if (!m_rx_packets.empty()) {

>From 40fd7756b8a6b467b6a7397706c718c3ddbf12d0 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 13 Mar 2025 11:22:29 -0700
Subject: [PATCH 2/2] Fix indentation

---
 lldb/tools/debugserver/source/RNBRemote.cpp | 146 ++--
 1 file changed, 73 insertions(+), 73 deletions(-)

diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index dd6da3db11814..02d1544c93191 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -1055,84 +1055,84 @@ void RNBRemote::CommDataReceived(const std::string 
&new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
 
-// Put the packet data into the buffer in a thread safe fashion
-PThreadMutex::Locker locker(m_mutex);
-
-std::string data;
-// See if we have any left over data from a previous call to this
-// function?
-if (!m_rx_partial_data.empty()) {
-  // We do, so lets start with that data
-  data.swap(m_rx_partial_data);
-}
-// Append the new incoming data
-data += new_data;
-
-// Parse up the packets into gdb remote packets
-size_t idx = 0;
-const size_t data_size = data.size();
-
-while (idx < data_size) {
-  // end_idx must be one past the last valid packet byte. Start
-  // it off with an invalid value that is the same as the current
-  // index.
-  size_t end_idx = idx;
-
-  switch (data[idx]) {
-  case '+':// Look for ack
-  case '-':// Look for cancel
-  case '\x03': // ^C to halt target
-end_idx = idx + 1; // The command is one byte long...
-break;
-
-  case '$':
-// Look for a standard gdb packet?
-end_idx = data.find('#', idx + 1);
-if (end_idx == std::string::npos || end_idx + 3 > data_size) {
-  end_idx = std::string::npos;
-} else {
-  // Add two for the checksum bytes and 1 to point to the
-  // byte just past the end of this packet
-  end_idx += 3;
-}
-break;
+  // Put the packet data into the buffer in a thread safe fashion
+  PThreadMutex::Locker locker(m_mutex);
+
+  std::string data;
+  // See if we have any left over data from a previous call to this
+  // function?
+  if (!m_rx_partial_data.empty()) {
+// We do, so lets start with that data
+data.swap(m_rx_partial_data);
+  }
+  // Append the new incoming data
+  data += new_data;
+
+  // Parse up the packets into gdb remote packets
+  size_t idx = 0;
+  const size_t data_size = data.size();
+
+  while (idx < data_size) {
+// end_idx must be one past the last valid packet byte. Start
+// it off with an invalid value that is the same as the current
+// index.
+size_t end_idx = idx;
+
+switch (data[idx]) {
+case '+':// Look for ack
+case '-':// Look for cancel
+case '\x03': // ^C to halt target
+  end_idx = idx + 1; // The command is one byte long...
+  break;
 
-  default:
-break;
+case '$':
+  // Look for a standard gdb packet?
+  end_idx = data.find('#', idx + 1);
+  if (end_idx == std::string::npos || end_idx + 3 > data_size) {
+end_idx = std::string::npos;
+  } else {
+// Add two for the checksum bytes and 1 to point to the
+// byte just past the end of this packet
+end_idx += 3;
  

[Lldb-commits] [lldb] [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (PR #131077)

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

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

>From 4d27dc4928cfd57b2c2bc8b3059d2cb773cfc7ca Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 12 Mar 2025 22:25:09 -0700
Subject: [PATCH 1/3] [debugserver] Fix mutex scope in
 RNBRemote::CommDataReceived

The mutex in RNBRemote::CommDataReceived protects m_rx_packets and
should extend to the end of the function to cover the read where we
check if the list is empty.
---
 lldb/tools/debugserver/source/RNBRemote.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index 8a53094429aba..dd6da3db11814 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -1054,7 +1054,7 @@ rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum 
*type) {
 void RNBRemote::CommDataReceived(const std::string &new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
-  {
+
 // Put the packet data into the buffer in a thread safe fashion
 PThreadMutex::Locker locker(m_mutex);
 
@@ -1132,7 +1132,6 @@ void RNBRemote::CommDataReceived(const std::string 
&new_data) {
  __FUNCTION__, data[idx]);
 idx = idx + 1;
   }
-}
   }
 
   if (!m_rx_packets.empty()) {

>From 40fd7756b8a6b467b6a7397706c718c3ddbf12d0 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Thu, 13 Mar 2025 11:22:29 -0700
Subject: [PATCH 2/3] Fix indentation

---
 lldb/tools/debugserver/source/RNBRemote.cpp | 146 ++--
 1 file changed, 73 insertions(+), 73 deletions(-)

diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index dd6da3db11814..02d1544c93191 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -1055,84 +1055,84 @@ void RNBRemote::CommDataReceived(const std::string 
&new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
 
-// Put the packet data into the buffer in a thread safe fashion
-PThreadMutex::Locker locker(m_mutex);
-
-std::string data;
-// See if we have any left over data from a previous call to this
-// function?
-if (!m_rx_partial_data.empty()) {
-  // We do, so lets start with that data
-  data.swap(m_rx_partial_data);
-}
-// Append the new incoming data
-data += new_data;
-
-// Parse up the packets into gdb remote packets
-size_t idx = 0;
-const size_t data_size = data.size();
-
-while (idx < data_size) {
-  // end_idx must be one past the last valid packet byte. Start
-  // it off with an invalid value that is the same as the current
-  // index.
-  size_t end_idx = idx;
-
-  switch (data[idx]) {
-  case '+':// Look for ack
-  case '-':// Look for cancel
-  case '\x03': // ^C to halt target
-end_idx = idx + 1; // The command is one byte long...
-break;
-
-  case '$':
-// Look for a standard gdb packet?
-end_idx = data.find('#', idx + 1);
-if (end_idx == std::string::npos || end_idx + 3 > data_size) {
-  end_idx = std::string::npos;
-} else {
-  // Add two for the checksum bytes and 1 to point to the
-  // byte just past the end of this packet
-  end_idx += 3;
-}
-break;
+  // Put the packet data into the buffer in a thread safe fashion
+  PThreadMutex::Locker locker(m_mutex);
+
+  std::string data;
+  // See if we have any left over data from a previous call to this
+  // function?
+  if (!m_rx_partial_data.empty()) {
+// We do, so lets start with that data
+data.swap(m_rx_partial_data);
+  }
+  // Append the new incoming data
+  data += new_data;
+
+  // Parse up the packets into gdb remote packets
+  size_t idx = 0;
+  const size_t data_size = data.size();
+
+  while (idx < data_size) {
+// end_idx must be one past the last valid packet byte. Start
+// it off with an invalid value that is the same as the current
+// index.
+size_t end_idx = idx;
+
+switch (data[idx]) {
+case '+':// Look for ack
+case '-':// Look for cancel
+case '\x03': // ^C to halt target
+  end_idx = idx + 1; // The command is one byte long...
+  break;
 
-  default:
-break;
+case '$':
+  // Look for a standard gdb packet?
+  end_idx = data.find('#', idx + 1);
+  if (end_idx == std::string::npos || end_idx + 3 > data_size) {
+end_idx = std::string::npos;
+  } else {
+// Add two for the checksum bytes and 1 to point to the
+// byte just past the end of this packet
+end_idx += 3;
  

[Lldb-commits] [lldb] [lldb] Update dwim-print to show expanded objc instances (PR #117500)

2025-03-13 Thread via lldb-commits

jimingham wrote:

If the result of `frame var` is 30 pointer variables, I would not be happy if 
that went from 30 lines I could parse and find the variable I was interested in 
to 30 x num_ivars lines, and now I've got many pages of much more noisy output 
to scan.

When I'm listing multiple variables, I'm doing so because I want to be able to 
scan them in totality, not dive into one of them.  I definitely would not want 
this feature when more than one top level variable was being printed.  For the 
same reason, I would definitely not want to do this for any contained objects, 
just top level vars.

It would be less disruptive if we did this when printing only ONE variable.  It 
would be weird to have `v`  the children in `v array_of_nsobjects` look quite 
different from `v foo` shows?  The collection one would be fairly easy to 
understand, the difference between `v` and `v foo` is a little odder, though 
people could get used to this.

We also have to make sure that we don't end up expanding variables that people 
have summaries for, and consequently don't need or want to see the children.  
Type summaries currently have --expand off by default, and we do want to 
preserver that behavior.

https://github.com/llvm/llvm-project/pull/117500
___
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-13 Thread Daniel Chen via lldb-commits

DanielCChen wrote:

> Wouldn't it be more maintainable to just force the value to OFF for AIX where 
> the `option()` is defined?

Unfortunately, the cmake command line option `-D 
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON` overrides the `option()` in the cmake 
file.

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


[Lldb-commits] [lldb] 998511c - [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (#131077)

2025-03-13 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-03-13T15:12:19-07:00
New Revision: 998511c8ef577f330c90bf32db37d5f8305c53f3

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

LOG: [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (#131077)

The mutex in RNBRemote::CommDataReceived protects m_rx_packets and
should extend to the end of the function to cover the read where we
check if the list is empty.

Added: 


Modified: 
lldb/tools/debugserver/source/RNBRemote.cpp

Removed: 




diff  --git a/lldb/tools/debugserver/source/RNBRemote.cpp 
b/lldb/tools/debugserver/source/RNBRemote.cpp
index 8a53094429aba..c225ac1667b54 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -1054,84 +1054,82 @@ rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum 
*type) {
 void RNBRemote::CommDataReceived(const std::string &new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
-  {
-// Put the packet data into the buffer in a thread safe fashion
-PThreadMutex::Locker locker(m_mutex);
-
-std::string data;
-// See if we have any left over data from a previous call to this
-// function?
-if (!m_rx_partial_data.empty()) {
-  // We do, so lets start with that data
-  data.swap(m_rx_partial_data);
-}
-// Append the new incoming data
-data += new_data;
-
-// Parse up the packets into gdb remote packets
-size_t idx = 0;
-const size_t data_size = data.size();
-
-while (idx < data_size) {
-  // end_idx must be one past the last valid packet byte. Start
-  // it off with an invalid value that is the same as the current
-  // index.
-  size_t end_idx = idx;
-
-  switch (data[idx]) {
-  case '+':// Look for ack
-  case '-':// Look for cancel
-  case '\x03': // ^C to halt target
-end_idx = idx + 1; // The command is one byte long...
-break;
 
-  case '$':
-// Look for a standard gdb packet?
-end_idx = data.find('#', idx + 1);
-if (end_idx == std::string::npos || end_idx + 3 > data_size) {
-  end_idx = std::string::npos;
-} else {
-  // Add two for the checksum bytes and 1 to point to the
-  // byte just past the end of this packet
-  end_idx += 3;
-}
-break;
+  // Put the packet data into the buffer in a thread safe fashion
+  PThreadMutex::Locker locker(m_mutex);
+
+  std::string data;
+  // See if we have any left over data from a previous call to this
+  // function?
+  if (!m_rx_partial_data.empty()) {
+// We do, so lets start with that data
+data.swap(m_rx_partial_data);
+  }
+  // Append the new incoming data
+  data += new_data;
+
+  // Parse up the packets into gdb remote packets
+  size_t idx = 0;
+  const size_t data_size = data.size();
+
+  while (idx < data_size) {
+// end_idx must be one past the last valid packet byte. Start
+// it off with an invalid value that is the same as the current
+// index.
+size_t end_idx = idx;
+
+switch (data[idx]) {
+case '+':// Look for ack
+case '-':// Look for cancel
+case '\x03': // ^C to halt target
+  end_idx = idx + 1; // The command is one byte long...
+  break;
 
-  default:
-break;
+case '$':
+  // Look for a standard gdb packet?
+  end_idx = data.find('#', idx + 1);
+  if (end_idx == std::string::npos || end_idx + 3 > data_size) {
+end_idx = std::string::npos;
+  } else {
+// Add two for the checksum bytes and 1 to point to the
+// byte just past the end of this packet
+end_idx += 3;
   }
+  break;
 
-  if (end_idx == std::string::npos) {
-// Not all data may be here for the packet yet, save it for
-// next time through this function.
-m_rx_partial_data += data.substr(idx);
-// DNBLogThreadedIf (LOG_RNB_MAX, "%8d RNBRemote::%s saving data for
-// later[%u, npos):
-// '%s'",(uint32_t)m_comm.Timer().ElapsedMicroSeconds(true),
-// __FUNCTION__, idx, m_rx_partial_data.c_str());
-idx = end_idx;
-  } else if (idx < end_idx) {
-m_packets_recvd++;
-// Hack to get rid of initial '+' ACK???
-if (m_packets_recvd == 1 && (end_idx == idx + 1) && data[idx] == '+') {
-  // DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s throwing 
first
-  // ACK away[%u, npos):
-  // '+'",(uint32_t)m_comm.Timer().ElapsedMicroSeconds(true),
-  // __FUNCTION__, idx);
-} else {
-  // We have a valid packet...
- 

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

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

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


[Lldb-commits] [lldb] [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (PR #131077)

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

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


[Lldb-commits] [lldb] [lldb] Remove use of comma operator (NFC) (PR #131233)

2025-03-13 Thread via lldb-commits

jimingham wrote:

You should also check that the update succeeded before getting its value.

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


[Lldb-commits] [lldb] 8b9031f - [lldb-dap] Support vscode launch URLs (#125843)

2025-03-13 Thread via lldb-commits

Author: Adrian Vogelsgesang
Date: 2025-03-13T23:49:05+01:00
New Revision: 8b9031f245a268c6acb331de5ea68da20be37051

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

LOG: [lldb-dap] Support vscode launch URLs (#125843)

This commit adds support for starting debug sessions through special
`vscode://llvm-vs-code-extensions.lldb-dap/start?config={launch-config}`
URIs. This allows tighter integration with custom scripts. One potential
use case is providing similar functionality to `xcdebug`, see #125777
for some discussion on that use case.

The functionality was inspired by @vadimcn's CodeLLDB extension, which
[provides similar
functionality](https://github.com/vadimcn/codelldb/blob/master/MANUAL.md#debugging-externally-launched-code).

Added: 
lldb/tools/lldb-dap/src-ts/uri-launch-handler.ts

Modified: 
lldb/tools/lldb-dap/README.md
lldb/tools/lldb-dap/package.json
lldb/tools/lldb-dap/src-ts/extension.ts

Removed: 




diff  --git a/lldb/tools/lldb-dap/README.md b/lldb/tools/lldb-dap/README.md
index 123869a033724..725e9cf63e02a 100644
--- a/lldb/tools/lldb-dap/README.md
+++ b/lldb/tools/lldb-dap/README.md
@@ -174,6 +174,25 @@ The default hostname being used `localhost`.
 }
 ```
 
+### Launching via `vscode://` URIs
+
+Debugging sessions can also be starting using special URIs.
+
+The `vscode://llvm-vs-code-extensions.lldb-dap/start?config={launch-config}`
+URI accepts a [URL-encoded](https://en.wikipedia.org/wiki/Percent-encoding)
+JSON launch config. The most frequently used arguments (`request`, `program`,
+`args`, `cwd`, `pid`, ...) can also specified directly, e.g.
+`vscode://llvm-vs-code-extensions.lldb-dap/start?request=attach&pid=1234`, or
+`vscode://llvm-vs-code-extensions.lldb-dap/start?program=ls&args=-a&args=/etc`.
+
+This is useful for integration with custom scripts to start debugging
+sessions. The URI might be printed to the terminal, potentially using
+[OSC-8 
hyperlinks](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda),
+or passed to `code --open-url` or `xdg-open`, although mileage may vary 
depending
+on your specific debugging setup. E.g., `code --open-url` will not work when 
using a
+SSH remote session. Furthermore, placeholders such as `${workspaceFolder}` are 
not
+supported within launch URLs.
+
 ### Configuration Settings Reference
 
 For both launch and attach configurations, lldb-dap accepts the following 
`lldb-dap`
@@ -328,4 +347,4 @@ The source code is part of the [LLVM 
repository](https://github.com/llvm/llvm-pr
 We use Github's [issue 
tracker](https://github.com/llvm/llvm-project/issues?q=label%3Alldb-dap) and 
patches can be submitted via [pull 
requests](https://github.com/llvm/llvm-project/pulls?q=label%3Alldb-dap).
 Furthermore, there is a [LLDB 
category](https://discourse.llvm.org/c/subprojects/lldb/8) on the LLVM 
discourse forum.
 
-For instructions on how to get started with development on lldb-dap, see the 
"[Contributing to lldb-dap](https://lldb.llvm.org/resources/lldbdap.html)"
+For instructions on how to get started with development on lldb-dap, see the 
"[Contributing to lldb-dap](https://lldb.llvm.org/resources/lldbdap.html)" 
guide.

diff  --git a/lldb/tools/lldb-dap/package.json 
b/lldb/tools/lldb-dap/package.json
index cd450a614b3f7..428624f46feba 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -35,7 +35,8 @@
 "typescript": "^5.7.3"
   },
   "activationEvents": [
-"onDebug"
+"onDebug",
+"onUri"
   ],
   "main": "./out/extension",
   "scripts": {

diff  --git a/lldb/tools/lldb-dap/src-ts/extension.ts 
b/lldb/tools/lldb-dap/src-ts/extension.ts
index a07bcdebcb68b..f0c7fb5bd1a71 100644
--- a/lldb/tools/lldb-dap/src-ts/extension.ts
+++ b/lldb/tools/lldb-dap/src-ts/extension.ts
@@ -5,6 +5,7 @@ import {
   isExecutable,
 } from "./debug-adapter-factory";
 import { DisposableContext } from "./disposable-context";
+import { LaunchUriHandler } from "./uri-launch-handler";
 
 /**
  * This class represents the extension and manages its life cycle. Other 
extensions
@@ -37,6 +38,10 @@ export class LLDBDapExtension extends DisposableContext {
 }
   }),
 );
+
+this.pushSubscription(
+  vscode.window.registerUriHandler(new LaunchUriHandler())
+);
   }
 }
 

diff  --git a/lldb/tools/lldb-dap/src-ts/uri-launch-handler.ts 
b/lldb/tools/lldb-dap/src-ts/uri-launch-handler.ts
new file mode 100644
index 0..0c3b1e9a00d9e
--- /dev/null
+++ b/lldb/tools/lldb-dap/src-ts/uri-launch-handler.ts
@@ -0,0 +1,78 @@
+import * as vscode from "vscode";
+
+export class LaunchUriHandler implements vscode.UriHandler {
+async handleUri(uri: vscode.Uri) {
+try {
+const params = new URLSearchParams(uri.query);
+i

[Lldb-commits] [lldb] d1deaed - [lldb] Split some lldb-server tests to avoid timeout (#129614)

2025-03-13 Thread via lldb-commits

Author: David Peixotto
Date: 2025-03-13T15:54:45-07:00
New Revision: d1deaed0d284f16870f3236ec2efe7d29308a56a

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

LOG: [lldb] Split some lldb-server tests to avoid timeout (#129614)

Split test cases out of TestLldbGdbServer.py and TestGdbRemoteFork.py
into separate files to avoid hitting the 600s timeout limit. The
inferior used by these tests (main.cpp) takes approximately 20s to
compile with a Debug build of clang, causing timeouts when a single test
file contains many tests. By grouping similar tests into separate files,
we can prevent timeouts and improve overall test efficiency.

Added: 
lldb/test/API/tools/lldb-server/TestGdbRemoteForkResume.py
lldb/test/API/tools/lldb-server/TestGdbRemote_qMemoryRegion.py
lldb/test/API/tools/lldb-server/TestGdbRemote_qRegisterInfo.py
lldb/test/API/tools/lldb-server/qSupported/Makefile
lldb/test/API/tools/lldb-server/qSupported/TestGdbRemote_qSupported.py
lldb/test/API/tools/lldb-server/qSupported/main.c

Modified: 
lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
index ae98b4e0f6935..13c4a85f51f7f 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py
@@ -190,52 +190,6 @@ def test_vkill_parent(self):
 def test_vkill_both(self):
 self.vkill_test(kill_parent=True, kill_child=True)
 
-@add_test_categories(["fork"])
-def test_c_parent(self):
-self.resume_one_test(run_order=["parent", "parent"])
-
-@add_test_categories(["fork"])
-def test_c_child(self):
-self.resume_one_test(run_order=["child", "child"])
-
-@add_test_categories(["fork"])
-def test_c_parent_then_child(self):
-self.resume_one_test(run_order=["parent", "parent", "child", "child"])
-
-@add_test_categories(["fork"])
-def test_c_child_then_parent(self):
-self.resume_one_test(run_order=["child", "child", "parent", "parent"])
-
-@add_test_categories(["fork"])
-def test_c_interspersed(self):
-self.resume_one_test(run_order=["parent", "child", "parent", "child"])
-
-@add_test_categories(["fork"])
-def test_vCont_parent(self):
-self.resume_one_test(run_order=["parent", "parent"], use_vCont=True)
-
-@add_test_categories(["fork"])
-def test_vCont_child(self):
-self.resume_one_test(run_order=["child", "child"], use_vCont=True)
-
-@add_test_categories(["fork"])
-def test_vCont_parent_then_child(self):
-self.resume_one_test(
-run_order=["parent", "parent", "child", "child"], use_vCont=True
-)
-
-@add_test_categories(["fork"])
-def test_vCont_child_then_parent(self):
-self.resume_one_test(
-run_order=["child", "child", "parent", "parent"], use_vCont=True
-)
-
-@add_test_categories(["fork"])
-def test_vCont_interspersed(self):
-self.resume_one_test(
-run_order=["parent", "child", "parent", "child"], use_vCont=True
-)
-
 @add_test_categories(["fork"])
 def test_vCont_two_processes(self):
 parent_pid, parent_tid, child_pid, child_tid = self.start_fork_test(

diff  --git a/lldb/test/API/tools/lldb-server/TestGdbRemoteForkResume.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkResume.py
new file mode 100644
index 0..d7fe4d026dd8d
--- /dev/null
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteForkResume.py
@@ -0,0 +1,60 @@
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+from fork_testbase import GdbRemoteForkTestBase
+
+
+class TestGdbRemoteForkResume(GdbRemoteForkTestBase):
+def setUp(self):
+GdbRemoteForkTestBase.setUp(self)
+if self.getPlatform() == "linux" and self.getArchitecture() in [
+"arm",
+"aarch64",
+]:
+self.skipTest("Unsupported for Arm/AArch64 Linux")
+
+@add_test_categories(["fork"])
+def test_c_parent(self):
+self.resume_one_test(run_order=["parent", "parent"])
+
+@add_test_categories(["fork"])
+def test_c_child(self):
+self.resume_one_test(run_order=["child", "child"])
+
+@add_test_categories(["fork"])
+def test_c_parent_then_child(self):
+self.resume_one_test(run_order=["parent", "parent", "child", "child"])
+
+@add_test_categories(["fork"])
+def test_c_child_then_parent(self):
+self.resume_one_test(run_order=["child", "child", "parent", "parent"])
+
+@add_test_categories(["fork"])
+def test_c_interspersed(self):
+ 

[Lldb-commits] [lldb] [lldb] Split some lldb-server tests to avoid timeout (PR #129614)

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

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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

ashgti wrote:

> What is your overall plan for this PR?
> 
> I assume the first step is to get buy-in from all reviewers into the new 
> structure for our JSON types. But what comes after? Are you planning to 
> update this PR to cover all JSON types / requests / responses? Are you 
> planning to land this PR for the `Source*` types only (as currently in 
> review) and do the remaining types in follow-up PRs?
> 
> (Both approaches would be fine by me. Just trying to understand the approach, 
> so I know when it's time to hit the "Approve" button 😉)

I was thinking of doing this more incrementally. I was planning to build on 
this for handling the 'cancel' request first but then I'd like to follow up 
with requests to use the new explicit types for handling arguments and 
responses.

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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

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

>From f26c9a79ca234bee77ec1a9694bf8be2d0e3745c Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Thu, 6 Mar 2025 13:21:10 +0100
Subject: [PATCH 1/6] [lldb-dap] Updating RequestHandler to encode/decode
 arguments and response.

This is a work in progress refactor to add explicit types instead of
generic 'llvm::json::Value' types to the DAP protocol.

This updates RequestHandler to have take the type of the arguments and
response body for serialization for requests.

The 'source' request is updated to show how the new flow works.
---
 lldb/tools/lldb-dap/DAP.cpp   |  57 +++--
 lldb/tools/lldb-dap/DAP.h |   4 +-
 lldb/tools/lldb-dap/DAPForward.h  |   2 +
 .../tools/lldb-dap/Handler/RequestHandler.cpp |  11 +-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 214 --
 .../lldb-dap/Handler/SourceRequestHandler.cpp | 104 ++---
 lldb/tools/lldb-dap/Protocol.cpp  |  44 
 lldb/tools/lldb-dap/Protocol.h| 131 +++
 8 files changed, 381 insertions(+), 186 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 4080e2c211035..9d42af2d7091f 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -8,10 +8,12 @@
 
 #include "DAP.h"
 #include "DAPLog.h"
+#include "Handler/RequestHandler.h"
 #include "Handler/ResponseHandler.h"
 #include "JSONUtils.h"
 #include "LLDBUtils.h"
 #include "OutputRedirector.h"
+#include "Protocol.h"
 #include "Transport.h"
 #include "lldb/API/SBBreakpoint.h"
 #include "lldb/API/SBCommandInterpreter.h"
@@ -25,6 +27,7 @@
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -41,6 +44,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if defined(_WIN32)
@@ -663,31 +667,23 @@ void DAP::SetTarget(const lldb::SBTarget target) {
 }
 
 bool DAP::HandleObject(const protocol::Message &M) {
-  // FIXME: Directly handle `Message` instead of serializing to JSON.
-  llvm::json::Value v = toJSON(M);
-  llvm::json::Object object = *v.getAsObject();
-  const auto packet_type = GetString(object, "type");
-  if (packet_type == "request") {
-const auto command = GetString(object, "command");
-
-auto new_handler_pos = request_handlers.find(command);
+  if (const auto *req = std::get_if(&M)) {
+auto new_handler_pos = request_handlers.find(req->command);
 if (new_handler_pos != request_handlers.end()) {
-  (*new_handler_pos->second)(object);
+  (*new_handler_pos->second)(*req);
   return true; // Success
 }
 
 DAP_LOG(log, "({0}) error: unhandled command '{1}'",
-transport.GetClientName(), command);
+transport.GetClientName(), req->command);
 return false; // Fail
   }
 
-  if (packet_type == "response") {
-auto id = GetInteger(object, "request_seq").value_or(0);
-
+  if (const auto *resp = std::get_if(&M)) {
 std::unique_ptr response_handler;
 {
   std::lock_guard locker(call_mutex);
-  auto inflight = inflight_reverse_requests.find(id);
+  auto inflight = inflight_reverse_requests.find(resp->request_seq);
   if (inflight != inflight_reverse_requests.end()) {
 response_handler = std::move(inflight->second);
 inflight_reverse_requests.erase(inflight);
@@ -695,19 +691,31 @@ bool DAP::HandleObject(const protocol::Message &M) {
 }
 
 if (!response_handler)
-  response_handler = std::make_unique("", id);
+  response_handler =
+  std::make_unique("", resp->request_seq);
 
 // Result should be given, use null if not.
-if (GetBoolean(object, "success").value_or(false)) {
-  llvm::json::Value Result = nullptr;
-  if (auto *B = object.get("body"))
-Result = std::move(*B);
-  (*response_handler)(Result);
+if (resp->success) {
+  (*response_handler)(resp->rawBody);
 } else {
-  llvm::StringRef message = GetString(object, "message");
-  if (message.empty()) {
-message = "Unknown error, response failed";
+  std::string message = "Unknown error, response failed";
+  if (resp->message) {
+message = std::visit(
+llvm::makeVisitor(
+[](const std::string &message) -> std::string {
+  return message;
+},
+[](const protocol::Response::Message &message) -> std::string {
+  switch (message) {
+  case protocol::Response::Message::cancelled:
+return "cancelled";
+  case protocol::Response::Message::notStopped:
+return "notStopped";
+  }
+}),
+*resp->message);
   }
+
   (*response_handler)(l

[Lldb-commits] [lldb] [lldb][lldb-dap] Return optional from json utils (PR #129919)

2025-03-13 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.

all good then!

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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

2025-03-13 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 5929de8c7731748bf58ad9b1fedfed75e7aae455 
b9e3f25cfd11e396b80a4624bff6953e73a53334 --extensions cpp,h -- 
lldb/tools/lldb-dap/DAP.cpp lldb/tools/lldb-dap/DAP.h 
lldb/tools/lldb-dap/DAPForward.h 
lldb/tools/lldb-dap/Handler/DisconnectRequestHandler.cpp 
lldb/tools/lldb-dap/Handler/RequestHandler.cpp 
lldb/tools/lldb-dap/Handler/RequestHandler.h 
lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp 
lldb/tools/lldb-dap/LLDBUtils.cpp lldb/tools/lldb-dap/LLDBUtils.h 
lldb/tools/lldb-dap/Protocol.cpp lldb/tools/lldb-dap/Protocol.h 
lldb/tools/lldb-dap/lldb-dap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/tools/lldb-dap/LLDBUtils.h b/lldb/tools/lldb-dap/LLDBUtils.h
index b514aa3095..aef21c2895 100644
--- a/lldb/tools/lldb-dap/LLDBUtils.h
+++ b/lldb/tools/lldb-dap/LLDBUtils.h
@@ -10,9 +10,9 @@
 #define LLDB_TOOLS_LLDB_DAP_LLDBUTILS_H
 
 #include "DAPForward.h"
-#include "lldb/API/SBError.h"
 #include "lldb/API/SBDebugger.h"
 #include "lldb/API/SBEnvironment.h"
+#include "lldb/API/SBError.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"

``




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


[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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

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

>From f26c9a79ca234bee77ec1a9694bf8be2d0e3745c Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Thu, 6 Mar 2025 13:21:10 +0100
Subject: [PATCH 1/7] [lldb-dap] Updating RequestHandler to encode/decode
 arguments and response.

This is a work in progress refactor to add explicit types instead of
generic 'llvm::json::Value' types to the DAP protocol.

This updates RequestHandler to have take the type of the arguments and
response body for serialization for requests.

The 'source' request is updated to show how the new flow works.
---
 lldb/tools/lldb-dap/DAP.cpp   |  57 +++--
 lldb/tools/lldb-dap/DAP.h |   4 +-
 lldb/tools/lldb-dap/DAPForward.h  |   2 +
 .../tools/lldb-dap/Handler/RequestHandler.cpp |  11 +-
 lldb/tools/lldb-dap/Handler/RequestHandler.h  | 214 --
 .../lldb-dap/Handler/SourceRequestHandler.cpp | 104 ++---
 lldb/tools/lldb-dap/Protocol.cpp  |  44 
 lldb/tools/lldb-dap/Protocol.h| 131 +++
 8 files changed, 381 insertions(+), 186 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 4080e2c211035..9d42af2d7091f 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -8,10 +8,12 @@
 
 #include "DAP.h"
 #include "DAPLog.h"
+#include "Handler/RequestHandler.h"
 #include "Handler/ResponseHandler.h"
 #include "JSONUtils.h"
 #include "LLDBUtils.h"
 #include "OutputRedirector.h"
+#include "Protocol.h"
 #include "Transport.h"
 #include "lldb/API/SBBreakpoint.h"
 #include "lldb/API/SBCommandInterpreter.h"
@@ -25,6 +27,7 @@
 #include "lldb/lldb-defines.h"
 #include "lldb/lldb-enumerations.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -41,6 +44,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if defined(_WIN32)
@@ -663,31 +667,23 @@ void DAP::SetTarget(const lldb::SBTarget target) {
 }
 
 bool DAP::HandleObject(const protocol::Message &M) {
-  // FIXME: Directly handle `Message` instead of serializing to JSON.
-  llvm::json::Value v = toJSON(M);
-  llvm::json::Object object = *v.getAsObject();
-  const auto packet_type = GetString(object, "type");
-  if (packet_type == "request") {
-const auto command = GetString(object, "command");
-
-auto new_handler_pos = request_handlers.find(command);
+  if (const auto *req = std::get_if(&M)) {
+auto new_handler_pos = request_handlers.find(req->command);
 if (new_handler_pos != request_handlers.end()) {
-  (*new_handler_pos->second)(object);
+  (*new_handler_pos->second)(*req);
   return true; // Success
 }
 
 DAP_LOG(log, "({0}) error: unhandled command '{1}'",
-transport.GetClientName(), command);
+transport.GetClientName(), req->command);
 return false; // Fail
   }
 
-  if (packet_type == "response") {
-auto id = GetInteger(object, "request_seq").value_or(0);
-
+  if (const auto *resp = std::get_if(&M)) {
 std::unique_ptr response_handler;
 {
   std::lock_guard locker(call_mutex);
-  auto inflight = inflight_reverse_requests.find(id);
+  auto inflight = inflight_reverse_requests.find(resp->request_seq);
   if (inflight != inflight_reverse_requests.end()) {
 response_handler = std::move(inflight->second);
 inflight_reverse_requests.erase(inflight);
@@ -695,19 +691,31 @@ bool DAP::HandleObject(const protocol::Message &M) {
 }
 
 if (!response_handler)
-  response_handler = std::make_unique("", id);
+  response_handler =
+  std::make_unique("", resp->request_seq);
 
 // Result should be given, use null if not.
-if (GetBoolean(object, "success").value_or(false)) {
-  llvm::json::Value Result = nullptr;
-  if (auto *B = object.get("body"))
-Result = std::move(*B);
-  (*response_handler)(Result);
+if (resp->success) {
+  (*response_handler)(resp->rawBody);
 } else {
-  llvm::StringRef message = GetString(object, "message");
-  if (message.empty()) {
-message = "Unknown error, response failed";
+  std::string message = "Unknown error, response failed";
+  if (resp->message) {
+message = std::visit(
+llvm::makeVisitor(
+[](const std::string &message) -> std::string {
+  return message;
+},
+[](const protocol::Response::Message &message) -> std::string {
+  switch (message) {
+  case protocol::Response::Message::cancelled:
+return "cancelled";
+  case protocol::Response::Message::notStopped:
+return "notStopped";
+  }
+}),
+*resp->message);
   }
+
   (*response_handler)(l

[Lldb-commits] [lldb] [lldb][debugserver] Synchronize interrupt and resume signals (PR #131073)

2025-03-13 Thread via lldb-commits


@@ -1573,6 +1576,8 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 }
 
 bool MachProcess::Interrupt() {
+  PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
+

jimingham wrote:

Would it be better to put this mutex lock after the IsRunning(state) on line 
1582.  You aren't doing anything that requires the mutex till then, and in 
general it's better to scope this as narrowly as possible.

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


[Lldb-commits] [lldb] [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (PR #131077)

2025-03-13 Thread via lldb-commits


@@ -1054,7 +1054,7 @@ rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum 
*type) {
 void RNBRemote::CommDataReceived(const std::string &new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
-  {
+
 // Put the packet data into the buffer in a thread safe fashion
 PThreadMutex::Locker locker(m_mutex);

jimingham wrote:

Should you also fix the indentation?

https://github.com/llvm/llvm-project/pull/131077
___
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] setVariable request should send the correct response (PR #130773)

2025-03-13 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


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


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

2025-03-13 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


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


[Lldb-commits] [lldb] [lldb-dap] Support vscode launch URLs (PR #125843)

2025-03-13 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


https://github.com/llvm/llvm-project/pull/125843
___
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-13 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/20] [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]Define TargetInfo for collecting data about a target (PR #127834)

2025-03-13 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][debugserver] Synchronize interrupt and resume signals (PR #131073)

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


@@ -1573,6 +1576,8 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 }
 
 bool MachProcess::Interrupt() {
+  PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
+

JDevlieghere wrote:

I was worried about lock order inversion between the exception mutex and the 
state mutex. That said, how we're protecting GetState is already questionable 
(i.e. nothing guarantees the state hasn't changed between the function returned 
you read the value) so I can tighten the scope and we can fix the issue if it 
comes up when we try to fix the state locking. 

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


[Lldb-commits] [lldb] [lldb][debugserver] Synchronize interrupt and resume signals (PR #131073)

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

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

>From 48ab516f56328fe101fe3fe1cd22a06ec1a033e2 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 12 Mar 2025 22:07:41 -0700
Subject: [PATCH 1/2] [lldb] Synchronize interrupt and resume signals in
 debugserver

This PR fixes a race condition in debugserver where the main thread
calls MachProcess::Interrupt, setting `m_sent_interrupt_signo` while
the exception monitoring thread is checking value of the variable.

I was on the fence between introducing a new mutex and reusing the
existing exception mutex. With the notable exception of
MachProcess::Interrupt, all the other places where we were already
locking this mutex before accessing the variable. I renamed the mutex to
make it clear that it's now protecting more than the exception messages.

Jason, while investigating a real issue, had a suspicion there was race
condition related to interrupts and I was able to narrow it down by
building debugserver with TSan.
---
 .../debugserver/source/MacOSX/MachProcess.h   |  6 +++---
 .../debugserver/source/MacOSX/MachProcess.mm  | 19 ---
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
index db673693a1b21..ec0a13b482267 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h
@@ -427,7 +427,7 @@ class MachProcess {
   m_profile_data_mutex; // Multithreaded protection for profile info data
   std::vector
   m_profile_data; // Profile data, must be protected by 
m_profile_data_mutex
-  PThreadEvent m_profile_events; // Used for the profile thread cancellable 
wait  
+  PThreadEvent m_profile_events; // Used for the profile thread cancellable 
wait
   DNBThreadResumeActions m_thread_actions; // The thread actions for the 
current
// MachProcess::Resume() call
   MachException::Message::collection m_exception_messages; // A collection of
@@ -435,8 +435,8 @@ class MachProcess {
// caught when
// listening to the
// exception port
-  PThreadMutex m_exception_messages_mutex; // Multithreaded protection for
-   // m_exception_messages
+  PThreadMutex m_exception_and_signal_mutex; // Multithreaded protection for
+ // exceptions and signals.
 
   MachThreadList m_thread_list; // A list of threads that is maintained/updated
 // after each stop
diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
index a2179bf2f91e5..7dcc04c07bbff 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -528,7 +528,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary 
*options,
   m_profile_data_mutex(PTHREAD_MUTEX_RECURSIVE), m_profile_data(),
   m_profile_events(0, eMachProcessProfileCancel), m_thread_actions(),
   m_exception_messages(),
-  m_exception_messages_mutex(PTHREAD_MUTEX_RECURSIVE), m_thread_list(),
+  m_exception_and_signal_mutex(PTHREAD_MUTEX_RECURSIVE), m_thread_list(),
   m_activities(), m_state(eStateUnloaded),
   m_state_mutex(PTHREAD_MUTEX_RECURSIVE), m_events(0, kAllEventsMask),
   m_private_events(0, kAllEventsMask), m_breakpoints(), m_watchpoints(),
@@ -1338,8 +1338,11 @@ static bool mach_header_validity_test(uint32_t magic, 
uint32_t cputype) {
   m_stop_count = 0;
   m_thread_list.Clear();
   {
-PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);
+PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
 m_exception_messages.clear();
+m_sent_interrupt_signo = 0;
+m_auto_resume_signo = 0;
+
   }
   m_activities.Clear();
   StopProfileThread();
@@ -1573,6 +1576,8 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 }
 
 bool MachProcess::Interrupt() {
+  PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
+
   nub_state_t state = GetState();
   if (IsRunning(state)) {
 if (m_sent_interrupt_signo == 0) {
@@ -1728,7 +1733,7 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 m_thread_actions.Append(thread_action);
 m_thread_actions.SetDefaultThreadActionIfNeeded(eStateRunning, 0);
 
-PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);
+PTHREAD_MUTEX_LOCKER(locker, m_exception_and_signal_mutex);
 
 ReplyToAllExceptions();
   }
@@ -1854,7 +1859,7 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
 }
 
 void MachProcess::ReplyToAllExceptions() {
-  PTHREAD_MUTEX_LOCKER(locker, m

[Lldb-commits] [lldb] 09a36c8 - [lldb][NFC] Correct whitespace in SearchForKernelWithDebugHints

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

Author: Jason Molenda
Date: 2025-03-13T10:08:09-07:00
New Revision: 09a36c82793ba32b87faf11fbfc2e7624f25e92e

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

LOG: [lldb][NFC] Correct whitespace in SearchForKernelWithDebugHints

Added: 


Modified: 

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 60724f3900ae7..fe9f5d086da2c 100644
--- 
a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -254,31 +254,33 @@ 
DynamicLoaderDarwinKernel::SearchForKernelWithDebugHints(Process *process) {
 
   uint8_t uval[8];
   if (process->GetAddressByteSize() == 8) {
-  for (size_t i = 0; kernel_addresses_64[i] != LLDB_INVALID_ADDRESS; i++) {
-  if (process->ReadMemoryFromInferior (kernel_addresses_64[i], uval, 8, 
read_err) == 8)
-  {
-  DataExtractor data (&uval, 8, process->GetByteOrder(), 
process->GetAddressByteSize());
-  lldb::offset_t offset = 0;
-  uint64_t addr = data.GetU64 (&offset);
-  if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
-  return addr;
-  }
+for (size_t i = 0; kernel_addresses_64[i] != LLDB_INVALID_ADDRESS; i++) {
+  if (process->ReadMemoryFromInferior(kernel_addresses_64[i], uval, 8,
+  read_err) == 8) {
+DataExtractor data(&uval, 8, process->GetByteOrder(),
+   process->GetAddressByteSize());
+lldb::offset_t offset = 0;
+uint64_t addr = data.GetU64(&offset);
+if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
+  return addr;
+}
   }
-  }
+}
   }
 
   if (process->GetAddressByteSize() == 4) {
-  for (size_t i = 0; kernel_addresses_32[i] != LLDB_INVALID_ADDRESS; i++) {
-  if (process->ReadMemoryFromInferior (kernel_addresses_32[i], uval, 4, 
read_err) == 4)
-  {
-  DataExtractor data (&uval, 4, process->GetByteOrder(), 
process->GetAddressByteSize());
-  lldb::offset_t offset = 0;
-  uint32_t addr = data.GetU32 (&offset);
-  if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
-  return addr;
-  }
+for (size_t i = 0; kernel_addresses_32[i] != LLDB_INVALID_ADDRESS; i++) {
+  if (process->ReadMemoryFromInferior(kernel_addresses_32[i], uval, 4,
+  read_err) == 4) {
+DataExtractor data(&uval, 4, process->GetByteOrder(),
+   process->GetAddressByteSize());
+lldb::offset_t offset = 0;
+uint32_t addr = data.GetU32(&offset);
+if (CheckForKernelImageAtAddress(addr, process).IsValid()) {
+  return addr;
+}
   }
-  }
+}
   }
 
   return LLDB_INVALID_ADDRESS;



___
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] Implement jump to cursor (PR #130503)

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


@@ -0,0 +1,119 @@
+//===-- GoToRequestHandler.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"
+
+namespace lldb_dap {
+
+/// Creates an \p StoppedEvent with the reason \a goto
+static void SendThreadGotoEvent(DAP &dap, lldb::tid_t thread_id) {
+

vogelsgesang wrote:

spurious empty line

```suggestion
static void SendThreadGotoEvent(DAP &dap, lldb::tid_t thread_id) {
```

https://github.com/llvm/llvm-project/pull/130503
___
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-13 Thread Vy Nguyen via lldb-commits


@@ -1064,6 +1065,29 @@ 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.
+  UUID exec_uuid;
+  // Check if there is (still) a valid target and get the debugger and 
exec_uuid
+  // from it.
+  TargetSP target_sp(Debugger::FindTargetWithProcessID(m_pid));
+  if (target_sp) {
+helper.SetDebugger(&(target_sp->GetDebugger()));
+exec_uuid = target_sp->GetExecModuleUUID();

oontvoo wrote:

I can't seem to reproduce it now but I was getting a crash (due to accessing 
the ModuleSP object here), hence the check on the TargetSP and the code to save 
it.

But anyway,  i'll revert that back to the simple case. We can fix the crash 
if/when it manifest again

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-13 Thread Vy Nguyen via lldb-commits


@@ -1064,6 +1065,29 @@ 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.
+  UUID exec_uuid;
+  // Check if there is (still) a valid target and get the debugger and 
exec_uuid
+  // from it.
+  TargetSP target_sp(Debugger::FindTargetWithProcessID(m_pid));
+  if (target_sp) {

oontvoo wrote:

done

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] [debugserver] Fix mutex scope in RNBRemote::CommDataReceived (PR #131077)

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


@@ -1054,7 +1054,7 @@ rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum 
*type) {
 void RNBRemote::CommDataReceived(const std::string &new_data) {
   //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8d RNBRemote::%s called",
   //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
-  {
+
 // Put the packet data into the buffer in a thread safe fashion
 PThreadMutex::Locker locker(m_mutex);

JDevlieghere wrote:

Yes, I don't know why clang-format isn't kicking in... 

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


[Lldb-commits] [lldb] Parallelize module loading in POSIX dyld code (PR #130912)

2025-03-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Tom Yang (zhyty)


Changes

This patch improves LLDB launch time on Linux machines for **preload 
scenarios**, particularly for executables with a lot of shared library 
dependencies (or modules). Specifically:
* Launching a binary with `target.preload-symbols = true` 
* Attaching to a process with `target.preload-symbols = true`.
It's completely controlled by a new flag added in the first commit 
`plugin.dynamic-loader.posix-dyld.parallel-module-load`, which *defaults to 
false*.

Some rough numbers to showcase perf improvement, run on a very beefy machine:
* Executable with ~5600 modules: baseline 45s, improvement 15s
* Executable with ~3800 modules: baseline 25s,  improvement 10s
* Executable with ~6650 modules: baseline 67s, improvement 20s
* Executable with ~12500 modules: baseline 185s, improvement 85s
* Executable with ~14700 modules: baseline 235s, improvement 120s
A lot of targets we deal with have a *ton* of modules, and unfortunately we're 
unable to convince other folks to reduce the number of modules, so performance 
improvements like this can be very impactful for user experience.

This patch achieves the performance improvement by parallelizing 
`DynamicLoaderPOSIXDYLD::RefreshModules` for the launch scenario, and 
`DynamicLoaderPOSIXDYLD::LoadAllCurrentModules` for the attach scenario. The 
commits have some context on their specific changes as well -- hopefully this 
helps the review.

# More context on implementation

We discovered the bottlenecks by via `perf record -g -p ` on 
a Linux machine. With an executable known to have 1000s of shared library 
dependencies, I ran
```
(lldb) b main
(lldb) r
# taking a while
```
and showed the resulting perf trace (snippet shown)
```
Samples: 85K of event 'cycles:P', Event count (approx.): 54615855812
  Children  Self  Command  Shared Object  Symbol
-   93.54% 0.00%  intern-state libc.so.6  [.] clone3
 clone3
 start_thread
 lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*)  
 r
 std::_Function_handler::_M_invoke(std::_Any_data
 const&)
 lldb_private::Process::RunPrivateStateThread(bool) 
 n
   - 
lldb_private::Process::HandlePrivateEvent(std::shared_ptr&)
  - 93.54% lldb_private::Process::ShouldBroadcastEvent(lldb_private::Event*)
 - 93.54% lldb_private::ThreadList::ShouldStop(lldb_private::Event*)
- lldb_private::Thread::ShouldStop(lldb_private::Event*)
 *
   - 93.53% 
lldb_private::StopInfoBreakpoint::ShouldStopSynchronous(lldb_private::Event*)   
 t
  - 93.52% 
lldb_private::BreakpointSite::ShouldStop(lldb_private::StoppointCallbackContext*)
 i
   
lldb_private::BreakpointLocationCollection::ShouldStop(lldb_private::StoppointCallbackContext*)
   k
   
lldb_private::BreakpointLocation::ShouldStop(lldb_private::StoppointCallbackContext*)
 b
   
lldb_private::BreakpointOptions::InvokeCallback(lldb_private::StoppointCallbackContext*,
 unsigned long, unsigned long)i
   DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(void*, 
lldb_private::StoppointCallbackContext*, unsigned long, unsigned lo
 - DynamicLoaderPOSIXDYLD::RefreshModules() 
 O
- 93.42% 
DynamicLoaderPOSIXDYLD::RefreshModules()::$_0::operator()(DYLDRendezvous::SOEntry
 const&) const u
   - 93.40% 
DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(lldb_private::FileSpec const&, 
unsigned long, unsigned long, bools
  - 
lldb_private::DynamicLoader::LoadModuleAtAddress(lldb_private::FileSpec 
const&, unsigned long, unsigned long, boos
 - 83.90% 
lldb_private::DynamicLoader::FindModuleViaTarget(lldb_private::FileSpec 
const&)o
- 83.01% 
lldb_private::Target::GetOrCreateModule(lldb_private::ModuleSpec const&, 
bool, lldb_private::Status*
   - 77.89% 
lldb_private::Module::PreloadSymbols()
  - 44.06% 
lldb_private::Symtab::PreloadSymbols()
 - 43.66% 
lldb_private::Symtab::InitNameIndexes()
...
```
We saw that majority of time was spent in `RefreshModules`, with the main 

[Lldb-commits] [lldb] [lldb-dap] Support vscode launch URLs (PR #125843)

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

https://github.com/vogelsgesang closed 
https://github.com/llvm/llvm-project/pull/125843
___
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-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Daniel Chen (DanielCChen)


Changes

We don't plan to support it on AIX.
This change will make it as if it is set to OFF.

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


9 Files Affected:

- (modified) compiler-rt/cmake/Modules/AddCompilerRT.cmake (+1-1) 
- (modified) compiler-rt/cmake/Modules/CompilerRTUtils.cmake (+2-2) 
- (modified) compiler-rt/cmake/base-config-ix.cmake (+2-2) 
- (modified) libcxx/CMakeLists.txt (+1-1) 
- (modified) libcxxabi/CMakeLists.txt (+1-1) 
- (modified) libunwind/CMakeLists.txt (+1-1) 
- (modified) lldb/test/CMakeLists.txt (+1-1) 
- (modified) lldb/utils/lldb-dotest/CMakeLists.txt (+1-1) 
- (modified) llvm-libgcc/CMakeLists.txt (+1-1) 


``diff
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)
 string(APPEND LIBCXXABI_TARGET_SUBDIR /${LIBCXXABI_LIBDIR_SUBDIR})
diff --git a/libunwind/CMakeLists

[Lldb-commits] [lldb] [lldb][debugserver] Synchronize interrupt and resume signals (PR #131073)

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

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

lgtm

https://github.com/llvm/llvm-project/pull/131073
___
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] Implement jump to cursor (PR #130503)

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


@@ -0,0 +1,120 @@
+//===-- GoToTargetsRequestHandler.cpp
+//--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "DAP.h"
+
+#include "JSONUtils.h"
+
+#include 
+
+namespace lldb_dap {
+
+//  "GotoTargetsRequest": {
+//"allOf": [ { "$ref": "#/definitions/Request" }, {
+//  "type": "object",
+//  "description": "This request retrieves the possible goto targets for 
the
+//  specified source location.\nThese targets can be used in the `goto`
+//  request.\nClients should only call this request if the corresponding
+//  capability `supportsGotoTargetsRequest` is true.", "properties": {
+//"command": {
+//  "type": "string",
+//  "enum": [ "gotoTargets" ]
+//},
+//"arguments": {
+//  "$ref": "#/definitions/GotoTargetsArguments"
+//}
+//  },
+//  "required": [ "command", "arguments"  ]
+//}]
+//  },
+//  "GotoTargetsArguments": {
+//"type": "object",
+//"description": "Arguments for `gotoTargets` request.",
+//"properties": {
+//  "source": {
+//"$ref": "#/definitions/Source",
+//"description": "The source location for which the goto targets are
+//determined."
+//  },
+//  "line": {
+//"type": "integer",
+//"description": "The line location for which the goto targets are
+//determined."
+//  },
+//  "column": {
+//"type": "integer",
+//"description": "The position within `line` for which the goto targets
+//are determined. It is measured in UTF-16 code units and the client
+//capability `columnsStartAt1` determines whether it is 0- or 1-based."
+//  }
+//},
+//"required": [ "source", "line" ]
+//  },
+//  "GotoTargetsResponse": {
+//"allOf": [ { "$ref": "#/definitions/Response" }, {
+//  "type": "object",
+//  "description": "Response to `gotoTargets` request.",
+//  "properties": {
+//"body": {
+//  "type": "object",
+//  "properties": {
+//"targets": {
+//  "type": "array",
+//  "items": {
+//"$ref": "#/definitions/GotoTarget"
+//  },
+//  "description": "The possible goto targets of the specified
+//  location."
+//}
+//  },
+//  "required": [ "targets" ]
+//}
+//  },
+//  "required": [ "body" ]
+//}]
+//  },
+void GoToTargetsRequestHandler::operator()(
+const llvm::json::Object &request) const {
+  llvm::json::Object response;
+  FillResponse(request, response);
+  const auto *arguments = request.getObject("arguments");
+  const auto *source = arguments->getObject("source");
+  const std::string path = GetString(source, "path").str();
+
+  const auto goto_line = GetInteger(arguments, "line").value_or(0u);
+  const auto goto_column =
+  GetInteger(arguments, "column").value_or(0u);
+
+  lldb::SBLineEntry line_entry{};
+  const lldb::SBFileSpec file_spec(path.c_str(), true);
+  line_entry.SetFileSpec(file_spec);
+  line_entry.SetLine(goto_line);
+  line_entry.SetColumn(goto_column);

da-viper wrote:

@walter-erquinigo  @vogelsgesang 

I was thinking instead we only support jumps within a function for the same 
reason as above. 

it would be something like this 

```py
def is_line_in_func(fn, line) ->:
   s_addr = fn.addr
   e_addr = fn.end_addr 
   
   return (s_addr <= line.addr )and (line.addr <= e_addr)

def get_line_valid_entry(file_spec, line, target):

```

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,330 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error SetFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(
+  log, "pid = {0}, detected architecture {1}", pid,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64).GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+static std::optional> WaitPid() {
+  Log *log = GetLog(POSIXLog::Process);
+
+  int status;
+  ::pid_t wait_pid =
+  llvm::sys::RetryAfterSignal(-1, ::waitpid, -1, &status, WNOHANG);
+
+  if (wait_pid == 0)
+return std::nullopt;
+
+  if (wait_pid == -1) {
+Status error(errno, eErrorTypePOSIX);
+LLDB_LOG(log, "waitpid(-1, &status, _) failed: {0}", error);
+return std::nullopt;
+  }
+
+  WaitStatus wait_status = WaitStatus::Decode(status);
+
+  LLDB_LOG(log, "waitpid

[Lldb-commits] [lldb] [lldb-dap] Updating RequestHandler to encode/decode arguments and response. (PR #130090)

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

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


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

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

DanielCChen wrote:

I will check all those failures and push an update soon.

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


[Lldb-commits] [lldb] [debugserver] Synchronize interrupt and resume signals (PR #131073)

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

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,330 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error SetFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(
+  log, "pid = {0}, detected architecture {1}", pid,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64).GetArchitectureName());

labath wrote:

And now you can delete all of this

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

[Lldb-commits] [lldb] [lldb] Remove Function::GetAddressRange usage from the gui (PR #130991)

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

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


[Lldb-commits] [lldb] 08de320 - [lldb] Remove Function::GetAddressRange usage from the gui (#130991)

2025-03-13 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-03-13T09:21:33+01:00
New Revision: 08de320aa2f46f3f9abcaf93d5382a8d0279d655

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

LOG: [lldb] Remove Function::GetAddressRange usage from the gui (#130991)

m_disassembly_range was used only to prune the list of breakpoints to
those that are in the current function. This isn't really necessary, as
the list is only used to highlight instructions with breakpoints on
them, and an unpruned list works just as well for that.

The shouldn't make things slower, since we still needed through iterate
through all breakpoints to create the list, and I doubt anyone will
notice the memory used to store the extra breakpoints.

Added: 


Modified: 
lldb/source/Core/IOHandlerCursesGUI.cpp

Removed: 




diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp 
b/lldb/source/Core/IOHandlerCursesGUI.cpp
index ee6e847cdb688..7f0e0fc3b7293 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -6781,8 +6781,7 @@ class StatusBarWindowDelegate : public WindowDelegate {
 class SourceFileWindowDelegate : public WindowDelegate {
 public:
   SourceFileWindowDelegate(Debugger &debugger)
-  : WindowDelegate(), m_debugger(debugger), m_sc(), m_file_sp(),
-m_disassembly_sp(), m_disassembly_range(), m_title() {}
+  : WindowDelegate(), m_debugger(debugger) {}
 
   ~SourceFileWindowDelegate() override = default;
 
@@ -6939,12 +6938,8 @@ class SourceFileWindowDelegate : public WindowDelegate {
   m_disassembly_scope = m_sc.function;
   m_disassembly_sp = m_sc.function->GetInstructions(
   exe_ctx, nullptr, !prefer_file_cache);
-  if (m_disassembly_sp) {
+  if (m_disassembly_sp)
 set_selected_line_to_pc = true;
-m_disassembly_range = m_sc.function->GetAddressRange();
-  } else {
-m_disassembly_range.Clear();
-  }
 } else {
   set_selected_line_to_pc = context_changed;
 }
@@ -6953,14 +6948,8 @@ class SourceFileWindowDelegate : public WindowDelegate {
   m_disassembly_scope = m_sc.symbol;
   m_disassembly_sp = m_sc.symbol->GetInstructions(
   exe_ctx, nullptr, prefer_file_cache);
-  if (m_disassembly_sp) {
+  if (m_disassembly_sp)
 set_selected_line_to_pc = true;
-m_disassembly_range.GetBaseAddress() =
-m_sc.symbol->GetAddress();
-m_disassembly_range.SetByteSize(m_sc.symbol->GetByteSize());
-  } else {
-m_disassembly_range.Clear();
-  }
 } else {
   set_selected_line_to_pc = context_changed;
 }
@@ -7114,13 +7103,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
  ++bp_loc_idx) {
   BreakpointLocationSP bp_loc_sp =
   bp_sp->GetLocationAtIndex(bp_loc_idx);
-  LineEntry bp_loc_line_entry;
-  const lldb::addr_t file_addr =
-  bp_loc_sp->GetAddress().GetFileAddress();
-  if (file_addr != LLDB_INVALID_ADDRESS) {
-if (m_disassembly_range.ContainsFileAddress(file_addr))
-  bp_file_addrs.insert(file_addr);
-  }
+  bp_file_addrs.insert(bp_loc_sp->GetAddress().GetFileAddress());
 }
   }
 }
@@ -7552,7 +7535,6 @@ class SourceFileWindowDelegate : public WindowDelegate {
   SourceManager::FileSP m_file_sp;
   SymbolContextScope *m_disassembly_scope = nullptr;
   lldb::DisassemblerSP m_disassembly_sp;
-  AddressRange m_disassembly_range;
   StreamString m_title;
   lldb::user_id_t m_tid = LLDB_INVALID_THREAD_ID;
   int m_line_width = 4;



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


[Lldb-commits] [lldb] [lldb] Split some tests to avoid timeout (PR #129614)

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




labath wrote:

let's make the folder name `qSupported`, as this is just too generic.

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


[Lldb-commits] [lldb] [lldb] Split some tests to avoid timeout (PR #129614)

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

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,330 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error SetFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(
+  log, "pid = {0}, detected architecture {1}", pid,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64).GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate,
+  HostInfo::GetArchitecture(HostInfo::eArchKind64), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+static std::optional> WaitPid() {
+  Log *log = GetLog(POSIXLog::Process);
+
+  int status;
+  ::pid_t wait_pid =
+  llvm::sys::RetryAfterSignal(-1, ::waitpid, -1, &status, WNOHANG);
+
+  if (wait_pid == 0)
+return std::nullopt;
+
+  if (wait_pid == -1) {
+Status error(errno, eErrorTypePOSIX);
+LLDB_LOG(log, "waitpid(-1, &status, _) failed: {0}", error);
+return std::nullopt;
+  }
+
+  WaitStatus wait_status = WaitStatus::Decode(status);
+
+  LLDB_LOG(log, "waitpid

[Lldb-commits] [lldb] [lldb] Split some tests to avoid timeout (PR #129614)

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

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

LGTM

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

[Lldb-commits] [lldb] [lldb] Update dwim-print to show expanded objc instances (PR #117500)

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

kastiglione wrote:

@jimingham this is the PR I mentioned in person on Tuesday.

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


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

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


@@ -172,6 +172,14 @@ let Definition = "debugger" in {
 Global,
 DefaultStringValue<"${ansi.normal}">,
 Desc<"When displaying progress in a color-enabled terminal, use the ANSI 
terminal code specified in this format immediately after the progress 
message.">;
+  def ShowStatusline: Property<"show-statusline", "Boolean">,
+Global,
+DefaultTrue,
+Desc<"Whether to show a statusline at the bottom of the terminal.">;
+  def StatuslineFormat: Property<"statusline-format", "FormatEntity">,
+Global,
+
DefaultStringValue<"${ansi.bg.blue}${ansi.fg.black}{${target.file.basename}}{ | 
${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ 
| {${progress.count} }${progress.message}}">,
+Desc<"The default statusline format string.">;

DavidSpickett wrote:

Great, that would be cool to have.

Another thing you will I assume do is link the format-strings page in your 
upcoming presentation, and Google will probably pick up the slides PDF for it, 
so that is another mitigation in the meantime.

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

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

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

https://github.com/labath commented:

This is better, though I'm not particularly fond of the addition of the new 
Target field. I'd like to see if we could remove that.

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-13 Thread Pavel Labath via lldb-commits


@@ -1064,6 +1065,29 @@ 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.
+  UUID exec_uuid;
+  // Check if there is (still) a valid target and get the debugger and 
exec_uuid
+  // from it.
+  TargetSP target_sp(Debugger::FindTargetWithProcessID(m_pid));
+  if (target_sp) {
+helper.SetDebugger(&(target_sp->GetDebugger()));
+exec_uuid = target_sp->GetExecModuleUUID();

labath wrote:

Are you sure about that. Modules normally exist long after the process exits:
```
$ lldb echo
(lldb) target create "echo"
Current executable set to '/bin/echo' (x86_64).
(lldb) r
Process 15996 launched: '/bin/echo' (x86_64)

Process 15996 exited with status = 0 (0x) 
(lldb) image list
[  0] 676F00F7 0x4000 /bin/echo 
[  1] D626A570 0x77fc6000 /lib64/ld-linux-x86-64.so.2 
[  2] 421DCFD2-138A-B321-D6F1-7AFD7B7FC999-F79CA445 0x77fc5000 [vdso] 
(0x77fc5000)
[  3] C88DE6C8 0x77d99000 /lib64/libc.so.6 
  /usr/lib/debug/lib64/libc.so.6.debug
```

It's possible this happens in some exceptional exit scenarios, but in that 
case, I'd like to know what they are. In general, you cannot assume that a 
target will always have an executable module due to the scenarios I mentioned 
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][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

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


@@ -0,0 +1,256 @@
+//===-- NativeProcessAIX.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 "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1)
+return errorCodeToError(errnoAsErrorCode());
+  if (fcntl(fd, F_SETFL, status | flags) == -1)
+return errorCodeToError(errnoAsErrorCode());
+  return Error::success();
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtoc

[Lldb-commits] [lldb] [lldb][debugserver] Synchronize interrupt and resume signals (PR #131073)

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

https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/131073
___
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-13 Thread Pavel Labath via lldb-commits


@@ -1064,6 +1065,29 @@ 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.
+  UUID exec_uuid;
+  // Check if there is (still) a valid target and get the debugger and 
exec_uuid
+  // from it.
+  TargetSP target_sp(Debugger::FindTargetWithProcessID(m_pid));
+  if (target_sp) {

labath wrote:

```suggestion
  Target &target = GetTarget();
```

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


  1   2   >