File: tutorial.html

package info (click to toggle)
jswat 1.7-2
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 5,656 kB
  • ctags: 3,210
  • sloc: java: 24,683; xml: 130; makefile: 59; sh: 21
file content (451 lines) | stat: -rw-r--r-- 18,839 bytes parent folder | download
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Linux/x86 (vers 1st February 2002), see www.w3.org">

    <title>JSwat - Tutorial</title>
    <link href="http://www.bluemarsh.com/style.css" rel="stylesheet" type="text/css">
  </head>

  <body>
    <!-- body table -->

    <table summary="formatting" valign="top" border="0" cellpadding="8"
    cellspacing="0" width="100%">
      <!-- start header -->
<tr>
  <td colspan="2">
    <!-- start title -->
    <table summary="table" align="center" bgcolor="#000000"
    border="0" cellpadding="1" cellspacing="0" width="100%">
      <tr>
        <td>
          <table summary="table" bgcolor="#ffffff" border="0"
          cellspacing="0" width="100%">
            <tr>
              <td width="10%" align="center">
                <img src="http://www.bluemarsh.com/images/cattails.jpg" alt="cattails">
              </td>
              <td align="left">
                <h1>Blue Marsh Softworks</h1>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    <!-- end title -->
  </td>
</tr>
<!-- end header -->


      <tr>
        <!-- left column -->

        <td valign="top" width="20%">
        <!-- start sidebox -->
<table summary="table" bgcolor="#000000" border="0" cellpadding="0"
cellspacing="0" width="100%">
  <tr>
    <td>
      <table summary="table" border="0" cellpadding="3" cellspacing="1"
      width="100%">
        <tr>
          <td bgcolor="#CCCCCC">&nbsp;<span class="title">Site
          Index</span></td>
        </tr>

        <tr>
          <td bgcolor="#ffffff">&nbsp;<span class="small">o</span> <a
          class="nav" href="http://www.bluemarsh.com/java/index.html">java projects</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://www.bluemarsh.com/personal/index.html">about me</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://www.bluemarsh.com/htdig/search.html">search</a><br>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- end sidebox -->


        <br>
         <!-- start links -->
<table summary="table" bgcolor="#000000" border="0" cellpadding="0"
cellspacing="0" width="100%">
  <tr>
    <td>
      <table summary="table" border="0" cellpadding="3" cellspacing="1"
      width="100%">
        <tr>
          <td bgcolor="#CCCCCC">&nbsp;<span class="title">My Java
          </span></td>
        </tr>

        <tr>
          <td bgcolor="#ffffff">&nbsp;<span class="small">o</span> <a
          class="nav" href="http://www.bluemarsh.com/java/tips.html">java tips</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://www.bluemarsh.com/java/faq.html">java faq</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://www.bluemarsh.com/java/contrib.html">contributing</a><br>
          </td>
        </tr>

        <tr>
          <td bgcolor="#CCCCCC">&nbsp;<span class="title">General
          Java</span></td>
        </tr>

        <tr>
          <td bgcolor="#ffffff">&nbsp;<span class="small">o</span> <a
          class="nav" href="http://java.sun.com/">JavaSoft</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://developer.java.sun.com/">Developer Connection</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://www.afu.com/javafaq.html">The Java FAQ</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href= 
          "http://mindprod.com/jgloss.html">Java Glossary</a><br>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- end links -->

        <br>
         <!-- start links -->
