This is the mail archive of the
frysk@sources.redhat.com
mailing list for the frysk project.
Patch: StackFrame.toString()
- From: Tom Tromey <tromey at redhat dot com>
- To: Frysk Hackers <frysk at sourceware dot org>
- Date: 05 Sep 2006 16:34:26 -0600
- Subject: Patch: StackFrame.toString()
- Reply-to: tromey at redhat dot com
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();
+ }
}