]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix the thread-name facility and associated test on Darwin.
authorJulian Seward <jseward@acm.org>
Sun, 12 Oct 2014 13:47:30 +0000 (13:47 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 12 Oct 2014 13:47:30 +0000 (13:47 +0000)
Patch from Rhys Kidd (rhyskidd@gmail.com).  Fixes #339442.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14622

coregrind/m_syswrap/syswrap-darwin.c
memcheck/tests/threadname.c
memcheck/tests/threadname.stderr.exp
memcheck/tests/threadname.vgtest

index 4bb88b37224ff7e82ea9ded415d5e3c8424e45b6..e04e39acf0e22ecaf2ba9e6ce2fee7cb3a1d5f55 100644 (file)
@@ -3915,9 +3915,41 @@ POST(proc_info)
 {
 #if VG_WORDSIZE == 4
    vg_assert(SUCCESS);
+
+   // Intercept internal call to proc_setcontrol() where flavor = 2, arg = 0
+   if (ARG1 == 5 && ARG3 == 2 && LOHI64(ARG4,ARG5) == 0 )
+   {
+       const HChar* new_name = (const HChar*) ARG6;
+       if (new_name) {    // Paranoia
+          ThreadState* tst = VG_(get_ThreadState)(tid);
+          SizeT new_len = VG_(strlen)(new_name);
+           
+          /* Don't bother reusing the memory. This is a rare event. */
+          tst->thread_name =
+             VG_(realloc)("syscall(proc_info)", tst->thread_name, new_len + 1);
+          VG_(strcpy)(tst->thread_name, new_name);
+       }
+   }
+    
    POST_MEM_WRITE(ARG6, ARG7);
 #else
    vg_assert(SUCCESS);
+
+   // Intercept internal call to proc_setcontrol() where flavor = 2, arg = 0
+   if (ARG1 == 5 && ARG3 == 2 && ARG4 == 0 )
+   {
+      const HChar* new_name = (const HChar*) ARG5;
+      if (new_name) {    // Paranoia
+         ThreadState* tst = VG_(get_ThreadState)(tid);
+         SizeT new_len = VG_(strlen)(new_name);
+            
+         /* Don't bother reusing the memory. This is a rare event. */
+         tst->thread_name =
+            VG_(realloc)("syscall(proc_info)", tst->thread_name, new_len + 1);
+         VG_(strcpy)(tst->thread_name, new_name);
+       }
+   }
+
    POST_MEM_WRITE(ARG5, ARG6);
 #endif
 }
index c08f8d825e024ab6cb76a1b3724f0966f06e1c5e..91e7f833eb8b60ac4862bef02d84bd2db7b276f7 100644 (file)
@@ -21,7 +21,11 @@ void* child_fn_2 ( void* arg )
 {
   const char* threadname = "012345678901234";
 
+#  if !defined(VGO_darwin)
   pthread_setname_np(pthread_self(), threadname);
+#  else
+  pthread_setname_np(threadname);
+#  endif
 
   bad_things(4);
 
@@ -33,7 +37,11 @@ void* child_fn_1 ( void* arg )
   const char* threadname = "try1";
   int r;
 
+#  if !defined(VGO_darwin)
   pthread_setname_np(pthread_self(), threadname);
+#  else
+  pthread_setname_np(threadname);
+#  endif
 
   bad_things(3);
 
index 8ee67529794873dfe4be24f17f153243854e1d6d..1cf231375692254aa0fa5aeb9cd7c20a763b5bc9 100644 (file)
@@ -1,50 +1,50 @@
 Invalid write of size 1
    at 0x........: bad_things (threadname.c:16)
-   by 0x........: main (threadname.c:68)
+   by 0x........: main (threadname.c:76)
  Address 0x........ is 0 bytes after a block of size 1 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: bad_things (threadname.c:15)
-   by 0x........: main (threadname.c:68)
+   by 0x........: main (threadname.c:76)
 
 Thread 2:
 Invalid write of size 1
    at 0x........: bad_things (threadname.c:16)
-   by 0x........: child_fn_0 (threadname.c:53)
+   by 0x........: child_fn_0 (threadname.c:61)
    ...
  Address 0x........ is 0 bytes after a block of size 2 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: bad_things (threadname.c:15)
-   by 0x........: child_fn_0 (threadname.c:53)
+   by 0x........: child_fn_0 (threadname.c:61)
    ...
 
 Thread 3 try1:
 Invalid write of size 1
    at 0x........: bad_things (threadname.c:16)
-   by 0x........: child_fn_1 (threadname.c:38)
+   by 0x........: child_fn_1 (threadname.c:46)
    ...
  Address 0x........ is 0 bytes after a block of size 3 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: bad_things (threadname.c:15)
-   by 0x........: child_fn_1 (threadname.c:38)
+   by 0x........: child_fn_1 (threadname.c:46)
    ...
 
 Thread 4 012345678901234:
 Invalid write of size 1
    at 0x........: bad_things (threadname.c:16)
-   by 0x........: child_fn_2 (threadname.c:26)
+   by 0x........: child_fn_2 (threadname.c:30)
    ...
  Address 0x........ is 0 bytes after a block of size 4 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: bad_things (threadname.c:15)
-   by 0x........: child_fn_2 (threadname.c:26)
+   by 0x........: child_fn_2 (threadname.c:30)
    ...
 
 Thread 1:
 Invalid write of size 1
    at 0x........: bad_things (threadname.c:16)
-   by 0x........: main (threadname.c:76)
+   by 0x........: main (threadname.c:84)
  Address 0x........ is 0 bytes after a block of size 5 alloc'd
    at 0x........: malloc (vg_replace_malloc.c:...)
    by 0x........: bad_things (threadname.c:15)
-   by 0x........: main (threadname.c:76)
+   by 0x........: main (threadname.c:84)
 
index 22d04f8b3cb42b2e38a41b6b600ed27b092f7a9f..2692bd078491fc0e87fec67b0b1ecde27b78c2f1 100644 (file)
@@ -1,3 +1,3 @@
 prog: threadname
-prereq: test -e ./threadname && ../../tests/os_test linux
+prereq: test -e ./threadname
 vgopts: -q