<table summary="table" bgcolor="#000000" border="0" cellpadding="0"
cellspacing="0" width="100%">
  <tr>
    <td>
      <table summary="table" border="0" cellpadding="3" cellspacing="1"
      width="100%">
        <tr>
          <td bgcolor="#CCCCCC">&nbsp;<span class="title">JSwat</span></td>
        </tr>

        <tr>
          <td bgcolor="#ffffff">&nbsp;<span class="small">o</span> <a
          class="nav" href=
          "http://sourceforge.net/project/showfiles.php?group_id=59085">
          downloads</a> <span class="nav">[sf.net]</span></a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "../download.html">other downloads</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "index.html">documentation</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "faq.html">faq</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "../mail-lists.html">mailing lists</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "../integrate.html">integrating</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "../contrib.html">contributing</a><br>
           &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://www.bluemarsh.com/bugzilla/">bugs</a><br>
          </td>
        </tr>

        <tr>
          <td bgcolor="#CCCCCC">&nbsp;<span class="title">Related
          Software</span></td>
        </tr>

        <tr>
          <td bgcolor="#ffffff">
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://www.eclipse.org/">Eclipse</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://www.oops.demon.co.uk/jdbtool/">JDBTool</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://jdee.sunsite.dk/">JDEE</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://sourceforge.net/projects/jenus/">Jenus</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://jipe.sourceforge.net/">Jipe</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://java.sun.com/products/jpda/">JPDA</a><br>
          &nbsp;<span class="small">o</span> <a class="nav" href=
          "http://www.netbeans.org/">NetBeans</a><br>
          </td>
        </tr>

        <tr>
          <td bgcolor="#CCCCCC">&nbsp;<span class="title">Related
          Links</span></td>
        </tr>

        <tr>
          <td bgcolor="#ffffff">
          &nbsp;<span class="small">o</span> <a class="nav"
          href="http://freshmeat.net/projects/jswat/">FreshMeat listing</a><br>
          &nbsp;<span class="small">o</span> <a class="nav"
          href="http://sourceforge.net/projects/jswat/">SourceForge page</a><br>
          &nbsp;<span class="small">o</span> <a
          class="nav" href="http://www.skylit.com/javamethods/nodebugger.html">
          Top Ten Reasons Not to Use a Java Debugger in School</a><br>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- end links -->

        </td>

        <td valign="top" width="75%">
                    <table summary="formatting" border="0" cellpadding="0"
          cellspacing="0" width="100%">
            <tr>
              <td valign="top" width="100%">
                <!-- start content -->

                <table summary="formatting" align="center" bgcolor= 
                "#000000" border="0" cellpadding="0" cellspacing="0"
                width="100%">
                  <tr>
                    <td>
                      <table summary="formatting" border="0"
                      cellpadding="8" cellspacing="1" width="100%">
                        <tr>
                          <td bgcolor="#ffffff">


          <h2>JSwat Tutorial</h2>

          <h3>Tutorial Program</h3>

          <p>Start by saving this <a href="http://www.bluemarsh.com/java/jswat/docs/tutorial.java">Java source
          code</a> to a file and call it <code>tutorial.java</code>. We
          will be using this example source code to learn more about
          what JSwat can do and how to use it. Compile this code using
          &#39;<code>javac -g</code>&#39; which will compile the class
          with local variables and line number information. Both are
          needed when using any Java debugger. Make sure the
          <code>tutorial.class</code> file is located somewhere in your
          classpath.</p>

          <p>Note that using Jikes may result in invalid class
          debugging information. I recommend using the Java compiler
          that comes with the JDK.</p>

          <h3>Loading the Class</h3>

          <p>Start the debugging session by launching JSwat and
          selecting &quot;Start VM&quot; from the &quot;Session&quot;
          menu. A dialog will appear asking you for the name of the
          class to be debugged, along with some other information that
          has already been filled in for you. Verify that the classpath
          shown in the &quot;Options&quot; field is correct. Then enter
          &quot;tutorial&quot; in the &quot;Class name&quot; field.
          Make sure the &quot;suspended&quot; checkbox is checked so
          the session will not resume until you tell it to.</p>

          <p align="center"><img src= 
          "http://www.bluemarsh.com/images/java/jswat/tutorial-load.jpg" width="386" height=
          "270" alt="load dialog"></p>

          <p>With the information entered, click on the Ok button. You
          should see a message that looks something like:</p>
