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.
This commit is contained in:
Tom Tromey 2021-01-23 12:20:11 -07:00
parent 18454c151f
commit 3637a558a5
9 changed files with 51 additions and 26 deletions

View 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)

View 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);

View 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

View 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,

View 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,

View 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,

View 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

View 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);

View 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);
};