Use std::vector for "registers_used" in compile feature
authorTom Tromey <tom@tromey.com>
Sat, 23 Jan 2021 19:20:11 +0000 (12:20 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 24 Jan 2021 03:33:25 +0000 (20:33 -0700)
This changes the GDB compile code to use std::vector<bool> when
computing which registers are used.  This is a bit more idiomatic, but
the main benefit is that it also adds some checking when the libstd++
debug mode is enabled.

2021-01-23  Tom Tromey  <tom@tromey.com>

* symtab.h (struct symbol_computed_ops) <generate_c_location>:
Change type of "registers_used".
* dwarf2/loc.h (dwarf2_compile_property_to_c): Update.
* dwarf2/loc.c (dwarf2_compile_property_to_c)
(locexpr_generate_c_location, loclist_generate_c_location): Change
type of "registers_used".
* compile/compile.h (compile_dwarf_expr_to_c)
(compile_dwarf_bounds_to_c): Update.
* compile/compile-loc2c.c (pushf_register_address)
(pushf_register, do_compile_dwarf_expr_to_c)
(compile_dwarf_expr_to_c, compile_dwarf_bounds_to_c): Change type
of "registers_used".
* compile/compile-c.h (generate_c_for_variable_locations):
Update.
* compile/compile-c-symbols.c (generate_vla_size)
(generate_c_for_for_one_variable): Change type of
"registers_used".
(generate_c_for_variable_locations): Return std::vector.
* compile/compile-c-support.c (generate_register_struct): Change
type of "registers_used".
(compute): Update.

gdb/ChangeLog
gdb/compile/compile-c-support.c
gdb/compile/compile-c-symbols.c
gdb/compile/compile-c.h
gdb/compile/compile-loc2c.c
gdb/compile/compile.h
gdb/dwarf2/loc.c
gdb/dwarf2/loc.h
gdb/symtab.h

index a45957b55a118d02926b9174458f41b4d047052c..8fa20fae30fa926a8726023c9f900771f817680d 100644 (file)
@@ -1,3 +1,27 @@
+2021-01-23  Tom Tromey  <tom@tromey.com>
+
+       * symtab.h (struct symbol_computed_ops) <generate_c_location>:
+       Change type of "registers_used".
+       * dwarf2/loc.h (dwarf2_compile_property_to_c): Update.
+       * dwarf2/loc.c (dwarf2_compile_property_to_c)
+       (locexpr_generate_c_location, loclist_generate_c_location): Change
+       type of "registers_used".
+       * compile/compile.h (compile_dwarf_expr_to_c)
+       (compile_dwarf_bounds_to_c): Update.
+       * compile/compile-loc2c.c (pushf_register_address)
+       (pushf_register, do_compile_dwarf_expr_to_c)
+       (compile_dwarf_expr_to_c, compile_dwarf_bounds_to_c): Change type
+       of "registers_used".
+       * compile/compile-c.h (generate_c_for_variable_locations):
+       Update.
+       * compile/compile-c-symbols.c (generate_vla_size)
+       (generate_c_for_for_one_variable): Change type of
+       "registers_used".
+       (generate_c_for_variable_locations): Return std::vector.
+       * compile/compile-c-support.c (generate_register_struct): Change
+       type of "registers_used".
+       (compute): Update.
+
 2021-01-23  Tom Tromey  <tom@tromey.com>
 
        * compile/compile-internal.h (class compile_instance)
index 7ce58c2942ed3788d083ccd720ff5ec440a7de2f..5f49a0a74f0428bffb745433fd28c9c1aace0275 100644 (file)
@@ -213,7 +213,7 @@ write_macro_definitions (const struct block *block, CORE_ADDR pc,
 
 static void
 generate_register_struct (struct ui_file *stream, struct gdbarch *gdbarch,
-                         const unsigned char *registers_used)
+                         const std::vector<bool> &registers_used)
 {
   int i;
   int seen = 0;
@@ -221,7 +221,7 @@ generate_register_struct (struct ui_file *stream, struct gdbarch *gdbarch,
   fputs_unfiltered ("struct " COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG " {\n",
                    stream);
 
-  if (registers_used != NULL)
+  if (!registers_used.empty ())
     for (i = 0; i < gdbarch_num_regs (gdbarch); ++i)
       {
        if (registers_used[i])
@@ -572,7 +572,7 @@ public:
           before generating the function header, so we can define the
           register struct before the function body.  This requires a
           temporary stream.  */
-       gdb::unique_xmalloc_ptr<unsigned char> registers_used
+       std::vector<bool> registers_used
          = generate_c_for_variable_locations (m_instance, &var_stream, m_arch,
                                               expr_block, expr_pc);
 
@@ -595,7 +595,7 @@ public:
                        mode, mode);
          }
 
-       generate_register_struct (&buf, m_arch, registers_used.get ());
+       generate_register_struct (&buf, m_arch, registers_used);
       }
 
     AddCodeHeaderPolicy::add_code_header (m_instance->scope (), &buf);
index 6ae3b424a78dfd663b6f66e982dd21d5933512fb..08ebe0f4f3be7e09a31bb0f03c7f635c5a61677a 100644 (file)
@@ -487,7 +487,7 @@ static void
 generate_vla_size (compile_instance *compiler,
                   string_file *stream,
                   struct gdbarch *gdbarch,
-                  unsigned char *registers_used,
+                  std::vector<bool> &registers_used,
                   CORE_ADDR pc,
                   struct type *type,
                   struct symbol *sym)
@@ -541,7 +541,7 @@ static void
 generate_c_for_for_one_variable (compile_instance *compiler,
                                 string_file *stream,
                                 struct gdbarch *gdbarch,
-                                unsigned char *registers_used,
+                                std::vector<bool> &registers_used,
                                 CORE_ADDR pc,
                                 struct symbol *sym)
 {
@@ -606,7 +606,7 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 
 /* See compile-c.h.  */
 
-gdb::unique_xmalloc_ptr<unsigned char>
+std::vector<bool>
 generate_c_for_variable_locations (compile_instance *compiler,
                                   string_file *stream,
                                   struct gdbarch *gdbarch,
@@ -618,10 +618,9 @@ generate_c_for_variable_locations (compile_instance *compiler,
   /* If we're already in the static or global block, there is nothing
      to write.  */
   if (static_block == NULL || block == static_block)
-    return NULL;
+    return {};
 
-  gdb::unique_xmalloc_ptr<unsigned char> registers_used
-    (XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch)));
+  std::vector<bool> registers_used (gdbarch_num_regs (gdbarch));
 
   /* Ensure that a given name is only entered once.  This reflects the
      reality of shadowing.  */
@@ -641,7 +640,7 @@ generate_c_for_variable_locations (compile_instance *compiler,
        {
          if (!symbol_seen (symhash.get (), sym))
            generate_c_for_for_one_variable (compiler, stream, gdbarch,
-                                            registers_used.get (), pc, sym);
+                                            registers_used, pc, sym);
        }
 
       /* If we just finished the outermost block of a function, we're
index 526cc98030e2a443255f34b79574510474238f42..e8082d8a5d5d38ea7bdf332cc98d53ef1735f28c 100644 (file)
@@ -66,7 +66,7 @@ private:
    register number, where each element indicates if the corresponding
    register is needed to compute a local variable.  */
 
-extern gdb::unique_xmalloc_ptr<unsigned char>
+extern std::vector<bool>
   generate_c_for_variable_locations
      (compile_instance *compiler,
       string_file *stream,
index 8ce4a23895992fb30103c8c132977767361adca8..ee9595c78edb0eb78f0174633e3648a997e6a5de 100644 (file)
@@ -511,12 +511,12 @@ print_label (string_file *stream, unsigned int scope, int target)
 
 static void
 pushf_register_address (int indent, string_file *stream,
-                       unsigned char *registers_used,
+                       std::vector<bool> &registers_used,
                        struct gdbarch *gdbarch, int regnum)
 {
   std::string regname = compile_register_name_mangled (gdbarch, regnum);
 
-  registers_used[regnum] = 1;
+  registers_used[regnum] = true;
   pushf (indent, stream,
         "(" GCC_UINTPTR ") &" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
         regname.c_str ());
@@ -529,12 +529,12 @@ pushf_register_address (int indent, string_file *stream,
 
 static void
 pushf_register (int indent, string_file *stream,
-               unsigned char *registers_used,
+               std::vector<bool> &registers_used,
                struct gdbarch *gdbarch, int regnum, uint64_t offset)
 {
   std::string regname = compile_register_name_mangled (gdbarch, regnum);
 
-  registers_used[regnum] = 1;
+  registers_used[regnum] = true;
   if (offset == 0)
     pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
           regname.c_str ());
@@ -579,7 +579,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
                            const char *result_name,
                            struct symbol *sym, CORE_ADDR pc,
                            struct gdbarch *arch,
-                           unsigned char *registers_used,
+                           std::vector<bool> &registers_used,
                            unsigned int addr_size,
                            const gdb_byte *op_ptr, const gdb_byte *op_end,
                            CORE_ADDR *initial,
@@ -1129,7 +1129,8 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 void
 compile_dwarf_expr_to_c (string_file *stream, const char *result_name,
                         struct symbol *sym, CORE_ADDR pc,
-                        struct gdbarch *arch, unsigned char *registers_used,
+                        struct gdbarch *arch,
+                        std::vector<bool> &registers_used,
                         unsigned int addr_size,
                         const gdb_byte *op_ptr, const gdb_byte *op_end,
                         dwarf2_per_cu_data *per_cu,
@@ -1147,7 +1148,8 @@ compile_dwarf_bounds_to_c (string_file *stream,
                           const char *result_name,
                           const struct dynamic_prop *prop,
                           struct symbol *sym, CORE_ADDR pc,
-                          struct gdbarch *arch, unsigned char *registers_used,
+                          struct gdbarch *arch,
+                          std::vector<bool> &registers_used,
                           unsigned int addr_size,
                           const gdb_byte *op_ptr, const gdb_byte *op_end,
                           dwarf2_per_cu_data *per_cu,
index 9dd7f38ebd96cfc1565a0137d129fb390ff0ae17..5e733f3e647f3cf4d5d629b4d7f53c827ef1996f 100644 (file)
@@ -64,7 +64,7 @@ extern void compile_dwarf_expr_to_c (string_file *stream,
                                     struct symbol *sym,
                                     CORE_ADDR pc,
                                     struct gdbarch *arch,
-                                    unsigned char *registers_used,
+                                    std::vector<bool> &registers_used,
                                     unsigned int addr_size,
                                     const gdb_byte *op_ptr,
                                     const gdb_byte *op_end,
@@ -103,7 +103,7 @@ extern void compile_dwarf_bounds_to_c (string_file *stream,
                                       const struct dynamic_prop *prop,
                                       struct symbol *sym, CORE_ADDR pc,
                                       struct gdbarch *arch,
-                                      unsigned char *registers_used,
+                                      std::vector<bool> &registers_used,
                                       unsigned int addr_size,
                                       const gdb_byte *op_ptr,
                                       const gdb_byte *op_end,
index 580e5b0dedaac2c54e8e8660ab4747f62af3791d..aec50da4b6da9437709f3b06849f4274d978bb02 100644 (file)
@@ -2699,7 +2699,7 @@ void
 dwarf2_compile_property_to_c (string_file *stream,
                              const char *result_name,
                              struct gdbarch *gdbarch,
-                             unsigned char *registers_used,
+                             std::vector<bool> &registers_used,
                              const struct dynamic_prop *prop,
                              CORE_ADDR pc,
                              struct symbol *sym)
@@ -4475,7 +4475,7 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 static void
 locexpr_generate_c_location (struct symbol *sym, string_file *stream,
                             struct gdbarch *gdbarch,
-                            unsigned char *registers_used,
+                            std::vector<bool> &registers_used,
                             CORE_ADDR pc, const char *result_name)
 {
   struct dwarf2_locexpr_baton *dlbaton
@@ -4707,7 +4707,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 static void
 loclist_generate_c_location (struct symbol *sym, string_file *stream,
                             struct gdbarch *gdbarch,
-                            unsigned char *registers_used,
+                            std::vector<bool> &registers_used,
                             CORE_ADDR pc, const char *result_name)
 {
   struct dwarf2_loclist_baton *dlbaton
index 694300f058b94b054e4d1a31228f48c1bb72405d..2943baf91d2213797f5f75f2a70733d0a1bab880 100644 (file)
@@ -120,7 +120,7 @@ bool dwarf2_evaluate_property (const struct dynamic_prop *prop,
 void dwarf2_compile_property_to_c (string_file *stream,
                                   const char *result_name,
                                   struct gdbarch *gdbarch,
-                                  unsigned char *registers_used,
+                                  std::vector<bool> &registers_used,
                                   const struct dynamic_prop *prop,
                                   CORE_ADDR address,
                                   struct symbol *sym);
index 3c3483e5415d56dfd76dc7e3ecd3d193e06abbce..f060e0ebc15cb76f835f1f425bfcabe9745425fc 100644 (file)
@@ -1022,7 +1022,7 @@ struct symbol_computed_ops
 
   void (*generate_c_location) (struct symbol *symbol, string_file *stream,
                               struct gdbarch *gdbarch,
-                              unsigned char *registers_used,
+                              std::vector<bool> &registers_used,
                               CORE_ADDR pc, const char *result_name);
 
 };