-
Notifications
You must be signed in to change notification settings - Fork 55
/
jdee-db.el
1970 lines (1697 loc) · 72.5 KB
/
jdee-db.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
;;; jdee-db.el -- Debugger mode for jdb.
;; Author: Paul Kinnucan <[email protected]>
;; Maintainer: Paul Landes <landes <at> mailc dt net>
;; Keywords: java, tools
;; Copyright (C) 1997, 2000, 2001, 2002, 2003, 2004, 2005 Paul Kinnucan.
;; Copyright (C) 2009 by Paul Landes
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, US
;;; Commentary:
;; This package interfaces Emacs to jdb, the debugger
;; distributed as part of JDK.
;;; Code:
(require 'cl-lib)
(require 'eieio)
(require 'jdee-classpath)
(require 'jdee-files)
(require 'jdee-open-source)
(require 'jdee-parse)
(require 'jdee-util)
(require 'widget)
(eval-when-compile
(require 'wid-edit))
;; FIXME: refactor
(declare-function jdee-dbs-debugger-running-p "jdee-dbs" ())
(declare-function jdee-dbs-get-target-process "jdee-dbs" ())
(declare-function jdee-jdb-get-jdb "jdee-jdb" ())
(defvar jdee-dbs-the-debugger)
(defvar jdee-debugger);; jde
;; ======================================================================
;; jdee-db variables
(defcustom jdee-db-query-missing-source-files t
"If nonnil, this variable causes the debugger to query you
for the path of a class source file that it cannot find in
`jdee-sourcepath'."
:group 'jdee-project
:type 'boolean)
(defcustom jdee-db-mode-hook nil
"*Customization hook for jdee-db inferior mode."
:group 'jdee-project
:type 'hook
)
(defcustom jdee-db-initial-step-p t
"*If non-nil, this option causes the debugger
to issue a step-into command after launching
a program. This causes the vm to step to the
first line of the debuggee program."
:group 'jdee-project
:type 'boolean)
(defcustom jdee-db-read-vm-args nil
"*Read vm arguments from the minibuffer.
If this variable is non-nil, the jdee-db command reads vm arguments
from the minibuffer and appends them to those specified by
the `jdee-db-option' variable group."
:group 'jdee-project
:type 'boolean)
(defvar jdee-db-interactive-vm-arg-history nil
"History of vm arguments read from the minibuffer")
(defcustom jdee-db-read-app-args nil
"*Read arguments to be passed to application from the minibuffer."
:group 'jdee-project
:type 'boolean)
(defvar jdee-db-interactive-app-arg-history nil
"History of application arguments read from the minibuffer")
(defcustom jdee-db-classic-mode-vm nil
"Runs applications in the classic (i.e., not HotSpot) mode when
debugging."
:group 'jdee-project
:type 'boolean)
(defgroup jdee-db-options nil
"JDE Debugger Options"
:group 'jdee
:prefix "jdee-db-option-")
(defcustom jdee-db-option-classpath nil
"*Specify paths of classes required to run this application.
The JDE uses the specified paths to construct a -classpath
argument to pass to the Java interpreter. This option overrides the
`jdee-global-classpath' option."
:group 'jdee-db-options
:type '(repeat (file :tag "Path")))
(defcustom jdee-db-option-verbose (list nil nil nil)
"*Print messages about the running process.
The messages are printed in the run buffer."
:group 'jdee-db-options
:type '(list :indent 2
(checkbox :format "\n %[%v%] %h \n"
:doc "Print classes loaded.
Prints a message in the run buffer each time a class is loaded.")
(checkbox :format "%[%v%] %h \n"
:doc "Print memory freed.
Prints a message in the run buffer each time the garbage collector
frees memory.")
(checkbox :format "%[%v%] %h \n"
:doc "Print JNI info.
Prints JNI-related messages including information about which native
methods have been linked and warnings about excessive creation of
local references.")))
(defcustom jdee-db-option-properties nil
"*Specify property values.
Enter the name of the property, for example, awt.button.color, in the
Property Name field; enter its value, for example, green, in the
Property Value field. You can specify as many properties as you like."
:group 'jdee-db-options
:type '(repeat (cons
(string :tag "Property Name")
(string :tag "Property Value"))))
(defcustom jdee-db-option-heap-size (list
(cons 1 "megabytes")
(cons 16 "megabytes"))
"*Specify the initial and maximum size of the interpreter heap."
:group 'jdee-db-options
:type '(list
(cons (integer :tag "Start")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))
(cons (integer :tag "Max")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))))
(defcustom jdee-db-option-stack-size (list
(cons 128 "kilobytes")
(cons 400 "kilobytes"))
"*Specify size of the C and Java stacks."
:group 'jdee-db-options
:type '(list
(cons (integer :tag "C Stack")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))
(cons (integer :tag "Java Stack")
(radio-button-choice (const "bytes")
(const "kilobytes")
(const "megabytes")
(const "gigabytes")))))
(defcustom jdee-db-option-garbage-collection (list t t)
"*Specify garbage collection options."
:group 'jdee-db-options
:type '(list :indent 2
(checkbox :format "%[%v%] %t \n"
:tag "Collect garbage asynchronously.")
(checkbox :format "%[%v%] %t \n"
:tag "Collect unused classes.")))
(defcustom jdee-db-option-java-profile (cons nil "./java.prof")
"*Enable Java profiling."
:group 'jdee-db-options
:type '(cons boolean
(file :tag "File"
:help-echo
"Specify where to put profile results here.")))
(defcustom jdee-db-option-heap-profile (cons nil
(list "./java.hprof"
5
20
"Allocation objects"))
"*Output heap profiling data."
:group 'jdee-db-options
:type '(cons boolean
(list
(string :tag "Output File Path")
(integer :tag "Stack Trace Depth")
(integer :tag "Allocation Sites")
(radio-button-choice :format "%t \n%v"
:tag "Sort output based on:"
(const "Allocation objects")
(const "Live objects")))))
(defcustom jdee-db-option-verify (list nil t)
"*Verify classes."
:group 'jdee-db-options
:type '(list :indent 2
(checkbox :format "%[%v%] %t \n"
:tag "Executed code in all classes.")
(checkbox :format "%[%v%] %t \n"
:tag "Classes loaded by a classloader.")))
(defcustom jdee-db-option-host ""
"Host of a remote process to which you wish to attach. This
option is invalid for JDK verions greater than JDK 1.1.x."
:group 'jdee-db-options
:type 'string)
;; (makunbound 'jdee-db-option-connect-socket)
(defcustom jdee-db-option-connect-socket (list nil "4444")
"Specify address of socket to be used to connect the debugger and a
debuggee process. Selecting \"Prompt\" from the customization value
menu causes the debugger to prompt you to enter the shared memory name
when you command it to attach to or listen for an existing
process. Selecting \"Specify\" allows you to specify a default socket
host and port to be used by the debugger. "
:group 'jdee-db-options
:type '(choice
(const :menu-tag "Prompt" nil)
(list
:menu-tag "Specify" :tag "Socket Address" :inline nil
(choice
:tag "Host"
(const :menu-tag "Local" nil)
(string :menu-tag "Remote" :tag "Name"))
(choice
:tag "Port"
(const :menu-tag "Default" "4444")
(string :menu-tag "Custom")))))
;; (makunbound 'jdee-db-option-connect-shared-memory-name)
(defcustom jdee-db-option-connect-shared-memory-name "javadebug"
"Specify name to use to establish a shared memory connection
between the debugger and a debuggee process. Selecting \"Prompt\" from
the customization value menu causes a debugger attach or listen
command, e.g., `jdee-jdb-attach-via-shared-memory', to prompt you to
enter the shared memory name. Selecting \"Specify\" allows you to
specify a name of your choosing."
:group 'jdee-db-options
:type '(choice
(const :menu-tag "Prompt" nil)
(string :menu-tag "Specify" :tag "Name")))
(defcustom jdee-db-option-vm-args nil
"*Specify arguments to be passed to the Java vm.
This option allows you to specify one or more arguments to be passed
to the Java interpreter. It is an alternative to using JDE Run Option
variables, such as `jdee-run-option-stack-size', to specify Java
interpreter options. Also, it makes it possible to use the JDE with
interpreters that accept command line arguments not supported by
the JDE Run Option variable set."
:group 'jdee-db-options
:type '(repeat (string :tag "Argument")))
(defcustom jdee-db-option-application-args nil
"*Specify command-line arguments to pass to the application.
The JDE passes the specified arguments to the application on
the command line."
:group 'jdee-db-options
:type '(repeat (string :tag "Argument")))
(defmacro jdee-assert-source-or-debug-buffer ()
"Asserts that the current buffer is a
Java source or a debug buffer."
'(assert
(or
(eq major-mode 'jdee-mode)
(and (slot-boundp 'jdee-db-debugger 'the-debugger)
(eq (current-buffer)
(oref (oref-default 'jdee-db-debugger the-debugger) buffer))))
nil
"This command works only in a Java source or debug buffer."))
(defcustom jdee-db-log-debugger-output-flag nil
"Log raw debugger output to a buffer. This variable is intended
to be used for debugging the JDEE's debuggers."
:group 'jdee-db-options
:type 'boolean)
(defun jdee-db-log-debugger-output (output)
(if jdee-db-log-debugger-output-flag
(let ((buf (get-buffer "debugger output")))
(when (not buf)
(setq buf (get-buffer-create "debugger output"))
(pop-to-buffer buf))
(with-current-buffer buf
(goto-char (point-max))
(insert output)))))
(defun jdee-db-get-debuggee-status ()
"Get the`jdee-db-debuggee-status' of the
current debuggee process."
(if (slot-boundp 'jdee-db-debugger 'the-debugger)
(let* ((debugger (oref-default 'jdee-db-debugger the-debugger))
(debuggee (oref debugger debuggee)))
(oref debuggee status))))
(defun jdee-db-debuggee-stopped-p ()
"Return t if current debuggee process is stopped."
(let ((status (jdee-db-get-debuggee-status)))
(if status
(oref status stopped-p))))
(defun jdee-db-debuggee-suspended-p ()
"Return t if current debuggee process is suspended."
(let ((status (jdee-db-get-debuggee-status)))
(if status
(oref status suspended-p))))
(defun jdee-db-debuggee-running-p ()
"Return t if current debuggee process is running."
(let ((status (jdee-db-get-debuggee-status)))
(if status
(oref status running-p))))
;; FIXME: the variable 'jdb-db-debugger' is not used anywhere else, so
;; this function is pointless.
;; ;;;###autoload
;; (defun jdee-db-set-debugger (name is-executable)
;; "Specify the pathname of the debugger, if an executable, or the
;; debugger's fully qualified class name, if a class."
;; (interactive
;; "sEnter name of Java interpreter: \nsIs %s executable? (yes): ")
;; (let ((db name)
;; (type
;; (if (stringp is-executable)
;; (if (or
;; (string= is-executable "")
;; (eq (aref is-executable 0) ?y))
;; "Executable"
;; "Class")
;; "Executable")))
;; (setq jdee-db-debugger (cons "Other" (cons db type)))))
;;;###autoload
(defun jdee-db-set-args (args)
"Specify the arguments (except -classpath) to be passed to the debugger."
(interactive
"sEnter arguments: ")
(setq jdee-db-option-vm-args (jdee-run-parse-args args)))
;;;###autoload
(defun jdee-db-set-app-args (args)
"Specify the arguments to be passed to the Java application class."
(interactive
"sEnter arguments: ")
(setq jdee-db-option-application-args (jdee-run-parse-args args)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Breakpoints ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom jdee-db-spec-breakpoint-face-colors (cons "black" "green")
"*Specifies the foreground and background colors used to highlight
the line at which you have specified that a breakpoint to be set."
:group 'jdee-project
:type '(cons :tag "Colors"
(string :tag "Foreground")
(string :tag "Background"))
:set '(lambda (sym val)
(make-face 'jdee-db-spec-breakpoint-face)
(set-face-foreground 'jdee-db-spec-breakpoint-face (car val))
(set-face-background 'jdee-db-spec-breakpoint-face (cdr val))
(set-default sym val)))
(defcustom jdee-db-requested-breakpoint-face-colors (cons "black" "yellow")
"*Specifies the foreground and background colors used to highlight
the line at which you have requested a breakpoint to be set."
:group 'jdee-project
:type '(cons :tag "Colors"
(string :tag "Foreground")
(string :tag "Background"))
:set '(lambda (sym val)
(make-face 'jdee-db-requested-breakpoint-face)
(set-face-foreground 'jdee-db-requested-breakpoint-face (car val))
(set-face-background 'jdee-db-requested-breakpoint-face (cdr val))
(set-default sym val)))
(defcustom jdee-db-active-breakpoint-face-colors (cons "black" "red")
"*Specifies the foreground and background colors used to highlight
a line where an active breakpoint exists."
:group 'jdee-project
:type '(cons :tag "Colors"
(string :tag "Foreground")
(string :tag "Background"))
:set '(lambda (sym val)
(make-face 'jdee-db-active-breakpoint-face)
(set-face-foreground 'jdee-db-active-breakpoint-face (car val))
(set-face-background 'jdee-db-active-breakpoint-face (cdr val))
(set-default sym val)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Breakpoint Marker Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-db-breakpoint-marker ()
((marker :initarg :marker
:documentation
"Overlay in Emacs, extent in XEmacs"))
"Indicates the location of breakpoints in a source buffer. This class
uses overlays as markers in Emacs and extents in XEmacs.")
(defmethod initialize-instance ((this jdee-db-breakpoint-marker) &rest fields)
"Create a breakpoint overlay at LINE in FILE."
;; Call parent initializer.
(call-next-method)
(oset this marker
(make-overlay
(jdee-line-beginning-position)
(1+ (jdee-line-end-position))
(current-buffer) nil t)))
(defmethod jdee-db-breakpoint-marker-set-face ((this jdee-db-breakpoint-marker) face)
"Apply FACE to OVERLAY."
(let ((marker (oref this marker)))
(progn
(overlay-put marker 'face face)
(overlay-put marker 'priority 98))))
(defun jdee-db-breakpoint-marker-p (marker)
"Return t if overlay is a breakpoint marker overlay."
(let ((marker-face
(overlay-get marker 'face)))
(or
(eq marker-face 'jdee-db-spec-breakpoint-face)
(eq marker-face 'jdee-db-requested-breakpoint-face)
(eq marker-face 'jdee-db-active-breakpoint-face))))
(defmethod jdee-db-breakpoint-marker-delete ((this jdee-db-breakpoint-marker))
"Remove breakpoint overlay at LINE in FILE."
(delete-overlay (oref this marker)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Breakpoint Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-db-breakpoint ()
((id :initarg :id
:type integer
:documentation
"Identifies this breakpoint.")
(file :initarg :file
:initform ""
:type string
:documentation
"Pathname of file containing this breakpoint.")
(line :initarg :line
:type integer
:documentation
"Number of line at which breakpoint is set.")
(marker :initarg :marker
:type (or null jdee-db-breakpoint-marker)
:initform nil
:documentation
"Marker used to highlight breakpoint line.")
(class :initarg :class
:type string
:documentation
"Qualified name of class containing breakpoint.")
(status :initarg status
:type symbol
:initform specified
:documentation
"Status of this breakpoint. Legal values are `specified', `requested', `active'."))
(:allow-nil-initform t)
"Class of breakpoints.")
(defmethod initialize-instance ((this jdee-db-breakpoint) &rest fields)
"Constructor for a breakpoint specification."
;; Call parent initializer.
(call-next-method)
(assert (oref this file))
(oset this
marker
(jdee-db-breakpoint-marker "breakpoint marker"))
(jdee-db-breakpoint-marker-set-face
(oref this marker) 'jdee-db-spec-breakpoint-face))
(defmethod jdee-db-breakpoint-get-line ((this jdee-db-breakpoint))
"Get the number of the line at which this breakpoint is set."
(with-current-buffer (find-file-noselect (oref this file))
(if (oref this marker)
(let ((marker-start
(overlay-start (oref (oref this marker) marker))))
(jdee-get-line-at-point marker-start))
(oref this line))))
(defvar jdee-db-breakpoints nil
"Current breakpoints.")
(defun jdee-db-get-breakpoint-marker (file line)
"Get breakpoint marker at FILE and LINE."
(let ((bp (jdee-db-find-breakpoint file line)))
(if bp
(oref bp marker))))
(defun jdee-db-mark-breakpoint-specified (file line)
"Changes the face of the breakpoint marker at LINE in FILE
to the specified face."
(let ((marker (jdee-db-get-breakpoint-marker file line)))
(if marker
(jdee-db-breakpoint-marker-set-face marker 'jdee-db-spec-breakpoint-face))))
(defun jdee-db-mark-breakpoint-active (file line)
"Changes the face of the breakpoint marker at LINE in FILE
to the active face."
(let ((marker (jdee-db-get-breakpoint-marker file line)))
(if marker
(jdee-db-breakpoint-marker-set-face marker 'jdee-db-active-breakpoint-face))))
(defun jdee-db-mark-breakpoint-requested (file line)
"Changes the face of the breakpoint marker at LINE in FILE
to the active face."
(let ((marker (jdee-db-get-breakpoint-marker file line)))
(if marker
(jdee-db-breakpoint-marker-set-face marker 'jdee-db-requested-breakpoint-face))))
(defun jdee-db-set-all-breakpoints-specified ()
"Changes the face of all breakpoints to `jdee-db-spec-breakpoint-face'
and sets the status of all breakpoints to `specified'."
(loop for bp-assoc in jdee-db-breakpoints do
(let* ((bp (cdr bp-assoc))
(marker (oref bp marker)))
(oset bp status 'specified)
(if marker
(jdee-db-breakpoint-marker-set-face marker 'jdee-db-spec-breakpoint-face)))))
(defun jdee-db-delete-breakpoint (bp)
"Delete the breakpoint at LINE in FILE."
(setq jdee-db-breakpoints
;; bp will be in the list so don't run the risk of using a
;; deleted extent.
(let ((bpline (jdee-db-breakpoint-get-line bp)))
(cl-remove-if
(lambda (assoc-x)
(let* ((xbp (cdr assoc-x))
(xfile (oref xbp file))
(deletep
(and
(string= (oref bp file) xfile)
(equal bpline (jdee-db-breakpoint-get-line xbp)))))
(if deletep
(jdee-db-breakpoint-marker-delete
(oref bp marker)))
deletep))
jdee-db-breakpoints))))
(defun jdee-db-clear-breakpoints ()
"Clear all breakpoints from all buffers."
(mapc
(lambda (assoc-x)
(let* ((xbp (cdr assoc-x))
(file (oref xbp file))
(buf (find-buffer-visiting file)))
(if buf
(with-current-buffer buf
(let ((xmarker (oref xbp marker)))
(jdee-db-breakpoint-marker-delete xmarker))))))
jdee-db-breakpoints)
(setq jdee-db-breakpoints nil))
(defvar jdee-db-bp-list nil)
(defun jdee-debug-list-breakpoints (&optional active)
"Brings a list of all set breakpoints. It allows the user to jump to a
particular breakpoint and to select breakpoints to be clear."
(interactive "i")
(if jdee-db-breakpoints
(progn
(switch-to-buffer "*Breakpoints List*")
(kill-all-local-variables)
(make-local-variable 'jdee-db-bp-list)
(setq jdee-db-bp-list nil)
(let ((inhibit-read-only t))
(erase-buffer))
(setq active (not active))
(widget-insert "Breakpoints:\n\n")
(mapc
(lambda (assoc-x)
(let* ((xbp (cdr assoc-x))
(id (oref xbp id))
(class (oref xbp class))
(file (oref xbp file))
(line (oref xbp line))
(status (oref xbp status)))
(widget-create
'checkbox
:notify (lambda (widget &rest ignore)
(if (widget-value widget)
(setq jdee-db-bp-list
(delete (widget-get widget :id)
jdee-db-bp-list))
(setq jdee-db-bp-list
(append jdee-db-bp-list
(list (widget-get widget :id))))))
:id id
active)
(if (not active)
(setq jdee-db-bp-list (append jdee-db-bp-list (list id))))
(widget-insert " ")
(widget-create 'push-button
:notify (lambda (widget &rest ignore)
(progn
(find-file-other-window
(widget-get widget :file))
(goto-char (point-min))
(forward-line
(1- (widget-get widget :line)))))
:button-face
(cond
((eq status 'specified)
'jdee-db-spec-breakpoint-face)
((eq status 'active)
'jdee-db-active-breakpoint-face)
(t 'jdee-db-requested-breakpoint-face))
:file file
:line line
(format "%s:%d" class line))
(widget-insert "\n")))
jdee-db-breakpoints)
(widget-insert "\n")
(widget-create 'push-button
:notify (lambda (&rest ignore)
(jdee-debug-list-breakpoints t))
"Clear All")
(widget-insert " ")
(widget-create 'push-button
:notify (lambda (&rest ignore)
(progn
(jdee-db-process-breakpoints)
(kill-buffer "*Breakpoints List*")))
"Apply Form")
(use-local-map widget-keymap)
(widget-insert "\n")
(widget-setup))
(message "No breakpoints")))
(defun jdee-db-process-breakpoints ()
"Deletes all the breakpoints found in `jdee-db-bp-list'"
(if jdee-db-bp-list
(if (jdee-db-debuggee-running-p)
(let* ((debugger (oref-default 'jdee-db-debugger the-debugger))
(bp-cmd (oref (oref debugger cmd-set) clear-bp)))
(oset
bp-cmd
breakpoints
(mapcar
(lambda (assoc-x)
(jdee-db-find-breakpoint-by-id assoc-x))
jdee-db-bp-list))
(jdee-db-exec-cmd debugger bp-cmd))
(loop for bp-assoc in jdee-db-bp-list do
(let ((bp (jdee-db-find-breakpoint-by-id bp-assoc)))
(jdee-db-delete-breakpoint bp))))))
(defun jdee-db-breakpoints-add (bp)
"Adds this breakpoint to the list of breakpoints."
(setq jdee-db-breakpoints
(cons (cons (oref bp id) bp)
jdee-db-breakpoints)))
(defun jdee-db-find-breakpoint-by-id (id)
"Finds the breakpoint object with ID"
(cdr (cl-find-if
(lambda (assoc-x)
(let ((bp (cdr assoc-x)))
(= (oref bp id) id)))
jdee-db-breakpoints)))
(defun jdee-db-find-breakpoint (file line)
"Finds the breakpoint object for the breakpoint at FILE and LINE."
(cdr (cl-find-if
(lambda (assoc-x)
(let ((bp (cdr assoc-x)))
(and (string= (oref bp file) file)
(equal (jdee-db-breakpoint-get-line bp) line))))
jdee-db-breakpoints)))
(defvar jdee-db-breakpoint-id-counter 0
"Counter for generating breakpoint ids")
(defun jdee-db-nullify-breakpoint-markers ()
"Set the marker field for each breakpoint
in the current buffer to nil."
(when (eq major-mode 'jdee-mode)
(let ((file (buffer-file-name)))
(loop for bp-assoc in jdee-db-breakpoints do
(let ((bp (cdr bp-assoc)))
(when (string= (oref bp file) file)
(oset bp line (jdee-db-breakpoint-get-line bp))
(oset bp marker nil)))))))
(add-hook 'kill-buffer-hook 'jdee-db-nullify-breakpoint-markers)
(defun jdee-db-remark-breakpoints ()
"Highlights all breakpoints in the current buffer if not
already highlighted."
(save-excursion
(loop for bp-assoc in jdee-db-breakpoints do
(let* ((bp (cdr bp-assoc))
(file (buffer-file-name))
(line (oref bp line))
(status (oref bp status)))
(if (string-equal file (oref bp file))
(progn
(goto-char (point-min))
(forward-line (1- line))
(oset bp
marker
(jdee-db-breakpoint-marker "breakpoint marker"))
(cond
((eq status 'specified)
(jdee-db-mark-breakpoint-specified file line))
((eq status 'requested)
(jdee-db-mark-breakpoint-requested file line))
((eq status 'active)
(jdee-db-mark-breakpoint-active file line))
(t
(error "Unknown breakpoint status: %s"
(symbol-name status))))))))
))
(add-hook 'jdee-mode-hook 'jdee-db-remark-breakpoints)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debug Cursor Handling ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun jdee-db-query-source-file (class)
(let ((source-file
(read-file-name
(format "Cannot find %s source. Enter path: " class))))
(if (and
source-file
(file-exists-p source-file)
(not (file-directory-p source-file)))
(find-file-noselect source-file))))
(defun jdee-db-find-class-source (class)
"Find and open the source file for a class. CLASS is the fully
qualified name of the class. If this function is unable to find the
source for CLASS in `jdee-sourcepath' and
`jdee-db-query-missing-source-files' is nonnil, this function queries
the user for the path to the source file. If successful, this function
returns an unselected buffer containing the source file for the
class. Otherwise, it returns nil."
(let* ((source-file (jdee-find-class-source-file class))
(source-buffer
(if source-file
(find-file-noselect source-file)
(if jdee-db-query-missing-source-files
(jdee-db-query-source-file class)))))
source-buffer))
(defun jdee-db-set-debug-cursor (class file line)
"Shows the source at LINE in CLASS."
(let* ((buffer (jdee-db-find-class-source class))
(window
(and buffer
(or (get-buffer-window buffer)
(selected-window))))
pos)
(if buffer
(progn
(if (not (get-buffer-window buffer))
(set-window-buffer window buffer))
(with-current-buffer buffer
(save-restriction
(widen)
(goto-char (point-min))
(forward-line (1- line))
(setq pos (point))
(setq overlay-arrow-string "=>")
(or overlay-arrow-position
(setq overlay-arrow-position (make-marker)))
(set-marker overlay-arrow-position (point) (current-buffer)))
(cond ((or (< pos (point-min)) (> pos (point-max)))
(widen)
(goto-char pos))))
(set-window-point window overlay-arrow-position)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debuggee Process Status Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-db-debuggee-status ()
((running-p :initarg :running-p
:type boolean
:initform nil
:documentation
"Non-nil if debuggee process is running.")
(stopped-p :initarg :stopped-p
:type boolean
:initform nil
:documentation
"Non-nil if debuggee process is stopped.")
(suspended-p :initarg :suspended-p
:type boolean
:initform nil
:documentation
"Non-nil if debuggee process is suspended."))
"Status of debuggee process.")
(defmethod initialize-instance ((this jdee-db-debuggee-status) &rest fields)
"Status of debuggee process."
(call-next-method))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debuggee Process Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-db-connector () ()
"Proxy for debugger connectors.")
(defclass jdee-db-launch-connector (jdee-db-connector) ()
"Launched by the debugger.")
(defclass jdee-db-socket-connector (jdee-db-connector)
((port :initarg :port
:type (or null string)
:initform nil
:documentation
"Port to the debuggee process."))
"Connect via a socket.")
(defclass jdee-db-shared-memory-connector (jdee-db-connector)
((name :initarg :name
:type (or null string)
:initform nil
:documentation
"Shared memory name of debuggee process."))
"Connect via a shared-memory transport (Windows only).")
(defclass jdee-db-attach-connector (jdee-db-connector) ()
"Attaches to debuggee.")
(defclass jdee-db-listen-connector (jdee-db-connector) ()
"Listens for debuggee.")
(defclass jdee-db-socket-attach-connector (jdee-db-socket-connector
jdee-db-attach-connector)
((host :initarg :host
:type (or null string)
:initform nil
:documentation
"Host on which the debuggee process runs."))
"Attach via a socket.")
(defclass jdee-db-shared-memory-attach-connector (jdee-db-shared-memory-connector
jdee-db-attach-connector)
()
"Attach via a shared memory connection.")
(defclass jdee-db-socket-listen-connector (jdee-db-socket-connector
jdee-db-listen-connector)
()
"Listen via a socket.")
(defclass jdee-db-shared-memory-listen-connector (jdee-db-shared-memory-connector
jdee-db-listen-connector)
()
"Listen via a shared memory connection.")
(defclass jdee-db-debuggee ()
((status :initarg :status
:type jdee-db-debuggee-status
:documentation
"Status of debuggee process.")
(stack-depth :initarg :stack-depth
:type string
:initform ""
:documentation
"Stack depth."))
"Program being debugged.")
(defmethod initialize-instance ((this jdee-db-debuggee) &rest fields)
"Constructs an instance of a debuggee."
(call-next-method))
(defclass jdee-db-debuggee-app (jdee-db-debuggee)
((main-class :initarg :main-class
:type string
:documentation
"Qualified name of debuggee main class.")
(connector :initarg :connector
:type jdee-db-connector
:documentation
"Type of connector between this debuggee and the debugger."))
"Application being debugged.")
(defclass jdee-db-debuggee-applet (jdee-db-debuggee)
((doc :initarg :doc
:type string
:documentation
"Path of applet HTML document."))
"Applet being debugged.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debugger Command Line Commands ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-db-cmd ()
((name :initarg :name
:type string
:documentation
"Name of command.")
(debugger :initarg :debugger
:type jdee-db-debugger
:documentation
"Debugger."))
"Super class of debugger commands.")
(defmethod initialize-instance ((this jdee-db-cmd) &rest fields)
"Constructor for debugger commands."
(call-next-method))
(defmethod jdee-db-cmd-init ((this jdee-db-cmd))
"The debugger invokes this method before executing the
command.")
(defmethod jdee-db-cmd-make-command-line ((this jdee-db-cmd))
"Creates the command line for this command."
(oref this name))
(defmethod jdee-db-cmd-notify-response ((this jdee-db-cmd) response)
"Invoked when the debugger responds to the command. RESPONSE
is the response.")
(defmethod jdee-db-cmd-response-p ((this jdee-db-cmd) output)
"Returns nonnil if external debugger's output is a
response to this command."
t)
(defclass jdee-db-cmd-breakpoint (jdee-db-cmd)
((breakpoints :initarg :breakpoints
:type list
:documentation
"List of breakpoint specification."))
"Class of breakpoint commands.")