The attached patch makes each thread remember the threadname if the application set one. This is done by intercepting the call to prctl(PR_SET_NAME, name). The name is then remembered in struct ThreadState. Then when printing a tid, I changed the code to also print the threadname. That makes error output and vgdb usage with lots of threads more funny. Reproducible: Always
Created attachment 81064 [details] remember threadname and print it when printing tid
The patch could be changed to make the default threadname be the same as argv[0] as for normal applications instead of being empty. I would like to have a testcase for vgdb, but some output filter need to be modified for this.
Created attachment 82308 [details] remember threadname and print it when printing tid (also in xml output) Updated the patch to also write the threadname to xml output. run testcase for text and xml output.
How should the xml changes be documented?
Thanks for the patch. Quite useful. I applied it with some minor mods as r13553.. As for your question regarding the documentation of the XML, that is in docs/internal/xml-output-protocol4.txt. Yeah, we should probably have a DTD. Maybe some day...
Closing now..
If a client does call pthread_setname_np (or directly prctrl) a second time to change the name, the first threadname is leaked. See this output from outer/inner on modified threadname.c: ==3366== 16 bytes in 1 blocks are definitely lost in loss record 11 of 125 ==3366== at 0x2803E365: vgPlain_arena_malloc (m_mallocfree.c:1710) ==3366== by 0x2803F29F: vgPlain_arena_strdup (m_mallocfree.c:2264) ==3366== by 0x2809EA34: vgSysWrap_linux_sys_prctl_after (syswrap-linux.c:957) ==3366== by 0x28089C57: vgPlain_post_syscall (syswrap-main.c:1784) ==3366== by 0x2808A366: vgPlain_client_syscall (syswrap-main.c:1706) ==3366== by 0x28086601: handle_syscall (scheduler.c:1068) ==3366== by 0x28087E46: vgPlain_scheduler (scheduler.c:1346) ==3366== by 0x2809A91E: run_a_thread_NORETURN (syswrap-linux.c:103) ==3366== by 0x2809ACB0: vgModuleLocal_start_thread_NORETURN (syswrap-linux.c:304) ==3366== by 0x280C5028: ??? (in /home/masc1329/work-hd/valgrind-inner.git/memcheck/memcheck-x86-linux)
(In reply to comment #7) > If a client does call pthread_setname_np (or directly prctrl) a second time > to change the name, the first threadname is leaked. > Yes, I have heard :) WIll fix.
(In reply to comment #8) > (In reply to comment #7) > > If a client does call pthread_setname_np (or directly prctrl) a second time > > to change the name, the first threadname is leaked. > > > > Yes, I have heard :) WIll fix. Done in 13561.