From 2b854f96b1a7be5c5c563fe798aaa2f6835ad2c6 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Mon, 23 Sep 2019 15:34:59 +0200 Subject: tools: add syz-expand The syz-expand tools allows to parse a program and print it including all the default values. This is mainly useful for debugging, like doing manual program modifications while trying to come up with a reproducer for some particular kernel behavior. --- prog/encoding.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'prog/encoding.go') diff --git a/prog/encoding.go b/prog/encoding.go index 904a3e11b..1da491186 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -25,11 +25,20 @@ func (p *Prog) String() string { } func (p *Prog) Serialize() []byte { + return p.serialize(false) +} + +func (p *Prog) SerializeVerbose() []byte { + return p.serialize(true) +} + +func (p *Prog) serialize(verbose bool) []byte { p.debugValidate() ctx := &serializer{ - target: p.Target, - buf: new(bytes.Buffer), - vars: make(map[*ResultArg]int), + target: p.Target, + buf: new(bytes.Buffer), + vars: make(map[*ResultArg]int), + verbose: verbose, } for _, c := range p.Calls { ctx.call(c) @@ -38,10 +47,11 @@ func (p *Prog) Serialize() []byte { } type serializer struct { - target *Target - buf *bytes.Buffer - vars map[*ResultArg]int - varSeq int + target *Target + buf *bytes.Buffer + vars map[*ResultArg]int + varSeq int + verbose bool } func (ctx *serializer) printf(text string, args ...interface{}) { @@ -91,7 +101,7 @@ func (a *PointerArg) serialize(ctx *serializer) { } target := ctx.target ctx.printf("&%v", target.serializeAddr(a)) - if a.Res != nil && isDefault(a.Res) && !target.isAnyPtr(a.Type()) { + if a.Res != nil && !ctx.verbose && isDefault(a.Res) && !target.isAnyPtr(a.Type()) { return } ctx.printf("=") @@ -136,7 +146,7 @@ func (a *GroupArg) serialize(ctx *serializer) { } ctx.buf.WriteByte(delims[0]) lastNonDefault := len(a.Inner) - 1 - if a.fixedInnerSize() { + if !ctx.verbose && a.fixedInnerSize() { for ; lastNonDefault >= 0; lastNonDefault-- { if !isDefault(a.Inner[lastNonDefault]) { break @@ -158,7 +168,7 @@ func (a *GroupArg) serialize(ctx *serializer) { func (a *UnionArg) serialize(ctx *serializer) { ctx.printf("@%v", a.Option.Type().FieldName()) - if isDefault(a.Option) { + if !ctx.verbose && isDefault(a.Option) { return } ctx.printf("=") -- cgit mrf-deployment