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

runtime/race: use runtime.CallersFrames #19749

Open
josharian opened this issue Mar 28, 2017 · 4 comments

Comments

@josharian
Copy link
Contributor

commented Mar 28, 2017

The backtraces from the race detector don't include inlined frames. But we now have that information available, via runtime.CallersFrames. It'd be nice to use it.

I went to look at adding this myself, but I'd need a few pointers--the race detector code is out of tree, and I can't find the place where the race detector traceback interacts with the Go runtime.

cc @dvyukov

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 28, 2017

The race detector run time support calls back into Go to print a stack trace. The callback function is passed to the race detector in the call to __tsan_init from raceinit in runtime/race.go. The callback function is racecallbackthunk, defined in runtime/race_amd64.s. It calls racecallback in runtime/race.go, which calls FuncForPC to get the Go function name.

The PC values passed to FuncForPC are collected by calls to racefuncenter and racefuncexit inserted by the compiler (cmd/compile/internal/gc/racewalk.go).

So, yes, it would be nice to use CallersFrames, but it's not clear that we have the right data or API.

@dvyukov

This comment has been minimized.

Copy link
Member

commented Mar 30, 2017

Re API: yes, need to extend it to make it possible to return several frames. Tsan runtime itself was always able to deal with inlined frames, so it's only tsan<->Go interface that needs to be changed.

Re right data: @ianlancetaylor why do you suspect that the data may not be right? Why calling CallersFrames with a single PC may not work?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 30, 2017

Calling CallersFrames with a single PC will work, but I think that only collecting PCs at function entry points won't produce sufficient info when using mid-stack inlining. If F calls G calls H calls I, and the middle is inlined, the race detector may report a stack trace showing F calling I. To get the correct stack trace it needs to have not just the PC when it enters I, but the PC within F that calls I.

Perhaps the race detector does collect that, and I just understand how it works.

@dvyukov

This comment has been minimized.

Copy link
Member

commented Mar 30, 2017

@ianlancetaylor on function entry it obtains caller pc, so it's actually call site. So everything should work.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Apr 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.