Giter Site home page Giter Site logo

amit-davidson / chronos Goto Github PK

View Code? Open in Web Editor NEW
420.0 5.0 11.0 13.75 MB

Chronos - A static race detector for the go language

License: MIT License

Go 100.00%
analysis golang synchronization detection race-conditions race-detection mutex-synchronisation pointer-analysis static-code-analysis static-analysis ssa detects-races data-race-detection race-condition go

chronos's Introduction

Chronos

made-with-Go made-with-Go MIT license PRs Welcome amit-davidson

Chronos is a static race detector for the Go language written in Go.

Quick Start:

Download the package

go get -v github.com/amit-davidson/Chronos/cmd/chronos

Pass the entry point

chronos --file <path_to_main> --mod <path_to_module>

Help

Usage of ./chronos:
  --file string
    	The file containing the entry point of the program
  --mod string
    	Absolute or relative path to the module where the search should be performed. Should end in the format:{VCS}/{organization}/{package}. Packages outside this path are excluded rom the search.

Example:

Features:

Support:

  • Detects races on pointers passed around the program.
  • Analysis of conditional branches, nested functions, interfaces, select, gotos, defers, for loops and recursions.
  • Synchronization using mutex and goroutines starts.

Limitations:

  • Big programs and external packages. (Due to stack overflow)
  • Synchronization using channels, waitgroups, once, cond and atomic.

Chronos vs go race:

Chronos successfully reports cases where go race fails thanks to it's static nature. Mostly because data races appear in unexpected production workloads, which are hard to produce in dev. In addition, go race is having trouble with short programs where without contrived synchronization the program may exit too quickly.

In contrast, Chronos managed to report only 244/403 = 60.5% of go race test cases. This can be explained by Chronos partial support with Go's features so this number will increase in the future. Also, it lacked due to his static nature where context/path sensitivity was required.

Therefore, I suggest using both according the strengths and weaknesses of each of the race detectors.

Credits:

Jan Wen, J., Jhala, R., & Lerner, S. (n.d.). RELAY: Static Race Detection on Millions of Lines of Code
Colin J. Fidge (February 1988). Timestamps in Message-Passing Systems That Preserve the Partial Ordering"

More examples:


chronos's People

Contributors

amit-davidson avatar de-sh avatar deepsourcebot avatar ninedraft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

chronos's Issues

How to Contribute?

Amazing project.
I'll be happy to contribute.
What are the milestones to start working with?

Add more user-friendly errors

Enhancement

When the program panics the entire stack trace is returned. A more user friendly should be returned.
It should contain the failing stacktrace but also the following messages as in the example stacktrace below (taken from that of the stdlib pointer package):

  • Internal panic in while performing analysis: at the top

  • Error in analysis (please report this bug) at the bottom

For that, a recover should be added to the start of the program and catch all panics and wrap them with the added messages.

Internal panic in while performing analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
        /usr/local/Cellar/go/1.15.3/libexec/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
        /usr/local/Cellar/go/1.15.3/libexec/src/runtime/debug/stack.go:16 +0x25
golang.org/x/tools/go/pointer.Analyze.func1(0xc05b607b00)
        /Users/amdavidson/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:227 +0x10b
panic(0x13502e0, 0xc03aff2380)
        /usr/local/Cellar/go/1.15.3/libexec/src/runtime/panic.go:969 +0x1b9
golang.org/x/tools/go/pointer.(*analysis).taggedValue(0xc042b7d340, 0xc00002acfd, 0x2, 0x64, 0xc00d7a8000)
        /Users/amdavidson/go/pkg/mod/golang.org/x/[email protected]/go/pointer/gen.go:272 +0x105
golang.org/x/tools/go/pointer.(*invokeConstraint).solve(0xc0499eb780, 0xc042b7d340, 0xc082a8e400)
        /Users/amdavidson/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:317 +0x24e
golang.org/x/tools/go/pointer.(*analysis).solveConstraints(0xc042b7d340, 0xc049a7f620, 0xc082a8e400)
        /Users/amdavidson/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:165 +0x178
golang.org/x/tools/go/pointer.(*analysis).solve(0xc042b7d340)
        /Users/amdavidson/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:59 +0x1ad
golang.org/x/tools/go/pointer.Analyze(0xc042efc690, 0x0, 0x1437dc0, 0xc03aff2390)
        /Users/amdavidson/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:331 +0x4bc
