Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASan should print thread names. #79

Closed
ramosian-glider opened this issue Aug 31, 2015 · 13 comments
Closed

ASan should print thread names. #79

ramosian-glider opened this issue Aug 31, 2015 · 13 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 79

Calling prctl(PR_SET_NAME) to name the threads is a nice feature that may be used by
many clients (Chromium does it, so does PulseAudio: http://0pointer.de/blog/projects/name-your-threads.html)
It will be nice to print the thread names in ASan reports.

Reported by ramosian.glider on 2012-06-14 16:03:44

@ramosian-glider
Copy link
Member Author

I'd like to try to implement this when I get time.  Any hints, e.g., where to start
looking.

Reported by mohamed.omar.bana on 2012-07-06 10:02:17

@ramosian-glider
Copy link
Member Author

First, you need a small program that spawns a thread, sets its name (GDB can help to
check whether it actually happens) and crashes because of an ASan error. We'll need
to put it into the test suite later.
Next, you'll need to wrap prctl() on Linux and pthread_setname_np() on Mac and store
the name somewhere. Mac-specific wrappers reside in asan_mac.cc, you'll need to introduce
something similar for Linux as well (maybe rename them to InitializePlatformInterceptors?)
The thread name should be stored in AsanThreadSummary, as we may want to print them
after the thread has been deleted.
After all, you'll need to replace all the code printing "T%d" with calls to an AsanThreadSummary
method that returns the thread number together with thread name (if it's available).
Keep in mind this may affect the output tests.

For the record, name-your-threads.html is down, but is available from Google cache:
http://webcache.googleusercontent.com/search?sugexp=chrome,mod=10&sourceid=chrome&ie=UTF-8&q=cache%3A0pointer.de%2Fblog%2Fprojects%2Fname-your-threads.html

Reported by ramosian.glider on 2012-07-06 10:41:28

@ramosian-glider
Copy link
Member Author

http://llvm.org/viewvc/llvm-project?rev=169598&view=rev implements part of what's needed.
Alex, Tiumur, what's the analog to prctl(PR_SET_NAME) on Mac/Windows. 

Also, how do we couple this with tsan's AnnotateThreadName? 
Should we route AnnotateThreadName to prctl? Unfortunately, names in prctl are limited
with 15 bytes, so that may degrade our functionality... 

Perhaps like this? 
  SanitizerSetThreadName calls prctl and also remembers the full name in a thread-local
variable. (not all platforms have TLS)

  SanitizerGetThreadName checks if we have our own thread-local variable set. 
  If yes, it returns it, otherwise it returns what's in prctl

Thoughts? 

Reported by konstantin.s.serebryany on 2012-12-07 11:35:26

@ramosian-glider
Copy link
Member Author

Reported by konstantin.s.serebryany on 2012-12-07 11:41:59

@ramosian-glider
Copy link
Member Author

I can't help with the other parts, but prctl(PR_SET_NAME,X,0,0,0) is also the right
way to set thread names on Mac.

Reported by lee@leecbaker.com on 2012-12-07 13:53:17

@ramosian-glider
Copy link
Member Author

http://llvm.org/viewvc/llvm-project?rev=169601&view=rev  implements 
reporting thread names in the actual reports: 

% AsanTest --gtest_filter=*DISABLED_DemoThreadedTest --gtest_also_run_disabled_tests
 2>&1 | grep hread 
...
WRITE of size 4 at 0x7fbb5ab95040 thread T3 (UseThr)
freed by thread T2 (FreeThr) here:
previously allocated by thread T1 (AllocThr) here:
Thread T3 (UseThr) created by T0 here:
Thread T2 (FreeThr) created by T0 here:
Thread T1 (AllocThr) created by T0 here:


Reported by konstantin.s.serebryany on 2012-12-07 15:18:50

@ramosian-glider
Copy link
Member Author

> what's the analog to prctl(PR_SET_NAME) on Windows
http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx

You could have looked it up in the Chromium sources, base/threading/platform_thread_win.cc

Reported by timurrrr@google.com on 2012-12-08 09:26:23

@ramosian-glider
Copy link
Member Author

FTR:
automagically, the current asan implementation on linux works for pthread_setname_np,
because this function calls prctl(PR_SET_NAME)

Reported by konstantin.s.serebryany on 2013-01-17 11:50:33

@ramosian-glider
Copy link
Member Author

FTR, this is only true if pthread_setname_np() is being called for the current thread.
Not sure if the other case is used wide enough.

Reported by ramosian.glider on 2013-01-17 12:02:25

@ramosian-glider
Copy link
Member Author

Reported by konstantin.s.serebryany on 2013-02-15 14:31:32

  • Labels added: OpSys-Windows, OpSys-OSX

@ramosian-glider
Copy link
Member Author

Reported by ramosian.glider on 2015-07-30 09:05:30

  • Labels added: ProjectAddressSanitizer

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:06:54

@ramosian-glider
Copy link
Member Author

Fixed long ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant