LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Find Resources
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Thu Nov 29 16:34:59 CET 2007
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/07/11 29:16:34

    Modified: jop/java/tools/src/com/jopdesign/debug/jdwp/test
    TestJopServer.java
    Log:
    Change to help during code development.

    Added methods and constants to provide a very basic

    (but still interactive) debug interface, to be used

    during the development of the JopDebugKernel class.



    - Added constants to control testing

    - Added methods to request more information from JOP

    - Changed main() to allow running both an automatic and

    an interactive set of tests.

    - Added methods to change the way printing is being done,

    to avoid issues with Ant (need to flush() for every print()).





    Methods changed:

    89: public static void main(String[] args) throws IOException

    634: public void testJopSimCommunication(String symbolFile) throws IOException, ClassNotFoundException

    - Changed test sequence to avoid allowing JopSim to hit the breakpoint.

    It currently can't handle properly new bytecodes, without

    changing JopSim directly.



    193: private void testSetBreakPoint_getConstant() throws IOException

    266: private void testMethodCalls() throws IOException

    283: private void testGetStackFrameList() throws IOException

    297: private void testInvokeStatic_2(String className, String methodName)

    298: throws IOException

    343: private void testStackAccess() throws IOException

    380: private void initialize(String symbolFile) throws IOException, ClassNotFoundException





    Methods created:

    174: public void testJopDebugKernelInteractively(String symbolFile)

    265: private void interactiveTestGetLocalVariable(BufferedReader reader) throws IOException

    305: private boolean isValidLocalVariableIndex(int frameIndex, int variableIndex)

    331: private boolean isValidStackFrameIndex(int frameIndex) throws IOException

    354: private void interactiveTestSetLocalVariable(BufferedReader reader) throws IOException

    392: private void interactiveTestPrintStackDepth(BufferedReader reader) throws IOException

    406: private void interactiveTestPrintStackFrame(BufferedReader reader) throws IOException

    428: private void interactiveTestDumpCallStack(BufferedReader reader)

    438: private void interactiveTestInvokeStaticMethod(BufferedReader reader)

    462: private static void print(Object data)

    474: private static void print(int data)

    486: private static void println(Object data)

    498: private static void println(int data)

    510: private static void println()

    519: private boolean isValidMethodPointer(int methodStructPointer)

    528: private void interactiveTestResumeExecution(BufferedReader reader)

    538: private void interactiveTestExit(BufferedReader reader) throws IOException

    546: private void printCommandMenu()

    585: private void printLine()
    593: private int readCommand(BufferedReader reader) 603: private static int readNonNegativeInteger(BufferedReader reader) Revision Changes Path 1.3 jop/java/tools/src/com/jopdesign/debug/jdwp/test/TestJopServer.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/debug/jdwp/test/TestJopServer.java.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: TestJopServer.java =================================================================== RCS file: /cvsroot/paulo/jop/java/tools/src/com/jopdesign/debug/jdwp/test/TestJopServer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- TestJopServer.java 8 Nov 2007 13:36:12 -0000 1.2 +++ TestJopServer.java 29 Nov 2007 15:34:59 -0000 1.3 @@ -21,7 +21,10 @@ package com.jopdesign.debug.jdwp.test; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.net.SocketException; import com.jopdesign.debug.jdwp.JOPDebugChannel; import com.jopdesign.debug.jdwp.SymbolManager; @@ -71,6 +74,20 @@ private static final String METHOD_NAME_TEST_INC = "testInc()I"; private static final String METHOD_NAME_GET_CONSTANT = "getConstant()I"; + // a few constants to control interactive testing + private static final int INVALID_OPTION = -1; + private static final int DUMP_CALL_STACK = 1; + private static final int PRINT_STACK_DEPTH = 2; + private static final int PRINT_STACK_FRAME = 3; + private static final int GET_LOCAL_VARIABLE = 4; + private static final int SET_LOCAL_VARIABLE = 5; + private static final int INVOKE_STATIC_METHOD = 6; + private static final int RESUME_EXECUTION = 7; + private static final int EXIT_OPTION = 8; + +// private static final int SET_BREAKPOINT = 9; +// private static final int CLEAR_BREAKPOINT = 10; + private JOPDebugChannel debugChannel; private SymbolManager manager; @@ -85,19 +102,55 @@ * @param args * @throws IOException * @throws ClassNotFoundException + * @throws ClassNotFoundException */ public static void main(String[] args) throws IOException { - if(args.length != 1) + if(args.length != 1 && args.length != 2) { - System.out.println(" Usage: TestJopServer <symbol file>"); - System.out.println(); + println(" Usage:"); + println(); + println(" Default test: TestJopServer <symbol file>"); + println(" Interactive test: TestJopServer <symbol file> -i"); + println(); + return; } TestJopServer testObject = new TestJopServer(); + + try + { + if(args.length == 1) + { testObject.testJopSimCommunication(args[0]); } + else + { + if(args.length == 2 && args[1].equals("-i")) + { + try + { + testObject.testJopDebugKernelInteractively(args[0]); + } + catch(SocketException exception) + { + println("Interrupted. Connection closed by the server."); + } + } + else + { + println("Failure: unexpected parameter -> " + args[1]); + } + } + } + catch (Exception exception) + { + println("Failure: " + exception.getMessage()); + println(); + exception.printStackTrace(); + } + } // public void basicCommunicationTest() throws IOException // { @@ -105,66 +158,505 @@ // int received; // // data = 1; -// System.out.println(" Will send " + data); +// println(" Will send " + data); // output.write(data); // // received = input.read(); // -// System.out.println(" Sent: " + data); -// System.out.println(" Received: " + received); +// println(" Sent: " + data); +// println(" Received: " + received); // if(data == received) // { -// System.out.println(" Success!!!"); +// println(" Success!!!"); // } // } + public void testJopDebugKernelInteractively(String symbolFile) throws IOException, ClassNotFoundException + { + int command; + boolean shouldContinue; + initialize(symbolFile); + + // create a reader to make it easy to read lines from the input + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + + // flag to control interactive loop + shouldContinue = true; + + // small loop to print a small menu, read a command from the user, + // send it to JOP, read back the answer, present it and continue. + do + { + printCommandMenu(); + + command = readCommand(reader); + + switch(command) + { + case GET_LOCAL_VARIABLE: + { + interactiveTestGetLocalVariable(reader); + break; + } + + case SET_LOCAL_VARIABLE: + { + interactiveTestSetLocalVariable(reader); + break; + } + + case PRINT_STACK_DEPTH: + { + interactiveTestPrintStackDepth(reader); + break; + } + + case PRINT_STACK_FRAME: + { + interactiveTestPrintStackFrame(reader); + break; + } + + case DUMP_CALL_STACK: + { + interactiveTestDumpCallStack(reader); + break; + } + + case INVOKE_STATIC_METHOD: + { + interactiveTestInvokeStaticMethod(reader); + break; + } + + case RESUME_EXECUTION: + { + interactiveTestResumeExecution(reader); + break; + } + + case EXIT_OPTION: + { + interactiveTestExit(reader); + // ok, stop execution here. + shouldContinue = false; + break; + } + // case SET_BREAKPOINT: { break; } + // case CLEAR_BREAKPOINT: { break; } + + case INVALID_OPTION: + default: + { + println("Invalid option. Ignoring."); + println(); + } + } + } + //while(command != EXIT_OPTION && command != RESUME_EXECUTION); + while(shouldContinue); + } + /** + * @param reader + * @throws IOException * + */ + private void interactiveTestGetLocalVariable(BufferedReader reader) throws IOException + { + int frameIndex, variableIndex; + int value; + + // get and test the stack frame index + print("Please input the stack frame index: "); + frameIndex = readNonNegativeInteger(reader); + + if(isValidStackFrameIndex(frameIndex) == false) + { + println("Failure: invalid stack frame index -> " + frameIndex); + println(); + return; + } + + // get and test the local variable index + print("Please input the local variable index: "); + variableIndex = readNonNegativeInteger(reader); + + if(isValidLocalVariableIndex(frameIndex, variableIndex) == false) + { + println("Failure: invalid local variable index -> " + variableIndex); + println(); + return; + } + + // get a local variable value + value = debugChannel.getLocalVariableValue(frameIndex, variableIndex); + + print("Value: "); + println(value); + } + + /** + * @param frameIndex + * @param variableIndex + * @return * @throws IOException - * @throws ClassNotFoundException */ - public void testJopSimCommunication(String symbolFile) throws IOException + private boolean isValidLocalVariableIndex(int frameIndex, int variableIndex) + throws IOException { - int received = 2; - int methodPointer; - int stackDepth; - int index; + int numOfLocalVariables; + boolean isValid = false; - try + if(isValidStackFrameIndex(frameIndex)) { - initialize(symbolFile); + numOfLocalVariables = debugChannel.getNumberOfLocalVariables(frameIndex); + if((variableIndex < 0) || (variableIndex >= numOfLocalVariables)) + { + isValid = false; } - catch(ClassNotFoundException exception) + else + { + isValid = true; + } + } + + return isValid; + } + + /** + * @param frameIndex + * @throws IOException + */ + private boolean isValidStackFrameIndex(int frameIndex) throws IOException + { + int depth; + boolean isValid = false; + + depth = debugChannel.getStackDepth(); + if(frameIndex < 0 || frameIndex >= depth) + { + isValid = false; + } + else { - System.out.println(); - System.out.println(" Class not found."); - System.out.println(exception.getMessage()); + isValid = true; + } + + return isValid; + } + + /** + * @param reader + * @throws IOException + * + */ + private void interactiveTestSetLocalVariable(BufferedReader reader) throws IOException + { + int frameIndex, variableIndex; + int value; + + println("Please input the stack frame index: "); + frameIndex = readNonNegativeInteger(reader); + + if(isValidStackFrameIndex(frameIndex) == false) + { + println("Failure: invalid stack frame index -> " + frameIndex); + println(); return; } - catch (Exception exception) + + // get and test the local variable index + print("Please input the local variable index: "); + variableIndex = readNonNegativeInteger(reader); + + if(isValidLocalVariableIndex(frameIndex, variableIndex) == false) { - System.out.println(); - System.out.println("Connection failure. Make sure the server is running."); + println("Failure: invalid local variable index -> " + variableIndex); + println(); return; } + println("Please input the new value: "); + value = readNonNegativeInteger(reader); + + debugChannel.setLocalVariableValue(frameIndex, variableIndex, value); + + println("Value updated."); + } + + /** + * @throws IOException + * + */ + private void interactiveTestPrintStackDepth(BufferedReader reader) throws IOException + { + int stackDepth; + + stackDepth = debugChannel.getStackDepth(); + + println("Stack depth: " + stackDepth); + println(); + } + + /** + * @throws IOException + * + */ + private void interactiveTestPrintStackFrame(BufferedReader reader) throws IOException + { + int frameIndex; + + // get and test the stack frame index + print("Please input the stack frame index: "); + frameIndex = readNonNegativeInteger(reader); + + if(isValidStackFrameIndex(frameIndex) == false) + { + println("Failure: invalid stack frame index -> " + frameIndex); + println(); + return; + } + + debugChannel.printStackFrame(frameIndex); + } + + /** + * @throws IOException + * + */ + private void interactiveTestDumpCallStack(BufferedReader reader) + throws IOException + { + debugChannel.printStackFrames(); + } + + /** + * @throws IOException + * + */ + private void interactiveTestInvokeStaticMethod(BufferedReader reader) + throws IOException + { + int methodStructPointer; + + print("Please input the method pointer : "); + methodStructPointer = readNonNegativeInteger(reader); + + if(isValidMethodPointer(methodStructPointer) == false) + { + println("Failure: invalid method pointer -> " + methodStructPointer); + println(); + return; + } + + debugChannel.invokeStaticMethod(methodStructPointer); + } + + /** + * Print an object to the standard output and flush the buffer. + * Created to better interact with Ant. + * + * @param data the object to be printed. + */ + private static void print(Object data) + { + System.out.println(data); + System.out.flush(); + } + + /** + * Print an int to the standard output and flush the buffer. + * Created to better interact with Ant. + * + * @param data the int to be printed. + */ + private static void print(int data) + { + System.out.print(data); + System.out.flush(); + } + + /** + * Print an object to the standard output, a newline and flush the buffer. + * Created to better interact with Ant. + * + * @param data the object to be printed. + */ + private static void println(Object data) + { + System.out.println(data); + System.out.flush(); + } + + /** + * Print an int to the standard output, a newline and flush the buffer. + * Created to better interact with Ant. + * + * @param data the int to be printed. + */ + private static void println(int data) + { + System.out.println(data); + System.out.flush(); + } + + /** + * Print a newline to the standard output and flush the buffer. + * Created to better interact with Ant. + * + * @param data the int to be printed. + */ + private static void println() + { + System.out.println(""); + System.out.flush(); + } + /** + * @param methodStructPointer + * @return + */ + private boolean isValidMethodPointer(int methodStructPointer) + { + return manager.isValidMethodStructurePointer(methodStructPointer); + } + + /** + * @throws IOException + * + */ + private void interactiveTestResumeExecution(BufferedReader reader) + throws IOException + { + debugChannel.sendResumeCommand(); + } + + /** + * @throws IOException + * + */ + private void interactiveTestExit(BufferedReader reader) throws IOException + { + debugChannel.sendExitCommand(0); + } + + /** + * + */ + private void printCommandMenu() + { + printLine(); + + print(DUMP_CALL_STACK); + println(". Dump the call stack"); + + print(PRINT_STACK_DEPTH); + println(". Print stack depth"); + + print(PRINT_STACK_FRAME); + println(". Print a stack frame"); + + print(GET_LOCAL_VARIABLE); + println(". Get a local variable"); + + print(SET_LOCAL_VARIABLE); + println(". Set a local variable"); + + print(INVOKE_STATIC_METHOD); + println(". Invoke a static method"); + + print(RESUME_EXECUTION); + println(". Resume execution (return from breakpoint call)"); + + print(EXIT_OPTION); + println(". Terminate execution: call System.exit()"); +// print(SET_BREAKPOINT); +// println(". "); +// print(CLEAR_BREAKPOINT); +// println(". "); + + println(); + printLine(); + } + + /** + * + */ + private void printLine() + { + println("----------------------------------------"); + } + + /** + * @return + */ + private int readCommand(BufferedReader reader) + { + int data; + + print("Next command: "); + data = readNonNegativeInteger(reader); + + return data; + } + + private static int readNonNegativeInteger(BufferedReader reader) + { + String text; + int data; + + data = INVALID_OPTION; + + try + { + text = reader.readLine(); + text = text.trim(); + data = Integer.parseInt(text); + } + catch(IOException exception) + { + exception.printStackTrace(); + } + catch(NumberFormatException exception) + { + data = INVALID_OPTION; + } + + return data; + } + + /** + * + * @throws IOException + * @throws ClassNotFoundException + * @throws ClassNotFoundException + */ + public void testJopSimCommunication(String symbolFile) throws IOException, ClassNotFoundException + { + int received = 2; + int methodPointer; + int stackDepth; + int index; + + initialize(symbolFile); + testStackAccess(); testMethodCalls(); // // this does not work, don't try it. -// System.out.println("Invoking the debug method now"); +// println("Invoking the debug method now"); //// methodPointer = 9207; //// methodPointer = 9119; //// methodPointer = 9556; // debugChannel.invokeStaticMethod(methodPointer, 65); -// System.out.println("Returning"); +// println("Returning"); //// debugChannel.requestExit(0); testGetStackFrameList(); // testEmbeddedprinter(); -// System.out.println("Returning"); +// println("Returning"); // debugChannel.requestExit(); // this test worked fine. @@ -172,18 +664,18 @@ received = testSetBreakPoint_identity(); - System.out.println("Resuming"); - debugChannel.resume(); +// println("Resuming"); +// debugChannel.resume(); // -//// System.out.println("If the next breakpoint it hit, shoud call 'printLine'now:"); +//// println("If the next breakpoint it hit, shoud call 'printLine'now:"); //// testInvokeStatic_2(DEBUG_TEST_JOP_DEBUG_KERNEL, METHOD_NAME_PRINT_LINE_V); // - System.out.println("Will clear the previous breakpoint now:"); + println("Will clear the previous breakpoint now:"); testClearBreakPoint_identity(received); - debugChannel.resume(); -// System.out.print("Available: "); -// System.out.println(input.available()); + debugChannel.sendResumeCommand(); +// print("Available: "); +// println(input.available()); } /** @@ -206,7 +698,7 @@ if(table.numLines() <= 0) { - System.out.println("Failure: empty line table!"); + println("Failure: empty line table!"); return; } @@ -215,14 +707,14 @@ offset = 5; num = manager.getMethodSizeInBytes(className, methodSignature); - System.out.println("Method size: " + num); + println("Method size: " + num); for(i = 0; i < num; i++) { offset = i; - System.out.println("Will set a breakpoint!"); + println("Will set a breakpoint!"); oldInstruction = debugChannel.setBreakPoint(methodPointer, offset); - System.out.println("Will clear the breakpoint!"); + println("Will clear the breakpoint!"); oldInstruction = debugChannel.clearBreakPoint(methodPointer, offset, oldInstruction); } } @@ -265,13 +757,13 @@ */ private void testMethodCalls() throws IOException { - System.out.println("Will request the machine to call some methods now."); - System.out.println("If an exception is thrown, check the method struct addresses."); - System.out.println("They should be correct since they came from the symbol file."); - System.out.println(); - System.out.println("Methods to be called:"); - System.out.println(" helloworld.TestJopDebugKernel.printValue(I)V"); - System.out.println(" helloworld.TestJopDebugKernel.printLine()V"); + println("Will request the machine to call some methods now."); + println("If an exception is thrown, check the method struct addresses."); + println("They should be correct since they came from the symbol file."); + println(); + println("Methods to be called:"); + println(" helloworld.TestJopDebugKernel.printValue(I)V"); + println(" helloworld.TestJopDebugKernel.printLine()V"); testInvokeStatic_1(DEBUG_TEST_JOP_DEBUG_KERNEL, METHOD_NAME_PRINT_VALUE_I_V); testInvokeStatic_2(DEBUG_TEST_JOP_DEBUG_KERNEL, METHOD_NAME_PRINT_LINE_V); @@ -284,9 +776,9 @@ { FrameList list = debugChannel.getStackFrameList(); - System.out.println(); - System.out.println("Frame list:"); - System.out.println(list); + println(); + println("Frame list:"); + println(list); } /** @@ -297,7 +789,7 @@ private void testInvokeStatic_2(String className, String methodName) throws IOException { - System.out.println(" Invoking a static method 4 times now..."); + println(" Invoking a static method 4 times now..."); int methodPointer; // call the debug module from itself, just to see what happens @@ -349,42 +841,64 @@ stackDepth = debugChannel.getStackDepth(); received = debugChannel.getLocalVariableValue(0, 1); - System.out.println("Local variable(0, 1): " + received); + println("Local variable(0, 1): " + received); debugChannel.setLocalVariableValue(0, 1, 32); received = debugChannel.getLocalVariableValue(0, 1); - System.out.println("After setting to 32, value is: " + received); + println("After setting to 32, value is: " + received); debugChannel.setLocalVariableValue(0, 1, 48); received = debugChannel.getLocalVariableValue(0, 1); - System.out.println("After setting to 48, value is: " + received); + println("After setting to 48, value is: " + received); - System.out.print("Stack depth: "); - System.out.println(stackDepth); - System.out.println(); + print("Stack depth: "); + println(stackDepth); + println(); for(index = 0; index <= stackDepth; index++) { methodPointer = debugChannel.getMethodPointer(index); - System.out.print("Method pointer at frame "); - System.out.print(index); - System.out.print(" is: "); - System.out.println(methodPointer); + print("Method pointer at frame "); + print(index); + print(" is: "); + println(methodPointer); } } /** + * Connect to the server and load the symbol file. + * * @param symbolFile * @throws IOException * @throws ClassNotFoundException */ private void initialize(String symbolFile) throws IOException, ClassNotFoundException { + try + { debugChannel.connect(); // handshake(); + } + catch (IOException exception) + { + println(); + println("Connection failure. Please make sure the server is running."); + throw exception; + } // load symbols to know the method addresses + try + { manager.loadSymbolTable(symbolFile); - System.out.println("Loaded symbols."); + println("Loaded symbols."); + } + catch(ClassNotFoundException exception) + { + println(); + println(" Class not found."); + println(exception.getMessage()); + throw exception; +// return; + } } /** @@ -404,33 +918,33 @@ // // if(value != index) // { -// System.out.println(" Value: " + value + " Expected: " + index); +// println(" Value: " + value + " Expected: " + index); // result = false; // } // else // { //// if((index & 63) == 0) //// { -//// System.out.println("."); +//// println("."); //// } //// else //// { -//// System.out.print("."); +//// print("."); //// } // // print index at every 1023 elements // if((index & 0x3ff) == 0) // { -// System.out.println(index); +// println(index); // } // } // } // if(result) // { -// System.out.println("Passed!"); +// println("Passed!"); // } // else // { -// System.out.println("Failed."); +// println("Failed."); // } // } @@ -446,9 +960,9 @@ // // if(value != index) // { -// System.out.println(" Value: " + value + " Expected: " + index); +// println(" Value: " + value + " Expected: " + index); // } // } -// System.out.println("Done."); +// println("Done."); // } }

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.