📄 11debugtutor.html
字号:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Together Tutorial -- Part 11</title>
<script language="JavaScript"><!--
function doExerciseWindow(questionURL, col, row, topPercent)
{
var wf = "";
wf = wf + "width=" + col;
wf = wf + ",height=" + row;
wf = wf + ",resizable=yes";
wf = wf + ",scrollbars=yes";
wf = wf + ",menubar=no";
wf = wf + ",toolbar=no";
wf = wf + ",directories=no";
wf = wf + ",location=no";
wf = wf + ",status=no";
var n = window.open("",
"questionWindow",
wf);
//"toolbar=no,width=500,height=500");
//windowFeatures);
// "toolbar=no,width=" + col + ",height=" + row);
// n.move(0,0);
var framesetString = '<FRAMESET ROWS="';
framesetString = framesetString + topPercent;
framesetString = framesetString + '%,*" frameborder=0 framespacing=2 border=0>';
n.document.write(framesetString);
n.document.write('<frame src="' + questionURL +'" name="question">');
n.document.write('<frame src="blankpage.html" name="answer">');
n.document.write('</frameset>');
n.document.write('<noframes> <body> </body> </noframes>');
}
// -->
</script>
<link href="tutor.css" rel="styleSheet" type="text/css">
</head>
<body bgcolor="white" link="#003399" alink="#999999" vlink="#000066">
<div align="left">
<p class="head2">
<span style="font-size: 9pt">
<a href="mailto:%20e.w@263.net">翻译: 李颖(e.w@263.net)</a></span></p>
</div>
<div align="center">
<p class="head2"><a name="top"></a>Together 教程<br>11: 运行和调试 Java 工程</p>
</div>
<p>在 Together 教程的最后一课中, 你将学习如何使用 Editor 面板和 Message 面板来编译和调试 Java 代码.
你已经忠实地参照本教程创建了 <b>airline</b> 工程. 但现在你要放弃它, 改用更丰富地 <b>CashSales</b> 工程.</p>
<p>在 Windows 平台下, Together 安装并使用 Java2<sup>TM</sup> SDK ver 1.3<b> </b>的 <b>javac.exe</b>
最为缺省的编译器. Unix 用户必须安装适当的 Java2 SDK 并将其加入搜索路径中. 对于所有的平台, Together 都提供了完整的 IDE
用于 Java 开发.</p>
<p><b>目录:</b></p>
<ul>
<li><a class="onPage" href="#tab">编译并运行一个工程</a><li><a class="onPage" href="#setbp">
设置断点并使调试器显示动态效果</a><li><a class="onPage" href="#running">在调试器下运行</a><li><a class="onPage" href="#watchpoint">
设置 watchpoint 并改变程序运行</a><li><a class="onPage" href="#tip">技巧</a></ul>
<p></p>
<p><img height="2" width="900" src="images/generic/rainbow2.gif" alt="Divider line"></p>
<p class="head3"><a name="tab"></a>编译并运行一个工程</p>
<p>作为 airline 工程最后的工作, 你可以在 <b>Driver</b> 类中增加简单的输出语句. (记得 <b>Driver</b>
类吗? 你可以在 <b>UserInterface</b> 包中找到它.)</p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 将以下语句插入到 <b>Driver.main()</b>
中.
<p> <b>System.out.println("Goodbye Airline Project.");</b></p>
<p>然后编译工程.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>make 按钮(<img src="images/icons/makebutton.gif" width="15" height="12" border="0" hspace="1" alt="Make button">)
和 build 按钮(<img src="images/icons/buildbutton.gif" width="15" height="12" border="0" hspace="1" alt="Build button">)
工程在主工具条中, 也在主菜单中的 <nobr><b>Project</b></nobr> 下.
当你 make 或 build 一个工程时, Together 运行缺省的 Java 编译器和 make
工具.</p>
<p>Together 将编译结果显示在 Message 面板中. 如果有错误或警告,
你可以点击 Message 内中适当的信息, 直接浏览对应的错误代码.</p>
<p>编译工程的输出信息将显示在 Message 面板中.</p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro11_compileroutput.png" width="526" height="186" border="0" alt="Compile messages" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 创建一个名为 "vanilla"
的运行配置, 使用 -classic 虚拟机选项.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>这是一个多步操作.</p>
<ol>
<li>从主菜单中选择 <b>Run | Run/Debug Configurations</b>.
结果对话框显示当前所有的运行配置 -- 它们都没有 -classic 选项.
<li>在 <b>Run/Debug Configurations</b>
的结果对话框中, 点击 <b>Add</b> 来创建新的运行配置.
<li>熟土配置名(我们将我们的配置命名为 "Vanilla"). <li>
对于 <b>Select class with 'main'</b> 输入框,
点击浏览按钮 (<img src="images/icons/selectboxbutton.gif" width="21" height="21" border="0" align="baseline" alt="Select button" hspace="1">).
<li>点击 <b>UserInterface.Driver</b>.
<li>点击 <b>Ok</b> 完成操作.
</ol>
<p></p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro11_makeclassicrunconfig.png" alt="Run configurations" width="543" height="408" border="0" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 在新配置下运行 <b>airline</b>
工程.</td>
</tr>
</table>
</td>
</tr>
</table>
<p>当你点击主工具条中的运行按钮(<img src="images/icons/runbutton.gif" width="15" height="11" border="0" alt="run button" hspace="1">)时, Together
显示一个对话框, 用于选择运行配置. 你应该选择刚才创建的配置.</p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>右图显示了我们的配置列表.</p>
<p>Message 面板提供了一个简单的控制台窗口, 它是 Together
中运行的程序的标准输入和输出窗口.</p>
<p>下图是运行中的程序. 面板右侧的页显示包含 <b>main</b> 方法的类.</p>
<p>注意 Message 面板包含几个页. (你可以通过页的右键菜单关闭它.)</p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro11_runairline.png" alt="Run arguments" width="621" height="370" border="0"></td>
</tr>
<tr>
<td colspan="2" valign="top" bgcolor="white">
<p><img src="images/airline/pro11_runresults.png" alt="Run results" width="526" height="186" border="0" hspace="10" vspace="5"></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>airline 工程的所有工作到此结束了. 祝贺你. 你已经学习了很多知识! 本教程中剩余的部分已经很少了.</p>
<p>
<hr>
<p class="head3"><a name="setbp"></a>设置断点并使调试器显示动态效果</P>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 打开 <b>CashSales</b>
工程. 然后打开<b> problem_domain</b> 模型图.</td>
</tr>
</table>
</td>
</tr>
</table>
<p>在 Explorer 面板的 Directory 页中浏览到 <b>CashSales.tpr</b>:</p>
<dl>
<dd><b>Samples | java | CashSales | CashSales.tpr</b>
</dl>
<p>Together 警告你它必须关闭当前工程才能打开另一个工程.</p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 在 <b>CashSaleDetail</b>
类(在 <b>problem_domain</b> 包中)的构造方法的最后一个大括号处设置一个断点.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>你需要将构造方法载入到 Together 编辑器中. 如果你对找到它有困难, 你可以使用
Designer 面板右下角的 Overview 按钮, 将 <b>CashSaleDetail</b>
滚动到模型图的中间. 然后在模型图中点击构造方法.</p>
<p>在编辑器中, 点击构造方法的结束大括号的代码行数字的左侧.
这样将把这一行高亮度显示为红色并在左侧空白区域显示一个断点图标.</p>
<p>鼠标点击左侧空白区域将打开和关闭断点.</p>
</td>
<td valign="top" bgcolor="white"><img height="161" width="472" src="images/airline/pro11_setbreakpoint.png" hspace="5" alt="Setting a breakpoint in the editor"></td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<p>Message 面板的 Debugger 页中显示所有的断点. (如果该页中没有显示, 从主菜单中选择 <nobr><b>View | Message Pane Tabs | Run/Debug </b>
来修改设置</nobr>.)</p>
<p><img src="images/airline/pro11_debuggertab.png" width="725" height="205" border="0" hspace="10" alt="Debugger tab" vspace="20"></p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 设置调试器,
使它在运行工程时显示模型图与代码之间的联系.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>进入工程设置或缺省设置, 展开 <b>Run/Debug</b>. 选中 <b>Animate class diagram during debugging</b>.</p>
<p>当你在动态效果的调试器下运行工程时, Together 将滚动类图,
将你当前跟踪的方法高亮度显示.</p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro11_animatedebugger.png" width="645" height="400" border="0" alt="Debug options" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<p>
<hr>
<p class="head3"><a name="running"></a>在调试器下运行</P>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 使用 Debug
运行配置在调试器下运行 <b>CashSales</b> 应用程序. 察看编辑器中的断点.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>主工具条中有 Run in Debugger 按钮(<img src="images/icons/runindebuggerbutton.gif" width="14" height="14" border="0" hspace="1">).
点击这个按钮将出现右图中的对话框. CashSales 的 Debug 运行配置时缺省的选项.
点击 <b>Ok</b> 开始运行.</p>
<p>请耐心等待应用程序启动. 你必须点击 "Scan" 按钮才能到达断点处.
当程序运行到断点处, 编辑器将代码行高亮度显示为蓝色.</p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro11_debugarguments.png" width="535" height="319" border="0" alt="Editor at breakpoint" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 在断点处, 察看当前栈结构和 <b>CashSaleDetail.qty</b>
值.</td>
</tr>
</table>
</td>
</tr>
</table>
<p>当调试器开始运行时, Debugger 页扩展开以便显示详细的运行时信息. Debugger 面板的左侧是一个工具条,
你可以通过其中的按钮控制程序执行, 察看栈和线程, 以及设置各种类型的断点.</p>
<p>Frame 页(下图中在最前)显示了到达断点时当前栈的内容. 当代码执行到这一点时, 你可以展开 <b>this</b> 以便察看 <b>CashSaleDetail.qty</b>.</p>
<p><img height="290" width="640" src="images/airline/pro11_debuggerframe1.png" hspace="10" vspace="10" alt="Top frame information"></p>
<p>点击 Frame 页顶部的方法名将显示当前线程的运行时刻调用栈.</p>
<p><img height="290" width="640" src="images/airline/pro11_debuggerframe2.png" hspace="10" vspace="10" alt="Stack trace"></p>
<p>当工程在调试模式下运行时, 编辑器左侧的空白区域将发生改变. 小的菱形图标<nobr>(</nobr><nobr><img height="5" width="5" src="images/icons/debugdiamond.gif" hspace="1" alt="Debug diamond">)表示可执行的代码行</nobr>.
断点图标从未运行<nobr>(</nobr><nobr><img height="14" width="14" src="images/icons/bpicon.gif" hspace="1" alt="Breakpoint icon" align="top">)改变为正在运行(<img height="14" width="14" src="images/icons/okbpicon.gif" hspace="1" alt="Breakpoint icon" align="top"></nobr><nobr>)</nobr>.</p>
<p>
<hr>
<p class="head3"><a name="watchpoint"></a>设置 watchpoint 并改变程序运行</P>
<p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 在 <b>CashSaleDetail.qty</b>
中设置一个 watchpoint. 然后将 <b>qty</b> 值修改为<b>47</b>.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>当程序运行到断点处暂停时, 你可以设置 watchpoint. 点击 Message
面板最左侧页面中的 watchpoint 图标(<img height="7" width="14" src="images/icons/watchpointicon.gif" hspace="2" vspace="2">).</p>
<p>Together 显示一个类似右图的对话框. 输入如图所示的表达式.</p>
<p></p>
</td>
<td valign="top" bgcolor="white"><img height="155" width="253" src="images/cashsales/addwatchpoint.png" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<p>你可以通过 watchpoint 行中的下拉菜单设置 watchpoint 表达式的值. 首先, 在该行上点击鼠标左键使它高亮度显示为蓝色.
然后点击鼠标右键显示菜单. 对于这个练习, 选择 <b>Change Value</b> 集合.</p>
<p>在对话框中输入的 <b>qty</b> 新值.</p>
<p><img src="images/airline/pro11_changewatchptvalue.png" width="700" height="295" border="0" alt="Change watchpoint expression value" hspace="2" vspace="5"></p>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr>
<td bgcolor="#bbbbbb">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<p>点击 Message 面板中的继续按钮( <img src="images/icons/continuebuttonicon.png" width="6" height="11" border="0">)
继续执行.</p>
<p>右图显示了我们用户界面中的执行结果. 实际运行结果将根据查询到的项目而有所不同.</p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro11_whitepopcorn.png" width="318" height="136" border="0" alt="Debug options" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<div align="left">
<hr>
<p class="head3"><a name="tip"></a>技巧</p>
</div>
<ul>
<div align="left">
<li>对于已编译过的或没有内容可编译的工程, 不要使用 make 按钮. 你可以从主菜单中选择 <b>Project | Rebuild Project</b>
来强制重新编译.<li>你可以通过 Debugger 页中断点的右键菜单来删除断点. 从调试器列表中选择断点, 点击鼠标右键,
然后选择 <b>Remove breakpoint</b>. 或者, 你可以选择断点并点击删除. <li>
当程序运行在方法调用处暂停时, 如果 Smart Step 已打开, 点击 <nobr>"Step into"</nobr>
按钮<nobr>(</nobr><nobr><img height="14" width="14" src="images/cashsales/stepintobutton.png" hspace="1" alt="Step into button" align="top">)将跟踪到方法内部</nobr>. (Debugger
页中有一个 "Skip classes" 页列出了调试器不会进入的类. 缺省状态下, 这将是标准 Java
类库中的类. 你可以使用 "Skip classes" 右键菜单将更多的类加入到列表中.
这个页中有一个选择框允许你跟踪进入类的内部, 如果它的源代码可用的话.)
<li>C++ 程序员也可以使用 Together 编译他们的代码. 但是首先, 他们需要将 Together
配置中指定的编译器修改为他们自己的 C++ 编译器.
</div>
</ul>
<center>
<p></p>
</center>
<center>
<hr>
<img height="19" width="235" src="images/generic/lastnavbutton.gif" vspace="10" alt="Navigation bar" usemap="#lastnavbuttonb6010a8f" border="0"><map name="lastnavbuttonb6010a8f"><area href="10qualityassurance.html" coords="4,1,94,16" shape="rect"><area href="#top" coords="101,1,144,17" shape="rect"><area href="index.html" coords="151,2,229,16" shape="rect"></map>
<hr>
</center>
<p class="footnote">Copyright © 2002 TogetherSoft Corporation. All rights reserved.</p>
<p class="footnote"><font color="#666666">Last Revised: </font><csobj w="88" h="12" t="DateTime" format="MedDate" region="0">Fri, Mar 8, 2002</csobj></P>
<p class="footnote">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -