https://github.com/aahrun updated 
https://github.com/llvm/llvm-project/pull/169844

>From 93984baf392a83851e9620ace89e20eca07ed2c1 Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Thu, 27 Nov 2025 17:25:48 +0000
Subject: [PATCH 1/4] [lldb-dap] Fix segfault in JSONUtils.cpp when
 GetUUIDString() returns nullptr

When creating a stack frame in JSONUtils.cpp CreateStackFrame() the code
constructs a std::string from module.GetUUIDString(), which can return
nullptr in some cases (as documented in the implementation of
SBModule::GetUUIDString()). This causes a segmentation fault when passed to
the std::string constructor.

This fix adds a null check before constructing the UUID string, falling back
to an empty string if nullptr is returned. The existing empty check ensures
the moduleId field is omitted from the JSON when no UUID exists.
---
 lldb/tools/lldb-dap/JSONUtils.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 5c4afa3fd2f62..019ab3ee8fb28 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -554,7 +554,8 @@ llvm::json::Value CreateStackFrame(DAP &dap, lldb::SBFrame 
&frame,
 
   lldb::SBModule module = frame.GetModule();
   if (module.IsValid()) {
-    std::string uuid = module.GetUUIDString();
+    const char *uuid_cstr = module.GetUUIDString();
+    std::string uuid = uuid_cstr ? uuid_cstr : "";
     if (!uuid.empty())
       object.try_emplace("moduleId", uuid);
   }

>From de60e81b2734ca378f12f7061837d1c03629c928 Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Fri, 28 Nov 2025 14:51:46 +0000
Subject: [PATCH 2/4] Update lldb/tools/lldb-dap/JSONUtils.cpp

Co-authored-by: Ebuka Ezike <[email protected]>
---
 lldb/tools/lldb-dap/JSONUtils.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 019ab3ee8fb28..40b4f5b9f7f90 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -554,10 +554,8 @@ llvm::json::Value CreateStackFrame(DAP &dap, lldb::SBFrame 
&frame,
 
   lldb::SBModule module = frame.GetModule();
   if (module.IsValid()) {
-    const char *uuid_cstr = module.GetUUIDString();
-    std::string uuid = uuid_cstr ? uuid_cstr : "";
-    if (!uuid.empty())
-      object.try_emplace("moduleId", uuid);
+    if (const llvm::StringRef uuid = module.GetUUIDString(); !uuid.empty())
+      object.try_emplace("moduleId", uuid.str());
   }
 
   return llvm::json::Value(std::move(object));

>From d61821f5a2f7109303e42695c84920697183279a Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Fri, 28 Nov 2025 15:53:41 +0000
Subject: [PATCH 3/4] Applied feedback from PR Better handling of module_id in
 CompileUnitsRequestHandler.cpp as per recommendation.

---
 lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
index cd937116f7380..5ed106857633d 100644
--- a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -10,6 +10,7 @@
 #include "EventHelper.h"
 #include "JSONUtils.h"
 #include "RequestHandler.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace lldb_dap {
 
@@ -60,12 +61,12 @@ void CompileUnitsRequestHandler::operator()(
   llvm::json::Object body;
   llvm::json::Array units;
   const auto *arguments = request.getObject("arguments");
-  const std::string module_id =
-      GetString(arguments, "moduleId").value_or("").str();
+  const llvm::StringRef module_id =
+      GetString(arguments, "moduleId").value_or("");
   int num_modules = dap.target.GetNumModules();
   for (int i = 0; i < num_modules; i++) {
     auto curr_module = dap.target.GetModuleAtIndex(i);
-    if (module_id == curr_module.GetUUIDString()) {
+    if (module_id == llvm::StringRef(curr_module.GetUUIDString())) {
       int num_units = curr_module.GetNumCompileUnits();
       for (int j = 0; j < num_units; j++) {
         auto curr_unit = curr_module.GetCompileUnitAtIndex(j);

>From 291da70c24f8bca1ab450942b54cb983a0d2506b Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Mon, 1 Dec 2025 13:45:56 +0000
Subject: [PATCH 4/4] Removed unnecessary include As recommended in PR

---
 lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp 
b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
index 5ed106857633d..0e5c2b23d8d67 100644
--- a/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/CompileUnitsRequestHandler.cpp
@@ -10,7 +10,6 @@
 #include "EventHelper.h"
 #include "JSONUtils.h"
 #include "RequestHandler.h"
-#include "llvm/ADT/StringRef.h"
 
 namespace lldb_dap {
 

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

Reply via email to