Return unique_xmalloc_ptr for generate_c_for_variable_locations
[deliverable/binutils-gdb.git] / gdb / compile / compile-loc2c.c
index f1296e8304ec6c4a80250000964b96d7b81ee027..aba791a20fc9421b4e3a2226a8317bc5f1ca9dd9 100644 (file)
@@ -1,6 +1,6 @@
 /* Convert a DWARF location expression to C
 
-   Copyright (C) 2014-2017 Free Software Foundation, Inc.
+   Copyright (C) 2014-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -62,7 +62,7 @@ struct insn_info
    NEED_TEMPVAR is an out parameter which is set if this expression
    needs a special temporary variable to be emitted (see the code
    generator).
-   INFO is an array of insn_info objects, indexed by offset from the
+   INFO is a vector of insn_info objects, indexed by offset from the
    start of the DWARF expression.
    TO_DO is a list of bytecodes which must be examined; it may be
    added to by this function.
@@ -71,8 +71,8 @@ struct insn_info
 
 static void
 compute_stack_depth_worker (int start, int *need_tempvar,
-                           struct insn_info *info,
-                           VEC (int) **to_do,
+                           std::vector<struct insn_info> *info,
+                           std::vector<int> *to_do,
                            enum bfd_endian byte_order, unsigned int addr_size,
                            const gdb_byte *op_ptr, const gdb_byte *op_end)
 {
@@ -80,8 +80,8 @@ compute_stack_depth_worker (int start, int *need_tempvar,
   int stack_depth;
 
   op_ptr += start;
-  gdb_assert (info[start].visited);
-  stack_depth = info[start].depth;
+  gdb_assert ((*info)[start].visited);
+  stack_depth = (*info)[start].depth;
 
   while (op_ptr < op_end)
     {
@@ -91,16 +91,16 @@ compute_stack_depth_worker (int start, int *need_tempvar,
       int ndx = op_ptr - base;
 
 #define SET_CHECK_DEPTH(WHERE)                         \
-      if (info[WHERE].visited)                         \
+      if ((*info)[WHERE].visited)                              \
        {                                               \
-         if (info[WHERE].depth != stack_depth)         \
+         if ((*info)[WHERE].depth != stack_depth)              \
            error (_("inconsistent stack depths"));     \
        }                                               \
       else                                             \
        {                                               \
          /* Stack depth not set, so set it.  */        \
-         info[WHERE].visited = 1;                      \
-         info[WHERE].depth = stack_depth;              \
+         (*info)[WHERE].visited = 1;                   \
+         (*info)[WHERE].depth = stack_depth;           \
        }
 
       SET_CHECK_DEPTH (ndx);
