This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] master: Re-implement StackCommands; merge in WhereCommand, add "frame".


The branch, master has been updated
       via  ed081c0d3afa9702c4d2bbce9ffa39fd02bce1f3 (commit)
      from  0af7f15678cc58ed51713bb1c76fb384aa58be6c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit ed081c0d3afa9702c4d2bbce9ffa39fd02bce1f3
Author: Andrew Cagney <cagney@redhat.com>
Date:   Mon Nov 12 16:22:22 2007 -0500

    Re-implement StackCommands; merge in WhereCommand, add "frame".
    
    frysk-core/frysk/debuginfo/ChangeLog
    2007-11-12  Andrew Cagney  <cagney@redhat.com>
    
    	* DebugInfoStackFactory.java (printStackTrace): Handle -ve
    	numberOfFrames.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-12  Andrew Cagney  <cagney@redhat.com>
    
    	* TestStackCommands.java (testFrame()): New.
    	* StackCommands.java (Up): New.
    	(Down): New.
    	(Frame): New.
    	* TopLevelCommand.java: Update.
    	* CommandOption.java (Mangitude): Copy to ...
    	* Magnitude.java: ... here.  New.
    	* ListCommand.java: Update.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/debuginfo/ChangeLog               |    5 +-
 .../frysk/debuginfo/DebugInfoStackFactory.java     |   13 +-
 frysk-core/frysk/hpd/ChangeLog                     |    9 +
 frysk-core/frysk/hpd/CommandOption.java            |   20 --
 frysk-core/frysk/hpd/ListCommand.java              |    2 +-
 .../hpd/{AssignCommand.java => Magnitude.java}     |   34 ++--
 frysk-core/frysk/hpd/StackCommands.java            |  226 ++++++++++++++++----
 frysk-core/frysk/hpd/TestStackCommands.java        |    7 +
 frysk-core/frysk/hpd/TopLevelCommand.java          |    7 +-
 frysk-core/frysk/hpd/WhereCommand.java             |  115 ----------
 10 files changed, 237 insertions(+), 201 deletions(-)
 copy frysk-core/frysk/hpd/{AssignCommand.java => Magnitude.java} (79%)
 delete mode 100644 frysk-core/frysk/hpd/WhereCommand.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/debuginfo/ChangeLog b/frysk-core/frysk/debuginfo/ChangeLog
index be11fec..9f1cd01 100644
--- a/frysk-core/frysk/debuginfo/ChangeLog
+++ b/frysk-core/frysk/debuginfo/ChangeLog
@@ -1,5 +1,8 @@
 2007-11-12  Andrew Cagney  <cagney@redhat.com>
-	
+
+	* DebugInfoStackFactory.java (printStackTrace): Handle -ve
+	numberOfFrames.
+
 	* TestFrameDebugInfo.java: Update; funit-inlined renamed to
 	funit-stack-inlined.
 
