add infcall_mmap and gcc_target_options gdbarch methods
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 14 May 2014 20:08:57 +0000 (14:08 -0600)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 12 Dec 2014 21:25:37 +0000 (22:25 +0100)
The compiler needed two new gdbarch methods.

The infcall_mmap method allocates memory in the inferior.
This is used when inserting the object code.

The gcc_target_options method computes some arch-specific gcc options
to pass to the compiler.  This is used to ensure that gcc generates
object code for the correct architecture.

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

* arch-utils.c (default_infcall_mmap)
(default_gcc_target_options): New functions.
* arch-utils.h (GDB_MMAP_PROT_READ, GDB_MMAP_PROT_WRITE)
(GDB_MMAP_PROT_EXEC): Define.
(default_infcall_mmap, default_gcc_target_options): Declare.
* gdbarch.h: Rebuild.
* gdbarch.c: Rebuild.
* gdbarch.sh (infcall_mmap, gcc_target_options): New methods.

gdb/ChangeLog
gdb/arch-utils.c
gdb/arch-utils.h
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh

index d7f0c2d16941f4380bf4e452a1928a47f826dbd5..b310769052023851748ade35e9cc808fd7d72c33 100644 (file)
@@ -1,3 +1,14 @@
+2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       * arch-utils.c (default_infcall_mmap)
+       (default_gcc_target_options): New functions.
+       * arch-utils.h (GDB_MMAP_PROT_READ, GDB_MMAP_PROT_WRITE)
+       (GDB_MMAP_PROT_EXEC): Define.
+       (default_infcall_mmap, default_gcc_target_options): Declare.
+       * gdbarch.h: Rebuild.
+       * gdbarch.c: Rebuild.
+       * gdbarch.sh (infcall_mmap, gcc_target_options): New methods.
+
 2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * dummy-frame.c (struct dummy_frame) <dtor, dtor_data>: New
index 33d5543101c95feebfec71c812ba95420d1d6024..3cd0a2188038e41f77a9eec2a4a248abeea8715f 100644 (file)
@@ -858,6 +858,22 @@ default_skip_permanent_breakpoint (struct regcache *regcache)
   regcache_write_pc (regcache, current_pc);
 }
 
+CORE_ADDR
+default_infcall_mmap (CORE_ADDR size, unsigned prot)
+{
+  error (_("This target does not support inferior memory allocation by mmap."));
+}
+
+/* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
+   created in inferior memory by GDB (normally it is set by ld.so).  */
+
+char *
+default_gcc_target_options (struct gdbarch *gdbarch)
+{
+  return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
+                    gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_gdbarch_utils;
 
index 11e68e278777eb0da938563bd607bcc02a4a8fa6..e1d2c4a190860d6fc7b3f06c8c87b6284a7747e5 100644 (file)
@@ -193,4 +193,13 @@ extern int default_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *ra
    module determines whether a breakpoint is permanent.  */
 extern void default_skip_permanent_breakpoint (struct regcache *regcache);
 
+/* Symbols for gdbarch_infcall_mmap; their Linux PROT_* system
+   definitions would be dependent on compilation host.  */
+#define GDB_MMAP_PROT_READ     0x1     /* Page can be read.  */
+#define GDB_MMAP_PROT_WRITE    0x2     /* Page can be written.  */
+#define GDB_MMAP_PROT_EXEC     0x4     /* Page can be executed.  */
+
+extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
+extern char *default_gcc_target_options (struct gdbarch *gdbarch);
+
 #endif
index 132fff35289686c7d73dbe3aafb00f3ac9adf35d..d815a1c19082f33028fe59ac3b8994cddb446869 100644 (file)
@@ -321,6 +321,8 @@ struct gdbarch
   gdbarch_insn_is_jump_ftype *insn_is_jump;
   gdbarch_auxv_parse_ftype *auxv_parse;
   gdbarch_vsyscall_range_ftype *vsyscall_range;
+  gdbarch_infcall_mmap_ftype *infcall_mmap;
+  gdbarch_gcc_target_options_ftype *gcc_target_options;
 };
 
 /* Create a new ``struct gdbarch'' based on information provided by
@@ -417,6 +419,8 @@ gdbarch_alloc (const struct gdbarch_info *info,
   gdbarch->insn_is_ret = default_insn_is_ret;
   gdbarch->insn_is_jump = default_insn_is_jump;
   gdbarch->vsyscall_range = default_vsyscall_range;
+  gdbarch->infcall_mmap = default_infcall_mmap;
+  gdbarch->gcc_target_options = default_gcc_target_options;
   /* gdbarch_alloc() */
 
   return gdbarch;
@@ -642,6 +646,8 @@ verify_gdbarch (struct gdbarch *gdbarch)
   /* Skip verify of insn_is_jump, invalid_p == 0 */
   /* Skip verify of auxv_parse, has predicate.  */
   /* Skip verify of vsyscall_range, invalid_p == 0 */
+  /* Skip verify of infcall_mmap, invalid_p == 0 */
+  /* Skip verify of gcc_target_options, invalid_p == 0 */
   buf = ui_file_xstrdup (log, &length);
   make_cleanup (xfree, buf);
   if (length > 0)
