]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
stacktrace.cc (ClassForFrame): Remove commented-out code.
authorBryce McKinlay <mckinlay@redhat.com>
Thu, 6 Jul 2006 23:26:24 +0000 (23:26 +0000)
committerBryce McKinlay <bryce@gcc.gnu.org>
Thu, 6 Jul 2006 23:26:24 +0000 (00:26 +0100)
2006-07-06  Bryce McKinlay <mckinlay@redhat.com>

        * stacktrace.cc (ClassForFrame): Remove commented-out code.
        (UnwindTraceFn): Use _Unwind_GetIPInfo and adjust IP
        only when needed.
        (getLineNumberForFrame): Don't adjust IP here.
        * testsuite/libjava.lang/StackTrace.java: New test case.
        * testsuite/libjava.lang/StackTrace.out: Ditto.

From-SVN: r115235

libjava/ChangeLog
libjava/stacktrace.cc
libjava/testsuite/libjava.lang/StackTrace.java [new file with mode: 0644]
libjava/testsuite/libjava.lang/StackTrace.out [new file with mode: 0644]

index 3900527024b7bc00f8e13b1f4ac182f28ce994f7..498d7c48847a4f4ef35fc08deae91448b3fdda22 100644 (file)
@@ -1,3 +1,12 @@
+2006-07-06  Bryce McKinlay <mckinlay@redhat.com>
+
+       * stacktrace.cc (ClassForFrame): Remove commented-out code.
+       (UnwindTraceFn): Use _Unwind_GetIPInfo and adjust IP
+       only when needed.
+       (getLineNumberForFrame): Don't adjust IP here.
+       * testsuite/libjava.lang/StackTrace.java: New test case.
+       * testsuite/libjava.lang/StackTrace.out: Ditto.
+
 2006-07-06  Thomas Fitzsimmons  <fitzsim@redhat.com>
 
        * Makefile.am (libgcj_tools_la_GCJFLAGS): Add
index 06a4dfadb98a4e2a275dcfede329667114b226b7..2ace9abc232e7212a5c4c6be51eaa8b48ec13a98 100644 (file)
@@ -79,8 +79,6 @@ _Jv_StackTrace::ClassForFrame (_Jv_StackFrame *frame)
 {
   JvAssert (frame->type == frame_native);
   jclass klass = NULL;
-  // use _Unwind_FindEnclosingFunction to find start of method
-  //void *entryPoint = _Unwind_FindEnclosingFunction (ip);
 
   // look it up in ncodeMap
   if (frame->start_ip)
@@ -124,13 +122,20 @@ _Jv_StackTrace::UnwindTraceFn (struct _Unwind_Context *context, void *state_ptr)
   else
 #endif
     {
+      _Unwind_Ptr ip;
+      int ip_before_insn = 0;
+      ip = _Unwind_GetIPInfo (context, &ip_before_insn);
+
+      // If the unwinder gave us a 'return' address, roll it back a little
+      // to ensure we get the correct line number for the call itself.
+      if (! ip_before_insn)
+       --ip;
+
       state->frames[pos].type = frame_native;
-      state->frames[pos].ip = (void *) _Unwind_GetIP (context);
+      state->frames[pos].ip = (void *) ip;
       state->frames[pos].start_ip = func_addr;
     }
 
-  //printf ("unwind ip: %p\n", _Unwind_GetIP (context));
-
   _Unwind_Reason_Code result = _URC_NO_REASON;
   if (state->trace_function != NULL)
     result = (state->trace_function) (state);
@@ -207,10 +212,6 @@ _Jv_StackTrace::getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder,
       else
         offset = (_Unwind_Ptr) ip - (_Unwind_Ptr) info.base;
 
-      // The unwinder gives us the return address. In order to get the right
-      // line number for the stack trace, roll it back a little.
-      offset -= 1;
-
       finder->lookup (binaryName, (jlong) offset);
       *sourceFileName = finder->getSourceFile();
       *lineNum = finder->getLineNum();
diff --git a/libjava/testsuite/libjava.lang/StackTrace.java b/libjava/testsuite/libjava.lang/StackTrace.java
new file mode 100644 (file)
index 0000000..b16e297
--- /dev/null
@@ -0,0 +1,76 @@
+// Check that stack trace's work, and stack trace line numbers, if available,
+// are correct.
+
+public class StackTrace
+{
+  public static void main(String[] args) 
+  { 
+    try
+    {
+      a();
+    }
+    catch (Exception x)
+    {
+      StackTraceElement[] trace = x.getStackTrace();
+      checkTrace(trace);
+    }
+  }
+
+  static void a() 
+  { 
+    new Inner();
+  }
+  
+  static class Inner
+  {
+    public Inner()
+    {
+      doCrash(null);
+    }  
+
+    public void doCrash(Object o)
+    {
+      o.toString();
+    }
+  }  
+  
+  static void checkTrace(StackTraceElement[] trace)
+  {
+    System.out.println("Trace length = " + trace.length);
+    checkLine(trace[0], "StackTrace$Inner", "doCrash", 33);
+    checkLine(trace[1], "StackTrace$Inner", "<init>", 28);
+    checkLine(trace[2], "StackTrace", "a", 21);
+    checkLine(trace[3], "StackTrace", "main", 10);
+  }
+  
+  static void checkLine(StackTraceElement frame, String expected_cl, 
+                       String expected_method, int expected_line)
+  {
+    if (frame.getClassName().equals(expected_cl))
+      System.out.print(expected_cl);
+    else
+      System.out.print("FAIL - expected " + expected_cl + ", got: " + 
+                      frame.getClassName());
+    
+    System.out.print(".");
+
+    if (frame.getMethodName().equals(expected_method))
+      System.out.print(expected_method);
+    else
+      System.out.print("FAIL - expected " + expected_method + ", got: " +
+                      frame.getMethodName());
+
+    System.out.print(":");
+    
+    // Permit either the correct line number or no line number. This is so
+    // we don't fail on platforms that don't yet support reading debug info 
+    // for stack traces, or when no debug info is available.
+    if (frame.getLineNumber() < 0
+        || (frame.getLineNumber() == expected_line
+            && frame.getFileName().equals("StackTrace.java")))
+      System.out.println("OK");
+    else
+      System.out.println("FAIL - expected " + expected_line + ", got: " +
+                        frame.getLineNumber());
+  }
+}
diff --git a/libjava/testsuite/libjava.lang/StackTrace.out b/libjava/testsuite/libjava.lang/StackTrace.out
new file mode 100644 (file)
index 0000000..417d471
--- /dev/null
@@ -0,0 +1,5 @@
+Trace length = 4
+StackTrace$Inner.doCrash:OK
+StackTrace$Inner.<init>:OK
+StackTrace.a:OK
+StackTrace.main:OK