allow building GDB with Python support on MinGW
[deliverable/binutils-gdb.git] / gdb / xtensa-tdep.c
index 07454978fe8342de1642a64bca3b805b4edfa0c8..c3ed28327b4d4f12d1d5bcb599d72ea7cf7185d6 100644 (file)
@@ -1,6 +1,6 @@
 /* Target-dependent code for the Xtensa port of GDB, the GNU debugger.
 
-   Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009
+   Copyright (C) 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -116,7 +116,8 @@ static int xtensa_debug_level = 0;
 #define PS_WOE                 (1<<18)
 #define PS_EXC                 (1<<4)
 
-/* Convert a live A-register number to the corresponding AR-register number.  */
+/* Convert a live A-register number to the corresponding AR-register
+   number.  */
 static int
 arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
 {
@@ -811,7 +812,7 @@ xtensa_supply_gregset (const struct regset *regset,
   struct gdbarch *gdbarch = get_regcache_arch (rc);
   int i;
 
-  DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...) \n", regnum);
+  DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
 
   if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
     regcache_raw_supply (rc, gdbarch_pc_regnum (gdbarch), (char *) &regs->pc);
@@ -869,7 +870,7 @@ xtensa_regset_from_core_section (struct gdbarch *core_arch,
                                 size_t sect_size)
 {
   DEBUGTRACE ("xtensa_regset_from_core_section "
-             "(..., sect_name==\"%s\", sect_size==%x) \n",
+             "(..., sect_name==\"%s\", sect_size==%x)\n",
              sect_name, (unsigned int) sect_size);
 
   if (strcmp (sect_name, ".reg") == 0
@@ -890,10 +891,11 @@ typedef struct xtensa_windowed_frame_cache
 {
   int wb;              /* WINDOWBASE of the previous frame.  */
   int callsize;                /* Call size of this frame.  */
-  int ws;              /* WINDOWSTART of the previous frame.  It keeps track of
-                          life windows only.  If there is no bit set for the
-                          window, that means it had been already spilled
-                          because of window overflow.  */
+  int ws;              /* WINDOWSTART of the previous frame.  It
+                          keeps track of life windows only.  If there
+                          is no bit set for the window, that means it
+                          had been already spilled because of window
+                          overflow.  */
 
   /* Spilled A-registers from the previous frame.
      AREGS[i] == -1, if corresponding AR is alive.  */
@@ -902,7 +904,8 @@ typedef struct xtensa_windowed_frame_cache
 
 /* Call0 ABI Definitions.  */
 
-#define C0_MAXOPDS  3  /* Maximum number of operands for prologue analysis.  */
+#define C0_MAXOPDS  3  /* Maximum number of operands for prologue
+                          analysis.  */
 #define C0_NREGS   16  /* Number of A-registers to track.  */
 #define C0_CLESV   12  /* Callee-saved registers are here and up.  */
 #define C0_SP      1   /* Register used as SP.  */
@@ -929,8 +932,9 @@ typedef struct xtensa_c0reg
     int            fr_reg;     /* original register from which register content
                           is derived, or C0_CONST, or C0_INEXP.  */
     int            fr_ofs;     /* constant offset from reg, or immediate value.  */
-    int            to_stk;     /* offset from original SP to register (4-byte aligned),
-                          or C0_NOSTK if register has not been saved.  */
+    int            to_stk;     /* offset from original SP to register (4-byte
+                          aligned), or C0_NOSTK if register has not
+                          been saved.  */
 } xtensa_c0reg_t;
 
 
@@ -938,7 +942,8 @@ typedef struct xtensa_c0reg
 typedef struct xtensa_call0_frame_cache
 {
   int c0_frmsz;                                /* Stack frame size.  */
-  int c0_hasfp;                                /* Current frame uses frame pointer.  */
+  int c0_hasfp;                                /* Current frame uses frame
+                                          pointer.  */
   int fp_regnum;                       /* A-register used as FP.  */
   int c0_fp;                           /* Actual value of frame pointer.  */
   xtensa_c0reg_t c0_rt[C0_NREGS];      /* Register tracking information.  */
@@ -1046,7 +1051,8 @@ xtensa_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
 /* Returns the best guess about which register is a frame pointer
    for the function containing CURRENT_PC.  */
 
-#define XTENSA_ISA_BSZ 32          /* Instruction buffer size.  */
+#define XTENSA_ISA_BSZ         32              /* Instruction buffer size.  */
+#define XTENSA_ISA_BADPC       ((CORE_ADDR)0)  /* Bad PC value.  */
 
 static unsigned int
 xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
@@ -1083,7 +1089,8 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
          ba = ia;
          bt = (ba + XTENSA_ISA_BSZ) < current_pc
            ? ba + XTENSA_ISA_BSZ : current_pc;
-         read_memory (ba, ibuf, bt - ba);
+         if (target_read_memory (ba, ibuf, bt - ba) != 0)
+           RETURN_FP;
        }
 
       xtensa_insnbuf_from_chars (isa, ins, &ibuf[ia-ba], 0);
@@ -1114,7 +1121,7 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
              unsigned int register_operand;
 
              /* Possible candidate for setting frame pointer
-                from A1. This is what we are looking for.  */
+                from A1.  This is what we are looking for.  */
 
              if (xtensa_operand_get_field (isa, opc, 1, ifmt, 
                                            is, slot, &register_operand) != 0)
@@ -1130,7 +1137,8 @@ xtensa_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR current_pc)
                                             &register_operand) != 0)
                    RETURN_FP;
 