<pre>
VM loading with following options, class name, and class arguments.
/path/to/java -cp /home/me/java
tutorial
VM loaded.
</pre>

          <p>This indicates that the debuggee VM was successfully
          created. At this point the debuggee VM has not attempted to
          locate the class in question. That is, you could use the
          start dialog to load the &quot;<code>noclass</code>&quot;
          class and the debuggee VM will load without an error. Only
          when you click on the &quot;Play&quot; button in the toolbar
          does the debuggee VM start and try to locate the main class.
          In fact, do this now to start the tutorial debuggee VM.</p>

          <p>The tutorial class will start and create a window with a
          single button. Now the tutorial program is waiting for you to
          do something. This gives us an opportunity to take a closer
          look at the JSwat window.</p>

          <h3>JSwat Window</h3>

          <p>Now that JSwat and the tutorial sample are running, you
          should notice that the JSwat window is made up of various
          panels. There is a panel called &quot;Threads&quot; which
          shows the threads in the debuggee VM. A panel showing the
          messages from JSwat is also visible, with a command input
          field below that. To the right is where source files are
          shown.</p>

          <p align="center"><img src= 
          "http://www.bluemarsh.com/images/java/jswat/tutorial-loaded.jpg" width="715" height= 
          "586" alt="tutorial loaded"></p>

          <p>You will notice that above the threads panel are a set of
          labeled tabs. When pressed these tabs bring other panels
          forward. They include a panel called &quot;Classes&quot;
          which shows the currently loaded classes in a hierarchal
          tree; &quot;Locals&quot; displays the local variables while
          single-stepping; and &quot;Watches&quot; which allows viewing
          field and local variables during program execution.</p>

          <p>If you have looked at the <code>tutorial.java</code> file
          you will notice that the first line of the
          <code>main()</code> method prints a message to the
          <code>System.out</code> output stream. The output from the
          debuggee VM is captured by JSwat into one of its panels.
          Click on the &quot;Output&quot; tab above the messages panel
          and you will see the message from the tutorial class. The
          &quot;Input:&quot; field below the output display is for
          entering text input to the debuggee VM on its
          <code>System.in</code> input stream.</p>

          <h3>Setting Breakpoints</h3>

          <p>With the tutorial class running, set a breakpoint at the
          <code>actionPerformed()</code> method. You could do this by
          typing &quot;<code>stop
          tutorial.actionPerformed(java.awt.event.ActionEvent)</code>&quot;.
          This is a rather lengthy way to set a breakpoint. Another way
          is to set the breakpoint at a specific line of code. You can
          do this with &quot;<code>stop tutorial:12</code>&quot;.
          Another way to set the breakpoint is through the &quot;Set
          Breakpoint&quot; item in the &quot;Breakpoints&quot; menu.
          This displays a dialog like the one shown below.</p>

          <p align="center"><img src= 
          "http://www.bluemarsh.com/images/java/jswat/tutorial-setbreak.jpg" width="332"
          height="161" alt="setting breakpoints"></p>

          <p>Yet another way to set a breakpoint is using the source
          code viewer. The <code>tutorial.java</code> file should be
          visible already, but if it is not, click on the
          &quot;Classes&quot; tab to bring the class tree panel
          forward, then double-click on the &quot;tutorial&quot; node
          and the <code>tutorial.java</code> source file should open.
          Now right-click on line 12 of the source code and you should
          see a popup menu appear. Select the &quot;Add
          breakpoint&quot; item and a new breakpoint will be set at
          line 12. The source code viewer will reflect this by drawing
          the line number in green. Disabled breakpoints are shown in
          gray.</p>

          <p>Now switch to the tutorial program&#39;s window and click
          on the &quot;Push me&quot; button. Immediately JSwat signals
          that the debuggee VM has hit a breakpoint. It shows the
          current location in the messages panel. The name of the
          thread is in square brackets (e.g.
          &quot;<code>[AWT-EventQueue-0]</code>&quot;), followed by the
          name of the method
          (&quot;<code>tutorial.actionPerformed</code>&quot;), which is
          in turn followed by the name of the source file and the line
          number where execution has stopped
          (&quot;<code>(tutorial.java:12)</code>&quot;). You should
          also notice that the source code viewer has changed slightly.
          The source line at line 12 is highlighted which indicates
          that it is the current line of execution.</p>

          <p>Just for your information, when a breakpoint is hit at a
          certain line number (in this example, line 12), the debuggee
          VM has not yet executed that line of code. In this example,
          the <code>pushCount</code> field variable has not yet been
          incremented.</p>

          <h3>Single-Stepping</h3>

          <p>Now you are ready to learn about single stepping through
          the source code. Stepping one line of code at a time is done
          by pressing the shortcut key for the &quot;Next Line&quot;
          menu item under the &quot;Step&quot; menu. The default
          shortcut key for this is the <code>F12</code> function
          key.</p>

          <p>Before you start single-stepping, click on the
          &quot;Locals&quot; tab above the class tree panel. This will
          bring the local variables display panel forward and show the
          currently visible local variables. At line 12 of the tutorial
          class, only <code>pushCount</code> (field variable),
          <code>e</code> (method argument), and <code>this</code>
          (reference to &#39;this&#39;) are visible.</p>

          <p>Press the <code>F12</code> key several times right now and
          observe how the source line highlighter moves along through
          the <code>actionPerformed()</code> method of the tutorial
          class. As you step through the code, you will also notice
          that the local variables panel is updated to show the latest
          visible variables and their values.</p>

          <p align="center"><img src= 
          "http://www.bluemarsh.com/images/java/jswat/tutorial-stopped.jpg" width="715" height= 
          "586" alt="stopped at breakpoint"></p>

          <p>To resume execution of the debuggee VM, press the
          &quot;Play&quot; button on the toolbar. Alternatively, you
          could type &quot;<code>resume</code>&quot; at the command
          prompt. The tutorial window will now have changed the button
          label to say &quot;Pushed 1 times&quot;.</p>

          <h3>Restarting the Session</h3>

          <p>Say that we want to reload the tutorial class after we
          have made a change to the source code and recompiled. An easy
          way to do this is to press the &quot;<code>New</code>&quot;
          button on the toolbar (the third button from the left). This
          brings up the &quot;Start VM&quot; dialog that you saw at the
          beginning of the tutorial. Notice that the dialog contains
          the values you entered earlier. That is because JSwat
          remembers the values from the last time we started the
          debuggee VM.</p>

          <p>When you click the Ok button in the Start VM dialog, it
          will terminate the current debugging session and start a new
          one.</p>

          <h3>Exiting the Session</h3>

          <p>Exiting JSwat is easy. Select the &quot;Exit&quot; item
          from the &quot;File&quot; menu. Or, type
          &quot;<code>exit</code>&quot; at the command prompt, or click
          on the window close button. All these methods will result in
          the same thing: the debuggee VM will be terminated and JSwat
          will exit.</p>

          <p>If you are debugging a remote debuggee VM (using the
          &#39;<code>attach</code>&#39; JSwat command), JSwat will
          merely detach from the remote VM without terminating it.</p>
                                    </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                </table>
                <!-- end content -->
              </td>
            </tr>
          </table>

        </td>
        <!-- end right column -->
      </tr>
      <!-- start footer -->
<tr>
  <td align="center" colspan="2">
  <span class="footer">&copy; Copyright 2000-2002 -
  <a href="http://www.bluemarsh.com/index.html">Blue Marsh Softworks</a></span>
  </td>
</tr>
<!-- end footer -->

    </table>
  </body>
</html>