Re: [PATCH 4/24] gdb: replace some so_list parameters to use references

Lancelot SIX
2023-10-19T11:08:21Z

[-- Attachment #1: Type: text/plain, Size: 3729 bytes --]

Hi Simon,

Some minor remarks below.

On Tue, Oct 10, 2023 at 04:39:59PM -0400, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
>
> A subsequent patch changes so_list to be linked using
> intrusive_list. Iterating an intrusive_list yields some references to
> the list elements. Convert some functions accepting so_list objects to
> take references, to make things easier and more natural. Add const
> where possible and convenient.
>
> Change-Id: Id5ab5339c3eb6432e809ad14782952d6a45806f3
> ---
> gdb/breakpoint.c | 5 +-
> gdb/bsd-uthread.c | 12 ++---
> gdb/exec.c | 4 +-
> gdb/interps.c | 4 +-
> gdb/interps.h | 8 +--
> gdb/mi/mi-cmd-file.c | 2 +-
> gdb/mi/mi-interp.c | 26 ++++-----
> gdb/mi/mi-interp.h | 6 +--
> gdb/nto-tdep.c | 6 +--
> gdb/nto-tdep.h | 3 +-
> gdb/observable.h | 5 +-
> gdb/progspace.h | 4 +-
> gdb/solib-aix.c | 11 ++--
> gdb/solib-darwin.c | 23 ++++----
> gdb/solib-dsbt.c | 9 ++--
> gdb/solib-frv.c | 9 ++--
> gdb/solib-rocm.c | 8 +--
> gdb/solib-svr4.c | 35 ++++++------
> gdb/solib-target.c | 49 +++++++++--------
> gdb/solib.c | 126 +++++++++++++++++++++----------------------
> gdb/solib.h | 4 +-
> gdb/solist.h | 13 +++--
> gdb/target-section.h | 2 +-
> 23 files changed, 183 insertions(+), 191 deletions(-)
>
> diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
> index f9af61f0a571..781a8dc6f466 100644
> --- a/gdb/mi/mi-interp.h
> +++ b/gdb/mi/mi-interp.h
> @@ -60,8 +60,8 @@ class mi_interp final : public interp
> void on_record_changed (inferior *inf, int started, const char *method,
> const char *format) override;
> void on_target_resumed (ptid_t ptid) override;
> - void on_solib_loaded (so_list *so) override;
> - void on_solib_unloaded (so_list *so) override;
> + void on_solib_loaded (const so_list &so) override;
> + void on_solib_unloaded (const so_list &so) override;

It is orthogonal to this change, but it would make sense for those
methods to be const as well.

Doing this requires interp::interp_ui_out to be const as well (as done
in attached patch).

> void on_about_to_proceed () override;
> void on_traceframe_changed (int tfnum, int tpnum) override;
> void on_tsv_created (const trace_state_variable *tsv) override;
> diff --git a/gdb/observable.h b/gdb/observable.h
> index acb05e9b535c..5ed6ca547ce0 100644
> --- a/gdb/observable.h
> +++ b/gdb/observable.h
> @@ -99,13 +99,12 @@ extern observable<inferior */* parent_inf */, inferior */* child_inf */,
> /* The shared library specified by SOLIB has been loaded. Note that
> when gdb calls this observer, the library's symbols probably
> haven't been loaded yet. */
> -extern observable<struct so_list */* solib */> solib_loaded;
> +extern observable<so_list &/* solib */> solib_loaded;

I am wondering, is there a reason to make the solib parameter const for
solib_unloaded but not for solib_loaded?

Changing it to const seems to still compile just fine. If down the line
an observer needs to modify the SO, the observer's signature can be
adjusted.

>
> /* The shared library SOLIB has been unloaded from program space PSPACE.
> Note when gdb calls this observer, the library's symbols have not
> been unloaded yet, and thus are still available. */
> -extern observable<struct program_space */* pspace */, struct so_list */* solib */>
> - solib_unloaded;
> +extern observable<program_space *, const so_list &/* solib */> solib_unloaded;
>
> /* The symbol file specified by OBJFILE has been loaded. */
> extern observable<struct objfile */* objfile */> new_objfile;

[-- Attachment #2: 0001-gdb-interp-Make-interp-interp_ui_out-const.patch --]
[-- Type: text/x-diff, Size: 3622 bytes --]

From 4e9158ca45ffc4e15c8c57a0df9f99ab49a35c0e Mon Sep 17 00:00:00 2001
From: Lancelot SIX <lancelot.six@amd.com>
Date: Thu, 19 Oct 2023 09:29:39 +0100
Subject: [PATCH] gdb/interp: Make interp::interp_ui_out const

The interp::interp_ui_out can be declared const. Make this change as it
will be used in a following patch.

Change-Id: I11844d36f44d369400049f916db94aca9f43be51
---
gdb/cli/cli-interp.c | 4 ++--
gdb/interps.h | 2 +-
gdb/mi/mi-interp.c | 2 +-
gdb/mi/mi-interp.h | 2 +-
gdb/python/py-dap.c | 2 +-
gdb/tui/tui-interp.c | 4 ++--
6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 829948b4993..21c78fd98a9 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -50,7 +50,7 @@ class cli_interp final : public cli_interp_base
void resume () override;
void suspend () override;
void exec (const char *command_str) override;
- ui_out *interp_ui_out () override;
+ ui_out *interp_ui_out () const override;

private:

@@ -255,7 +255,7 @@ cli_interp_base::supports_command_editing ()
}

ui_out *
-cli_interp::interp_ui_out ()
+cli_interp::interp_ui_out () const
{
return m_cli_uiout.get ();
}
diff --git a/gdb/interps.h b/gdb/interps.h
index 287df2c8c81..a3cbf32aa12 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -65,7 +65,7 @@ class interp : public intrusive_list_node<interp>
interpreter. It can be a formatter for stdout, as is the case
for the console & mi outputs, or it might be a result
formatter. */
- virtual ui_out *interp_ui_out () = 0;
+ virtual ui_out *interp_ui_out () const = 0;

/* Provides a hook for interpreters to do any additional
setup/cleanup that they might need when logging is enabled or
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 0d3c8235c2c..70075eed16b 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -875,7 +875,7 @@ mi_interp::on_user_selected_context_changed (user_selected_what selection)
}

ui_out *
-mi_interp::interp_ui_out ()
+mi_interp::interp_ui_out () const
{
return this->mi_uiout;
}
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index f9af61f0a57..ff3c439f1e3 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -37,7 +37,7 @@ class mi_interp final : public interp
void resume () override;
void suspend () override;
void exec (const char *command_str) override;
- ui_out *interp_ui_out () override;
+ ui_out *interp_ui_out () const override;
void set_logging (ui_file_up logfile, bool logging_redirect,
bool debug_redirect) override;
void pre_command_loop () override;
diff --git a/gdb/python/py-dap.c b/gdb/python/py-dap.c
index 3444eccb6fb..7a78e54571f 100644
--- a/gdb/python/py-dap.c
+++ b/gdb/python/py-dap.c
@@ -56,7 +56,7 @@ class dap_interp final : public interp
/* Just ignore it. */
}

- ui_out *interp_ui_out () override
+ ui_out *interp_ui_out () const override
{
return m_ui_out.get ();
}
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 299cc4caea0..a88162c08e1 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -50,7 +50,7 @@ class tui_interp final : public cli_interp_base
void resume () override;
void suspend () override;
void exec (const char *command_str) override;
- ui_out *interp_ui_out () override;
+ ui_out *interp_ui_out () const override;
};

/* Cleanup the tui before exiting. */
@@ -141,7 +141,7 @@ tui_interp::suspend ()
}

ui_out *
-tui_interp::interp_ui_out ()
+tui_interp::interp_ui_out () const
{
if (tui_active)
return tui_out;

--
2.34.1