Commit 255a3c99 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fe1ca6f5
......@@ -201,7 +201,7 @@ func parseTraceEvent(prog *loader.Program, pkgi *loader.PackageInfo, srcfile *as
}
// packageTrace returns tracing information about a package
func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package {
func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) (*Package, error) {
eventv := []*traceEvent{}
importv := []*traceImport{}
......@@ -223,7 +223,7 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package {
textv := strings.SplitN(comment.Text, " ", 2)
if len(textv) != 2 {
log.Fatalf("%v: invalid directive format")
return nil, fmt.Errorf("%v: invalid directive format", pos)
}
directive, arg := textv[0], textv[1]
......@@ -231,22 +231,28 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package {
case "//trace:event":
event, err := parseTraceEvent(prog, pkgi, file, pos, arg)
if err != nil {
log.Fatal(err)
nil, err
}
eventv = append(eventv, event)
case "//trace:import":
// Unqote arg as in regular import
importPath, err := strconv.Unquote(arg)
if err != nil || arg[0] == `'` {
nil, fmt.Errorf("%v: invalid trace-import path %v", pos, arg)
}
// reject duplicate imports
for _, imported := range importv {
if arg == imported.PkgPath {
log.Fatalf("%v: duplicate trace import of %v (previous at %v)", pos, arg, imported.Pos)
if importPath == imported.PkgPath {
return nil, fmt.Errorf("%v: duplicate trace import of %v (previous at %v)", pos, importPath, imported.Pos)
}
}
importv = append(importv, &traceImport{Pos: pos, PkgPath: arg})
importv = append(importv, &traceImport{Pos: pos, PkgPath: importPath})
default:
log.Fatalf("%v: unknown tracing directive %q", pos, directive)
return nil, fmt.Errorf("%v: unknown tracing directive %q", pos, directive)
}
}
}
......
......@@ -3,7 +3,7 @@ package pkg1
import (
"net/url"
// extra import which is used in package but should not be used in tracing
// extra import which is used in package but should not be used in tracing code
"fmt"
)
......@@ -41,3 +41,6 @@ func ParseURL(ustr string) (*url.URL, error) {
func DoSomething(topic string) {
traceDoSomething(topic)
}
// TODO package-local non-exported tracepoint
package pkg2
import "a/pkg1" // TODO should not be needed eventually
// XXX vvv kill
//import "a/pkg1" // TODO should not be needed eventually
//trace:import a/pkg1
//trace:import "a/pkg1"
//trace:event DoSomething(i, j int, q string)
// additional tracepoint which pkg2 defines
//trace:event traceDoSomething(i, j int, q string)
func DoSomething(i, j int, q string) {
traceDoSomething(i, j, q)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment