[Lldb-commits] [lldb] [lldb-dap] Fix segfault in JSONUtils.cpp when GetUUIDString() returns nullptr (PR #169844)

via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 28 07:09:19 PST 2025


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

>From 28aa746d16753483df75f0208651420a9a5f29c1 Mon Sep 17 00:00:00 2001
From: aaron <adron at modular.com>
Date: Thu, 27 Nov 2025 17:25:48 +0000
Subject: [PATCH 1/2] [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 <adron at modular.com>
Date: Fri, 28 Nov 2025 14:51:46 +0000
Subject: [PATCH 2/2] Update lldb/tools/lldb-dap/JSONUtils.cpp

Co-authored-by: Ebuka Ezike <yerimyah1 at gmail.com>
---
 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));



More information about the lldb-commits mailing list