1 /*
2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
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 nsk.jdi.StringReference.value;
25 
26 import nsk.share.*;
27 import nsk.share.jpda.*;
28 import nsk.share.jdi.*;
29 
30 import java.io.*;
31 
32 /**
33  * This class is used as debuggee application for the value001a JDI test.
34  */
35 
36 public class value001a {
37 
38     //----------------------------------------------------- templete section
39 
40     static final int PASSED = 0;
41     static final int FAILED = 2;
42     static final int PASS_BASE = 95;
43 
44     //--------------------------------------------------   log procedures
45 
46     static boolean verbMode = false;  // debugger may switch to true
47 
log1(String message)48     private static void log1(String message) {
49         if (verbMode)
50             System.err.println("**> value001a: " + message);
51     }
52 
logErr(String message)53     private static void logErr(String message) {
54         if (verbMode)
55             System.err.println("!!**> value001a: " + message);
56     }
57 
58     //====================================================== test program
59     //................................................... globals for a debugger
60 
61     static ClassForCheck class1 = null;
62 
63     //....................................................
64     //----------------------------------------------------   main method
65 
main(String argv[])66     public static void main (String argv[]) {
67 
68         int result = new value001a().runThis(argv, System.out);
69 
70         System.exit(result + PASS_BASE);
71     }
72 
73 
runThis(String argv[], PrintStream out)74     private static int runThis (String argv[], PrintStream out) {
75 
76         for (int i=0; i<argv.length; i++) {
77             if ( argv[i].equals("-vbs") || argv[i].equals("-verbose") ) {
78                 verbMode = true;
79                 break;
80             }
81         }
82         log1("debuggee started!");
83 
84         // informing a debugger of readyness
85         ArgumentHandler argHandler = new ArgumentHandler(argv);
86         IOPipe pipe = argHandler.createDebugeeIOPipe();
87         pipe.println("ready");
88 
89 
90         int exitCode = PASSED;
91         for (int i = 0; ; i++) {
92 
93             String instruction;
94 
95             if (exitCode == FAILED) break ;
96 
97             log1("waiting for an instruction from the debugger ...");
98             instruction = pipe.readln();
99             if (instruction.equals("quit")) {
100                 log1("'quit' recieved");
101                 break ;
102 
103             } else if (instruction.equals("newcheck")) {
104                 switch (i) {
105 
106     //------------------------------------------------------  section tested
107 
108                 case 0: class1 = new ClassForCheck();
109                         pipe.println("checkready");
110                         instruction = pipe.readln();
111                         if (!instruction.equals("continue")){
112                             logErr("ERRROR: unexpected instruction: " +
113                                    instruction);
114                             exitCode = FAILED;
115                         } else {
116                             class1 = null;
117                             pipe.println("docontinue");
118                         }
119                         break ;
120 
121     //-------------------------------------------------    standard end section
122 
123                 default:
124                                 pipe.println("checkend");
125                                 break ;
126                 }
127 
128             } else {
129                 logErr("ERRROR: unexpected instruction: " + instruction);
130                 exitCode = FAILED;
131                 break ;
132             }
133         }
134 
135         return exitCode;
136     }
137 }
138 
139 
140 class ClassForCheck {
141 
142 static String str = "abc";
143 
144 }
145