@@ -324,7 +324,7 @@ compute_stack_depth_worker (int start, int *need_tempvar,
 
        case DW_OP_GNU_push_tls_address:
        case DW_OP_form_tls_address:
-         info[ndx].is_tls = 1;
+         (*info)[ndx].is_tls = 1;
          break;
 
        case DW_OP_skip:
@@ -333,10 +333,10 @@ compute_stack_depth_worker (int start, int *need_tempvar,
          offset = op_ptr + offset - base;
          /* If the destination has not been seen yet, add it to the
             to-do list.  */
-         if (!info[offset].visited)
-           VEC_safe_push (int, *to_do, offset);
+         if (!(*info)[offset].visited)
+           to_do->push_back (offset);
          SET_CHECK_DEPTH (offset);
-         info[offset].label = 1;
+         (*info)[offset].label = 1;
          /* We're done with this line of code.  */
          return;
 
@@ -347,10 +347,10 @@ compute_stack_depth_worker (int start, int *need_tempvar,
          --stack_depth;
          /* If the destination has not been seen yet, add it to the
             to-do list.  */
-         if (!info[offset].visited)
-           VEC_safe_push (int, *to_do, offset);
+         if (!(*info)[offset].visited)
+           to_do->push_back (offset);
          SET_CHECK_DEPTH (offset);
-         info[offset].label = 1;
+         (*info)[offset].label = 1;
          break;
 
        case DW_OP_nop:
@@ -387,27 +387,23 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
                     int *need_tempvar, int *is_tls,
                     const gdb_byte *op_ptr, const gdb_byte *op_end,
                     int initial_depth,
-                    struct insn_info **info)
+                    std::vector<struct insn_info> *info)
 {
-  unsigned char *set;
-  struct cleanup *outer_cleanup, *cleanup;
-  VEC (int) *to_do = NULL;
+  std::vector<int> to_do;
   int stack_depth, i;
 
-  *info = XCNEWVEC (struct insn_info, op_end - op_ptr);
-  outer_cleanup = make_cleanup (xfree, *info);
-
-  cleanup = make_cleanup (VEC_cleanup (int), &to_do);
+  info->resize (op_end - op_ptr);
 
-  VEC_safe_push (int, to_do, 0);
+  to_do.push_back (0);
   (*info)[0].depth = initial_depth;
   (*info)[0].visited = 1;
 
-  while (!VEC_empty (int, to_do))
+  while (!to_do.empty ())
     {
-      int ndx = VEC_pop (int, to_do);
+      int ndx = to_do.back ();
+      to_do.pop_back ();
 
-      compute_stack_depth_worker (ndx, need_tempvar, *info, &to_do,
+      compute_stack_depth_worker (ndx, need_tempvar, info, &to_do,
                                  byte_order, addr_size,
                                  op_ptr, op_end);
     }
@@ -422,8 +418,6 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
        *is_tls = 1;
     }
 
-  do_cleanups (cleanup);
-  discard_cleanups (outer_cleanup);
   return stack_depth + 1;
 }
 
@@ -517,15 +511,12 @@ pushf_register_address (int indent, string_file &stream,
                        unsigned char *registers_used,
                        struct gdbarch *gdbarch, int regnum)
 {
-  char *regname = compile_register_name_mangled (gdbarch, regnum);
-  struct cleanup *cleanups = make_cleanup (xfree, regname);
+  std::string regname = compile_register_name_mangled (gdbarch, regnum);
 
   registers_used[regnum] = 1;
   pushf (indent, stream,
         "(" GCC_UINTPTR ") &" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
-        regname);
-
-  do_cleanups (cleanups);
+        regname.c_str ());
 }
 
 /* Emit code that pushes a register's value on the stack.
@@ -538,19 +529,16 @@ pushf_register (int indent, string_file &stream,
                unsigned char *registers_used,
                struct gdbarch *gdbarch, int regnum, uint64_t offset)
 {
-  char *regname = compile_register_name_mangled (gdbarch, regnum);
-  struct cleanup *cleanups = make_cleanup (xfree, regname);
+  std::string regname = compile_register_name_mangled (gdbarch, regnum);
 
   registers_used[regnum] = 1;
   if (offset == 0)
     pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
-          regname);
+          regname.c_str ());
   else
     pushf (indent, stream,
           COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + (" GCC_UINTPTR ") %s",
-          regname, hex_string (offset));
-
-  do_cleanups (cleanups);
+          regname.c_str (), hex_string (offset));
 }
 
 /* Compile a DWARF expression to C code.
@@ -602,8 +590,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
   const gdb_byte * const base = op_ptr;
   int need_tempvar = 0;
   int is_tls = 0;
-  struct cleanup *cleanup;
-  struct insn_info *info;
+  std::vector<struct insn_info> info;
   int stack_depth;
 
   ++scope;
@@ -617,7 +604,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
                                     &need_tempvar, &is_tls,
                                     op_ptr, op_end, initial != NULL,
                                     &info);
-  cleanup = make_cleanup (xfree, info);
 
   /* This is a hack until we can add a feature to glibc to let us
      properly generate code for TLS.  You might think we could emit
@@ -651,7 +637,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
                         result_name,
                         core_addr_to_string (value_address (val)));
       fprintfi_filtered (indent - 2, &stream, "}\n");
-      do_cleanups (cleanup);
       return;
     }
 
@@ -724,6 +709,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
          break;
 
        case DW_OP_addr:
+         uoffset = extract_unsigned_integer (op_ptr, addr_size, byte_order);
          op_ptr += addr_size;
          /* Some versions of GCC emit DW_OP_addr before
             DW_OP_GNU_push_tls_address.  In this case the value is an
@@ -1124,8 +1110,6 @@ do_compile_dwarf_expr_to_c (int indent, string_file &stream,
   fprintfi_filtered (indent, &stream, "%s = __gdb_stack[__gdb_tos];\n",
                     result_name);
   fprintfi_filtered (indent - 2, &stream, "}\n");
-
-  do_cleanups (cleanup);
 }
 
 /* See compile.h.  */
This page took 0.028144 seconds and 4 git commands to generate.