-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracemallocs.go
51 lines (46 loc) · 1.07 KB
/
tracemallocs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Distributed under the MIT license. See the LICENSE file.
* Copyright (c) 2014--2016 Thomas Fogal */
package main
import (
"./msg"
"io"
)
var evc = msg.StdChan("evc")
func supervise(argv []string, ie InferiorEvent) {
inferior, err := instrument(argv)
if err != nil {
evc.Error("err starting program: %v\n", err)
return
}
defer inferior.Close()
if err := ie.Setup(inferior); err != nil {
evc.Error("Could not initialize event handler: %v", err)
return
}
defer ie.Close(inferior)
for {
ievent, err := ihandle(inferior)
if err == io.EOF {
break
} else if err != nil {
evc.Error("running %s: %v\n", argv[0], err)
return
}
switch iev := ievent.(type) {
case trap:
if err := ie.Trap(inferior, iev.iptr); err != nil {
evc.Error("error trapping 0x%x: %v\n", iev.iptr, err)
return
}
case segfault:
if err := ie.Segfault(inferior, iev.addr); err != nil {
evc.Error("segfault error: %v\n", err)
return
}
default:
evc.Error("unexpected event: %v\n", iev)
return
}
}
evc.Printf("%s exited normally.\n", argv[0])
}