github.com/amit-davidson/Chronos/pointerAnalysis.Analysis(0xc02ebbdb00, 0xc02e1361e0, 0xc042cd6f00, 0x5c, 0x60, 0x0, 0x7c)
        /Users/amdavidson/go/pkg/mod/github.com/amit-davidson/[email protected]/pointerAnalysis/PointerAnalysis.go:51 +0x38a
main.main()
        /Users/amdavidson/go/pkg/mod/github.com/amit-davidson/[email protected]/cmd/chronos/main.go:35 +0x473
Error in analysis (please report this bug)

SIGSEGV on analysing a repo

Command executed:

chronos --pkg gitlab.com/poldi1405/bulkrename --file main.go

Version: 29ca129

Output:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c8598]

goroutine 1 [running]:
github.com/amit-davidson/Chronos/ssaUtils.GetDefersSummary(0xc00a036640, 0xc002f7ef20, 0x9fd698, 0x0, 0x0, 0xc002211f50)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:95 +0x238
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc00a036640, 0xc005090780, 0x1)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:177 +0x1dc
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc00a036640, 0xc00617a140, 0x405529, 0x0)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc00a036640, 0xc006161ef0, 0x744980)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc00a036640, 0xc006161ef0, 0x0)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:58 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0018c9a40, 0xc00a036640, 0xc006161ef0)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:121 +0x1f0
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc00a036640, 0xc006161ef0, 0x7ffd54d59bbf, 0x1f)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:69 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc00a036640, 0xc005090500, 0x1)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc00a036640, 0xc0018c9980, 0x4054c9, 0x0)
	/home/moritz/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:45 +0x49b
main.main()
	/home/moritz/go/src/github.com/amit-davidson/Chronos/cmd/chronos/main.go:34 +0x43c

what “--mod <path_to_module>” means in chronos

My project structure is:

- main
    - main.go

And in main.go, I copied code from chronos testdata:

package main

type A struct {
	X int
}

func main() {
	a := A{}
	go func() {
		a.X = 1
	}()
	a.X = 2
}

But when I tried the args :

--file <path to project>\main\main.go --mod <path to project>\main

The output is No data races found
What's wrong? And what's mod in chronos?
Thanks.

Panic while self check

Runnig chronos on ./cmd/main.go will cause a panic

Call: chronos -file ./cmd/main.go

Result:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c78d8]

goroutine 1 [running]:
github.com/amit-davidson/Chronos/ssaUtils.GetDefersSummary(0xc01ea325c0, 0xc019c78790, 0xa00880, 0x0, 0x0, 0xc011cfec80)
	/dev/Chronos/ssaUtils/CFG.go:94 +0x238
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc01ea325c0, 0xc010bc68c0, 0x1)
	/dev/Chronos/ssaUtils/Functions.go:177 +0x1dc
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc01ea325c0, 0xc010d982c0, 0x9b09b5, 0x0)
	/dev/Chronos/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc01ea325c0, 0xc0037c33f0, 0x1)
	/dev/Chronos/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc01ea325c0, 0xc0037c33f0, 0x2)
	/dev/Chronos/ssaUtils/CFG.go:57 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc01ea295c0, 0xc01ea325c0, 0xc0037c33f0)
	/dev/Chronos/ssaUtils/CFG.go:114 +0x11d
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc01ea295c0, 0xc01ea325c0, 0xc0037c3340)
	/dev/Chronos/ssaUtils/CFG.go:131 +0x1bd
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc01ea295c0, 0xc01ea325c0, 0xc0037c3290)
	/dev/Chronos/ssaUtils/CFG.go:131 +0x1bd
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc01ea325c0, 0xc0037c3290, 0xc001d62240, 0x21)
	/dev/Chronos/ssaUtils/CFG.go:68 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc01ea325c0, 0xc010c1ea00, 0x1)
	/dev/Chronos/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc01ea325c0, 0xc01ea29500, 0x9b0810, 0x0)
	/dev/Chronos/ssaUtils/Functions.go:45 +0x49b
main.main()
	/dev/Chronos/cmd/main.go:34 +0x43c

Internal panic in pointer analysis

$ chronos --file ./pilot/cmd/pilot-agent/main.go
Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x22
golang.org/x/tools/go/pointer.Analyze.func1(0xc03e10fad0)
        /usr/local/google/home/howardjohn/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:227 +0x10b
