mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07:00
x/tools/cmd/callgraph: add -ptalog flag
Since this tool is a handy way to run the pointer analysis during debugging. Change-Id: If9a62f71dd8651ad6c782ead85bb84f09c703cba Reviewed-on: https://go-review.googlesource.com/17382 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
eb69368e05
commit
c0008c5889
@ -20,12 +20,14 @@ package main // import "golang.org/x/tools/cmd/callgraph"
|
||||
// callee file/line/col
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"go/token"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"text/template"
|
||||
@ -41,15 +43,21 @@ import (
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
)
|
||||
|
||||
var algoFlag = flag.String("algo", "rta",
|
||||
`Call graph construction algorithm (static, cha, rta, pta)`)
|
||||
// flags
|
||||
var (
|
||||
algoFlag = flag.String("algo", "rta",
|
||||
`Call graph construction algorithm (static, cha, rta, pta)`)
|
||||
|
||||
var testFlag = flag.Bool("test", false,
|
||||
"Loads test code (*_test.go) for imported packages")
|
||||
testFlag = flag.Bool("test", false,
|
||||
"Loads test code (*_test.go) for imported packages")
|
||||
|
||||
var formatFlag = flag.String("format",
|
||||
"{{.Caller}}\t--{{.Dynamic}}-{{.Line}}:{{.Column}}-->\t{{.Callee}}",
|
||||
"A template expression specifying how to format an edge")
|
||||
formatFlag = flag.String("format",
|
||||
"{{.Caller}}\t--{{.Dynamic}}-{{.Line}}:{{.Column}}-->\t{{.Callee}}",
|
||||
"A template expression specifying how to format an edge")
|
||||
|
||||
ptalogFlag = flag.String("ptalog", "",
|
||||
"Location of the points-to analysis log file, or empty to disable logging.")
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc)
|
||||
@ -194,6 +202,25 @@ func doCallgraph(ctxt *build.Context, algo, format string, tests bool, args []st
|
||||
cg = cha.CallGraph(prog)
|
||||
|
||||
case "pta":
|
||||
// Set up points-to analysis log file.
|
||||
var ptalog io.Writer
|
||||
if *ptalogFlag != "" {
|
||||
if f, err := os.Create(*ptalogFlag); err != nil {
|
||||
log.Fatalf("Failed to create PTA log file: %s", err)
|
||||
} else {
|
||||
buf := bufio.NewWriter(f)
|
||||
ptalog = buf
|
||||
defer func() {
|
||||
if err := buf.Flush(); err != nil {
|
||||
log.Printf("flush: %s", err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
log.Printf("close: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
main, err := mainPackage(prog, tests)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -201,6 +228,7 @@ func doCallgraph(ctxt *build.Context, algo, format string, tests bool, args []st
|
||||
config := &pointer.Config{
|
||||
Mains: []*ssa.Package{main},
|
||||
BuildCallGraph: true,
|
||||
Log: ptalog,
|
||||
}
|
||||
ptares, err := pointer.Analyze(config)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user