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

>From 28aa746d16753483df75f0208651420a9a5f29c1 Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Thu, 27 Nov 2025 17:25:48 +0000
Subject: [PATCH 1/3] [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 81eadae03bb48..1cc01cd547582 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 e2e10eb9d55d9a0fe65e648b02bc6d29acbceaa1 Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Fri, 28 Nov 2025 14:51:46 +0000
Subject: [PATCH 2/3] 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 1cc01cd547582..33f266b55bd2e 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 5910663dbdbebc508c587a16e343456aa4379ae0 Mon Sep 17 00:00:00 2001
From: aaron <[email protected]>
Date: Fri, 28 Nov 2025 15:53:41 +0000
Subject: [PATCH 3/3] 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);

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

Reply via email to