aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding.go
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2019-09-23 15:34:59 +0200
committerAndrey Konovalov <andreyknvl@gmail.com>2019-09-23 17:13:23 +0200
commit2b854f96b1a7be5c5c563fe798aaa2f6835ad2c6 (patch)
tree8fe736742849104c860be93b989f4b7cddc28bc2 /prog/encoding.go
parent1e9788a0d9bd8fca36978810fd3fc50b6c4f060b (diff)
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.
Diffstat (limited to 'prog/encoding.go')
-rw-r--r--prog/encoding.go30
1 files changed, 20 insertions, 10 deletions
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("=")