OSDN Git Service

2010-01-27 Vincent Celier <celier@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / tracebak.c
index db825d1..835b7a8 100644 (file)
@@ -6,7 +6,7 @@
  *                                                                          *
  *                          C Implementation File                           *
  *                                                                          *
- *                     Copyright (C) 2000-2005, AdaCore                     *
+ *                     Copyright (C) 2000-2009, AdaCore                     *
  *                                                                          *
  * GNAT is free software;  you can  redistribute it  and/or modify it under *
  * terms of the  GNU General Public License as published  by the Free Soft- *
@@ -34,8 +34,9 @@
    functions.
    It has been tested on the following configurations:
    PowerPC/AiX
+   PowerPC/Darwin
    PowerPC/VxWorks
-   Sparc/Solaris
+   SPARC/Solaris
    i386/GNU/Linux
    i386/Solaris
    i386/NT
@@ -56,6 +57,8 @@
 #else
 #include "config.h"
 #include "system.h"
+/* We don't want fancy_abort here.  */
+#undef abort
 #endif
 
 extern int __gnat_backtrace (void **, int, void *, void *, int);
@@ -96,7 +99,12 @@ extern void (*Unlock_Task) (void);
 
 #include "tb-alvms.c"
 
+#elif defined (__ia64__) && defined (__VMS__)
+
+#include "tb-ivms.c"
+
 #else
+
 /* No target specific implementation.  */
 
 /*----------------------------------------------------------------*
@@ -115,7 +123,7 @@ extern void (*Unlock_Task) (void);
    we store in the tracebacks array. The latter allows us to loop over the
    successive frames in the chain.
 
-   To initiate the process, we retrieve an initial frame pointer using the
+   To initiate the process, we retrieve an initial frame address using the
    appropriate GCC builtin (__builtin_frame_address).
 
    This scheme is unfortunately not applicable on every target because the
@@ -125,8 +133,8 @@ extern void (*Unlock_Task) (void);
    o struct layout, describing the expected stack data layout relevant to the
      information we are interested in,
 
-   o FRAME_OFFSET, the offset, from a given frame pointer, at which this
-     layout will be found,
+   o FRAME_OFFSET, the offset, from a given frame address or frame pointer
+     value, at which this layout will be found,
 
    o FRAME_LEVEL, controls how many frames up we get at to start with,
      from the initial frame pointer we compute by way of the GCC builtin,
@@ -139,7 +147,7 @@ extern void (*Unlock_Task) (void);
      of a call instruction), which is what we want in the output array, and
      the associated return address, which is what we retrieve from the stack.
 
-   o STOP_FRAME, to decide wether we reached the top of the call chain, and
+   o STOP_FRAME, to decide whether we reached the top of the call chain, and
      thus if the process shall stop.
 
           :
@@ -187,13 +195,14 @@ extern void (*Unlock_Task) (void);
 
    o FETCH_UP_FRAME, to force an invocation of __builtin_frame_address with a
      positive argument right after a possibly forced call even if FRAME_LEVEL
-     is 0. See the Sparc Solaris case for an example where this is useful.
+     is 0. See the SPARC Solaris case for an example where this is useful.
 
   */
 
 /*--------------------------- PPC AIX/Darwin ----------------------------*/
 
-#if (defined (__ppc__) && ((defined (_AIX) || defined (__APPLE__))))
+#if ((defined (_POWER) && defined (_AIX)) || \
+(defined (__ppc__) && defined (__APPLE__)))
 
 #define USE_GENERIC_UNWINDER
 
@@ -204,7 +213,7 @@ struct layout
   void *return_address;
 };
 
-#define FRAME_OFFSET 0
+#define FRAME_OFFSET(FP) 0
 #define PC_ADJUST -4
 #define STOP_FRAME(CURRENT, TOP_STACK) ((void *) (CURRENT) < (TOP_STACK))
 
@@ -215,14 +224,15 @@ struct layout
    To have __gnat_backtrace retrieve its own return address, we then
    define ... */
 
-#define FORCE_CALL
+#define FORCE_CALL 1
 #define FRAME_LEVEL 1
 
 #define BASE_SKIP 1
 
-/*---------------------------- PPC VxWorks------------------------------*/
+/*-------------------- PPC ELF (GNU/Linux & VxWorks) ---------------------*/
 
-#elif defined (_ARCH_PPC) && defined (__vxworks)
+#elif (defined (_ARCH_PPC) && defined (__vxworks)) ||  \
+  (defined (linux) && defined (__powerpc__))
 
 #define USE_GENERIC_UNWINDER
 
@@ -232,11 +242,11 @@ struct layout
   void *return_address;
 };
 
-#define FORCE_CALL
+#define FORCE_CALL 1
 #define FRAME_LEVEL 1
 /* See the PPC AIX case for an explanation of these values.  */
 
-#define FRAME_OFFSET 0
+#define FRAME_OFFSET(FP) 0
 #define PC_ADJUST -4
 #define STOP_FRAME(CURRENT, TOP_STACK) ((CURRENT)->next == 0)
 
@@ -264,13 +274,13 @@ struct layout
 #endif
 
 #define FRAME_LEVEL 0
-#define FRAME_OFFSET (14 * sizeof (void*) + STACK_BIAS)
+#define FRAME_OFFSET(FP) (14 * sizeof (void*) + (FP ? STACK_BIAS : 0))
 #define PC_ADJUST 0
 #define STOP_FRAME(CURRENT, TOP_STACK) \
   ((CURRENT)->return_address == 0|| (CURRENT)->next == 0 \
    || (void *) (CURRENT) < (TOP_STACK))
 
