]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/i386-tdep.c
import gdb-19990422 snapshot
[thirdparty/binutils-gdb.git] / gdb / i386-tdep.c
index e6ee9ce0928d21b51aa4b3c8d63fcf7367508666..228b1acdde7ce5e5638cb6298bd67f3fd74d61cb 100644 (file)
@@ -1,5 +1,6 @@
 /* Intel 386 target-dependent stuff.
-   Copyright (C) 1988, 1989, 1991, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1989, 1991, 1994, 1995, 1996, 1998
+   Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -15,31 +16,51 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
+#include "gdb_string.h"
 #include "frame.h"
 #include "inferior.h"
 #include "gdbcore.h"
 #include "target.h"
+#include "floatformat.h"
 #include "symtab.h"
+#include "gdbcmd.h"
+#include "command.h"
 
-static long
-i386_get_frame_setup PARAMS ((int));
+static long i386_get_frame_setup PARAMS ((CORE_ADDR));
 
-static void
-i386_follow_jump PARAMS ((void));
+static void i386_follow_jump PARAMS ((void));
 
-static void
-codestream_read PARAMS ((unsigned char *, int));
+static void codestream_read PARAMS ((unsigned char *, int));
 
-static void
-codestream_seek PARAMS ((int));
+static void codestream_seek PARAMS ((CORE_ADDR));
 
-static unsigned char 
-codestream_fill PARAMS ((int));
+static unsigned char codestream_fill PARAMS ((int));
+
+CORE_ADDR skip_trampoline_code PARAMS ((CORE_ADDR, char *));
+
+static int gdb_print_insn_i386 (bfd_vma, disassemble_info *);
+
+void _initialize_i386_tdep PARAMS ((void));
+
+/* This is the variable the is set with "set disassembly-flavor",
+ and its legitimate values. */
+static char att_flavor[] = "att";
+static char intel_flavor[] = "intel";
+static char *valid_flavors[] = {
+  att_flavor,
+  intel_flavor,
+  NULL
+};
+static char *disassembly_flavor = att_flavor;
+
+/* This is used to keep the bfd arch_info in sync with the disassembly flavor.  */
+static void set_disassembly_flavor_sfunc PARAMS ((char *, int, struct cmd_list_element *));
+static void set_disassembly_flavor ();
 
-/* helper functions for tm-i386.h */
+void (*disassembly_flavor_hook) PARAMS((char *args, int from_tty));
 
 /* Stdio style buffering was used to minimize calls to ptrace, but this
    buffering did not take into account that the code section being accessed
@@ -89,7 +110,7 @@ codestream_fill (peek_flag)
 
 static void
 codestream_seek (place)
-    int place;
+    CORE_ADDR place;
 {
   codestream_next_addr = place / CODESTREAM_BUFSIZ;
   codestream_next_addr *= CODESTREAM_BUFSIZ;
@@ -173,7 +194,7 @@ i386_follow_jump ()
 
 static long
 i386_get_frame_setup (pc)
-     int pc;
+     CORE_ADDR pc;
 {
   unsigned char op;
 
@@ -214,6 +235,39 @@ i386_get_frame_setup (pc)
       op = codestream_get (); /* update next opcode */
     }
 
