-
Notifications
You must be signed in to change notification settings - Fork 5
/
debug_screen.go
164 lines (141 loc) · 4.35 KB
/
debug_screen.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"errors"
"time"
. "github.com/emad-elsaid/debugger/ui"
"github.com/fsnotify/fsnotify"
)
const STACK_LIMIT = 100000
var (
ErrCantInspectTargetProcess = errors.New("Can't inspect target process")
ErrProcessExited = errors.New("Process exited")
ErrNoSelectedGoRoutine = errors.New("Can't find any go routines")
ErrCantGetScope = errors.New("Can't get current scope")
)
type DebugScreen struct {
Watch *fsnotify.Watcher
Analytics Analytics
Debugger *Debugger
BottomTabs Tabs
Toolbar Toolbar
SideBar SideBar
FunctionsPanel FunctionsPanel
PackagesPanel PackagesPanel
SourcesPanel SourcesPanel
StackPanel StackPanel
TypesPanel TypesPanel
ConsolePanel ConsolePanel
BreakpointsPanel BreakpointsPanel
DisassemblyPanel DisassemblyPanel
SourcePanel SourcePanel
OpenFilesPanel OpenFilesPanel
MemoryPanel MemoryPanel
}
func (d *DebugScreen) Layout(c C) D {
debugger := d.Debugger
if debugger.File == "" {
debugger.JumpToFunction("main.main")
}
return Rows(
Rigid(d.Toolbar.Layout(debugger)),
Rigid(HR(1)),
Flexed(2,
Columns(
Flexed(4, d.SourcePanel.Layout(debugger)),
Flexed(1, d.SideBar.Layout(debugger)),
),
),
Flexed(1,
d.BottomTabs.Layout(
&TabChild{Name: "Console", Panel: func(c C) D { return d.ConsolePanel.Layout(debugger)(c) }},
&TabChild{Name: "Stack Trace", Panel: func(c C) D { return d.StackPanel.Layout(debugger)(c) }},
&TabChild{Name: "Types", Panel: func(c C) D { return d.TypesPanel.Layout(debugger)(c) }},
&TabChild{Name: "Functions", Panel: func(c C) D { return d.FunctionsPanel.Layout(debugger)(c) }},
&TabChild{Name: "Packages", Panel: func(c C) D { return d.PackagesPanel.Layout(debugger)(c) }},
&TabChild{Name: "Sources", Panel: func(c C) D { return d.SourcesPanel.Layout(debugger)(c) }},
&TabChild{Name: "Disassembly", Panel: func(c C) D { return d.DisassemblyPanel.Layout(debugger)(c) }},
&TabChild{Name: "Breakpoints", Panel: func(c C) D { return d.BreakpointsPanel.Layout(debugger)(c) }},
&TabChild{Name: "Open Files", Panel: func(c C) D { return d.OpenFilesPanel.Layout(debugger, &d.Analytics)(c) }},
&TabChild{Name: "Memory", Panel: func(c C) D { return d.MemoryPanel.Layout(&d.Analytics)(c) }},
),
),
)(c)
}
func NewDebugScreen(debugger *Debugger) (*DebugScreen, error) {
w := &DebugScreen{
Debugger: debugger,
Analytics: NewAnalytics(),
BottomTabs: Tabs{},
Toolbar: Toolbar{},
SideBar: NewSideBar(),
FunctionsPanel: NewFunctionsPanel(),
PackagesPanel: NewPackagesPanel(),
SourcesPanel: NewSourcesPanel(),
StackPanel: NewStackPanel(),
TypesPanel: NewTypesPanel(),
ConsolePanel: NewConsolePanel(),
BreakpointsPanel: NewBreakpointsPanel(),
DisassemblyPanel: NewDisassemblyPanel(),
SourcePanel: NewSourcePanel(),
OpenFilesPanel: NewOpenFilesPanel(),
MemoryPanel: NewMemoryPanel(),
}
go w.Clock()
go w.StartWatch()
return w, nil
}
func (d *DebugScreen) Log(kind LogKind, log string, params ...interface{}) {
d.ConsolePanel.Log(kind, log, params...)
}
func (d *DebugScreen) StopWatch() {
if d.Watch != nil {
d.Watch.Close()
d.Watch = nil
}
}
func (d *DebugScreen) StartWatch() {
debugger := d.Debugger
watcher, err := fsnotify.NewWatcher()
if err != nil {
d.Log(LogError, "Can't create watch. Error: %s", err)
return
}
defer watcher.Close()
d.Watch = watcher
done := make(chan bool)
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
isWrite := event.Op == fsnotify.Write
isRename := event.Op == fsnotify.Rename
isRemove := event.Op == fsnotify.Remove
supportedOp := isWrite || isRename || isRemove
if supportedOp && event.Name != d.Debugger.BinName {
d.Log(LogInfo, "%s file: %s", event.Op, event.Name)
debugger.Restart()
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
d.Log(LogError, "Watch error: %s", err)
}
}
}()
if err := WatchAddRecursive(watcher, debugger.Path); err != nil {
d.Log(LogError, "Can't watch: %s Error: %s", debugger.Path, err)
}
<-done
}
func (d *DebugScreen) Clock() {
for {
if d.Debugger.IsRunning() {
d.Analytics.Collect(d.Debugger.Target().Pid())
}
time.Sleep(time.Millisecond * 10)
}
}