From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20806 invoked by alias); 18 Nov 2007 00:20:45 -0000 Received: (qmail 20754 invoked by uid 367); 18 Nov 2007 00:20:42 -0000 Date: Sun, 18 Nov 2007 00:20:00 -0000 Message-ID: <20071118002042.20739.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Use Expression in DebugInfo; simplify. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 5c771ea53ce8b3c98d3c47d6cc591746fb6d80e4 X-Git-Newrev: 8895957a8e291f3aa8103be5ea07a6fd44048561 Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2007-q4/txt/msg00388.txt.bz2 The branch, master has been updated via 8895957a8e291f3aa8103be5ea07a6fd44048561 (commit) via 5d3e7d0651efd963e11ab6d77fa9418cecdf9c29 (commit) via f230b8b7febc14c739bb70954b32ee1c9a67f540 (commit) from 5c771ea53ce8b3c98d3c47d6cc591746fb6d80e4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 8895957a8e291f3aa8103be5ea07a6fd44048561 Author: Andrew Cagney Date: Sat Nov 17 19:18:05 2007 -0500 Use Expression in DebugInfo; simplify. frysk-core/frysk/debuginfo/ChangeLog 2007-11-17 Andrew Cagney * DebugInfo.java (printNoSymbolTable(String,boolean)): Delete. (print(String,DebugInfoFrame,boolean)): Delete. (print(String,DebugInfoFrame)): Re-implement using Expression. * gen-type-expect-tests.py (j.prologue): Update. commit 5d3e7d0651efd963e11ab6d77fa9418cecdf9c29 Author: Andrew Cagney Date: Sat Nov 17 18:50:52 2007 -0500 Change hpd to use frysk.expr.Expression. frysk-core/frysk/hpd/ChangeLog 2007-11-17 Andrew Cagney * CLI.java (parseValue(Task,String,boolean)): Delete. (parseValue(Task,String)): Delete. (parseExpression(Task,String)): New. * DisassembleCommand.java: Update. * EvalCommands.java: Update. * ExamineCommand.java: Update. * PlocationCommand.java: Update. * PtypeCommand.java: Update. * TestPtypeCommand.java: Update. commit f230b8b7febc14c739bb70954b32ee1c9a67f540 Author: Andrew Cagney Date: Sat Nov 17 17:51:38 2007 -0500 Add Expression, encapsulates the parse tree from parsing an expression string. frysk-core/frysk/expr/ChangeLog 2007-11-17 Andrew Cagney * TestArithmetics.java (eval(String)): Use Expression. * ExpressionFactory.java (parse(ExprSymTab,String)): New. * Expression.java: New. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/debuginfo/ChangeLog | 5 + frysk-core/frysk/debuginfo/DebugInfo.java | 98 +------------------ .../frysk/debuginfo/gen-type-expect-tests.py | 2 +- frysk-core/frysk/expr/ChangeLog | 4 + .../{CompletionException.java => Expression.java} | 62 ++++++++----- frysk-core/frysk/expr/ExpressionFactory.java | 18 ++++ frysk-core/frysk/expr/TestArithmetics.java | 16 +--- frysk-core/frysk/hpd/CLI.java | 27 +++--- frysk-core/frysk/hpd/ChangeLog | 10 ++ frysk-core/frysk/hpd/DisassembleCommand.java | 9 +- frysk-core/frysk/hpd/EvalCommands.java | 30 ++++--- frysk-core/frysk/hpd/ExamineCommand.java | 10 +- frysk-core/frysk/hpd/PlocationCommand.java | 13 +-- frysk-core/frysk/hpd/PtypeCommand.java | 17 +-- frysk-core/frysk/hpd/TestPtypeCommand.java | 4 +- 15 files changed, 142 insertions(+), 183 deletions(-) copy frysk-core/frysk/expr/{CompletionException.java => Expression.java} (66%) First 500 lines of diff: diff --git a/frysk-core/frysk/debuginfo/ChangeLog b/frysk-core/frysk/debuginfo/ChangeLog index b307901..b21149f 100644 --- a/frysk-core/frysk/debuginfo/ChangeLog +++ b/frysk-core/frysk/debuginfo/ChangeLog @@ -1,5 +1,10 @@ 2007-11-17 Andrew Cagney + * DebugInfo.java (printNoSymbolTable(String,boolean)): Delete. + (print(String,DebugInfoFrame,boolean)): Delete. + (print(String,DebugInfoFrame)): Re-implement using Expression. + * gen-type-expect-tests.py (j.prologue): Update. + * DebugInfo.java (complete(DebugInfoFrame,String,int,List)): Delete. * ObjectDeclarationSearchEngine.java (complete(String,List)): New. diff --git a/frysk-core/frysk/debuginfo/DebugInfo.java b/frysk-core/frysk/debuginfo/DebugInfo.java index 9bc2dab..12e817c 100644 --- a/frysk-core/frysk/debuginfo/DebugInfo.java +++ b/frysk-core/frysk/debuginfo/DebugInfo.java @@ -36,18 +36,14 @@ // modification, you must delete this exception statement from your // version and license this file solely under the GPL without // exception. + package frysk.debuginfo; -import antlr.collections.AST; +import frysk.expr.ExpressionFactory; import frysk.dwfl.DwflCache; -import frysk.expr.CExprLexer; -import frysk.expr.CExprParser; -import frysk.expr.ExprSymTab; -import frysk.expr.CExprEvaluator; import frysk.proc.Proc; import frysk.value.Type; import frysk.value.Value; -import java.io.StringReader; import lib.dwfl.Dwarf; import lib.dwfl.DwarfCommand; import lib.dwfl.DwarfDie; @@ -58,7 +54,6 @@ import lib.dwfl.DwAt; import lib.dwfl.DwflDieBias; import lib.dwfl.Elf; import lib.dwfl.ElfCommand; -import frysk.expr.ScratchSymTab; public class DebugInfo { private Elf elf; @@ -150,92 +145,11 @@ public class DebugInfo { /** * Implement the cli print request. - * - * @param sInput - * @return Variable */ - public Value print (String sInput, DebugInfoFrame frame) { - return print (sInput, frame, false); - } - - public Value print (String sInput, DebugInfoFrame frame, boolean dumpTree) { - Value result = null; - sInput += (char) 3; - - CExprLexer lexer = new CExprLexer(new StringReader(sInput)); - CExprParser parser = new CExprParser(lexer); - try { - parser.start(); - } catch (antlr.RecognitionException r) { - throw new RuntimeException(r); - } catch (antlr.TokenStreamException t) { - throw new RuntimeException(t); - } - - AST exprAST = parser.getAST(); - if (dumpTree) - System.out.println("parse tree: " + exprAST.toStringTree()); - CExprEvaluator cExprEvaluator; - /* - * If this request has come from the SourceWindow, there's no way to - * know which thread the mouse request came from; if there are multiple - * innermost frames of multiple threads in the same source file, than - * all of the threads have to be checked. If there's only one thread; - * than this loop will run only once anyways. - */ - ObjectDeclarationSearchEngine declarationSearchEngine = new ObjectDeclarationSearchEngine(frame); - cExprEvaluator = new CExprEvaluator(declarationSearchEngine); - try { - result = cExprEvaluator.expr(exprAST); - } catch (ArithmeticException ae) { - ae.printStackTrace(); - throw ae; - } catch (antlr.RecognitionException r) { - throw new RuntimeException(r); - } catch (frysk.value.InvalidOperatorException i) { - throw new RuntimeException(i); - } catch (frysk.value.OperationNotDefinedException o) { - throw new RuntimeException(o); - } - - return result; + public Value print(String expression, DebugInfoFrame frame) { + ObjectDeclarationSearchEngine symTab + = new ObjectDeclarationSearchEngine(frame); + return ExpressionFactory.parse(symTab, expression).getValue(); } - static public Value printNoSymbolTable (String sInput, boolean dump_tree) { - Value result = null; - sInput += (char) 3; - - CExprLexer lexer = new CExprLexer(new StringReader(sInput)); - CExprParser parser = new CExprParser(lexer); - try { - parser.start(); - } catch (antlr.RecognitionException r) { - throw new RuntimeException(r); - } catch (antlr.TokenStreamException t) { - throw new RuntimeException(t); - } - - AST t = parser.getAST(); - if (dump_tree) - // Print the resulting tree out in LISP notation - System.out.println("parse tree: " + t.toStringTree()); - CExprEvaluator cExprEvaluator; - ExprSymTab tmpSymTab = new ScratchSymTab(); - cExprEvaluator = new CExprEvaluator(tmpSymTab); - - try { - result = cExprEvaluator.expr(t); - } catch (ArithmeticException ae) { - ae.printStackTrace(); - throw ae; - } catch (antlr.RecognitionException r) { - throw new RuntimeException(r); - } catch (frysk.value.InvalidOperatorException i) { - throw new RuntimeException(i); - } catch (frysk.value.OperationNotDefinedException o) { - throw new RuntimeException(o); - } - - return result; - } } diff --git a/frysk-core/frysk/debuginfo/gen-type-expect-tests.py b/frysk-core/frysk/debuginfo/gen-type-expect-tests.py index b73d7ff..caf26d5 100644 --- a/frysk-core/frysk/debuginfo/gen-type-expect-tests.py +++ b/frysk-core/frysk/debuginfo/gen-type-expect-tests.py @@ -136,7 +136,7 @@ public class %s extends TestLib { System.out.println("Error: Cannot find " + expect[i].symbol); assertNotNull(varDie); DebugInfo debugInfo = new DebugInfo(frame); - Value value = debugInfo.print(expect[i].symbol, frame, false); + Value value = debugInfo.print(expect[i].symbol, frame); value.toPrint(pw, task.getMemory(), Format.NATURAL); pw.flush(); String valueString = baos.toString(); diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog index 784f33d..431c6b8 100644 --- a/frysk-core/frysk/expr/ChangeLog +++ b/frysk-core/frysk/expr/ChangeLog @@ -1,5 +1,9 @@ 2007-11-17 Andrew Cagney + * TestArithmetics.java (eval(String)): Use Expression. + * ExpressionFactory.java (parse(ExprSymTab,String)): New. + * Expression.java: New. + * CompletionException.java (getMessage()): New. * TestCompletion.java (testOneCompletion()): New. (testTwoCompletions()): New. diff --git a/frysk-core/frysk/expr/CompletionException.java b/frysk-core/frysk/expr/Expression.java similarity index 66% copy from frysk-core/frysk/expr/CompletionException.java copy to frysk-core/frysk/expr/Expression.java index 56f2ede..1196026 100644 --- a/frysk-core/frysk/expr/CompletionException.java +++ b/frysk-core/frysk/expr/Expression.java @@ -40,39 +40,57 @@ package frysk.expr; import antlr.collections.AST; +import java.io.PrintWriter; +import frysk.value.Type; +import frysk.value.Value; +import frysk.value.Location; /** - * An incomplete blah. + * An expression (well actually the expression tree). */ -public class CompletionException extends RuntimeException { - static final long serialVersionUID = 1; +public class Expression { + private final ExprSymTab symTab; private final AST ast; - CompletionException(AST ast) { + Expression(ExprSymTab symTab, AST ast) { + this.symTab = symTab; this.ast = ast; } - public String getMessage() { - return ("complete <<" - + getText() - + ">> at " - + getColumn()); + + /** + * Print the expression tree. + */ + public void toPrint(PrintWriter writer) { + writer.print(ast.toStringTree()); } + /** - * Return the incomplete string (minus the tab). + * Evaluate the expression returning the result's Value. This may + * have side effects - modifying the inferior. */ - public String getText() { - String text = ast.getText(); - int tab = text.indexOf("\t"); - if (tab < 0) - throw new RuntimeException("No tab found in " + ast); - return text.substring(0, tab); + public Value getValue() { + try { + return new CExprEvaluator(symTab).expr(ast); + } catch (antlr.RecognitionException r) { + throw new RuntimeException(r); + } } - // Useful? - public int getLine() { - return ast.getLine(); + + /** + * Determine the expressions result type. + */ + public Type getType() { + // XXX: Fixme; should be walking the tree, not evaluating the + // expresision. + return getValue().getType(); } - public int getColumn() { - // Antlr counts columns starting at 1. - return ast.getColumn() - 1; + + /** + * Return the expression's location. + */ + public Location getLocation() { + // XXX: should this walk the tree recording each required + // location? + return getValue().getLocation(); } } diff --git a/frysk-core/frysk/expr/ExpressionFactory.java b/frysk-core/frysk/expr/ExpressionFactory.java index 65d01bf..16fb8f1 100644 --- a/frysk-core/frysk/expr/ExpressionFactory.java +++ b/frysk-core/frysk/expr/ExpressionFactory.java @@ -82,4 +82,22 @@ public class ExpressionFactory { } return -1; // nothing completed. } + + + /** + * Parse the string, returning an expression. + */ + public static Expression parse(ExprSymTab symTab, String expression) { + try { + String input = expression + (char)3; + CExprParser parser + = new CExprParser(new CExprLexer(new StringReader(input))); + parser.start(); + return new Expression(symTab, parser.getAST()); + } catch (antlr.RecognitionException r) { + throw new RuntimeException(r); + } catch (antlr.TokenStreamException t) { + throw new RuntimeException(t); + } + } } diff --git a/frysk-core/frysk/expr/TestArithmetics.java b/frysk-core/frysk/expr/TestArithmetics.java index 5db7d88..d70eac3 100644 --- a/frysk-core/frysk/expr/TestArithmetics.java +++ b/frysk-core/frysk/expr/TestArithmetics.java @@ -41,7 +41,6 @@ package frysk.expr; import frysk.junit.TestCase; import frysk.value.Value; -import java.io.StringReader; import frysk.expr.ScratchSymTab; /** @@ -51,19 +50,8 @@ import frysk.expr.ScratchSymTab; public class TestArithmetics extends TestCase { private Value eval(String input) { - try { - input += (char) 3; - CExprLexer lexer = new CExprLexer(new StringReader(input)); - CExprParser parser = new CExprParser(lexer); - parser.start(); - ExprSymTab symTab = new ScratchSymTab(); - CExprEvaluator exprEvaluator = new CExprEvaluator(symTab); - return exprEvaluator.expr(parser.getAST()); - } catch (antlr.RecognitionException e) { - throw new RuntimeException(e); - } catch (antlr.TokenStreamException e) { - throw new RuntimeException(e); - } + ExprSymTab symTab = new ScratchSymTab(); + return ExpressionFactory.parse(symTab, input).getValue(); } private void checkExpr(long value, String expr) { diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java index 2134399..c996366 100644 --- a/frysk-core/frysk/hpd/CLI.java +++ b/frysk-core/frysk/hpd/CLI.java @@ -39,6 +39,7 @@ package frysk.hpd; +import frysk.debuginfo.ObjectDeclarationSearchEngine; import java.io.PrintStream; import java.io.PrintWriter; import java.util.HashMap; @@ -59,7 +60,10 @@ import frysk.rt.ProcTaskIDManager; import frysk.stepping.SteppingEngine; import frysk.stepping.TaskStepEngine; import frysk.util.CountDownLatch; -import frysk.value.Value; +import frysk.expr.Expression; +import frysk.expr.ScratchSymTab; +import frysk.expr.ExprSymTab; +import frysk.expr.ExpressionFactory; public class CLI { ProcTaskIDManager idManager; @@ -185,18 +189,15 @@ public class CLI { /* * Public methods */ - - Value parseValue(Task task, String value) { - return parseValue(task, value, false); - } - - Value parseValue(Task task, String value, boolean dumpTree) { - DebugInfoFrame frame = getTaskFrame(task); - DebugInfo debugInfo = getTaskDebugInfo(task); - if (debugInfo != null) - return debugInfo.print(value, frame, dumpTree); - else - return DebugInfo.printNoSymbolTable(value, dumpTree); + Expression parseExpression(Task task, String expression) { + ExprSymTab symTab; + if (task == null) { + symTab = new ScratchSymTab(); + } else { + DebugInfoFrame frame = getTaskFrame(task); + symTab = new ObjectDeclarationSearchEngine(frame); + } + return ExpressionFactory.parse(symTab, expression); } /** diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog index aa2b302..a2532f0 100644 --- a/frysk-core/frysk/hpd/ChangeLog +++ b/frysk-core/frysk/hpd/ChangeLog @@ -1,5 +1,15 @@ 2007-11-17 Andrew Cagney + * CLI.java (parseValue(Task,String,boolean)): Delete. + (parseValue(Task,String)): Delete. + (parseExpression(Task,String)): New. + * DisassembleCommand.java: Update. + * EvalCommands.java: Update. + * ExamineCommand.java: Update. + * PlocationCommand.java: Update. + * PtypeCommand.java: Update. + * TestPtypeCommand.java: Update. + * CompletionFactory.java (completeExpression(CLI,Input,int,List)): Re-implement using ExpressionFactory.complete(ExprSymTab,String,List) and diff --git a/frysk-core/frysk/hpd/DisassembleCommand.java b/frysk-core/frysk/hpd/DisassembleCommand.java index 8cc0eef..207c53e 100644 --- a/frysk-core/frysk/hpd/DisassembleCommand.java +++ b/frysk-core/frysk/hpd/DisassembleCommand.java @@ -116,7 +116,8 @@ public class DisassembleCommand extends ParameterizedCommand { if (cmd.size() == 1) { try { currentInstruction - = cli.parseValue(task, cmd.parameter(0)).asLong(); + = cli.parseExpression(task, cmd.parameter(0)) + .getValue().asLong(); symbol = SymbolFactory.getSymbol(task, currentInstruction); } catch (RuntimeException nnfe) { cli.addMessage(new Message(nnfe.getMessage(), @@ -127,9 +128,11 @@ public class DisassembleCommand extends ParameterizedCommand { long startInstruction, endInstruction; try { startInstruction - = cli.parseValue(task, cmd.parameter(0)).asLong(); + = cli.parseExpression(task, cmd.parameter(0)) + .getValue().asLong(); endInstruction - = cli.parseValue(task, cmd.parameter(1)).asLong(); + = cli.parseExpression(task, cmd.parameter(1)) + .getValue().asLong(); } catch (RuntimeException nnfe) { cli.addMessage(new Message(nnfe.getMessage(), Message.TYPE_ERROR)); diff --git a/frysk-core/frysk/hpd/EvalCommands.java b/frysk-core/frysk/hpd/EvalCommands.java index ada61ce..98b83cc 100644 --- a/frysk-core/frysk/hpd/EvalCommands.java +++ b/frysk-core/frysk/hpd/EvalCommands.java @@ -42,10 +42,10 @@ package frysk.hpd; import frysk.value.Format; import java.util.Iterator; import frysk.proc.Task; -import frysk.value.Value; import frysk.value.PointerType; import frysk.value.Type; import java.util.List; +import frysk.expr.Expression; /** * Evaluate an expression; in various forms. @@ -82,7 +82,6 @@ abstract class EvalCommands extends ParameterizedCommand { Options options) { if (expression.equals("")) throw new InvalidCommandException("missing expression"); - Value result = null; Iterator taskDataIter = ptset.getTaskData(); do { Task task = null; @@ -92,23 +91,28 @@ abstract class EvalCommands extends ParameterizedCommand { td.toPrint(cli.outWriter, true); cli.outWriter.println(); } + Expression result; try { - result = cli.parseValue(task, expression, options.dumpTree); + result = cli.parseExpression(task, expression); } catch (RuntimeException e) { cli.outWriter.println(); cli.printError(e); continue; } - - Type t = result.getType(); - if (t instanceof PointerType) { - cli.outWriter.print("("); - t.toPrint(cli.outWriter); - cli.outWriter.print(") "); - } - result.toPrint(cli.outWriter, - task == null ? null : task.getMemory(), - options.format); + if (options.dumpTree) { + result.toPrint(cli.outWriter); + } else { + Type t = result.getType(); + if (t instanceof PointerType) { + cli.outWriter.print("("); + t.toPrint(cli.outWriter); + cli.outWriter.print(") "); + } + result.getValue() + .toPrint(cli.outWriter, + task == null ? null : task.getMemory(), + options.format); + } cli.outWriter.println(); } while (taskDataIter.hasNext()); } diff --git a/frysk-core/frysk/hpd/ExamineCommand.java b/frysk-core/frysk/hpd/ExamineCommand.java index 0bdb7ca..be1952e 100644 --- a/frysk-core/frysk/hpd/ExamineCommand.java +++ b/frysk-core/frysk/hpd/ExamineCommand.java @@ -55,22 +55,22 @@ public class ExamineCommand extends ParameterizedCommand { if (cmd.size() == 0) { throw new InvalidCommandException("No value to examine"); } - Value value; Iterator taskDataIter = ptset.getTaskData(); while (taskDataIter.hasNext()) { TaskData tdata = (TaskData) taskDataIter.next(); + tdata.toPrint(cli.outWriter, true); + cli.outWriter.println(); + Value value; try { hooks/post-receive -- frysk system monitor/debugger