< prev index next >

test/jdk/com/sun/jdi/lib/jdb/JdbCommand.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package lib.jdb;
  25 
  26 import java.util.Arrays;

  27 import java.util.stream.Collectors;
  28 
  29 /**
  30  * Represents list of commands of <code>jdb</code> from JDK1.4:
  31  *
  32  *   run [class [args]]        -- start execution of application's main class
  33  *
  34  *   threads [threadgroup]     -- list threads
  35  *   thread <thread id>        -- set default thread
  36  *   suspend [thread id(s)]    -- suspend threads (default: all)
  37  *   resume [thread id(s)]     -- resume threads (default: all)
  38  *   where [thread id] | all   -- dump a thread's stack
  39  *   wherei [thread id] | all  -- dump a thread's stack, with pc info
  40  *   up [n frames]             -- move up a thread's stack
  41  *   down [n frames]           -- move down a thread's stack
  42  *   kill <thread> <expr>      -- kill a thread with the given exception object
  43  *   interrupt <thread>        -- interrupt a thread
  44  *
  45  *   print <expr>              -- print value of expression
  46  *   dump <expr>               -- print all object information


 101  *   enablegc <expr>           -- permit garbage collection of an object
 102  *
 103  *   !!                        -- repeat last command
 104  *   <n> <command>             -- repeat command n times
 105  *   help (or ?)               -- list commands
 106  *   version                   -- print version information
 107  *   exit (or quit)            -- exit debugger
 108  *
 109  *   <class id>: full class name with package qualifiers or a
 110  *   pattern with a leading or trailing wildcard ('*').
 111  *   <thread id>: thread number as reported in the 'threads' command
 112  *   <expr>: a Java(tm) Programming Language expression.
 113  *   Most common syntax is supported.
 114  *
 115  *   Startup commands can be placed in either "jdb.ini" or ".jdbrc"
 116  *   in user.home or user.dir
 117  */
 118 public class JdbCommand {
 119     final String cmd;
 120     boolean allowExit = false;


 121 
 122     public JdbCommand(String cmd) {
 123         this.cmd = cmd;
 124     }
 125 
 126     public JdbCommand allowExit() {
 127         allowExit = true;
 128         return this;
 129     }
 130 





 131 
 132     public static JdbCommand run(String ... params) {
 133         return new JdbCommand("run " + Arrays.stream(params).collect(Collectors.joining(" ")));
 134     }
 135     public static JdbCommand cont() {
 136         return new JdbCommand("cont");
 137     }
 138     public static JdbCommand dump(String what) {
 139         return new JdbCommand("dump " + what);
 140     }
 141     public static JdbCommand quit() {
 142         // the command suppose jdb terminates
 143         return new JdbCommand("quit").allowExit();
 144     }
 145     public static JdbCommand stopAt(String targetClass, int lineNum) {
 146         return new JdbCommand("stop at " + targetClass + ":" + lineNum);
 147     }






 148     public static JdbCommand stopIn(String targetClass, String methodName) {
 149         return new JdbCommand("stop in " + targetClass + "." + methodName);
 150     }
 151 


 152     // clear <class id>:<line>   -- clear a breakpoint at a line
 153     public static JdbCommand clear(String targetClass, int lineNum) {
 154         return new JdbCommand("clear " + targetClass + ":" + lineNum);
 155     }
 156 
 157     // exception type used by catch/ignore
 158     public enum ExType{
 159         uncaught,
 160         caught,
 161         all
 162     }
 163     public static JdbCommand catch_(String classId) {
 164         return new JdbCommand("catch " + classId);
 165     }
 166     public static JdbCommand catch_(ExType eType, String classId) {
 167         return catch_(eType.toString() + " " + classId);
 168     }
 169     public static JdbCommand ignore(String classId) {
 170         return new JdbCommand("ignore " + classId);
 171     }




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package lib.jdb;
  25 
  26 import java.util.Arrays;
  27 import java.util.regex.Pattern;
  28 import java.util.stream.Collectors;
  29 
  30 /**
  31  * Represents list of commands of <code>jdb</code> from JDK1.4:
  32  *
  33  *   run [class [args]]        -- start execution of application's main class
  34  *
  35  *   threads [threadgroup]     -- list threads
  36  *   thread <thread id>        -- set default thread
  37  *   suspend [thread id(s)]    -- suspend threads (default: all)
  38  *   resume [thread id(s)]     -- resume threads (default: all)
  39  *   where [thread id] | all   -- dump a thread's stack
  40  *   wherei [thread id] | all  -- dump a thread's stack, with pc info
  41  *   up [n frames]             -- move up a thread's stack
  42  *   down [n frames]           -- move down a thread's stack
  43  *   kill <thread> <expr>      -- kill a thread with the given exception object
  44  *   interrupt <thread>        -- interrupt a thread
  45  *
  46  *   print <expr>              -- print value of expression
  47  *   dump <expr>               -- print all object information


 102  *   enablegc <expr>           -- permit garbage collection of an object
 103  *
 104  *   !!                        -- repeat last command
 105  *   <n> <command>             -- repeat command n times
 106  *   help (or ?)               -- list commands
 107  *   version                   -- print version information
 108  *   exit (or quit)            -- exit debugger
 109  *
 110  *   <class id>: full class name with package qualifiers or a
 111  *   pattern with a leading or trailing wildcard ('*').
 112  *   <thread id>: thread number as reported in the 'threads' command
 113  *   <expr>: a Java(tm) Programming Language expression.
 114  *   Most common syntax is supported.
 115  *
 116  *   Startup commands can be placed in either "jdb.ini" or ".jdbrc"
 117  *   in user.home or user.dir
 118  */
 119 public class JdbCommand {
 120     final String cmd;
 121     boolean allowExit = false;
 122     // Default pattern to wait for command to complete
 123     Pattern waitForPattern = Jdb.PROMPT_REGEXP;
 124 
 125     public JdbCommand(String cmd) {
 126         this.cmd = cmd;
 127     }
 128 
 129     public JdbCommand allowExit() {
 130         allowExit = true;
 131         return this;
 132     }
 133 
 134     public JdbCommand waitForPrompt(String pattern, boolean isMultiline) {
 135         waitForPattern = Pattern.compile(pattern, isMultiline ? Pattern.MULTILINE : 0);
 136         return this;
 137     }
 138 
 139 
 140     public static JdbCommand run(String ... params) {
 141         return new JdbCommand("run " + Arrays.stream(params).collect(Collectors.joining(" ")));
 142     }
 143     public static JdbCommand cont() {
 144         return new JdbCommand("cont");
 145     }
 146     public static JdbCommand dump(String what) {
 147         return new JdbCommand("dump " + what);
 148     }
 149     public static JdbCommand quit() {
 150         // the command suppose jdb terminates
 151         return new JdbCommand("quit").allowExit();
 152     }
 153     public static JdbCommand stopAt(String targetClass, int lineNum) {
 154         return new JdbCommand("stop at " + targetClass + ":" + lineNum);
 155     }
 156     public static JdbCommand stopThreadAt(String targetClass, int lineNum) {
 157         return new JdbCommand("stop thread at " + targetClass + ":" + lineNum);
 158     }
 159     public static JdbCommand stopGoAt(String targetClass, int lineNum) {
 160         return new JdbCommand("stop go at " + targetClass + ":" + lineNum);
 161     }
 162     public static JdbCommand stopIn(String targetClass, String methodName) {
 163         return new JdbCommand("stop in " + targetClass + "." + methodName);
 164     }
 165     public static JdbCommand thread(int threadNumber) {
 166         return new JdbCommand("thread " + threadNumber);
 167     }
 168     // clear <class id>:<line>   -- clear a breakpoint at a line
 169     public static JdbCommand clear(String targetClass, int lineNum) {
 170         return new JdbCommand("clear " + targetClass + ":" + lineNum);
 171     }
 172 
 173     // exception type used by catch/ignore
 174     public enum ExType{
 175         uncaught,
 176         caught,
 177         all
 178     }
 179     public static JdbCommand catch_(String classId) {
 180         return new JdbCommand("catch " + classId);
 181     }
 182     public static JdbCommand catch_(ExType eType, String classId) {
 183         return catch_(eType.toString() + " " + classId);
 184     }
 185     public static JdbCommand ignore(String classId) {
 186         return new JdbCommand("ignore " + classId);
 187     }


< prev index next >