diff options
author | Tom Tromey <tom@tromey.com> | 2021-01-23 12:20:11 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-01-23 20:33:25 -0700 |
commit | 3637a558a50141676f9997979491296dc007168d (patch) | |
tree | 6a15b32e0bbf8f7d81f6557cbc0ce0e343bddbd2 | |
parent | 18454c151f5824564130ba626bd90e9de30444ef (diff) | |
download | binutils-3637a558a50141676f9997979491296dc007168d.zip binutils-3637a558a50141676f9997979491296dc007168d.tar.gz binutils-3637a558a50141676f9997979491296dc007168d.tar.bz2 |
Use std::vector for "registers_used" in compile feature
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.
-rw-r--r-- | gdb/ChangeLog | 24 | ||||
-rw-r--r-- | gdb/compile/compile-c-support.c | 8 | ||||
-rw-r--r-- | gdb/compile/compile-c-symbols.c | 13 | ||||
-rw-r--r-- | gdb/compile/compile-c.h | 2 | ||||
-rw-r--r-- | gdb/compile/compile-loc2c.c | 16 | ||||
-rw-r--r-- | gdb/compile/compile.h | 4 | ||||
-rw-r--r-- | gdb/dwarf2/loc.c | 6 | ||||
-rw-r--r-- | gdb/dwarf2/loc.h | 2 | ||||
-rw-r--r-- | gdb/symtab.h | 2 |
9 files changed, 51 insertions, 26 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a45957b..8fa20fa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,29 @@ 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) <set_arguments>: Change return type. * compile/compile.c (compile_to_object): Remove call to reset. diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index 7ce58c2..5f49a0a 100644 --- a/gdb/compile/compile-c-support.c +++ b/gdb/compile/compile-c-support.c @@ -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> ®isters_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); diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 6ae3b42..08ebe0f 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -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> ®isters_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> ®isters_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 diff --git a/gdb/compile/compile-c.h b/gdb/compile/compile-c.h index 526cc98..e8082d8 100644 --- a/gdb/compile/compile-c.h +++ b/gdb/compile/compile-c.h @@ -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, diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c index 8ce4a23..ee9595c 100644 --- a/gdb/compile/compile-loc2c.c +++ b/gdb/compile/compile-loc2c.c @@ -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> ®isters_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> ®isters_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> ®isters_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> ®isters_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> ®isters_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, dwarf2_per_cu_data *per_cu, diff --git a/gdb/compile/compile.h b/gdb/compile/compile.h index 9dd7f38..5e733f3 100644 --- a/gdb/compile/compile.h +++ b/gdb/compile/compile.h @@ -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> ®isters_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> ®isters_used, unsigned int addr_size, const gdb_byte *op_ptr, const gdb_byte *op_end, diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 580e5b0..aec50da 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -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> ®isters_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> ®isters_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> ®isters_used, CORE_ADDR pc, const char *result_name) { struct dwarf2_loclist_baton *dlbaton diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index 694300f..2943baf 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -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> ®isters_used, const struct dynamic_prop *prop, CORE_ADDR address, struct symbol *sym); diff --git a/gdb/symtab.h b/gdb/symtab.h index 3c3483e..f060e0e 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -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> ®isters_used, CORE_ADDR pc, const char *result_name); }; |