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/tui/tui-disasm.c | 2 +- gdb/tui/tui-disasm.h | 2 +- gdb/tui/tui-hooks.c | 2 +- gdb/tui/tui-regs.c | 4 ++-- gdb/tui/tui-regs.h | 2 +- gdb/tui/tui-source.c | 2 +- gdb/tui/tui-source.h | 2 +- gdb/tui/tui-status.c | 4 ++-- gdb/tui/tui-status.h | 2 +- gdb/tui/tui-winsource.h | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) (limited to 'gdb/tui') diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 45c60db..5dc27c3 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -490,7 +490,7 @@ tui_disasm_window::addr_is_displayed (CORE_ADDR addr) const } void -tui_disasm_window::maybe_update (frame_info_ptr fi, symtab_and_line sal) +tui_disasm_window::maybe_update (const frame_info_ptr &fi, symtab_and_line sal) { CORE_ADDR low; diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h index 9c4eabb..0aef091 100644 --- a/gdb/tui/tui-disasm.h +++ b/gdb/tui/tui-disasm.h @@ -41,7 +41,7 @@ struct tui_disasm_window : public tui_source_window_base bool location_matches_p (struct bp_location *loc, int line_no) override; - void maybe_update (frame_info_ptr fi, symtab_and_line sal) override; + void maybe_update (const frame_info_ptr &fi, symtab_and_line sal) override; void erase_source_content () override { diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c index 28d0b74..289a259 100644 --- a/gdb/tui/tui-hooks.c +++ b/gdb/tui/tui-hooks.c @@ -66,7 +66,7 @@ tui_all_objfiles_removed (program_space *pspace) /* Observer for the register_changed notification. */ static void -tui_register_changed (frame_info_ptr frame, int regno) +tui_register_changed (const frame_info_ptr &frame, int regno) { frame_info_ptr fi; diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 504aed4..e7c1839 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -85,7 +85,7 @@ tab_expansion_file::write (const char *buf, long length_buf) representation of it. */ static std::string -tui_register_format (frame_info_ptr frame, int regnum) +tui_register_format (const frame_info_ptr &frame, int regnum) { struct gdbarch *gdbarch = get_frame_arch (frame); @@ -406,7 +406,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll) given a particular frame. If the values have changed, they are updated with the new value and highlighted. */ void -tui_data_window::check_register_values (frame_info_ptr frame) +tui_data_window::check_register_values (const frame_info_ptr &frame) { if (frame == nullptr) set_register_group (nullptr); diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h index 9d9cae4..07b9513 100644 --- a/gdb/tui/tui-regs.h +++ b/gdb/tui/tui-regs.h @@ -74,7 +74,7 @@ struct tui_data_window : public tui_win_info return DATA_NAME; } - void check_register_values (frame_info_ptr frame); + void check_register_values (const frame_info_ptr &frame); void set_register_group (const reggroup *group); diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 635cb2f..fa956b2 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -199,7 +199,7 @@ tui_source_window::line_is_displayed (int line) const } void -tui_source_window::maybe_update (frame_info_ptr fi, symtab_and_line sal) +tui_source_window::maybe_update (const frame_info_ptr &fi, symtab_and_line sal) { int start_line = (sal.line - ((height - box_size ()) / 2)) + 1; if (start_line <= 0) diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h index 0bf43b6..6d4ad4e 100644 --- a/gdb/tui/tui-source.h +++ b/gdb/tui/tui-source.h @@ -46,7 +46,7 @@ struct tui_source_window : public tui_source_window_base bool showing_source_p (const char *filename) const; - void maybe_update (frame_info_ptr fi, symtab_and_line sal) override; + void maybe_update (const frame_info_ptr &fi, symtab_and_line sal) override; void erase_source_content () override { diff --git a/gdb/tui/tui-status.c b/gdb/tui/tui-status.c index df4675f..aac391d 100644 --- a/gdb/tui/tui-status.c +++ b/gdb/tui/tui-status.c @@ -213,7 +213,7 @@ tui_status_window::make_status_line () const name is demangled if demangling is turned on. Returns a pointer to a static area holding the result. */ static char* -tui_get_function_from_frame (frame_info_ptr fi) +tui_get_function_from_frame (const frame_info_ptr &fi) { static char name[256]; string_file stream; @@ -267,7 +267,7 @@ tui_status_window::rerender () refresh. */ void -tui_show_frame_info (frame_info_ptr fi) +tui_show_frame_info (const frame_info_ptr &fi) { bool status_changed_p; diff --git a/gdb/tui/tui-status.h b/gdb/tui/tui-status.h index efef537..0af4466 100644 --- a/gdb/tui/tui-status.h +++ b/gdb/tui/tui-status.h @@ -51,6 +51,6 @@ private: }; extern void tui_show_status_content (void); -extern void tui_show_frame_info (frame_info_ptr); +extern void tui_show_frame_info (const frame_info_ptr &); #endif /* TUI_TUI_STATUS_H */ diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h index 628fc22..6465973 100644 --- a/gdb/tui/tui-winsource.h +++ b/gdb/tui/tui-winsource.h @@ -159,7 +159,7 @@ public: /* Update the window to display the given location. Does nothing if the location is already displayed. */ - virtual void maybe_update (frame_info_ptr fi, symtab_and_line sal) = 0; + virtual void maybe_update (const frame_info_ptr &fi, symtab_and_line sal) = 0; void update_source_window_as_is (struct gdbarch *gdbarch, const struct symtab_and_line &sal); -- cgit v1.1