📜  JDB-基本命令

📅  最后修改于: 2020-11-13 04:47:08             🧑  作者: Mango


本章将引导您完成JDB的基本命令。启动会话后,这些命令将用于调试程序。

以下是用于调试的命令列表。

Name Description
help or ? The most important JDB command; it displays a list of recognized commands with a brief description.
run After starting JDB and setting the necessary breakpoints, you can use this command to start execution and debug an application.
cont Continues execution of the debugged application after a breakpoint, exception, or step.
print Displays Java objects and primitive values.
dump For primitive values, this command is identical to print. For objects, it prints the current value of each field defined in the object. Static and instance fields are included.
threads Lists the threads that are currently running.
thread Selects a thread to be the current thread.
where Dumps the stack of the current thread.

让我们假设我们有一个名为Add的示例类,用于以下示例:

添加.java

public class Add
{
   public int addition( int x, int y)
   {
      int z = x + y;
      return z;
   }
   
   public static void main( String ar[ ] )
   {
      int a = 5, b = 6;
      Add ob = new Add();
      
      int c = ob.addition(a,b);
      System.out.println("Add: " + c);
   }
}

使用以下命令编译此类Add.java:

\>javac Add.java

此命令执行主类文件,该文件已添加到JDB中以进行调试。执行以下命令以运行Add类。

\>jdb Add
initializing jdb …
>run

执行这些命令时,您将看到以下输出:

基本命令