gdb/
[deliverable/binutils-gdb.git] / gdb / jit.c
index 01ac5fa3a0d9502a5385020fe86716a7b1b8afdd..954d297309a0faa3b04c45f02528e25f4886f14e 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -40,8 +40,7 @@ static const char *const jit_descriptor_name = "__jit_debug_descriptor";
 
 static const struct inferior_data *jit_inferior_data = NULL;
 
-static void
-jit_inferior_init (struct gdbarch *gdbarch);
+static void jit_inferior_init (struct gdbarch *gdbarch);
 
 /* Non-zero if we want to see trace of jit level stuff.  */
 
@@ -206,10 +205,11 @@ static void
 jit_read_code_entry (struct gdbarch *gdbarch,
                     CORE_ADDR code_addr, struct jit_code_entry *code_entry)
 {
-  int err;
+  int err, off;
   struct type *ptr_type;
   int ptr_size;
   int entry_size;
+  int align_bytes;
   gdb_byte *entry_buf;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
@@ -231,8 +231,13 @@ jit_read_code_entry (struct gdbarch *gdbarch,
       extract_typed_address (&entry_buf[ptr_size], ptr_type);
   code_entry->symfile_addr =
       extract_typed_address (&entry_buf[2 * ptr_size], ptr_type);
+
+  align_bytes = gdbarch_long_long_align_bit (gdbarch) / 8;
+  off = 3 * ptr_size;
+  off = (off + (align_bytes - 1)) & ~(align_bytes - 1);
+
   code_entry->symfile_size =
-      extract_unsigned_integer (&entry_buf[3 * ptr_size], 8, byte_order);
+      extract_unsigned_integer (&entry_buf[off], 8, byte_order);
 }
 
 /* This function registers code associated with a JIT code entry.  It uses the
@@ -248,7 +253,7 @@ jit_register_code (struct gdbarch *gdbarch,
   struct section_addr_info *sai;
   struct bfd_section *sec;
   struct objfile *objfile;
-  struct cleanup *old_cleanups, *my_cleanups;
+  struct cleanup *old_cleanups;
   int i;
   const struct bfd_arch_info *b;
   CORE_ADDR *entry_addr_ptr;
@@ -262,7 +267,11 @@ jit_register_code (struct gdbarch *gdbarch,
 
   nbfd = bfd_open_from_target_memory (code_entry->symfile_addr,
                                       code_entry->symfile_size, gnutarget);
-  old_cleanups = make_cleanup_bfd_close (nbfd);
+  if (nbfd == NULL)
+    {
+      puts_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"));
+      return;
+    }
 
   /* Check the format.  NOTE: This initializes important data that GDB uses!
      We would segfault later without this line.  */
@@ -270,7 +279,7 @@ jit_register_code (struct gdbarch *gdbarch,
     {
       printf_unfiltered (_("\
 JITed symbol file is not an object file, ignoring it.\n"));
-      do_cleanups (old_cleanups);
+      bfd_close (nbfd);
       return;
     }
 
@@ -285,7 +294,7 @@ JITed symbol file is not an object file, ignoring it.\n"));
      file is generated by the JIT at runtime, it should all of the absolute
      addresses that we care about.  */
   sai = alloc_section_addr_info (bfd_count_sections (nbfd));
-  make_cleanup_free_section_addr_info (sai);
+  old_cleanups = make_cleanup_free_section_addr_info (sai);
   i = 0;
   for (sec = nbfd->sections; sec != NULL; sec = sec->next)
     if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
@@ -298,7 +307,7 @@ JITed symbol file is not an object file, ignoring it.\n"));
         ++i;
       }
 
-  /* This call takes ownership of sai.  */
+  /* This call takes ownership of NBFD.  It does not take ownership of SAI.  */
   objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);
 
   /* Remember a mapping from entry_addr to objfile.  */
@@ -306,7 +315,7 @@ JITed symbol file is not an object file, ignoring it.\n"));
   *entry_addr_ptr = entry_addr;
   set_objfile_data (objfile, jit_objfile_data, entry_addr_ptr);
 
-  discard_cleanups (old_cleanups);
+  do_cleanups (old_cleanups);
 }
 
 /* This function unregisters JITed code and frees the corresponding
This page took 0.025967 seconds and 4 git commands to generate.