* utils.c (query): Remove test for energize from top. Now
[deliverable/binutils-gdb.git] / gdb / mips-tdep.c
index 98520d43d09d6a8751f2c066a1bf0b42498d849a..c7e65475672da92a6e1451a859749a95e43b9247 100644 (file)
@@ -1,5 +1,5 @@
 /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
-   Copyright 1988, 1989, 1990, 1991, 1992  Free Software Foundation, Inc.
+   Copyright 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
    Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
    and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
 
@@ -43,6 +43,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif
 
 #include "gdbcore.h"
+#include "symfile.h"
+#include "objfiles.h"
 
 #ifndef        MIPSMAGIC
 #ifdef MIPSEL
@@ -59,19 +61,19 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/stat.h>
 
 \f
-#define PROC_LOW_ADDR(proc) ((proc)->adr) /* least address */
-#define PROC_HIGH_ADDR(proc) ((proc)->pad2) /* upper address bound */
-#define PROC_FRAME_OFFSET(proc) ((proc)->framesize)
-#define PROC_FRAME_REG(proc) ((proc)->framereg)
-#define PROC_REG_MASK(proc) ((proc)->regmask)
-#define PROC_FREG_MASK(proc) ((proc)->fregmask)
-#define PROC_REG_OFFSET(proc) ((proc)->regoffset)
-#define PROC_FREG_OFFSET(proc) ((proc)->fregoffset)
-#define PROC_PC_REG(proc) ((proc)->pcreg)
-#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->isym)
+#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
+#define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
+#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
+#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
+#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
+#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
+#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
+#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
+#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
+#define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
 #define _PROC_MAGIC_ 0x0F0F0F0F
-#define PROC_DESC_IS_DUMMY(proc) ((proc)->isym == _PROC_MAGIC_)
-#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->isym = _PROC_MAGIC_)
+#define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
+#define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
 
 struct linked_proc_info
 {
@@ -82,7 +84,7 @@ struct linked_proc_info
 \f
 #define READ_FRAME_REG(fi, regno) read_next_frame_reg((fi)->next, regno)
 
-int
+static int
 read_next_frame_reg(fi, regno)
      FRAME fi;
      int regno;
@@ -111,38 +113,28 @@ int
 mips_frame_saved_pc(frame)
      FRAME frame;
 {
-  mips_extra_func_info_t proc_desc = (mips_extra_func_info_t)frame->proc_desc;
+  mips_extra_func_info_t proc_desc = frame->proc_desc;
   int pcreg = proc_desc ? PROC_PC_REG(proc_desc) : RA_REGNUM;
+
   if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
       return read_memory_integer(frame->frame - 4, 4);
-#if 0
-  /* If in the procedure prologue, RA_REGNUM might not have been saved yet.
-   * Assume non-leaf functions start with:
-   *   addiu $sp,$sp,-frame_size
-   *   sw $ra,ra_offset($sp)
-   * This if the pc is pointing at either of these instructions,
-   * then $ra hasn't been trashed.
-   * If the pc has advanced beyond these two instructions,
-   * then $ra has been saved.
-   * critical, and much more complex. Handling $ra is enough to get
-   * a stack trace, but some register values with be wrong.
-   */
-  if (frame->proc_desc && frame->pc < PROC_LOW_ADDR(proc_desc) + 8)
-      return read_register(pcreg);
-#endif
+
   return read_next_frame_reg(frame, pcreg);
 }
 
 static struct mips_extra_func_info temp_proc_desc;
 static struct frame_saved_regs temp_saved_regs;
 
-CORE_ADDR heuristic_proc_start(pc)
+static CORE_ADDR
+heuristic_proc_start(pc)
     CORE_ADDR pc;
 {
-
     CORE_ADDR start_pc = pc;
-    CORE_ADDR fence = start_pc - 10000;
+    CORE_ADDR fence = start_pc - 200;
+
+    if (start_pc == 0) return 0;
     if (fence < VM_MIN_ADDRESS) fence = VM_MIN_ADDRESS;
+
     /* search back for previous return */
     for (start_pc -= 4; ; start_pc -= 4)
        if (start_pc < fence) return 0; 
@@ -158,7 +150,7 @@ CORE_ADDR heuristic_proc_start(pc)
     return start_pc;
 }
 
-mips_extra_func_info_t
+static mips_extra_func_info_t
 heuristic_proc_desc(start_pc, limit_pc, next_frame)
     CORE_ADDR start_pc, limit_pc;
     FRAME next_frame;
@@ -182,6 +174,7 @@ heuristic_proc_desc(start_pc, limit_pc, next_frame)
 
        status = read_memory_nobpt (cur_pc, &word, 4); 
        if (status) memory_error (status, cur_pc); 
+       SWAP_TARGET_AND_HOST (&word, sizeof (word));
        if ((word & 0xFFFF0000) == 0x27bd0000) /* addiu $sp,$sp,-i */
            frame_size += (-word) & 0xFFFF;
        else if ((word & 0xFFFF0000) == 0x23bd0000) /* addu $sp,$sp,-i */
@@ -228,30 +221,30 @@ heuristic_proc_desc(start_pc, limit_pc, next_frame)
     return &temp_proc_desc;
 }
 
