From 5831d16d18029819d39f99bdc2060b8eff410b6b Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Mon, 22 May 2017 16:11:25 -0400 Subject: [PATCH] cmd/callgraph: fix "import path of the enclosing package" example in usage Caller is *ssa.Function. Its Pkg field is *ssa.Package. But ssa.Package struct doesn't contain either field or method named Object. So one gets the following error: $ callgraph -format '{{.Caller.Pkg.Object.Path}} -> {{.Callee.Pkg.Object.Path}}' \ $(go env GOROOT)/src/net/http/triv.go | sort | uniq callgraph: template: -format:1:9: executing "-format" at <.Caller.Pkg.Object.P...>: can't evaluate field Object in type *ssa.Package ssa.Package contains Pkg field: Pkg *types.Package // the corresponding go/types.Package types.Package contains Path() method that returns the package path. That appears to be the right way to get the "import path of the enclosing package" with the current x/tools/go/ssa API. Fixes golang/go#20459. Change-Id: I3cb7b61b767148f5c771d57f8f5e7e6ab20aea87 Reviewed-on: https://go-review.googlesource.com/43812 Reviewed-by: Avelino Reviewed-by: Alan Donovan --- cmd/callgraph/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/callgraph/main.go b/cmd/callgraph/main.go index bff39c2395..8ef4597c1f 100644 --- a/cmd/callgraph/main.go +++ b/cmd/callgraph/main.go @@ -114,7 +114,7 @@ Flags: Caller and Callee are *ssa.Function values, which print as "(*sync/atomic.Mutex).Lock", but other attributes may be - derived from them, e.g. Caller.Pkg.Object.Path yields the + derived from them, e.g. Caller.Pkg.Pkg.Path yields the import path of the enclosing package. Consult the go/ssa API documentation for details. @@ -128,7 +128,7 @@ Examples: Same, but show only the packages of each function: - callgraph -format '{{.Caller.Pkg.Object.Path}} -> {{.Callee.Pkg.Object.Path}}' \ + callgraph -format '{{.Caller.Pkg.Pkg.Path}} -> {{.Callee.Pkg.Pkg.Path}}' \ $GOROOT/src/net/http/triv.go | sort | uniq Show functions that make dynamic calls into the 'fmt' test package,