-/* The sparc register windows need to be flushed before we may access them
+/* The SPARC register windows need to be flushed before we may access them
    from the stack. This is achieved by way of builtin_frame_address only
    when the "count" argument is positive, so force at least one such call.  */
 #define FETCH_UP_FRAME_ADDRESS
@@ -284,9 +294,11 @@ struct layout
 
 #elif defined (i386)
 
-#ifdef __WIN32
+#if defined (__WIN32)
 #include <windows.h>
 #define IS_BAD_PTR(ptr) (IsBadCodePtr((void *)ptr))
+#elif defined (sun)
+#define IS_BAD_PTR(ptr) ((unsigned long)ptr == -1UL)
 #else
 #define IS_BAD_PTR(ptr) 0
 #endif
@@ -299,17 +311,16 @@ struct layout
   void *return_address;
 };
 
-#define LOWEST_ADDR 0
 #define FRAME_LEVEL 1
 /* builtin_frame_address (1) is expected to work on this target, and (0) might
    return the soft stack pointer, which does not designate a location where a
    backchain and a return address might be found.  */
 
-#define FRAME_OFFSET 0
+#define FRAME_OFFSET(FP) 0
 #define PC_ADJUST -2
 #define STOP_FRAME(CURRENT, TOP_STACK) \
-  (IS_BAD_PTR((long)(CURRENT)->return_address) \
-   || (unsigned int)(CURRENT)->return_address < LOWEST_ADDR \
+  (IS_BAD_PTR((long)(CURRENT)) \
+   || IS_BAD_PTR((long)(CURRENT)->return_address) \
    || (CURRENT)->return_address == 0|| (CURRENT)->next == 0  \
    || (void *) (CURRENT) < (TOP_STACK))
 
@@ -361,10 +372,8 @@ struct layout
    library. On HP-UX 11.23 this requires patch PHSS_33352, which adds
    _Unwind_Backtrace to the system unwind library. */
 
-#define PC_ADJUST -16
-/* Every call on ia64 is part of a 128 bit bundle, so an adjustment of
-   minus 16 bytes from the point of return finds the address of the
-   previous bundle. */
+#define PC_ADJUST -4
+
 
 #endif
 
@@ -404,13 +413,19 @@ struct layout
 #define MAX(x,y) ((x) > (y) ? (x) : (y))
 #endif
 
-/* Define a dummy function to call if FORCE_CALL is defined.  Don't
-   define it otherwise, as this could lead to "defined but not used"
-   warnings.  */
-#if defined (FORCE_CALL)
-static void forced_callee () {}
+#ifndef FORCE_CALL
+#define FORCE_CALL 0
 #endif
 
+/* Make sure the function is not inlined.  */
+static void forced_callee (void) __attribute__ ((noinline));
+
+static void forced_callee (void)
+{
+  /* Make sure the function is not pure.  */
+  volatile int i __attribute__ ((unused)) = 0;
+}
+
 int
 __gnat_backtrace (void **array,
                   int size,
@@ -423,13 +438,11 @@ __gnat_backtrace (void **array,
   void *top_stack;
   int cnt = 0;
 
-  /* Honor FORCE_CALL when defined.  */
-#if defined (FORCE_CALL)
-  forced_callee ();
-#endif
+  if (FORCE_CALL)
+    forced_callee ();
 
   /* Force a call to builtin_frame_address with a positive argument
-     if required. This is necessary e.g. on sparc to have the register
+     if required. This is necessary e.g. on SPARC to have the register
      windows flushed before we attempt to access them on the stack.  */
 #if defined (FETCH_UP_FRAME_ADDRESS) && (FRAME_LEVEL == 0)
   __builtin_frame_address (1);
@@ -437,7 +450,7 @@ __gnat_backtrace (void **array,
 
   top_frame = __builtin_frame_address (FRAME_LEVEL);
   top_stack = CURRENT_STACK_FRAME;
-  current = (struct layout *) ((size_t) top_frame + FRAME_OFFSET);
+  current = (struct layout *) ((size_t) top_frame + FRAME_OFFSET (0));
 
   /* Skip the number of calls we have been requested to skip, accounting for
      the BASE_SKIP parameter.
@@ -450,7 +463,7 @@ __gnat_backtrace (void **array,
 
   while (cnt < skip_frames)
     {
-      current = (struct layout *) ((size_t) current->next + FRAME_OFFSET);
+      current = (struct layout *) ((size_t) current->next + FRAME_OFFSET (1));
       cnt++;
     }
 
@@ -465,7 +478,7 @@ __gnat_backtrace (void **array,
          || current->return_address > exclude_max)
         array[cnt++] = current->return_address + PC_ADJUST;
 
-      current = (struct layout *) ((size_t) current->next + FRAME_OFFSET);
+      current = (struct layout *) ((size_t) current->next + FRAME_OFFSET (1));
     }
 
   return cnt;
@@ -481,12 +494,11 @@ __gnat_backtrace (void **array,
  *------------------------------*/
 
 int
-__gnat_backtrace (array, size, exclude_min, exclude_max, skip_frames)
-     void **array ATTRIBUTE_UNUSED;
-     int size ATTRIBUTE_UNUSED;
-     void *exclude_min ATTRIBUTE_UNUSED;
-     void *exclude_max ATTRIBUTE_UNUSED;
-     int skip_frames ATTRIBUTE_UNUSED;
+__gnat_backtrace (void **array ATTRIBUTE_UNUSED,
+                  int size ATTRIBUTE_UNUSED,
+                  void *exclude_min ATTRIBUTE_UNUSED,
+                  void *exclude_max ATTRIBUTE_UNUSED,
+                  int skip_frames ATTRIBUTE_UNUSED)
 {
   return 0;
 }