+  if (op == 0x68 || op == 0x6a)
+    {
+      /*
+       * this function may start with
+       *
+       *   pushl constant
+       *   call _probe
+       *   addl $4, %esp
+       *      followed by 
+       *     pushl %ebp
+       *     etc.
+       */
+      int pos;
+      unsigned char buf[8];
+
+      /* Skip past the pushl instruction; it has either a one-byte 
+         or a four-byte operand, depending on the opcode.  */
+      pos = codestream_tell ();
+      if (op == 0x68)
+       pos += 4;
+      else
+       pos += 1;
+      codestream_seek (pos);
+
+      /* Read the following 8 bytes, which should be "call _probe" (6 bytes)
+         followed by "addl $4,%esp" (2 bytes).  */
+      codestream_read (buf, sizeof (buf));
+      if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4)
+       pos += sizeof (buf);
+      codestream_seek (pos);
+      op = codestream_get (); /* update next opcode */
+    }
+
   if (op == 0x55)              /* pushl %ebp */
     {                  
       /* check for movl %esp, %ebp - can be written two ways */
@@ -318,7 +372,7 @@ i386_frame_num_args (fi)
        nameless arguments.  */
     return -1;
 
-  pfi = get_prev_frame_info (fi);                      
+  pfi = get_prev_frame (fi);                   
   if (pfi == 0)
     {
       /* Note:  this can happen if we are looking at the frame for
@@ -395,10 +449,11 @@ i386_frame_find_saved_regs (fip, fsrp)
      struct frame_info *fip;
      struct frame_saved_regs *fsrp;
 {
-  long locals;
+  long locals = -1;
   unsigned char op;
   CORE_ADDR dummy_bottom;
   CORE_ADDR adr;
+  CORE_ADDR pc;
   int i;
   
   memset (fsrp, 0, sizeof *fsrp);
@@ -421,7 +476,9 @@ i386_frame_find_saved_regs (fip, fsrp)
       return;
     }
   
-  locals = i386_get_frame_setup (get_pc_function_start (fip->pc));
+  pc = get_pc_function_start (fip->pc);
+  if (pc != 0)
+    locals = i386_get_frame_setup (pc);
   
   if (locals >= 0) 
     {
@@ -431,7 +488,12 @@ i386_frame_find_saved_regs (fip, fsrp)
          op = codestream_get ();
          if (op < 0x50 || op > 0x57)
            break;
+#ifdef I386_REGNO_TO_SYMMETRY
+         /* Dynix uses different internal numbering.  Ick.  */
+         fsrp->regs[I386_REGNO_TO_SYMMETRY(op - 0x50)] = adr;
+#else
          fsrp->regs[op - 0x50] = adr;
+#endif
          adr -= 4;
        }
     }
