0N/A#!/bin/sh
0N/A
0N/A#
2362N/A# Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A#
0N/A# This code is free software; you can redistribute it and/or modify it
0N/A# under the terms of the GNU General Public License version 2 only, as
0N/A# published by the Free Software Foundation.
0N/A#
0N/A# This code is distributed in the hope that it will be useful, but WITHOUT
0N/A# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A# version 2 for more details (a copy is included in the LICENSE file that
0N/A# accompanied this code).
0N/A#
0N/A# You should have received a copy of the GNU General Public License version
0N/A# 2 along with this work; if not, write to the Free Software Foundation,
0N/A# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A#
2362N/A# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A# or visit www.oracle.com if you need additional information or have any
2362N/A# questions.
0N/A#
0N/A
0N/A# @test
0N/A# @bug 6202891
0N/A# @summary TTY: Add support for method exit event return values to jdb
0N/A# @author Jim Holmlund
0N/A# @run shell JdbMethodExitTest.sh
0N/A
0N/A# These are variables that can be set to control execution
0N/A
0N/A#pkg=untitled7
0N/Aclassname=JdbMethodExitTest
0N/AcompileOptions=-g
0N/A#java="java_g"
0N/A#set -x
0N/A
0N/AcreateJavaFile()
0N/A{
0N/A cat <<EOF > $classname.java.1
0N/Aimport java.util.*;
0N/Aimport java.net.URLClassLoader;
0N/Aimport java.net.URL;
0N/A
0N/A/*
0N/A * This tests the jdb trace command
0N/A */
0N/A
0N/Aclass $classname {
0N/A // These are the values that will be returned by the methods
0N/A static URL[] urls = new URL[1];
0N/A public static byte byteValue = 89;
0N/A public static char charValue = 'x';
0N/A public static double doubleValue = 2.2;
0N/A public static float floatValue = 3.3f;
0N/A public static int intValue = 1;
0N/A public static short shortValue = 8;
0N/A public static boolean booleanValue = false;
0N/A
0N/A public static Class classValue = Object.class;
0N/A public static ClassLoader classLoaderValue;
0N/A {
0N/A try {
0N/A urls[0] = new URL("hi there");
0N/A } catch (java.net.MalformedURLException ee) {
0N/A }
0N/A classLoaderValue = new URLClassLoader(urls);
0N/A }
0N/A
0N/A public static Thread threadValue;
0N/A public static ThreadGroup threadGroupValue;
0N/A public static String stringValue = "abc";
0N/A public static int[] intArrayValue = new int[] {1, 2, 3};
0N/A
0N/A public static $classname objectValue =
0N/A new $classname();
0N/A public String ivar = stringValue;
0N/A
0N/A // These are the instance methods
0N/A public byte i_bytef() { return byteValue; }
0N/A public char i_charf() { return charValue; }
0N/A public double i_doublef() { return doubleValue; }
0N/A public float i_floatf() { return floatValue; }
0N/A public int i_intf() { return intValue; }
0N/A public short i_shortf() { return shortValue; }
0N/A public boolean i_booleanf() { return booleanValue; }
0N/A public String i_stringf() { return stringValue; }
0N/A public Class i_classf() { return classValue; }
0N/A public ClassLoader i_classLoaderf()
0N/A { return classLoaderValue; }
0N/A public Thread i_threadf() { return threadValue = Thread.currentThread(); }
0N/A public ThreadGroup i_threadGroupf()
0N/A { return threadGroupValue = threadValue.getThreadGroup(); }
0N/A public int[] i_intArrayf() { return intArrayValue; }
0N/A public Object i_nullObjectf() { return null; }
0N/A public Object i_objectf() { return objectValue; }
0N/A public void i_voidf() {}
0N/A
0N/A static void doit($classname xx) {
0N/A
0N/A xx.i_bytef();
0N/A xx.i_charf();
0N/A xx.i_doublef();
0N/A xx.i_floatf();
0N/A xx.i_intf();
0N/A xx.i_shortf();
0N/A xx.i_booleanf();
0N/A xx.i_stringf();
0N/A xx.i_intArrayf();
0N/A xx.i_classf();
0N/A xx.i_classLoaderf();
0N/A xx.i_threadf();
0N/A xx.i_threadGroupf();
0N/A xx.i_nullObjectf();
0N/A xx.i_objectf();
0N/A xx.i_voidf();
0N/A
0N/A // Prove it works for native methods too
0N/A StrictMath.sin(doubleValue);
0N/A stringValue.intern();
0N/A }
0N/A
0N/A public static void bkpt() {
0N/A int i = 0; //@1 breakpoint
0N/A }
0N/A
0N/A public static String traceMethods() {
0N/A return "traceMethods";
0N/A }
0N/A
0N/A public static String traceMethods1() {
0N/A return "traceMethods1";
0N/A }
0N/A
0N/A public static String traceExits() {
0N/A return "traceExits";
0N/A }
0N/A
0N/A public static String traceExits1() {
0N/A return "traceExits1";
0N/A }
0N/A
0N/A public static String traceExit() {
0N/A return "traceExit";
0N/A }
0N/A
0N/A public static String traceExit1() {
0N/A return "traceExit1";
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A // The debugger will stop at the start of main,
0N/A // enable method exit events, and then do
0N/A // a resume.
0N/A
0N/A $classname xx = new $classname();
0N/A
0N/A bkpt();
0N/A
0N/A // test all possible return types
0N/A doit(xx);
0N/A bkpt();
0N/A
0N/A // test trace methods
0N/A traceMethods();
0N/A
0N/A // test trace go methods
0N/A traceMethods1();
0N/A bkpt();
0N/A
0N/A // test trace method exits
0N/A traceExits();
0N/A
0N/A // test trace method exits
0N/A traceExits1();
0N/A bkpt();
0N/A
0N/A // test trace method exit
0N/A traceExit();
0N/A
0N/A // test trace method exit
0N/A traceExit1();
0N/A bkpt();
0N/A
0N/A }
0N/A}
0N/AEOF
0N/A}
0N/A
0N/A
0N/A# drive jdb by sending cmds to it and examining its output
0N/AdojdbCmds()
0N/A{
0N/A setBkpts @1
0N/A
0N/A # test all possible return types
0N/A runToBkpt @1
0N/A cmd untrace
0N/A
0N/A cmd trace methods
0N/A cmd trace
0N/A jdbFailIfNotPresent "trace methods in effect"
0N/A
0N/A cmd trace go methods
0N/A cmd trace
0N/A jdbFailIfNotPresent "trace go methods in effect"
0N/A
0N/A cmd trace method exits
0N/A cmd trace
0N/A jdbFailIfNotPresent "trace method exits in effect"
0N/A
0N/A cmd trace go method exits
0N/A cmd trace
0N/A jdbFailIfNotPresent "trace go method exits in effect"
0N/A
0N/A cmd trace method exit
0N/A cmd trace
0N/A jdbFailIfNotPresent "trace method exit in effect for JdbMethodExitTest.bkpt"
0N/A
0N/A cmd trace go method exit
0N/A cmd trace
0N/A jdbFailIfNotPresent "trace go method exit in effect for JdbMethodExitTest.bkpt"
0N/A
0N/A
0N/A # trace exit of methods with all the return values
0N/A # (but just check a couple of them)
0N/A cmd trace go exits
0N/A cmd cont
0N/A jdbFailIfNotPresent "instance of JdbMethodExitTest"
0N/A jdbFailIfNotPresent "return value = 8"
0N/A
0N/A # Get out of bkpt back to the call to traceMethods
0N/A cmd step up
0N/A
0N/A
0N/A cmd trace methods
0N/A cmd cont
0N/A jdbFailIfNotPresent "Method entered:"
0N/A cmd cont
0N/A jdbFailIfNotPresent "Method exited: return value = \"traceMethods\""
0N/A cmd step up
0N/A
0N/A
0N/A cmd trace go methods
0N/A cmd cont
0N/A jdbFailIfNotPresent "Method entered: \"thread=main\", JdbMethodExitTest.traceMethods1"
0N/A jdbFailIfNotPresent 'Method exited: .* JdbMethodExitTest.traceMethods1'
0N/A cmd untrace
0N/A cmd step up
0N/A
0N/A
0N/A cmd trace method exits
0N/A cmd cont
0N/A jdbFailIfNotPresent "Method exited: return value = \"traceExits\""
0N/A cmd untrace
0N/A cmd step up
0N/A
0N/A
0N/A cmd trace go method exits
0N/A cmd cont
0N/A jdbFailIfNotPresent 'Method exited: .* JdbMethodExitTest.traceExits1'
0N/A cmd untrace
0N/A cmd step up
0N/A
0N/A
0N/A cmd step # step into traceExit()
0N/A cmd trace method exit
0N/A cmd cont
0N/A jdbFailIfNotPresent "Method exited: return value = \"traceExit\""
0N/A cmd untrace
0N/A cmd step up
0N/A
0N/A
0N/A cmd step
0N/A cmd step # skip over setting return value in caller :-(
0N/A cmd trace go method exit
0N/A cmd cont
0N/A jdbFailIfNotPresent 'Method exited: .*JdbMethodExitTest.traceExit1'
0N/A cmd quit
0N/A}
0N/A
0N/A
0N/Amysetup()
0N/A{
0N/A if [ -z "$TESTSRC" ] ; then
0N/A TESTSRC=.
0N/A fi
0N/A
0N/A for ii in . $TESTSRC $TESTSRC/.. ; do
0N/A if [ -r "$ii/ShellScaffold.sh" ] ; then
0N/A . $ii/ShellScaffold.sh
0N/A break
0N/A fi
0N/A done
0N/A}
0N/A
0N/A# You could replace this next line with the contents
0N/A# of ShellScaffold.sh and this script will run just the same.
0N/Amysetup
0N/A
0N/Arunit
0N/AjdbFailIfNotPresent "Breakpoint hit"
0N/Apass