-
Notifications
You must be signed in to change notification settings - Fork 55
/
jdee-jdb.el
1745 lines (1467 loc) · 65.8 KB
/
jdee-jdb.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-jdb.el -- Debugger mode for jdb.
;; Author: Paul Kinnucan <paulk@mathworks.com>x
;; 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 JavaSoft's Java
;; Development Kit (JDK).
;;; Code:
(require 'jdee-db)
(require 'semantic/util-modes);; semantic-add-minor-mode
;; FIXME: refactor
(defvar jdee-debugger);; jde
(declare-function jdee-java-major-version "jdee" ())
(declare-function jdee-java-minor-version "jdee" ())
(declare-function jdee-get-jdk-prog "jdee" (progname))
(declare-function jdee-find-jdee-doc-directory "jdee" ())
(declare-function jdee-convert-cygwin-path "jdee" (path &optional separator))
;; Thanks to "David J. Biesack" <sasdjb@unx.sas.com> for this function
;; and its use in jdee-db-marker-filter.
;; Amended by "Patrick J. McNerthney" <pat@mcnerthney.com> to allow
;; package names to begin with underscores.
(defun jdee-jdb-make-qualified-class-name-regexp (class)
"Constructs a regular expression to extract a qualified class name from a jdb
breakpoint message."
(concat "\\(\\(\\(\\(\\w\\|[_]\\)*\\.\\)*\\)" class "\\)\\(\\b\\|\\$\\)"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; jdb Debugger Commands ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Launch debuggee command
(defclass jdee-jdb-cmd-launch (jdee-db-cmd-launch) ()
"Asks jdb to launch a debuggee process.")
(defmethod jdee-db-cmd-launch-buffer-name ((this jdee-jdb-cmd-launch))
"Return the name of the buffer for this process. Descendant
classes should override this method to create a name that is appropriate
for the process being launched, e.g., an applet or application." nil)
(defmethod jdee-db-cmd-launch-cmd-path ((this jdee-jdb-cmd-launch))
"Return the path of the command to be used to launch the process. Descendant
classes should override this method to return a path appropriate to
the command to be used to launch the debuggee process, e.g., jdb or
appletviewer." nil)
(defmethod jdee-db-cmd-launch-startup-cmds ((this jdee-jdb-cmd-launch))
"Add commands to debugger's initial command queue. Derived classes
should override this method to specify commands that should be
executed immediately after the debugger starts, e.g., an initial
step command." nil)
(defmethod jdee-db-cmd-init ((this jdee-jdb-cmd-launch))
"The debugger invokes this method before executing the launch
command. Launch the debuggee process."
(let ((debugger (oref this debugger)))
(if (or
(not (slot-boundp debugger 'buffer))
(not (oref debugger :buffer))
(not (comint-check-proc (oref debugger :buffer))))
(let* ((debuggee
(oref debugger debuggee))
(source-directory default-directory)
(working-directory
(jdee-db-debugger-get-working-dir debugger))
(prog-args (jdee-db-debugger-get-prog-args debugger))
(cmd-path (jdee-db-cmd-launch-cmd-path this))
(command-string
(concat
cmd-path " "
(jdee-run-make-arg-string prog-args) "\n\n")))
(oset debugger :buffer-name (jdee-db-cmd-launch-buffer-name this))
(oset debugger :buffer (get-buffer-create (oref debugger :buffer-name)))
(jdee-db-cmd-launch-startup-cmds this)
(oset debugger :path cmd-path)
(jdee-db-jdb-start debugger prog-args command-string)
(let ((debuggee-status (oref debuggee status)))
(oset debuggee-status running-p t)
(oset debuggee-status stopped-p t)))
(progn
(message "An instance of %s is running." (oref this :buffer-name))
(pop-to-buffer (oref this :buffer-name))))))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-launch))
"Returns nil because jdb launches the debuggee application automatically
when it is started." nil)
;; Launch application command
(defclass jdee-jdb-cmd-launch-app (jdee-jdb-cmd-launch
jdee-db-cmd-launch-app) ()
"Asks jdb to launch the debuggee application.")
(defmethod initialize-instance ((this jdee-jdb-cmd-launch-app) &rest fields)
(call-next-method)
(oset this name "launch application in jdb debug mode"))
(defmethod jdee-db-cmd-launch-cmd-path ((this jdee-jdb-cmd-launch-app))
"Return the path of the jdb command."
(let* ((debugger (oref this :debugger)))
(oref debugger :path)))
(defmethod jdee-db-cmd-launch-buffer-name ((this jdee-jdb-cmd-launch-app))
(let* ((debugger (oref this :debugger))
(debuggee (oref debugger :debuggee))
(main-class (oref debuggee :main-class)))
(concat "*debug" main-class "*")))
(defmethod jdee-db-cmd-launch-startup-cmds ((this jdee-jdb-cmd-launch-app))
"If `jdee-db-initial-step-p' is nonnil, add a step command to the
debugger's startup command queue."
(if jdee-db-initial-step-p
(let* ((debugger (oref this debugger))
(step-cmd (oref (oref debugger cmd-set) step-into)))
(oset debugger next-cmd
(append (oref debugger next-cmd) (list step-cmd))))))
;; Launch applet command
(defclass jdee-jdb-cmd-launch-applet (jdee-jdb-cmd-launch
jdee-db-cmd-launch-applet) ()
"Asks jdb to launch the debuggee applet.")
(defmethod initialize-instance ((this jdee-jdb-cmd-launch-applet) &rest fields)
(call-next-method)
(oset this name "launch applet in jdb debug mode"))
(defmethod jdee-db-cmd-launch-cmd-path ((this jdee-jdb-cmd-launch-applet))
"Return the path of the command to be used to launch the process. Descendant
classes should override this method to return a path appropriate to
the command to be used to launch the debuggee process, e.g., jdb or
appletviewer."
(let* ((debugger (oref this :debugger))
(jdb-path (oref debugger :path))
(jdb-dir (file-name-directory jdb-path)))
(expand-file-name "appletviewer" jdb-dir)))
(defmethod jdee-db-cmd-launch-buffer-name ((this jdee-jdb-cmd-launch-applet))
(let* ((debugger (oref this :debugger))
(debuggee (oref debugger :debuggee))
(doc (oref debuggee :doc)))
(concat "*debug" (file-name-nondirectory doc) "*")))
(defmethod jdee-db-cmd-launch-startup-cmds ((this jdee-jdb-cmd-launch-applet))
"If `jdee-db-initial-step-p' is nonnil, add a run command followed by a
step command to the debugger's startup command queue."
(if jdee-db-initial-step-p
(let* ((debugger (oref this debugger))
(cmd-set (oref debugger cmd-set))
(run-cmd (oref cmd-set run))
(step-cmd (oref cmd-set step-into)))
(oset debugger next-cmd
(append
(oref debugger next-cmd)
(list run-cmd)
(list step-cmd))))))
;; Run command
(defclass jdee-jdb-cmd-run (jdee-db-cmd) ()
"Asks jdb to start the debuggee application.")
(defmethod initialize-instance ((this jdee-jdb-cmd-run) &rest fields)
(call-next-method)
(oset this name "run"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-run))
"Creates command line for jdb run command."
"run")
;; Cont command
(defclass jdee-jdb-cmd-cont (jdee-db-cmd) ()
"Asks jdb to continue the debuggee application from its current
stopping point.")
(defmethod initialize-instance ((this jdee-jdb-cmd-cont) &rest fields)
(call-next-method)
(oset this name "cont"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-cont))
"Creates command line for jdb cont command."
"cont")
;; Quit command
(defclass jdee-jdb-cmd-quit (jdee-db-cmd) ()
"Quit debugging the current application.")
(defmethod initialize-instance ((this jdee-jdb-cmd-quit) &rest fields)
(call-next-method)
(oset this name "quit"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-quit))
"Creates command line for jdb quit command."
"quit")
;; Step-over command
(defclass jdee-jdb-cmd-step-over (jdee-db-cmd) ()
"Step to the next line in the current frame.")
(defmethod initialize-instance ((this jdee-jdb-cmd-step-over) &rest fields)
(call-next-method)
(oset this name "next"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-step-over))
"Creates command line for jdb step-over command."
"next")
;; Step-into command
(defclass jdee-jdb-cmd-step-into (jdee-db-cmd) ()
"Step to the next line in the current program.")
(defmethod initialize-instance ((this jdee-jdb-cmd-step-into) &rest fields)
(call-next-method)
(oset this name "step"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-step-into))
"Creates command line for jdb step-into command."
"step")
;; Step-out command
(defclass jdee-jdb-cmd-step-out (jdee-db-cmd) ()
"Continue to the end of the current method.")
(defmethod initialize-instance ((this jdee-jdb-cmd-step-out) &rest fields)
(call-next-method)
(oset this name "step up"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-step-out))
"Creates command line for jdb step-out command."
"step up")
;; Up stack command
(defclass jdee-jdb-cmd-up (jdee-db-cmd) ()
"Move up one stack frame.")
(defmethod initialize-instance ((this jdee-jdb-cmd-up) &rest fields)
(call-next-method)
(oset this name "up"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-up))
"Creates command line for jdb up command."
"up")
(defmethod jdee-db-cmd-notify-response ((this jdee-jdb-cmd-up) response)
"Invoked when the debugger responds to the command. RESPONSE
is the response. This method invokes the jdb where
command in order to position the debug pointer at the
current stack location."
;; (jdee-debug-where)
(let* ((jdb (oref this debugger))
(cmds (oref jdb cmd-set))
(cmd (oref cmds where)))
(jdee-db-exec-cmd jdb cmd)))
;; Down stack command
(defclass jdee-jdb-cmd-down (jdee-db-cmd) ()
"Move down one stack frame.")
(defmethod initialize-instance ((this jdee-jdb-cmd-down) &rest fields)
(call-next-method)
(oset this name "down"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-down))
"Creates command line for jdb down command."
"down")
(defmethod jdee-db-cmd-notify-response ((this jdee-jdb-cmd-down) response)
"Invoked when the debugger responds to the command. RESPONSE
is the response. This method invokes the jdb where
command in order to position the debug pointer at the
current stack location."
;;(jdee-debug-where)
(let* ((jdb (oref this debugger))
(cmds (oref jdb cmd-set))
(cmd (oref cmds where)))
(jdee-db-exec-cmd jdb cmd)))
;; Where stack command
(defclass jdee-jdb-cmd-where (jdee-db-cmd) ()
"Point to current location on the stack.")
(defmethod initialize-instance ((this jdee-jdb-cmd-where) &rest fields)
(call-next-method)
(oset this name "where"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-where))
"Creates command line for jdb where command."
"where")
(defmethod jdee-db-cmd-notify-response ((this jdee-jdb-cmd-where) output)
"Processes the output of the jdb where
command, which lists the current stack. An example of the output
is
[1] jmath.LinearSystem$InnerClass.print (LinearSystem.java:36)
[2] jmath.LinearSystem.<init> (LinearSystem.java:52)
[3] jmath.Test.main (Test.java:38)
This method positions the source line cursor at the position that
matches the current location of the debugger in the program's
stack (set by the jdb up and down stack commands)."
(let* ((jdb (oref this debugger))
(debuggee (oref jdb debuggee)))
;; if the stack depth is not set default to 1
(if (string-equal "" (oref debuggee :stack-depth))
(oset debuggee :stack-depth "1"))
(if (string-match
(concat "^ \\["
(oref debuggee :stack-depth)
"\\] .*(\\([^\$\n]*\\).*:\\([0-9]*[^[:digit:]]?[0-9]+\\))")
output)
(let ((marker (match-string 0 output))
(class (match-string 1 output))
(line-no (jdee-jdb-string-to-int (match-string 2 output)))
(package ""))
(if (equal ".java" (substring class -5))
(setq class (substring class 0 -5)))
;; Extract package path from input.
(let ((case-fold-search nil)) ;; Make sure search is case-sensitive
(and (string-match (jdee-jdb-make-qualified-class-name-regexp class) marker)
(setq package
(substring marker (match-beginning 2) (match-end 2)))))
(jdee-db-set-debug-cursor
(if package (concat package class) class)
(concat class ".java") line-no)))
output))
;; Set Breakpoint command
(defclass jdee-jdb-cmd-set-breakpoint (jdee-db-cmd-breakpoint) ()
"Asks jdb to set the breakpoint specified by the
breakpoint field.")
(defmethod initialize-instance ((this jdee-jdb-cmd-set-breakpoint) &rest fields)
(call-next-method)
(oset this name "stop at"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-set-breakpoint))
"Creates command line for jdb set breakpoint command."
(let* ((bps (oref this breakpoints))
(bp (car bps)))
(format "stop at %s:%d"
(oref bp class)
(jdee-db-breakpoint-get-line bp))))
(defmethod jdee-db-cmd-notify-response ((this jdee-jdb-cmd-set-breakpoint) output)
"Called when the debugger responds to the last set-breakpoint
command. Invokes `jdee-db-mark-breakpoint-requested' on the breakpoint and
updates the breakpoint to `requested' status. Removes the breakpoint
from the command's breakpoint list. If the list contains more
breakpoints, this method reissues the command on the next breakpoint
on the list."
;; (message "set-bp resp <<%s>>" output)
(if (or
(string-match "Deferring breakpoint" output)
(string-match "Set breakpoint" output)
(string-match "Unable to set" output))
(let* ((bps (oref this breakpoints))
(bp (car bps)) file line)
(if (not (null bp))
(progn
(setq file (oref bp file))
(setq line (jdee-db-breakpoint-get-line bp))
(if (string-match "Unable to set breakpoint" output)
(jdee-db-delete-breakpoint bp)
(if (string-match "Unable to set deferred breakpoint" output)
(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 (list bp))
(jdee-db-exec-cmd debugger bp-cmd))
(jdee-db-delete-breakpoint bp))
(if (string-match "Deferring breakpoint" output)
(progn
(oset bp status 'requested)
(jdee-db-mark-breakpoint-requested file line))
(if (string-match "Set breakpoint" output)
(progn
(oset bp status 'active)
(jdee-db-mark-breakpoint-active file line))))))
(setq bps (cdr bps))
(oset this breakpoints bps)
(if bps
(let ((jdb (oref this debugger)))
(jdee-db-exec-cmd jdb this))))))))
;; Clear Breakpoint command
(defclass jdee-jdb-cmd-clear-breakpoint (jdee-db-cmd-breakpoint) ()
"Asks jdb to clear the breakpoint specified by the
breakpoint field.")
(defmethod initialize-instance ((this jdee-jdb-cmd-clear-breakpoint) &rest fields)
(call-next-method)
(oset this name "clear"))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-clear-breakpoint))
"Creates command line for jdb clear breakpoint command."
(let* ((bps (oref this breakpoints))
(bp (car bps)))
(format "clear %s:%d"
(oref bp class)
(jdee-db-breakpoint-get-line bp))))
(defmethod jdee-db-cmd-notify-response ((this jdee-jdb-cmd-clear-breakpoint) output)
"Called when the debugger responds to the last clear-breakpoint command.
Removes the breakpoint from the command's breakpoint list. If the list contains
more breakpoints, this method reissues the clear command on the next breakpoint
on the list."
(let* ((bps (oref this breakpoints))
(bp (car bps)))
(jdee-db-delete-breakpoint bp)
(setq bps (cdr bps))
(oset this breakpoints bps)
(if bps
(let ((jdb (oref this debugger)))
(jdee-db-exec-cmd jdb this)))))
;; Print command
(defvar jdee-jdb-cmd-print-history nil)
(defclass jdee-jdb-cmd-print (jdee-db-cmd)
((expr :initarg :expr
:type string
:initform ""
:documentation
"Expression passed to jdb"))
"Asks jdb to print value of expression at point")
(defmethod initialize-instance ((this jdee-jdb-cmd-print) &rest fields)
(call-next-method)
(oset this name "print")
(oset this expr ""))
(defmethod jdee-db-cmd-init ((this jdee-jdb-cmd-print))
"The debugger invokes this method before executing the
command."
(oset this expr (read-from-minibuffer "expr: " (thing-at-point 'word)
nil nil 'jdee-jdb-cmd-print-history)))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-print))
"Creates a command line for jdb print command."
(format "%s %s"
(oref this name)
(oref this expr)))
;; Dump command
(defclass jdee-jdb-cmd-dump (jdee-jdb-cmd-print) ()
"Asks jdb to print all object information of the expression at point")
(defmethod initialize-instance ((this jdee-jdb-cmd-dump) &rest fields)
(call-next-method)
(oset this name "dump"))
;; Eval command
(defclass jdee-jdb-cmd-eval (jdee-jdb-cmd-print) ()
"Ask jdb to evaluate the expression(Same as the print command)")
(defmethod initialize-instance ((this jdee-jdb-cmd-eval) &rest fields)
(call-next-method)
(oset this name "eval"))
;; Set command
(defclass jdee-jdb-cmd-set-var (jdee-jdb-cmd-print)
((value :initarg :value
:type string
:initform "null"
:document
"Value to assign to the variable"))
"Ask jdb to assign new value to a field/variable/array element")
(defmethod initialize-instance ((this jdee-jdb-cmd-set-var) &rest fields)
(call-next-method)
(oset this name "set"))
(defmethod jdee-db-cmd-init ((this jdee-jdb-cmd-set-var))
"The debugger invokes this method before executing the
command."
(oset this expr (read-from-minibuffer "variable: " (thing-at-point 'word)
nil nil 'jdee-jdb-cmd-print-history))
(oset this value (read-from-minibuffer "value: " nil
nil nil '(null))))
(defmethod jdee-db-cmd-make-command-line ((this jdee-jdb-cmd-set-var))
"Creates a command line for jdb print command."
(format "%s %s = %s"
(oref this name)
(oref this expr)
(oref this value)))
;; Locals commands
(defclass jdee-jdb-cmd-locals (jdee-jdb-cmd-print) ()
"Ask jdb to print al local variables in current stack frame")
(defmethod initialize-instance ((this jdee-jdb-cmd-locals) &rest fields)
(call-next-method)
(oset this name "locals"))
(defmethod jdee-db-cmd-init ((this jdee-jdb-cmd-locals))
"The debugger invokes this method before executing the
command."
(oset this expr ""))
;; jdb Command Set
(defclass jdee-jdb-cmd-set (jdee-db-cmd-set)
((print :initarg :print
:type jdee-jdb-cmd-print
:documentation
"Asks jdb to print the value of expression at point")
(dump :initarg :dump
:type jdee-jdb-cmd-dump
:documentation
"Ask jdb to print all object information from the
expression at poing")
(eval :initarg :eval
:type jdee-jdb-cmd-eval
:documentation
"Ask jdb to evaluate the expression at point")
(set-var :initarg :set-var
:type jdee-jdb-cmd-set-var
:documentation
"Ask jdb to assign a new value to the expression at point")
(locals :initarg :locals
:type jdee-jdb-cmd-locals
:documentation
"Ask jdb to print all local variables in current stack frame")
)
"Set of debugger commands implemented by jdb.")
(defmethod initialize-instance ((this jdee-jdb-cmd-set) &rest fields)
"Construct jdb command set."
(call-next-method)
(let ((jdb (oref this debugger)))
(oset this launch-app
(jdee-jdb-cmd-launch-app "launch" :debugger jdb))
(oset this launch-applet
(jdee-jdb-cmd-launch-applet "launch" :debugger jdb))
(oset this run
(jdee-jdb-cmd-run "run" :debugger jdb))
(oset this cont
(jdee-jdb-cmd-cont "cont" :debugger jdb))
(oset this quit
(jdee-jdb-cmd-quit "jdb quit" :debugger jdb))
(oset this step-over
(jdee-jdb-cmd-step-over "jdb step-over cmd" :debugger jdb))
(oset this step-into
(jdee-jdb-cmd-step-into "jdb step-into cmd" :debugger jdb))
(oset this step-out
(jdee-jdb-cmd-step-out "jdb step-out cmd" :debugger jdb))
(oset this up
(jdee-jdb-cmd-up "jdb up cmd" :debugger jdb))
(oset this down
(jdee-jdb-cmd-down "jdb down cmd" :debugger jdb))
(oset this where
(jdee-jdb-cmd-where "jdb where cmd" :debugger jdb))
(oset this set-bp
(jdee-jdb-cmd-set-breakpoint "jdb set breakpoint" :debugger jdb))
(oset this clear-bp
(jdee-jdb-cmd-clear-breakpoint "jdb clear breakpoint" :debugger jdb))
(oset this print
(jdee-jdb-cmd-print "jdb print cmd" :debugger jdb))
(oset this dump
(jdee-jdb-cmd-dump "jdb dump cmd" :debugger jdb))
(oset this eval
(jdee-jdb-cmd-eval "jdb eval cmd" :debugger jdb))
(oset this set-var
(jdee-jdb-cmd-set-var "jdb set cmd" :debugger jdb))
(oset this locals
(jdee-jdb-cmd-locals "jdb locals cmd" :debugger jdb))
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; jdb Breakpoint Listener ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-jdb-breakpoint-listener (jdee-db-listener)
((marker-regexp :initarg :marker-regexp
:type string
:documentation
"Regular expression for parsing breakpoint messages.")
(class-index :initarg :class-index
:type integer
:initform 3
:documentation
"Index of class name parsed by marker-regex")
(line-index :initarg :line-index
:type integer
:initform 5
:documentation
"Index of line number parsed by marker-regex")
(noline-regexp :initarg :noline-regexp
:type string
:documentation
"Regular expression for parsing breakpoint messages without line numbers.")
;; There's no guarantee that Emacs will hand the filter the entire
;; marker at once; it could be broken up across several strings. We
;; might even receive a big chunk with several markers in it. If we
;; receive a chunk of text which looks like it might contain the
;; beginning of a marker, we save it here between calls to the
;; filter.
(marker-acc :initarg :marker-acc
:type string
:initform ""
:documentation
"Debug output accumulator")
)
"Handles jdb breakpoint events.")
(defmethod initialize-instance ((this jdee-jdb-breakpoint-listener) &rest fields)
"Construct breakpoint listener."
(call-next-method)
;; Regular expression used to find a jdb breakpoint position marker.
;; The regular expression must have two subexpressions. The first matches
;; the name of the class in which the breakpoint occurs; the second, the
;; line number at which the breakpoint occurs. The default expression
;; matches breakpoint messages emitted by jdb. You may need to change
;; the expression to accommodate other debuggers."
(oset
this
:marker-regexp
"^.*: thread=.*, \\(\\(.*[.]\\)*\\)\\([^\$]*\\)\\(\$.*\\)*[.].+(), line=\\([0-9,. ]*\\),")
;; Regular expression to match a breakpoint message that lacks a line
;; number because the breakpoint occurs in a class compiled without deug
;; information.
(oset
this
:noline-regexp
"^Breakpoint hit: .*(pc \\([0-9]*\\))"))
(defmethod jdee-jdb-fixup-output ((this jdee-jdb-breakpoint-listener))
;; This is a hack to accommodate reorder of message chunks
;; on Solaris at debugger startup.
(if (string-match "running ...\n" (oref this :marker-acc))
(oset this :marker-acc
(concat "running ...\n"
(substring (oref this :marker-acc) 0 (match-beginning 0))
(substring (oref this :marker-acc) (match-end 0)))))
;; This is a hack to fix reordering of message chunks on Windows 2000
;; The problem is the debugger prompt - the thread name with the stack
;; depth (eg main[1]) - sometimes shows up in the middle of the output
;; from the command sent to the debugger.
;; This seems to show up most often with step commands.
;;(message "checking string %s" (oref jdb :marker-acc))
(if (string-match "^.*: \\([-a-zA-Z0-9_$]+\\[[0-9]+\\] \\)thread="
(oref this :marker-acc))
(oset this :marker-acc
(concat (match-string 1 (oref this :marker-acc))
(substring (oref this :marker-acc) 0 (match-beginning 1))
(substring (oref this :marker-acc) (match-end 1)))))
;; (message "fixed string is %s" jdee-db-marker-acc)
)
(defmethod jdee-jdb-set-breakpoint-listener ((this jdee-jdb-breakpoint-listener) output)
"Listens for set breakpoint messages."
(let ((msgs (split-string output "\n")))
(loop for msg in msgs do
(if (and (string-match
"^.*Set .*breakpoint \\(.*\\):\\([0-9]+\\)"
msg)
(not (string-match "Unable to set.*" msg)))
(let* ((class (substring
msg
(match-beginning 1)
(match-end 1)))
(line (string-to-number
(substring
msg
(match-beginning 2)
(match-end 2))))
(source-buffer (jdee-db-find-class-source class))
(path (buffer-file-name source-buffer))
(bp (jdee-db-find-breakpoint path line)))
(oset bp status 'active)
(jdee-db-mark-breakpoint-active path line))))))
(defmethod jdee-db-listener-filter-output ((this jdee-jdb-breakpoint-listener) input)
"Filters the output of the debugger."
(let ((jdb (oref this debugger))
(output ""))
;; Accumulate next chunk of debugger output.
(oset this
:marker-acc (concat
(oref this :marker-acc)
(string-make-unibyte input)))
;; (message (format "<acc-start>%s<acc-end>" (oref this :marker-acc)))
(jdee-jdb-fixup-output this)
(let* ((marker-regexp (oref this :marker-regexp))
(marker-regexp-class-index (oref this :class-index))
(marker-regexp-line-index (oref this :line-index)))
;; (message (concat "jdb output:" input))
;; (message (concat "acc = " jdee-db-marker-acc))
;; Process all the complete markers in this chunk.
(if (string-match marker-regexp (oref this :marker-acc))
;; Extract the frame position from the marker.
(let ((premarker (substring
(oref this :marker-acc) 0 (match-beginning 0)))
(marker (substring (oref this :marker-acc)
(match-beginning 0) (match-end 0)))
(rest (substring (oref this :marker-acc) (match-end 0)))
(class (substring
(oref this :marker-acc)
(match-beginning marker-regexp-class-index)
(match-end marker-regexp-class-index)))
(line-no (jdee-jdb-string-to-int
(substring
(oref this :marker-acc)
(match-beginning marker-regexp-line-index)
(match-end marker-regexp-line-index))))
(package ""))
;; Extract package path from input.
(let ((case-fold-search nil)) ;; Make sure search is case-sensitive
(and (string-match (jdee-jdb-make-qualified-class-name-regexp class) marker)
(setq package
(substring marker (match-beginning 2) (match-end 2))))
;; (message "jdee-db package: %s. marker = %s" jdee-db-last-package marker)
;;(message "case-fold-search = %s" (if case-fold-search "true" "false"))
)
;; Insert debugger output into debugger buffer.
(setq output (concat premarker marker))
;; Set the accumulator to the remaining text.
(oset this :marker-acc rest)
(jdee-db-set-debug-cursor
(concat package class) (concat class ".java") line-no)
(let* ((debuggee (oref jdb debuggee))
(status (oref debuggee status)))
(oset status stopped-p t)))))
;; Handle case where there is no line number info in current class.
(if (string-match (oref this noline-regexp) (oref this marker-acc))
(let ((premarker (substring
(oref this :marker-acc) 0 (match-beginning 0)))
(marker (substring (oref this :marker-acc)
(match-beginning 0) (match-end 0)))
(pc (substring (oref this :marker-acc)
(match-beginning 1) (match-end 1)))
(rest (substring (oref this :marker-acc) (match-end 0))))
(setq output (concat premarker marker))
(oset this :marker-acc rest)))
;; Does the remaining text look like it might end with the
;; beginning of another marker? If it does, then keep it in
;; marker-acc until we receive the rest of it. Since we
;; know the full marker regexp above failed, it's pretty simple to
;; test for marker starts.
(if (string-match "\\(^Breakpoint hit:\\)\\|\\(^Step completed:\\)"
(oref this :marker-acc))
(progn
;; Everything before the potential marker start can be output.
(setq output (concat output
(substring (oref this :marker-acc)
0 (match-beginning 0))))
;; Everything after, we save, to combine with later input.
(oset this
:marker-acc
(substring (oref this :marker-acc) (match-beginning 0))))
(setq output
(concat output (oref this :marker-acc)))
(oset this :marker-acc ""))
(jdee-jdb-set-breakpoint-listener this output)
output))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; jdb Stack Listener ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-jdb-stack-listener (jdee-db-listener)
((stack-depth :initarg :stack-depth
:type string
:initform ""
:documentation
"Stack depth."))
"Listens for changes in the current stack frame.")
;; Thanks to Michael Ernst <mernst@cs.washington.edu> for the following
;; stack-related code.
;;
;; Extract the index of the current stack frame from the jdb prompt, where
;; the prompt is of the form
;;
;; thread[stack_index]
;;
;; e.g.,
;;
;; main[1]
;;
;; The user can move the debugger up and down the stack via the up and
;; down commands. The debugger indicates the current location by the
;; stack index portion of its prompt.
(defmethod jdee-db-listener-filter-output ((this jdee-jdb-stack-listener) output)
(let* ((jdb (oref this debugger))
(debuggee (oref jdb debuggee)))
(if (string-match "^[-a-zA-Z0-9_$ -]+\\[\\([0-9]*,?[0-9]+\\)\\] " output)
(oset debuggee :stack-depth (match-string 1 output)))
output))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; jdb Application Debuggee ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-jdb-debuggee-app (jdee-db-debuggee-app) ()
"Application process being debugged with jdb.")
(defmethod initialize-instance ((this jdee-jdb-debuggee-app) &rest fields)
"Constructs an instance of a jdb debuggee."
(call-next-method)
(oset this status (jdee-db-debuggee-status "jdb status")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; jdb Applet Debuggee ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-jdb-debuggee-applet (jdee-db-debuggee-applet) ()
"Application process being debugged with jdb.")
(defmethod initialize-instance ((this jdee-jdb-debuggee-applet) &rest fields)
"Constructs an instance of a jdb debuggee."
(call-next-method)
(oset this status (jdee-db-debuggee-status "jdb status")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Class of JDE Debuggers based on jdb. ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defclass jdee-db-jdb (jdee-db-debugger)
((exec-name :initarg :exec-name
:type string
:initform "jdb"
:documentation
"Name of the jdb executable.")
(path :initarg :path
:type string
:initform "jdb"
:documentation
"Path of the jdb executable.")
(bp-listener :initarg :bp-listener
:type jdee-jdb-breakpoint-listener
:documentation "Breakpoint listener."))
(:allow-nil-initform t)
"Class of generic jdb debuggers")
(defmethod initialize-instance ((this jdee-db-jdb) &rest fields)
"Constructor for generic jdb debugger."
(call-next-method)
(oset this :name "jdb")
;; Install jdb versions of debugger commands.
(oset this cmd-set (jdee-jdb-cmd-set "jdb commands" :debugger this))
(oset this bp-listener
(jdee-jdb-breakpoint-listener
"jdb breakpoint listener"
:debugger this))
(jdee-db-add-listener this (oref this bp-listener))
(jdee-db-add-listener
this
(jdee-jdb-stack-listener
"jdb stack listener"
:debugger this)))
(defmethod jdee-db-create-debuggee-app ((this jdee-db-jdb) main-class)
(oset
this
:debuggee (jdee-jdb-debuggee-app
(concat "Application: " main-class)
:main-class main-class)))
(defmethod jdee-db-create-debuggee-applet ((this jdee-db-jdb) applet-doc)
(oset
this
:debuggee (jdee-jdb-debuggee-applet
(concat "Applet: " applet-doc)
:doc applet-doc)))
(defmethod jdee-db-jdb-start ((this jdee-db-jdb) prog-args cmdstr)
"Start the debugger."
(let ((w32-quote-process-args ?\")
(win32-quote-process-args ?\") ;; XEmacs
(source-directory default-directory)
(working-directory
(jdee-db-debugger-get-working-dir this)))
(oset this :buffer (get-buffer-create (oref this :buffer-name)))
(with-current-buffer (oref this :buffer)
;; Do not erase the last transcript; user may wish to view it.
;; (erase-buffer)
(goto-char (point-max))
(cd working-directory)
(insert (concat "cd " working-directory "\n"))
(insert cmdstr)
(comint-mode)
(make-local-variable 'comint-prompt-regexp)
(setq comint-prompt-regexp "\\(^> *\\)\\|\\(^.*\\[[0-9]+\\] *\\)")
(make-local-variable 'paragraph-start)
(setq paragraph-start comint-prompt-regexp)
(let ((process-connection-type nil))
(comint-exec (oref this :buffer)
(oref this :buffer-name)
(oref this :path)
nil
prog-args))
(oset this process
(get-buffer-process (oref this buffer)))
(cd source-directory)
(jdee-db-set-process-filter this)
(jdee-db-set-process-sentinel this)
(run-hooks 'jdee-jdb-mode-hook)
(pop-to-buffer (oref this buffer))