panic(0x8b8b20, 0xc0b6a0a760)
        /usr/local/go/src/runtime/panic.go:967 +0x15d
golang.org/x/tools/go/pointer.(*analysis).taggedValue(0xc07a85d6c0, 0xc0000984b7, 0x2, 0x64, 0xc0338c5880)
        /usr/local/google/home/howardjohn/go/pkg/mod/golang.org/x/[email protected]/go/pointer/gen.go:272 +0x102
golang.org/x/tools/go/pointer.(*invokeConstraint).solve(0xc0bb920750, 0xc07a85d6c0, 0xc070062140)
        /usr/local/google/home/howardjohn/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:317 +0x24c
golang.org/x/tools/go/pointer.(*analysis).solveConstraints(0xc07a85d6c0, 0xc0aea87170, 0xc070062140)
        /usr/local/google/home/howardjohn/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:165 +0x171
golang.org/x/tools/go/pointer.(*analysis).solve(0xc07a85d6c0)
        /usr/local/google/home/howardjohn/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:59 +0x1a2
golang.org/x/tools/go/pointer.Analyze(0xc040099180, 0x0, 0xa290a0, 0xc0b6a0a7b0)
        /usr/local/google/home/howardjohn/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:331 +0x4a5
github.com/amit-davidson/Chronos/pointerAnalysis.Analysis(0xc05177de00, 0xc0102010e0, 0xc0462aae00, 0x7, 0x8, 0x0, 0x7c)
        /usr/local/google/home/howardjohn/go/pkg/mod/github.com/amit-davidson/[email protected]/pointerAnalysis/PointerAnalysis.go:51 +0x36a
main.main()
        /usr/local/google/home/howardjohn/go/pkg/mod/github.com/amit-davidson/[email protected]/cmd/chronos/main.go:35 +0x468
Error in analysis:internal error in pointer analysis: not a tagged object: n623799 (please report this bug)

Codebase is run against https://github.com/istio/istio

invalid memory address

zhouqiang@MacBook-Pro-4 tidb % /Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/cmd/chronos/chronos --file tidb-server/main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1439ea0]

goroutine 1 [running]:
github.com/amit-davidson/Chronos/ssaUtils.GetDefersSummary(0xc0875e6300, 0xc0695b8580, 0x19acde8, 0x0, 0x0, 0xc0811a60f0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:96 +0x250
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc0875e6300, 0xc065e523c0, 0x1)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:177 +0x1cd
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc0875e6300, 0xc0722538c0, 0x2e85ae2, 0x0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:45 +0x549
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc0875e6300, 0xc072257130, 0x14f5620)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:133 +0x520
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc0875e6300, 0xc072257130, 0x0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:59 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc087c93680, 0xc0875e6300, 0xc072257130)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:122 +0x1e5
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc0875e6300, 0xc072257130, 0xc06a70c000, 0x18)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:70 +0xd6
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc0875e6300, 0xc065e588c0, 0x1)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:174 +0x190
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc0875e6300, 0xc067e319c0, 0x2e8528b, 0x0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:45 +0x549
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc0875e6300, 0xc045e84e70, 0x1)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:133 +0x520
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc0875e6300, 0xc045e84e70, 0x2)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:59 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc087c93040, 0xc0875e6300, 0xc045e84e70)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:122 +0x1e5
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc087c93040, 0xc0875e6300, 0xc045e84dc0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:139 +0x288
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc087c93040, 0xc0875e6300, 0xc045e84d10)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:139 +0x288
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc0875e6300, 0xc045e84d10, 0xc06a70c000, 0x18)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:70 +0xd6
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc0875e6300, 0xc065e58140, 0x1)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:174 +0x190
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc0875e6300, 0xc087c92f40, 0x2e85221, 0x0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:45 +0x549
main.main()
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/cmd/chronos/main.go:34 +0x431

Panic in the tests (37a9373)

Running on 37a9373

go test -race ./e2e-tests/

will cause

--- FAIL: TestE2E (3.24s)
    --- FAIL: TestE2E/Lock (3.24s)
panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 22 [running]:
testing.tRunner.func1.1(0x9b86a0, 0xc000e6a9c0)
	/usr/lib/go/src/testing/testing.go:1076 +0x46a
testing.tRunner.func1(0xc000082d80)
	/usr/lib/go/src/testing/testing.go:1079 +0x636
