[2/3] Pass inferior to terminal_inferior

Message ID 20181016033835.17594-2-simon.marchi@polymtl.ca
State New
Headers show
Series
  • [1/3] Pass inferior to terminal_save_inferior
Related show

Commit Message

Simon Marchi Oct. 16, 2018, 3:38 a.m.
Same as the previous patch, but for the terminal_inferior method.

gdb/ChangeLog:

	* target.h (struct target_ops) <terminal_inferior>: Add inferior
	pointer parameter.
	* target.c (target_terminal::inferior): Pass inferior to
	terminal_inferior.
	* target-delegates.c: Re-generate.
	* inf-child.h (inf_child_target) <terminal_inferior>: Add
	inferior pointer parameter.
	* inf-child.c (inf_child_target::terminal_inferior): Likewise.
	* inferior.h (child_terminal_inferior): Likewise.
	* inflow.c (child_terminal_inferior): Likewise.
	* remote.c (struct remote_target) <terminal_inferior>: Likewise.
	(remote_target::terminal_inferior): Likewise.
---
 gdb/inf-child.c        |  4 ++--
 gdb/inf-child.h        |  2 +-
 gdb/inferior.h         |  2 +-
 gdb/inflow.c           |  3 +--
 gdb/remote.c           |  4 ++--
 gdb/target-delegates.c | 15 ++++++++-------
 gdb/target.c           |  5 ++---
 gdb/target.h           |  9 ++++++++-
 8 files changed, 25 insertions(+), 19 deletions(-)

-- 
2.19.1

Comments

Pedro Alves Oct. 22, 2018, 8:54 p.m. | #1
On 10/16/2018 04:38 AM, Simon Marchi wrote:

> diff --git a/gdb/target.h b/gdb/target.h

> index c37405205a0a..310c942bbe5b 100644

> --- a/gdb/target.h

> +++ b/gdb/target.h

> @@ -581,7 +581,14 @@ struct target_ops

>        TARGET_DEFAULT_RETURN (false);

>      virtual void terminal_init ()

>        TARGET_DEFAULT_IGNORE ();

> -    virtual void terminal_inferior ()

> +

> +    /* If INF shares a terminal with GDB, restore the saved terminal settings

> +       associated to INF (see terminal_save_inferior) to the current

> +       terminal.  In a scenario where multiple inferiors share GDB's terminal,

> +       don't apply the settings of another inferior's settings are currently


s/of/if/.

> +       applied (in other words, the first inferior's settings win and should not

> +       be overwritten).  */


> +    virtual void terminal_inferior (inferior *inf)

>        TARGET_DEFAULT_IGNORE ();

>  

>      /* If INF shares a terminal with GDB, save the current terminal settings

> 


OK.

Thanks,
Pedro Alves
Simon Marchi Oct. 23, 2018, 9:14 a.m. | #2
On 2018-10-22 16:54, Pedro Alves wrote:
> On 10/16/2018 04:38 AM, Simon Marchi wrote:

> 

>> diff --git a/gdb/target.h b/gdb/target.h

>> index c37405205a0a..310c942bbe5b 100644

>> --- a/gdb/target.h

>> +++ b/gdb/target.h

>> @@ -581,7 +581,14 @@ struct target_ops

>>        TARGET_DEFAULT_RETURN (false);

>>      virtual void terminal_init ()

>>        TARGET_DEFAULT_IGNORE ();

>> -    virtual void terminal_inferior ()

>> +

>> +    /* If INF shares a terminal with GDB, restore the saved terminal 

>> settings

>> +       associated to INF (see terminal_save_inferior) to the current

>> +       terminal.  In a scenario where multiple inferiors share GDB's 

>> terminal,

>> +       don't apply the settings of another inferior's settings are 

>> currently

> 

> s/of/if/.


Fixed.

>> +       applied (in other words, the first inferior's settings win and 

>> should not

>> +       be overwritten).  */

> 

>> +    virtual void terminal_inferior (inferior *inf)

>>        TARGET_DEFAULT_IGNORE ();

>> 

>>      /* If INF shares a terminal with GDB, save the current terminal 

>> settings

>> 

> 

> OK.


Thanks.

Simon

Patch

diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 94f42ec2adc0..f02720028211 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -108,9 +108,9 @@  inf_child_target::terminal_init ()
 }
 
 void
-inf_child_target::terminal_inferior ()
+inf_child_target::terminal_inferior (inferior *inf)
 {
-  child_terminal_inferior (this);
+  child_terminal_inferior (this, inf);
 }
 
 void
diff --git a/gdb/inf-child.h b/gdb/inf-child.h
index b0625391ebb2..c544ceaf520e 100644
--- a/gdb/inf-child.h
+++ b/gdb/inf-child.h
@@ -45,7 +45,7 @@  public:
 
   bool supports_terminal_ours () override;
   void terminal_init () override;
-  void terminal_inferior () override;
+  void terminal_inferior (inferior *inf) override;
   void terminal_save_inferior (inferior *inf) override;
   void terminal_ours_for_output () override;
   void terminal_ours () override;
diff --git a/gdb/inferior.h b/gdb/inferior.h
index d09263e34bef..badd82e17c35 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -152,7 +152,7 @@  extern void child_terminal_ours (struct target_ops *self);
 
 extern void child_terminal_ours_for_output (struct target_ops *self);
 
-extern void child_terminal_inferior (struct target_ops *self);
+extern void child_terminal_inferior (struct target_ops *self, inferior *inf);
 
 extern void child_terminal_save_inferior (struct target_ops *self,
 					  inferior *inf);
diff --git a/gdb/inflow.c b/gdb/inflow.c
index 372ef7844f01..e355f4aa9fc5 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -342,7 +342,7 @@  sharing_input_terminal (inferior *inf)
    preparation for starting or resuming the inferior.  */
 
 void
