1 /* 2 * Copyright (c) 2002, 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 /* 25 * @test 26 * @bug 4777868 27 * @summary Compile with java -g, do a RedefineClasses, and you don't get local vars 28 * @comment converted from test/jdk/com/sun/jdi/Redefine-g.sh 29 * 30 * @library /test/lib 31 * @compile RedefineG.java 32 * @run main/othervm RedefineG 33 */ 34 35 import jdk.test.lib.process.OutputAnalyzer; 36 import lib.jdb.JdbCommand; 37 import lib.jdb.JdbTest; 38 39 40 // Compile the first version without -g and the 2nd version with -g. 41 class RedefineGTarg { RedefineGTarg()42 public RedefineGTarg() { 43 } main(String[] args)44 public static void main(String[] args){ 45 int gus=22; 46 RedefineGTarg kk=new RedefineGTarg(); 47 kk.m1("ab"); 48 } 49 m1(String p1)50 void m1(String p1) { 51 int m1l1 = 1; 52 System.out.println("m1(String) called"); 53 m1(p1, "2nd"); 54 // @1 uncomment System.out.println("Hello Milpitas!"); 55 } 56 m1(String p1, String p2)57 void m1(String p1, String p2) { 58 int m1l2 = 2; 59 System.out.println("m2" + p1 + p2); // @1 breakpoint 60 } 61 62 } 63 64 public class RedefineG extends JdbTest { main(String argv[])65 public static void main(String argv[]) { 66 new RedefineG().run(); 67 } 68 RedefineG()69 private RedefineG() { 70 super(DEBUGGEE_CLASS, 71 "RedefineG.java"); 72 } 73 74 private static final String DEBUGGEE_CLASS = RedefineGTarg.class.getName(); 75 76 @Override runCases()77 protected void runCases() { 78 setBreakpoints(1); 79 jdb.command(JdbCommand.run()); 80 jdb.command(JdbCommand.where("")); 81 jdb.command(JdbCommand.locals()); 82 83 redefineClass(1, "-g"); 84 jdb.command(JdbCommand.where("")); 85 jdb.command(JdbCommand.locals()); 86 87 jdb.command(JdbCommand.pop()); 88 jdb.command(JdbCommand.where("")); 89 jdb.command(JdbCommand.locals()); 90 91 jdb.command(JdbCommand.pop()); 92 jdb.command(JdbCommand.where("")); 93 jdb.command(JdbCommand.locals()); 94 95 jdb.contToExit(1); 96 97 new OutputAnalyzer(getJdbOutput()) 98 .shouldContain("p1 = \"ab\"") 99 .shouldContain("p2 = \"2nd\"") 100 .shouldContain("m1l2 = 2") 101 .shouldNotContain("m1l1") 102 .shouldContain("args = instance of java.lang.String") 103 .shouldContain("gus = 22") 104 .shouldContain("kk = instance of " + DEBUGGEE_CLASS); 105 } 106 } 107