[Lldb-commits] [lldb] caf508d - [lldb] [test] Synchronize before the breakpoint in fork tests

Michał Górny via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 10 04:06:09 PDT 2021


Author: Michał Górny
Date: 2021-09-10T13:06:01+02:00
New Revision: caf508d7124353522e7604dbfea36b429469bd39

URL: https://github.com/llvm/llvm-project/commit/caf508d7124353522e7604dbfea36b429469bd39
DIFF: https://github.com/llvm/llvm-project/commit/caf508d7124353522e7604dbfea36b429469bd39.diff

LOG: [lldb] [test] Synchronize before the breakpoint in fork tests

We set breakpoint on child_func, so synchronization inside it is too
late to guarantee ordering between the parent output and child
breakpoint.  Split the function in two, and perform synchronization
before the breakpoint.

Differential Revision: https://reviews.llvm.org/D109591

Added: 
    

Modified: 
    lldb/test/Shell/Subprocess/Inputs/fork.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/Shell/Subprocess/Inputs/fork.cpp b/lldb/test/Shell/Subprocess/Inputs/fork.cpp
index f4cf1c2c42dc1..81b1d116c9436 100644
--- a/lldb/test/Shell/Subprocess/Inputs/fork.cpp
+++ b/lldb/test/Shell/Subprocess/Inputs/fork.cpp
@@ -28,9 +28,24 @@ void wait_for_parent() {
   assert(ret == 0);
 }
 
-int child_func(void *argv0_ptr) {
+// This is the function we set breakpoint on.
+int child_func(const char *argv0) {
+  // we need to avoid memory modifications for vfork(), yet we want
+  // to be able to test watchpoints, so do the next best thing
+  // and restore the original value
+  g_val = 2;
+  g_val = 0;
+  execl(argv0, argv0, parent_done_str, NULL);
+  assert(0 && "this should not be reached");
+  return 1;
+}
+
+int child_top_func(void *argv0_ptr) {
   const char *argv0 = static_cast<char*>(argv0_ptr);
 
+  int ret = close(parent_done[1]);
+  assert(ret == 0);
+
   // NB: when using vfork(), the parent may be suspended while running
   // this function, so do not rely on any synchronization until we exec
 #if defined(TEST_FORK)
@@ -38,17 +53,7 @@ int child_func(void *argv0_ptr) {
 #endif
     wait_for_parent();
 
-  int ret = close(parent_done[1]);
-  assert(ret == 0);
-
-  // we need to avoid memory modifications for vfork(), yet we want
-  // to be able to test watchpoints, so do the next best thing
-  // and restore the original value
-  g_val = 2;
-  g_val = 0;
-  execl(argv0, argv0, parent_done_str, NULL);
-  assert(0 && "this should not be reached");
-  return 1;
+  return child_func(argv0);
 }
 
 int main(int argc, char* argv[]) {
@@ -77,12 +82,12 @@ int main(int argc, char* argv[]) {
   assert(ret != -1);
 
 #if defined(TEST_CLONE)
-  pid_t pid = clone(child_func, &stack[sizeof(stack)], 0, argv[0]);
+  pid_t pid = clone(child_top_func, &stack[sizeof(stack)], 0, argv[0]);
 #elif defined(TEST_FORK)
   pid_t pid = TEST_FORK();
   // NB: this must be equivalent to the clone() call above
   if (pid == 0)
-    _exit(child_func(argv[0]));
+    _exit(child_top_func(argv[0]));
 #endif
   assert(pid != -1);
 


        


More information about the lldb-commits mailing list