Skip to content

Commit 5842f62

Browse files
committed
Make common code handle target_terminal_* idempotency
I found a place that should be giving back the terminal to the target, but only if the target was already owning it. So I need to add a getter for who owns the terminal. The trouble is that several places/target have their own globals to track this state: - inflow.c:terminal_is_ours - remote.c:remote_async_terminal_ours_p - linux-nat.c:async_terminal_is_ours - go32-nat.c:terminal_is_ours While one might think of adding a new target_ops method to query this, conceptually, this state isn't really part of a particular target_ops. Considering multi-target, the core shouldn't have to ask all targets to know whether it's GDB that owns the terminal. There's only one GDB (or rather, only one top level interpreter). So what this comment does is add a new global that is tracked by the core instead. A subsequent pass may later remove the other globals. Tested on x86_64 Fedora 20, native and gdbserver. gdb/ 2014-10-17 Pedro Alves <[email protected]> * target.c (enum terminal_state): New enum. (terminal_state): New global. (target_terminal_init): New function. (target_terminal_inferior): Skip if inferior already owns the terminal. (target_terminal_ours, target_terminal_ours_for_output): New functions. * target.h (target_terminal_init): Convert to function prototype. (target_terminal_ours_for_output): Convert to function prototype and tweak comment. (target_terminal_ours): Convert to function prototype and tweak comment. * windows-nat.c (do_initial_windows_stuff): Call target_terminal_init instead of child_terminal_init_with_pgrp.
1 parent 3f73082 commit 5842f62

File tree

4 files changed

+81
-14
lines changed

4 files changed

+81
-14
lines changed

gdb/ChangeLog

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2014-10-17 Pedro Alves <[email protected]>
2+
3+
* target.c (enum terminal_state): New enum.
4+
(terminal_state): New global.
5+
(target_terminal_init): New function.
6+
(target_terminal_inferior): Skip if inferior already owns the
7+
terminal.
8+
(target_terminal_ours, target_terminal_ours_for_output): New
9+
functions.
10+
* target.h (target_terminal_init): Convert to function prototype.
11+
(target_terminal_ours_for_output): Convert to function prototype
12+
and tweak comment.
13+
(target_terminal_ours): Convert to function prototype and tweak
14+
comment.
15+
* windows-nat.c (do_initial_windows_stuff): Call
16+
target_terminal_init instead of child_terminal_init_with_pgrp.
17+
118
2014-10-17 Pedro Alves <[email protected]>
219

320
* Makefile.in (ALL_64_TARGET_OBS): Remove alpha-osf1-tdep.o.

gdb/target.c

+56
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,35 @@ target_load (const char *arg, int from_tty)
432432
(*current_target.to_load) (&current_target, arg, from_tty);
433433
}
434434

435+
/* Possible terminal states. */
436+
437+
enum terminal_state
438+
{
439+
/* The inferior's terminal settings are in effect. */
440+
terminal_is_inferior = 0,
441+
442+
/* Some of our terminal settings are in effect, enough to get
443+
proper output. */
444+
terminal_is_ours_for_output = 1,
445+
446+
/* Our terminal settings are in effect, for output and input. */
447+
terminal_is_ours = 2
448+
};
449+
450+
static enum terminal_state terminal_state;
451+
452+
/* See target.h. */
453+
454+
void
455+
target_terminal_init (void)
456+
{
457+
(*current_target.to_terminal_init) (&current_target);
458+
459+
terminal_state = terminal_is_ours;
460+
}
461+
462+
/* See target.h. */
463+
435464
void
436465
target_terminal_inferior (void)
437466
{
@@ -442,9 +471,36 @@ target_terminal_inferior (void)
442471
if (target_can_async_p () && !sync_execution)
443472
return;
444473

474+
if (terminal_state == terminal_is_inferior)
475+
return;
476+
445477
/* If GDB is resuming the inferior in the foreground, install
446478
inferior's terminal modes. */
447479
(*current_target.to_terminal_inferior) (&current_target);
480+
terminal_state = terminal_is_inferior;
481+
}
482+
483+
/* See target.h. */
484+
485+
void
486+
target_terminal_ours (void)
487+
{
488+
if (terminal_state == terminal_is_ours)
489+
return;
490+
491+
(*current_target.to_terminal_ours) (&current_target);
492+
terminal_state = terminal_is_ours;
493+
}
494+
495+
/* See target.h. */
496+
497+
void
498+
target_terminal_ours_for_output (void)
499+
{
500+
if (terminal_state != terminal_is_inferior)
501+
return;
502+
(*current_target.to_terminal_ours_for_output) (&current_target);
503+
terminal_state = terminal_is_ours_for_output;
448504
}
449505

450506
/* See target.h. */

gdb/target.h

+7-13
Original file line numberDiff line numberDiff line change
@@ -1383,31 +1383,25 @@ extern int target_remove_breakpoint (struct gdbarch *gdbarch,
13831383
/* Initialize the terminal settings we record for the inferior,
13841384
before we actually run the inferior. */
13851385

1386-
#define target_terminal_init() \
1387-
(*current_target.to_terminal_init) (&current_target)
1386+
extern void target_terminal_init (void);
13881387

13891388
/* Put the inferior's terminal settings into effect.
13901389
This is preparation for starting or resuming the inferior. */
13911390

13921391
extern void target_terminal_inferior (void);
13931392

1394-
/* Put some of our terminal settings into effect,
1395-
enough to get proper results from our output,
1396-
but do not change into or out of RAW mode
1397-
so that no input is discarded.
1393+
/* Put some of our terminal settings into effect, enough to get proper
1394+
results from our output, but do not change into or out of RAW mode
1395+
so that no input is discarded. This is a no-op if terminal_ours
1396+
was most recently called. */
13981397

1399-
After doing this, either terminal_ours or terminal_inferior
1400-
should be called to get back to a normal state of affairs. */
1401-
1402-
#define target_terminal_ours_for_output() \
1403-
(*current_target.to_terminal_ours_for_output) (&current_target)
1398+
extern void target_terminal_ours_for_output (void);
14041399

14051400
/* Put our terminal settings into effect.
14061401
First record the inferior's terminal settings
14071402
so they can be restored properly later. */
14081403

1409-
#define target_terminal_ours() \
1410-
(*current_target.to_terminal_ours) (&current_target)
1404+
extern void target_terminal_ours (void);
14111405

14121406
/* Return true if the target stack has a non-default
14131407
"to_terminal_ours" method. */

gdb/windows-nat.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
17411741
current thread until we report an event out of windows_wait. */
17421742
inferior_ptid = pid_to_ptid (pid);
17431743

1744-
child_terminal_init_with_pgrp (pid);
1744+
target_terminal_init ();
17451745
target_terminal_inferior ();
17461746

17471747
windows_initialization_done = 0;

0 commit comments

Comments
 (0)