-                 fp_regnum = gdbarch_tdep (gdbarch)->a0_base + register_operand;
+                 fp_regnum
+                   = gdbarch_tdep (gdbarch)->a0_base + register_operand;
                  RETURN_FP;
                }
            }
@@ -1164,8 +1172,7 @@ done:
 
        cache->base    = SP (or best guess about FP) of this frame;
        cache->pc      = entry-PC (entry point of the frame function);
-       cache->prev_sp = SP of the previous frame.
-*/
+       cache->prev_sp = SP of the previous frame.  */
 
 static void
 call0_frame_cache (struct frame_info *this_frame,
@@ -1276,8 +1283,9 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
        }
 
       if ((cache->prev_sp == 0) && ( ra != 0 ))
-       /* If RA is equal to 0 this frame is an outermost frame.  Leave
-          cache->prev_sp unchanged marking the boundary of the frame stack.  */
+       /* If RA is equal to 0 this frame is an outermost frame.
+          Leave cache->prev_sp unchanged marking the boundary of the
+          frame stack.  */
        {
          if ((cache->wd.ws & (1 << cache->wd.wb)) == 0)
            {
@@ -1294,7 +1302,8 @@ xtensa_frame_cache (struct frame_info *this_frame, void **this_cache)
                             (gdbarch, gdbarch_tdep (gdbarch)->a0_base + 1,
                              cache->wd.wb);
 
-             cache->prev_sp = get_frame_register_unsigned (this_frame, regnum);
+             cache->prev_sp = get_frame_register_unsigned (this_frame,
+                                                           regnum);
            }
        }
     }
@@ -1404,7 +1413,8 @@ xtensa_frame_prev_register (struct frame_info *this_frame,
              spe = cache->c0.c0_fp
                - cache->c0.c0_rt[cache->c0.fp_regnum].fr_ofs;
 
-             return frame_unwind_got_memory (this_frame, regnum, spe + stkofs);
+             return frame_unwind_got_memory (this_frame, regnum,
+                                             spe + stkofs);
            }
        }
     }
@@ -1470,7 +1480,8 @@ xtensa_extract_return_value (struct type *type,
       /* On Xtensa, we can return up to 4 words (or 2 for call12).  */
       if (len > (callsize > 8 ? 8 : 16))
        internal_error (__FILE__, __LINE__,
-                       _("cannot extract return value of %d bytes long"), len);
+                       _("cannot extract return value of %d bytes long"),
+                       len);
 
       /* Get the register offset of the return
         register (A2) in the caller window.  */
