[Lldb-commits] [lldb] [lldb][test] Make TestMultipleDebuggers check every debug session (PR #233526)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 20 08:06:16 PDT 2026
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/233526
>From da8d0d8e9dec9c217adc648e17a01beb5c435756 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Mon, 19 Oct 2026 18:42:56 +0100
Subject: [PATCH 1/2] [lldb][test] Make TestMultipleDebuggers check every debug
session
---
.../multi-process-driver.cpp | 57 ++++++++++++-------
1 file changed, 36 insertions(+), 21 deletions(-)
diff --git a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
index 8af3695db5591d..07a89be79f35c0 100644
--- a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
+++ b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
@@ -99,6 +99,15 @@ walk_stack_to_main (SBThread thread)
return found_main;
}
+// Function names are spelled differently on each platform, for example
+// "foo()" on Linux and "int foo(void)" on Windows, so check the breakpoint.
+bool
+stopped_at_breakpoint (SBThread thread, SBBreakpoint breakpoint)
+{
+ return thread.GetStopReason() == eStopReasonBreakpoint &&
+ thread.GetStopReasonDataAtIndex(0) == (uint64_t) breakpoint.GetID();
+}
+
void *do_one_debugger (void *in)
{
uint64_t threadnum = (uint64_t) in;
@@ -118,6 +127,8 @@ void *do_one_debugger (void *in)
if (debugger.IsValid ())
{
debugger.SetAsync (true);
+ // Like dotest, give lldb-server time to answer on a loaded host.
+ debugger.HandleCommand ("settings set plugin.process.gdb-remote.packet-timeout 600");
SBTarget target = debugger.CreateTargetWithFileAndArch(inferior_process_name,
STR(LLDB_HOST_ARCH));
SBCommandInterpreter command_interp = debugger.GetCommandInterpreter();
@@ -138,6 +149,12 @@ void *do_one_debugger (void *in)
SBLaunchInfo launch_info (NULL);
SBError error;
SBProcess process = target.Launch (launch_info, error);
+ if (error.Fail())
+ {
+ printf ("#%" PRIu64 ": process failed to launch: %s\n", threadnum, error.GetCString());
+ completed_threads_array[threadnum] = true;
+ return (void*) 1;
+ }
if (process.IsValid())
{
SBListener listener = debugger.GetListener();
@@ -151,24 +168,16 @@ void *do_one_debugger (void *in)
wait_for_stop_event (process, listener);
- if (!walk_stack_to_main (process.GetThreadAtIndex(0)))
+ if (!walk_stack_to_main (process.GetSelectedThread()))
{
printf ("#%" PRIu64 ": backtrace while @ foo() failed\n", threadnum);
completed_threads_array[threadnum] = true;
return (void *) 1;
}
- // On Linux the () are included.
- const char* hit_fn_name = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName();
- if (!hit_fn_name || (strcmp (hit_fn_name, "foo") != 0 && strcmp (hit_fn_name, "foo()") != 0))
+ if (!stopped_at_breakpoint (process.GetSelectedThread(), foo_br))
{
-#if DEBUG == 1
- printf ("#%" PRIu64 ": First breakpoint did not stop at foo(), instead stopped at ", threadnum);
- if (hit_fn_name)
- printf ("'%s'\n", hit_fn_name);
- else
- printf ("an unnamed function\n");
-#endif
+ printf ("#%" PRIu64 ": First breakpoint did not stop at foo()\n", threadnum);
completed_threads_array[threadnum] = true;
return (void*) 1;
}
@@ -185,17 +194,16 @@ void *do_one_debugger (void *in)
}
- if (!walk_stack_to_main (process.GetThreadAtIndex(0)))
+ if (!walk_stack_to_main (process.GetSelectedThread()))
{
printf ("#%" PRIu64 ": backtrace while @ bar() failed\n", threadnum);
completed_threads_array[threadnum] = true;
return (void *) 1;
}
- hit_fn_name = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName();
- if (!hit_fn_name || (strcmp (hit_fn_name, "bar") != 0 && strcmp (hit_fn_name, "bar()") != 0))
+ if (!stopped_at_breakpoint (process.GetSelectedThread(), bar_br))
{
- printf ("#%" PRIu64 ": First breakpoint did not stop at bar()\n", threadnum);
+ printf ("#%" PRIu64 ": Second breakpoint did not stop at bar()\n", threadnum);
completed_threads_array[threadnum] = true;
return (void*) 1;
}
@@ -296,6 +304,11 @@ int main (int argc, char **argv)
printf ("%d threads completed successfully out of %d\n", successful_threads, NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
#endif
SBDebugger::Terminate();
+ if (successful_threads != NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS)
+ {
+ printf ("only %d threads completed successfully, out of %d\n", successful_threads, NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
+ exit(1);
+ }
exit(0);
}
else
@@ -304,14 +317,16 @@ int main (int argc, char **argv)
printf ("%d threads completed so far (%d successfully), out of %d\n", total_completed_threads, successful_threads, NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
#endif
}
- if (iter == max_time_to_wait)
- printf("reached maximum timeout but only %d threads have completed "
- "so far "
- "(%d successfully), out of %d. Exiting.\n",
- total_completed_threads, successful_threads,
- NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
}
+ printf("reached maximum timeout but only %d threads have completed so far "
+ "(%d successfully), out of %d. Exiting.\n",
+ count_completed_threads(NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS),
+ count_successful_threads(NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS),
+ NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
+ // _exit doesn't flush stdout.
+ fflush(stdout);
+
// We do not call SBDebugger::Terminate() here because it will destroy
// data that might be being used by threads that are still running. Which
// would change the timeout into an unrelated crash.
>From bdbbfa862c986f160611a1899b42e05f3187d530 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 20 Oct 2026 16:06:00 +0100
Subject: [PATCH 2/2] formatting fixup
---
.../multi-process-driver.cpp | 74 ++++++++++---------
1 file changed, 38 insertions(+), 36 deletions(-)
diff --git a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
index 07a89be79f35c0..93e70df87ec3e2 100644
--- a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
+++ b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
@@ -101,11 +101,9 @@ walk_stack_to_main (SBThread thread)
// Function names are spelled differently on each platform, for example
// "foo()" on Linux and "int foo(void)" on Windows, so check the breakpoint.
-bool
-stopped_at_breakpoint (SBThread thread, SBBreakpoint breakpoint)
-{
- return thread.GetStopReason() == eStopReasonBreakpoint &&
- thread.GetStopReasonDataAtIndex(0) == (uint64_t) breakpoint.GetID();
+bool stopped_at_breakpoint(SBThread thread, SBBreakpoint breakpoint) {
+ return thread.GetStopReason() == eStopReasonBreakpoint &&
+ thread.GetStopReasonDataAtIndex(0) == (uint64_t)breakpoint.GetID();
}
void *do_one_debugger (void *in)
@@ -128,7 +126,8 @@ void *do_one_debugger (void *in)
{
debugger.SetAsync (true);
// Like dotest, give lldb-server time to answer on a loaded host.
- debugger.HandleCommand ("settings set plugin.process.gdb-remote.packet-timeout 600");
+ debugger.HandleCommand(
+ "settings set plugin.process.gdb-remote.packet-timeout 600");
SBTarget target = debugger.CreateTargetWithFileAndArch(inferior_process_name,
STR(LLDB_HOST_ARCH));
SBCommandInterpreter command_interp = debugger.GetCommandInterpreter();
@@ -149,11 +148,11 @@ void *do_one_debugger (void *in)
SBLaunchInfo launch_info (NULL);
SBError error;
SBProcess process = target.Launch (launch_info, error);
- if (error.Fail())
- {
- printf ("#%" PRIu64 ": process failed to launch: %s\n", threadnum, error.GetCString());
- completed_threads_array[threadnum] = true;
- return (void*) 1;
+ if (error.Fail()) {
+ printf("#%" PRIu64 ": process failed to launch: %s\n", threadnum,
+ error.GetCString());
+ completed_threads_array[threadnum] = true;
+ return (void *)1;
}
if (process.IsValid())
{
@@ -168,18 +167,20 @@ void *do_one_debugger (void *in)
wait_for_stop_event (process, listener);
- if (!walk_stack_to_main (process.GetSelectedThread()))
- {
- printf ("#%" PRIu64 ": backtrace while @ foo() failed\n", threadnum);
- completed_threads_array[threadnum] = true;
- return (void *) 1;
+ if (!walk_stack_to_main(process.GetSelectedThread())) {
+ printf("#%" PRIu64 ": backtrace while @ foo() failed\n",
+ threadnum);
+ completed_threads_array[threadnum] = true;
+ return (void *)1;
}
- if (!stopped_at_breakpoint (process.GetSelectedThread(), foo_br))
- {
- printf ("#%" PRIu64 ": First breakpoint did not stop at foo()\n", threadnum);
- completed_threads_array[threadnum] = true;
- return (void*) 1;
+ if (!stopped_at_breakpoint(process.GetSelectedThread(),
+ foo_br)) {
+ printf("#%" PRIu64
+ ": First breakpoint did not stop at foo()\n",
+ threadnum);
+ completed_threads_array[threadnum] = true;
+ return (void *)1;
}
process.Continue();
@@ -193,19 +194,20 @@ void *do_one_debugger (void *in)
return (void *) 1;
}
-
- if (!walk_stack_to_main (process.GetSelectedThread()))
- {
- printf ("#%" PRIu64 ": backtrace while @ bar() failed\n", threadnum);
- completed_threads_array[threadnum] = true;
- return (void *) 1;
+ if (!walk_stack_to_main(process.GetSelectedThread())) {
+ printf("#%" PRIu64 ": backtrace while @ bar() failed\n",
+ threadnum);
+ completed_threads_array[threadnum] = true;
+ return (void *)1;
}
- if (!stopped_at_breakpoint (process.GetSelectedThread(), bar_br))
- {
- printf ("#%" PRIu64 ": Second breakpoint did not stop at bar()\n", threadnum);
- completed_threads_array[threadnum] = true;
- return (void*) 1;
+ if (!stopped_at_breakpoint(process.GetSelectedThread(),
+ bar_br)) {
+ printf("#%" PRIu64
+ ": Second breakpoint did not stop at bar()\n",
+ threadnum);
+ completed_threads_array[threadnum] = true;
+ return (void *)1;
}
process.Kill();
@@ -304,10 +306,10 @@ int main (int argc, char **argv)
printf ("%d threads completed successfully out of %d\n", successful_threads, NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
#endif
SBDebugger::Terminate();
- if (successful_threads != NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS)
- {
- printf ("only %d threads completed successfully, out of %d\n", successful_threads, NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
- exit(1);
+ if (successful_threads != NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS) {
+ printf("only %d threads completed successfully, out of %d\n",
+ successful_threads, NUMBER_OF_SIMULTANEOUS_DEBUG_SESSIONS);
+ exit(1);
}
exit(0);
}
More information about the lldb-commits
mailing list