You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2005/09/22 16:14:12 UTC

[DAISY] Created: Debugging FAQs

A new document has been created.

http://cocoon.zones.apache.org/daisy/legacydocs/721.html

Document ID: 721
Branch: main
Language: default
Name: Debugging FAQs
Document Type: Document
Created: 9/22/05 2:13:53 PM
Creator (owner): Helma van der Linden
State: publish

Parts
=====

Content
-------
Mime type: text/xml
Size: 3652 bytes
Content:
<html>
<body>

<h2>How do I debug Cocoon using JDK1.3+?</h2>

<p>With JDK1.3 or above, first set the <tt>CATALINA_OPTS</tt> (for Tomcat 4.x as
shown below (on Win2K).</p>

<pre>set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE
    -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
</pre>

<p class="note">For Tomcat 3.x the param is TOMCAT_OPTS and the first value is
<tt>-classic</tt> instead of <tt>-server</tt>.</p>

<p>Add it to the <tt>catalina.bat</tt>, that can be found in
<tt>%TOMCAT_HOME%\bin\</tt>, right after the first <tt>rem</tt> section. <br/>
The same information in more detail can be found at
<a href="http://jakarta.apache.org/site/idedev-rdtomcat.html">Setting up Tomcat
for Remote Debugging</a>.</p>

<p>The problem of this approach is the blocking of using Tomcat in another mode.
You always have to touch <tt>catalina.bat</tt> again when changing the mode and
this file is really a batch beast, isn't it? Furthermore <tt>catalina.bat</tt>
is only a starting mode library and should not be touched by hand IMO.<br/>
Let me propose my approach: Go to the last line of <tt>startup.bat</tt> where
<tt>catalina.bat</tt> is called. Replace</p>

<pre>call "%EXECUTABLE%" start %CMD_LINE_ARGS%</pre>

<p>with</p>

<pre>set JPDA_TRANSPORT=dt_socket
set JPDA_ADDRESS=8000
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
      </pre>

<p>A switch can now be done by adding and removing <tt>jpda</tt>. You can also
place the old line in comments and switch between them. Or you copy
<tt>startup.bat</tt> to <tt>debug.bat</tt> and do the changes there.</p>

<p class="note">Note that Tomcat must be started using <tt>startup.bat</tt> in
order to set these values; if you are using "<tt>java.exe -jar ...bootstrap.jar
start</tt>" or anything similar to start Tomcat, you have to set the
<tt>CATALINA_OPTS</tt> on the commandline or for Windows in general.</p>

<p class="note">If you use Jetty included with Cocoon 2.1 it's much easier.
Instead of doing "<tt>cocoon.bat servlet</tt>" you simply call "<tt>cocoon.bat
servlet-debug</tt>".</p>

<p>After having started Tomcat or the servlet container of your choice in remote
debugging mode, attach the debugger to localhost:8000 using "<tt>jdb -attach
myhost:8000</tt>". If you get an error "<tt>Error accessing shared memory, rc =
-1</tt>", try "<tt>jdb -connect com.sun.jdi.SocketAttach:port=8000</tt>"
instead. <br/>
More information on this can be found in the
<a href="http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html"> JPDA
documentation</a>.</p>

<p class="note">The attaching of the debugger to that port can be done very
easily in almost all modern IDEs as Eclipse, IDEA, NetBeans or JBuilder. Mostly
port <tt>8000</tt> and <tt>dt_socket</tt> are preselected.</p>

<h2>Now that I have prepared Tomcat and my IDE for debugging: How do I debug?
</h2>

<p>Of course we can not give to many details here as it might be different for
all the possible IDEs out there, but the general proceeding should be the same.
The following steps are for jdb, it should be much easier for the IDEs.<br/>
1. Set a breakpoint in a class via "<tt>stop in
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.checkPipeline</tt>".
<br/>
2. Enter a URL in your browser to get Cocoon to do the stuff that needs
debugging. When your breakpoint is hit, you'll get the message in jdb: <br/>
<tt>Breakpoint hit: "thread=Thread-11",
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.checkPipeline(),
line=363 bci=0</tt>. <br/>
3. Use the debugger commands "print", "next", and "cont" to examine the data and
step through the code.</p>

</body>
</html>

Collections
===========
The document belongs to the following collections: legacydocs