From 8480a37e146c40e82a93c0ecf6144571516c95c5 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 19 Feb 2024 13:07:47 -0500 Subject: gdb: pass frames as `const frame_info_ptr &` We currently pass frames to function by value, as `frame_info_ptr`. This is somewhat expensive: - the size of `frame_info_ptr` is 64 bytes, which is a bit big to pass by value - the constructors and destructor link/unlink the object in the global `frame_info_ptr::frame_list` list. This is an `intrusive_list`, so it's not so bad: it's just assigning a few points, there's no memory allocation as if it was `std::list`, but still it's useless to do that over and over. As suggested by Tom Tromey, change many function signatures to accept `const frame_info_ptr &` instead of `frame_info_ptr`. Some functions reassign their `frame_info_ptr` parameter, like: void the_func (frame_info_ptr frame) { for (; frame != nullptr; frame = get_prev_frame (frame)) { ... } } I wondered what to do about them, do I leave them as-is or change them (and need to introduce a separate local variable that can be re-assigned). I opted for the later for consistency. It might not be clear why some functions take `const frame_info_ptr &` while others take `frame_info_ptr`. Also, if a function took a `frame_info_ptr` because it did re-assign its parameter, I doubt that we would think to change it to `const frame_info_ptr &` should the implementation change such that it doesn't need to take `frame_info_ptr` anymore. It seems better to have a simple rule and apply it everywhere. Change-Id: I59d10addef687d157f82ccf4d54f5dde9a963fd0 Approved-By: Andrew Burgess --- gdb/gdbarch.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'gdb/gdbarch.c') diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index b9be394..80a04bf 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -1894,7 +1894,7 @@ gdbarch_pseudo_register_read_value_p (struct gdbarch *gdbarch) } struct value * -gdbarch_pseudo_register_read_value (struct gdbarch *gdbarch, frame_info_ptr next_frame, int cookednum) +gdbarch_pseudo_register_read_value (struct gdbarch *gdbarch, const frame_info_ptr &next_frame, int cookednum) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->pseudo_register_read_value != NULL); @@ -1918,7 +1918,7 @@ gdbarch_pseudo_register_write_p (struct gdbarch *gdbarch) } void -gdbarch_pseudo_register_write (struct gdbarch *gdbarch, frame_info_ptr next_frame, int pseudo_reg_num, gdb::array_view buf) +gdbarch_pseudo_register_write (struct gdbarch *gdbarch, const frame_info_ptr &next_frame, int pseudo_reg_num, gdb::array_view buf) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->pseudo_register_write != NULL); @@ -2240,7 +2240,7 @@ set_gdbarch_register_type (struct gdbarch *gdbarch, } struct frame_id -gdbarch_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame) +gdbarch_dummy_id (struct gdbarch *gdbarch, const frame_info_ptr &this_frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->dummy_id != NULL); @@ -2339,7 +2339,7 @@ set_gdbarch_push_dummy_code (struct gdbarch *gdbarch, } int -gdbarch_code_of_frame_writable (struct gdbarch *gdbarch, frame_info_ptr frame) +gdbarch_code_of_frame_writable (struct gdbarch *gdbarch, const frame_info_ptr &frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->code_of_frame_writable != NULL); @@ -2356,7 +2356,7 @@ set_gdbarch_code_of_frame_writable (struct gdbarch *gdbarch, } void -gdbarch_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, frame_info_ptr frame, int regnum, int all) +gdbarch_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, const frame_info_ptr &frame, int regnum, int all) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->print_registers_info != NULL); @@ -2373,7 +2373,7 @@ set_gdbarch_print_registers_info (struct gdbarch *gdbarch, } void -gdbarch_print_float_info (struct gdbarch *gdbarch, struct ui_file *file, frame_info_ptr frame, const char *args) +gdbarch_print_float_info (struct gdbarch *gdbarch, struct ui_file *file, const frame_info_ptr &frame, const char *args) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->print_float_info != NULL); @@ -2397,7 +2397,7 @@ gdbarch_print_vector_info_p (struct gdbarch *gdbarch) } void -gdbarch_print_vector_info (struct gdbarch *gdbarch, struct ui_file *file, frame_info_ptr frame, const char *args) +gdbarch_print_vector_info (struct gdbarch *gdbarch, struct ui_file *file, const frame_info_ptr &frame, const char *args) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->print_vector_info != NULL); @@ -2472,7 +2472,7 @@ gdbarch_get_longjmp_target_p (struct gdbarch *gdbarch) } int -gdbarch_get_longjmp_target (struct gdbarch *gdbarch, frame_info_ptr frame, CORE_ADDR *pc) +gdbarch_get_longjmp_target (struct gdbarch *gdbarch, const frame_info_ptr &frame, CORE_ADDR *pc) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->get_longjmp_target != NULL); @@ -2523,7 +2523,7 @@ set_gdbarch_convert_register_p (struct gdbarch *gdbarch, } int -gdbarch_register_to_value (struct gdbarch *gdbarch, frame_info_ptr frame, int regnum, struct type *type, gdb_byte *buf, int *optimizedp, int *unavailablep) +gdbarch_register_to_value (struct gdbarch *gdbarch, const frame_info_ptr &frame, int regnum, struct type *type, gdb_byte *buf, int *optimizedp, int *unavailablep) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->register_to_value != NULL); @@ -2540,7 +2540,7 @@ set_gdbarch_register_to_value (struct gdbarch *gdbarch, } void -gdbarch_value_to_register (struct gdbarch *gdbarch, frame_info_ptr frame, int regnum, struct type *type, const gdb_byte *buf) +gdbarch_value_to_register (struct gdbarch *gdbarch, const frame_info_ptr &frame, int regnum, struct type *type, const gdb_byte *buf) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->value_to_register != NULL); @@ -2656,7 +2656,7 @@ set_gdbarch_return_value_as_value (struct gdbarch *gdbarch, } CORE_ADDR -gdbarch_get_return_buf_addr (struct gdbarch *gdbarch, struct type *val_type, frame_info_ptr cur_frame) +gdbarch_get_return_buf_addr (struct gdbarch *gdbarch, struct type *val_type, const frame_info_ptr &cur_frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->get_return_buf_addr != NULL); @@ -3048,7 +3048,7 @@ set_gdbarch_frame_args_skip (struct gdbarch *gdbarch, } CORE_ADDR -gdbarch_unwind_pc (struct gdbarch *gdbarch, frame_info_ptr next_frame) +gdbarch_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->unwind_pc != NULL); @@ -3065,7 +3065,7 @@ set_gdbarch_unwind_pc (struct gdbarch *gdbarch, } CORE_ADDR -gdbarch_unwind_sp (struct gdbarch *gdbarch, frame_info_ptr next_frame) +gdbarch_unwind_sp (struct gdbarch *gdbarch, const frame_info_ptr &next_frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->unwind_sp != NULL); @@ -3089,7 +3089,7 @@ gdbarch_frame_num_args_p (struct gdbarch *gdbarch) } int -gdbarch_frame_num_args (struct gdbarch *gdbarch, frame_info_ptr frame) +gdbarch_frame_num_args (struct gdbarch *gdbarch, const frame_info_ptr &frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->frame_num_args != NULL); @@ -3348,7 +3348,7 @@ gdbarch_single_step_through_delay_p (struct gdbarch *gdbarch) } int -gdbarch_single_step_through_delay (struct gdbarch *gdbarch, frame_info_ptr frame) +gdbarch_single_step_through_delay (struct gdbarch *gdbarch, const frame_info_ptr &frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->single_step_through_delay != NULL); @@ -3382,7 +3382,7 @@ set_gdbarch_print_insn (struct gdbarch *gdbarch, } CORE_ADDR -gdbarch_skip_trampoline_code (struct gdbarch *gdbarch, frame_info_ptr frame, CORE_ADDR pc) +gdbarch_skip_trampoline_code (struct gdbarch *gdbarch, const frame_info_ptr &frame, CORE_ADDR pc) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->skip_trampoline_code != NULL); @@ -3723,7 +3723,7 @@ gdbarch_fetch_pointer_argument_p (struct gdbarch *gdbarch) } CORE_ADDR -gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, frame_info_ptr frame, int argi, struct type *type) +gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, const frame_info_ptr &frame, int argi, struct type *type) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->fetch_pointer_argument != NULL); @@ -5414,7 +5414,7 @@ set_gdbarch_type_align (struct gdbarch *gdbarch, } std::string -gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, frame_info_ptr frame, CORE_ADDR pc) +gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, const frame_info_ptr &frame, CORE_ADDR pc) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->get_pc_address_flags != NULL); -- cgit v1.1