-
Notifications
You must be signed in to change notification settings - Fork 55
/
jdee-dbs.el
3300 lines (2755 loc) · 128 KB
/
jdee-dbs.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-dbs.el -- JDEbug Session Interface Functions
;; Author: Paul Kinnucan <[email protected]>
;; Maintainer: Paul Landes <landes <at> mailc dt net>
;; Keywords: java, tools
;; Copyright (C) 1997, 1998, 1999, 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, USA.
;;; Commentary:
;; This is one of a set of packages that make up the JDEE.
;; See the JDEE User's Guide for more information.
;;; Code:
(require 'cl-lib)
(require 'eieio)
(require 'jdee-classpath)
(require 'jdee-db)
(require 'jdee-dbo)
(require 'jdee-files)
(require 'tree-widget)
;; FIXME: refactor to eliminate these
(defvar jdee-bug-debug)
(defvar jdee-bug-debugger-command-timeout)
(defvar jdee-bug-debugger-host-address)
(declare-function jdee-bug-vm-includes-jpda-p "jdee-bug" ())
(declare-function jdee-get-tools-jar "jdee" nil)
;; Need jdee-run only to get the definition for
;; save-w32-show-window macro. FIXME: refactor
(eval-when-compile
(require 'jdee-run))
(defcustom jdee-bug-sio-connect-delay 1
"Length of time in seconds that the JDE waits
before attempting to connect to the
debuggee application's standard I/O. This delay
is intended to give JDEbug time to create the
SIO socket. Try increasing this variable if JDEbug
hangs while launching an application. If your
system never hangs, you can reduce this setting
to 0 to eliminate the connection delay."
:group 'jdee-bug
:type 'integer)
(defvar jdee-dbs-comint-filter nil
"Standard comint filter for debugger buffer.")
(defvar jdee-dbs-debugger-process-name "jdebug"
"Name of debugger process.")
(defun jdee-dbs-get-debugger-process ()
(get-process jdee-dbs-debugger-process-name))
(defvar jdee-dbs-debugger-output-buffer-name "*JDEbug Messages*"
"Name of buffer used to display messages from the debugger.")
(defvar jdee-dbs-debugger-socket-process-name "jdebug-socket"
"Name of debugger socket process.")
(defvar jdee-dbs-debugger-hook nil
"Hook to run when starting or stopping the debugger.
The hook is run with a single argument which is non-nil when the
debugger is starting and nil when it is quitting.")
(defun jdee-dbs-get-debugger-socket-process ()
(get-process jdee-dbs-debugger-socket-process-name))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Process Set ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc-set ()
((proc-alist :initarg :proc-alist
:type list
:initform nil
:documentation
"List of active debugee processes"))
"Class of debuggee process sets.")
(defmethod jdee-dbs-proc-set-add ((this jdee-dbs-proc-set) process)
"Adds a process to this debuggee process set."
(oset this :proc-alist
(cons
(cons (oref process :id) process)
(oref this :proc-alist))))
(defmethod jdee-dbs-proc-set-remove ((this jdee-dbs-proc-set) process)
(oset this :proc-alist
(cl-remove-if
(lambda (assoc-x)
(let* ((xproc (cdr assoc-x))
(xid (oref xproc id))
(id (oref process id)))
(equal xid id)))
(oref this proc-alist))))
(defmethod jdee-dbs-proc-set-get-proc ((this jdee-dbs-proc-set) id)
(cdr (assq id (oref this :proc-alist))))
(defmethod jdee-dbs-proc-set-find ((this jdee-dbs-proc-set) field value)
"Finds the process in the set whose FIELD is equal to VALUE."
(if (slot-boundp this :proc-alist)
(cdr (cl-find-if
(lambda (assoc-x)
(let ((process-x (cdr assoc-x)))
(equal (eieio-oref process-x field) value)))
(oref this :proc-alist)))))
(defmethod jdee-dbs-proc-set-contains-p ((this jdee-dbs-proc-set) process)
(assq (oref process :id) (oref this :proc-alist)))
(defmethod jdee-dbs-proc-set-get-size ((this jdee-dbs-proc-set))
"Gets the number of processes in this set."
(if (slot-boundp this 'proc-alist)
(length (oref this proc-alist))
0))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Process Registry ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc-registry (jdee-dbs-proc-set)
((target-process :initarg :target-process
:type jdee-dbs-proc
:documentation
"Process that currently has the debugger command focus."))
"Class of process registries.")
(defmethod jdee-dbs-proc-registry-set-target-proc ((this jdee-dbs-proc-registry) &optional id)
"Sets process specified by ID to be the target process. If ID is not specified, the first
registered process becomes the target process"
(let ((target-process
(if id
(let ((process (jdee-dbs-proc-set-get-proc this id)))
(if process
(if (jdee-dbs-proc-set-contains-p this process)
process
(message "Error: process %s is dead." id)
nil)
(message "Error: process %s does not exist." id)
nil))
(let ((existing-processes
(oref jdee-dbs-the-process-registry :proc-alist)))
(if existing-processes (cdr (nth 0 existing-processes)))))))
(when target-process
(oset this target-process target-process)
(set-window-configuration (oref target-process win-cfg)))
target-process))
(defvar jdee-dbs-the-process-registry
(jdee-dbs-proc-registry "Process Registry")
"The debuggee process registry.")
(defun jdee-dbs-get-target-process ()
(and jdee-dbs-the-process-registry
(slot-boundp jdee-dbs-the-process-registry :target-process)
(oref jdee-dbs-the-process-registry :target-process)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Process Morgue ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc-morgue (jdee-dbs-proc-set) ()
"Class of process morgues. A process morgue contains dead or dying processes.
Their carcasses must be kept around until the debugger stops sending messages
concerning them." )
(defmethod jdee-dbs-proc-morgue-bury-the-dead ((this jdee-dbs-proc-morgue))
(mapc
(lambda (dead-proc-assoc)
(let* ((dead-proc (cdr dead-proc-assoc))
(cli-buffer (if (slot-boundp dead-proc 'cli-buf) (oref dead-proc cli-buf)))
(msg-buffer (if (slot-boundp dead-proc 'msg-buf) (oref dead-proc msg-buf)))
(locals-buffer (if (slot-boundp dead-proc 'locals-buf) (oref dead-proc locals-buf)))
(threads-buffer (if (slot-boundp dead-proc 'threads-buf) (oref dead-proc threads-buf))))
(if cli-buffer (kill-buffer cli-buffer))
(if msg-buffer (kill-buffer msg-buffer))
(if locals-buffer (kill-buffer locals-buffer))
(if threads-buffer (kill-buffer threads-buffer))))
(oref this proc-alist))
(oset this proc-alist nil))
(defvar jdee-dbs-the-process-morgue
(jdee-dbs-proc-morgue "Process Morgue")
"The JDE process morgue. This morgue contains processes that are dead or
dying, for example, because they have been terminated by the user or the
debugger. Their corpses must be kept around until it is clear they are dead and
the debugger ceases sending messages concerning them.")
(defun jdee-dbs-get-process (id)
"Get the process whose id is ID. This function looks first in the process registry
and then in the process morgue for the process."
(let ((process
(jdee-dbs-proc-set-get-proc jdee-dbs-the-process-registry id)))
(if (not process)
(setq process (jdee-dbs-proc-set-get-proc jdee-dbs-the-process-morgue id)))
process))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Process State Info ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc-state-info ()
((state :initarg :state)
(reason :initarg :reason)
(thread-id :initarg :thread-id)
(thread-name :initarg :thread-name))
"Class of process state information objects.")
(defmethod jdee-dbs-proc-state-info-set ((this jdee-dbs-proc-state-info)
state reason thread-id thread-name)
(oset this reason reason)
(oset this state state)
(oset this thread-id thread-id)
(oset this thread-name thread-name))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Breakpoint Specification ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc-bpspec ()
((id :initarg :id
:type integer
:documentation
"Id assigned to this breakpoint by the debugger.")
(breakpoint :initarg :breakpoint
:type jdee-db-breakpoint
:documentation
"Instance of `jdee-db-breakpoint'.")
(resolved :initarg :resolved))
(:allow-nil-initform t)
"Class of breakpoint specifications. A breakpoint specification contains
process-specific information about a breakpoint")
;; Defines a class of containers for breakpoint specs.
;; Each container lists the process specs for breakpoints set in a
;; particular process.
(defun jdee-dbs-proc-bpspecs-add (bpspecs bpspec)
"Adds BPSPEC to BPSPECS, a process's breakpoint spec list."
(cons
(cons (oref bpspec id) bpspec)
bpspecs))
(defun jdee-dbs-proc-bpspecs-remove (bpspecs bpspec)
"Removes BPSPEC from BPSPECS"
(cl-remove-if (lambda (x)
(equal (car x) (oref bpspec id) ))
bpspecs))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Trace Request Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-trace-request ()
((id :initarg :id
:type integer
:documentation
"Trace request id")
(suspend-policy :initarg :suspend-policy
:type string
:initform "none"
:documentation
"Valid values are all (all threads), thread (current thread), or none")
(inclusion-filters :initarg :inclusion-filters
:type list
:documentation
"List of regular expressions specifying classes to include in trace.")
(exclusion-filters :initarg :exclusion-filters
:type list
:documentation
"List of regular expressions specifying classes to exclude from trace.")
(cancel-command :initarg :cancel-command
:type string
:documentation
"Name of command used to cancel this request.")
)
"Super class of trace requests."
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Trace Method Request Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-trace-methods-request (jdee-dbs-trace-request)
((trace-type :initarg :trace-type
:type string
:initform "entry"
:documentation
"Entry or exit.")
(thread-restriction :initarg :thread-restriction
:type string
:documentation
"Thread to trace."))
"Trace methods request."
)
(defmethod initialize-instance ((this jdee-dbs-trace-methods-request) &rest fields)
"Constructor for objects of `jdee-dbs-trace-methods-request' class."
(call-next-method)
(oset this cancel-command "cancel_trace_methods"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Trace Classes Request Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-trace-classes-request (jdee-dbs-trace-request)
((trace-type :initarg :trace-type
:type string
:initform "preparation"
:documentation
"Valid values are preparation or unloading."))
"Trace classes request."
)
(defmethod initialize-instance ((this jdee-dbs-trace-classes-request) &rest fields)
"Constructor for objects of `jdee-dbs-trace-classes-request' class."
(call-next-method)
(oset this cancel-command "cancel_trace_classes"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Trace Exceptions Request Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-trace-exceptions-request (jdee-dbs-trace-request)
((exception-class :initarg :exception-class
:type string
:documentation
"Class of exceptions to trace. Can be a wild card pattern.")
(trace-type :initarg :trace-type
:type string
:initform "both"
:documentation
"Valid values are caught, uncaught, or both."))
"Trace exceptions request."
)
(defmethod initialize-instance ((this jdee-dbs-trace-exceptions-request) &rest fields)
"Constructor for objects of `jdee-dbs-trace-exceptions-request' class."
(call-next-method)
(oset this cancel-command "clear"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Watch Field Request Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-watch-field-request (jdee-dbs-trace-request)
((watch-type :initarg :watch-type
:type string
:documentation
"Valid values are \"access\" and \"modification\".")
(object-class :initarg :object-class
:type string
:documentation
"Class of object to watch. Can be a wild card pattern.")
(field-name :initarg :field-name
:type string
:documentation
"Name of field to watch.")
(expression :initarg :expression
:type string
:documentation
"Boolean expression that must be satisfied to suspend execution.")
(object-id :initarg :object-id
:type string
:documentation
"Id of object to watch."))
"Watch field request."
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debuggee Process Status ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc-status (jdee-db-debuggee-status)
((startup-p :initarg :startupp
:type boolean
:initform nil
:documentation
"Non-nil if this process is in the startup state.")
(steppable-p :initarg :steppablep
:type boolean
:initform nil
:documentation
"Non-nil if this process can be single-stepped."))
"Status of process being debugged with JDEbug.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debuggee Process Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-proc (jdee-db-debuggee-app)
((id :initarg :id
:type integer
:documentation
"Id assigned by the JDE.")
(cli-socket :initarg :cli-socket
:type integer
:documentation
"Number of socket used by the process's command line interface.")
(cli-buf :initarg :cli-buf
:type buffer
:documentation
"Buffer for the process's command-line interface.")
(msg-buf :initarg :msf-buf
:type buffer
:documentation
"Buffer used to display debugger output for this process")
(threads-buf :initarg :threads-buf
:type buffer
:documentation
"Buffer used to display threads.")
(locals-buf :initarg :locals-buf
:type buffer
:documentation
"Buffer used to display local variables.")
(startupp :initarg :startupp
:type boolean
:initform nil
:documentation
"non-nil if this process is in the startup state.")
(suspendedp :initarg :suspendedp
:type boolean
:initform nil
:documentation
"non-nil if this process has been suspended by the debugger.")
(steppablep :initarg :steppablep
:type boolean
:initform nil
:documentation
"non-nil if this process can be single-stepped.")
(state-info :initarg :state-info
:type jdee-dbs-proc-state-info
:documentation
"Process state information.")
(stack :initarg :stack
:type list
:documentation
"Lists stack frames for thread of current step or breakpoint.")
(stack-ptr :initarg :stack-ptr
:type integer
:initform 0
:documentation
"Points to the current frame on the stack.")
(trace-req :initarg :trace-req
:type list
:documentation
"List of outstanding trace requests.")
(watch-req :initarg :watch-req
:type list
:documentation
"List of outstanding watch field requests.")
(object-refs :initarg :object-refs
:type list
:initform nil
:documentation
"IDs of debuggee objects currently referenced by the debugger.")
(bpspecs :initarg :bpspecs
:type list
:documentation
"Breakpoints set in this process.")
(last-cmd :initarg :last-cmd
:type jdee-dbs-cmd
:documentation
"Most recent command targeting this process.")
(win-cfg :initarg :win-cfg
:type window-configuration
:documentation
"Desired window configuration for this process.")
(attachedp :initarg :attachedp
:type boolean
:initform nil
:documentation
"Non-nil if the debugger was attached to this process."))
(:allow-nil-initform t)
"Class of debuggee processes.")
(defmethod initialize-instance ((this jdee-dbs-proc) &rest fields)
"Constructor for objects of `jdee-dbs-proc' class."
(call-next-method)
(if (not (slot-boundp this 'state-info))
(oset this state-info
(jdee-dbs-proc-state-info
(format "State Info %d" (oref this id)))))
(assert (slot-boundp this 'main-class))
(assert (slot-boundp this 'id))
(oset this msg-buf (get-buffer-create
(format "*Process %s(%d)*"
(oref this main-class)
(oref this id))))
(with-current-buffer (oref this msg-buf)
(erase-buffer)
(goto-char (point-min))
(insert
(format "*** Debugger Output for Process %s(%d) ***\n\n"
(oref this main-class)
(oref this id))))
(oset this locals-buf (get-buffer-create
(format "*%s(%d) Local Variables*"
(oref this main-class)
(oref this id))))
(oset this threads-buf (get-buffer-create
(format "*%s(%d) Threads*"
(oref this main-class)
(oref this id)))))
(defmethod jdee-dbs-proc-set-state ((this jdee-dbs-proc) state)
(let ((state-info (oref this state-info)))
(oset state-info state state)))
(defmethod jdee-dbs-proc-set-state-reason ((this jdee-dbs-proc) reason)
(let ((state-info (oref this state-info)))
(oset state-info reason reason)))
(defmethod jdee-dbs-proc-get-state ((this jdee-dbs-proc))
(oref (oref this state-info) state))
(defmethod jdee-dbs-proc-get-state-reason ((this jdee-dbs-proc))
(oref (oref this state-info) reason))
(defmethod jdee-dbs-proc-display-debug-message ((this jdee-dbs-proc)
message
&optional pop-buffer)
(let ((buffer
(oref this msg-buf)))
(if buffer
(save-excursion
(let ((source-window (selected-window))
(currbuffp (equal buffer (current-buffer)))
win)
(if (not currbuffp) (other-window -1))
(set-buffer buffer)
(goto-char (point-max))
(insert (concat message "\n"))
(goto-char (point-max))
(if (not currbuffp) (other-window 1))
(if (and pop-buffer (one-window-p))
(progn
(setq win (split-window source-window))
(set-window-buffer win buffer)))
(if pop-buffer
(progn
(set-window-buffer (next-window source-window) buffer)
(select-window source-window))
(if (not currbuffp)
(message message))))))))
(defmethod jdee-dbs-proc-move-to-morgue ((this jdee-dbs-proc))
"Moves this process from the process registry to the process morgue."
(jdee-dbs-proc-set-remove jdee-dbs-the-process-registry this)
(jdee-dbs-proc-set-add jdee-dbs-the-process-morgue this))
(defmethod jdee-dbs-proc-move-to-registry ((this jdee-dbs-proc))
"Moves this process from the registry to the morgue."
(jdee-dbs-proc-set-remove jdee-dbs-the-process-morgue this)
(jdee-dbs-proc-set-add jdee-dbs-the-process-registry this))
(defmethod jdee-dbs-proc-get-bpspec ((this jdee-dbs-proc) bp)
"Gets the process specification for a breakpoint. BP may be either
an instance of `jdee-db-breakpoint' or the debugger-assigned id
for the breakpoint."
(if (slot-boundp this 'bpspecs)
(let ((bpspecs (oref this bpspecs)))
(if (and (object-p bp) (jdee-db-breakpoint-p bp))
(let* ((jdee-id (oref bp id)))
(cdr
(cl-find-if
(lambda (assoc-x)
(let ((spec (cdr assoc-x)))
(equal (oref (oref spec breakpoint) id) jdee-id)))
bpspecs)))
(cdr (assoc bp bpspecs))))))
(defmethod jdee-dbs-proc-runnable-p ((this jdee-dbs-proc))
(or
(oref this startupp)
(oref this suspendedp)
(oref this steppablep)))
(defun jdee-dbs-target-process-runnable-p ()
(interactive)
(let ((target (jdee-dbs-get-target-process)))
(and target (jdee-dbs-proc-runnable-p target))))
(defun jdee-dbs-target-process-steppable-p ()
(interactive)
(let ((target (jdee-dbs-get-target-process)))
(and target (oref target steppablep))))
(defun jdee-dbs-display-debug-message (proc-id message)
(let ((process (jdee-dbs-get-process proc-id)))
(if process
(jdee-dbs-proc-display-debug-message process message)
(message message))))
(defvar jdee-dbs-proc-counter 0
"Process counter. Used to generate process IDs.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Java Object ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-java-obj ()
((jtype :initarg :jtype
:type string
:documentation
"Type of this object."))
"Superclass of Java objects.")
(defmethod jdee-dbs-java-obj-to-string ((this jdee-dbs-java-obj))
"")
(defclass jdee-dbs-java-primitive (jdee-dbs-java-obj)
((value :initarg :value
:type (or string number)
:documentation
"Value of this primitive object."))
"Class of Java primitives.")
(defmethod jdee-dbs-java-obj-to-string ((this jdee-dbs-java-primitive))
(format "%s" (oref this value)))
(defclass jdee-dbs-java-null (jdee-dbs-java-obj) ()
"Java null object.")
(defmethod initialize-instance ((this jdee-dbs-java-null) &rest fields)
"Constructor for run process command."
;; Call parent initializer.
(call-next-method)
(oset this jtype "null"))
(defmethod jdee-dbs-java-obj-to-string ((this jdee-dbs-java-null))
"null")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Java Variable ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-java-variable ()
((name :initarg :name
:type string
:documentation
"Name of this variable")
(jtype :initarg :jtype
:type string
:documentation
"Type of this variable.")
(value :initarg :value
:type jdee-dbs-java-obj
:documentation
"Value of this variable."))
"Class that defines the JDE's representation of a Java variable.")
(defmethod jdee-dbs-java-variable-to-string ((this jdee-dbs-java-variable))
(format "%s %s = %s"
(oref this jtype)
(oref this name)
(jdee-dbs-java-obj-to-string (oref this value))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Java Class Instance ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-java-class-instance (jdee-dbs-java-obj)
((id :initarg :id
:type integer
:documentation
"Id assigned to this object by the debugger.")
(gc-flag :initarg :gc-flag
:type boolean
:documentation
"t if this object has been garbage collected."))
"Instance of a Java class accessed via the debugger.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Java Array ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-java-array (jdee-dbs-java-class-instance)
((length :initarg :length
:type integer
:documentation
"Length of this array.")
(elements :initarg :elements
:type list
:initform nil
:documentation
"Elements of this array."))
"Class of Lisp objects representing instances of Java arrays.")
(defmethod jdee-dbs-java-obj-to-string ((this jdee-dbs-java-array))
(let ((str (format "<%s:%d%s> %d"
(if (slot-boundp this :jtype)
(oref this jtype))
(if (slot-boundp this :id)
(oref this id))
(if (slot-boundp this :gc-flag)
(if (oref this gc-flag) ":gc" ""))
(if (slot-boundp this :length)
(oref this length)
0)))
(elements (if (slot-boundp this :elements)
(oref this elements))))
(if elements
(let ((sep "\n |- "))
(concat
str
sep
(mapconcat
(lambda (element)
(jdee-dbs-java-obj-to-string element))
elements sep)))
str)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Java User-Defined Class Instance ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-java-udci (jdee-dbs-java-class-instance)
((fields :initarg :fields
:type list
:initform nil
:documentation
"Fields of this object."))
"Class of Lisp objects representing instances of user-defined Java classes.")
(defmethod jdee-dbs-java-udci-add-field ((this jdee-dbs-java-udci) field)
(oset this fields
(nconc (oref this fields) (list (cons (oref field name) field)))))
(defmethod jdee-dbs-java-obj-to-string ((this jdee-dbs-java-udci))
(let ((str (format "<%s:%d%s>"
(oref this jtype)
(oref this id)
(if (oref this gc-flag) ":gc" "")))
(fields (oref this fields)))
(if fields
(let ((sep "\n |- "))
(concat
str
sep
(mapconcat
(lambda (assoc-x)
(jdee-dbs-java-variable-to-string (cdr assoc-x)))
fields sep)))
str)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Debugger Class ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-debugger (jdee-db-debugger)
((comint-filter :initarg :comint-filter)
(started-p :initarg :started-p
:initform nil
:type boolean
:documentation
"True if debugger started successfully."))
"Class of JDEbug debuggers.")
(defmethod initialize-instance ((this jdee-dbs-debugger) &rest fields)
"Constructor for JDEbug."
(oset this :name "JDEbug")
(oset this :buffer-name "*JDEbug*"))
(defmethod jdee-dbs-debugger-register-process-filter ((debugger jdee-dbs-debugger) filter)
"Set the process filter for the debugger to FILTER."
(set-process-filter (oref debugger process) filter))
(defmethod jdee-dbs-debugger-display-message ((debugger jdee-dbs-debugger) message)
"Displays message in the debugger process buffer."
(let ((buffer
(oref debugger buffer)))
(if buffer
(with-current-buffer buffer
(goto-char (process-mark (get-buffer-process buffer)))
(insert-before-markers (concat message "\n"))))))
(defmethod jdee-dbs-debugger-start ((this jdee-dbs-debugger))
"Starts the debugger."
(if (jdee-dbs-debugger-running-p)
(progn
(message "An instance of the debugger is running.")
(pop-to-buffer (jdee-dbs-get-app-buffer-name))
nil)
(let* ((debugger-buffer-name
(oref this buffer-name))
(debugger-buffer
(let ((old-buf (get-buffer debugger-buffer-name)))
(if old-buf (kill-buffer old-buf))
(get-buffer-create debugger-buffer-name)))
(win32-p (eq system-type 'windows-nt))
(w32-quote-process-args ?\")
(win32-quote-process-args ?\") ;; XEmacs
(source-directory default-directory)
(working-directory
(if (and
jdee-run-working-directory
(not (string= jdee-run-working-directory "")))
(jdee-normalize-path 'jdee-run-working-directory)
source-directory))
(vm (oref (jdee-run-get-vm) :path))
(vm-args
(let (args)
(setq args
(append
args
(list
"-classpath"
(jdee-build-classpath
(list
jdee-server-dir
(if (jdee-bug-vm-includes-jpda-p)
(jdee-get-tools-jar)
(expand-file-name
"lib/jpda.jar" (jdee-normalize-path
'jdee-bug-jpda-directory))))))))
(if jdee-bug-debug
(setq args
(append args
(list "-Xdebug"
"-Xnoagent"
"-Xrunjdwp:transport=dt_socket,address=2112,server=y,suspend=n"))))
(setq args (append args (list "jde.debugger.Main")))
args))
(command-string
(concat
vm " "
(jdee-run-make-arg-string
vm-args)
"\n\n"))
debugger-process)
(run-hook-with-args 'jdee-dbs-debugger-hook t)
(oset this started-p nil)
(setq jdee-dbs-debugger-output nil)
(with-current-buffer debugger-buffer
(erase-buffer)
;; Set working directory
(if (and
(file-exists-p working-directory)
(file-directory-p working-directory))
(cd working-directory)
(error "Invalid working directory: %s" working-directory))
(insert (concat "cd " working-directory "\n"))
(insert command-string)
(jdee-run-mode))
(save-w32-show-window
(comint-exec debugger-buffer debugger-buffer-name vm nil vm-args)
(setq debugger-process (get-process debugger-buffer-name))
(oset this process debugger-process)
(oset this buffer debugger-buffer)
(oset this comint-filter (process-filter debugger-process))
(jdee-dbs-debugger-register-process-filter this 'jdee-dbs-asynch-output-listener)
)
(cd source-directory)
(bury-buffer debugger-buffer)
(setq jdee-dbs-proc-counter 0)
(setq jdee-dbs-cmd-counter 0)
;; Wait for response from debugger
(if (not (accept-process-output debugger-process jdee-bug-debugger-command-timeout 0))
(progn
(message "Error: debugger failed to start.")
nil)
(oref this started-p))
;; Create a process registry for registering debuggee processes
;; started by the debugger.
(setq jdee-dbs-the-process-registry
(jdee-dbs-proc-registry "Process Registry"))
;; Create a registry for debuggee processes that have died but
;; still may be getting messages from the debugger.
(setq jdee-dbs-the-process-morgue
(jdee-dbs-proc-morgue "Process Morgue")))))
(defmethod jdee-dbs-debugger-quit ((debugger jdee-dbs-debugger))
(jdee-dbs-do-command -1 "quit")
(run-hook-with-args 'jdee-dbs-debugger-hook nil)
(slot-makeunbound debugger :process)
(slot-makeunbound debugger :buffer)
(slot-makeunbound debugger :comint-filter))
(defun jdee-dbs-debugger-running-p ()
"*Returns t if the debugger is running."
(and (slot-boundp jdee-dbs-the-debugger 'buffer)
(oref jdee-dbs-the-debugger started-p)
(comint-check-proc (oref jdee-dbs-the-debugger buffer))))
(defmethod jdee-db-debugger-launch ((this jdee-dbs-debugger) main-class)
"Launch the application whose main class is MAIN-CLASS in debug mode."
)
(defvar jdee-dbs-the-debugger (jdee-dbs-debugger "JDEbug")
"The debugger.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; JDEbug Command Line Commands ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-dbs-cmd (jdee-db-cmd)
((process :initarg :process
:type jdee-dbs-proc
:documentation
"Process that this command targets.")
(id :initarg :id
:type integer
:documentation
"Command id.")