Make xml_escape_text return an std::string
[deliverable/binutils-gdb.git] / gdb / rs6000-aix-tdep.c
index 62bc6eed9ad2681698d3bce81b8e890b591d3ead..fc37d6c5236184c410313103b36586f5a9e584b2 100644 (file)
@@ -1,6 +1,6 @@
 /* Native support code for PPC AIX, for GDB the GNU debugger.
 
-   Copyright (C) 2006-2013 Free Software Foundation, Inc.
+   Copyright (C) 2006-2017 Free Software Foundation, Inc.
 
    Free Software Foundation, Inc.
 
@@ -20,8 +20,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_string.h"
-#include "gdb_assert.h"
 #include "osabi.h"
 #include "regcache.h"
 #include "regset.h"
@@ -35,7 +33,6 @@
 #include "rs6000-tdep.h"
 #include "ppc-tdep.h"
 #include "rs6000-aix-tdep.h"
-#include "exceptions.h"
 #include "xcoffread.h"
 #include "solib.h"
 #include "solib-aix.h"
@@ -135,39 +132,32 @@ rs6000_aix_collect_regset (const struct regset *regset,
 
 /* AIX register set.  */
 
-static struct regset rs6000_aix32_regset =
+static const struct regset rs6000_aix32_regset =
 {
   &rs6000_aix32_reg_offsets,
   rs6000_aix_supply_regset,
   rs6000_aix_collect_regset,
 };
 
-static struct regset rs6000_aix64_regset =
+static const struct regset rs6000_aix64_regset =
 {
   &rs6000_aix64_reg_offsets,
   rs6000_aix_supply_regset,
   rs6000_aix_collect_regset,
 };
 
-/* Return the appropriate register set for the core section identified
-   by SECT_NAME and SECT_SIZE.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-rs6000_aix_regset_from_core_section (struct gdbarch *gdbarch,
-                                    const char *sect_name, size_t sect_size)
+static void
+rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
+                                        iterate_over_regset_sections_cb *cb,
+                                        void *cb_data,
+                                        const struct regcache *regcache)
 {
   if (gdbarch_tdep (gdbarch)->wordsize == 4)
-    {
-      if (strcmp (sect_name, ".reg") == 0 && sect_size >= 592)
-        return &rs6000_aix32_regset;
-    }
+    cb (".reg", 592, &rs6000_aix32_regset, NULL, cb_data);
   else
-    {
-      if (strcmp (sect_name, ".reg") == 0 && sect_size >= 576)
-        return &rs6000_aix64_regset;
-    }
-
-  return NULL;
+    cb (".reg", 576, &rs6000_aix64_regset, NULL, cb_data);
 }
 
 
@@ -263,7 +253,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
             Always store the floating point value using the register's
             floating-point format.  */
          const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
-         gdb_byte reg_val[MAX_REGISTER_SIZE];
+         gdb_byte reg_val[PPC_MAX_REGISTER_SIZE];
          struct type *reg_type = register_type (gdbarch, fp_regnum);
 
          gdb_assert (len <= 8);