panic(0x9b86a0, 0xc000e6a9c0)
	/usr/lib/go/src/runtime/panic.go:975 +0x3e9
github.com/amit-davidson/Chronos/e2e-tests/testutils.GetRelativePath(0x1a09dc, 0xc000f9ca00, 0xc000641bf8, 0x0)
	/dev/pet/Chronos/e2e-tests/testutils/JsonDomains.go:68 +0x276
github.com/amit-davidson/Chronos/e2e-tests/testutils.LocksetToJSON(0xc003570030, 0x8db85e)
	/dev/pet/Chronos/e2e-tests/testutils/JsonDomains.go:48 +0x1e5
github.com/amit-davidson/Chronos/e2e-tests/testutils.NewTestResult(0xc003570030, 0xc003570070, 0x2, 0x2, 0xc0037fbf08)
	/dev/pet/Chronos/e2e-tests/testutils/utils.go:18 +0x56
github.com/amit-davidson/Chronos/e2e-tests.TestE2E.func1(0xc000082d80)
	/dev/pet/Chronos/e2e-tests/summary_test.go:187 +0x599
testing.tRunner(0xc000082d80, 0xc0000963f0)
	/usr/lib/go/src/testing/testing.go:1127 +0x203
created by testing.(*T).Run
	/usr/lib/go/src/testing/testing.go:1178 +0x797
FAIL	github.com/amit-davidson/Chronos/e2e-tests	3.287s
FAIL

Another invalid memory address

Using the latest build

zhouqiang@MacBook-Pro-4 bin % ./chronos --file /Users/zhouqiang/go/src/github.com/pingcap/tidb/tidb-server/main.go 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x146f456]

goroutine 1 [running]:
github.com/amit-davidson/Chronos/ssaUtils.GetTopLevelPackageName(0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Packages.go:56 +0x26
github.com/amit-davidson/Chronos/ssaUtils.SetGlobals(0xc020293b80, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/ssaUtils/Packages.go:48 +0xf2
main.main()
	/Users/zhouqiang/go/src/github.com/amit-davidson/Chronos/cmd/chronos/main.go:26 +0x21a

nil pointer dereference HandleCallCommon Functions.go:64

After my first try a month ago when I had a nil pointer exception I now first I ran:
go get -u github.com/amit-davidson/Chronos/cmd/chronos

Then tried again to run the application but no luck. The issue is within a single package I think. I tried with the -pkg flag and seems that all the other packages work well including internal.

Hope this helps you:
Functions.go:64
fs := domain.CreateFunctionState(blockStateRet.GuardedAccesses, blockStateRet.Lockset)

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x146e3c4]

goroutine 1 [running]:
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc04186c780, 0xc02ad5be08, 0x13a592c, 0x0)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:64 +0x774
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc0259b9f48, 0xc02ad4c840, 0xb)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:160 +0x43e
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).calculateBlockStateIfNeeded(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c840)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:90 +0x75
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c840)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:33 +0xa8
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c790)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c6e0)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c630)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c420)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c4d0)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02ad4c370)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02a551ce0)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc02a551c30)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc00c0f9ce0)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc00c0f9c30)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc00c0f9b80)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0259b9ce8, 0xc0259b9f48, 0xc0259b9ba8)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:41 +0x4c2
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).calculateFunctionState(0xc0259b9ce8, 0xc0259b9f48, 0xc00c0f9b80)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/CFG.go:27 +0xd0
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc0259b9f48, 0xc02840b040, 0xc0239a1e60)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:201 +0x298
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc0259b9f48, 0xc04185ae40, 0x13a565f, 0x0)
/Users/developer/go/src/github.com/amit-davidson/Chronos/ssaUtils/Functions.go:63 +0x767
main.main()
/Users/developer/go/src/github.com/amit-davidson/Chronos/cmd/chronos/main.go:34 +0x4b9

Could Chronos detect one arbitrary go file?

Chrono privide such way to use.
$ chronos --file <path_to_main> --mod <path_to_module>

Why should I specify path_to_main, could I just detect one arbitrary go file, like:
$ go run -race mysrc.go

panic: runtime error: invalid memory address or nil pointer dereference

I'm using the following version:

