Fix handling of undocumented SLL instruction for the Z80 target.
[binutils-gdb.git] / gdb / solib-svr4.c
index 11e29c1868adab713d1498a8901b18ea6c74baf4..29d07312becbf7823751b9c73ee3de0a511e1215 100644 (file)
@@ -432,11 +432,11 @@ read_program_header (int type, int *p_sect_size, int *p_arch_size,
   int pt_phdr_p = 0;
 
   /* Get required auxv elements from target.  */
-  if (target_auxv_search (&current_target, AT_PHDR, &at_phdr) <= 0)
+  if (target_auxv_search (current_top_target (), AT_PHDR, &at_phdr) <= 0)
     return 0;
-  if (target_auxv_search (&current_target, AT_PHENT, &at_phent) <= 0)
+  if (target_auxv_search (current_top_target (), AT_PHENT, &at_phent) <= 0)
     return 0;
-  if (target_auxv_search (&current_target, AT_PHNUM, &at_phnum) <= 0)
+  if (target_auxv_search (current_top_target (), AT_PHNUM, &at_phnum) <= 0)
     return 0;
   if (!at_phdr || !at_phnum)
     return 0;
@@ -1243,13 +1243,13 @@ svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
   gdb_assert (annex == NULL || target_augmented_libraries_svr4_read ());
 
   /* Fetch the list of shared libraries.  */
-  gdb::unique_xmalloc_ptr<char> svr4_library_document
-    = target_read_stralloc (&current_target, TARGET_OBJECT_LIBRARIES_SVR4,
+  gdb::optional<gdb::char_vector> svr4_library_document
+    = target_read_stralloc (current_top_target (), TARGET_OBJECT_LIBRARIES_SVR4,
                            annex);
-  if (svr4_library_document == NULL)
+  if (!svr4_library_document)
     return 0;
 
-  return svr4_parse_libraries (svr4_library_document.get (), list);
+  return svr4_parse_libraries (svr4_library_document->data (), list);
 }
 
 #else
@@ -1858,7 +1858,7 @@ svr4_handle_solib_event (void)
   struct svr4_info *info = get_svr4_info ();
   struct probe_and_action *pa;
   enum probe_action action;
-  struct cleanup *old_chain, *usm_chain;
+  struct cleanup *old_chain;
   struct value *val = NULL;
   CORE_ADDR pc, debug_base, lm = 0;
   struct frame_info *frame = get_current_frame ();
@@ -1902,72 +1902,73 @@ svr4_handle_solib_event (void)
      so we can guarantee that the dynamic linker's sections are in the
      section map.  We can therefore inhibit section map updates across
      these calls to evaluate_argument and save a lot of time.  */
-  inhibit_section_map_updates (current_program_space);
-  usm_chain = make_cleanup (resume_section_map_updates_cleanup,
-                           current_program_space);
+  {
+    scoped_restore inhibit_updates
+      = inhibit_section_map_updates (current_program_space);
 
-  TRY
-    {
-      val = pa->prob->evaluate_argument (1, frame);
-    }
-  CATCH (ex, RETURN_MASK_ERROR)
-    {
-      exception_print (gdb_stderr, ex);
-      val = NULL;
-    }
-  END_CATCH
+    TRY
+      {
+       val = pa->prob->evaluate_argument (1, frame);
+      }
+    CATCH (ex, RETURN_MASK_ERROR)
+      {
+       exception_print (gdb_stderr, ex);
+       val = NULL;
+      }
+    END_CATCH
 
-  if (val == NULL)
-    {
-      do_cleanups (old_chain);
-      return;
-    }
+    if (val == NULL)
+      {
+       do_cleanups (old_chain);
+       return;
+      }
 
-  debug_base = value_as_address (val);
-  if (debug_base == 0)
-    {
-      do_cleanups (old_chain);
-      return;
-    }
+    debug_base = value_as_address (val);
+    if (debug_base == 0)
+      {
+       do_cleanups (old_chain);
+       return;
+      }
 
-  /* Always locate the debug struct, in case it moved.  */
-  info->debug_base = 0;
-  if (locate_base (info) == 0)
-    {
-      do_cleanups (old_chain);
-      return;
-    }
+    /* Always locate the debug struct, in case it moved.  */
+    info->debug_base = 0;
+    if (locate_base (info) == 0)
+      {
+       do_cleanups (old_chain);
+       return;
+      }
 
-  /* GDB does not currently support libraries loaded via dlmopen
-     into namespaces other than the initial one.  We must ignore
-     any namespace other than the initial namespace here until
-     support for this is added to GDB.  */
-  if (debug_base != info->debug_base)
-    action = DO_NOTHING;
+    /* GDB does not currently support libraries loaded via dlmopen
+       into namespaces other than the initial one.  We must ignore
+       any namespace other than the initial namespace here until
+       support for this is added to GDB.  */
+    if (debug_base != info->debug_base)
+      action = DO_NOTHING;
 
-  if (action == UPDATE_OR_RELOAD)
-    {
-      TRY
-       {
-         val = pa->prob->evaluate_argument (2, frame);
-       }
-      CATCH (ex, RETURN_MASK_ERROR)
-       {
-         exception_print (gdb_stderr, ex);
-         do_cleanups (old_chain);
-         return;
-       }
-      END_CATCH
+    if (action == UPDATE_OR_RELOAD)
+      {
+       TRY
+         {
+           val = pa->prob->evaluate_argument (2, frame);
+         }
+       CATCH (ex, RETURN_MASK_ERROR)
+         {
+           exception_print (gdb_stderr, ex);
+           do_cleanups (old_chain);
+           return;
+         }
+       END_CATCH
 
-      if (val != NULL)
-       lm = value_as_address (val);
+       if (val != NULL)
+         lm = value_as_address (val);
 
-      if (lm == 0)
-       action = FULL_RELOAD;
-    }
+       if (lm == 0)
+         action = FULL_RELOAD;
+      }
 
-  /* Resume section map updates.  */
-  do_cleanups (usm_chain);
+    /* Resume section map updates.  Closing the scope is
+       sufficient.  */
+  }
 
   if (action == UPDATE_OR_RELOAD)
     {
@@ -2217,9 +2218,10 @@ enable_break (struct svr4_info *info, int from_tty)
       struct obj_section *os;
 
       sym_addr = gdbarch_addr_bits_remove
-       (target_gdbarch (), gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
-                                                            sym_addr,
-                                                            &current_target));
+       (target_gdbarch (),
+        gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
+                                            sym_addr,
+                                            current_top_target ()));
 
       /* On at least some versions of Solaris there's a dynamic relocation
         on _r_debug.r_brk and SYM_ADDR may not be relocated yet, e.g., if
@@ -2334,7 +2336,7 @@ enable_break (struct svr4_info *info, int from_tty)
       /* If we were not able to find the base address of the loader
          from our so_list, then try using the AT_BASE auxilliary entry.  */
       if (!load_addr_found)
