GDB (xrefs)
Loading...
Searching...
No Matches
gdb
tui
tui-interp.c
Go to the documentation of this file.
1
/* TUI Interpreter definitions for GDB, the GNU debugger.
2
3
Copyright (C) 2003-2023 Free Software Foundation, Inc.
4
5
This file is part of GDB.
6
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 3 of the License, or
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20
#include "
defs.h
"
21
#include "
cli/cli-interp.h
"
22
#include "
interps.h
"
23
#include "
ui.h
"
24
#include "
event-top.h
"
25
#include "gdbsupport/event-loop.h"
26
#include "
ui-out.h
"
27
#include "
cli-out.h
"
28
#include "
tui/tui-data.h
"
29
#include "
tui/tui-win.h
"
30
#include "
tui/tui.h
"
31
#include "
tui/tui-io.h
"
32
#include "
infrun.h
"
33
#include "
observable.h
"
34
#include "
gdbthread.h
"
35
#include "
inferior.h
"
36
#include "
main.h
"
37
38
/* Set to true when the TUI mode must be activated when we first start
39
gdb. */
40
static
bool
tui_start_enabled
=
false
;
41
42
class
tui_interp
final :
public
cli_interp_base
43
{
44
public
:
45
explicit
tui_interp
(
const
char
*
name
)
46
:
cli_interp_base
(
name
)
47
{}
48
49
void
init
(
bool
top_level)
override
;
50
void
resume
()
override
;
51
void
suspend
()
override
;
52
void
exec
(
const
char
*command_str)
override
;
53
ui_out
*
interp_ui_out
()
override
;
54
};
55
56
/* Cleanup the tui before exiting. */
57
58
static
void
59
tui_exit
(
void
)
60
{
61
/* Disable the tui. Curses mode is left leaving the screen in a
62
clean state (see endwin()). */
63
tui_disable
();
64
}
65
66
/* These implement the TUI interpreter. */
67
68
void
69
tui_interp::init
(
bool
top_level)
70
{
71
/* Install exit handler to leave the screen in a good shape. */
72
atexit (
tui_exit
);
73
74
tui_initialize_io
();
75
if
(
gdb_stdout
->isatty ())
76
{
77
tui_ensure_readline_initialized
();
78
79
/* This installs the SIGWINCH signal handler. The handler needs to do
80
readline calls (to rl_resize_terminal), so it must not be installed
81
unless readline is properly initialized. */
82
tui_initialize_win
();
83
}
84
}
85
86
/* Used as the command handler for the tui. */
87
88
static
void
89
tui_command_line_handler
(gdb::unique_xmalloc_ptr<char> &&rl)
90
{
91
/* When a tui enabled GDB is running in either tui mode or cli mode then
92
it is always the tui interpreter that is in use. As a result we end
93
up in here even in standard cli mode.
94
95
We only need to do any special actions when the tui is in use
96
though. When the tui is active the users return is not echoed to the
97
screen as a result the display will not automatically move us to the
98
next line. Here we manually insert a newline character and move the
99
cursor. */
100
if
(
tui_active
)
101
tui_inject_newline_into_command_window
();
102
103
/* Now perform GDB's standard CLI command line handling. */
104
command_line_handler
(std::move (rl));
105
}
106
107
void
108
tui_interp::resume
()
109
{
110
struct
ui
*
ui
=
current_ui
;
111
struct
ui_file
*stream;
112
113
/* gdb_setup_readline will change gdb_stdout. If the TUI was
114
previously writing to gdb_stdout, then set it to the new
115
gdb_stdout afterwards. */
116
117
stream =
tui_old_uiout
->
set_stream
(
gdb_stdout
);
118
if
(stream !=
gdb_stdout
)
119
{
120
tui_old_uiout
->
set_stream
(stream);
121
stream = NULL;
122
}
123
124
gdb_setup_readline
(1);
125
126
ui
->
input_handler
=
tui_command_line_handler
;
127
128
if
(stream != NULL)
129
tui_old_uiout
->
set_stream
(
gdb_stdout
);
130
131
if
(
tui_start_enabled
)
132
tui_enable
();
133
}
134
135
void
136
tui_interp::suspend
()
137
{
138
gdb_disable_readline
();
139
tui_start_enabled
=
tui_active
;
140
tui_disable
();
141
}
142
143
ui_out
*
144
tui_interp::interp_ui_out
()
145
{
146
if
(
tui_active
)
147
return
tui_out
;
148
else
149
return
tui_old_uiout
;
150
}
151
152
void
153
tui_interp::exec
(
const
char
*command_str)
154
{
155
internal_error (_(
"tui_exec called"
));
156
}
157
158
159
/* Factory for TUI interpreters. */
160
161
static
struct
interp
*
162
tui_interp_factory
(
const
char
*
name
)
163
{
164
return
new
tui_interp
(
name
);
165
}
166
167
void
_initialize_tui_interp
();
168
void
169
_initialize_tui_interp
()
170
{
171
interp_factory_register
(
INTERP_TUI
,
tui_interp_factory
);
172
173
if
(
interpreter_p
==
INTERP_TUI
)
174
tui_start_enabled
=
true
;
175
176
if
(
interpreter_p
==
INTERP_CONSOLE
)
177
interpreter_p
=
INTERP_TUI
;
178
179
/* There are no observers here because the CLI interpreter's
180
observers work for the TUI interpreter as well. See
181
cli-interp.c. */
182
}
name
const char *const name
Definition
aarch64-tdep.c:75
cli_interp_base
Definition
cli-interp.h:26
cli_ui_out::set_stream
ui_file * set_stream(ui_file *stream)
Definition
cli-out.c:446
interp
Definition
interps.h:51
interp::name
const char * name() const
Definition
interps.h:87
tui_interp
Definition
tui-interp.c:43
tui_interp::tui_interp
tui_interp(const char *name)
Definition
tui-interp.c:45
tui_interp::init
void init(bool top_level) override
Definition
tui-interp.c:69
tui_interp::suspend
void suspend() override
Definition
tui-interp.c:136
tui_interp::resume
void resume() override
Definition
tui-interp.c:108
tui_interp::interp_ui_out
ui_out * interp_ui_out() override
Definition
tui-interp.c:144
tui_interp::exec
void exec(const char *command_str) override
Definition
tui-interp.c:153
ui_file
Definition
ui-file.h:28
ui_out
Definition
ui-out.h:160
cli-interp.h
cli-out.h
defs.h
gdb_setup_readline
void gdb_setup_readline(int editing)
Definition
event-top.c:1278
gdb_disable_readline
void gdb_disable_readline(void)
Definition
event-top.c:1319
command_line_handler
void command_line_handler(gdb::unique_xmalloc_ptr< char > &&rl)
Definition
event-top.c:717
event-top.h
gdbthread.h
inferior.h
infrun.h
interp_factory_register
void interp_factory_register(const char *name, interp_factory_func func)
Definition
interps.c:78
interps.h
INTERP_CONSOLE
#define INTERP_CONSOLE
Definition
interps.h:367
INTERP_TUI
#define INTERP_TUI
Definition
interps.h:372
interpreter_p
std::string interpreter_p
Definition
main.c:61
main.h
observable.h
ui
Definition
ui.h:55
ui::input_handler
void(* input_handler)(gdb::unique_xmalloc_ptr< char > &&)
Definition
ui.h:82
tui-data.h
tui_start_enabled
static bool tui_start_enabled
Definition
tui-interp.c:40
tui_command_line_handler
static void tui_command_line_handler(gdb::unique_xmalloc_ptr< char > &&rl)
Definition
tui-interp.c:89
_initialize_tui_interp
void _initialize_tui_interp()
Definition
tui-interp.c:169
tui_interp_factory
static struct interp * tui_interp_factory(const char *name)
Definition
tui-interp.c:162
tui_exit
static void tui_exit(void)
Definition
tui-interp.c:59
tui_initialize_io
void tui_initialize_io(void)
Definition
tui-io.c:910
tui_out
struct ui_out * tui_out
Definition
tui-io.c:115
tui_old_uiout
cli_ui_out * tui_old_uiout
Definition
tui-io.c:121
tui_inject_newline_into_command_window
void tui_inject_newline_into_command_window()
Definition
tui-io.c:1048
tui-io.h
tui_initialize_win
void tui_initialize_win(void)
Definition
tui-win.c:581
tui-win.h
tui_disable
void tui_disable(void)
Definition
tui.c:523
tui_ensure_readline_initialized
void tui_ensure_readline_initialized()
Definition
tui.c:294
tui_enable
void tui_enable(void)
Definition
tui.c:381
tui_active
bool tui_active
Definition
tui.c:73
tui.h
ui-out.h
current_ui
struct ui * current_ui
Definition
ui.c:35
ui.h
gdb_stdout
#define gdb_stdout
Definition
utils.h:182
Generated by
1.10.0