@@ -544,16 +606,14 @@ i386_push_dummy_frame ()
 void
 i386_pop_frame ()
 {
-  FRAME frame = get_current_frame ();
+  struct frame_info *frame = get_current_frame ();
   CORE_ADDR fp;
   int regnum;
   struct frame_saved_regs fsr;
-  struct frame_info *fi;
   char regbuf[MAX_REGISTER_RAW_SIZE];
   
-  fi = get_frame_info (frame);
-  fp = fi->frame;
-  get_frame_saved_regs (fi, &fsr);
+  fp = FRAME_FP (frame);
+  get_frame_saved_regs (frame, &fsr);
   for (regnum = 0; regnum < NUM_REGS; regnum++) 
     {
       CORE_ADDR adr;
@@ -569,8 +629,6 @@ i386_pop_frame ()
   write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
   write_register (SP_REGNUM, fp + 8);
   flush_cached_frames ();
-  set_current_frame ( create_new_frame (read_register (FP_REGNUM),
-                                       read_pc ()));
 }
 
 #ifdef GET_LONGJMP_TARGET
@@ -607,31 +665,29 @@ get_longjmp_target(pc)
 
 #endif /* GET_LONGJMP_TARGET */
 
-#ifdef I386_AIX_TARGET
-/* On AIX, floating point values are returned in floating point registers.  */
-
 void
 i386_extract_return_value(type, regbuf, valbuf)
      struct type *type;
      char regbuf[REGISTER_BYTES];
      char *valbuf;
 {
+/* On AIX, floating point values are returned in floating point registers.  */
+#ifdef I386_AIX_TARGET
   if (TYPE_CODE_FLT == TYPE_CODE(type))
     {
-      extern struct ext_format ext_format_i387;
       double d;
       /* 387 %st(0), gcc uses this */
-      ieee_extended_to_double (&ext_format_i387,
-                              &regbuf[REGISTER_BYTE(FP0_REGNUM)],
-                              &d);
+      floatformat_to_double (&floatformat_i387_ext,
+                            &regbuf[REGISTER_BYTE(FP0_REGNUM)],
+                            &d);
       store_floating (valbuf, TYPE_LENGTH (type), d);
     }
   else
+#endif /* I386_AIX_TARGET */
     { 
       memcpy (valbuf, regbuf, TYPE_LENGTH (type)); 
     }
 }
-#endif /* I386_AIX_TARGET */
 
 #ifdef I386V4_SIGTRAMP_SAVED_PC
 /* Get saved user PC for sigtramp from the pushed ucontext on the stack
@@ -639,20 +695,19 @@ i386_extract_return_value(type, regbuf, valbuf)
 
 CORE_ADDR
 i386v4_sigtramp_saved_pc (frame)
-     FRAME frame;
+     struct frame_info *frame;
 {
   CORE_ADDR saved_pc_offset = 4;
   char *name = NULL;
 
-  find_pc_partial_function (frame->pc, &name,
-                           (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
+  find_pc_partial_function (frame->pc, &name, NULL, NULL);
   if (name)
     {
       if (STREQ (name, "_sigreturn"))
        saved_pc_offset = 132 + 14 * 4;
-      if (STREQ (name, "_sigacthandler"))
+      else if (STREQ (name, "_sigacthandler"))
        saved_pc_offset = 80 + 14 * 4;
-      if (STREQ (name, "sigvechandler"))
+      else if (STREQ (name, "sigvechandler"))
        saved_pc_offset = 120 + 14 * 4;
     }
 
@@ -661,3 +716,120 @@ i386v4_sigtramp_saved_pc (frame)
   return read_memory_integer (read_register (SP_REGNUM) + saved_pc_offset, 4);
 }
 #endif /* I386V4_SIGTRAMP_SAVED_PC */
+
+#ifdef STATIC_TRANSFORM_NAME
+/* SunPRO encodes the static variables.  This is not related to C++ mangling,
+   it is done for C too.  */
+
+char *
+sunpro_static_transform_name (name)
+     char *name;
+{
+  char *p;
+  if (IS_STATIC_TRANSFORM_NAME (name))
+    {
+      /* For file-local statics there will be a period, a bunch
+        of junk (the contents of which match a string given in the
+        N_OPT), a period and the name.  For function-local statics
+        there will be a bunch of junk (which seems to change the
+        second character from 'A' to 'B'), a period, the name of the
+        function, and the name.  So just skip everything before the
+        last period.  */
+      p = strrchr (name, '.');
+      if (p != NULL)
+       name = p + 1;
+    }
+  return name;
+}
+#endif /* STATIC_TRANSFORM_NAME */
+
+
+
+/* Stuff for WIN32 PE style DLL's but is pretty generic really. */
+
+CORE_ADDR
+skip_trampoline_code (pc, name)
+     CORE_ADDR pc;
+     char *name;
+{
+  if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */
+    {
+      unsigned long indirect = read_memory_unsigned_integer (pc+2, 4);
+      struct minimal_symbol *indsym =
+       indirect ? lookup_minimal_symbol_by_pc (indirect) : 0;
+      char *symname = indsym ? SYMBOL_NAME(indsym) : 0;
+
+      if (symname) 
+       {
+         if (strncmp (symname,"__imp_", 6) == 0
+             || strncmp (symname,"_imp_", 5) == 0)
+           return name ? 1 : read_memory_unsigned_integer (indirect, 4);
+       }
+    }
+  return 0;                    /* not a trampoline */
+}
+
+static int
+gdb_print_insn_i386 (memaddr, info)
+     bfd_vma memaddr;
+     disassemble_info * info;
+{
+  if (disassembly_flavor == att_flavor)
+    return print_insn_i386_att (memaddr, info);
+  else if (disassembly_flavor == intel_flavor)
+    return print_insn_i386_intel (memaddr, info);
+  /* Never reached - disassembly_flavour is always either att_flavor
+     or intel_flavor */
+  abort ();
+}
+
+/* If the disassembly mode is intel, we have to also switch the
+   bfd mach_type.  This function is run in the set disassembly_flavor
+   command, and does that.  */
+
+static void
+set_disassembly_flavor_sfunc (args, from_tty, c)
+     char *args;
+     int from_tty;
+     struct cmd_list_element *c;
+{
+  set_disassembly_flavor ();
+  
+  if (disassembly_flavor_hook != NULL)
+    disassembly_flavor_hook(args, from_tty);
+}
+
+static void
+set_disassembly_flavor ()
+{
+  if (disassembly_flavor == att_flavor)
+    set_architecture_from_arch_mach (bfd_arch_i386, bfd_mach_i386_i386);
+  else if (disassembly_flavor == intel_flavor)
+    set_architecture_from_arch_mach (bfd_arch_i386, bfd_mach_i386_i386_intel_syntax);
+}
+
+void
+_initialize_i386_tdep ()
+{
+  struct cmd_list_element *new_cmd;
+  
+  tm_print_insn = gdb_print_insn_i386;
+  tm_print_insn_info.mach = bfd_lookup_arch (bfd_arch_i386, 0)->mach;
+
+  /* Add the variable that controls the disassembly flavor */
+
+  new_cmd = add_set_enum_cmd ("disassembly-flavor", no_class,
+                                 valid_flavors,
+                                 (char *) &disassembly_flavor,
+                                 "Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
+and the default value is \"att\".",
+                                 &setlist);
+  new_cmd->function.sfunc = set_disassembly_flavor_sfunc;
+  add_show_from_set(new_cmd, &showlist);
+  
+  /* Finally, initialize the disassembly flavor to the default given
+     in the disassembly_flavor variable */
+
+  set_disassembly_flavor ();
+  
+}