Skip to content

[lldb-dap] Treat empty thread names as unset #141529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lldb/test/API/tools/lldb-dap/threads/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
C_SOURCES := main.c
CXX_SOURCES := main.cpp

ENABLE_THREADS := YES

Expand Down
27 changes: 19 additions & 8 deletions lldb/test/API/tools/lldb-dap/threads/TestDAP_threads.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Test lldb-dap setBreakpoints request
Test lldb-dap threads request
"""

from lldbsuite.test.decorators import *
Expand All @@ -9,7 +9,6 @@


class TestDAP_threads(lldbdap_testcase.DAPTestCaseBase):
@skipIfWindows
def test_correct_thread(self):
"""
Tests that the correct thread is selected if we continue from
Expand All @@ -19,7 +18,7 @@ def test_correct_thread(self):
"""
program = self.getBuildArtifact("a.out")
self.build_and_launch(program)
source = "main.c"
source = "main.cpp"
breakpoint_line = line_number(source, "// break here")
lines = [breakpoint_line]
# Set breakpoint in the thread function
Expand All @@ -42,8 +41,10 @@ def test_correct_thread(self):
)
self.assertFalse(stopped_event[0]["body"]["preserveFocusHint"])
self.assertTrue(stopped_event[0]["body"]["threadCausedFocus"])
# All threads should be named Thread {index}
threads = self.dap_server.get_threads()
self.assertTrue(all(len(t["name"]) > 0 for t in threads))

@skipIfWindows
def test_thread_format(self):
"""
Tests the support for custom thread formats.
Expand All @@ -54,7 +55,7 @@ def test_thread_format(self):
customThreadFormat="This is thread index #${thread.index}",
stopCommands=["thread list"],
)
source = "main.c"
source = "main.cpp"
breakpoint_line = line_number(source, "// break here")
lines = [breakpoint_line]
# Set breakpoint in the thread function
Expand All @@ -63,8 +64,18 @@ def test_thread_format(self):
len(breakpoint_ids), len(lines), "expect correct number of breakpoints"
)
self.continue_to_breakpoints(breakpoint_ids)
# We are stopped at the second thread
# We are stopped at the first thread
threads = self.dap_server.get_threads()
print("got thread", threads)
self.assertEqual(threads[0]["name"], "This is thread index #1")
self.assertEqual(threads[1]["name"], "This is thread index #2")
if self.getPlatform() == "windows":
# Windows creates a thread pool once WaitForSingleObject is called
# by thread.join(). As we are in the thread function, we can't be
# certain that join() has been called yet and a thread pool has
# been created, thus we only check for the first two threads.
names = list(sorted(t["name"] for t in threads))[:2]
self.assertEqual(
names, ["This is thread index #1", "This is thread index #2"]
)
else:
self.assertEqual(threads[0]["name"], "This is thread index #1")
self.assertEqual(threads[1]["name"], "This is thread index #2")
21 changes: 0 additions & 21 deletions lldb/test/API/tools/lldb-dap/threads/main.c

This file was deleted.

18 changes: 18 additions & 0 deletions lldb/test/API/tools/lldb-dap/threads/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <cstdio>
#include <thread>

int state_var;

void thread() {
state_var++; // break here
}

int main(int argc, char **argv) {
std::thread t1(thread);
t1.join();
std::thread t2(thread);
t2.join();

printf("state_var is %d\n", state_var);
return 0;
}
10 changes: 5 additions & 5 deletions lldb/tools/lldb-dap/JSONUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading