[PATCHv2,17,1/2] gdb: rename scoped_gdb_tty_state, and make it non-copyable

Message ID b700e887a5f618e3f4c67b3fb081deeb4952e14c.1765615940.git.aburgess@redhat.com
State New
Headers
Series Fixes for scoped_gdb_ttystate class |

Commit Message

Andrew Burgess Dec. 13, 2025, 8:53 a.m. UTC
  The scoped_gdb_tty_state class seems misnamed.  For save/restore type
classes the pattern in GDB is usually scoped_restore_<whatever>, so
lets rename this to scoped_restore_tty_state.  I dropped the 'gdb' part
of the name as the underlying functions being called are
serial_get_tty_state and serial_set_tty_state, so the new name
matches (I think) what's actually being called.

I've also made the class non-copyable like other scoped_restore_
classes.

There should be no user visible changes after this commit.
---
 gdb/cli/cli-cmds.c |  2 +-
 gdb/inflow.c       |  4 ++--
 gdb/terminal.h     | 11 +++++++----
 3 files changed, 10 insertions(+), 7 deletions(-)
  

Comments

Simon Marchi Dec. 15, 2025, 9:06 p.m. UTC | #1
On 12/13/25 3:53 AM, Andrew Burgess wrote:
> The scoped_gdb_tty_state class seems misnamed.  For save/restore type
> classes the pattern in GDB is usually scoped_restore_<whatever>, so
> lets rename this to scoped_restore_tty_state.  I dropped the 'gdb' part
> of the name as the underlying functions being called are
> serial_get_tty_state and serial_set_tty_state, so the new name
> matches (I think) what's actually being called.
> 
> I've also made the class non-copyable like other scoped_restore_
> classes.
> 
> There should be no user visible changes after this commit.

Thanks, I like it.  The class could be made moveable if ever needed, but
it's not needed currently.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  

Patch

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index cf5571c5419..0f048d4fc27 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -950,7 +950,7 @@  shell_escape (const char *arg, int from_tty)
 static void
 shell_command (const char *arg, int from_tty)
 {
-  scoped_gdb_ttystate save_restore_gdb_ttystate;
+  scoped_restore_tty_state save_restore_gdb_ttystate;
   restore_initial_gdb_ttystate ();
 
   shell_escape (arg, from_tty);
diff --git a/gdb/inflow.c b/gdb/inflow.c
index ccab019158a..518b2dcf4e0 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -57,14 +57,14 @@  static struct serial *stdin_serial;
 
 /* See terminal.h.  */
 
-scoped_gdb_ttystate::scoped_gdb_ttystate ()
+scoped_restore_tty_state::scoped_restore_tty_state ()
 {
   m_ttystate = serial_get_tty_state (stdin_serial);
 }
 
 /* See terminal.h.  */
 
-scoped_gdb_ttystate::~scoped_gdb_ttystate ()
+scoped_restore_tty_state::~scoped_restore_tty_state ()
 {
   serial_set_tty_state (stdin_serial, m_ttystate);
 }
diff --git a/gdb/terminal.h b/gdb/terminal.h
index 87a1aee37fb..225554a60c3 100644
--- a/gdb/terminal.h
+++ b/gdb/terminal.h
@@ -49,12 +49,15 @@  extern void set_initial_gdb_ttystate (void);
 extern void restore_initial_gdb_ttystate (void);
 
 /* An RAII-based object that saves the tty state, and then restores it again
-   when this object is destroyed. */
-class scoped_gdb_ttystate
+   when this object is destroyed.  */
+class scoped_restore_tty_state
 {
 public:
-  scoped_gdb_ttystate ();
-  ~scoped_gdb_ttystate ();
+  scoped_restore_tty_state ();
+  ~scoped_restore_tty_state ();
+
+  DISABLE_COPY_AND_ASSIGN (scoped_restore_tty_state);
+
 private:
   serial_ttystate m_ttystate;
 };