From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2981 invoked by alias); 22 Nov 2007 15:29:22 -0000 Received: (qmail 2953 invoked by uid 9561); 22 Nov 2007 15:29:21 -0000 Date: Thu, 22 Nov 2007 15:29:00 -0000 Message-ID: <20071122152921.2938.qmail@sourceware.org> From: swagiaal@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: swagiaal: fstack now takes a -n option. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: e968bea4004ca57402fc394bfa30edbf82756362 X-Git-Newrev: 3f968fbe46d1ba360e37d072921d716e147f6826 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/msg00424.txt.bz2 The branch, master has been updated via 3f968fbe46d1ba360e37d072921d716e147f6826 (commit) from e968bea4004ca57402fc394bfa30edbf82756362 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 3f968fbe46d1ba360e37d072921d716e147f6826 Author: Sami Wagiaalla Date: Wed Nov 21 14:30:05 2007 -0500 swagiaal: fstack now takes a -n option. frysk-core/frysk/bindir/ChangeLog +2007-11-21 Sami Wagiaalla + + * TestFstack.java (testBackTraceWithDashN): New test. + (testBackTraceWithDashNDashA): New test. + * fstack.java (Stacker.Stacker): Added number-of-frames option + and handling. + frysk-core/frysk/debuginfo/ChangeLog +2007-11-21 Sami Wagiaalla + + * DebugInfoStackFactory.java (printTaskStackTrace): Added + numberOfFrames argument. + (printVirtualTaskStackTrace): Ditto. + frysk-core/frysk/stack/ChangeLog +2007-11-21 Sami Wagiaalla + + * StackFactory.java (printTaskStackTrace): Added number of + frames check. + frysk-core/frysk/util/ChangeLog +2007-11-21 Sami Wagiaalla + + * StacktraceAction.java: Now passes numberOfFrames argument. + ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/bindir/ChangeLog | 7 ++++ frysk-core/frysk/bindir/TestFstack.java | 37 ++++++++++++++++++++ frysk-core/frysk/bindir/fstack.java | 30 ++++++++++++---- frysk-core/frysk/debuginfo/ChangeLog | 6 +++ .../frysk/debuginfo/DebugInfoStackFactory.java | 10 +++-- frysk-core/frysk/debuginfo/TestFrameDebugInfo.java | 2 +- frysk-core/frysk/proc/dead/TestLinuxCore.java | 36 ++++++++++--------- frysk-core/frysk/stack/ChangeLog | 5 +++ frysk-core/frysk/stack/StackFactory.java | 10 ++++- frysk-core/frysk/util/ChangeLog | 4 ++ frysk-core/frysk/util/StacktraceAction.java | 16 +++++--- frysk-core/frysk/util/StressTestFStack.java | 2 +- frysk-core/frysk/util/TestFStack.java | 8 ++-- 13 files changed, 131 insertions(+), 42 deletions(-) First 500 lines of diff: diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog index 4dbced2..3ca398a 100644 --- a/frysk-core/frysk/bindir/ChangeLog +++ b/frysk-core/frysk/bindir/ChangeLog @@ -1,3 +1,10 @@ +2007-11-21 Sami Wagiaalla + + * TestFstack.java (testBackTraceWithDashN): New test. + (testBackTraceWithDashNDashA): New test. + * fstack.java (Stacker.Stacker): Added number-of-frames option + and handling. + 2007-11-20 Sami Wagiaalla * TestFstack.java (testBackTraceWithDashC): Removed check for diff --git a/frysk-core/frysk/bindir/TestFstack.java b/frysk-core/frysk/bindir/TestFstack.java index d45899d..fa0f4a4 100644 --- a/frysk-core/frysk/bindir/TestFstack.java +++ b/frysk-core/frysk/bindir/TestFstack.java @@ -138,4 +138,41 @@ public class TestFstack e.expect("\\#3 .*main"); } + public void testBackTraceWithDashN () { + Expect e = fstack("funit-long-stack", new String[]{"-n","5"}); + e.expect("\\#0 .*crash[^\\r\\n]*"); + e.expect("\\#1 .*first[^\\r\\n]*"); + e.expect("\\#2 .*first[^\\r\\n]*"); + e.expect("\\#3 .*first[^\\r\\n]*"); + e.expect("\\#4 .*first[^\\r\\n]*"); + e.expect("..."); + e.close(); + + e = fstack("funit-long-stack", new String[]{"-n","4"}); + e.expect("\\#0 .*crash[^\\r\\n]*"); + e.expect("\\#1 .*first[^\\r\\n]*"); + e.expect("\\#2 .*first[^\\r\\n]*"); + e.expect("\\#3 .*first[^\\r\\n]*"); + e.expect("..."); + e.close(); + + e = fstack("funit-long-stack", new String[]{"-n","0"}); + e.expect("\\#51 .*first[^\\r\\n]*"); + e.close(); + + } + + public void testBackTraceWithDashNDashA () { + Expect e = fstack("funit-long-stack", new String[]{"-n","5", "-a"}); + e.expect("\\#0 .*crash[^\\r\\n]*"); + e.expect("\\#1 .*first[^\\r\\n]*"); + e.expect("\\#2 .*first[^\\r\\n]*"); + e.expect("\\#3 .*first[^\\r\\n]*"); + e.expect("\\#4 .*first[^\\r\\n]*"); + e.expect("..."); + e.close(); + } + + + } diff --git a/frysk-core/frysk/bindir/fstack.java b/frysk-core/frysk/bindir/fstack.java index 2889f39..bb4f250 100644 --- a/frysk-core/frysk/bindir/fstack.java +++ b/frysk-core/frysk/bindir/fstack.java @@ -51,11 +51,11 @@ import frysk.proc.ProcBlockAction; import frysk.proc.ProcCoreAction; import frysk.proc.ProcId; import frysk.util.CommandlineParser; +import frysk.util.CoreExePair; import frysk.util.StacktraceAction; import frysk.util.Util; import gnu.classpath.tools.getopt.Option; import gnu.classpath.tools.getopt.OptionException; -import frysk.util.CoreExePair; public final class fstack { @@ -67,6 +67,7 @@ public final class fstack private static PrintWriter printWriter = new PrintWriter(System.out); + static int numberOfFrames; static boolean virtualFrames = false; static boolean elfOnly = true; static boolean printParameters = false; @@ -78,11 +79,11 @@ public final class fstack { Proc proc; - public Stacker (PrintWriter printWriter, Proc theProc, Event theEvent,boolean elfOnly, boolean virtualFrames, + public Stacker (PrintWriter printWriter, Proc theProc, Event theEvent,int numberOfFrames, boolean elfOnly, boolean virtualFrames, boolean printParameters, boolean printScopes, boolean fullpath, boolean printSourceLibrary) { - super(printWriter, theProc, theEvent, elfOnly,virtualFrames, printParameters, printScopes, fullpath,printSourceLibrary); + super(printWriter, theProc, theEvent, numberOfFrames, elfOnly,virtualFrames, printParameters, printScopes, fullpath,printSourceLibrary); this.proc = theProc; } @@ -141,7 +142,7 @@ public final class fstack { Proc proc = Util.getProcFromCoreExePair(coreExePair); - stacker = new Stacker(printWriter, proc, new PrintEvent(),elfOnly,virtualFrames,printParameters,printScopes, fullpath,printSourceLibrary); + stacker = new Stacker(printWriter, proc, new PrintEvent(), numberOfFrames, elfOnly,virtualFrames,printParameters,printScopes, fullpath,printSourceLibrary); new ProcCoreAction(proc, stacker); Manager.eventLoop.run(); } @@ -149,13 +150,14 @@ public final class fstack private static void stackPid (ProcId procId) { Proc proc = Util.getProcFromPid(procId); - stacker = new Stacker(printWriter, proc, new AbandonPrintEvent(proc),elfOnly,virtualFrames,printParameters,printScopes, fullpath,printSourceLibrary); + stacker = new Stacker(printWriter, proc, new AbandonPrintEvent(proc), numberOfFrames, elfOnly,virtualFrames,printParameters,printScopes, fullpath,printSourceLibrary); new ProcBlockAction(proc, stacker); Manager.eventLoop.run(); } public static void main (String[] args) { + parser = new CommandlineParser("fstack") { //@Override @@ -168,12 +170,26 @@ public final class fstack //@Override public void parsePids (ProcId[] pids) { + for (int i = 0; i < pids.length; i++) stackPid(pids[i]); } - }; - + }; + + parser.add(new Option("number-of-frames", 'n', "number of frames to print. Use -n 0 or" + + " -n all to print all frames.", "") { + public void parsed(String arg) throws OptionException { + if(arg.equals("all")){ + numberOfFrames = 0; + }else{ + numberOfFrames = Integer.parseInt(arg); + return; + } + } + }); + + parser.add(new Option("all", 'a', "print all information that can currently be retrieved" + "about the stack\n" + "this is equivalent to -p functions,params,scopes,fullpath"){ diff --git a/frysk-core/frysk/debuginfo/ChangeLog b/frysk-core/frysk/debuginfo/ChangeLog index a088723..54ca18b 100644 --- a/frysk-core/frysk/debuginfo/ChangeLog +++ b/frysk-core/frysk/debuginfo/ChangeLog @@ -1,3 +1,9 @@ +2007-11-21 Sami Wagiaalla + + * DebugInfoStackFactory.java (printTaskStackTrace): Added + numberOfFrames argument. + (printVirtualTaskStackTrace): Ditto. + 2007-11-20 Stan Cox * TypeEntry.java (getType): Remove reference to DwarfDie.getBaseType(). diff --git a/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java b/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java index 325c389..83a0cb3 100644 --- a/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java +++ b/frysk-core/frysk/debuginfo/DebugInfoStackFactory.java @@ -97,22 +97,22 @@ public class DebugInfoStackFactory { return innermostFrame; } - public static final void printTaskStackTrace (PrintWriter printWriter, Task task, boolean printParameters, boolean printScopes, boolean fullpath) + public static final void printTaskStackTrace (PrintWriter printWriter, Task task, int numberOfFrames, boolean printParameters, boolean printScopes, boolean fullpath) { if (task != null){ printWriter.println("Task #" + task.getTid()); DebugInfoFrame frame = createDebugInfoStackTrace(task); - printStackTrace(printWriter, frame, 20, printParameters,printScopes,fullpath); + printStackTrace(printWriter, frame, numberOfFrames, printParameters,printScopes,fullpath); } printWriter.flush(); } - public static final void printVirtualTaskStackTrace (PrintWriter printWriter, Task task, boolean printParameters, boolean printScopes, boolean fullpath) + public static final void printVirtualTaskStackTrace (PrintWriter printWriter, Task task, int numberOfFrames, boolean printParameters, boolean printScopes, boolean fullpath) { if (task != null){ printWriter.println("Task #" + task.getTid()); DebugInfoFrame frame = createVirtualStackTrace(task); - printStackTrace(printWriter,frame, 20, printParameters,printScopes,fullpath); + printStackTrace(printWriter,frame, numberOfFrames, printParameters,printScopes,fullpath); } printWriter.flush(); } @@ -124,6 +124,8 @@ public class DebugInfoStackFactory { boolean printScopes, boolean fullpath) { + System.out.println("DebugInfoStackFactory.printStackTrace() numberOfFrames " + numberOfFrames); + int count = 0; for (DebugInfoFrame frame = topFrame; frame != null; frame = frame.getOuterDebugInfoFrame()) { diff --git a/frysk-core/frysk/debuginfo/TestFrameDebugInfo.java b/frysk-core/frysk/debuginfo/TestFrameDebugInfo.java index 8342b3c..3cf8375 100644 --- a/frysk-core/frysk/debuginfo/TestFrameDebugInfo.java +++ b/frysk-core/frysk/debuginfo/TestFrameDebugInfo.java @@ -188,7 +188,7 @@ public class TestFrameDebugInfo Task task = (new DaemonBlockedAtSignal("funit-stack-inlined")).getMainTask(); StringWriter stringWriter = new StringWriter(); - DebugInfoStackFactory.printVirtualTaskStackTrace(new PrintWriter(stringWriter), task, true, true, true); + DebugInfoStackFactory.printVirtualTaskStackTrace(new PrintWriter(stringWriter), task,0, true, true, true); assertTrue("contains inline", stringWriter.getBuffer().toString().contains("inline")); assertTrue("contains first", stringWriter.getBuffer().toString().contains("first")); diff --git a/frysk-core/frysk/proc/dead/TestLinuxCore.java b/frysk-core/frysk/proc/dead/TestLinuxCore.java index 9eaf26d..8d41403 100644 --- a/frysk-core/frysk/proc/dead/TestLinuxCore.java +++ b/frysk-core/frysk/proc/dead/TestLinuxCore.java @@ -39,34 +39,36 @@ package frysk.proc.dead; -import frysk.Config; import inua.eio.ByteBuffer; import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; + +import lib.dwfl.Dwfl; +import lib.dwfl.DwflModule; +import lib.dwfl.SymbolBuilder; +import frysk.Config; +import frysk.dwfl.DwflCache; +import frysk.event.Event; +import frysk.event.RequestStopEvent; import frysk.isa.IA32Registers; import frysk.proc.Action; -import frysk.proc.Task; -import frysk.proc.Proc; -import frysk.proc.Host; import frysk.proc.Auxv; -import frysk.testbed.DaemonBlockedAtSignal; -import frysk.testbed.TestLib; -import frysk.proc.ProcId; +import frysk.proc.Host; import frysk.proc.Manager; import frysk.proc.MemoryMap; -import frysk.proc.TaskObserver; -import frysk.util.CoredumpAction; -import frysk.util.StacktraceAction; -import frysk.event.Event; -import frysk.event.RequestStopEvent; +import frysk.proc.Proc; import frysk.proc.ProcBlockAction; import frysk.proc.ProcCoreAction; +import frysk.proc.ProcId; +import frysk.proc.Task; +import frysk.proc.TaskObserver; +import frysk.testbed.DaemonBlockedAtSignal; import frysk.testbed.LegacyOffspring; - -import lib.dwfl.*; -import frysk.dwfl.*; +import frysk.testbed.TestLib; +import frysk.util.CoredumpAction; +import frysk.util.StacktraceAction; public class TestLinuxCore extends TestLib @@ -156,7 +158,7 @@ public class TestLinuxCore // Create a Stacktrace of the blocked live process liveStacktrace = new StacktraceAction(new PrintWriter(liveStackOutput), testProc, - new RequestStopEvent(Manager.eventLoop), + new RequestStopEvent(Manager.eventLoop),0, true, false, false, false, false, false) { @@ -187,7 +189,7 @@ public class TestLinuxCore // Create a stackktrace of a the corefile process coreStacktrace = new StacktraceAction(new PrintWriter(coreStackOutput), coreProc, - new PrintEvent(), + new PrintEvent(),0, true, false, false, false , false, false) { diff --git a/frysk-core/frysk/stack/ChangeLog b/frysk-core/frysk/stack/ChangeLog index 110edfe..2684148 100644 --- a/frysk-core/frysk/stack/ChangeLog +++ b/frysk-core/frysk/stack/ChangeLog @@ -1,3 +1,8 @@ +2007-11-21 Sami Wagiaalla + + * StackFactory.java (printTaskStackTrace): Added number of + frames check. + 2007-11-19 Mark Wielaard * LibunwindFrame.java (getAddress): Don't do a proc name lookup, diff --git a/frysk-core/frysk/stack/StackFactory.java b/frysk-core/frysk/stack/StackFactory.java index 106f38f..0bdaced 100644 --- a/frysk-core/frysk/stack/StackFactory.java +++ b/frysk-core/frysk/stack/StackFactory.java @@ -87,13 +87,19 @@ public class StackFactory public static final void printTaskStackTrace(PrintWriter writer, Task task, - boolean printSourceLibrary) { + boolean printSourceLibrary, int numberOfFrames) { if (task != null) { writer.print("Task #"); writer.print(task.getTid()); writer.println(); Frame frame = StackFactory.createFrame(task); - for (; frame != null; frame = frame.getOuter()) { + for (int i = 0; frame != null; frame = frame.getOuter(),i++) { + + if (numberOfFrames > 0 && i >= numberOfFrames) { + writer.println("..."); + break; + } + frame.printLevel(writer); writer.print(" "); frame.toPrint(writer, printSourceLibrary); diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog index 0c48a08..5c50a53 100644 --- a/frysk-core/frysk/util/ChangeLog +++ b/frysk-core/frysk/util/ChangeLog @@ -1,3 +1,7 @@ +2007-11-21 Sami Wagiaalla + + * StacktraceAction.java: Now passes numberOfFrames argument. + 2007-11-20 Andrew Cagney * X8664LinuxElfCorefile.java: Fix typo; "eflags" -> "rflags". diff --git a/frysk-core/frysk/util/StacktraceAction.java b/frysk-core/frysk/util/StacktraceAction.java index 51087e7..2418dc7 100644 --- a/frysk-core/frysk/util/StacktraceAction.java +++ b/frysk-core/frysk/util/StacktraceAction.java @@ -79,6 +79,7 @@ public abstract class StacktraceAction private Event event; boolean elfOnly; + private final int numberOfFrames; boolean printParameters; boolean printScopes; boolean fullpath; @@ -93,6 +94,7 @@ public abstract class StacktraceAction * @param theProc the process to run the stack trace on. * @param theEvent an event to run on completion of the stack trace. For * example: Stop the eventLoop and exit the program. + * @param numberOfFrames number of frames to print pass value <=0 to print all frames. * @param elfOnly if true print an elf only stack back trace not referring to any * stack debug information. Otherwise, print a rich stack trace using * debug information. @@ -104,10 +106,11 @@ public abstract class StacktraceAction * file path is printed other wise only the name of the file is printed. * @throws ProcException */ - public StacktraceAction (PrintWriter printWriter, Proc theProc, Event theEvent,boolean elfOnly, boolean virtualFrames, boolean printParameters, boolean printScopes, boolean fullpath, boolean printSourceLibrary) + public StacktraceAction (PrintWriter printWriter, Proc theProc, Event theEvent, int numberOfFrames, boolean elfOnly, boolean virtualFrames, boolean printParameters, boolean printScopes, boolean fullpath, boolean printSourceLibrary) { event = theEvent; - + + this.numberOfFrames = numberOfFrames; this.virtualFrames = virtualFrames; this.elfOnly = elfOnly; this.printParameters = printParameters; @@ -116,7 +119,7 @@ public abstract class StacktraceAction this.printSourceLibrary = printSourceLibrary; this.printWriter = printWriter; - Manager.eventLoop.add(new InterruptEvent(theProc)); + Manager.eventLoop.add(new InterruptEvent(theProc)); } public final void existingTask (Task task) @@ -150,14 +153,15 @@ public abstract class StacktraceAction Task task = (Task) iter.next(); if(elfOnly){ - StackFactory.printTaskStackTrace(printWriter,task,printSourceLibrary); + StackFactory.printTaskStackTrace(printWriter,task,printSourceLibrary, numberOfFrames); }else{ if(virtualFrames){ - DebugInfoStackFactory.printVirtualTaskStackTrace(printWriter,task,printParameters,printScopes,fullpath); + DebugInfoStackFactory.printVirtualTaskStackTrace(printWriter,task,numberOfFrames, printParameters,printScopes,fullpath); }else{ - DebugInfoStackFactory.printTaskStackTrace(printWriter,task,printParameters,printScopes,fullpath); + DebugInfoStackFactory.printTaskStackTrace(printWriter,task,numberOfFrames, printParameters,printScopes,fullpath); } } + printWriter.println(); } logger.log(Level.FINE, "{0} exiting printTasks\n", this); } diff --git a/frysk-core/frysk/util/StressTestFStack.java b/frysk-core/frysk/util/StressTestFStack.java index 49cb8bb..deb2b88 100644 --- a/frysk-core/frysk/util/StressTestFStack.java +++ b/frysk-core/frysk/util/StressTestFStack.java @@ -88,7 +88,7 @@ public class StressTestFStack { proc.requestAbandonAndRunEvent(new RequestStopEvent(Manager.eventLoop)); } - }, true,false, false, false, false,true) + },0, true,false, false, false, false,true) { public void addFailed (Object observable, Throwable w) diff --git a/frysk-core/frysk/util/TestFStack.java b/frysk-core/frysk/util/TestFStack.java index c2fe417..42b5df8 100644 --- a/frysk-core/frysk/util/TestFStack.java +++ b/frysk-core/frysk/util/TestFStack.java @@ -93,18 +93,18 @@ public class TestFStack + "#[\\d]+ 0x[\\da-f]+ in server \\(\\).*\n" + "#[\\d]+ 0x[\\da-f]+ in main \\(\\).*\n" + "#[\\d]+ 0x[\\da-f]+ in __libc_start_main \\(\\).*\n" - + "#[\\d]+ 0x[\\da-f]+ in _start \\(\\).*\n"; + + "#[\\d]+ 0x[\\da-f]+ in _start \\(\\).*\n\n"; String thread = "Task #\\d+\n" + "(#[\\d]+ 0x[\\da-f]+ in .*\n)*" + "#[\\d]+ 0x[\\da-f]+ in server \\(\\).*\n" + "#[\\d]+ 0x[\\da-f]+ in start_thread \\(\\).*\n" - + "#[\\d]+ 0x[\\da-f]+ in (__)?clone \\(\\).*\n"; + + "#[\\d]+ 0x[\\da-f]+ in (__)?clone \\(\\).*\n\n"; final Proc proc = ackProc.assertFindProcAndTasks(); StacktraceAction stacker; - stacker = new StacktraceAction(new PrintWriter(stringWriter),proc, new RequestStopEvent(Manager.eventLoop), true, false,false, false, false,true) + stacker = new StacktraceAction(new PrintWriter(stringWriter),proc, new RequestStopEvent(Manager.eventLoop),20, true, false,false, false, false,true) { public void addFailed (Object observable, Throwable w) @@ -145,7 +145,7 @@ public class TestFStack Proc proc = (Proc) iter.next(); StacktraceAction stacker; - stacker = new StacktraceAction(new PrintWriter(stringWriter),proc, new RequestStopEvent(Manager.eventLoop), true, false,false, false, false,true) + stacker = new StacktraceAction(new PrintWriter(stringWriter),proc, new RequestStopEvent(Manager.eventLoop),20, true, false,false, false, false,true) { public void addFailed (Object observable, Throwable w) hooks/post-receive -- frysk system monitor/debugger