2009-08-10 Hui Zhu <teawater@gmail.com>
[deliverable/binutils-gdb.git] / gdb / linux-tdep.c
index f1f73735e352b56d28e31555b560cc62bd0b47d3..663470303924a751028b80da559313c31789e931 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "gdbcore.h"
 #include "gdbtypes.h"
+#include "linux-tdep.h"
+#include "observer.h"
+
+#include "elf-bfd.h"
 
 /* This function is suitable for architectures that don't
    extend/override the standard siginfo structure.  */
@@ -32,43 +37,40 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
   struct type *siginfo_type, *sifields_type;
   struct type *type;
 
-  int_type = init_type (TYPE_CODE_INT,
-                       gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT,
-                       0, "int", NULL);
-  uint_type = init_type (TYPE_CODE_INT,
-                        gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT,
-                        0, "unsigned int", NULL);
-  long_type = init_type (TYPE_CODE_INT,
-                        gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT,
-                        0, "long", NULL);
+  int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                               0, "int");
+  uint_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
+                                1, "unsigned int");
+  long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
+                                0, "long");
   void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
 
   /* sival_t */
-  sigval_type = init_composite_type (NULL, TYPE_CODE_UNION);
+  sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
   TYPE_NAME (sigval_type) = xstrdup ("sigval_t");
   append_composite_type_field (sigval_type, "sival_int", int_type);
   append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
 
   /* __pid_t */
-  pid_type = init_type (TYPE_CODE_TYPEDEF, TYPE_LENGTH (int_type),
-                       TYPE_FLAG_TARGET_STUB, NULL, NULL);
-  TYPE_NAME (pid_type) = xstrdup ("__pid_t");
+  pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (int_type),
+                       xstrdup ("__pid_t"));
   TYPE_TARGET_TYPE (pid_type) = int_type;
+  TYPE_TARGET_STUB (pid_type) = 1;
 
   /* __uid_t */
-  uid_type = init_type (TYPE_CODE_TYPEDEF, TYPE_LENGTH (uint_type),
-                       TYPE_FLAG_TARGET_STUB, NULL, NULL);
-  TYPE_NAME (uid_type) = xstrdup ("__uid_t");
+  uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (uint_type),
+                       xstrdup ("__uid_t"));
   TYPE_TARGET_TYPE (uid_type) = uint_type;
+  TYPE_TARGET_STUB (uid_type) = 1;
 
   /* __clock_t */
-  clock_type = init_type (TYPE_CODE_TYPEDEF, TYPE_LENGTH (long_type),
-                         TYPE_FLAG_TARGET_STUB, NULL, NULL);
-  TYPE_NAME (clock_type) = xstrdup ("__clock_t");
+  clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (long_type),
+                         xstrdup ("__clock_t"));
   TYPE_TARGET_TYPE (clock_type) = long_type;
+  TYPE_TARGET_STUB (clock_type) = 1;
 
   /* _sifields */
-  sifields_type = init_composite_type (NULL, TYPE_CODE_UNION);
+  sifields_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
 
   {
     const int si_max_size = 128;
@@ -85,27 +87,27 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
   }
 
   /* _kill */
-  type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   append_composite_type_field (type, "si_pid", pid_type);
   append_composite_type_field (type, "si_uid", uid_type);
   append_composite_type_field (sifields_type, "_kill", type);
 
   /* _timer */
-  type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   append_composite_type_field (type, "si_tid", int_type);
   append_composite_type_field (type, "si_overrun", int_type);
   append_composite_type_field (type, "si_sigval", sigval_type);
   append_composite_type_field (sifields_type, "_timer", type);
 
   /* _rt */
-  type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   append_composite_type_field (type, "si_pid", pid_type);
   append_composite_type_field (type, "si_uid", uid_type);
   append_composite_type_field (type, "si_sigval", sigval_type);
   append_composite_type_field (sifields_type, "_rt", type);
 
   /* _sigchld */
-  type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   append_composite_type_field (type, "si_pid", pid_type);
   append_composite_type_field (type, "si_uid", uid_type);
   append_composite_type_field (type, "si_status", int_type);
@@ -114,18 +116,18 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
   append_composite_type_field (sifields_type, "_sigchld", type);
 
   /* _sigfault */
-  type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   append_composite_type_field (type, "si_addr", void_ptr_type);
   append_composite_type_field (sifields_type, "_sigfault", type);
 
   /* _sigpoll */
-  type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   append_composite_type_field (type, "si_band", long_type);
   append_composite_type_field (type, "si_fd", int_type);
   append_composite_type_field (sifields_type, "_sigpoll", type);
 
   /* struct siginfo */
-  siginfo_type = init_composite_type (NULL, TYPE_CODE_STRUCT);
+  siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
   TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
   append_composite_type_field (siginfo_type, "si_signo", int_type);
   append_composite_type_field (siginfo_type, "si_errno", int_type);
@@ -136,3 +138,30 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
 
   return siginfo_type;
 }
+
+/* Observer for the executable_changed event, to check whether the new
+   exec binary is a PIE (Position Independent Executable) specimen, which
+   is currently unsupported.  */
+
+static void
+check_is_pie_binary (void)
+{
+  Elf_Internal_Ehdr *elf_hdr;
+
+  if (!exec_bfd)
+    return;
+  else if (bfd_get_flavour (exec_bfd) != bfd_target_elf_flavour)
+    return;
+
+  if (elf_tdata (exec_bfd)->elf_header->e_type == ET_DYN)
+    warning (_("\
+The current binary is a PIE (Position Independent Executable), which\n\
+GDB does NOT currently support.  Most debugger features will fail if used\n\
+in this session.\n"));
+}
+
+void
+_initialize_linux_tdep (void)
+{
+  observer_attach_executable_changed (check_is_pie_binary);
+}
This page took 0.028548 seconds and 4 git commands to generate.