@@ -1610,8 +1621,8 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
     int align;                 /* alignment */
     union
     {
-      int offset;              /* stack offset if on stack */
-      int regno;               /* regno if in register */
+      int offset;              /* stack offset if on stack */
+      int regno;               /* regno if in register */
     } u;
   };
 
@@ -1634,8 +1645,9 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
         {
          struct value *arg = args[i];
          struct type *arg_type = check_typedef (value_type (arg));
-         fprintf_unfiltered (gdb_stdlog, "%2d: 0x%lx %3d ",
-                             i, (unsigned long) arg, TYPE_LENGTH (arg_type));
+         fprintf_unfiltered (gdb_stdlog, "%2d: %s %3d ", i,
+                             host_address_to_string (arg),
+                             TYPE_LENGTH (arg_type));
          switch (TYPE_CODE (arg_type))
            {
            case TYPE_CODE_INT:
@@ -1648,8 +1660,8 @@ xtensa_push_dummy_call (struct gdbarch *gdbarch,
              fprintf_unfiltered (gdb_stdlog, "%3d", TYPE_CODE (arg_type));
              break;
            }
-         fprintf_unfiltered (gdb_stdlog, " 0x%lx\n",
-                             (unsigned long) value_contents (arg));
+         fprintf_unfiltered (gdb_stdlog, " %s\n",
+                             host_address_to_string (value_contents (arg)));
        }
     }
 
@@ -1909,7 +1921,8 @@ typedef enum {
   c0opc_mov,          /* Moving a register to a register.  */
   c0opc_movi,         /* Moving an immediate to a register.  */
   c0opc_l32r,         /* Loading a literal.  */
-  c0opc_s32i,         /* Storing word at fixed offset from a base register.  */
+  c0opc_s32i,         /* Storing word at fixed offset from a base
+                         register.  */
   c0opc_NrOf          /* Number of opcode classifications.  */
 } xtensa_insn_kind;
 
@@ -2055,7 +2068,7 @@ call0_track_op (struct gdbarch *gdbarch,
        }
       break;
     default:
-       gdb_assert (0);
+       gdb_assert_not_reached ("unexpected instruction kind");
     }
 }
 
@@ -2125,7 +2138,7 @@ call0_analyze_prologue (struct gdbarch *gdbarch,
      Assume we may be in the prologue until we hit a flow control instr.  */
 
   rtmp = NULL;
-  body_pc = INT_MAX;
+  body_pc = UINT_MAX;
   end_pc = 0;
 
   /* Find out, if we have an information about the prologue from DWARF.  */
@@ -2171,6 +2184,8 @@ call0_analyze_prologue (struct gdbarch *gdbarch,
          ba = ia;
          bt = (ba + XTENSA_ISA_BSZ) < body_pc ? ba + XTENSA_ISA_BSZ : body_pc;
          read_memory (ba, ibuf, bt - ba);
+         /* If there is a memory reading error read_memory () will report it
+            and then throw an exception, stopping command execution.  */
        }
 
       /* Decode format information.  */
@@ -2211,7 +2226,8 @@ call0_analyze_prologue (struct gdbarch *gdbarch,
            goto done;
 
          opc = xtensa_opcode_decode (isa, ifmt, is, slot);
-         DEBUGVERB ("[call0_analyze_prologue] instr addr = 0x%08x, opc = %d\n", 
+         DEBUGVERB ("[call0_analyze_prologue] instr "
+                    "addr = 0x%08x, opc = %d\n", 
                     (unsigned)ia, opc);
          if (opc == XTENSA_UNDEFINED) 
            opclass = c0opc_illegal;
@@ -2290,14 +2306,15 @@ done:
             (unsigned)ia, fail ? "failed" : "succeeded");
   xtensa_insnbuf_free(isa, slot);
   xtensa_insnbuf_free(isa, ins);
-  return fail ? 0 : ia;
+  return fail ? XTENSA_ISA_BADPC : ia;
 }
 
 /* Initialize frame cache for the current frame in CALL0 ABI.  */
 
 static void
 call0_frame_cache (struct frame_info *this_frame,
-                  xtensa_frame_cache_t *cache, CORE_ADDR pc, CORE_ADDR litbase)
+                  xtensa_frame_cache_t *cache,
+                  CORE_ADDR pc, CORE_ADDR litbase)
 {
   struct gdbarch *gdbarch = get_frame_arch (this_frame);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
@@ -2315,6 +2332,10 @@ call0_frame_cache (struct frame_info *this_frame,
                                        C0_NREGS,
                                        &cache->c0.c0_rt[0],
                                        &cache->call0);
+
+      if (body_pc == XTENSA_ISA_BADPC)
+       error (_("Xtensa-specific internal error: CALL0 prologue \
+analysis failed in this frame. GDB command execution stopped."));
     }
   
   sp = get_frame_register_unsigned
