Skip to content

Commit

Permalink
fix trace replay issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs committed Sep 1, 2017
1 parent aeee0b5 commit 5df5b0f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go/cmd/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func main() {
}
} else if *prettyFlag {
if err := PrintPretty(tf); err != nil {
fmt.Fprintf(os.Stderr, "error printing json: %v\n", err)
fmt.Fprintf(os.Stderr, "error printing pretty: %v\n", err)
os.Exit(1)
}
}
Expand Down
6 changes: 0 additions & 6 deletions go/models/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ type Op interface {
Pack(w io.Writer) (int, error)
Unpack(r io.Reader) (int, error)
}

type NoOp struct {
}

func (n *NoOp) Pack(w io.Writer) (int, error) { return 0, nil }
func (n *NoOp) Unpack(r io.Reader) (int, error) { return 0, nil }
2 changes: 1 addition & 1 deletion go/models/trace/filter_membatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// OpMemBatch is a collection of reads and writes that occured within a basic block
type OpMemBatch struct {
models.NoOp
OpNop
Ops []models.Op
}

Expand Down
7 changes: 5 additions & 2 deletions go/models/trace/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func packOps(w io.Writer, ops []models.Op) (total int, err error) {
func unpackOps(r io.Reader, count int) (ops []models.Op, total int, err error) {
ops = make([]models.Op, count)
for i := 0; i < count; i++ {
op, n, err := Unpack(r)
op, n, err := Unpack(r, true)
if err != nil {
return ops, total + n, errors.Wrap(err, "unpacking op list")
} else {
Expand All @@ -53,7 +53,7 @@ func unpackOps(r io.Reader, count int) (ops []models.Op, total int, err error) {
return ops, total, nil
}

func Unpack(r io.Reader) (models.Op, int, error) {
func Unpack(r io.Reader, nested bool) (models.Op, int, error) {
var tmp [1]byte
if _, err := r.Read(tmp[:]); err != nil {
return nil, 0, err
Expand Down Expand Up @@ -89,6 +89,9 @@ func Unpack(r io.Reader) (models.Op, int, error) {
default:
return nil, 0, errors.Errorf("Unknown op: %d", tmp[0])
}
if nested && (tmp[0] == OP_FRAME || tmp[0] == OP_KEYFRAME) {
return nil, 0, errors.Errorf("fatal: nested frame")
}
n, err := op.Unpack(r)
return op, n + 1, err
}
Expand Down
6 changes: 3 additions & 3 deletions go/models/trace/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestOpFrame(t *testing.T) {
if _, err := testFrame.Pack(&buf); err != nil {
t.Fatal(err)
}
op, _, err := Unpack(&buf)
op, _, err := Unpack(&buf, false)
if err != nil {
t.Fatal(err)
}
Expand All @@ -49,7 +49,7 @@ func TestOpFrame(t *testing.T) {
if _, err := op.Pack(&buf2); err != nil {
t.Fatal(err)
}
_, _, err = Unpack(&buf2)
_, _, err = Unpack(&buf2, false)
if err != nil {
t.Fatal(err)
}
Expand All @@ -71,7 +71,7 @@ func BenchmarkUnpack(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.Seek(0, 0)
if _, _, err := Unpack(r); err != nil {
if _, _, err := Unpack(r, false); err != nil {
b.Fatal(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go/models/trace/tracefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewReader(r io.ReadCloser) (*TraceReader, error) {
}

func (t *TraceReader) Next() (models.Op, error) {
op, _, err := Unpack(t.zr)
op, _, err := Unpack(t.zr, false)
return op, err
}

Expand Down

0 comments on commit 5df5b0f

Please sign in to comment.