From 3637a558a50141676f9997979491296dc007168d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 23 Jan 2021 12:20:11 -0700 Subject: [PATCH] Use std::vector for "registers_used" in compile feature This changes the GDB compile code to use std::vector 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 * symtab.h (struct symbol_computed_ops) : 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 | 24 ++++++++++++++++++++++++ gdb/compile/compile-c-support.c | 8 ++++---- gdb/compile/compile-c-symbols.c | 13 ++++++------- gdb/compile/compile-c.h | 2 +- gdb/compile/compile-loc2c.c | 16 +++++++++------- gdb/compile/compile.h | 4 ++-- gdb/dwarf2/loc.c | 6 +++--- gdb/dwarf2/loc.h | 2 +- gdb/symtab.h | 2 +- 9 files changed, 51 insertions(+), 26 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a45957b55a1..8fa20fae30f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,27 @@ +2021-01-23 Tom Tromey + + * symtab.h (struct symbol_computed_ops) : + 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 * compile/compile-internal.h (class compile_instance) diff --git a/gdb/compile/compile-c-support.c b/gdb/compile/compile-c-support.c index 7ce58c2942e..5f49a0a74f0 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 ®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 registers_used + std::vector 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 6ae3b424a78..08ebe0f4f3b 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 ®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 ®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 +std::vector 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 registers_used - (XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch))); + std::vector 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 526cc98030e..e8082d8a5d5 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 +extern std::vector 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 8ce4a238959..ee9595c78ed 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 ®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 ®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 ®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 ®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 ®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 9dd7f38ebd9..5e733f3e647 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 ®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 ®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 580e5b0deda..aec50da4b6d 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 ®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 ®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 ®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 694300f058b..2943baf91d2 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 ®isters_used, const struct dynamic_prop *prop, CORE_ADDR address, struct symbol *sym); diff --git a/gdb/symtab.h b/gdb/symtab.h index 3c3483e5415..f060e0ebc15 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 ®isters_used, CORE_ADDR pc, const char *result_name); }; -- 2.39.5