-child_terminal_inferior (struct target_ops *self)
+child_terminal_inferior (struct target_ops *self, inferior *inf)
 {
   /* If we resume more than one inferior in the foreground on GDB's
      terminal, then the first inferior's terminal settings "win".
@@ -353,7 +353,6 @@  child_terminal_inferior (struct target_ops *self)
   if (gdb_tty_state == target_terminal_state::is_inferior)
     return;
 
-  inferior *inf = current_inferior ();
   terminal_info *tinfo = get_inflow_inferior_data (inf);
 
   if (gdb_has_a_terminal ()
diff --git a/gdb/remote.c b/gdb/remote.c
index c53553af5bda..268cce84afa8 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -557,7 +557,7 @@  public:
 
   int can_do_single_step () override;
 
-  void terminal_inferior () override;
+  void terminal_inferior (inferior *inf) override;
 
   void terminal_ours () override;
 
@@ -6812,7 +6812,7 @@  remote_target::interrupt_query ()
    is required.  */
 
 void
-remote_target::terminal_inferior ()
+remote_target::terminal_inferior (inferior *inf)
 {
   /* NOTE: At this point we could also register our selves as the
      recipient of all input.  Any characters typed could then be
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index f2b352c44888..1d1bd0ae4234 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -44,7 +44,7 @@  struct dummy_target : public target_ops
   int can_do_single_step () override;
   bool supports_terminal_ours () override;
   void terminal_init () override;
-  void terminal_inferior () override;
+  void terminal_inferior (inferior *arg0) override;
   void terminal_save_inferior (inferior *arg0) override;
   void terminal_ours_for_output () override;
   void terminal_ours () override;
@@ -211,7 +211,7 @@  struct debug_target : public target_ops
   int can_do_single_step () override;
   bool supports_terminal_ours () override;
   void terminal_init () override;
-  void terminal_inferior () override;
+  void terminal_inferior (inferior *arg0) override;
   void terminal_save_inferior (inferior *arg0) override;
   void terminal_ours_for_output () override;
   void terminal_ours () override;
@@ -1229,22 +1229,23 @@  debug_target::terminal_init ()
 }
 
 void
-target_ops::terminal_inferior ()
+target_ops::terminal_inferior (inferior *arg0)
 {
-  this->beneath ()->terminal_inferior ();
+  this->beneath ()->terminal_inferior (arg0);
 }
 
 void
-dummy_target::terminal_inferior ()
+dummy_target::terminal_inferior (inferior *arg0)
 {
 }
 
 void
-debug_target::terminal_inferior ()
+debug_target::terminal_inferior (inferior *arg0)
 {
   fprintf_unfiltered (gdb_stdlog, "-> %s->terminal_inferior (...)\n", this->beneath ()->shortname ());
-  this->beneath ()->terminal_inferior ();
+  this->beneath ()->terminal_inferior (arg0);
   fprintf_unfiltered (gdb_stdlog, "<- %s->terminal_inferior (", this->beneath ()->shortname ());
+  target_debug_print_inferior_p (arg0);
   fputs_unfiltered (")\n", gdb_stdlog);
 }
 
diff --git a/gdb/target.c b/gdb/target.c
index 93d16b90f179..631b2c3b0f12 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -444,7 +444,7 @@  target_terminal::inferior (void)
 
   if (inf->terminal_state != target_terminal_state::is_inferior)
     {
-      current_top_target ()->terminal_inferior ();
+      current_top_target ()->terminal_inferior (inf);
       inf->terminal_state = target_terminal_state::is_inferior;
     }
 
@@ -479,8 +479,7 @@  target_terminal::restore_inferior (void)
       {
 	if (inf->terminal_state == target_terminal_state::is_ours_for_output)
 	  {
-	    set_current_inferior (inf);
-	    current_top_target ()->terminal_inferior ();
+	    current_top_target ()->terminal_inferior (inf);
 	    inf->terminal_state = target_terminal_state::is_inferior;
 	  }
       }
diff --git a/gdb/target.h b/gdb/target.h
index c37405205a0a..310c942bbe5b 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -581,7 +581,14 @@  struct target_ops
       TARGET_DEFAULT_RETURN (false);
     virtual void terminal_init ()
       TARGET_DEFAULT_IGNORE ();
-    virtual void terminal_inferior ()
+
+    /* If INF shares a terminal with GDB, restore the saved terminal settings
+       associated to INF (see terminal_save_inferior) to the current
+       terminal.  In a scenario where multiple inferiors share GDB's terminal,
+       don't apply the settings of another inferior's settings are currently
+       applied (in other words, the first inferior's settings win and should not
+       be overwritten).  */
+    virtual void terminal_inferior (inferior *inf)
       TARGET_DEFAULT_IGNORE ();
 
     /* If INF shares a terminal with GDB, save the current terminal settings