From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26239 invoked by alias); 30 May 2008 17:21:06 -0000 Received: (qmail 26208 invoked by uid 9697); 30 May 2008 17:21:05 -0000 Date: Fri, 30 May 2008 17:21:00 -0000 Message-ID: <20080530172105.26193.qmail@sourceware.org> From: pmachata@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Simplify SymbolRule handling in Ftrace X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 7b9112dfabcff8ee1eb5903f148300239ff0339b X-Git-Newrev: 4534ebccc1d0c6b21464f0b5cffda72943079b73 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: 2008-q2/txt/msg00308.txt.bz2 The branch, master has been updated via 4534ebccc1d0c6b21464f0b5cffda72943079b73 (commit) via 0d47203d34e3a73153c0f9f8058b04a65758cf92 (commit) via 77512e08077890d6c65df711fb460db48bb30c18 (commit) via 7bb4eb0ea13e76d0105457c6de7e084ce4b0ccc5 (commit) via 802083fb59ce2f05111e04d61991c45bff266799 (commit) via 43be185d80b4452237a337a441ca26a8e411be0b (commit) from 7b9112dfabcff8ee1eb5903f148300239ff0339b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 4534ebccc1d0c6b21464f0b5cffda72943079b73 Author: Petr Machata Date: Fri May 30 19:16:37 2008 +0200 Simplify SymbolRule handling in Ftrace * this is possible because the necessary functionality has been moved over to more general classes, and ftrace doesn't have to invent it anymore. * (In particular, PLTRule has been dropped and merged with SymbolRule, and FQIdentifier can now do soname matching.) commit 0d47203d34e3a73153c0f9f8058b04a65758cf92 Author: Petr Machata Date: Fri May 30 19:12:33 2008 +0200 FQIdentifier has soname matching capabilities commit 77512e08077890d6c65df711fb460db48bb30c18 Author: Petr Machata Date: Fri May 30 18:13:10 2008 +0200 Rename FQIdentifier.dso to FQIdentifier.soname commit 7bb4eb0ea13e76d0105457c6de7e084ce4b0ccc5 Author: Petr Machata Date: Fri May 30 16:35:18 2008 +0200 File moves * frysk.expr.FqIdentToken renamed to frysk.expr.FQIdentToken * frysk.ftrace.SymbolTracePoint moved to frysk.expr.FQIdentifier * Fq* consistently renamed to FQ*... commit 802083fb59ce2f05111e04d61991c45bff266799 Author: Petr Machata Date: Fri May 30 16:10:17 2008 +0200 Ftrace uses new FQ Iden parser from CExprLexer commit 43be185d80b4452237a337a441ca26a8e411be0b Author: Petr Machata Date: Fri May 30 16:08:32 2008 +0200 Extract parsing of fully qualified identifier into public function * ... for easier reuse ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/bindir/ChangeLog | 15 ++ frysk-core/frysk/bindir/ftrace.java | 66 ++-------- frysk-core/frysk/expr/CExpr.g | 49 +++++++- frysk-core/frysk/expr/ChangeLog | 20 +++- .../expr/{FqIdentToken.java => FQIdentToken.java} | 4 +- frysk-core/frysk/expr/FQIdentifier.java | 142 ++++++++++++++++++++ frysk-core/frysk/ftrace/ChangeLog | 13 ++ frysk-core/frysk/ftrace/FtraceController.java | 11 +-- frysk-core/frysk/ftrace/PLTRule.java | 61 --------- frysk-core/frysk/ftrace/SymbolRule.java | 44 +++---- frysk-core/frysk/ftrace/SymbolTracePoint.java | 67 --------- 11 files changed, 272 insertions(+), 220 deletions(-) rename frysk-core/frysk/expr/{FqIdentToken.java => FQIdentToken.java} (97%) create mode 100644 frysk-core/frysk/expr/FQIdentifier.java delete mode 100644 frysk-core/frysk/ftrace/PLTRule.java delete mode 100644 frysk-core/frysk/ftrace/SymbolTracePoint.java First 500 lines of diff: diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog index d27a3c9..80bb042 100644 --- a/frysk-core/frysk/bindir/ChangeLog +++ b/frysk-core/frysk/bindir/ChangeLog @@ -1,3 +1,18 @@ +2008-05-30 Petr Machata + + * ftrace.java: Drop more of the PLT special casing. Use + SymbolRule for all symbol rules, get rid of now unnecessary + abstraction SymbolRuleCreator. + +2008-05-30 Petr Machata + + * ftrace.java: Adapt to changes in frysk.ftrace and frysk.expr + +2008-05-30 Petr Machata + + * ftrace.java: Move FQ identifier parsing logic to CExprLexer. + (parseSymbolRules): Use new function from CExprLexer. + 2008-05-29 Rick Moseley * fhpd.java: Add code for parameter passing. diff --git a/frysk-core/frysk/bindir/ftrace.java b/frysk-core/frysk/bindir/ftrace.java index 3ce1738..1ac4f89 100644 --- a/frysk-core/frysk/bindir/ftrace.java +++ b/frysk-core/frysk/bindir/ftrace.java @@ -41,7 +41,6 @@ package frysk.bindir; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -53,19 +52,15 @@ import gnu.classpath.tools.getopt.OptionException; import gnu.classpath.tools.getopt.OptionGroup; import inua.util.PrintWriter; -import antlr.Token; - import frysk.debuginfo.PrintStackOptions; import frysk.expr.CExprLexer; -import frysk.expr.FqIdentToken; +import frysk.expr.FQIdentifier; import frysk.ftrace.AddrRule; import frysk.ftrace.Ftrace; import frysk.ftrace.FtraceController; -import frysk.ftrace.PLTRule; import frysk.ftrace.Rule; import frysk.ftrace.RuleOptions; import frysk.ftrace.SymbolRule; -import frysk.ftrace.SymbolTracePoint; import frysk.isa.signals.Signal; import frysk.isa.syscalls.Syscall; import frysk.proc.Proc; @@ -103,11 +98,6 @@ class ftrace { = new PrintStackOptions(); private final Ftrace tracer = new Ftrace(stackPrintOptions); - private interface SymbolRuleCreator { - Rule createRule(boolean addition, RuleOptions options, - SymbolTracePoint spec); - } - private interface RuleMatcher { void rule(String str, boolean addition, RuleOptions options, Collection c); @@ -153,42 +143,22 @@ class ftrace { return rules; } - private void garbage(String text) { - warning.log("Ignoring garbage after the end of the symbol rule", text); - } - private void invalid(String text) { - warning.log("Invalid symbol rule", text); - } - - private List parseSymbolRules(String arg, final SymbolRuleCreator creator) { + private List parseSymbolRules(String arg) { return parseGenericRules(arg, new RuleMatcher() { public void rule(String str, boolean addition, RuleOptions options, Collection rules) { - StringReader r = new StringReader(str); - CExprLexer lexer = new CExprLexer(r); - Token tok; - try { - tok = lexer.nextToken(); - - if (!(tok instanceof FqIdentToken)) { - invalid(str); - return; - } - - if (lexer.nextToken().getType() != Token.EOF_TYPE) - garbage(tok.getText()); - - } catch (antlr.TokenStreamException exc) { - invalid(str); - return; + FQIdentifier fqid = CExprLexer.parseFQIdentifier(str); + rules.add(new SymbolRule(addition, options, fqid)); + } + catch (CExprLexer.FQIdentExtraGarbageException exc) { + warning.log("Ignoring garbage after the end of the symbol rule", + exc.getMessage()); + } + catch (CExprLexer.FQIdentInvalidTokenException exc) { + warning.log("Invalid symbol rule", exc.getMessage()); } - - FqIdentToken fqTok = (FqIdentToken)tok; - - SymbolTracePoint spec = new SymbolTracePoint(fqTok); - rules.add(creator.createRule(addition, options, spec)); } }); } @@ -427,20 +397,8 @@ class ftrace { symRules.add("-#INTERP#*"); // Symbol tracing - class SymbolCreator implements SymbolRuleCreator { - public Rule createRule(boolean addition, RuleOptions options, - SymbolTracePoint spec) { - if (spec.wantPlt) - return new PLTRule(addition, options, - spec.symbol, spec.dso, spec.version); - else - return new SymbolRule(addition, options, - spec.symbol, spec.dso, spec.version); - } - } - SymbolRuleCreator symbolCreator = new SymbolCreator(); for (Iterator it = symRules.iterator(); it.hasNext(); ) { - List rules = parseSymbolRules((String)it.next(), symbolCreator); + List rules = parseSymbolRules((String)it.next()); controller.gotSymRules(rules); } diff --git a/frysk-core/frysk/expr/CExpr.g b/frysk-core/frysk/expr/CExpr.g index 631f188..41a33c6 100644 --- a/frysk-core/frysk/expr/CExpr.g +++ b/frysk-core/frysk/expr/CExpr.g @@ -82,6 +82,7 @@ header import java.util.regex.Pattern; import java.util.regex.Matcher; + import java.io.StringReader; } class CExprParser extends Parser; @@ -442,6 +443,52 @@ tokens } super.match(s); } + + public static class FQIdentException extends RuntimeException { + private static final long serialVersionUID = 1L; + public FQIdentException(String s) { + super(s); + } + } + + public static class FQIdentExtraGarbageException extends FQIdentException { + private static final long serialVersionUID = 1L; + public FQIdentExtraGarbageException(String garbage) { + super(garbage); + } + } + + public static class FQIdentInvalidTokenException extends FQIdentException { + private static final long serialVersionUID = 1L; + public FQIdentInvalidTokenException(String token) { + super(token); + } + } + + public static FQIdentifier parseFQIdentifier(String str) + throws FQIdentExtraGarbageException, FQIdentInvalidTokenException + { + StringReader r = new StringReader(str); + CExprLexer lexer = new CExprLexer(r); + Token tok; + + try { + tok = lexer.nextToken(); + + if (!(tok instanceof FQIdentToken)) + throw new FQIdentInvalidTokenException(tok.getText()); + + FQIdentToken fqTok = (FQIdentToken)tok; + + if ((tok = lexer.nextToken()).getType() != Token.EOF_TYPE) + throw new FQIdentExtraGarbageException(tok.getText()); + + return new FQIdentifier(fqTok); + + } catch (antlr.TokenStreamException exc) { + throw new FQIdentInvalidTokenException(str); + } + } } AMPERSAND : '&' ; @@ -641,7 +688,7 @@ PARSE_FQIDENT if (!Character.isJavaIdentifierStart(part.charAt(0))) throw new RecognitionException("Invalid symbol `" + part + "'."); - FqIdentToken tok = new FqIdentToken(IDENT, matched); + FQIdentToken tok = new FQIdentToken(IDENT, matched); tok.dso = partDso; tok.file = partFile; tok.line = partLine; diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog index 29ec07b..efbd0e7 100644 --- a/frysk-core/frysk/expr/ChangeLog +++ b/frysk-core/frysk/expr/ChangeLog @@ -1,7 +1,25 @@ +2008-05-30 Petr Machata + + * FQIdentifier.java: Implement soname expansion and soname + matching. (Parts copied over from frysk.ftrace.FtraceController.) + +2008-05-30 Petr Machata + + * FQIdentToken.java: Renamed from FqIdentToken + * FQIdentifier: Moved from frysk.ftrace.SymbolTracePoint + * CExpr.g: Rename exceptions to FQIdent*Exception, adapt to above. + (parseFqIdent): Return FQIdentifier instead if FqIdentToken + +2008-05-30 Petr Machata + + * CExpr.g + (CExprLexer.parseFqIdent): New function, logic extracted from ftrace. + (CExprLexer.FqIdent*Exception): Exception classes for the above. + 2008-05-29 Petr Machata * CExpr.g (PARSE_FQIDENT): Forbid empty string as symbol name. - * FqIdentToken (wantPlt): Publish. + * FqIdentToken.java (wantPlt): Publish. 2008-05-28 Petr Machata diff --git a/frysk-core/frysk/expr/FqIdentToken.java b/frysk-core/frysk/expr/FQIdentToken.java similarity index 97% rename from frysk-core/frysk/expr/FqIdentToken.java rename to frysk-core/frysk/expr/FQIdentToken.java index 0b6c13c..aaf3e6d 100644 --- a/frysk-core/frysk/expr/FqIdentToken.java +++ b/frysk-core/frysk/expr/FQIdentToken.java @@ -39,14 +39,14 @@ package frysk.expr; -public class FqIdentToken +public class FQIdentToken extends antlr.CommonToken { public String dso = null, file = null, line = null, proc = null, symbol = null, version = null; public boolean wantPlt = false; - public FqIdentToken(int t, String txt) { + public FQIdentToken(int t, String txt) { super (t, txt); } diff --git a/frysk-core/frysk/expr/FQIdentifier.java b/frysk-core/frysk/expr/FQIdentifier.java new file mode 100644 index 0000000..ee197de --- /dev/null +++ b/frysk-core/frysk/expr/FQIdentifier.java @@ -0,0 +1,142 @@ +// This file is part of the program FRYSK. +// +// Copyright 2008, 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.expr; + +// Both necessary for soname expansion. In principle this doesn't +// belong here, but it doesn't seem to be worth it to create separate +// class just for soname expansion capabilities. Right now at least. +import frysk.dwfl.ObjectFile; +import frysk.proc.Task; + +public class FQIdentifier { + + final public String soname; + final public String file; + final public Long line; + final public String proc; + final public String symbol; + final public String version; + final public boolean wantPlt; + + final private int metasoname; + final private static int soname_null = -1; + final private static int soname_name = 0; + final private static int soname_MAIN = 2; + final private static int soname_INTERP = 3; + final private boolean sonameIsPath; + + public FQIdentifier(FQIdentToken tok) { + this.soname = tok.dso; + this.file = tok.file; + this.proc = tok.proc; + this.symbol = tok.symbol; + this.version = tok.version; + this.wantPlt = tok.wantPlt; + + if (tok.line != null) + this.line = new Long(Long.parseLong(tok.line, 10)); + else + this.line = null; + + if (soname == null) { + this.sonameIsPath = false; + this.metasoname = soname_null; + } else { + this.sonameIsPath = soname.indexOf('/') != -1; + if (soname.equals("MAIN")) + this.metasoname = soname_MAIN; + else if (soname.equals("INTERP")) + this.metasoname = soname_INTERP; + else + this.metasoname = soname_name; + } + } + + public String toString() { + StringBuffer buf = new StringBuffer(); + if (soname != null) + buf.append('#').append(soname).append('#'); + if (file != null) + buf.append(file).append('#'); + if (line != null) + buf.append(line.longValue()).append('#'); + if (proc != null) + buf.append(proc).append('#'); + if (wantPlt) + buf.append("plt:"); + buf.append(symbol); + if (version != null) + buf.append('@').append(version); + return buf.toString(); + } + + /** + * Translate MAIN and INTERP meta-sonames to main binary and + * dynamic linker of given task. + */ + public String expandSoname(Task task) { + if (metasoname == soname_null) + return null; + else if (metasoname == soname_name) + return soname; + else { + // Don't cache so that the identifier is usable for + // multiple tasks. + String path = task.getProc().getExeFile().getSysRootedPath(); + ObjectFile objf = ObjectFile.buildFromFile(path); + if (metasoname == soname_MAIN) + return objf.getSoname(); + else + return ObjectFile.buildFromFile(objf.getInterp()).getSoname(); + } + } + + /** + * Check if given ObjectFile WHAT matches this soname identifier. + */ + public boolean sonameMatches(Task task, ObjectFile what) { + if (metasoname == soname_null) + return true; + else if (sonameIsPath) + return soname.equals(what.getFilename().getPath()); + else + return this.expandSoname(task).equals(what.getSoname()); + } +} diff --git a/frysk-core/frysk/ftrace/ChangeLog b/frysk-core/frysk/ftrace/ChangeLog index 20135a0..2e7fbc9 100644 --- a/frysk-core/frysk/ftrace/ChangeLog +++ b/frysk-core/frysk/ftrace/ChangeLog @@ -1,3 +1,16 @@ +2008-05-30 Petr Machata + + * PLTRule.java: Drop. The functionality is taken over by... + * SymbolRule.java: ... SymbolRule, which now works with + FQIdentifier instead of set of Strings. Hence the globbing was + definitely dropped for the time being. + * FtraceController.java: Defer soname matching to FQIdentifier + where this feature has been implemented. + +2008-05-30 Petr Machata + + * SymbolTracePoint.java: Moved to frysk.expr.FQIdentifier + 2008-05-29 Petr Machata * SymbolTracePoint.java: New class. diff --git a/frysk-core/frysk/ftrace/FtraceController.java b/frysk-core/frysk/ftrace/FtraceController.java index f94ef6c..09f064f 100644 --- a/frysk-core/frysk/ftrace/FtraceController.java +++ b/frysk-core/frysk/ftrace/FtraceController.java @@ -195,15 +195,8 @@ public class FtraceController final SymbolRule rule = (SymbolRule)it.next(); fine.log("Considering symbol rule " + rule + "."); - // MAIN is meta-soname meaning "main executable". - if ((rule.sonamePattern.pattern().equals("MAIN") - && task.getProc().getExeFile().getSysRootedPath().equals(path)) - || (rule.sonamePattern.pattern().equals("INTERP") - && isInterpOf(objf, task.getProc().getExeFile().getSysRootedPath())) - || rule.sonamePattern.matcher(objf.getSoname()).matches()) - { + if (rule.fqid.sonameMatches(task, objf)) rule.apply(tracePoints, workingSet, stackTraceSet); - } } // Finally, apply constructed working set. @@ -237,7 +230,7 @@ public class FtraceController final List candidate = new ArrayList(1); candidate.add(new Long(rule.addr)); - fine.log("Considering addr rule " + rule + "."); + fine.log("Considering addr rule", rule); // MAIN is meta-soname meaning "main executable". if ((rule.sonamePattern.pattern().equals("MAIN") diff --git a/frysk-core/frysk/ftrace/PLTRule.java b/frysk-core/frysk/ftrace/PLTRule.java deleted file mode 100644 index e37642e..0000000 --- a/frysk-core/frysk/ftrace/PLTRule.java +++ /dev/null @@ -1,61 +0,0 @@ -// This file is part of the program FRYSK. -// -// Copyright 2005, 2006, 2007, 2008, 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 hooks/post-receive -- frysk system monitor/debugger