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

>From faf89e2e754b92e2e704b351e66bc2c39985f724 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Wed, 26 Aug 2026 20:21:30 +0100
Subject: [PATCH 1/2] [lldb-dap][NFC] Create a type alias for sourceReference.

The spec requires sourceReference to be of type int32
and a minimum value of 0. src_ref_t is an alias to int32_t.

Replace narrowed values in function helpers and struct declarations.
---
 lldb/tools/lldb-dap/DAP.cpp                          |  7 ++++---
 lldb/tools/lldb-dap/DAP.h                            |  6 +++---
 .../Handler/BreakpointLocationsRequestHandler.cpp    |  2 +-
 lldb/tools/lldb-dap/Handler/RequestHandler.h         |  4 ++--
 lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp |  2 +-
 lldb/tools/lldb-dap/Protocol/ProtocolRequests.h      |  2 +-
 lldb/tools/lldb-dap/Protocol/ProtocolTypes.h         | 12 ++++++++++--
 lldb/tools/lldb-dap/SourceBreakpoint.cpp             |  2 +-
 lldb/tools/lldb-dap/SourceBreakpoint.h               |  2 +-
 9 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index d09e5fef9d1ef..67db252d31d97 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -521,17 +521,18 @@ void DAP::SendProgressEvent(uint64_t progress_id, const 
char *message,
   progress_event_reporter.Push(progress_id, message, completed, total);
 }
 
