Skip to content

Commit

Permalink
compiler-rt/lib/tsan: allow the Go runtime to return multiple stack f…
Browse files Browse the repository at this point in the history
…rames for a single PC

This fix allows tsan to report stack traces correctly even in the
presence of mid-stack inlining by the Go compiler.

See golang/go#33309
  • Loading branch information
randall77 committed Sep 16, 2019
1 parent 8626a35 commit 1328352
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/tsan/go/tsan_go.cpp
Expand Up @@ -54,20 +54,33 @@ struct SymbolizeCodeContext {
};

SymbolizedStack *SymbolizeCode(uptr addr) {
SymbolizedStack *s = SymbolizedStack::New(addr);
SymbolizeCodeContext cbctx;
internal_memset(&cbctx, 0, sizeof(cbctx));
cbctx.pc = addr;
go_runtime_cb(CallbackSymbolizeCode, &cbctx);
if (cbctx.res) {
SymbolizedStack *first = SymbolizedStack::New(addr);
SymbolizedStack *s = first;
while(true) {
SymbolizeCodeContext cbctx;
internal_memset(&cbctx, 0, sizeof(cbctx));
cbctx.pc = addr;
go_runtime_cb(CallbackSymbolizeCode, &cbctx);
if (cbctx.res == 0) {
break;
}
AddressInfo &info = s->info;
info.module_offset = cbctx.off;
info.function = internal_strdup(cbctx.func ? cbctx.func : "??");
info.file = internal_strdup(cbctx.file ? cbctx.file : "-");
info.line = cbctx.line;
info.column = 0;

if (cbctx.pc == addr) { // outermost (non-inlined) function
break;
}
addr = cbctx.pc;
// Allocate a stack entry for the parent of the inlined function.
SymbolizedStack *s2 = SymbolizedStack::New(addr);
s->next = s2;
s = s2;
}
return s;
return first;
}

struct SymbolizeDataContext {
Expand Down

0 comments on commit 1328352

Please sign in to comment.