OSDN Git Service

2005-07-01 Andrew Pinski <pinskia@physics.uc.edu>
[pf3gnuchains/gcc-fork.git] / libjava / stacktrace.cc
index 6484dc6..e027678 100644 (file)
@@ -29,17 +29,13 @@ details.  */
 #include <gnu/gcj/runtime/NameFinder.h>
 
 #include <sysdep/backtrace.h>
+#include <sysdep/descriptor.h>
 
 using namespace java::lang;
 using namespace java::lang::reflect;
 using namespace java::util;
 using namespace gnu::gcj::runtime;
 
-struct _Jv_FindCallingClassState: _Jv_UnwindState
-{
-  jclass result;
-};
-
 // Maps ncode values to their containing native class.
 // NOTE: Currently this Map contradicts class GC for native classes. This map
 // (and the "new class stack") will need to use WeakReferences in order to 
@@ -67,12 +63,12 @@ _Jv_StackTrace::UpdateNCodeMap ()
       for (int i=0; i < klass->method_count; i++)
         {
          _Jv_Method *method = &klass->methods[i];
+         void *ncode = method->ncode;
          // Add non-abstract methods to ncodeMap.
-         if (method->ncode)
+         if (ncode)
            {
-             //printf("map->put 0x%x / %s.%s\n", method->ncode, klass->name->data,
-             //  method->name->data);
-             ncodeMap->put ((java::lang::Object *) method->ncode, klass);
+             ncode = UNWRAP_FUNCTION_DESCRIPTOR (ncode);
+             ncodeMap->put ((java::lang::Object *)ncode, klass);
            }
        }
     }
@@ -189,13 +185,13 @@ _Jv_StackTrace::getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder,
 #endif
   // Use dladdr() to determine in which binary the address IP resides.
 #if defined (HAVE_DLFCN_H) && defined (HAVE_DLADDR)
-  extern char **_Jv_argv;
   Dl_info info;
   jstring binaryName = NULL;
+  const char *argv0 = _Jv_GetSafeArg(0);
 
   void *ip = frame->ip;
   _Unwind_Ptr offset = 0;
-  
+
   if (dladdr (ip, &info))
     {
       if (info.dli_fname)
@@ -204,7 +200,7 @@ _Jv_StackTrace::getLineNumberForFrame(_Jv_StackFrame *frame, NameFinder *finder,
         return;
 
       // addr2line expects relative addresses for shared libraries.
-      if (strcmp (info.dli_fname, _Jv_argv[0]) == 0)
+      if (strcmp (info.dli_fname, argv0) == 0)
         offset = (_Unwind_Ptr) ip;
       else
         offset = (_Unwind_Ptr) ip - (_Unwind_Ptr) info.dli_fbase;
@@ -464,19 +460,17 @@ _Jv_StackTrace::GetClassContext (jclass checkClass)
       _Jv_StackFrame *frame = &state.frames[i];
       FillInFrameInfo (frame);
       
-      if (seen_checkClass
-          && frame->klass
-         && frame->klass != checkClass)
+      if (seen_checkClass)
        {
-          jframe_count++;
-         if (start_pos == -1)
-           start_pos = i;
+         if (frame->klass)
+           {
+             jframe_count++;
+             if (start_pos == -1)
+               start_pos = i;
+           }
        }
-
-      if (!seen_checkClass
-          && frame->klass
-          && frame->klass == checkClass)
-        seen_checkClass = true;
+      else
+       seen_checkClass = frame->klass == checkClass;
     }
   result = (JArray<jclass> *) _Jv_NewObjectArray (jframe_count, &Class::class$, NULL);
   int pos = 0;
@@ -502,7 +496,7 @@ _Jv_StackTrace::non_system_trace_fn (_Jv_UnwindState *state)
     {
       classLoader = frame->klass->getClassLoaderInternal();
 #ifdef INTERPRETER
-      if (classLoader != NULL && classLoader != ClassLoader::systemClassLoader)
+      if (classLoader != NULL)
         {
           state->trace_data = (void *) classLoader;
          return _URC_NORMAL_STOP;