From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12126 invoked by alias); 18 May 2007 20:28:10 -0000 Received: (qmail 11989 invoked by uid 22791); 18 May 2007 20:28:06 -0000 X-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,DK_POLICY_SIGNSOME,SPF_HELO_PASS,SPF_PASS,TW_DW X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 18 May 2007 20:28:01 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l4IKRw6o014516 for ; Fri, 18 May 2007 16:27:58 -0400 Received: from pobox.toronto.redhat.com (pobox.toronto.redhat.com [172.16.14.4]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l4IKRvVE008168; Fri, 18 May 2007 16:27:57 -0400 Received: from [172.16.14.55] (toner.toronto.redhat.com [172.16.14.55]) by pobox.toronto.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id l4IKRvQj030877; Fri, 18 May 2007 16:27:57 -0400 Message-ID: <464E0C4D.9050701@redhat.com> Date: Sat, 19 May 2007 01:48:00 -0000 From: Sami Wagiaalla User-Agent: Thunderbird 1.5.0.10 (X11/20070302) MIME-Version: 1.0 To: Stan Cox , Andrew Cagney CC: frysk@sourceware.org Subject: proposed patch Content-Type: multipart/mixed; boundary="------------060201070907010708080102" X-Virus-Checked: Checked by ClamAV on sourceware.org X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q2/txt/msg00176.txt.bz2 This is a multi-part message in MIME format. --------------060201070907010708080102 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 264 Hi Andrew and Stan, After a huge learning curve here is a patch of me getting started on the stack work. Please take a close look. I just want to make sure I am on the right track specifics can be sorted out later. Any guidance is appreciated. Thanx, Sami --------------060201070907010708080102 Content-Type: text/x-patch; name="RichFrame.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="RichFrame.patch" Content-length: 15610 ? RichFrame.patch Index: .classpath =================================================================== RCS file: /cvs/frysk/frysk-top/.classpath,v retrieving revision 1.14 diff -u -r1.14 .classpath --- .classpath 4 May 2007 18:26:54 -0000 1.14 +++ .classpath 18 May 2007 20:22:57 -0000 @@ -16,5 +16,6 @@ + Index: .settings/org.eclipse.jdt.core.prefs =================================================================== RCS file: /cvs/frysk/frysk-top/.settings/org.eclipse.jdt.core.prefs,v retrieving revision 1.5 diff -u -r1.5 org.eclipse.jdt.core.prefs --- .settings/org.eclipse.jdt.core.prefs 5 Apr 2007 19:55:13 -0000 1.5 +++ .settings/org.eclipse.jdt.core.prefs 18 May 2007 20:22:57 -0000 @@ -1,4 +1,4 @@ -#Mon Apr 02 11:16:02 EDT 2007 +#Fri May 18 15:21:49 EDT 2007 eclipse.preferences.version=1 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=18 @@ -34,13 +34,13 @@ org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=next_line_shifted -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line_shifted +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines=true org.eclipse.jdt.core.formatter.comment.format_comments=true Index: frysk-core/frysk/pkglibdir/funit-stacks.c =================================================================== RCS file: frysk-core/frysk/pkglibdir/funit-stacks.c diff -N frysk-core/frysk/pkglibdir/funit-stacks.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ frysk-core/frysk/pkglibdir/funit-stacks.c 18 May 2007 20:22:57 -0000 @@ -0,0 +1,32 @@ +#include + +void third(){ + if(1+1){ + while(1){ + { + exit(1); + } + } + } +} + +void second(){ + + third(); + +} + +void first(){ + + second(); + +} + + +int main(){ + + first (); + + return 0; +} + Index: frysk-core/frysk/proc/TestLib.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/proc/TestLib.java,v retrieving revision 1.154 diff -u -r1.154 TestLib.java --- frysk-core/frysk/proc/TestLib.java 18 May 2007 19:27:47 -0000 1.154 +++ frysk-core/frysk/proc/TestLib.java 18 May 2007 20:22:58 -0000 @@ -840,6 +840,11 @@ { mainTask.requestUnblock(execBlockingObserver); } + + public Task getMainTask () + { + return this.mainTask; + } } /** Index: frysk-core/frysk/rt/Frame.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/rt/Frame.java,v retrieving revision 1.13 diff -u -r1.13 Frame.java --- frysk-core/frysk/rt/Frame.java 15 May 2007 21:38:20 -0000 1.13 +++ frysk-core/frysk/rt/Frame.java 18 May 2007 20:22:58 -0000 @@ -123,7 +123,7 @@ */ public abstract Line[] getLines (); - public final Subprogram getSubprogram () + public Subprogram getSubprogram () { return subprogram; } Index: frysk-core/frysk/rt/RichFrame.java =================================================================== RCS file: frysk-core/frysk/rt/RichFrame.java diff -N frysk-core/frysk/rt/RichFrame.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ frysk-core/frysk/rt/RichFrame.java 18 May 2007 20:22:58 -0000 @@ -0,0 +1,144 @@ +// This file is part of the program FRYSK. +// +// Copyright 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.rt; + +import lib.dw.DwTagEncodings; +import lib.dw.DwarfDie; +import lib.dw.Dwfl; +import lib.dw.DwflDieBias; +import lib.unwind.Cursor; +import frysk.proc.Task; + +public class RichFrame + extends RemoteFrame +{ + + RichFrame (Cursor cursor, Task task) + { + super(cursor, task); + } + + public final Subprogram getSubprogram () + { + Subprogram subprogram = super.getSubprogram(); + + if (subprogram == null) { + + Dwfl dwfl = new Dwfl(this.getTask().getProc().getPid()); + DwflDieBias bias = dwfl.getDie(getAdjustedAddress()); + + if (bias != null) { + + DwarfDie[] scopes = bias.die.getScopes(getAdjustedAddress()); + + for (int i = 0; i < scopes.length; i++) { + if (scopes[i].getTag() == DwTagEncodings.DW_TAG_subprogram_) { + subprogram = new Subprogram(scopes[i]); + } + } + } + this.setSubprogram(subprogram); + } + + return subprogram; + } + + public Frame getOuter () + { + if (outer == null) { + Cursor newCursor = this.cursor.unwind(); + if (newCursor != null) { + outer = new RichFrame(newCursor, task); + outer.inner = this; + } + } + return outer; + } + + /** + * Return a simple string representation of this stack frame. The + * returned string is suitable for display to the user. + */ + public String toPrint (boolean name) + { + // XXX: There is always an inner cursor. + if (this.cursor == null) + return "Empty stack trace"; + + // Pad the address based on the task's word size. + StringBuffer builder = new StringBuffer("0x"); + String addr = Long.toHexString(getAddress()); + int padding = 2 * task.getIsa().getWordSize() - addr.length(); + for (int i = 0; i < padding; ++i) + builder.append('0'); + builder.append(addr); + + if (getSubprogram() != null) { + builder.append(" dwarf: " + getSubprogram().getName()); + } + else { + // Print the symbol, if known append (). + Symbol symbol = getSymbol(); + builder.append(" in "); + builder.append(symbol.getDemangledName()); + if (symbol != Symbol.UNKNOWN) + builder.append(" ()"); + } + + // If there's line number information append that. + Line[] lines = getLines(); + for (int i = 0; i < lines.length; i++) { + Line line = lines[i]; + builder.append(" from: "); + if (name) { + builder.append(line.getFile().getName()); + builder.append(": line #"); + builder.append(line.getLine()); + } + else { + builder.append(line.getFile().getPath()); + builder.append("#"); + builder.append(line.getLine()); + } + } + return builder.toString(); + } +} Index: frysk-core/frysk/rt/StackFactory.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/rt/StackFactory.java,v retrieving revision 1.26 diff -u -r1.26 StackFactory.java --- frysk-core/frysk/rt/StackFactory.java 11 May 2007 15:32:11 -0000 1.26 +++ frysk-core/frysk/rt/StackFactory.java 18 May 2007 20:22:58 -0000 @@ -142,7 +142,7 @@ buffer.append(new StringBuffer("Task #" + task.getTid() + "\n")); int count = 0; - for (Frame frame = StackFactory.createFrame(task); frame != null; frame = frame.getOuter()) + for (Frame frame = StackFactory.createRichFrame(task,0); frame != null; frame = frame.getOuter()) { // FIXME: do valgrind-like '=== PID ===' ? StringBuffer output = new StringBuffer("#" + count + " " @@ -171,5 +171,20 @@ return string; } + + public static RichFrame createRichFrame (Task task, int i) + { + Unwind unwinder; + if (task.getIsa().getWordSize() == 4) + unwinder = new UnwindX86(); + else + unwinder = new UnwindNative(); + AddressSpace addressSpace = new AddressSpace(unwinder, lib.unwind.ByteOrder.DEFAULT); + StackAccessors accessors = new StackAccessors(addressSpace, task, + lib.unwind.ByteOrder.DEFAULT); + + Cursor cursor = new Cursor(addressSpace, accessors); + return new RichFrame(cursor, task); + } } Index: frysk-core/frysk/rt/Subprogram.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/rt/Subprogram.java,v retrieving revision 1.2 diff -u -r1.2 Subprogram.java --- frysk-core/frysk/rt/Subprogram.java 11 May 2007 11:43:52 -0000 1.2 +++ frysk-core/frysk/rt/Subprogram.java 18 May 2007 20:22:58 -0000 @@ -43,6 +43,7 @@ package frysk.rt; +import lib.dw.DwarfDie; import frysk.value.Value; public class Subprogram @@ -51,7 +52,22 @@ Subprogram outer; LexicalBlock block; Value[] parameters; + private DwarfDie die; + public Subprogram (DwarfDie die) + { + this.die = die; + } + + public Subprogram () + { + + } + + public String getName(){ + return this.die.getName(); + } + public LexicalBlock getBlock () { return block; Index: frysk-core/frysk/rt/TestRichFrame.java =================================================================== RCS file: frysk-core/frysk/rt/TestRichFrame.java diff -N frysk-core/frysk/rt/TestRichFrame.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ frysk-core/frysk/rt/TestRichFrame.java 18 May 2007 20:22:58 -0000 @@ -0,0 +1,107 @@ +// This file is part of the program FRYSK. +// +// Copyright 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.rt; + +import java.util.logging.Logger; + +import frysk.proc.Action; +import frysk.proc.Manager; +import frysk.proc.Task; +import frysk.proc.TestLib; +import frysk.proc.TaskObserver.Terminating; + +public class TestRichFrame + extends TestLib +{ + + Logger logger = Logger.getLogger("frysk"); + + public void testRichFrame () + { + Task task = getStoppedTask(); + + RichFrame richFrame = StackFactory.createRichFrame(task, 0); + String string = StackFactory.printStackTrace(richFrame); + System.out.println("TestRichFrame.testRichFrame()\n"+string); + + assertTrue("first", string.contains("first")); + assertTrue("second", string.contains("second")); + assertTrue("third",string.contains("third")); + + } + + public Task getStoppedTask () + { + + AttachedDaemonProcess ackProc = new AttachedDaemonProcess( + new String[] { getExecPath("funit-stacks") }); + + Task task = ackProc.getMainTask(); + + task.requestAddTerminatingObserver(new Terminating() + { + + public void deletedFrom (Object observable) + { + } + + public void addedTo (Object observable) + { + } + + public Action updateTerminating (Task task, boolean signal, int value) + { + Manager.eventLoop.requestStop(); + return Action.BLOCK; + } + + public void addFailed (Object observable, Throwable w) + { + throw new RuntimeException(w); + } + }); + ackProc.resume(); + assertRunUntilStop("Attach to process"); + + return task; + } + +} --------------060201070907010708080102--