aboutsummaryrefslogtreecommitdiffstats
path: root/prog/parse.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-12-23 19:18:13 +0100
committerDmitry Vyukov <dvyukov@google.com>2015-12-23 19:18:13 +0100
commit1c801e8512cc5a40ec13ea8b80c87836f5222781 (patch)
tree1d0b8007d2142186a4774c9a395aeb707274aebd /prog/parse.go
parent2eb388c0f81bfc3acf0c147654905c6d5c03df0d (diff)
prog: factor out execution log parsing functionality
It will be needed to reproduction tool.
Diffstat (limited to 'prog/parse.go')
-rw-r--r--prog/parse.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/prog/parse.go b/prog/parse.go
new file mode 100644
index 000000000..e4a4e15ad
--- /dev/null
+++ b/prog/parse.go
@@ -0,0 +1,68 @@
+// Copyright 2015 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package prog
+
+import (
+ "bytes"
+ "strconv"
+)
+
+// LogEntry describes one program in execution log.
+type LogEntry struct {
+ P *Prog
+ Proc int // index of parallel proc
+ Start int // start offset in log
+ End int // end offset in log
+}
+
+func ParseLog(data []byte) []*LogEntry {
+ var entries []*LogEntry
+ ent := &LogEntry{}
+ var cur []byte
+ for pos := 0; pos < len(data); {
+ nl := bytes.IndexByte(data[pos:], '\n')
+ if nl == -1 {
+ nl = len(data)
+ } else {
+ nl += pos
+ }
+ line := data[pos : nl+1]
+ pos0 := pos
+ pos = nl + 1
+ const delim = "executing program "
+ if delimPos := bytes.Index(line, []byte(delim)); delimPos != -1 {
+ if ent.P != nil && len(ent.P.Calls) != 0 {
+ ent.End = pos0
+ entries = append(entries, ent)
+ }
+ procStart := delimPos + len(delim)
+ procEnd := procStart
+ for procEnd != len(line) && line[procEnd] >= '0' && line[procEnd] <= '9' {
+ procEnd++
+ }
+ proc, _ := strconv.Atoi(string(line[procStart:procEnd]))
+ ent = &LogEntry{
+ Proc: proc,
+ Start: pos0,
+ }
+ cur = nil
+ continue
+ }
+ if ent == nil {
+ continue
+ }
+ tmp := append(cur, line...)
+ p, err := Deserialize(tmp)
+ if err != nil {
+ continue
+ }
+ cur = tmp
+ ent.P = p
+ }
+ if ent.P != nil && len(ent.P.Calls) != 0 {
+ ent.End = len(data)
+ entries = append(entries, ent)
+ }
+ return entries
+}