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]

Patch: StackFrame.toString()


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

BTW it would be nice if the boundary cases for StackFrame accessor
methods were documented -- this toString is written assuming:

* getMethodName could return null or the empty string if it can't get
  the function's name (and btw the name "getMethodName" is kind of a
  misnomer IMO)

* getSourceFile will return null if the source file name can't be
  found

* getLineNumber will return 0 if the line number is not known

I'm happy to document these accessors if someone would confirm that
this is the intended interpretation.

Tom

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

	* StackFrame.java (toString): New method.

Index: frysk-core/frysk/rt/StackFrame.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/rt/StackFrame.java,v
retrieving revision 1.4
diff -u -r1.4 StackFrame.java
--- frysk-core/frysk/rt/StackFrame.java 26 Jul 2006 16:24:00 -0000 1.4
+++ frysk-core/frysk/rt/StackFrame.java 5 Sep 2006 22:12:13 -0000
@@ -136,4 +136,37 @@
   {
     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("at 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();
+  }
 }


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