+github.com/amit-davidson/Chronos v0.0.0-20201017170051-1634412958f8 h1:MZrylyYLgUexduUsYWV9DbgxqJduLk3phvT2jGPKJfU=
+github.com/amit-davidson/Chronos v0.0.0-20201017170051-1634412958f8/go.mod h1:w8yL4vxG5cWT/GztYUDpB3vRuOuSimZf0yWp2eRx6Fc=

When trying to analyse a command (sorry, closed source!) I am getting:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c7c07]

goroutine 1 [running]:
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc058872260, 0xc04387ca50, 0xc017beb8c0, 0x1a)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:69 +0xe7
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc058872260, 0xc0399fbe00, 0x1)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc058872260, 0xc0439024c0, 0x1f86e74, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc058872260, 0xc04387c840, 0xc058937df0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc058872260, 0xc04387c840, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:57 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc05895c900, 0xc058872260, 0xc04387c840)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:114 +0x11d
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc058872260, 0xc04387c840, 0xc017beb8c0, 0x1a)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:68 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc058872260, 0xc0399fbcc0, 0x1)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc058872260, 0xc03d6c94c0, 0x1f87a7e, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc058872260, 0xc03cb456b0, 0xc058936fd0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc058872260, 0xc03cb456b0, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:57 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc058945180, 0xc058872260, 0xc03cb456b0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:114 +0x11d
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc058872260, 0xc03cb456b0, 0xc017beb8c0, 0x1a)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:68 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc058872260, 0xc0399fba40, 0x1)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc058872260, 0xc0436ec840, 0x1f9767a, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc058872260, 0xc0436e0bb0, 0xc0589364c0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc058872260, 0xc0436e0bb0, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:57 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc058927cc0, 0xc058872260, 0xc0436e0bb0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:114 +0x11d
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc058872260, 0xc0436e0bb0, 0xc017beb8c0, 0x1a)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:68 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc058872260, 0xc039a34780, 0x1)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc058872260, 0xc03d26da40, 0x1f99056, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc058872260, 0xc02a05e210, 0xc058861e70)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc058872260, 0xc02a05e210, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:57 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc0588652c0, 0xc058872260, 0xc02a05e210)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:114 +0x11d
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc058872260, 0xc02a05e210, 0xc017beb8c0, 0x1a)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:68 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc058872260, 0xc039a61b80, 0x1)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc058872260, 0xc027dff8c0, 0x1f993ed, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:45 +0x49b
github.com/amit-davidson/Chronos/ssaUtils.GetBlockSummary(0xc058872260, 0xc025c76790, 0xc058861a70)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:133 +0x4ff
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary.func1(0xc058872260, 0xc025c76790, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:57 +0x35
github.com/amit-davidson/Chronos/ssaUtils.(*CFG).traverseGraph(0xc058864b80, 0xc058872260, 0xc025c76790)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:114 +0x11d
github.com/amit-davidson/Chronos/ssaUtils.GetBlocksSummary(0xc058872260, 0xc025c76790, 0xc017beb8c0, 0x1a)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/CFG.go:68 +0xdb
github.com/amit-davidson/Chronos/ssaUtils.HandleFunction(0xc058872260, 0xc039a61e00, 0x1)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:174 +0x19f
github.com/amit-davidson/Chronos/ssaUtils.HandleCallCommon(0xc058872260, 0xc058864ac0, 0x1f9932d, 0x0)
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/ssaUtils/Functions.go:45 +0x49b
main.main()
	/home/rjeczalik/pkg/mod/github.com/amit-davidson/[email protected]/cmd/main.go:34 +0x43c

Improve control flow graph to support for loops

Proposal

The control flow graph traverses between vertices from the start to the last block using DFS. If it reaches a block where not all of his dependencies are calculated (A block after a condition where not all the preceding branches were visited yet), then it returns up the graph, and the block will be reached again later from a different path.
Loops pose a problem since the graph is cyclic (due to the back edge between the loop body and header). As a result, the dependencies can't be calculated since each vertice depends on the other.
The traversing function should be improved to support such cases.

For more details:
https://en.wikipedia.org/wiki/Control-flow_graph

Add command line argument for shorter warning output

Enhancement

At the moment, a lengthy description of all the possible race conditions is printed. It includes all the race conditions pairs and the stack trace of that flow. This might be too long and too complicated.
A new command-line argument called --short should be added that will allow displaying less information. It should include:

  • The total amount of possible race conditions

  • The variables themselves (same as in the more lengthy version)

  • Path to the variable (without including the stacktrace)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.