-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.go
1148 lines (989 loc) · 27.5 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016, Gdlv Authors
package main
import (
"bufio"
"bytes"
"fmt"
"image/color"
"io/ioutil"
"math"
"os"
"runtime"
"runtime/pprof"
"strings"
"sync"
"time"
"github.com/aarzilli/gdlv/internal/assets"
"github.com/aarzilli/gdlv/internal/dlvclient/service/api"
"github.com/aarzilli/gdlv/internal/dlvclient/service/rpc2"
"github.com/aarzilli/nucular"
"github.com/aarzilli/nucular/font"
"github.com/aarzilli/nucular/rect"
"github.com/aarzilli/nucular/richtext"
nstyle "github.com/aarzilli/nucular/style"
"golang.org/x/mobile/event/key"
)
//go:generate go-bindata -o internal/assets/assets.go -pkg assets fontawesome-webfont.ttf droid-sans.bold.ttf codicon.ttf
const profileEnabled = false
var zeroWidth, arrowWidth, starWidth, spaceWidth int
var fontInit sync.Once
var iconFace font.Face
var codiconFace font.Face
var boldFace font.Face
var normalFontData []byte
var boldFontData []byte
var iconFontData []byte
var codiconFontData []byte
var (
linkColor = color.RGBA{0x00, 0x88, 0xdd, 0xff}
linkHoverColor = color.RGBA{0x00, 0xaa, 0xff, 0xff}
)
const (
arrowIconChar = "\uf061"
breakpointIconChar = "\uf28d"
interruptIconChar = "\uEAD1"
continueIconChar = "\uEACF"
cancelIconChar = "\uEAD7"
nextIconChar = "\uEAD6"
stepIconChar = "\uEAD4"
stepoutIconChar = "\uEAD5"
)
func setupStyle() {
switch conf.Theme {
default:
fallthrough
case darkTheme:
wnd.SetStyle(nstyle.FromTheme(nstyle.DarkTheme, conf.Scaling))
case whiteTheme:
wnd.SetStyle(nstyle.FromTheme(nstyle.WhiteTheme, conf.Scaling))
case redTheme:
wnd.SetStyle(nstyle.FromTheme(nstyle.RedTheme, conf.Scaling))
case boringTheme:
style := makeBoringStyle()
style.Scale(conf.Scaling)
wnd.SetStyle(style)
}
fontInit.Do(func() {
iconFontData, _ = assets.Asset("fontawesome-webfont.ttf")
codiconFontData, _ = assets.Asset("codicon.ttf")
normalFontPath := os.Getenv("GDLV_NORMAL_FONT")
boldFontPath := os.Getenv("GDLV_BOLD_FONT")
customFonts := false
if normalFontPath != "" && boldFontPath != "" {
_, normerr := os.Stat(normalFontPath)
_, bolderr := os.Stat(boldFontPath)
if normerr == nil && bolderr == nil {
normalFontData, normerr = ioutil.ReadFile(normalFontPath)
boldFontData, bolderr = ioutil.ReadFile(boldFontPath)
if normerr == nil && bolderr == nil {
customFonts = true
}
}
if normerr != nil {
fmt.Fprintf(os.Stderr, "Error opening GDLV_NORMAL_FONT %q: %v\n", normalFontPath, normerr)
}
if bolderr != nil {
fmt.Fprintf(os.Stderr, "Error opening GDLV_BOLD_FONT %q: %v\n", boldFontPath, bolderr)
}
} else if normalFontPath != "" && boldFontPath == "" {
fmt.Fprintf(os.Stderr, "GDLV_NORMAL_FONT set without GDLV_BOLD_FONT\n")
} else if normalFontPath == "" && boldFontPath != "" {
fmt.Fprintf(os.Stderr, "GDLV_BOLD_FONT set without GDLV_NORMAL_FONT\n")
}
if !customFonts {
boldFontData, _ = assets.Asset("droid-sans.bold.ttf")
}
})
style := wnd.Style()
style.Tab.Indent = style.Tab.Padding.X + style.Tab.Spacing.X + nucular.FontHeight(style.Font) + style.GroupWindow.Spacing.X
style.Selectable.Normal.Data.Color = style.NormalWindow.Background
style.GroupWindow.Padding.Y = 0
style.GroupWindow.FooterPadding.Y = 0
style.MenuWindow.FooterPadding.Y = 0
style.ContextualWindow.FooterPadding.Y = 0
zeroWidth = nucular.FontWidth(style.Font, "0")
spaceWidth = nucular.FontWidth(style.Font, " ")
sz := int(12 * conf.Scaling)
var err error
iconFace, err = font.NewFace(iconFontData, sz)
if err != nil {
fmt.Fprintf(os.Stderr, "could not parse icon font: %v\n", err)
os.Exit(1)
}
codiconFace, err = font.NewFace(codiconFontData, sz)
if err != nil {
fmt.Fprintf(os.Stderr, "could not parse codicon font: %v\n", err)
os.Exit(1)
}
boldFace, err = font.NewFace(boldFontData, sz)
if err != nil {
fmt.Fprintf(os.Stderr, "could not parse bold font: %v\n", err)
os.Exit(1)
}
if normalFontData != nil {
style.Font, err = font.NewFace(normalFontData, sz)
if err != nil {
fmt.Fprintf(os.Stderr, "could not parse normal font: %v\n", err)
os.Exit(1)
}
}
arrowWidth = nucular.FontWidth(iconFace, arrowIconChar)
starWidth = nucular.FontWidth(style.Font, breakpointIconChar)
saveConfiguration()
}
const commandLineHeight = 28
type listline struct {
idx string
lineno int
text string
textWithTabs string
pc bool
bp *api.Breakpoint
bpenabled bool
}
var listingPanel struct {
file string
abbrevFile string
recenterListing bool
recenterDisassembly bool
listing []listline
text []wrappedInstruction
framePC uint64
pinnedLoc *api.Location
stale bool
optimized bool
id int
stepIntoInfo stepIntoInfo
stepIntoFilled bool
disassHoverIdx int
disassHoverClickIdx int
centerOnDisassHover bool
}
var wnd nucular.MasterWindow
var nextInProgress bool
var client *rpc2.RPCClient
var curThread, oldThread int
var curPid int
var curGid, oldGid int64
var curFrameOffset, oldFrameOffset int64
var firstStop bool = true
var ignoreFrameChange bool
var curFrame int
var curDeferredCall int
var curPC uint64
var lastModExe time.Time
var scriptRunning bool
var starlarkMode chan string
var starlarkPrompt string
var commandLineEditor nucular.TextEditor
var delayFrame bool
var frameCount int
func guiUpdate(w *nucular.Window) {
defer richTextCleanup()
df := delayFrame
delayFrame = false
if df {
time.Sleep(50 * time.Millisecond)
}
mw := w.Master()
for _, e := range wnd.Input().Keyboard.Keys {
switch {
case (e.Modifiers&key.ModControl != 0) && e.Code == key.CodeEqualSign:
// mitigation for shiny bug on macOS (see https://github.com/aarzilli/gdlv/issues/39)
fallthrough
case (e.Modifiers&key.ModControl != 0) && e.Rune == '+':
conf.Scaling += 0.1
setupStyle()
case (e.Modifiers&key.ModControl != 0) && e.Code == key.CodeHyphenMinus:
// mitigation for shiny bug on macOS (see https://github.com/aarzilli/gdlv/issues/39)
fallthrough
case (e.Modifiers&key.ModControl != 0) && e.Rune == '-':
conf.Scaling -= 0.1
setupStyle()
case (e.Modifiers == key.ModControl) && (e.Code == key.CodeF):
mw.SetPerf(!mw.GetPerf())
case (e.Modifiers == 0) && (e.Code == key.CodeEscape):
mw.ActivateEditor(findWindow(infoCommand), &commandLineEditor)
mw.Changed()
case (e.Modifiers == key.ModAlt) && (e.Code == key.CodeReturnEnter):
fallthrough
case (e.Modifiers == 0) && (e.Code == key.CodeF5):
if !client.Running() && client != nil {
doCommand("continue")
}
case (e.Modifiers == 0) && (e.Code == key.CodeF10):
fallthrough
case (e.Modifiers == key.ModAlt) && (e.Code == key.CodeRightArrow):
if !client.Running() && client != nil {
doCommand("next")
}
case (e.Modifiers == 0) && (e.Code == key.CodeF11):
fallthrough
case (e.Modifiers == key.ModAlt) && (e.Code == key.CodeDownArrow):
if !client.Running() && client != nil {
doCommand("step")
}
case (e.Modifiers == key.ModShift) && (e.Code == key.CodeF11):
fallthrough
case (e.Modifiers == key.ModAlt) && (e.Code == key.CodeUpArrow):
if !client.Running() && client != nil {
doCommand("stepout")
}
case (e.Modifiers == key.ModShift) && (e.Code == key.CodeF5):
fallthrough
case (e.Modifiers == key.ModControl) && (e.Code == key.CodeDeleteForward):
if client != nil {
doCommand("interrupt")
}
case (e.Modifiers == key.ModShift) && (e.Code == key.CodeReturnEnter):
if findWindow(infoLocals) != nil {
go addExpression("", true)
}
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code1):
openWindow(infoListing)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code2):
openWindow(infoLocals)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code3):
openWindow(infoGlobal)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code4):
openWindow(infoRegisters)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code5):
openWindow(infoBps)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code6):
openWindow(infoStacktrace)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code7):
openWindow(infoDisassembly)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code8):
openWindow(infoGoroutines)
case (e.Modifiers == key.ModAlt) && (e.Code == key.Code9):
openWindow(infoThreads)
}
}
descale := func(x int) int {
return int(float64(x) / conf.Scaling)
}
frameCount++
if frameCount%200 == 0 {
changed := false
wnd.Walk(func(_ *nucular.Window, title string, data interface{}, docked bool, size int, rect rect.Rect) {
if docked {
return
}
title = cleanWindowTitle(title)
rect.X = descale(rect.X)
rect.Y = descale(rect.Y)
rect.H = descale(rect.H)
rect.W = descale(rect.W)
if rect != conf.SavedBounds[title] {
conf.SavedBounds[title] = rect
changed = true
}
})
if changed {
saveConfiguration()
}
}
}
func currentPrompt() string {
if client.Running() {
return "running"
} else if client == nil {
switch {
case BackendServer.connectionFailed:
return "failed"
case !BackendServer.buildok:
return "build failed"
default:
return "connecting"
}
} else {
pmpt := ">"
if starlarkMode != nil {
pmpt = starlarkPrompt
}
pfx := ""
if curPid != 0 {
pfx = fmt.Sprintf("pid %d ", curPid)
}
if curThread < 0 {
return fmt.Sprintf("%sdlv%s", pfx, pmpt)
} else if curGid < 0 {
return fmt.Sprintf("%sthread %d:%d%s", pfx, curThread, curFrame, pmpt)
} else if curDeferredCall > 0 {
return fmt.Sprintf("%sdeferred call %d:%d:%d%s", pfx, curGid, curFrame, curDeferredCall, pmpt)
} else {
return fmt.Sprintf("%sgoroutine %d:%d%s", pfx, curGid, curFrame, pmpt)
}
}
}
func updateCommandPanel(w *nucular.Window) {
style := w.Master().Style()
w.Row(headerRow).Static()
w.LayoutReserveRow(commandLineHeight, 1)
commandToolbar(w)
w.Row(0).Dynamic(1)
if c := scrollbackEditor.Widget(w, scrollbackClear); c != nil {
c.SetStyle(richtext.TextStyle{Cursor: font.TextCursor})
scrollbackClear = false
c.Align(richtext.AlignLeftDumb)
if len(scrollbackPreInitWrite) > 0 {
c.Text(string(scrollbackPreInitWrite))
}
c.End()
scrollbackEditor.Sel.S = int32(len(scrollbackPreInitWrite))
scrollbackEditor.Sel.E = scrollbackEditor.Sel.S
scrollbackEditor.FollowCursor()
scrollbackMu.Lock()
scrollbackInitialized = true
scrollbackMu.Unlock()
}
p := currentPrompt()
p2 := p
if historySearch {
p2 += " (searching)"
}
promptwidth := nucular.FontWidth(style.Font, p2) + style.Text.Padding.X*2
w.Row(commandLineHeight).StaticScaled(promptwidth, 0)
w.Label(p2, "LC")
if client.Running() {
//commandLineEditor.Flags |= nucular.EditReadOnly
if !commandLineEditor.Active {
w.Master().ActivateEditor(w, &commandLineEditor)
}
} else {
commandLineEditor.Flags &= ^nucular.EditReadOnly
}
if commandLineEditor.Active {
showHistory := false
kbd := &w.Input().Keyboard
for _, k := range kbd.Keys {
switch {
case k.Modifiers == 0 && k.Code == key.CodeTab:
historySearch = false
w.Input().Keyboard.Text = ""
completeAny()
case k.Modifiers == 0 && k.Code == key.CodeUpArrow:
historySearch = false
historyShown--
showHistory = true
case k.Modifiers == 0 && k.Code == key.CodeDownArrow:
historySearch = false
historyShown++
showHistory = true
case k.Modifiers == key.ModControl && k.Code == key.CodeR:
historySearch = true
historyShown = -1
historyNeedle = ""
showHistory = true
case k.Modifiers == 0 && k.Code == key.CodeEscape:
historySearch = false
historyShown = -1
showHistory = true
case k.Modifiers == 0 && k.Code == key.CodeDeleteBackspace && historySearch:
historyNeedle = historyNeedle[:len(historyNeedle)]
}
}
if historySearch && kbd.Text != "" && kbd.Text != "\n" {
historyNeedle = historyNeedle + kbd.Text
kbd.Text = ""
searchHistory()
showHistory = true
}
if showHistory {
w.Input().Keyboard.Keys = w.Input().Keyboard.Keys[:0]
if historyShown < 0 || historyShown > len(cmdhistory) {
historyShown = len(cmdhistory)
}
if historyShown != len(cmdhistory) {
commandLineEditor.Buffer = []rune(cmdhistory[historyShown])
commandLineEditor.Cursor = len(commandLineEditor.Buffer)
commandLineEditor.CursorFollow = true
} else {
commandLineEditor.Buffer = commandLineEditor.Buffer[:0]
commandLineEditor.Cursor = 0
commandLineEditor.CursorFollow = true
}
}
}
active := commandLineEditor.Edit(w)
if active&nucular.EditCommitted != 0 {
historySearch = false
var scrollbackOut = editorWriter{false}
cmd := string(commandLineEditor.Buffer)
if scriptRunning {
fmt.Fprintf(&scrollbackOut, "a script is running\n")
} else if starlarkMode != nil {
cmdhistory = append(cmdhistory, cmd)
fmt.Fprintf(&scrollbackOut, "%s %s\n", p, cmd)
starlarkMode <- cmd
} else if canExecuteCmd(cmd) && !client.Running() {
if cmd == "" {
if len(cmdhistory) > 0 {
fmt.Fprintf(&scrollbackOut, "%s %s\n", p, cmdhistory[len(cmdhistory)-1])
cmd = cmdhistory[len(cmdhistory)-1]
} else {
cmd = "help"
}
} else {
cmdhistory = append(cmdhistory, cmd)
fmt.Fprintf(&scrollbackOut, "%s %s\n", p, cmd)
}
historyShown = len(cmdhistory)
go executeCommand(cmd)
} else if client.Running() && client != nil && BackendServer.stdinChan != nil && curThread >= 0 {
select {
case BackendServer.stdinChan <- cmd + "\n":
default:
}
} else {
fmt.Fprintf(&scrollbackOut, "Only quit and restart available when not connected to delve\n")
}
commandLineEditor.Buffer = commandLineEditor.Buffer[:0]
commandLineEditor.Cursor = 0
commandLineEditor.CursorFollow = true
commandLineEditor.Active = true
}
}
func searchHistory() {
if historyShown < 0 || historyShown >= len(cmdhistory) {
historyShown = len(cmdhistory) - 1
}
for historyShown >= 0 {
if strings.Index(cmdhistory[historyShown], historyNeedle) >= 0 {
return
}
historyShown--
}
historyShown = -1
}
func canExecuteCmd(cmd string) bool {
if client != nil {
return true
}
return cmd == "q" || cmd == "quit" || cmd == "r" || cmd == "restart"
}
func digits(n int) int {
if n <= 0 {
return 1
}
return int(math.Floor(math.Log10(float64(n)))) + 1
}
func expandTabsEx(in string, colno int) (string, int) {
hastab := false
for _, c := range in {
if c == '\t' {
hastab = true
break
}
}
if !hastab {
return in, colno
}
var buf bytes.Buffer
count := 0
colidx := -1
for i, c := range in {
switch c {
case '\t':
d := (((count/8)+1)*8 - count)
for i := 0; i < d; i++ {
colno--
buf.WriteRune(' ')
}
count = 0
case '\n':
colno--
buf.WriteRune('\n')
count = 0
default:
colno--
buf.WriteRune(c)
count++
}
if colno <= 0 && colidx < 0 {
colidx = i
}
}
return buf.String(), colidx
}
func expandTabs(in string) string {
r, _ := expandTabsEx(in, 0)
return r
}
type clearKind uint16
const (
clearFrameSwitch clearKind = iota
clearGoroutineSwitch
clearStop
clearBreakpoint
clearNothing
)
type refreshToFrame uint16
const (
refreshToFrameZero refreshToFrame = iota
refreshToSameFrame
refreshToUserFrame
)
func refreshState(toframe refreshToFrame, clearKind clearKind, state *api.DebuggerState) {
defer wnd.Changed()
if clearKind == clearStop {
oldGid = curGid
oldThread = curThread
oldFrameOffset = curFrameOffset
}
var scrollbackOut = editorWriter{false}
failstate := func(pos string, err error) {
fmt.Fprintf(&scrollbackOut, "Error refreshing state %s: %v\n", pos, err)
}
if state == nil {
var err error
state, err = client.GetState()
if err != nil {
wnd.Lock()
curThread = -1
curGid = -1
curFrame = 0
curDeferredCall = 0
if !strings.Contains(err.Error(), " has exited with status ") {
failstate("GetState()", err)
}
listingPanel.id++
if clearKind != clearBreakpoint {
loadListing(listingPanel.pinnedLoc, failstate)
}
wnd.Unlock()
return
}
} else if state != nil && state.Err != nil {
state2, err := client.GetState()
if err == nil && state2.Err == nil {
state = state2
}
}
wnd.Lock()
defer wnd.Unlock()
nextInProgress = state.NextInProgress
delayFrame = true
curPid = state.Pid
if curPid != 0 {
tgts, _ := client.ListTargets()
if len(tgts) <= 1 {
curPid = 0
}
}
if state.CurrentThread != nil {
curThread = state.CurrentThread.ID
} else {
curThread = -1
curFrame = 0
curDeferredCall = 0
}
if state.SelectedGoroutine != nil && state.SelectedGoroutine.ID > 0 {
curGid = state.SelectedGoroutine.ID
} else {
curGid = -1
}
switch clearKind {
case clearNothing:
// nothing to clear
case clearBreakpoint:
breakpointsPanel.asyncLoad.clear()
checkpointsPanel.asyncLoad.clear()
case clearFrameSwitch:
localsPanel.asyncLoad.clear()
listingPanel.pinnedLoc = nil
for i := range stackPanel.isnew {
stackPanel.isnew[i] = false
}
case clearGoroutineSwitch:
stackPanel.asyncLoad.clear()
localsPanel.asyncLoad.clear()
regsPanel.asyncLoad.clear()
listingPanel.pinnedLoc = nil
case clearStop:
localsPanel.asyncLoad.clear()
regsPanel.asyncLoad.clear()
goroutinesPanel.asyncLoad.clear()
stackPanel.asyncLoad.clear()
threadsPanel.asyncLoad.clear()
globalsPanel.asyncLoad.clear()
breakpointsPanel.asyncLoad.clear()
checkpointsPanel.asyncLoad.clear()
listingPanel.pinnedLoc = nil
silenced = false
bpcount := 0
for _, th := range state.Threads {
if th.Breakpoint != nil {
bpcount++
}
}
if bpcount > 1 {
fmt.Fprintf(&scrollbackOut, "Simultaneously stopped on %d goroutines!\n", bpcount)
}
}
loc := listingPanel.pinnedLoc
if loc == nil {
findCurrentLocation:
switch toframe {
case refreshToFrameZero:
curFrame = 0
curDeferredCall = 0
loc = currentLocation(state)
case refreshToSameFrame:
frames, err := client.Stacktrace(curGid, curFrame+1, api.StacktraceReadDefers, nil)
if err != nil {
curFrame = 0
curDeferredCall = 0
failstate("Stacktrace()", err)
return
}
if curFrame >= len(frames) {
curFrame = 0
curDeferredCall = 0
}
if curFrame < len(frames) {
if curDeferredCall-1 >= len(frames[curFrame].Defers) {
curDeferredCall = 0
}
if curDeferredCall <= 0 {
loc = &frames[curFrame].Location
} else if curDeferredCall-1 < len(frames[curFrame].Defers) {
if stackPanel.showDeferPos {
loc = &frames[curFrame].Defers[curDeferredCall-1].DeferLoc
} else {
loc = &frames[curFrame].Defers[curDeferredCall-1].DeferredLoc
}
}
}
case refreshToUserFrame:
const runtimeprefix = "runtime."
curFrame = 0
curDeferredCall = 0
frames, err := client.Stacktrace(curGid, 20, 0, nil)
if err != nil {
failstate("Stacktrace()", err)
return
}
if len(frames) == 0 {
toframe = refreshToFrameZero
goto findCurrentLocation
}
for i := range frames {
if frames[i].Function == nil {
continue
}
name := frames[i].Function.Name()
if !strings.HasPrefix(name, runtimeprefix) {
curFrame = i
curDeferredCall = 0
break
}
if len(name) > len(runtimeprefix) {
ch := name[len(runtimeprefix)]
if ch >= 'A' && ch <= 'Z' {
curFrame = i
curDeferredCall = 0
break
}
}
}
loc = &frames[curFrame].Location
}
}
if loc == nil {
curPC = 0
return
}
curPC = loc.PC
listingPanel.id++
listingPanel.text = nil
disassemblyPanel.asyncLoad.clear()
disassemblyPanel.loc = *loc
if clearKind != clearBreakpoint {
loadListing(loc, failstate)
}
applyBreakpoints(failstate)
if clearKind == clearStop {
frames, _ := client.Stacktrace(curGid, 1, 0, nil)
if len(frames) > 0 {
curFrameOffset = frames[0].FrameOffset
}
}
if clearKind == clearStop && ignoreFrameChange {
ignoreFrameChange = false
oldFrameOffset = curFrameOffset
}
if clearKind == clearStop && firstStop {
firstStop = false
oldGid = curGid
oldThread = curThread
oldFrameOffset = curFrameOffset
}
wnd.Walk(func(_ *nucular.Window, title string, data interface{}, docked bool, splitSize int, rect rect.Rect) {
if asyncLoad, ok := data.(*asyncLoad); ok && asyncLoad != nil {
if title == "Details" && clearKind != clearNothing && clearKind != clearBreakpoint {
asyncLoad.clear()
}
asyncLoad.startLoad()
}
})
}
func loadDisassembly(p *asyncLoad) {
listingPanel.text = nil
listingPanel.recenterDisassembly = true
listingPanel.disassHoverIdx = -1
listingPanel.disassHoverClickIdx = -1
loc := disassemblyPanel.loc
flavour := api.IntelFlavour
if conf.DisassemblyFlavour == 1 {
flavour = api.GNUFlavour
}
if loc.PC != 0 {
text, err := client.DisassemblePC(currentEvalScope(), loc.PC, flavour)
if err != nil {
p.done(err)
return
}
listingPanel.text = wrapInstructions(text, loc.PC)
listingPanel.framePC = loc.PC
} else {
listingPanel.text = nil
listingPanel.framePC = 0
}
p.done(nil)
}
func loadListing(loc *api.Location, failstate func(string, error)) {
listingPanel.listing = listingPanel.listing[:0]
listingPanel.recenterListing = true
listingPanel.stepIntoInfo.Filename = ""
listingPanel.stepIntoInfo.Lineno = -1
listingPanel.stepIntoInfo.Colno = -1
listingPanel.stepIntoInfo.Valid = false
if loc == nil {
listingPanel.file = ""
listingPanel.abbrevFile = ""
return
}
listingPanel.file = loc.File
listingPanel.abbrevFile = abbrevFileName(loc.File)
if loc.File == "<autogenerated>" {
return
}
fh, err := os.Open(conf.substitutePath(loc.File))
if err != nil {
failstate("Open()", err)
return
}
defer fh.Close()
fi, _ := fh.Stat()
listingPanel.stale = fi.ModTime().After(lastModExe)
listingPanel.optimized = false
if loc.Function != nil && loc.Function.Optimized {
listingPanel.optimized = true
}
buf := bufio.NewScanner(fh)
lineno := 0
for buf.Scan() {
lineno++
atpc := lineno == loc.Line && listingPanel.pinnedLoc == nil
linetext := expandTabs(buf.Text())
listingPanel.listing = append(listingPanel.listing, listline{"", lineno, linetext, buf.Text(), atpc, nil, false})
}
const maxFontCacheSize = 500000
sz := 4*len(listingPanel.listing) + len(listingPanel.listing)/2
if sz > maxFontCacheSize {
sz = maxFontCacheSize
}
nucular.ChangeFontWidthCache(sz)
if err := buf.Err(); err != nil {
failstate("(reading file)", err)
return
}
d := digits(len(listingPanel.listing))
if d < 3 {
d = 3
}
for i := range listingPanel.listing {
listingPanel.listing[i].idx = fmt.Sprintf("%*d", d, i+1)
}
}
func applyBreakpoints(failstate func(string, error)) {
breakpoints, err := client.ListBreakpoints(false)
if err != nil {
failstate("ListBreakpoints()", err)
return
}
bpmap := map[int]*api.Breakpoint{}
for _, bp := range breakpoints {
if bp.File == listingPanel.file {
bpmap[bp.Line] = bp
}
}
for i := range listingPanel.listing {
b := bpmap[listingPanel.listing[i].lineno]
listingPanel.listing[i].bp = b
listingPanel.listing[i].bpenabled = false
if b != nil {
listingPanel.listing[i].bpenabled = !b.Disabled
}
}
}
func currentLocation(state *api.DebuggerState) *api.Location {
if state.SelectedGoroutine != nil {
if state.CurrentThread != nil && state.SelectedGoroutine.ThreadID == state.CurrentThread.ID {
return &api.Location{File: state.CurrentThread.File, Line: state.CurrentThread.Line, PC: state.CurrentThread.PC, Function: state.CurrentThread.Function}
} else {
return &state.SelectedGoroutine.CurrentLoc
}
} else if state.CurrentThread != nil {
return &api.Location{File: state.CurrentThread.File, Line: state.CurrentThread.Line, PC: state.CurrentThread.PC, Function: state.CurrentThread.Function}
}
return nil
}
func currentEvalScope() api.EvalScope {
return api.EvalScope{curGid, curFrame, curDeferredCall}
}
func usage(err string) {
if err != "" {
if err[len(err)-1] != '\n' {
err += "\n"
}
fmt.Fprintf(os.Stderr, err)
}
fmt.Fprintf(os.Stderr, `Usage:
gdlv [options] connect <address>
gdlv [options] debug <program's arguments...>
gdlv [options] run <program file> <program's arguments...>
gdlv [options] exec <executable> <program's arguments...>
gdlv [options] test <testflags...>
gdlv [options] attach <pid> [path to executable]
gdlv [options] core <executable> <core file>
gdlv [options] replay <trace directory>
All commands except "core" and "replay" can be prefixed with the name of a backend, for example:
gdlv rr:run <program file> <program's arguments...>
Executes "gdlv run" using mozilla rr has a backend.
Options must appear before the command and include:
-d <dir> builds inside the specified directory instead of the current directory (for debug and test)
-tags <taglist> list of tags to pass to 'go build'
-r [stdin|stdout|stderr:]path redirects a standard file descriptor to a file, if none is specified stdin is implied
`)
os.Exit(1)