@@ -2373,21 +2394,23 @@ call0_frame_cache (struct frame_info *this_frame,
   else if (cache->c0.c0_rt[C0_RA].fr_reg == C0_CONST
           && cache->c0.c0_rt[C0_RA].fr_ofs == 0)
     {
-      /* Special case for terminating backtrace at a function that wants to
-        be seen as the outermost.  Such a function will clear it's RA (A0)
-        register to 0 in the prologue instead of saving its original value.  */
+      /* Special case for terminating backtrace at a function that
+        wants to be seen as the outermost.  Such a function will
+        clear it's RA (A0) register to 0 in the prologue instead of
+        saving its original value.  */
       ra = 0;
     }
   else
     {
-      /* RA was copied to another register or (before any function call) may
-        still be in the original RA register.  This is not always reliable:
-        even in a leaf function, register tracking stops after prologue, and
-        even in prologue, non-prologue instructions (not tracked) may overwrite
-        RA or any register it was copied to.  If likely in prologue or before
-        any call, use retracking info and hope for the best (compiler should
-        have saved RA in stack if not in a leaf function).  If not in prologue,
-        too bad.  */
+      /* RA was copied to another register or (before any function
+        call) may still be in the original RA register.  This is not
+        always reliable: even in a leaf function, register tracking
+        stops after prologue, and even in prologue, non-prologue
+        instructions (not tracked) may overwrite RA or any register
+        it was copied to.  If likely in prologue or before any call,
+        use retracking info and hope for the best (compiler should
+        have saved RA in stack if not in a leaf function).  If not in
+        prologue, too bad.  */
 
       int i;
       for (i = 0; 
@@ -2658,7 +2681,7 @@ xtensa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_register_name (gdbarch, xtensa_register_name);
   set_gdbarch_register_type (gdbarch, xtensa_register_type);
 
-  /* To call functions from GDB using dummy frame */
+  /* To call functions from GDB using dummy frame */
   set_gdbarch_push_dummy_call (gdbarch, xtensa_push_dummy_call);
 
   set_gdbarch_believe_pcc_promotion (gdbarch, 1);
@@ -2727,9 +2750,9 @@ _initialize_xtensa_tdep (void)
 
   add_setshow_zinteger_cmd ("xtensa",
                            class_maintenance,
-                           &xtensa_debug_level, _("\
-Set Xtensa debugging."), _("\
-Show Xtensa debugging."), _("\
+                           &xtensa_debug_level,
+                           _("Set Xtensa debugging."),
+                           _("Show Xtensa debugging."), _("\
 When non-zero, Xtensa-specific debugging is enabled. \
 Can be 1, 2, 3, or 4 indicating the level of debugging."),
                            NULL,
This page took 0.027602 seconds and 4 git commands to generate.