This is the mail archive of the frysk@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: StackFrame.toString()


Tom> I thought it would be handy if StackFrame had a toString method that
Tom> did something sensible.  Patch appended.

I've updated this patch to add javadoc for the accessors I use.

However in doing so I noticed that some of the things I thought were
valid, no longer are.

In particular getSourceFile() will never return null now -- instead
sourceFile is set to "<Unknown file>" in the constructor.  I think the
previous behavior is preferable -- now there is no good way to tell
whether the stack frame's source file is known.  I didn't see anything
depending on this, so I changed it back.

Also I noticed a typo in the API, the updated patch fixes this
everywhere.

Before I check this in (assuming it blessed of course) I wanted to ask
about all the new accessors in StackFrame.  Any word on what their
boundary values are?  Will startLine == lineNum always be true?  (And
if so, how about we get rid of one of them entirely?)  What are the
startOffset and endOffset fields for?

I tried to run this through 'make check' on x86 FC5 but it hung in the
breakpoint tests; I assume this isn't caused by this patch but I
haven't checked yet.  In any case this isn't quite ready since I'd
like to document the other accessors first.

Tom

Index: frysk-core/frysk/rt/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* StackFrame.java (toString): New method.
	(StackFrame): Don't initialize sourceFile if file is not known.
	(startOffset): Renamed.
	(getStartOffset): Likewise.

Index: frysk-core/frysk/rt/StackFrame.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/rt/StackFrame.java,v
retrieving revision 1.5
diff -u -r1.5 StackFrame.java
--- frysk-core/frysk/rt/StackFrame.java 18 Sep 2006 15:52:09 -0000 1.5
+++ frysk-core/frysk/rt/StackFrame.java 19 Sep 2006 00:25:53 -0000
@@ -61,7 +61,7 @@
 
   private int endLine;
 
-  private int startOffsset;
+  private int startOffset;
 
   private int endOffset;
 
@@ -96,16 +96,12 @@
             this.lineNum = line.getLineNum();
             this.startLine = this.lineNum;
             this.endLine = this.lineNum;
-            this.startOffsset = 0;
+            this.startOffset = 0;
             this.endOffset = -1;
             this.sourceFile = line.getSourceFile();
             this.column = line.getColumn();
           }
       }
-    else
-      {
-        this.sourceFile = "<Unknown file>";
-      }
   }
   
   public void setFunction(DOMFunction f)
@@ -132,16 +128,29 @@
     return this.data;
   }
 
+  /**
+   * Return the name of the function associated with this stack frame.
+   * This will return null if the function's name is not known.
+   */
   public String getMethodName ()
   {
     return methodName;
   }
 
+  /**
+   * Return the name of the source file associated with this stack
+   * frame.  If the source file is not known, this will return null.
+   */
   public String getSourceFile ()
   {
     return sourceFile;
   }
 
+  /**
+   * Return the line number of the source code associated with this
+   * stack frame.  Line numbers begin at 1.  If the source line number
+   * is not known, this will return 0.
+   */
   public int getLineNumber ()
   {
     return lineNum;
@@ -178,13 +187,46 @@
   {
     return outer;
   }
+
+  /**
+   * Return a string representation of this stack frame.
+   * The returned string is suitable for display to the user.
+   */
+  public String toString ()
+  {
+    StringBuffer builder = new StringBuffer("0x");
+    builder.append(Long.toHexString(getAddress()));
+    String mn = getMethodName();
+    if (mn != null && ! "".equals(mn))
+      {
+	builder.append(" in function: ");
+	builder.append(getMethodName());
+      }
+    String sf = getSourceFile();
+    int line = getLineNumber();
+    if (sf != null || line != 0)
+      {
+	builder.append(" (");
+	if (sf != null)
+	  builder.append(sf);
+	else
+	  builder.append("Unknown source");
+	if (line != 0)
+	  {
+	    builder.append(":");
+	    builder.append(line);
+	  }
+	builder.append(")");
+      }
+    return builder.toString();
+  }
   
   public int getEndLine ()
   {
     return endLine;
   }
   
-  public void setEndLine (int i )
+  public void setEndLine (int i)
   {
     this.endLine = i;
   }
@@ -204,8 +246,8 @@
     this.startLine = i;
   }
 
-  public int getStartOffsset ()
+  public int getStartOffset ()
   {
-    return startOffsset;
+    return startOffset;
   }
 }
Index: frysk-gui/frysk/gui/srcwin/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* CurrentLineSection.java (startOffset): Renamed.
	(CurrentLineSection): Updated.
	(getStartOffset): Renamed.
	(setStartOffset): Likewise.
	* SourceBuffer.java (setCurrentLine): Use renamed getStartOffset.

Index: frysk-gui/frysk/gui/srcwin/CurrentLineSection.java
===================================================================
RCS file: /cvs/frysk/frysk-gui/frysk/gui/srcwin/CurrentLineSection.java,v
retrieving revision 1.3
diff -u -r1.3 CurrentLineSection.java
--- frysk-gui/frysk/gui/srcwin/CurrentLineSection.java 8 Sep 2006 18:19:36 -0000 1.3
+++ frysk-gui/frysk/gui/srcwin/CurrentLineSection.java 19 Sep 2006 00:25:55 -0000
@@ -46,7 +46,7 @@
 
   private int endLine;
 
-  private int startOffsset;
+  private int startOffset;
 
   private int endOffset;
 
@@ -59,7 +59,7 @@
   {
     startLine = lineStart;
     endLine = lineEnd;
-    startOffsset = colStart;
+    startOffset = colStart;
     endOffset = colEnd;
   }
 
@@ -113,13 +113,13 @@
     this.startLine = startLine;
   }
 
-  public int getStartOffsset ()
+  public int getStartOffset ()
   {
-    return startOffsset;
+    return startOffset;
   }
 
-  public void setStartOffsset (int startOffsset)
+  public void setStartOffset (int startOffset)
   {
-    this.startOffsset = startOffsset;
+    this.startOffset = startOffset;
   }
 }
Index: frysk-gui/frysk/gui/srcwin/SourceBuffer.java
===================================================================
RCS file: /cvs/frysk/frysk-gui/frysk/gui/srcwin/SourceBuffer.java,v
retrieving revision 1.69
diff -u -r1.69 SourceBuffer.java
--- frysk-gui/frysk/gui/srcwin/SourceBuffer.java 18 Sep 2006 15:52:09 -0000 1.69
+++ frysk-gui/frysk/gui/srcwin/SourceBuffer.java 19 Sep 2006 00:25:55 -0000
@@ -267,7 +267,7 @@
   {
 
     int startLine = frame.getStartLine();
-    int startCol = frame.getStartOffsset();
+    int startCol = frame.getStartOffset();
     int endLine = frame.getEndLine();
     int endCol = frame.getEndOffset();
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]