@@ -911,6 +917,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   fprintf_unfiltered (file,
                       "gdbarch_dump: frame_red_zone_size = %s\n",
                       plongest (gdbarch->frame_red_zone_size));
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: gcc_target_options = <%s>\n",
+                      host_address_to_string (gdbarch->gcc_target_options));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_gcore_bfd_target_p() = %d\n",
                       gdbarch_gcore_bfd_target_p (gdbarch));
@@ -977,6 +986,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
   fprintf_unfiltered (file,
                       "gdbarch_dump: in_solib_return_trampoline = <%s>\n",
                       host_address_to_string (gdbarch->in_solib_return_trampoline));
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: infcall_mmap = <%s>\n",
+                      host_address_to_string (gdbarch->infcall_mmap));
   fprintf_unfiltered (file,
                       "gdbarch_dump: gdbarch_info_proc_p() = %d\n",
                       gdbarch_info_proc_p (gdbarch));
@@ -4519,6 +4531,40 @@ set_gdbarch_vsyscall_range (struct gdbarch *gdbarch,
   gdbarch->vsyscall_range = vsyscall_range;
 }
 
+CORE_ADDR
+gdbarch_infcall_mmap (struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->infcall_mmap != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_infcall_mmap called\n");
+  return gdbarch->infcall_mmap (size, prot);
+}
+
+void
+set_gdbarch_infcall_mmap (struct gdbarch *gdbarch,
+                          gdbarch_infcall_mmap_ftype infcall_mmap)
+{
+  gdbarch->infcall_mmap = infcall_mmap;
+}
+
+char *
+gdbarch_gcc_target_options (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch != NULL);
+  gdb_assert (gdbarch->gcc_target_options != NULL);
+  if (gdbarch_debug >= 2)
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_gcc_target_options called\n");
+  return gdbarch->gcc_target_options (gdbarch);
+}
+
+void
+set_gdbarch_gcc_target_options (struct gdbarch *gdbarch,
+                                gdbarch_gcc_target_options_ftype gcc_target_options)
+{
+  gdbarch->gcc_target_options = gcc_target_options;
+}
+
 
 /* Keep a registry of per-architecture data-pointers required by GDB
    modules.  */
index ba4fe62ae9485f8ea414ee60ab64560c7e1ed99c..d086553bba8bfc89e95fa2ad74f626b1a9a413ba 100644 (file)
@@ -1390,6 +1390,23 @@ typedef int (gdbarch_vsyscall_range_ftype) (struct gdbarch *gdbarch, struct mem_
 extern int gdbarch_vsyscall_range (struct gdbarch *gdbarch, struct mem_range *range);
 extern void set_gdbarch_vsyscall_range (struct gdbarch *gdbarch, gdbarch_vsyscall_range_ftype *vsyscall_range);
 
+/* Allocate SIZE bytes of PROT protected page aligned memory in inferior.
+   PROT has GDB_MMAP_PROT_* bitmask format.
+   Throw an error if it is not possible.  Returned address is always valid. */
+
+typedef CORE_ADDR (gdbarch_infcall_mmap_ftype) (CORE_ADDR size, unsigned prot);
+extern CORE_ADDR gdbarch_infcall_mmap (struct gdbarch *gdbarch, CORE_ADDR size, unsigned prot);
+extern void set_gdbarch_infcall_mmap (struct gdbarch *gdbarch, gdbarch_infcall_mmap_ftype *infcall_mmap);
+
+/* Return string (caller has to use xfree for it) with options for GCC
+   to produce code for this target, typically "-m64", "-m32" or "-m31".
+   These options are put before CU's DW_AT_producer compilation options so that
+   they can override it.  Method may also return NULL. */
+
+typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch);
+extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch);
+extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options);
+
 /* Definition for an unknown syscall, used basically in error-cases.  */
 #define UNKNOWN_SYSCALL (-1)
 
index 25544e3d8d58dd4b8ff54309ddfe88303a45ec8c..8f4cd693fcccb14cd0eb95b4be61f5c32c5b7acc 100755 (executable)
@@ -1076,6 +1076,17 @@ M:int:auxv_parse:gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_AD
 # range with zero length is returned.  Returns true if the vsyscall is
 # found, false otherwise.
 m:int:vsyscall_range:struct mem_range *range:range::default_vsyscall_range::0
+
+# Allocate SIZE bytes of PROT protected page aligned memory in inferior.
+# PROT has GDB_MMAP_PROT_* bitmask format.
+# Throw an error if it is not possible.  Returned address is always valid.
+f:CORE_ADDR:infcall_mmap:CORE_ADDR size, unsigned prot:size, prot::default_infcall_mmap::0
+
+# Return string (caller has to use xfree for it) with options for GCC
+# to produce code for this target, typically "-m64", "-m32" or "-m31".
+# These options are put before CU's DW_AT_producer compilation options so that
+# they can override it.  Method may also return NULL.
+m:char *:gcc_target_options:void:::default_gcc_target_options::0
 EOF
 }
 
This page took 0.065928 seconds and 4 git commands to generate.