-mips_extra_func_info_t
+static mips_extra_func_info_t
 find_proc_desc(pc, next_frame)
     CORE_ADDR pc;
     FRAME next_frame;
 {
   mips_extra_func_info_t proc_desc;
-  extern struct block *block_for_pc();
-  struct block   *b = block_for_pc(pc);
-
+  struct block *b = block_for_pc(pc);
   struct symbol *sym =
       b ? lookup_symbol(".gdbinfo.", b, LABEL_NAMESPACE, 0, NULL) : NULL;
-  if (sym != NULL)
+
+  if (sym)
     {
        /* IF this is the topmost frame AND
         * (this proc does not have debugging information OR
         * the PC is in the procedure prologue)
-        * THEN create a "hueristic" proc_desc (by analyzing
+        * THEN create a "heuristic" proc_desc (by analyzing
         * the actual code) to replace the "official" proc_desc.
         */
-       proc_desc = (struct mips_extra_func_info *)sym->value.value;
+       proc_desc = (mips_extra_func_info_t)SYMBOL_VALUE(sym);
        if (next_frame == NULL) {
            struct symtab_and_line val;
            struct symbol *proc_symbol =
                PROC_DESC_IS_DUMMY(proc_desc) ? 0 : PROC_SYMBOL(proc_desc);
+
            if (proc_symbol) {
                val = find_pc_line (BLOCK_START
                                    (SYMBOL_BLOCK_VALUE(proc_symbol)),
@@ -268,6 +261,11 @@ find_proc_desc(pc, next_frame)
     }
   else
     {
+      /* Is linked_proc_desc_table really necessary?  It only seems to be used
+        by procedure call dummys.  However, the procedures being called ought
+        to have their own proc_descs, and even if they don't,
+        heuristic_proc_desc knows how to create them! */
+
       register struct linked_proc_info *link;
       for (link = linked_proc_desc_table; link; link = link->next)
          if (PROC_LOW_ADDR(&link->info) <= pc
@@ -281,28 +279,23 @@ find_proc_desc(pc, next_frame)
 
 mips_extra_func_info_t cached_proc_desc;
 
-FRAME_ADDR mips_frame_chain(frame)
+FRAME_ADDR
+mips_frame_chain(frame)
     FRAME frame;
 {
-    extern CORE_ADDR startup_file_start;       /* From blockframe.c */
     mips_extra_func_info_t proc_desc;
     CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
-    if (startup_file_start)
-      { /* has at least the __start symbol */
-       if (saved_pc == 0 || !outside_startup_file (saved_pc)) return 0;
-      }
-    else
-      { /* This hack depends on the internals of __start. */
-       /* We also assume the breakpoints are *not* inserted */
-        if (saved_pc == 0
-           || read_memory_integer (saved_pc + 8, 4) & 0xFC00003F == 0xD)
-           return 0;  /* break */
-      }
+
+    if (saved_pc == 0 || inside_entry_file (saved_pc))
+      return 0;
+
     proc_desc = find_proc_desc(saved_pc, frame);
-    if (!proc_desc) return 0;
+    if (!proc_desc)
+      return 0;
+
     cached_proc_desc = proc_desc;
     return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
-       + PROC_FRAME_OFFSET(proc_desc);
+      + PROC_FRAME_OFFSET(proc_desc);
 }
 
 void
@@ -313,11 +306,12 @@ init_extra_frame_info(fci)
   /* Use proc_desc calculated in frame_chain */
   mips_extra_func_info_t proc_desc = fci->next ? cached_proc_desc :
       find_proc_desc(fci->pc, fci->next);
+
   fci->saved_regs = (struct frame_saved_regs*)
     obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
   bzero(fci->saved_regs, sizeof(struct frame_saved_regs));
   fci->proc_desc =
-      proc_desc == &temp_proc_desc ? (char*)NULL : (char*)proc_desc;
+      proc_desc == &temp_proc_desc ? 0 : proc_desc;
   if (proc_desc)
     {
       int ireg;
@@ -370,12 +364,11 @@ init_extra_frame_info(fci)
 
       fci->saved_regs->regs[PC_REGNUM] = fci->saved_regs->regs[RA_REGNUM];
     }
-  if (fci->next == 0)
-      supply_register(FP_REGNUM, &fci->frame);
 }
 
 
-CORE_ADDR mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
+CORE_ADDR
+mips_push_arguments(nargs, args, sp, struct_return, struct_addr)
   int nargs;
   value *args;
   CORE_ADDR sp;
@@ -535,15 +528,20 @@ mips_pop_frame()
   set_current_frame (create_new_frame (new_sp, read_pc ()));
 }
 
-static
+static void
 mips_print_register(regnum, all)
      int regnum, all;
 {
-      unsigned char raw_buffer[8];
+      unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE];
       REGISTER_TYPE val;
 
-      read_relative_register_raw_bytes (regnum, raw_buffer);
-
+      /* Get the data in raw format.  */
+      if (read_relative_register_raw_bytes (regnum, raw_buffer))
+       {
+         printf_filtered ("%s: [Invalid]", reg_names[regnum]);
+         return;
+       }
+      
       /* If an even floating pointer register, also print as double. */
       if (regnum >= FP0_REGNUM && regnum < FP0_REGNUM+32
          && !((regnum-FP0_REGNUM) & 1)) {
@@ -573,6 +571,7 @@ mips_print_register(regnum, all)
          long val;
 
          bcopy (raw_buffer, &val, sizeof (long));
+         SWAP_TARGET_AND_HOST ((char *)&val, sizeof (long));
          if (val == 0)
            printf_filtered ("0");
          else if (all)
@@ -583,6 +582,7 @@ mips_print_register(regnum, all)
 }
 
 /* Replacement for generic do_registers_info.  */
+void
 mips_do_registers_info (regnum, fpregs)
      int regnum;
      int fpregs;
@@ -609,6 +609,7 @@ mips_do_registers_info (regnum, fpregs)
 /* Return number of args passed to a frame. described by FIP.
    Can return -1, meaning no way to tell.  */
 
+int
 mips_frame_num_args(fip)
        FRAME fip;
 {
@@ -759,7 +760,8 @@ fill_fpregset (fpregsetp, regno)
    itself if the code at PC does not look like a function prologue,
    PC+4 if it does (our caller does not need anything more fancy). */
 
-CORE_ADDR mips_skip_prologue(pc)
+CORE_ADDR
+mips_skip_prologue(pc)
      CORE_ADDR pc;
 {
     struct symbol *f;
@@ -795,7 +797,7 @@ CORE_ADDR mips_skip_prologue(pc)
 
        Actually, it would not hurt to skip the storing
        of arguments on the stack as well. */
-    if (((struct mips_extra_func_info *)f->value.value)->framesize)
+    if (((mips_extra_func_info_t)SYMBOL_VALUE(f))->pdr.frameoffset)
        return pc + 4;
 
     return pc;
This page took 0.026916 seconds and 4 git commands to generate.