// This file is part of the program FRYSK. // // Copyright 2007, Red Hat Inc. // // FRYSK is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; version 2 of the License. // // FRYSK is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with FRYSK; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. // // In addition, as a special exception, Red Hat, Inc. gives You the // additional right to link the code of FRYSK with code not covered // under the GNU General Public License ("Non-GPL Code") and to // distribute linked combinations including the two, subject to the // limitations in this paragraph. Non-GPL Code permitted under this // exception must only link to the code of FRYSK through those well // defined interfaces identified in the file named EXCEPTION found in // the source code files (the "Approved Interfaces"). The files of // Non-GPL Code may instantiate templates or use macros or inline // functions from the Approved Interfaces without causing the // resulting work to be covered by the GNU General Public // License. Only Red Hat, Inc. may make changes or additions to the // list of Approved Interfaces. You must obey the GNU General Public // License in all respects for all of the FRYSK code and other code // used in conjunction with FRYSK except the Non-GPL Code covered by // this exception. If you modify this file, you may extend this // exception to your version of the file, but you are not obligated to // do so. If you do not wish to provide this exception without // modification, you must delete this exception statement from your // version and license this file solely under the GPL without // exception. package frysk.rt; import java.text.ParseException; import java.util.LinkedList; import java.util.Observable; import java.util.Observer; import javax.naming.NameNotFoundException; import frysk.debuginfo.DebugInfo; import frysk.proc.Manager; import frysk.proc.Proc; import frysk.proc.Task; import frysk.proc.TestLib; import frysk.value.Value; public class TestDisplay extends TestLib { private Task myTask; private Proc myProc; public void setUp () { super.setUp (); } public void tearDown () { super.tearDown (); } public void testVarValueChanged() { // Start the daemon process // AckDaemonProcess process = new AckDaemonProcess(Sig.USR1, // new String[]{ // getExecPath("funit-rt-varchange"), // ""+ Pid.get(), // ""+ Sig.USR1_ // }); AttachedDaemonProcess process = new AttachedDaemonProcess(new String[]{"/home/ajocksch/src/tests/dummy"}); // Attach to the process myTask = process.mainTask;//findTaskUsingRefresh(true); // TaskObserver.Attached blocker = new TaskObserver.Attached() // { // public void deletedFrom (Object observable) {} // public void addedTo (Object observable) {} // public void addFailed (Object observable, Throwable w) {} // // public Action updateAttached (Task task) // { //// System.err.println("Attached to task"); // Manager.eventLoop.requestStop(); // return Action.BLOCK; // } // }; // myTask.requestAddAttachedObserver(blocker); // assertRunUntilStop("Attaching to process"); // Get the process myProc = myTask.getProc(); assertNotNull(myTask); assertNotNull(myProc); // Set up the stepping engine, breakpoint manager, and symbol table SteppingEngine.setProc(myProc); BreakpointManager bpManager = SteppingEngine.getBreakpointManager(); SteppingEngine.addObserver(new Observer() { public void update (Observable observable, Object arg) { // Thread.dumpStack(); // System.err.println("updated"); // System.err.println(arg); Manager.eventLoop.requestStop(); } }); assertRunUntilStop("Adding to Stepping Engine"); /* * Add the first breakpoint: * void loop () * { * lock = 0; * while(1){ * int x = 1; * x = 2; <---- Breakpoint (line 25) * x = 3; * } * } */ LineBreakpoint brk1 = bpManager.addLineBreakpoint("/home/ajocksch/src/tests/dummy.c",//Config.getRootSrcDir() + "frysk-core/frysk/pkglibdir/funit-rt-varchange.c", 4, 0); brk1.addObserver(new SourceBreakpointObserver() { public void deletedFrom (Object observable) {} public void addedTo (Object observable) { // System.err.println("Added!"); } public void addFailed (Object observable, Throwable w) {} public void updateHit (SourceBreakpoint breakpoint, Task task, long address) { // System.err.println("hit!"); Manager.eventLoop.requestStop(); } }); bpManager.enableBreakpoint(brk1, myTask); // Let the process continue until we hit the breakpoint LinkedList list = new LinkedList(); list.add(myTask); SteppingEngine.continueExecution(list); process.resume(); // myTask.requestUnblock(blocker); // Manager.eventLoop.runPending(); assertRunUntilStop("First breakpoint"); System.err.println(myTask); DebugInfo info = new DebugInfo(myTask.getTid(), myProc, myTask, StackFactory.createFrame(myTask)); info.toString(); // XXX: make the compiler happy Value val = null; try{ val = DebugInfo.print("x"); } catch (ParseException e) { e.printStackTrace(); } catch (NameNotFoundException e) { e.printStackTrace(); } System.err.println(val); assertNotNull(val); Display disp = new Display(val); System.err.println("TADA"); // Check the value of the variable 'x', make sure it's equal to one Value firstVal = disp.getValue(); assertNotNull(firstVal); assertEquals("Variable value at first breakpoint", firstVal.getInt(), 1); /* * Add the second breakpoint: * void loop () * { * lock = 0; * while(1){ * int x = 1; * x = 2; * x = 3; <---- Breakpoint (line 26) * } * } */ } }