From c3c107f67c86e9e0bf03f831be4f9417c75463a4 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Fri, 30 Nov 2012 10:27:43 +0400 Subject: [PATCH] cmd/gc: racewalk: collect stack traces in sync and sync/atomic W/o this change stack traces do not show from where sync.Once() or atomic.XXX was called. This change add funcenter/exit instrumentation to sync/sync.atomic packages. R=golang-dev CC=golang-dev https://golang.org/cl/6854112 --- src/cmd/gc/racewalk.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/cmd/gc/racewalk.c b/src/cmd/gc/racewalk.c index 17e02a19b2..2d216ec67a 100644 --- a/src/cmd/gc/racewalk.c +++ b/src/cmd/gc/racewalk.c @@ -28,26 +28,42 @@ static void foreach(Node *n, void(*f)(Node*, void*), void *c); static void hascallspred(Node *n, void *c); static Node* detachexpr(Node *n, NodeList **init); -static const char *omitPkgs[] = {"runtime", "runtime/race", "sync", "sync/atomic"}; +// Do not instrument the following packages at all, +// at best instrumentation would cause infinite recursion. +static const char *omit_pkgs[] = {"runtime", "runtime/race"}; +// Only insert racefuncenter/racefuncexit into the following packages. +// Memory accesses in the packages are either uninteresting or will cause false positives. +static const char *noinst_pkgs[] = {"sync", "sync/atomic"}; + +static int +ispkgin(const char **pkgs, int n) +{ + int i; + + if(myimportpath) { + for(i=0; inbody, nil); - // nothing interesting for race detector in fn->enter - racewalklist(fn->exit, nil); + if(!ispkgin(noinst_pkgs, nelem(noinst_pkgs))) { + racewalklist(fn->nbody, nil); + // nothing interesting for race detector in fn->enter + racewalklist(fn->exit, nil); + } // nodpc is the PC of the caller as extracted by // getcallerpc. We use -widthptr(FP) for x86.