Skip to content

Commit dff7877

Browse files
authored
chore(tool): format generated debugging files (#191)
1 parent 02815cf commit dff7877

File tree

8 files changed

+22
-18
lines changed

8 files changed

+22
-18
lines changed

pkg/instrumentation/helloworld/helloworld_hook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func MyHookAfter(ictx inst.HookContext) {
6565

6666
func MyHook1Before(ictx inst.HookContext, recv interface{}) {
6767
println("Before MyStruct.Example()")
68+
fmt.Printf("funcName:%s\n", ictx.GetFuncName())
69+
fmt.Printf("packageName:%s\n", ictx.GetPackageName())
70+
fmt.Printf("paramCount:%d\n", ictx.GetParamCount())
71+
fmt.Printf("returnValCount:%d\n", ictx.GetReturnValCount())
72+
fmt.Printf("isSkipCall:%t\n", ictx.IsSkipCall())
6873
}
6974

7075
func MyHook1After(ictx inst.HookContext) {

test/integration/basic_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func TestBasic(t *testing.T) {
2727
"[MyHook]",
2828
"=setupOpenTelemetry=",
2929
"RawCode",
30+
"funcName:Example",
31+
"packageName:main",
32+
"paramCount:1",
33+
"returnValCount:0",
34+
"isSkipCall:false",
3035
}
3136
for _, e := range expect {
3237
require.Contains(t, output, e)

tool/internal/ast/primitives.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ func BoolFalse() *dst.BasicLit {
127127
}
128128

129129
func InterfaceType() *dst.InterfaceType {
130-
return &dst.InterfaceType{Methods: &dst.FieldList{List: nil}}
130+
return &dst.InterfaceType{
131+
Methods: &dst.FieldList{Opening: true, Closing: true},
132+
}
131133
}
132134

133135
func ArrayType(elem dst.Expr) *dst.ArrayType {

tool/internal/instrument/optimize.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ func newHookContextImpl(tjump *TJump) dst.Expr {
139139
// Build the struct literal: &HookContextImpl{params:..., returnVals:...}
140140
return ast.StructLit(
141141
structName,
142-
ast.KeyValueExpr("params", paramsSlice),
143-
ast.KeyValueExpr("returnVals", returnValsSlice),
142+
ast.KeyValueExpr(trampolineParamsIdentifier, paramsSlice),
143+
ast.KeyValueExpr(trampolineReturnValsIdentifier, returnValsSlice),
144144
)
145145
}
146146

@@ -316,7 +316,7 @@ func flattenTJump(tjump *TJump, removedOnExit bool) error {
316316

317317
func stripTJumpLabel(tjump *TJump) {
318318
ifStmt := tjump.ifStmt
319-
ifStmt.Decs.If = ifStmt.Decs.If[1:]
319+
ifStmt.Decs.If = nil
320320
}
321321

322322
func (ip *InstrumentPhase) optimizeTJumps() error {

tool/internal/instrument/optimize_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,20 @@ func TestStripTJumpLabel(t *testing.T) {
277277
name string
278278
source string
279279
extraDecorations []string
280-
expectedAfter int
281280
}{
282281
{
283282
name: "strips single label",
284283
source: `if condition {
285284
// do something
286285
}`,
287286
extraDecorations: []string{"other-decoration"},
288-
expectedAfter: 1,
289287
},
290288
{
291289
name: "strips label from multiple decorations",
292290
source: `if condition {
293291
// do something
294292
}`,
295293
extraDecorations: []string{"decoration1", "decoration2"},
296-
expectedAfter: 2,
297294
},
298295
}
299296

@@ -305,12 +302,8 @@ func TestStripTJumpLabel(t *testing.T) {
305302

306303
tjump := &TJump{ifStmt: ifStmt}
307304

308-
initialCount := len(ifStmt.Decs.If)
309305
stripTJumpLabel(tjump)
310-
finalCount := len(ifStmt.Decs.If)
311-
312-
assert.Equal(t, tt.expectedAfter, finalCount)
313-
assert.Equal(t, initialCount-1, finalCount, "should remove exactly one decoration")
306+
assert.Empty(t, ifStmt.Decs.If)
314307
})
315308
}
316309
}

tool/internal/instrument/testdata/golden/after-only/after_only.main.go.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ func Func1(p1 string, p2 int) (_unnamedRetVal0 float32, _unnamedRetVal1 error) {
1515
//line <generated>:1
1616
if false {
1717
} else {
18-
defer OtelAfterTrampoline_Func13335793671(&HookContextImpl3335793671{params: []interface {
19-
}{&p1, &p2}, returnVals: []interface {
20-
}{&_unnamedRetVal0, &_unnamedRetVal1}}, &_unnamedRetVal0, &_unnamedRetVal1)
18+
defer OtelAfterTrampoline_Func13335793671(&HookContextImpl3335793671{params: []interface{}{&p1, &p2}, returnVals: []interface{}{&_unnamedRetVal0, &_unnamedRetVal1}}, &_unnamedRetVal0, &_unnamedRetVal1)
2119
}
2220
//line main.go:13:2
2321
println("Hello, World!")

tool/internal/instrument/testdata/golden/method-receiver/method_receiver.main.go.golden

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ func OtelAfterTrampoline_Func12501994857(hookContext HookContext, arg0 *float32,
164164
}
165165

166166
//go:linkname H3Before testdata.H3Before
167-
func H3Before(hookContext HookContext, recv0 interface {
168-
}, param1 string, param2 int)
167+
func H3Before(hookContext HookContext, recv0 interface{}, param1 string, param2 int)
169168

170169
//go:linkname H3After testdata.H3After
171170
func H3After(hookContext HookContext, arg0 float32, arg1 error)

tool/internal/setup/setup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func Setup(ctx context.Context, args []string) error {
8181
if err != nil {
8282
return err
8383
}
84-
sp.Info("Setup completed successfully")
8584
return nil
8685
}
8786

@@ -143,9 +142,12 @@ func GoBuild(ctx context.Context, args []string) error {
143142
if err != nil {
144143
return err
145144
}
145+
logger.InfoContext(ctx, "Setup completed successfully")
146+
146147
err = BuildWithToolexec(ctx, args)
147148
if err != nil {
148149
return err
149150
}
151+
logger.InfoContext(ctx, "Instrumentation completed successfully")
150152
return nil
151153
}

0 commit comments

Comments
 (0)