-        if (target_auxv_search (&current_target, AT_BASE, &load_addr) > 0)
+       if (target_auxv_search (current_top_target (), AT_BASE, &load_addr) > 0)
          {
            int addr_bit = gdbarch_addr_bit (target_gdbarch ());
 
@@ -2459,7 +2461,7 @@ enable_break (struct svr4_info *info, int from_tty)
          sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
          sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
                                                         sym_addr,
-                                                        &current_target);
+                                                        current_top_target ());
          svr4_create_solib_event_breakpoints (target_gdbarch (), sym_addr);
          return 1;
        }
@@ -2476,7 +2478,7 @@ enable_break (struct svr4_info *info, int from_tty)
              sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
              sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
                                                             sym_addr,
-                                                            &current_target);
+                                                            current_top_target ());
              svr4_create_solib_event_breakpoints (target_gdbarch (), sym_addr);
              return 1;
            }
@@ -2571,7 +2573,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
   if ((bfd_get_file_flags (exec_bfd) & DYNAMIC) == 0)
     return 0;
 
-  if (target_auxv_search (&current_target, AT_ENTRY, &entry_point) <= 0)
+  if (target_auxv_search (current_top_target (), AT_ENTRY, &entry_point) <= 0)
     return 0;
 
   exec_displacement = entry_point - bfd_get_start_address (exec_bfd);
@@ -2707,8 +2709,10 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
 
                  /* Strip modifies the flags and alignment of PT_GNU_RELRO.
                     CentOS-5 has problems with filesz, memsz as well.
+                    Strip also modifies memsz of PT_TLS.
                     See PR 11786.  */
-                 if (phdr2[i].p_type == PT_GNU_RELRO)
+                 if (phdr2[i].p_type == PT_GNU_RELRO
+                     || phdr2[i].p_type == PT_TLS)
                    {
                      Elf32_External_Phdr tmp_phdr = *phdrp;
                      Elf32_External_Phdr tmp_phdr2 = *phdr2p;
@@ -2838,8 +2842,10 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
 
                  /* Strip modifies the flags and alignment of PT_GNU_RELRO.
                     CentOS-5 has problems with filesz, memsz as well.
+                    Strip also modifies memsz of PT_TLS.
                     See PR 11786.  */
-                 if (phdr2[i].p_type == PT_GNU_RELRO)
+                 if (phdr2[i].p_type == PT_GNU_RELRO
+                     || phdr2[i].p_type == PT_TLS)
                    {
                      Elf64_External_Phdr tmp_phdr = *phdrp;
                      Elf64_External_Phdr tmp_phdr2 = *phdr2p;