From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20090 invoked by alias); 15 May 2008 11:42:20 -0000 Received: (qmail 20053 invoked by uid 9697); 15 May 2008 11:42:20 -0000 Date: Thu, 15 May 2008 11:42:00 -0000 Message-ID: <20080515114219.20038.qmail@sourceware.org> From: pmachata@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: More sytax checks for -addr rules X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 2b063520b309b9ddcefbc3835c876089adbbd44c X-Git-Newrev: 68a03f3103ec5a4532507d0a49ae3595151f01bd 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/msg00247.txt.bz2 The branch, master has been updated via 68a03f3103ec5a4532507d0a49ae3595151f01bd (commit) via abc13345ba0acefe6879dcdb2e2d084eddbdf36d (commit) via fa9cc6e5ca4f62d61c92f97f905073b6f0a58e7f (commit) via 8ca14466d2e7e3fc7caa4947e486bc67b0087cc7 (commit) via b0a985480f645bf092997b5e6401985df7a6598c (commit) via ed8ff035ff68280aa739b9481cf50e5931d4e9bd (commit) via 46f21c6f5c3fff2fa967259133029181db4b3f37 (commit) via ad20db2bb1d736131549642b0c342755e0ef1047 (commit) via a8e2282802dbf89bbb6fef9820a81a19a48d54eb (commit) via 7cf98c30d26312c8e530fc13aa2363f70c866669 (commit) via f2fba8c23f25b65d97d492d565b9448f41264b4f (commit) via 7387cf922a203ad61fe323e88b188413c225670f (commit) via f97a4613489794779e94b9ab177433e8373730df (commit) from 2b063520b309b9ddcefbc3835c876089adbbd44c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 68a03f3103ec5a4532507d0a49ae3595151f01bd Author: Petr Machata Date: Thu May 15 10:24:38 2008 +0200 More sytax checks for -addr rules commit abc13345ba0acefe6879dcdb2e2d084eddbdf36d Author: Petr Machata Date: Wed May 14 18:48:08 2008 +0200 Coding style cleanups commit fa9cc6e5ca4f62d61c92f97f905073b6f0a58e7f Author: Petr Machata Date: Wed May 14 18:47:42 2008 +0200 Address tracing option in ftrace driver program * ... and a nice description in man page commit 8ca14466d2e7e3fc7caa4947e486bc67b0087cc7 Author: Petr Machata Date: Wed May 14 18:44:51 2008 +0200 Support for address tracing in "ftrace" package commit b0a985480f645bf092997b5e6401985df7a6598c Author: Petr Machata Date: Wed May 14 18:33:19 2008 +0200 Load symbols in FtraceController, not in Ftrace commit ed8ff035ff68280aa739b9481cf50e5931d4e9bd Author: Petr Machata Date: Wed May 14 18:22:16 2008 +0200 Mapping events report the virtual address where the object was mapped commit 46f21c6f5c3fff2fa967259133029181db4b3f37 Author: Petr Machata Date: Wed May 14 18:15:25 2008 +0200 Commentary changes commit ad20db2bb1d736131549642b0c342755e0ef1047 Author: Petr Machata Date: Wed May 14 18:06:50 2008 +0200 DwflDieBias getLowPC, getHighPC: two new proxy methods commit a8e2282802dbf89bbb6fef9820a81a19a48d54eb Author: Petr Machata Date: Tue May 13 12:19:42 2008 +0200 New function ArchFormatter.toHexString(int, long) * formats to given width in digits * toHexString(Task, long) is just a proxy to this commit 7cf98c30d26312c8e530fc13aa2363f70c866669 Author: Petr Machata Date: Wed May 7 15:18:11 2008 +0200 ElfSymbolType has toString * ... to enable sensible formatting in logs commit f2fba8c23f25b65d97d492d565b9448f41264b4f Author: Petr Machata Date: Wed May 7 15:17:08 2008 +0200 Nits commit 7387cf922a203ad61fe323e88b188413c225670f Author: Petr Machata Date: Wed May 7 15:16:17 2008 +0200 SymbolBuilder recognizes defined or undefined symbols * The interface supports new parameter "defined". The only thing that mattered so far was value, but that can be non-0 even for undefined symbol. commit f97a4613489794779e94b9ab177433e8373730df Author: Petr Machata Date: Tue May 6 16:11:00 2008 +0200 Drop over-zealous errno checking * ... because libelf handles libc errors itself ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/bindir/ChangeLog | 5 + frysk-core/frysk/bindir/ftrace.java | 180 +++++++++++++++---- frysk-core/frysk/bindir/ftrace.xml-in | 107 +++++++++--- frysk-core/frysk/debuginfo/ChangeLog | 5 + .../debuginfo/ObjectDeclarationSearchEngine.java | 3 +- .../frysk/ftrace/AddrRule.java | 38 +++-- frysk-core/frysk/ftrace/ChangeLog | 21 +++ frysk-core/frysk/ftrace/Ftrace.java | 56 +++--- frysk-core/frysk/ftrace/FtraceController.java | 84 ++++++++- frysk-core/frysk/ftrace/TaskTracer.java | 61 ++++++- .../frysk/isa/watchpoints/TestWatchpoint.java | 3 +- frysk-core/frysk/proc/TestInstructions.java | 3 +- .../frysk/proc/TestTaskObserverWatchpoint.java | 3 +- frysk-core/frysk/proc/dead/TestLinuxCore.java | 3 +- .../frysk/proc/live/TestTaskObserverCode.java | 3 +- frysk-core/frysk/rt/FunctionBreakpoint.java | 3 +- frysk-core/frysk/symtab/ChangeLog | 7 + frysk-core/frysk/symtab/DwflSymbol.java | 9 +- frysk-core/frysk/symtab/SymbolFactory.java | 28 ++- frysk-core/frysk/util/ArchFormatter.java | 15 ++- frysk-core/frysk/util/ChangeLog | 4 + frysk-core/frysk/util/Glob.java | 4 +- frysk-sys/lib/dwfl/ChangeLog | 23 +++ frysk-sys/lib/dwfl/DwflDieBias.java | 8 + frysk-sys/lib/dwfl/ElfSymbolType.java | 23 +++ frysk-sys/lib/dwfl/SymbolBuilder.java | 3 +- frysk-sys/lib/dwfl/cni/DwflModule.cxx | 8 +- frysk-sys/lib/dwfl/cni/Elf.cxx | 10 +- 28 files changed, 566 insertions(+), 154 deletions(-) copy frysk-sys/lib/dwfl/DwflDieBias.java => frysk-core/frysk/ftrace/AddrRule.java (75%) First 500 lines of diff: diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog index 095bb5f..0c1c86b 100644 --- a/frysk-core/frysk/bindir/ChangeLog +++ b/frysk-core/frysk/bindir/ChangeLog @@ -1,3 +1,8 @@ +2008-05-14 Petr Machata + + * ftrace.java: Support address tracing. + * ftrace.xml-in: Describe it. + 2008-04-17 Andrew Cagney * TestFauxv.java: Use frysk.config.Prefix. diff --git a/frysk-core/frysk/bindir/ftrace.java b/frysk-core/frysk/bindir/ftrace.java index b82b090..a9706f5 100644 --- a/frysk-core/frysk/bindir/ftrace.java +++ b/frysk-core/frysk/bindir/ftrace.java @@ -42,6 +42,7 @@ package frysk.bindir; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; @@ -52,6 +53,7 @@ import gnu.classpath.tools.getopt.OptionGroup; import inua.util.PrintWriter; import frysk.debuginfo.PrintStackOptions; +import frysk.ftrace.AddrRule; import frysk.ftrace.Ftrace; import frysk.ftrace.FtraceController; import frysk.ftrace.PLTRule; @@ -61,13 +63,15 @@ import frysk.isa.signals.Signal; import frysk.isa.syscalls.Syscall; import frysk.proc.Proc; import frysk.rsl.Log; +import frysk.rsl.LogFactory; import frysk.util.CommandlineParser; import frysk.util.Glob; import frysk.util.StackPrintUtil; import frysk.util.Util; class ftrace { - private static final Log fine = Log.fine(ftrace.class); + static private final Log fine = LogFactory.fine(ftrace.class); + static private final Log warning = LogFactory.warning(ftrace.class); //Where to send the output. private PrintWriter writer; @@ -82,6 +86,7 @@ class ftrace { // reason we need these temporary array lists. private final List pltRules = new ArrayList(); private final List symRules = new ArrayList(); + private final List addrRules = new ArrayList(); private final List sysRules = new ArrayList(); private final List sigRules = new ArrayList(); private final FtraceController controller = new FtraceController(); @@ -96,37 +101,19 @@ class ftrace { String nameRe, String sonameRe, String versionRe); } - private List parseSymbolRules(String arg, SymbolRuleCreator creator) { + private interface RuleMatcher { + void rule(String str, boolean addition, boolean stackTrace, Collection c); + void check(); + } + + private List parseGenericRules(String arg, RuleMatcher matcher) + { String[] strs = arg.split(",", -1); List rules = new ArrayList(); for (int i = 0; i < strs.length; ++i) { - // 111 single fully qualified symbol: 'symbol@soname@@version' - // 101 symbol of given version in all dsos: 'symbol@@version' - // 100 symbol of given name from any dso: 'symbol' - // 011 all symbols of given version of the dso: '@soname@@version' - // 010 all symbols of given soname: '@soname' - // 001 all symbols of given version: '@@version' - // 000 all symbols of all versions in all dsos: '' - String str = strs[i]; - final String symbolRe, sonameRe, versionRe; final boolean addition; final boolean stackTrace; - int pos; - - if ((pos = str.indexOf("@@")) != -1) { - versionRe = str.substring(pos + 2); - str = str.substring(0, pos); - } - else - versionRe = null; - - if ((pos = str.indexOf('@')) != -1) { - sonameRe = str.substring(pos + 1); - str = str.substring(0, pos); - } - else - sonameRe = null; if (str.length() > 0 && str.charAt(0) == '-') { addition = false; @@ -142,20 +129,127 @@ class ftrace { else stackTrace = false; - if (!str.equals("")) - symbolRe = str; - else - symbolRe = null; - - fine.log(i + ": " + str + ": symbol=" + symbolRe - + ", soname=" + sonameRe + ", version=" + versionRe); - Rule rule = creator.createRule(addition, stackTrace, - symbolRe, sonameRe, versionRe); - rules.add(rule); + matcher.rule(str, addition, stackTrace, rules); } + matcher.check(); return rules; } + private List parseSymbolRules(String arg, final SymbolRuleCreator creator) { + return parseGenericRules(arg, new RuleMatcher() { + public void rule(String str, boolean addition, + boolean stackTrace, Collection rules) { + // 111 single fully qualified symbol: 'symbol@soname@@version' + // 101 symbol of given version in all dsos: 'symbol@@version' + // 100 symbol of given name from any dso: 'symbol' + // 011 all symbols of given version of the dso: '@soname@@version' + // 010 all symbols of given soname: '@soname' + // 001 all symbols of given version: '@@version' + // 000 all symbols of all versions in all dsos: '' + + final String symbolRe, sonameRe, versionRe; + int pos; + + if ((pos = str.indexOf("@@")) != -1) { + versionRe = str.substring(pos + 2); + str = str.substring(0, pos); + } + else + versionRe = null; + + if ((pos = str.indexOf('@')) != -1) { + sonameRe = str.substring(pos + 1); + str = str.substring(0, pos); + } + else + sonameRe = null; + + if (!str.equals("")) + symbolRe = str; + else + symbolRe = null; + + fine.log(str + ": symbol=" + symbolRe + + ", soname=" + sonameRe + + ", version=" + versionRe); + + rules.add(creator.createRule(addition, stackTrace, + symbolRe, sonameRe, + versionRe)); + } + public void check() {} + }); + } + + private final static Pattern addressPat = Pattern.compile("(0x)?[0-9a-fA-F]+"); + private final static Pattern sysnumPat = Pattern.compile("[0-9]+"); + + private List parseAddrRules(String arg) { + return parseGenericRules(arg, new RuleMatcher() { + class Delayed { + private final boolean addition; + private final boolean stackTrace; + private final long addr; + + public Delayed(boolean addition, boolean stackTrace, long addr) { + this.addition = addition; + this.stackTrace = stackTrace; + this.addr = addr; + } + + public Rule gotSoname(String sonameRe) { + return new AddrRule(this.addition, this.stackTrace, + this.addr, sonameRe); + } + } + + List delays = new ArrayList(); + + public void rule(String str, boolean addition, + boolean stackTrace, Collection rules) { + // address[@soname]. If soname is omitted, then + // the soname of next soname-full rule is used. + + String addressS, sonameRe; + int pos; + if ((pos = str.indexOf('@')) >= 0) { + sonameRe = str.substring(pos + 1); + addressS = str.substring(0, pos); + } else { + sonameRe = null; + addressS = str; + } + + if (!addressPat.matcher(addressS).matches()) { + warning.log("Ignoring rule `" + str + "' with mangled or missing address component."); + return; + } + + if (addressS.startsWith("0x")) + addressS = addressS.substring(2); + long addr = Long.parseLong(addressS, 16); + + fine.log(str + ": address=" + Long.toHexString(addr) + + ", soname=" + sonameRe); + if (sonameRe != null) { + for (Iterator it = delays.iterator(); it.hasNext(); ) + rules.add(((Delayed)it.next()).gotSoname(sonameRe)); + delays.clear(); + rules.add(new AddrRule(addition, stackTrace, + addr, sonameRe)); + } + else + delays.add(new Delayed(addition, stackTrace, addr)); + } + + public void check() { + if (!delays.isEmpty()) + warning.log("Ignoring", delays.size(), + "address rules that miss soname qualificator"); + } + }); + } + private static interface TraceableExaminer { int traceableNumber(Object traceable); String traceableName(Object traceable); @@ -165,7 +259,6 @@ class ftrace { String optionalPrefix) { String[] strs = arg.split(",", -1); - Pattern sysnumPat = Pattern.compile("[0-9]+"); List rules = new ArrayList(); for (int i = 0; i < strs.length; ++i) { // "14": traceable number 14 @@ -303,6 +396,11 @@ class ftrace { symRules.add(arg); } }); + group.add(new Option("addr", "trace address inside the binary", "RULE[,RULE]...") { + public void parsed(String arg) { + addrRules.add(arg); + } + }); group.add(new Option("stack", "stack trace on every traced entity") { public void parsed(String arg) { controller.stackTraceEverything(); @@ -340,7 +438,7 @@ class ftrace { writer = new PrintWriter(System.out); tracer.setWriter(writer); - if (!pltRules.isEmpty() || !symRules.isEmpty()) { + if (!pltRules.isEmpty() || !symRules.isEmpty() || !addrRules.isEmpty()) { // If tracing dynamic linker disabled, generate implicit // -@INTERP rule at the end of the chain. if (!allowInterpTracing) { @@ -348,6 +446,7 @@ class ftrace { symRules.add("-@INTERP"); } + // Symbol tracing class SymbolCreator implements SymbolRuleCreator { public Rule createRule(boolean addition, boolean stackTrace, String nameRe, String sonameRe, @@ -362,6 +461,7 @@ class ftrace { controller.gotSymRules(rules); } + // PLT tracing class PLTCreator implements SymbolRuleCreator { public Rule createRule(boolean addition, boolean stackTrace, String nameRe, String sonameRe, @@ -376,6 +476,10 @@ class ftrace { controller.gotPltRules(rules); } + // Address tracing + for (Iterator it = addrRules.iterator(); it.hasNext(); ) + controller.gotAddrRules(parseAddrRules((String)it.next())); + tracer.setTraceFunctions(controller, controller); } diff --git a/frysk-core/frysk/bindir/ftrace.xml-in b/frysk-core/frysk/bindir/ftrace.xml-in index f43fb9e..5ecc742 100644 --- a/frysk-core/frysk/bindir/ftrace.xml-in +++ b/frysk-core/frysk/bindir/ftrace.xml-in @@ -87,6 +87,7 @@ -sig=SIG[,SIG...] -plt=RULE[,RULE...] -sym=RULE[,RULE...] + -addr=RULE[,RULE...] -stack -- command arguments... @@ -128,32 +129,6 @@ - System Call and Signal Tracing - - - - -sys=SYSCALL[,SYSCALL...] - - Trace system calls that match given - SYSCALL ruleset. See - below for description of - SYSCALL syntax. - - - - - -sig=SIGNAL[,SIGNAL...] - - Trace signals that match given - SIGNAL ruleset. See - below for description of - SIGNAL syntax. - - - - - - Symbol Tracing @@ -202,6 +177,42 @@ + Other Traceable Events + + + + -sys=SYSCALL[,SYSCALL...] + + Trace system calls that match given + SYSCALL ruleset. See + below for description of + SYSCALL syntax. + + + + + -sig=SIGNAL[,SIGNAL...] + + Trace signals that match given + SIGNAL ruleset. See + below for description of + SIGNAL syntax. + + + + + -addr=RULE[,RULE...] + + Trace addresses given by + RULEs. See below for + description of address RULE + syntax. + + + + + + Other Options @@ -324,6 +335,50 @@ + ADDRESS RULE SYNTAX + + The process of establishing a working set of addresses that + should be traced is the same as for symbol rules, and the general + syntax reflects that. Each rule looks like this: + + [-][#]pattern + + Each pattern however looks like this: + + 0xaddress@soname + + Addresses are given in hexadecimal, even if initial 0x is + missing. + + soname component is the same as + in symbol tracing, i.e. it's a glob that's matched against a + soname of a library in which we wish to trace the address. Same + rules apply regarding INTERP and MAIN meta-sonames. Refer there + for detailed description. + + Even though soname is optional, + at least one soname has to be specified at the end of the + command. That's because in general it + makes no sense to want to trace the same address in ALL object + files at once. The components that are soname-less are assumed to + have a soname of the next soname-full component. + + + For example, this will trace two addresses from the main + binary, and stack trace one of them: + ftrace -addr=#0x08052780,08049314@MAIN -- ls + + + If you need to trace the same address in several files, you + can use the fact that the soname pattern is a glob. + + The addresses are assumed to be copied from readelf or + objdump. ftrace biases the value accordingly depending on where + the module is actually mapped. + + + + EXAMPLES diff --git a/frysk-core/frysk/debuginfo/ChangeLog b/frysk-core/frysk/debuginfo/ChangeLog index 424c906..c91a411 100644 --- a/frysk-core/frysk/debuginfo/ChangeLog +++ b/frysk-core/frysk/debuginfo/ChangeLog @@ -10,6 +10,11 @@ * TestObjectDeclarationSearchEngineTopDown.java (testGetObjectHashFileHashSymbol): enabled test. +2008-05-07 Petr Machata + + * ObjectDeclarationSearchEngine.java (getObjectUsingBinaryInfo): + Adjust SymbolBuilder instance to changes in interface. + 2008-04-30 Stan Cox * TypeFactory.java (getGccStructOrClassType): Set dieHash. diff --git a/frysk-core/frysk/debuginfo/ObjectDeclarationSearchEngine.java b/frysk-core/frysk/debuginfo/ObjectDeclarationSearchEngine.java index 0efe281..71cf9fd 100644 --- a/frysk-core/frysk/debuginfo/ObjectDeclarationSearchEngine.java +++ b/frysk-core/frysk/debuginfo/ObjectDeclarationSearchEngine.java @@ -188,7 +188,8 @@ public class ObjectDeclarationSearchEngine implements ExprSymTab{ public void symbol(String name, long value, long size, lib.dwfl.ElfSymbolType type, lib.dwfl.ElfSymbolBinding bind, - lib.dwfl.ElfSymbolVisibility visibility) + lib.dwfl.ElfSymbolVisibility visibility, + boolean defined) { if(name.equals(objectName)){ objectDeclaration = new SymbolObjectDeclaration(name, type, value, size); diff --git a/frysk-sys/lib/dwfl/DwflDieBias.java b/frysk-core/frysk/ftrace/AddrRule.java similarity index 75% copy from frysk-sys/lib/dwfl/DwflDieBias.java copy to frysk-core/frysk/ftrace/AddrRule.java index ecc2876..15cf3ba 100644 --- a/frysk-sys/lib/dwfl/DwflDieBias.java +++ b/frysk-core/frysk/ftrace/AddrRule.java @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2005, Red Hat Inc. +// 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 @@ -37,23 +37,29 @@ // version and license this file solely under the GPL without // exception. -package lib.dwfl; +package frysk.ftrace; -import java.util.ArrayList; -import java.util.Iterator; +import java.util.regex.Pattern; +import frysk.util.Glob; -public class DwflDieBias -{ - public DwarfDie die; - public long bias; +public class AddrRule extends Rule { + final public long addr; + final public Pattern sonamePattern; hooks/post-receive -- frysk system monitor/debugger