-
Notifications
You must be signed in to change notification settings - Fork 3
/
gklee-mode.el
2665 lines (2412 loc) · 86.3 KB
/
gklee-mode.el
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
(require 'cl)
;(defvar gklee-home-path "/home/sawaya/gklee/")
(defvar gklee-home-path nil)
(defvar gklee-compile-bin "bin/klee-l++")
(defvar gklee-compile-buffer-name "*gklee-compile-debug*")
(defvar gklee-compile-args '("-g"))
(defvar gklee-opt-level nil)
(defcustom gklee-user-compile-args '() "Command line arguments to be passed to klee-l++ -- should be entered in list form, i.e. '(\"arg1\" \"arg2\"" :type '(repeat string))
(defvar gklee-comp-out-path nil)
(defvar gklee-default-path "./")
(defvar gklee-run-buffer-name "*gklee-run*")
(defvar gklee-run-debug-buffer-name "*gklee-run-debug*")
(defvar gklee-run-user-args '())
(defvar gklee-user-program-args nil)
(defvar gklee-info-notice "GKLEE, copyright (c) 2011, Gauss Group, University of Utah\n")
(defvar gklee-trace-buffer nil)
(defvar gklee-active-filter-buffer "*gklee-active-filters*")
(defvar gklee-available-filter-buffer "*gklee-available-filters*")
(defvar gklee-source-path nil)
(defvar gklee-filter-obarray)
(defvar gklee-current-trace-line 1)
(defconst gklee-filter-obarray-size 8191 "This is the size to initialize the
gklee-filter-obarray object to -- it must be a vector, and, according to elisp manual (23.3) performs best with a size prime or power of 2 - 1. Was chosen for max blocksize.x + max gridsize.x (of dev cap 2.0 CUDA)")
(defvar gklee-warp-count 0)
;;(defvar gklee-trace-first-err-line nil)
;;(defvar gklee-trace-error-lines 0)
;; This is being replaced by gklee-error-alist
;; (defvar gklee-error-htable (make-hash-table :test 'equal)
;; "This is where errors are stored for lookup in order to match to the other threads
;; involved in the error -- in form:
;; [key] = location [value] = (([errorType] [location] [optional location])([errorType] [location] ...))location = trace#:file:lineno:block#:thread")
(defvar gklee-error-alist nil)
(defvar gklee-trace-error-list nil
"This is a circular list, such that the cdr of the last element points to the first element --
it is a list of (point)s in the trace buffer that are potential error locations. They
are only potential because we don't maintain enough state to be certain that the execution pass
at the indicated location is the one that caused the error -- we only maintain blk:thd:file:line")
(defconst gklee-threads-per-warp 32)
(defvar gklee-block-syms nil)
(defvar gklee-thread-syms nil)
(defvar gklee-file-syms nil)
(defvar gklee-loc-syms nil)
(defvar gklee-warp-syms nil)
(setq gklee-options-alist
'(("--ignore-concur-bug" . 0)
("--check-BC" . 1)
("--check-MC" . 1)
("--check-WD" . 1)
;("--check-Race" . 1)
("--check-volatile" . 1)
("--check-barrier-redundant" . 0)
("--device-capability" . 2)
("--reduce-tests" . 0)
("--bc-cov" . 0)
("--Path-Reduce" . "")
("--verbose" . 0)
("--check-level" . 1)
("--pure-canonical-schedule" . 0)
)
)
;;GLOBAL KEYMAPS
(global-set-key "\M-gtcb" 'gklee-toggle-concurrency-bug)
(global-set-key "\M-gtbc" 'gklee-toggle-bank-conflicts)
(global-set-key "\M-gtmc" 'gklee-toggle-memory-coalesce)
(global-set-key "\M-gtwd" 'gklee-toggle-warp-divergence)
;(global-set-key "\M-gtrc" 'gklee-toggle-race-condition)
(global-set-key "\M-gor" 'gklee-open-remote-package)
(global-set-key "\M-gtcv" 'gklee-toggle-check-volatle)
(global-set-key "\M-gtrb" 'gklee-toggle-check-barrier)
(global-set-key "\M-gsdc" 'gklee-set-device-capability)
(global-set-key "\M-gtrt" 'gklee-toggle-reduce-tests)
(global-set-key "\M-gtgc" 'gklee-toggle-bytecode-coverage)
(global-set-key "\M-gspr" 'gklee-set-path-reduction)
(global-set-key "\M-gtv" 'gklee-toggle-verbose)
(global-set-key "\M-gscl" 'gklee-set-check-level)
(global-set-key "\M-gr" 'gklee-run)
(global-set-key "\M-gupa" 'gklee-modify-user-prog-args)
(global-set-key "\M-guca" 'gklee-modify-user-compile-args)
(global-set-key "\M-gaga" 'gklee-modify-addn-gklee-args)
(global-set-key "\M-gk" 'gklee-kill)
(defvar gklee-remote-home nil)
(defun gklee-translate-path (path)
(if gklee-remote-home
(progn
(if (string-match
"/home/tomcat/gklee_remote/[[:alnum:]_.-]*/\\([[:alnum:].-/_]+\\)"
path)
(concat gklee-remote-home (match-string 1 path))
(if (string-match "/home/tomcat/gklee/\\([[:alnum:].-/_]+\\)" path)
(concat gklee-remote-home (match-string 1 path))
nil
;;(error "Unable to translate %s to local path" path)
)
)
)
path)
)
(defun gklee-open-remote-package()
(interactive)
(let((package (read-file-name "Enter location of output.tgz:\n"))
(curr-dir (make-temp-file "gklee" t))
(newname (make-temp-file "gklee")))
(if (not (string-match "23." (emacs-version)))
(message "You must have Emacs version 23 or later to use source code region filtering")
)
(setq gklee-remote-home (file-name-as-directory curr-dir))
(copy-file package newname t)
;;trying to let $PATH locate bash and tar . . . (removed abs paths)
(call-process "bash" nil gklee-run-debug-buffer-name
nil "-c" (concat "tar -C " curr-dir " -zxf "
newname))
(call-process "bash" nil gklee-run-debug-buffer-name
nil "-c" (concat "tar -C " curr-dir " -zxf "
(file-name-as-directory curr-dir) "inc_source.tgz"))
(setq gklee-source-file
(gklee-translate-path (with-temp-buffer
(insert-file-contents (concat (file-name-as-directory curr-dir) "lastran"))
(buffer-string))))
(set-buffer (find-file gklee-source-file))
(setq gklee-source-path (file-name-directory gklee-source-file))
(setq gklee-source-buffer (current-buffer))
(gklee-create-windows gklee-source-buffer gklee-run-buffer-name
gklee-run-debug-buffer-name gklee-compile-buffer-name)
(with-current-buffer gklee-run-buffer-name
(setq gklee-source-mark (point-marker)) ;;sets the buffer property of gklee-source-mark? may not be necessary
(gklee-reset-run-state (current-buffer))
(erase-buffer)
(buffer-disable-undo)
;(setq buffer-read-only t)
(setq output (with-temp-buffer
(insert-file-contents (concat gklee-source-path "gklee_out"))
(buffer-string)))
(with-current-buffer gklee-compile-buffer-name
(let ((split-pt (string-match "****RUNTIME****" output)))
(insert (substring output 0 split-pt))
(setq output (concat (substring output split-pt) "\n"))))
(gklee-process-output (current-buffer) output)
(gklee-full-refresh)
)
))
(defun gklee-circularize-list (lst)
"this function must be called with a proper list (listp lst)"
(let ((elm lst))
(while (cdr elm)
(setq elm (cdr elm)))
(if lst
(setcdr elm lst)
)
))
(defun gklee-modify-addn-gklee-args()
"User may enter additional arguments for GKLEE program"
(interactive)
(gklee-user-mod-list gklee-run-user-args "Enter args to pass to GKLEE: ")
)
(defun gklee-modify-user-compile-args()
"User may set options to be passed to LLVM compiler"
(interactive)
(gklee-user-mod-list gklee-user-compile-args "Enter args for klee-l++: ")
)
(defun gklee-modify-user-prog-args ()
"This allows user to enter command line args
for the program under test by GKLEE"
(interactive)
(gklee-user-mod-list gklee-user-program-args "Enter user program args: ")
)
(defun gklee-user-mod-list (lst prompt)
"This allows users to modify a given list (such as command
line arguments"
(interactive)
(setq lst (split-string
(read-string prompt
(mapconcat 'identity
lst " "))
" "))
)
(defun gklee-toggle-run-option(option)
(let ((old-value (cdr (assoc option gklee-options-alist))))
(if (equal old-value 0)
(progn
(message (concat "setting " option " to 1"))
(setcdr (assoc option gklee-options-alist) 1)
)
(message (concat "setting " option " to 0"))
(setcdr (assoc option gklee-options-alist) 0)
)
))
(defun gklee-toggle-concurrency-bug()
(interactive)
(gklee-toggle-run-option "--ignore-concur-bug"))
(defun gklee-toggle-bank-conflicts()
(interactive)
(gklee-toggle-run-option "--check-BC"))
(defun gklee-toggle-pure-connonical-schedule()
(interactive)
(gklee-toggle-run-option "--pure-canonical-schedule"))
(defun gklee-toggle-memory-coalesce()
(interactive)
(gklee-toggle-run-option "--check-MC"))
(defun gklee-toggle-warp-divergence()
(interactive)
(gklee-toggle-run-option "--check-WD"))
;; (defun gklee-toggle-race-condition()
;; (interactive)
;; (gklee-toggle-run-option "--check-Race"))
(defun gklee-toggle-check-volatile()
(interactive)
(gklee-toggle-run-option "--check-volatile"))
(defun gklee-toggle-reduce-tests()
(interactive)
(gklee-toggle-run-option "--reduce-tests"))
(defun gklee-toggle-bytecode-coverage()
(interactive)
(gklee-toggle-run-option "--bc-cov"))
(defun gklee-toggle-verbose()
(interactive)
(gklee-toggle-run-option "--verbose"))
(defun gklee-toggle-check-barrier()
(interactive)
(gklee-toggle-run-option "--check-barrier-redundant"))
(defun gklee-set-device-capability(n)
(interactive "nDevice Capability (0)1.0-1.1 (1)1.2-1.3 (2)2: ")
(if (and (< n 3)(> n -1))
(setcdr (assoc "--device-capability" gklee-options-alist) n)
(message "set device capability to default of 2")
(setcdr (assoc "--device-capability" gklee-options-alist) 2)
))
(defun gklee-set-path-reduction(BorT)
(interactive "sset path reduction to b(line/branch) or t(line or branch): ")
(if (or (equal "b" BorT)(equal "t" BorT)(equal "" BorT))
(setcdr (assoc "--Path-Reduce" gklee-options-alist) BorT)
(message "set path reduction to default: ''")
(setcdr (assoc "--Path-Reduce" gklee-options-alist) "")
))
(defun gklee-set-check-level(n)
(interactive "nset race check level (0)none (1)shared mem (2)full: ")
(if (and (> n -1)(< n 3))
(setcdr (assoc "--check-level" gklee-options-alist) n)
(message "setting race check level to default of 1")
(setcdr (assoc "--check-level" gklee-options-alist) 1)
))
(make-local-variable 'gklee-compile-process)
(make-local-variable 'gklee-run-process)
(make-local-variable 'gklee-run-buffer)
(make-local-variable 'gklee-unparsed)
(put 'gklee-line-cat 'mouse-face 'highlight)
(put 'gklee-filter-cat 'mouse-face 'highlight)
(defvar gklee-unparsed "")
(defvar gklee-record nil)
(defvar gklee-race-info-list nil)
(defvar gklee-deadlock-info-list nil)
(defvar gklee-assertion-info-list nil)
(defvar gklee-config-info-list nil)
(defvar gklee-bankcon-info-list nil)
(defvar gklee-memcol-info-list nil)
(defvar gklee-warpdiv-info-list nil)
(defvar gklee-summary-info-list nil)
(defvar gklee-process-record-count 0)
(defvar gklee-trace-source-buffers nil)
(defvar gklee-trace-instr-array nil)
(defvar gklee-asm-visible t)
(setq gklee-filter-keymap
(let ((map (make-sparse-keymap)))
(define-key map [mouse-1] 'gklee-filter-event)
(define-key map "\^M" 'gklee-filter-event-key)
map))
(setq gklee-trace-keymap
(let ((map (make-sparse-keymap)))
(define-key map "\d" 'gklee-exit-trace)
(define-key map [mouse-1] 'gklee-goto-line-event)
(define-key map "\^M" 'gklee-goto-line-key)
;; (define-key map "n" 'gklee-next-trace-inst)
;; (define-key map "p" 'gklee-prev-trace-inst)
(define-key map "\M-gst" 'gklee-show-thread)
(define-key map "\M-gsw" 'gklee-show-warp)
(define-key map "\M-gsf" 'gklee-show-file)
(define-key map "\M-gsb" 'gklee-show-block)
(define-key map "\M-gat" 'gklee-add-thread-show) ;add filter
(define-key map "\M-gaw" 'gklee-add-warp-show)
(define-key map "\M-gaf" 'gklee-add-file-show)
(define-key map "\M-gab" 'gklee-add-block-show)
(define-key map "\M-grt" 'gklee-remove-thread) ;remove filter
(define-key map "\M-grw" 'gklee-remove-warp)
(define-key map "\M-grf" 'gklee-remove-file)
(define-key map "\M-grb" 'gklee-remove-block)
(define-key map "\M-guf" 'gklee-unfilter) ;unfilter
(define-key map "\M-gta" 'gklee-toggle-asm-visible)
;Change maybe?
(define-key map "\M-gss" 'gklee-start-step)
(define-key map "\M-gne" 'gklee-next-error)
map))
(defun gklee-next-error ()
"This function will advance the gklee-trace-error-list
-- a circular list -- and set the trace buffer focus
to the next error"
(interactive)
(progn
(setq gklee-trace-error-list (cdr gklee-trace-error-list))
(gklee-set-focus-to-error)
))
;;filter handling
(defun gklee-toggle-asm-visible()
(interactive)
(with-current-buffer gklee-trace-buffer
(setq invSym (gklee-intern "ASM" gklee-filter-obarray))
(if gklee-asm-visible
(progn
(setq gklee-asm-visible nil)
(gklee-add-to-invisibility-spec invSym)
)
(setq gklee-asm-visible t)
(remove-from-invisibility-spec invSym)
)
;; (setq redisplay-dont-pause t)
;; (redisplay t)
(redraw-display)
)
)
(defun gklee-remove-item(id prefix)
"This function will add id-prefix to the trace
filter list"
(with-current-buffer gklee-trace-buffer
(let ((symbol (gklee-intern (concat prefix (if (stringp id)
id
(number-to-string id)))
gklee-filter-obarray)))
(gklee-add-to-invisibility-spec symbol))))
(defun gklee-remove-thread(id)
"This function will add thread id to the trace buffer
filter list -- thereby hiding it"
(interactive "nThread: ")
(gklee-remove-item id "T"))
(defun gklee-remove-block(id)
"This function will add block id to the trace buffer
filter list -- thereby hiding it"
(interactive "nBlock: ")
(gklee-remove-item id "B"))
(defun gklee-remove-file(file)
"This function will add file id to the trace buffer
filter list"
(interactive "fFile: ")
(gklee-remove-item (expand-file-name file) "F"))
;; (defun gklee-show-locations (locations)
;; "This function will hide all but the locations
;; passed in (in form of '(file:line file1:line1 . . .))"
;; (with-current-buffer gklee-trace-buffer
;; (gklee-reset-base-invisibility-spec)
;; (mapatoms
;; (lambda (atm)
;; (let ((symName (symbol-name atm)))
;; (catch 'equ
;; (mapc (lambda (loc)
;; (if (equal symName loc)
;; (throw 'equ)
;; )
;; )
;; )
;; (gklee-add-to-invisibility-spec atm))))
;; gklee-filter-obarray)
;; ))
(defun gklee-remove-warp(id)
"This function will add warp id to the trace buffer
filter list"
(interactive "nWarp: ")
(let* ((firstT (gklee-get-first-t-in-warp warp))
(lastT (gklee-get-last-t-in-warp warp))
(iter firstT))
(while (<= iter lastT)
(gklee-remove-item iter "T")
(setq iter (+ iter 1)))))
(defun gklee-reset-base-invisibility-spec ()
(progn
(setq buffer-invisibility-spec nil)
(if (not gklee-asm-visible)
(gklee-add-to-invisibility-spec (gklee-intern "ASM" gklee-filter-obarray)))))
;; (defun gklee-show-errors(ids)
;; "This function will clear filter list and
;; add all but id"
;; (gklee-show-items ids "C")
;; )
;; (with-current-buffer gklee-trace-buffer
;; (gklee-reset-base-invisibility-spec)
;; ; (setq buffer-invisibility-spec nil)
;; (mapatoms
;; (lambda (atm)
;; (let ((symName (symbol-name atm))
;; ;; (convID (if (stringp id)
;; ;; id
;; ;; (number-to-string id)
;; )
;; (if (and
;; ;; (not (eq 0 atm))
;; ;; (equal (substring symName 0 (length prefix))
;; ;; prefix)
;; (not (equal symName id)))
;; (gklee-add-to-invisibility-spec atm))))
;; gklee-filter-obarray)
;; ))
(defun gklee-show-items(ids prefix)
"This will clear the trace filter and add all items
with same prefix to the filter list except those in ids"
(with-current-buffer gklee-trace-buffer
(gklee-reset-base-invisibility-spec)
; (setq buffer-invisibility-spec nil)
(mapatoms
(lambda (atm)
(let ((symName (symbol-name atm))
)
(catch 'equ
(mapc (lambda (loc)
(if (and
(not (eq 0 atm))
(equal (substring symName 0 (length prefix))
prefix)
(equal symName (concat prefix loc)))
(throw 'equ nil)
)
) ids
)
(if (equal (substring symName 0 (length prefix))
prefix)
(gklee-add-to-invisibility-spec atm)))))
gklee-filter-obarray)
))
(defun gklee-show-item(id prefix)
"This function will clear the trace filter list and filter
out all items of the same type as prefix except id"
(with-current-buffer gklee-trace-buffer
(gklee-reset-base-invisibility-spec)
; (setq buffer-invisibility-spec nil)
(mapatoms
(lambda (atm)
(let ((symName (symbol-name atm))
(convID (if (stringp id)
id
(number-to-string id)
)))
(if (and
(not (eq 0 atm))
(equal (substring symName 0 (length prefix))
prefix)
(not (equal symName (concat prefix convID))))
(gklee-add-to-invisibility-spec atm))))
gklee-filter-obarray)
))
(defun gklee-add-show-item(id prefix)
"This function will remove prefix+id from the
trace filter list"
(with-current-buffer gklee-trace-buffer
(let* ((convID (if (stringp id)
id
(number-to-string id)))
(symbol (gklee-intern (concat prefix convID) gklee-filter-obarray)))
(remove-from-invisibility-spec symbol))))
(defun gklee-add-block-show(blk)
"This interactive will remove a block id from trace filter list"
(interactive "nBlock: ")
(gklee-add-show-item blk "B"))
(defun gklee-add-thread-show(thd)
"This interactive will remove a thread id from trace filter list"
(interactive "nThread: ")
(gklee-add-show-item thd "T"))
(defun gklee-add-file-show(file)
"This function will remove trace lines in file 'file'"
(interactive "fFile: ")
(gklee-add-show-item (expand-file-name file) "F"))
(defun gklee-show-thread(thd)
"This interactive will filter all threads from trace except
'thd'"
(interactive "nThread: ")
(gklee-show-item thd "T"))
(defun gklee-show-block(blk)
"This interactive will filter all blocks from trace except
'blk'"
(interactive "nBlock: ")
(gklee-show-item blk "B"))
(defun gklee-show-file(file)
"This function will filter all trace lines of files
different than 'file'"
(interactive "fFile: ")
(gklee-show-item (expand-file-name file) "F"))
(defun gklee-show-warp(warp)
"This interactive will filter all warps from trace except
'warp'"
(interactive "nWarp: ")
(let* ((firstT (gklee-get-first-t-in-warp warp))
(lastT (gklee-get-last-t-in-warp warp))
(iter (+ firstT 1)))
(gklee-show-item firstT "T")
(while (<= iter lastT)
(gklee-add-show-item iter "T")
(setq iter (+ iter 1)))))
(defun gklee-get-first-t-in-warp(warp)
(* warp gklee-threads-per-warp)
)
(defun gklee-get-last-t-in-warp(warp)
(+ (* warp gklee-threads-per-warp) (- gklee-threads-per-warp 1))
)
;; (defun gklee-set-filter(blk thd)
;; (with-current-buffer gklee-trace-buffer
;; (setq buffer-invisibility-spec (list
;; (gklee-intern
;; (concat "B"
;; (number-to-string blk)
;; )
;; )
;; (gklee-intern
;; (concat "T"
;; (number-to-string thd)
;; )
;; )
;; )))
;; )
(defun gklee-unfilter()
"This interactive will clear the trace filter list"
(interactive)
(with-current-buffer gklee-trace-buffer
(gklee-reset-base-invisibility-spec)
; (setq buffer-invisibility-spec nil)
))
;; (defun gklee-filter(blk thd)
;; (interactive "nBlock:\nnThread:\n")
;; (gklee-set-filter blk thd)
;; )
(defun gklee-get-current-trace-num()
"Extracts the number for the current trace from the name of the trace buffer.
This is used to lookup errors when matching them to trace lines. This
should not be called if a trace hasn't been selected in *gklee-run*."
(gklee-get-lineno gklee-trace-buffer)
)
(defun gklee-trace-has-errors(tname)
"Decision proceedure that checks gklee-error-htable for errors
for the given trace"
(catch 'exit
(maphash (lambda (key val)
(let ((res (string-match "\\(^[0-9]+\\):" key)))
(if (and
res
(equal (string-to-number (match-string 1 key))
(gklee-get-lineno tname)))
(throw 'exit t))))
gklee-error-htable)
))
(defconst gklee-error-table
'(
("assert" . "Assertion violation")
("wwrwb" . "Write write race within warp benign")
("wwrw" . "Write write race within warp")
("wwrawb" . "Write write race across warps benign")
("wwraw" . "Write write race across warps")
("rwraw" . "Read write race across warps")
("wwbdb" . "Write write branch divergence race benign")
("wwbd" . "Write write branch divergence race")
("rwbd" . "Read write branch divergence race")
("rw" . "Write read race")
("ww" . "Write write race")
("dlbm" . "Deadlock due to barrier mismatch\nlocation reported is first thread in divergent set")
("dbs" . "Potential deadlock -- different barrier sequence")
("bsdl" . "Potential deadlock -- barrier sequences of differing length")
("wwbc" . "Write write bank conflict")
("rrbc" . "Read read bank conflict")
("rwbc" . "Read write bank conflict")
("mc" . "Non-coalesced global memory access")
("mv" . "Missing volatile")
("wd" . "Warp divergence")))
(defun gklee-lookup-error-code (code)
"This function returns a descriptive string of the passed
error code"
(cdr (assoc code gklee-error-table))
)
;; (defun gklee-remove-trace (code)
;; "This removes the trace info from an error code"
;; (let ((match (string-match "[0-9]*:" code)))
;; (substring code (match-end 0) (length code)))
;; )
;; (defun gklee-lookup-filter-error-code (line)
;; "Takes an error info list: (code loc0 loc1) and
;; returns a ..."
;; (let (value)
;; (dolist (item (cdr line) value)
;; (setq value (cons (gklee-remove-trace item) value))))
;; )
(defun gklee-deconstruct-location (loc)
"This function will break up an id string
into a human readable form and return the resulting
string"
(if loc
(let* ((split (split-string loc ":")))
(if (> (length split) 0)
(let ((file (gklee-get-file-from-path (nth 2 split)))
(line (nth 3 split)))
(if (not
(and file line))
"Location information not available."
(concat
file
" on line: " line
", block: " (nth 0 split)
", thread: " (nth 1 split))
)))
))
)
(defun gklee-get-id-string (item err-code)
"This function produces a string that shows identifying info for
error to be listed with a trace header in gklee-run"
(if (equal err-code "dlbm")
(gklee-deconstruct-location(car (cdr item)))
(concat (gklee-deconstruct-location(car (cdr item)))
"\n" (gklee-deconstruct-location(car (cdr (cdr item)))))
))
(defun gklee-get-error-type-list(err-lists properties)
(let ((result))
(dolist (item err-lists result)
(let ((prop-loc (cons 'gklee-err-info
(cons (cdr item) properties))))
(setq result
(concat
(apply 'propertize
(cons (concat "\n" (gklee-lookup-error-code (car item)) "\n")
(append prop-loc (list 'face (list :foreground "red")))))
(apply 'propertize
(cons (gklee-get-id-string item (car item)) prop-loc))
;gklee-lookup-filter-error-code item) properties)))
result))
))))
(defun gklee-list-trace-errors (tname properties)
"Function returns string of errors associated with the given trace
and propertizes with given properties plus a filter property for each error"
(let ((err-info-lines "")
(tr-err-list (cadr (assoc (gklee-get-lineno (file-name-nondirectory tname))
gklee-error-alist)))
)
(gklee-get-error-type-list tr-err-list properties)))
;; (mapc (lambda (err)
;; (let ((descr (assoc (car err) gklee-error-table))
;; ()))))))
;;the old version:
;; (catch 'exit
;; (maphash (lambda (key val)
;; (let ((res (string-match "\\(^[0-9]+\\):" key)))
;; (if (and
;; res
;; (equal (string-to-number (match-string 1 key))
;; (gklee-get-lineno tname)))
;; (throw 'exit
;; (gklee-get-error-type-list val
;; (append
;; (list 'face
;; (list :foreground "red"))
;; properties))
;; ))))
;; gklee-error-htable)
;; )
;; )
(defun gklee-reset-trace-source-states(trace-source-list)
"Restores all source windows associated with a trace
to their previous state. trace-source-list is an alist in form:
'((buffer-name file was-open was-read-only saved-point)([next rec]))'"
(let* ((ts-list (car trace-source-list))
(vals (cdr ts-list))
(buffer (get-buffer (car ts-list)))
(was-open (cadr vals))
(was-read-only (cadr (cdr vals)))
(ts-rest (cdr trace-source-list))
(src-point (cadr (cdr (cdr vals)))))
(if buffer
(with-current-buffer buffer
(if (not was-open)
(kill-buffer buffer)
(if (not was-read-only)
(progn
(setq buffer-read-only nil)
)
)
(buffer-enable-undo)
(set-marker gklee-source-mark src-point)
(setq overlay-arrow-position nil)
)
)
)
(if ts-rest
(gklee-reset-trace-source-states ts-rest)
)))
(defun gklee-reset-trace-source-state ()
(if gklee-trace-source-buffers
(gklee-reset-trace-source-states gklee-trace-source-buffers)))
(defun gklee-exit-trace ()
"This function causes the run buffer to become active rather
than the trace window"
(interactive)
(progn
(if (get-buffer gklee-active-filter-buffer)
(kill-buffer gklee-active-filter-buffer))
(if (get-buffer gklee-available-filter-buffer)
(kill-buffer gklee-available-filter-buffer))
(gklee-reset-trace-source-state)
(set-window-buffer (selected-window) gklee-run-buffer)
(kill-buffer gklee-trace-buffer)
; (kill-buffer gklee-trace-error-buffer)
(setq gklee-trace-buffer nil)
;(setq gklee-trace-error-buffer nil)
))
(defun gklee-populate-trace-error-list ()
"This function creates the gklee-trace-error-buffer, or clears the existing
one, and then loads it with a hierarchical list by
trace, file, line, block and tid"
(if (get-buffer gklee-trace-error-buffer)
(kill-buffer gklee-trace-error-buffer))
(get-buffer-create gklee-trace-error-buffer)
(gklee-load-trace-error-buff)
)
(defun gklee-load-trace-error-buff()
"Loads the trace error buffer so that an error may be
selected to filter the trace on in order to locate the
problem in the source code"
(let (;(buf-num (gklee-get-current-trace-num))
last-file
last-line
sorted-keys
(indent 0))
(with-current-buffer gklee-trace-error-buffer
(insert (concat
(format "Error list for trace %s by location\n" gklee-trace-buffer)
"Click on an error to select\n\n"))
(maphash (lambda (key val)
(setq sorted-keys (cons key sorted-keys))) gklee-error-htable)
(sort sorted-keys 'string<)
(mapcar (lambda (key)
(let* ((value (gethash key gklee-error-htable))
(key-comps (split-string key ":"))
(file (nth 4 key-comps))
(line (nth 3 key-comps))
)
(if (not (equal last-file file))
(progn
(insert (concat file "\n"))
(setq last-file file)
(setq last-line nil)))
(if (not (equal last-line line))
(progn
(insert (concat "line: " line "\n"))
(setq last-line line)))
)) sorted-keys
))))
(defun gklee-set-focus-to-error ()
"This function sets the focus to the current car of
gklee-trace-error-list"
(if gklee-trace-error-list
(with-current-buffer gklee-trace-buffer
(goto-char (car gklee-trace-error-list))
(beginning-of-line 2))))
;; "This function moves the trace buffer point to the location of
;; the first error, if any"
;; (if gklee-trace-first-err-line
;; (let ((pos 1))
;; (while (setq pos (next-single-property-change pos 'gklee-trace-line))
;; (if (equal gklee-trace-first-err-line
;; (get-text-property pos 'gklee-trace-line))
;; (progn
;; (goto-char pos)
;; (setq pos (point-max)) ;this will cause exit
;; ))))))
(defun gklee-filter-event (e)
"This is called when clicking on a filter item in either
available or active filter buffers"
(interactive "e")
(gklee-filter-item
(posn-point (event-end e)))
)
(defun gklee-filter-event-key ()
"This is called when pressing enter on a filter item in either
available or active filter buffers"
(interactive)
(gklee-filter-item (point))
(forward-char) ;;so that the cursor is not still on the invisible item
)
(defun gklee-filter-all (sym is-active-buf)
"This function takes one of the 'all' filter
symbols, which represent all of the members of
one of the filter categories (such as blocks)
and then applies all the symbols for that group
to either activate or deactivate its filter
in the trace buffer (and do the bookkeeping
required for showing / hiding in active/available
filter buffers"
(if (equal (symbol-name sym) "All_Blocks")
(setq sym-list gklee-block-syms)
(if (equal (symbol-name sym) "All_Threads")
(setq sym-list gklee-thread-syms)
(if (equal (symbol-name sym) "All_Files")
(setq sym-list gklee-file-syms)
(if (equal (symbol-name sym) "All_Locations")
(setq sym-list gklee-loc-syms)
(if (equal (symbol-name sym) "All_Warps")
(progn
(gklee-filter-all (gklee-intern "All_Threads" gklee-filter-obarray) is-active-buf)
(setq sym-list gklee-warp-syms)
)
)))))
(if is-active-buf
(progn
(with-current-buffer gklee-active-filter-buffer
(mapc 'add-to-invisibility-spec sym-list))
(with-current-buffer gklee-available-filter-buffer
(mapc 'remove-from-invisibility-spec sym-list))
(with-current-buffer gklee-trace-buffer
(mapc 'remove-from-invisibility-spec sym-list)))
(with-current-buffer gklee-active-filter-buffer
(mapc 'remove-from-invisibility-spec sym-list))
(with-current-buffer gklee-available-filter-buffer
(mapc 'add-to-invisibility-spec sym-list))
(with-current-buffer gklee-trace-buffer
(mapc 'add-to-invisibility-spec sym-list)))
)
(defun gklee-get-invis-tag-id (sym &optional prefix-len)
"Takes a symbol used for invisibility list
filtering, and returns the numerical id for it"
(let ((pre-len (if prefix-len prefix-len 1)))
(string-to-number (substring (symbol-name sym) pre-len (length (symbol-name sym))))
)
)
(defun gklee-get-threads-by-warp (warp threads)
(let* ((warp-id (gklee-get-invis-tag-id warp))
(first-thread (gklee-get-first-t-in-warp warp-id))
(last-thread (gklee-get-last-t-in-warp warp-id))
(out-list))
(mapcar (lambda (thd)
(let ((cw (gklee-get-invis-tag-id thd)))
(if (and
(not (equal "All_Threads" (symbol-name thd)))
(<= cw last-thread)
(>= cw first-thread))
thd
)))
threads))
)
(defun gklee-remove-from-invisibility-spec (item)
(if item
(remove-from-invisibility-spec item))
)
(defun gklee-add-to-invisibility-spec (item)
(if item
(add-to-invisibility-spec item))
)
(defun gklee-filter-warp (sym in-active-buf)
"This takes a warp symbol and then filters/unfilters all threads
related to that symbol, depending upon whether this is being
called under the 'active' filter buffer or the 'available' filter
buffer. This function handles all bookkeeping wrt the visibility
of the symbol in the filter buffers"
(let ((threads (gklee-get-threads-by-warp sym gklee-thread-syms)))
(if in-active-buf
(progn
(with-current-buffer gklee-active-filter-buffer
(mapc 'gklee-add-to-invisibility-spec threads))
(with-current-buffer gklee-available-filter-buffer
(mapc 'gklee-remove-from-invisibility-spec threads))
(with-current-buffer gklee-trace-buffer
(mapc 'gklee-remove-from-invisibility-spec threads))
)
(with-current-buffer gklee-active-filter-buffer
(mapc 'gklee-remove-from-invisibility-spec threads))
(with-current-buffer gklee-available-filter-buffer
(mapc 'gklee-add-to-invisibility-spec threads))
(with-current-buffer gklee-trace-buffer
(mapc 'gklee-add-to-invisibility-spec threads))))
)
(defun gklee-filter-item (pos)
"This function takes a point from a filter buffer
and performs the filter operation (shuffling filter
symbols around buffer-invisibility-spec's)"
(let* ((buf (buffer-name))
(isym (get-text-property pos 'invisible))
(in-active (equal gklee-active-filter-buffer buf))
(sym-name (symbol-name isym))
)
(gklee-add-to-invisibility-spec isym)
(if (and
(> (length sym-name) 2)
(equal (substring (symbol-name isym) 0 3) "All"))
(gklee-filter-all isym in-active)
(if (equal (substring (symbol-name isym) 0 1) "W")
(gklee-filter-warp isym in-active)))
(if in-active
(progn
(with-current-buffer gklee-trace-buffer
(remove-from-invisibility-spec isym))
(with-current-buffer gklee-available-filter-buffer
(remove-from-invisibility-spec isym))
)
(with-current-buffer gklee-trace-buffer
(gklee-add-to-invisibility-spec isym))
(with-current-buffer gklee-active-filter-buffer
(remove-from-invisibility-spec isym)
))
(redraw-display) ;;redraw-display is a hack to get the buffers to update after filtering
))
(defun gklee-insert-symbols-with-invis (symlist sep invis &optional is-path)
"Performs an insert (with current buffer) of symlist,
separated by 'sep', adding itself
as an 'invisible symbol -- the symbols MUST be interned in
gklee-filter-obarray already"
(let ((i-list (if is-path
(list 'invisible (gklee-intern "HIDDEN" gklee-filter-obarray))