https://github.com/Nerixyz created 
https://github.com/llvm/llvm-project/pull/141529

When a target thread returned an empty but not `nullptr` string as its name, 
the thread would show up with an empty name in lldb-dap.

I don't know how this works on macOS and Linux, but on Windows, 
[`TargetThreadWindows::GetName`](https://github.com/llvm/llvm-project/blob/deedc8a181b9598d188b2175357bce990a271d5d/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp#L178-L204)
 returns a non-null pointer to an empty string, because on MSVC's STL, 
`std::string{}.c_str()` returns a pointer to inside the object (the SSO 
storage).

This changes the check in `CreateThread`, when no custom thread formatter is 
set, to check for the length of the thread and queue name instead of it being 
`nullptr`.

>From 331742fc3d9f01c6f5f6755b6ec94c69bf8a2ac8 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerix...@outlook.de>
Date: Mon, 26 May 2025 22:25:05 +0200
Subject: [PATCH] [lldb-dap] Treat empty thread names as unset

---
 lldb/tools/lldb-dap/JSONUtils.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index c9c6f4554c325..f0b3dfb595717 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -764,12 +764,12 @@ llvm::json::Value CreateThread(lldb::SBThread &thread, 
lldb::SBFormat &format) {
   if (format && thread.GetDescriptionWithFormat(format, stream).Success()) {
     thread_str = stream.GetData();
   } else {
-    const char *thread_name = thread.GetName();
-    const char *queue_name = thread.GetQueueName();
+    llvm::StringRef thread_name(thread.GetName());
+    llvm::StringRef queue_name(thread.GetQueueName());
 
-    if (thread_name) {
-      thread_str = std::string(thread_name);
-    } else if (queue_name) {
+    if (!thread_name.empty()) {
+      thread_str = thread_name.str();
+    } else if (!queue_name.empty()) {
       auto kind = thread.GetQueue().GetKind();
       std::string queue_kind_label = "";
       if (kind == lldb::eQueueKindSerial) {

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

Reply via email to