diff --git a/pkg/rules/test/errors_hook.go b/pkg/rules/test/errors_hook.go index 3bce71ef..ef298215 100644 --- a/pkg/rules/test/errors_hook.go +++ b/pkg/rules/test/errors_hook.go @@ -83,3 +83,13 @@ func onExitTestGetSetRecv(call errors.CallContext, arg1 int, arg2 float64) { call.SetReturnVal(0, arg1) call.SetReturnVal(1, arg2) } + +func onExitOnlyRet(call errors.CallContext, _ int, _ string) { + call.SetReturnVal(0, 2033) + call.SetReturnVal(1, "hangzhou") +} + +func onEnterOnlyArgs(call errors.CallContext, _ int, _ string) { + call.SetParam(0, 2024) + call.SetParam(1, "shanghai") +} diff --git a/pkg/rules/test/long/sub/p4.go b/pkg/rules/test/long/sub/p4.go index 1af8bb6a..42a0886c 100644 --- a/pkg/rules/test/long/sub/p4.go +++ b/pkg/rules/test/long/sub/p4.go @@ -28,3 +28,11 @@ type Recv struct{ X int } func (t *Recv) TestGetSetRecv(arg1 int, arg2 float64) (int, float64) { return arg1, arg2 } + +func OnlyRet() (int, string) { + return 1024, "gansu" +} + +func OnlyArgs(arg1 int, arg2 string) { + println(arg1, arg2) +} diff --git a/pkg/rules/test/rule.go b/pkg/rules/test/rule.go index 15ecb59c..e4730d84 100644 --- a/pkg/rules/test/rule.go +++ b/pkg/rules/test/rule.go @@ -187,4 +187,12 @@ func init() { api.NewRule("errors", "TestGetSetRecv", "*Recv", "onEnterTestGetSetRecv", "onExitTestGetSetRecv"). WithRuleName("testrule"). Register() + + api.NewRule("errors", "OnlyRet", "", "", "onExitOnlyRet"). + WithRuleName("testrule"). + Register() + + api.NewRule("errors", "OnlyArgs", "", "onEnterOnlyArgs", ""). + WithRuleName("testrule"). + Register() } diff --git a/test/errors-test/main.go b/test/errors-test/main.go index 25b3b962..9ba23e39 100644 --- a/test/errors-test/main.go +++ b/test/errors-test/main.go @@ -22,4 +22,8 @@ func main() { recv := &errors.Recv{} a, b := recv.TestGetSetRecv(1, 3.14) fmt.Printf("recv%v %v %v\n", recv, a, b) + + errors.OnlyArgs(1, "jiangsu") + c, d := errors.OnlyRet() + fmt.Printf("onlyret%v %v\n", c, d) } diff --git a/test/errors_test.go b/test/errors_test.go index 7d11f645..8e30fcf3 100644 --- a/test/errors_test.go +++ b/test/errors_test.go @@ -11,7 +11,7 @@ func TestRunErrors(t *testing.T) { UseApp(ErrorsAppName) RunInstrument(t, "-debuglog", "-disablerules=fmt") - stdout, _ := RunApp(t, ErrorsAppName) + stdout, stderr := RunApp(t, ErrorsAppName) ExpectContains(t, stdout, "wow") ExpectContains(t, stdout, "old:wow") ExpectContains(t, stdout, "ptr") @@ -21,6 +21,8 @@ func TestRunErrors(t *testing.T) { ExpectContains(t, stdout, "4008208820") ExpectContains(t, stdout, "118888") ExpectContains(t, stdout, "0.001") + ExpectContains(t, stderr, "2024 shanghai") + ExpectContains(t, stdout, "2033 hangzhou") text := ReadInstrumentLog(t, "debug_fn_otel_inst_file_p4.go") re := regexp.MustCompile(".*OtelOnEnterTrampoline_TestSkip.*") diff --git a/tool/instrument/inst_func.go b/tool/instrument/inst_func.go index c38d35a8..4ecf79ad 100644 --- a/tool/instrument/inst_func.go +++ b/tool/instrument/inst_func.go @@ -349,7 +349,7 @@ func (rp *RuleProcessor) applyFuncRules(bundle *resource.RuleBundle) (err error) return fmt.Errorf("failed to rewrite: %w for %v", err, rule) } - log.Printf("Apply func rule %s for %v\n", rule, file) + log.Printf("Apply func rule %s\n", rule) } break } diff --git a/tool/instrument/instrument.go b/tool/instrument/instrument.go index 0fe30fc0..5fd4d738 100644 --- a/tool/instrument/instrument.go +++ b/tool/instrument/instrument.go @@ -136,7 +136,7 @@ func Instrument() error { // Is compile command? if shared.IsCompileCommand(strings.Join(args, " ")) { if shared.Verbose { - log.Printf("Compiling: %v\n", args) + log.Printf("CompileCmd: %v\n", args) } bundles, err := resource.LoadRuleBundles() if err != nil { @@ -151,7 +151,12 @@ func Instrument() error { if err != nil { return fmt.Errorf("failed to apply rules: %w", err) } - log.Printf("Compiled: %v", rp.compileArgs) + if !shared.Verbose { + log.Printf("CompileCmd: %v (%v)\n", + bundle.ImportPath, bundle.PackageName) + } else { + log.Printf("CompileCmd: %v\n", rp.compileArgs) + } // Good, run final compilation after instrumentation return util.RunCmd(rp.compileArgs...) }