From edbf1f1e04bdad0e4c42f95cbd3807d4948a7442 Mon Sep 17 00:00:00 2001 From: OscarBohlin Date: Thu, 13 Feb 2025 16:10:42 +0100 Subject: [PATCH 1/5] Ignore dot-to-dot conversion in outputDot --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 92fe911..d610736 100644 --- a/main.go +++ b/main.go @@ -108,6 +108,10 @@ func outputDot(fname string, outputFormat string) { log.Fatalf("%v\n", writeErr) } + if outputFormat == "dot" { + return + } + log.Printf("converting dot to %s\n", outputFormat) _, err = dotToImage(fname, outputFormat, output) From 21d3cc92d842937489e09e4962186aa694009194 Mon Sep 17 00:00:00 2001 From: OscarBohlin Date: Fri, 14 Feb 2025 15:28:05 +0100 Subject: [PATCH 2/5] add vta analysis option --- analysis.go | 13 ++++++++++++- main.go | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/analysis.go b/analysis.go index 86ad102..8aeaf8e 100644 --- a/analysis.go +++ b/analysis.go @@ -16,6 +16,7 @@ import ( "golang.org/x/tools/go/callgraph" "golang.org/x/tools/go/callgraph/cha" "golang.org/x/tools/go/callgraph/rta" + "golang.org/x/tools/go/callgraph/vta" "golang.org/x/tools/go/callgraph/static" "golang.org/x/tools/go/packages" @@ -29,6 +30,7 @@ const ( CallGraphTypeStatic CallGraphType = "static" CallGraphTypeCha CallGraphType = "cha" CallGraphTypeRta CallGraphType = "rta" + CallGraphTypeVta CallGraphType = "vta" ) // ==[ type def/func: analysis ]=============================================== @@ -134,6 +136,8 @@ func (a *analysis) DoAnalysis( graph = static.CallGraph(prog) case CallGraphTypeCha: graph = cha.CallGraph(prog) + case CallGraphTypeVta: + fallthrough case CallGraphTypeRta: mains, err := mainPackages(prog.AllPackages()) if err != nil { @@ -152,8 +156,15 @@ func (a *analysis) DoAnalysis( for _, init := range inits { roots = append(roots, init) } - graph = rta.Analyze(roots, true).CallGraph + + if algo == CallGraphTypeVta { + funcs := make(map[*ssa.Function]bool) + for fun := range graph.Nodes { + funcs[fun] = true + } + graph = vta.CallGraph(funcs, graph) + } default: return fmt.Errorf("invalid call graph type: %s", a.opts.algo) } diff --git a/main.go b/main.go index d610736..d31ea18 100644 --- a/main.go +++ b/main.go @@ -43,8 +43,8 @@ var ( outputFile = flag.String("file", "", "output filename - omit to use server mode") outputFormat = flag.String("format", "svg", "output file format [svg | png | jpg | ...]") cacheDir = flag.String("cacheDir", "", "Enable caching to avoid unnecessary re-rendering, you can force rendering by adding 'refresh=true' to the URL query or emptying the cache directory") - callgraphAlgo = flag.String("algo", string(CallGraphTypeStatic), fmt.Sprintf("The algorithm used to construct the call graph. Possible values inlcude: %q, %q, %q", - CallGraphTypeStatic, CallGraphTypeCha, CallGraphTypeRta)) + callgraphAlgo = flag.String("algo", string(CallGraphTypeStatic), fmt.Sprintf("The algorithm used to construct the call graph. Possible values inlcude: %q, %q, %q, %q", + CallGraphTypeStatic, CallGraphTypeCha, CallGraphTypeRta, CallGraphTypeVta)) debugFlag = flag.Bool("debug", false, "Enable verbose log.") versionFlag = flag.Bool("version", false, "Show version and exit.") From ab3265f5fb8d4b1fa6c31d742c6a9877f1c989b2 Mon Sep 17 00:00:00 2001 From: OscarBohlin Date: Mon, 17 Feb 2025 16:59:54 +0100 Subject: [PATCH 3/5] fix indentation --- analysis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analysis.go b/analysis.go index 8aeaf8e..b582e33 100644 --- a/analysis.go +++ b/analysis.go @@ -30,7 +30,7 @@ const ( CallGraphTypeStatic CallGraphType = "static" CallGraphTypeCha CallGraphType = "cha" CallGraphTypeRta CallGraphType = "rta" - CallGraphTypeVta CallGraphType = "vta" + CallGraphTypeVta CallGraphType = "vta" ) // ==[ type def/func: analysis ]=============================================== From 00724db4edc0dc46f8f58e06af0640968855406a Mon Sep 17 00:00:00 2001 From: OscarBohlin Date: Mon, 17 Feb 2025 17:01:18 +0100 Subject: [PATCH 4/5] document vta algorithm in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 271179b..4a70935 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Usage of go-callvis: -tests Include test code. -algo string - Use specific algorithm for package analyzer: static, cha or rta (default "static") + Use specific algorithm for package analyzer: static, cha, rta or vta (default "static") -version Show version and exit. ``` From 804786bf5b3e3306c81c3dad0d8bfe26ca30ceb7 Mon Sep 17 00:00:00 2001 From: OscarBohlin Date: Mon, 17 Feb 2025 17:01:18 +0100 Subject: [PATCH 5/5] document vta algorithm in README --- README.md | 2 +- main.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 271179b..4a70935 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ Usage of go-callvis: -tests Include test code. -algo string - Use specific algorithm for package analyzer: static, cha or rta (default "static") + Use specific algorithm for package analyzer: static, cha, rta or vta (default "static") -version Show version and exit. ``` diff --git a/main.go b/main.go index d31ea18..4b0987f 100644 --- a/main.go +++ b/main.go @@ -108,10 +108,6 @@ func outputDot(fname string, outputFormat string) { log.Fatalf("%v\n", writeErr) } - if outputFormat == "dot" { - return - } - log.Printf("converting dot to %s\n", outputFormat) _, err = dotToImage(fname, outputFormat, output)