home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / JBuilder8.iso / Solaris / resource / jre / man / sman1 / jdb.1 < prev    next >
Encoding:
Text File  |  2002-09-06  |  17.6 KB  |  320 lines

  1. <!DOCTYPE REFENTRY PUBLIC "-//Sun Microsystems//DTD DocBook V3.0-Based SolBook Subset V2.0//EN" [
  2. <!--ArborText, Inc., 1988-1999, v.4002-->
  3. <!ENTITY % javaents SYSTEM "javaman.ent">
  4. %javaents;
  5. ]>
  6. <?Pub UDT _bookmark _target>
  7. <refentry id="jdb-1">
  8. <!--@(#)jdb.1 1.13 01/03/14 SMI;-->
  9. <refmeta><refentrytitle>jdb</refentrytitle><manvolnum>1</manvolnum>
  10. <refmiscinfo class="date">23 Apr 2001</refmiscinfo>
  11. <refmiscinfo class="sectdesc">&man1;</refmiscinfo>
  12. <refmiscinfo class="software">&java-release;</refmiscinfo>
  13. <refmiscinfo class="arch">generic</refmiscinfo>
  14. <refmiscinfo class="copyright"> Copyright 2001 Sun Microsystems, Inc. All
  15. rights reserved.  Copyright 2001 Sun Microsystems, Inc. Tous droits réservés.
  16. </refmiscinfo>
  17. </refmeta>
  18. <refnamediv><refname>jdb</refname><refpurpose>Java debugger</refpurpose></refnamediv>
  19. <refsynopsisdiv><title>&synp-tt;</title>
  20. <cmdsynopsis><command>jdb</command><arg choice="opt"><replaceable>options
  21. </replaceable></arg><arg choice="opt"><replaceable>class</replaceable></arg>
  22. <arg choice="opt"><replaceable>arguments</replaceable></arg>
  23. </cmdsynopsis></refsynopsisdiv>
  24. <refsect1><title>&parm-tt;</title>
  25. <variablelist termlength="narrow">
  26. <varlistentry><term remap="15"><replaceable>options</replaceable> </term>
  27. <listitem><para>Command-line options.</para>
  28. </listitem></varlistentry>
  29. <varlistentry><term><replaceable>class</replaceable> </term><listitem><para>
  30. Name of the class to begin debugging.</para>
  31. </listitem></varlistentry>
  32. <varlistentry><term><replaceable>arguments</replaceable> </term><listitem>
  33. <para>Arguments passed to the <function>main</function> method of <replaceable>
  34. class</replaceable>. </para>
  35. </listitem></varlistentry>
  36. </variablelist></refsect1>
  37. <refsect1><title>&desc-tt;</title>
  38. <indexterm id="jdb-1-indx-1"><primary sortas="Java debugger">Java debugger —
  39. jdb</primary></indexterm><indexterm id="jdb-1-indx-2"><primary sortas="jdb">
  40. jdb — Java debugger</primary></indexterm><para>The Java™ debugger, <command>
  41. jdb</command>, is a simple command-line debugger for Java classes. It is a
  42. demonstration of the <literal>Java Platform Debugger Architecture</literal>
  43. that provides inspection and debugging of a local or remote Java Virtual Machine.
  44. </para>
  45. <refsect2>
  46. <title>Starting a jdb Session</title>
  47. <indexterm id="jdb-1-indx-3"><primary sortas="jdb">jdb — Java debugger
  48. </primary><secondary>Starting a jdb Session</secondary></indexterm><para>
  49. There are many ways to start a  jdb session. The most frequently used way
  50. is to have <command>jdb</command> launch a new Java Virtual Machine (VM) with
  51. the main class of the application to be debugged. This is done by substituting
  52. the command <command>jdb</command> for <command>java</command> (see <citerefentry>
  53. <refentrytitle>java</refentrytitle><manvolnum>1</manvolnum></citerefentry>)
  54. in the command line. For example, if your application's main class is <literal>
  55. MyClass</literal>, you use the following command to debug it under <command>
  56. jdb</command>:<informalexample><para><screen>example% <userinput>jdb MyClass
  57. </userinput></screen> </para>
  58. </informalexample></para>
  59. <para>When started this way, <command>jdb</command> invokes a second Java
  60. VM with any specified parameters, loads the specified class, and stops the
  61. VM before executing that class's first instruction.</para>
  62. <para>Another way to use <command>jdb</command> is by attaching it to a Java
  63. VM that is already running. A VM that is to be debugged with <command>jdb
  64. </command> must be started with the following options:</para>
  65. <para><screen>    Option                             Purpose
  66.  
  67.     -Xdebug                            Enables debugging support 
  68.                                        in the VM.
  69.  
  70.     -Xrunjdwp:transport=dt_socket,     Loads in-process debugging
  71.     server=y,suspend=n                 libraries and specifies the
  72.                                        kind of connection to
  73.                                        be made.</screen></para>
  74. <para>For example, the following command will run the <literal>MyClass</literal>
  75. application and allow <command>jdb</command> to connect to it at a later time:<informalexample>
  76. <para><screen>example% <userinput>java –Xdebug \
  77.    –Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n MyClass<?Pub Caret>
  78. </userinput></screen></para>
  79. </informalexample></para>
  80. <para>You can then attach <command>jdb</command> to the VM with the following
  81. commmand:<informalexample><para><screen>example% <userinput>jdb –attach 8000
  82. </userinput></screen></para>
  83. </informalexample></para>
  84. <para>Notice that <command>MyClass</command> is not specified in the <literal>
  85. jdb</literal> command line in this case because <command>jdb</command> is
  86. connecting to an existing VM instead of launching a new one.</para>
  87. <para>There are many other ways to connect the debugger to a VM, and all of
  88. them are supported by <command>jdb</command>. The Java Platform Debugger Architecture
  89. has additional documentation on these connection options.</para>
  90. </refsect2>
  91. <refsect2>
  92. <title>Basic jdb Commands</title>
  93. <indexterm id="jdb-1-indx-4"><primary sortas="jdb">jdb — Java debugger
  94. </primary><secondary>Basic jdb Commands</secondary></indexterm><para>The following
  95. is a list of the basic <command>jdb</command> commands. The Java debugger
  96. supports other commands listed with the <command>help</command> command.</para>
  97. <para>Notice that to display local (stack) variables, the class  must have
  98. been compiled with the <command>javac</command> <option>g</option> option.
  99. </para>
  100. <variablelist termlength="narrow">
  101. <varlistentry><term remap="15"><command>cont</command> </term><listitem><para>
  102. Continues execution of the debugged application after a breakpoint, exception,
  103. or step.</para>
  104. </listitem></varlistentry>
  105. <varlistentry><term><command>dump</command> </term><listitem><para>For primitive
  106. values, this command is identical to <command>print</command>. For objects,
  107. it prints the current value of each field defined in the object. Static and
  108. instance fields are included. The <command>dump</command> command supports
  109. the same set of expressions as the <command>print</command> command. </para>
  110. </listitem></varlistentry>
  111. <varlistentry><term><command>help</command></term><term><command>?</command></term>
  112. <listitem><para>As the most important <command>jdb</command> command, <command>
  113. help</command> displays the list of recognized commands with a brief description.
  114. </para>
  115. </listitem></varlistentry>
  116. <varlistentry><term><command>print</command> </term><listitem><para>Displays
  117. Java objects and primitive values. For variables or fields of primitive types,
  118. the actual value is printed. For objects, a short description is printed.
  119. See the <command>dump</command> command for getting more information about
  120. an object. <command>print</command> supports many simple Java expressions
  121. including those with method invocations. For example:  <itemizedlist>
  122. <listitem><para><userinput>print MyClass.myStaticField</userinput></para>
  123. </listitem>
  124. <listitem><para><userinput>print myObj.myInstanceField</userinput></para>
  125. </listitem>
  126. <listitem><para><userinput>print <replaceable>i</replaceable> <literal>+</literal> <replaceable>
  127. j</replaceable> <literal>+</literal> <replaceable>k</replaceable></userinput>
  128.  ... where <replaceable>i</replaceable>, <replaceable>j</replaceable>, and <replaceable>
  129. k</replaceable> are primitives and either fields or local variables.</para>
  130. </listitem>
  131. <listitem><para><userinput>print myObj.myMethod( )</userinput>  ...
  132. if <literal>myMethod</literal> returns a non-null.</para>
  133. </listitem>
  134. <listitem><para><userinput>print new java.lang.String("Hello").length( )
  135. </userinput></para>
  136. </listitem>
  137. </itemizedlist></para>
  138. </listitem></varlistentry>
  139. <varlistentry><term remap="15"><command>thread</command> </term><listitem>
  140. <para>Selects a thread to be the current thread. Many <literal>jdb</literal>
  141. commands are based on the setting of the current thread. The thread is specified
  142. with the thread index described in the <command>threads</command> command.
  143. </para>
  144. </listitem></varlistentry>
  145. <varlistentry><term><command>threads</command> </term><listitem><para>Lists
  146. the threads that are currently running. For each thread, its name and current
  147. status are printed, as well as an index that can be used for other commands.
  148. For example:  <informalexample><para><computeroutput>4. (java.lang.Thread)0x1
  149. main running</computeroutput></para>
  150. </informalexample>In this example, the thread index is <literal>4</literal>,
  151. the thread is an instance of <literal>java.lang.Thread</literal>, the thread
  152. name is <literal>main</literal>, and it is currently running.</para>
  153. </listitem></varlistentry>
  154. <varlistentry><term remap="15"><command>run</command> </term><listitem><para>
  155. After starting <command>jdb</command>, and setting any necessary breakpoints,
  156. use this command to start the execution of the debugged application. This
  157. command is available only when <command>jdb</command> launches the debugged
  158. application (as opposed to attaching to an existing VM).</para>
  159. </listitem></varlistentry>
  160. <varlistentry><term remap="15"><command>where</command> </term><listitem>
  161. <para>The <literal>where</literal> subcommand with no arguments dumps the
  162. stack of the current thread (which is set with the <command>thread</command>
  163. command). Using <command>where</command> <literal>all</literal> dumps the
  164. stack of all threads in the current thread group. Using <command>where</command> <replaceable>
  165. threadindex</replaceable> dumps the stack of the specified thread. If the
  166. current thread is suspended (either through an event such as a breakpoint
  167. or through the  <command>suspend</command> command), local variables and fields
  168. can be displayed with the <command>print</command> and  <command>dump</command>
  169. commands. The <command>up</command> and  <command>down</command> commands
  170. select which stack frame is current.</para>
  171. </listitem></varlistentry>
  172. </variablelist></refsect2>
  173. <refsect2>
  174. <title>Breakpoint Commands</title>
  175. <indexterm id="jdb-1-indx-5"><primary sortas="jdb">jdb — Java debugger
  176. </primary><secondary>Breakpoints</secondary></indexterm><para>Breakpoints
  177. are set in <command>jdb</command> at line numbers or at the first instruction
  178. of a method. For example:</para>
  179. <variablelist termlength="wholeline">
  180. <varlistentry><term remap="25"><userinput>stop at MyClass:22</userinput></term>
  181. <listitem><para>Sets a breakpoint at the first instruction for line <literal>
  182. 22</literal> of the source file containing <literal>MyClass</literal>.</para>
  183. </listitem></varlistentry>
  184. <varlistentry><term><userinput>stop in java.lang.String.length</userinput></term>
  185. <listitem><para>Sets a breakpoint at the beginning of the method <literal>
  186. java.lang.String.length</literal>.</para>
  187. </listitem></varlistentry>
  188. <varlistentry><term><userinput>stop in MyClass.<replaceable>init</replaceable></userinput></term>
  189. <listitem><para><replaceable>init</replaceable> identifies the <literal>MyClass
  190. </literal> constructor.</para>
  191. </listitem></varlistentry>
  192. <varlistentry><term><userinput>stop in MyClass.<replaceable>clinit</replaceable></userinput> 
  193. </term><listitem><para><replaceable>clinit</replaceable> identifies the static
  194. initialization code for <literal>MyClass</literal>.</para>
  195. </listitem></varlistentry>
  196. </variablelist><para>If a method is overloaded, you must also specify its
  197. argument types so that the proper method can be selected for a breakpoint.
  198. For example,<informalexample><para><screen><userinput>MyClass.myMethod(int,java.lang.String)
  199. </userinput></screen></para>
  200. </informalexample>or<informalexample><para><screen><userinput>MyClass.myMethod()
  201. </userinput></screen></para>
  202. </informalexample></para>
  203. <para>The <command>clear</command> command removes breakpoints using a syntax
  204. as in <command>clear</command><literal>MyClass:45</literal>. Using the <command>
  205. clear</command> command with no argument displays a list of all breakpoints
  206. currently set. The <command>cont</command> command continues execution.</para>
  207. </refsect2>
  208. <refsect2>
  209. <title>Stepping Commands</title>
  210. <indexterm id="jdb-1-indx-6"><primary sortas="jdb">jdb — Java debugger
  211. </primary><secondary>Stepping</secondary></indexterm><para>The <command>step
  212. </command> command advances execution to the next line, whether it is in the
  213. current stack frame or a called method. The <command>next</command> command
  214. advances execution to the next line in the current stack frame.</para>
  215. </refsect2>
  216. <refsect2>
  217. <title>Exception Commands</title>
  218. <indexterm id="jdb-1-indx-7"><primary sortas="jdb">jdb — Java debugger
  219. </primary><secondary>Exceptions</secondary></indexterm><para>When an exception
  220. occurs for which there is no catch statement anywhere in the throwing thread's
  221. call stack, the VM normally prints an exception trace and exits. When running
  222. under <command>jdb</command>, however, control returns to <command>jdb</command>
  223. at the offending throw. Use <command>jdb</command> to determine the cause
  224. of the exception.</para>
  225. <variablelist termlength="narrow">
  226. <varlistentry><term remap="15"><command>catch</command> </term><listitem>
  227. <para>Causes the debugged application to stop at other thrown exceptions.
  228. For example:<informalexample><para><screen><userinput>catch java.io.FileNotFoundException
  229. </userinput></screen></para>
  230. </informalexample>or<informalexample><para><screen><userinput>catch mypackage.BigTroubleException
  231. </userinput></screen></para>
  232. </informalexample></para>
  233. </listitem></varlistentry>
  234. </variablelist>
  235. <informalexample><para>Any exception which is an instance of the specified
  236. class (or of a subclass) will stop the application at the point where it is
  237. thrown.</para>
  238. </informalexample>
  239. <variablelist termlength="narrow">
  240. <varlistentry><term remap="15"><command>ignore</command> </term><listitem>
  241. <para>Negates the effect of a previous <command>catch</command> command. Notice
  242. that the <command>ignore</command> command does not cause the debugged VM
  243. to ignore specific exceptions, only the debugger.</para>
  244. </listitem></varlistentry>
  245. </variablelist></refsect2>
  246. </refsect1>
  247. <refsect1><title>&opts-tt;</title>
  248. <para>When using <command>jdb</command> in place of the Java application launcher
  249. on the command line, <command>jdb</command> accepts many of the same options
  250. as the <citerefentry><refentrytitle>java</refentrytitle><manvolnum>1</manvolnum>
  251. </citerefentry> command, including <option>D</option>, <option>classpath</option>,
  252. and <option>X</option><replaceable>option.</replaceable></para>
  253. <para>The following additional options are accepted by <command>jdb</command>:
  254. </para>
  255. <variablelist termlength="medium">
  256. <varlistentry><term remap="15"><option>sourcepath</option> <replaceable>dir1:
  257. </replaceable><replaceable>dir2</replaceable> . . .</term><listitem><para>
  258. Uses the given path in searching for source files in the specified path. If
  259. this option is not specified, the default path of "." is used.</para>
  260. </listitem></varlistentry>
  261. <varlistentry><term><option>attach</option> <replaceable>address</replaceable> 
  262. </term><listitem><para>Attaches the debugger to previously running VM using
  263. the default connection mechanism.</para>
  264. </listitem></varlistentry>
  265. <varlistentry><term><option>launch</option> </term><listitem><para>Launches
  266. the debugged application immediately upon startup of <command>jdb</command>.
  267. This option removes the need for using the <literal>run</literal> command.
  268. The debuged application is launched and then stopped just before the initial
  269. application class is loaded. At that point, you can set any necessary breakpoints
  270. and use the <command>cont</command> command to continue execution.</para>
  271. </listitem></varlistentry>
  272. <varlistentry><term><option role="nodash">J</option><replaceable>option</replaceable></term>
  273. <listitem><para>Pass <replaceable>option</replaceable> to the Java virtual
  274. machine, where option is one of the options described on the man page for
  275. the java application launcher, java (1). For example, <literal>-J-Xms48m</literal>
  276. sets the startup memory to 48 megabytes. It is a common convention for <literal>
  277. -J</literal> to pass options to the underlying virtual machine.</para>
  278. </listitem></varlistentry><?Pub Caret>
  279. </variablelist><para>Other options are supported for alternate mechanisms
  280. for connecting the debugger and the VM it is to debug. The Java Platform Debugger
  281. Architecture has additional documentation on these connection alternatives.
  282. </para>
  283. </refsect1>
  284. <refsect1><title>&attr-tt;</title>
  285. <para>See <citerefentry><refentrytitle>attributes</refentrytitle><manvolnum>
  286. 5</manvolnum></citerefentry> for a description of the following attributes:
  287. </para>
  288. <informaltable frame="all" orient="port">
  289. <tgroup cols="2" colsep="1" rowsep="1"><colspec colnum="1" colname="col1"
  290. colwidth="1*" colsep="1" align="left"><colspec colnum="2" colname="col2" colwidth="1*"
  291. align="left">
  292. <thead>
  293. <row><entry colname="col1" align="center" valign="top">ATTRIBUTE TYPE</entry>
  294. <entry colname="col2" align="center" valign="top">ATTRIBUTE VALUE</entry>
  295. </row>
  296. </thead>
  297. <tbody>
  298. <row><entry>Availability</entry><entry>SUNWj3dev</entry></row>
  299. </tbody>
  300. </tgroup>
  301. </informaltable>
  302. </refsect1>
  303. <refsect1><title>&also-tt;</title>
  304. <para><citerefentry><refentrytitle>java</refentrytitle><manvolnum>1</manvolnum>
  305. </citerefentry>, <citerefentry><refentrytitle>javac</refentrytitle><manvolnum>
  306. 1</manvolnum></citerefentry>, <citerefentry><refentrytitle>javadoc</refentrytitle>
  307. <manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>javah
  308. </refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry><refentrytitle>
  309. javap</refentrytitle><manvolnum>1</manvolnum></citerefentry>, <citerefentry>
  310. <refentrytitle>attributes</refentrytitle><manvolnum>5</manvolnum></citerefentry> 
  311. </para>
  312. </refsect1>
  313. <!--+ 07/27/00 08:34:48
  314.     | tagMorph:  $Id: tagMorph-engine 1.54 1998/01/19 05:44:48 $
  315.     | tagMorph library:  $Id: libtagMorph.a 1.50 1998/01/19 22:02:51 $
  316.     | sunman-to-solbook 1.17
  317.     +-->
  318. </refentry>
  319. <?Pub *0000017446>
  320.