@@ -280,7 +270,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
          /* Argument takes more than one register.  */
          while (argbytes < len)
            {
-             gdb_byte word[MAX_REGISTER_SIZE];
+             gdb_byte word[PPC_MAX_REGISTER_SIZE];
              memset (word, 0, reg_size);
              memcpy (word,
                      ((char *) value_contents (arg)) + argbytes,
@@ -300,9 +290,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       else
        {
          /* Argument can fit in one register.  No problem.  */
-         int adj = gdbarch_byte_order (gdbarch)
-                   == BFD_ENDIAN_BIG ? reg_size - len : 0;
-         gdb_byte word[MAX_REGISTER_SIZE];
+         gdb_byte word[PPC_MAX_REGISTER_SIZE];
 
          memset (word, 0, reg_size);
          memcpy (word, value_contents (arg), len);
@@ -582,19 +570,20 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
     {
       CORE_ADDR pc = 0;
       struct obj_section *pc_section;
-      volatile struct gdb_exception e;
 
-      TRY_CATCH (e, RETURN_MASK_ERROR)
+      TRY
         {
           pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
         }
-      if (e.reason < 0)
+      CATCH (e, RETURN_MASK_ERROR)
         {
           /* An error occured during reading.  Probably a memory error
              due to the section not being loaded yet.  This address
              cannot be a function descriptor.  */
           return addr;
         }
+      END_CATCH
+
       pc_section = find_pc_section (pc);
 
       if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE))
@@ -608,10 +597,10 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
 /* Calculate the destination of a branch/jump.  Return -1 if not a branch.  */
 
 static CORE_ADDR
-branch_dest (struct frame_info *frame, int opcode, int instr,
+branch_dest (struct regcache *regcache, int opcode, int instr,
             CORE_ADDR pc, CORE_ADDR safety)
 {
-  struct gdbarch *gdbarch = get_frame_arch (frame);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR dest;
@@ -644,29 +633,33 @@ branch_dest (struct frame_info *frame, int opcode, int instr,
 
       if (ext_op == 16)                /* br conditional register */
        {
-          dest = get_frame_register_unsigned (frame, tdep->ppc_lr_regnum) & ~3;
+          dest = regcache_raw_get_unsigned (regcache, tdep->ppc_lr_regnum) & ~3;
 
          /* If we are about to return from a signal handler, dest is
             something like 0x3c90.  The current frame is a signal handler
             caller frame, upon completion of the sigreturn system call
             execution will return to the saved PC in the frame.  */
          if (dest < AIX_TEXT_SEGMENT_BASE)
-           dest = read_memory_unsigned_integer
-                    (get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
-                     tdep->wordsize, byte_order);
+           {
+             struct frame_info *frame = get_current_frame ();
+
+             dest = read_memory_unsigned_integer
+               (get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
+                tdep->wordsize, byte_order);
+           }
        }
 
       else if (ext_op == 528)  /* br cond to count reg */
        {
-          dest = get_frame_register_unsigned (frame,
-                                             tdep->ppc_ctr_regnum) & ~3;
+          dest = regcache_raw_get_unsigned (regcache,
+                                           tdep->ppc_ctr_regnum) & ~3;
 
          /* If we are about to execute a system call, dest is something
             like 0x22fc or 0x3b00.  Upon completion the system call
             will return to the address in the link register.  */
          if (dest < AIX_TEXT_SEGMENT_BASE)
-            dest = get_frame_register_unsigned (frame,
-                                               tdep->ppc_lr_regnum) & ~3;
+            dest = regcache_raw_get_unsigned (regcache,
+                                             tdep->ppc_lr_regnum) & ~3;
        }
       else
        return -1;
@@ -680,27 +673,27 @@ branch_dest (struct frame_info *frame, int opcode, int instr,
 
 /* AIX does not support PT_STEP.  Simulate it.  */
 
-static int
-rs6000_software_single_step (struct frame_info *frame)
+static std::vector<CORE_ADDR>
+rs6000_software_single_step (struct regcache *regcache)
 {
-  struct gdbarch *gdbarch = get_frame_arch (frame);
-  struct address_space *aspace = get_frame_address_space (frame);
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int ii, insn;
   CORE_ADDR loc;
   CORE_ADDR breaks[2];
   int opcode;
 
-  loc = get_frame_pc (frame);
+  loc = regcache_read_pc (regcache);
 
   insn = read_memory_integer (loc, 4, byte_order);
 
-  if (ppc_deal_with_atomic_sequence (frame))
-    return 1;
+  std::vector<CORE_ADDR> next_pcs = ppc_deal_with_atomic_sequence (regcache);
+  if (!next_pcs.empty ())
+    return next_pcs;
   
   breaks[0] = loc + PPC_INSN_SIZE;
   opcode = insn >> 26;
-  breaks[1] = branch_dest (frame, opcode, insn, loc, breaks[0]);
+  breaks[1] = branch_dest (regcache, opcode, insn, loc, breaks[0]);
 
   /* Don't put two breakpoints on the same address.  */
   if (breaks[1] == breaks[0])
@@ -711,12 +704,13 @@ rs6000_software_single_step (struct frame_info *frame)
       /* ignore invalid breakpoint.  */
       if (breaks[ii] == -1)
        continue;
-      insert_single_step_breakpoint (gdbarch, aspace, breaks[ii]);
+
+      next_pcs.push_back (breaks[ii]);
     }
 
   errno = 0;                   /* FIXME, don't ignore errors!  */
   /* What errors?  {read,write}_memory call error().  */
-  return 1;
+  return next_pcs;
 }
 
 /* Implement the "auto_wide_charset" gdbarch method for this platform.  */
@@ -914,20 +908,16 @@ static void
 rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
                                  struct obstack *obstack)
 {
-  char *p;
-
   obstack_grow_str (obstack, "<library name=\"");
-  p = xml_escape_text (ldi->filename);
-  obstack_grow_str (obstack, p);
-  xfree (p);
+  std::string p = xml_escape_text (ldi->filename);
+  obstack_grow_str (obstack, p.c_str ());
   obstack_grow_str (obstack, "\"");
 
   if (ldi->member_name[0] != '\0')
     {
       obstack_grow_str (obstack, " member=\"");
       p = xml_escape_text (ldi->member_name);
-      obstack_grow_str (obstack, p);
-      xfree (p);
+      obstack_grow_str (obstack, p.c_str ());
       obstack_grow_str (obstack, "\"");
     }
 
@@ -965,14 +955,14 @@ rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
    as the consumer of the XML library list might live in a different
    process.  */
 
-LONGEST
+ULONGEST
 rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
-                          gdb_byte *readbuf, ULONGEST offset, LONGEST len,
+                          gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
                           int close_ldinfo_fd)
 {
   struct obstack obstack;
   const char *buf;
-  LONGEST len_avail;
+  ULONGEST len_avail;
 
   obstack_init (&obstack);
   obstack_grow_str (&obstack, "<library-list-aix version=\"1.0\">\n");
@@ -992,7 +982,7 @@ rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
 
   obstack_grow_str0 (&obstack, "</library-list-aix>\n");
 
-  buf = obstack_finish (&obstack);
+  buf = (const char *) obstack_finish (&obstack);
   len_avail = strlen (buf);
   if (offset >= len_avail)
     len= 0;
@@ -1009,11 +999,11 @@ rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
 
 /* Implement the core_xfer_shared_libraries_aix gdbarch method.  */
 
-static LONGEST
+static ULONGEST
 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
                                           gdb_byte *readbuf,
                                           ULONGEST offset,
-                                          LONGEST len)
+                                          ULONGEST len)
 {
   struct bfd_section *ldinfo_sec;
   int ldinfo_size;
@@ -1027,7 +1017,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
           bfd_errmsg (bfd_get_error ()));
   ldinfo_size = bfd_get_section_size (ldinfo_sec);
 
-  ldinfo_buf = xmalloc (ldinfo_size);
+  ldinfo_buf = (gdb_byte *) xmalloc (ldinfo_size);
   cleanup = make_cleanup (xfree, ldinfo_buf);
 
   if (! bfd_get_section_contents (core_bfd, ldinfo_sec,
@@ -1054,7 +1044,6 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
      software single-stepping.  */
   set_gdbarch_displaced_step_copy_insn (gdbarch, NULL);
   set_gdbarch_displaced_step_fixup (gdbarch, NULL);
-  set_gdbarch_displaced_step_free_closure (gdbarch, NULL);
   set_gdbarch_displaced_step_location (gdbarch, NULL);
 
   set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
@@ -1067,8 +1056,8 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
     (gdbarch, rs6000_convert_from_func_ptr_addr);
 
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section
-    (gdbarch, rs6000_aix_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, rs6000_aix_iterate_over_regset_sections);
   set_gdbarch_core_xfer_shared_libraries_aix
     (gdbarch, rs6000_aix_core_xfer_shared_libraries_aix);
 
@@ -1086,14 +1075,16 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
   else
     set_gdbarch_frame_red_zone_size (gdbarch, 0);
 
+  if (tdep->wordsize == 8)
+    set_gdbarch_wchar_bit (gdbarch, 32);
+  else
+    set_gdbarch_wchar_bit (gdbarch, 16);
+  set_gdbarch_wchar_signed (gdbarch, 0);
   set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
 
   set_solib_ops (gdbarch, &solib_aix_so_ops);
 }
 
-/* Provide a prototype to silence -Wmissing-prototypes.  */
-extern initialize_file_ftype _initialize_rs6000_aix_tdep;
-
 void
 _initialize_rs6000_aix_tdep (void)
 {
This page took 0.028765 seconds and 4 git commands to generate.