diff --git a/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java b/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java
index effea88..325c389 100644
--- a/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java
+++ b/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java
@@ -128,10 +128,17 @@ public class DebugInfoStackFactory {
         for (DebugInfoFrame frame = topFrame; frame != null;
 	     frame = frame.getOuterDebugInfoFrame()) {
             
-	    if (numberOfFrames > 0 && count++ >= numberOfFrames) {
-		writer.println("...");
-		break;
+	    // Terminate early?
+	    if (numberOfFrames > 0) {
+		if (count >= numberOfFrames) {
+		    writer.println("...");
+		    break;
+		}
+	    } else if (numberOfFrames < 0) {
+		if (count >= -numberOfFrames)
+		    break;
 	    }
+	    count++;
 
 	    frame.printLevel(writer);
 	    writer.print(" ");
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 0defec5..5f65f6c 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,5 +1,14 @@
 2007-11-12  Andrew Cagney  <cagney@redhat.com>
 
+	* TestStackCommands.java (testFrame()): New.
+	* StackCommands.java (Up): New.
+	(Down): New.
+	(Frame): New.
+	* TopLevelCommand.java: Update.
+	* CommandOption.java (Mangitude): Copy to ...
+	* Magnitude.java: ... here.  New.
+	* ListCommand.java: Update.
+
 	* StackCommands.java: Rename FrameCommands.java.
 	* TopLevelCommand.java: Update.
 	* TestStackCommands.java: New.
diff --git a/frysk-core/frysk/hpd/CommandOption.java b/frysk-core/frysk/hpd/CommandOption.java
index 5672fbd..5f795a1 100644
--- a/frysk-core/frysk/hpd/CommandOption.java
+++ b/frysk-core/frysk/hpd/CommandOption.java
@@ -85,26 +85,6 @@ abstract class CommandOption {
     }
 
     /**
-     * Parse sign/magnitude integer.
-     */
-    static class Magnitude {
-	final int sign;
-	final int magnitude;
-	Magnitude(String argument) {
-	    if (argument.charAt(0) == '+') {
-		sign = 1;
-		magnitude = Integer.parseInt(argument.substring(1));
-	    } else if (argument.charAt(0) == '-') {
-		sign = -1;
-		magnitude = Integer.parseInt(argument.substring(1));
-	    } else {
-		sign = 0;
-		magnitude = Integer.parseInt(argument);
-	    }
-	}
-    }
-
-    /**
      * Template option; parse a format.
      */
     static abstract class FormatOption extends CommandOption {
diff --git a/frysk-core/frysk/hpd/ListCommand.java b/frysk-core/frysk/hpd/ListCommand.java
index da46304..8f76a8e 100644
--- a/frysk-core/frysk/hpd/ListCommand.java
+++ b/frysk-core/frysk/hpd/ListCommand.java
@@ -71,7 +71,7 @@ class ListCommand extends ParameterizedCommand {
 	    });
     }
     private static class Options {
-	CommandOption.Magnitude length;
+	Magnitude length;
     }
     Object options() {
 	return new Options();
diff --git a/frysk-core/frysk/hpd/AssignCommand.java b/frysk-core/frysk/hpd/Magnitude.java
similarity index 79%
copy from frysk-core/frysk/hpd/AssignCommand.java
copy to frysk-core/frysk/hpd/Magnitude.java
index cf2a7e4..065ecf1 100644
--- a/frysk-core/frysk/hpd/AssignCommand.java
+++ b/frysk-core/frysk/hpd/Magnitude.java
@@ -39,18 +39,26 @@
 
 package frysk.hpd;
 
-public class AssignCommand extends PrintCommand {
-
-    static String full = "The assign command evaluates a scalar expression and "
-	    + "uses the result to\n"
-	    + "replace the previous contents of a program variable. The target "
-	    + "location\n"
-	    + "may be a scalar variable, an element of an array or "
-	    + "structure/record, or\n" + "a de-referenced pointer variable.";
-
-    AssignCommand() {
-	super("assign", "Change the value of a scalar program variable.",
-	      "assign scalar-target scalar-value [-force]", full);
+/**
+ * Parse sign/magnitude integer; for instance: -1, 1, or +1.
+ */
+class Magnitude {
+    final int sign;
+    final int magnitude;
+    Magnitude(int sign, int magnitude) {
+	this.sign = sign;
+	this.magnitude = magnitude;
+    }
+    Magnitude(String argument) {
+	if (argument.charAt(0) == '+') {
+	    sign = 1;
+	    magnitude = Integer.parseInt(argument.substring(1));
+	} else if (argument.charAt(0) == '-') {
+	    sign = -1;
+	    magnitude = Integer.parseInt(argument.substring(1));
+	} else {
+	    sign = 0;
+	    magnitude = Integer.parseInt(argument);
+	}
     }
-
 }
diff --git a/frysk-core/frysk/hpd/StackCommands.java b/frysk-core/frysk/hpd/StackCommands.java
index 882c849..af5b84d 100644
--- a/frysk-core/frysk/hpd/StackCommands.java
+++ b/frysk-core/frysk/hpd/StackCommands.java
@@ -42,21 +42,34 @@ package frysk.hpd;
 import java.util.Iterator;
 import java.util.List;
 import frysk.debuginfo.DebugInfoFrame;
+import frysk.debuginfo.DebugInfoStackFactory;
 import frysk.proc.Task;
 
-class StackCommands extends ParameterizedCommand {
+abstract class StackCommands extends ParameterizedCommand {
+
+    private static class Options {
+	boolean printScopes;
+    }
+    Object options() {
+	return new Options();
+    }
+
+    StackCommands(String name, String description, String syntax,
+		  String full) {
+	super(name, description, syntax, full);
+	add(new CommandOption("scopes", "include scopes") {
+		void parse(String arg, Object options) {
+		    ((Options)options).printScopes = true;
+		}
+	    });
+    }
 
     StackCommands(String name) {
-	super(name,
-	      ("Move " + name + " one or more levels in the call stack"),
-	      (name + " [num-levels]"),
-	      ("The up (down) command modifies the current frame"
-	       + " location(s) by adding (subtracting) num-levels.  Call"
-	       + " stack movements are all relative, so up effectively"
-	       + " \"moves up\" (or back) in the call stack, to a frame"
-	       + " that has existed longer, while down \"moves down\" in"
-	       + " the call stack, following the progress of program"
-	       + " execution."));
+	this(name,
+	     ("Move " + name + " one or more levels in the call stack"),
+	     (name + " [num-levels]"),
+	     ("Move up (towards the stack top or inner most frame) or"
+	      + " or down (towards the stack bottom or outer most frame)"));
     }
 
     int complete(CLI cli, PTSet ptset, String incomplete, int base,
@@ -64,46 +77,169 @@ class StackCommands extends ParameterizedCommand {
 	return -1;
     }
 
-    public void interpret(CLI cli, Input cmd, Object options) {
-	PTSet ptset = cli.getCommandPTSet(cmd);
-	int level = 1;
-	boolean down = true;
+    static private void printStack(CLI cli, DebugInfoFrame frame,
+				   int stopLevel, Options options) {
+	DebugInfoStackFactory.printStackTrace(cli.outWriter, frame,
+					      stopLevel, true,
+					      options.printScopes, true);
+    }
+    static private void printFrame(CLI cli, DebugInfoFrame frame,
+				   Options options) {
+	printStack(cli, frame, -1, options);
+    }
 
-	if (cmd.size() != 0)
-	    level = Integer.parseInt(cmd.parameter(0));
+    static private void select(CLI cli, PTSet ptset, Magnitude whereTo,
+			       Options options) {
+	for (Iterator i = ptset.getTaskData(); i.hasNext(); ) {
+	    TaskData td = (TaskData)i.next();
+	    Task task = td.getTask();
+	    td.toPrint(cli.outWriter, true);
+	    cli.outWriter.println();
+	    DebugInfoFrame currentFrame = cli.getTaskFrame(task);
+	    // Where to?
+	    int newLevel;
+	    if (whereTo.sign > 0) {
+		newLevel = currentFrame.level() + whereTo.magnitude;
+	    } else if (whereTo.sign < 0) {
+		newLevel = currentFrame.level() - whereTo.magnitude;
+	    } else {
+		newLevel = whereTo.magnitude;
+	    }
+	    // Get there.
+	    DebugInfoFrame newFrame = currentFrame;
+	    while (newFrame != null && newFrame.level() != newLevel) {
+		if (newFrame.level() < newLevel) {
+		    newFrame = newFrame.getOuterDebugInfoFrame();
+		} else {
+		    newFrame = newFrame.getInnerDebugInfoFrame();
+		}
+	    }
+	    // Success?
+	    if (newFrame == null) {
+		// Reached end-of-stack
+		if (currentFrame.level() > newLevel) {
+		    cli.outWriter.println("Top of stack");
+		} else {
+		    cli.outWriter.println("Bottom of stack");
+		}
+	    } else if (newFrame == currentFrame) {
+		// Same frame; just print it.
+		printFrame(cli, newFrame, options);
+	    } else {
+		// New frame, change it.
+		cli.setTaskFrame(task, newFrame);
+		printFrame(cli, newFrame, options);
+	    }
+	}
+    }
 
-	// For user command 'down', move a level towards the bottom of the
-	// call-stack
-	if (cmd.getAction().compareTo("down") == 0)
-	    down = true;
-	// For user command 'up', move a level towards the top of the call-stack
-	else if (cmd.getAction().compareTo("up") == 0)
-	    down = false;
+    static class Down extends StackCommands {
+	Down() {
+	    super("down");
+	}
+	void interpret(CLI cli, Input input, Object options) {
+	    int count;
+	    switch (input.size()) {
+	    case 0:
+		count = 1;
+		break;
+	    case 1:
+		count = Integer.parseInt(input.parameter(0));
+		break;
+	    default:
+		throw new InvalidCommandException("too many arguments");
+	    }
+	    select(cli, cli.getCommandPTSet(input), new Magnitude(+1, count),
+		   (Options)options);
+	}
+    }
 
-	Iterator taskIter = ptset.getTasks();
-	while (taskIter.hasNext()) {
-	    Task task = (Task) taskIter.next();
-	    DebugInfoFrame currentFrame = cli.getTaskFrame(task);
-	    DebugInfoFrame tmpFrame = currentFrame;
+    static class Up extends StackCommands {
+	Up() {
+	    super("up");
+	}
+	void interpret(CLI cli, Input input, Object options) {
+	    int count;
+	    switch (input.size()) {
+	    case 0:
+		count = 1;
+		break;
+	    case 1:
+		count = Integer.parseInt(input.parameter(0));
+		break;
+	    default:
+		throw new InvalidCommandException("too many arguments");
+	    }
+	    select(cli, cli.getCommandPTSet(input), new Magnitude(-1, count),
+		   (Options)options);
+	}
+    }
 
-	    int l = level;
-	    while (tmpFrame != null && l != 0) {
-		if (down)
-		    tmpFrame = tmpFrame.getOuterDebugInfoFrame();
-		else
-		    tmpFrame = tmpFrame.getInnerDebugInfoFrame();
-		l = l - 1;
+    static class Frame extends StackCommands {
+	Frame() {
+	    super("frame");
+	}
+	void interpret(CLI cli, Input input, Object options) {
+	    Magnitude count;
+	    switch (input.size()) {
+	    case 0:
+		count = new Magnitude(+1, 0); // go no where
+		break;
+	    case 1:
+		count = new Magnitude(input.parameter(0));
+		break;
+	    default:
+		throw new InvalidCommandException("too many arguments");
 	    }
+	    select(cli, cli.getCommandPTSet(input), count, (Options)options);
+	}
+    }
+
+    static class Where extends StackCommands {
+	Where() {
+	    super("where",
+		  "Display the current execution location and call stack",
+		  "where [ {num-levels ] [ -scopes ]",
+		  ("The where command displays the current execution"
+		   + " location(s) and the call stack(s) - or sequence"
+		   + " of procedure calls - which led to that point."));
+	}
 
-	    if (tmpFrame != null && tmpFrame != currentFrame) {
-		cli.setTaskFrame(task, tmpFrame);
+	int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		     List candidates) {
+	    return -1;
+	}
+
+	public void interpret(CLI cli, Input input, Object o) {
+	    int levels;
+	    switch (input.size()) {
+	    case 0:
+		levels = 0;
+		break;
+	    case 1:
+		levels = Integer.parseInt(input.parameter(0));
+		break;
+	    default:
+		throw new InvalidCommandException("Too many arguments");
 	    }
-	    if (tmpFrame == null)
-		tmpFrame = currentFrame;
-	    tmpFrame.printLevel(cli.outWriter);
-	    cli.outWriter.print(" ");
-	    tmpFrame.toPrint(cli.outWriter, false);
-	    cli.outWriter.println();
+	    Options options = (Options)o;	
+	    PTSet ptset = cli.getCommandPTSet(input);
+	    for (Iterator i = ptset.getTaskData(); i.hasNext(); ) {
+		TaskData td = (TaskData)i.next();
+		Task task = td.getTask();
+		DebugInfoFrame currentFrame = cli.getTaskFrame(task);
+		td.toPrint(cli.outWriter, true);
+		cli.outWriter.println();
+		// XXX: How come the pt set code didn't sort this out;
+		// filtering out running tasks???
+		if (cli.getSteppingEngine() == null
+		    || !cli.getSteppingEngine().isTaskRunning(task)) {
+		    printStack(cli, currentFrame, levels, options);
+		} else {
+		    cli.outWriter.println("Running task?");
+		}
+	    }
+	    cli.outWriter.flush();
 	}
     }
-}
\ No newline at end of file
+}
diff --git a/frysk-core/frysk/hpd/TestStackCommands.java b/frysk-core/frysk/hpd/TestStackCommands.java
index b2d6a47..41483e8 100644
--- a/frysk-core/frysk/hpd/TestStackCommands.java
+++ b/frysk-core/frysk/hpd/TestStackCommands.java
@@ -88,8 +88,15 @@ public class TestStackCommands extends TestLib {
 
     public void testUpDown () {
 	e = HpdTestbed.hpdTerminatingProgram("funit-stack-outlined");
+	e.sendCommandExpectPrompt("where 1", "\\#0.*third.*");
 	e.sendCommandExpectPrompt("down", "\\#1.*second.*");
 	e.sendCommandExpectPrompt("down", "\\#2.*first.*");
 	e.sendCommandExpectPrompt("up", "\\#1.*second.*");
     }
+
+    public void testFrame() {
+	e = HpdTestbed.hpdTerminatingProgram("funit-stack-outlined");
+	e.sendCommandExpectPrompt("frame 3", "\\#3.*main.*");
+	e.sendCommandExpectPrompt("frame 1", "\\#1.*second.*");
+    }
 }
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index 41acaf2..b4bddf9 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -85,7 +85,10 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new ActionPointCommands.Delete());
         add(new ActionPointCommands.Disable());
         add(new ActionPointCommands.Enable());
-        add(new StackCommands("down"));
+        add(new StackCommands.Down());
+        add(new StackCommands.Up());
+        add(new StackCommands.Frame());
+        add(new StackCommands.Where());
         add(new StepFinishCommand());
         add(new FocusCommand());
         add(new GoCommand());
@@ -104,10 +107,8 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new StepInstructionCommand());
         add(new UndefsetCommand());
         add(new DbgVariableCommands.Unset());
-        add(new StackCommands("up"));
         add(new ViewsetCommand());
         add(new WhatCommand());
-        add(new WhereCommand());
         add(new WhichsetsCommand());
         add(new DisplayCommand());
         add(new RunCommand());
diff --git a/frysk-core/frysk/hpd/WhereCommand.java b/frysk-core/frysk/hpd/WhereCommand.java
deleted file mode 100644
index ced71cf..0000000
--- a/frysk-core/frysk/hpd/WhereCommand.java
+++ /dev/null
@@ -1,115 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2005, 2006, 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.hpd;
-
-import java.util.Iterator;
-import frysk.proc.Task;


hooks/post-receive
--
frysk system monitor/debugger


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]