[Lldb-commits] [lldb] 380d489 - [lldb][test] Fix undefined behaviour in multi process driver (#226949)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 28 04:13:40 PDT 2026
Author: David Spickett
Date: 2026-09-28T12:13:29+01:00
New Revision: 380d489bcd2a4e4dbe877f9518ee696348f419ea
URL: https://github.com/llvm/llvm-project/commit/380d489bcd2a4e4dbe877f9518ee696348f419ea
DIFF: https://github.com/llvm/llvm-project/commit/380d489bcd2a4e4dbe877f9518ee696348f419ea.diff
LOG: [lldb][test] Fix undefined behaviour in multi process driver (#226949)
This code was using strcmp on function names. Function names can be null
(see SBFrame::GetFunctionName), and passing null to strcmp is UB.
Added:
Modified:
lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
Removed:
################################################################################
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 30af50ba389c4..8af3695db5591 100644
--- a/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
+++ b/lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
@@ -88,7 +88,8 @@ walk_stack_to_main (SBThread thread)
while (!found_main && curr_frame < framecount)
{
SBFrame frame = thread.GetFrameAtIndex (curr_frame);
- if (strcmp (frame.GetFunctionName(), "main") == 0)
+ const char* function_name = frame.GetFunctionName();
+ if (function_name && strcmp (function_name, "main") == 0)
{
found_main = true;
break;
@@ -158,11 +159,15 @@ void *do_one_debugger (void *in)
}
// On Linux the () are included.
- const char* hit_fn = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName();
- if (strcmp (hit_fn, "foo") != 0 && strcmp (hit_fn, "foo()") != 0)
+ 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 DEBUG == 1
- printf ("#%" PRIu64 ": First breakpoint did not stop at foo(), instead stopped at '%s'\n", threadnum, process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName());
+ 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
completed_threads_array[threadnum] = true;
return (void*) 1;
@@ -187,8 +192,8 @@ void *do_one_debugger (void *in)
return (void *) 1;
}
- hit_fn = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName();
- if (strcmp (hit_fn, "bar") != 0 && strcmp (hit_fn, "bar()") != 0)
+ 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))
{
printf ("#%" PRIu64 ": First breakpoint did not stop at bar()\n", threadnum);
completed_threads_array[threadnum] = true;
More information about the lldb-commits
mailing list