-int32_t DAP::CreateSourceReference(lldb::addr_t address) {
+src_ref_t DAP::CreateSourceReference(lldb::addr_t address) {
   std::lock_guard<std::mutex> guard(m_source_references_mutex);
   auto iter = llvm::find(m_source_references, address);
   if (iter != m_source_references.end())
     return std::distance(m_source_references.begin(), iter) + 1;
 
   m_source_references.emplace_back(address);
-  return static_cast<int32_t>(m_source_references.size());
+  return static_cast<src_ref_t>(m_source_references.size());
 }
 
-std::optional<lldb::addr_t> DAP::GetSourceReferenceAddress(int32_t reference) {
+std::optional<lldb::addr_t>
+DAP::GetSourceReferenceAddress(src_ref_t reference) {
   std::lock_guard<std::mutex> guard(m_source_references_mutex);
   if (reference <= LLDB_DAP_INVALID_SRC_REF)
     return std::nullopt;
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 68a401919b3be..ed4fa0b2d84c5 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -238,9 +238,9 @@ struct DAP final : public DAPTransport::MessageHandler {
   void SendProgressEvent(uint64_t progress_id, const char *message,
                          uint64_t completed, uint64_t total);
 
-  int32_t CreateSourceReference(lldb::addr_t address);
+  src_ref_t CreateSourceReference(lldb::addr_t address);
 
-  std::optional<lldb::addr_t> GetSourceReferenceAddress(int32_t reference);
+  std::optional<lldb::addr_t> GetSourceReferenceAddress(src_ref_t reference);
 
   ExceptionBreakpoint *GetExceptionBPFromStopReason(lldb::SBThread &thread);
 
@@ -512,7 +512,7 @@ struct DAP final : public DAPTransport::MessageHandler {
   const protocol::Request *m_active_request;
 
   llvm::StringMap<SourceBreakpointMap> m_source_breakpoints;
-  llvm::DenseMap<int64_t, SourceBreakpointMap> m_source_assembly_breakpoints;
+  llvm::DenseMap<src_ref_t, SourceBreakpointMap> m_source_assembly_breakpoints;
 };
 
 } // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/Handler/BreakpointLocationsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/BreakpointLocationsRequestHandler.cpp
index 29c1df7065016..8a18abd4d60a8 100644
--- a/lldb/tools/lldb-dap/Handler/BreakpointLocationsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/BreakpointLocationsRequestHandler.cpp
@@ -104,7 +104,7 @@ 
BreakpointLocationsRequestHandler::GetSourceBreakpointLocations(
 
 std::vector<std::pair<uint32_t, uint32_t>>
 BreakpointLocationsRequestHandler::GetAssemblyBreakpointLocations(
-    int64_t source_reference, uint32_t start_line, uint32_t end_line) const {
+    src_ref_t source_reference, uint32_t start_line, uint32_t end_line) const {
   std::vector<std::pair<uint32_t, uint32_t>> locations;
   lldb::SBAddress address(source_reference, dap.target);
   if (!address.IsValid())
diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.h 
b/lldb/tools/lldb-dap/Handler/RequestHandler.h
index 4b4f1435e7acb..0cab2b1a9b2e6 100644
--- a/lldb/tools/lldb-dap/Handler/RequestHandler.h
+++ b/lldb/tools/lldb-dap/Handler/RequestHandler.h
@@ -234,8 +234,8 @@ class BreakpointLocationsRequestHandler
                                uint32_t start_column, uint32_t end_line,
                                uint32_t end_column) const;
   std::vector<std::pair<uint32_t, uint32_t>>
-  GetAssemblyBreakpointLocations(int64_t source_reference, uint32_t start_line,
-                                 uint32_t end_line) const;
+  GetAssemblyBreakpointLocations(src_ref_t source_reference,
+                                 uint32_t start_line, uint32_t end_line) const;
 };
 
 class CompletionsRequestHandler
diff --git a/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
index b2074e54e6be2..cf0c96177d5ac 100644
--- a/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SourceRequestHandler.cpp
@@ -30,7 +30,7 @@ namespace lldb_dap {
 llvm::Expected<protocol::SourceResponseBody>
 SourceRequestHandler::Run(const protocol::SourceArguments &args) const {
 
-  uint32_t source_ref =
+  src_ref_t source_ref =
       args.source ? args.source->sourceReference.value_or(args.sourceReference)
                   : args.sourceReference;
   const std::optional<lldb::addr_t> source_addr_opt =
diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h 
b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h
index a9372aaf77aa9..7d7a4647c2328 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolRequests.h
@@ -520,7 +520,7 @@ struct SourceArguments {
   /// The reference to the source. This is the same as 
`source.sourceReference`.
   /// This is provided for backward compatibility since old clients do not
   /// understand the `source` attribute.
-  int64_t sourceReference = LLDB_DAP_INVALID_SRC_REF;
+  src_ref_t sourceReference = LLDB_DAP_INVALID_SRC_REF;
 };
 bool fromJSON(const llvm::json::Value &, SourceArguments &, llvm::json::Path);
 
diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h 
b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
index a50f4c85d4fff..847421428692a 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
@@ -29,12 +29,16 @@
 #include <cstdint>
 #include <optional>
 
-#define LLDB_DAP_INVALID_SRC_REF 0
+#define LLDB_DAP_INVALID_SRC_REF int32_t(0U)
 #define LLDB_DAP_INVALID_VALUE_LOC 0
 #define LLDB_DAP_INVALID_STACK_FRAME_ID UINT64_MAX
 
 namespace lldb_dap::protocol {
 
+/// The DAP `sourceReference`.
+/// The spec defines it as int32 with a minimum value of 0.
+using src_ref_t = int32_t;
+
 /// An `ExceptionBreakpointsFilter` is shown in the UI as an filter option for
 /// configuring how exceptions are dealt with.
 struct ExceptionBreakpointsFilter {
@@ -413,7 +417,7 @@ struct Source {
   /// `source` request (even if a path is specified). Since a `sourceReference`
   /// is only valid for a session, it can not be used to persist a source. The
   /// value should be less than or equal to 2147483647 (2^31-1).
-  std::optional<int32_t> sourceReference;
+  std::optional<src_ref_t> sourceReference;
 
   /// A hint for how to present the source in the UI. A value of `deemphasize`
   /// can be used to indicate that the source is not available or that it is
@@ -1134,4 +1138,8 @@ llvm::json::Value toJSON(const StackFrame &);
 
 } // namespace lldb_dap::protocol
 
+namespace lldb_dap {
+using src_ref_t = protocol::src_ref_t;
+} // namespace lldb_dap
+
 #endif
diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.cpp 
b/lldb/tools/lldb-dap/SourceBreakpoint.cpp
index 77da2966723e6..4cec1a927f618 100644
--- a/lldb/tools/lldb-dap/SourceBreakpoint.cpp
+++ b/lldb/tools/lldb-dap/SourceBreakpoint.cpp
@@ -86,7 +86,7 @@ void SourceBreakpoint::CreatePathBreakpoint(const 
protocol::Source &source) {
 }
 
 llvm::Error SourceBreakpoint::CreateAssemblyBreakpointWithSourceReference(
-    int64_t source_reference) {
+    src_ref_t source_reference) {
   std::optional<lldb::addr_t> raw_addr =
       m_dap.GetSourceReferenceAddress(source_reference);
   if (!raw_addr)
diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.h 
b/lldb/tools/lldb-dap/SourceBreakpoint.h
index 34054a8dcfd5f..bd67039d54984 100644
--- a/lldb/tools/lldb-dap/SourceBreakpoint.h
+++ b/lldb/tools/lldb-dap/SourceBreakpoint.h
@@ -53,7 +53,7 @@ class SourceBreakpoint : public Breakpoint {
 protected:
   void CreatePathBreakpoint(const protocol::Source &source);
   llvm::Error
-  CreateAssemblyBreakpointWithSourceReference(int64_t source_reference);
+  CreateAssemblyBreakpointWithSourceReference(src_ref_t source_reference);
   llvm::Error CreateAssemblyBreakpointWithPersistenceData(
       const protocol::PersistenceData &persistence_data);
 

>From fe139b367200bd8957aa5930d7c836263895c72a Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Thu, 27 Aug 2026 12:59:03 +0100
Subject: [PATCH 2/2] add review change

---
 lldb/tools/lldb-dap/Protocol/ProtocolTypes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h 
b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
index 847421428692a..39eaeb064ccd2 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.h
@@ -29,7 +29,7 @@
 #include <cstdint>
 #include <optional>
 
-#define LLDB_DAP_INVALID_SRC_REF int32_t(0U)
+#define LLDB_DAP_INVALID_SRC_REF int32_t(0)
 #define LLDB_DAP_INVALID_VALUE_LOC 0
 #define LLDB_DAP_INVALID_STACK_FRAME_ID UINT64_MAX
 

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to