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 ...@@ -201,7 +201,7 @@ func parseTraceEvent(prog *loader.Program, pkgi *loader.PackageInfo, srcfile *as
} }
// packageTrace returns tracing information about a package // 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{} eventv := []*traceEvent{}
importv := []*traceImport{} importv := []*traceImport{}
...@@ -223,7 +223,7 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package { ...@@ -223,7 +223,7 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package {
textv := strings.SplitN(comment.Text, " ", 2) textv := strings.SplitN(comment.Text, " ", 2)
if len(textv) != 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] directive, arg := textv[0], textv[1]
...@@ -231,22 +231,28 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package { ...@@ -231,22 +231,28 @@ func packageTrace(prog *loader.Program, pkgi *loader.PackageInfo) *Package {
case "//trace:event": case "//trace:event":
event, err := parseTraceEvent(prog, pkgi, file, pos, arg) event, err := parseTraceEvent(prog, pkgi, file, pos, arg)
if err != nil { if err != nil {
log.Fatal(err) nil, err
} }
eventv = append(eventv, event) eventv = append(eventv, event)
case "//trace:import": 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 // reject duplicate imports
for _, imported := range importv { for _, imported := range importv {
if arg == imported.PkgPath { if importPath == imported.PkgPath {
log.Fatalf("%v: duplicate trace import of %v (previous at %v)", pos, arg, imported.Pos) 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: 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 ...@@ -3,7 +3,7 @@ package pkg1
import ( import (
"net/url" "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" "fmt"
) )
...@@ -41,3 +41,6 @@ func ParseURL(ustr string) (*url.URL, error) { ...@@ -41,3 +41,6 @@ func ParseURL(ustr string) (*url.URL, error) {
func DoSomething(topic string) { func DoSomething(topic string) {
traceDoSomething(topic) traceDoSomething(topic)
} }
// TODO package-local non-exported tracepoint
package pkg2 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"
// additional tracepoint which pkg2 defines
//trace:event DoSomething(i, j int, q string) //trace:event traceDoSomething(i, j int, q string)
func DoSomething(i, j int, q string) { func DoSomething(i, j int, q string) {
traceDoSomething(i, j, q) 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