Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI layout window management. |
f33c6cbf | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 | 5 | Contributed by Hewlett-Packard Company. |
c906108c | 6 | |
f377b406 SC |
7 | This file is part of GDB. |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
957b8b5a | 23 | #include "arch-utils.h" |
c906108c SS |
24 | #include "command.h" |
25 | #include "symtab.h" | |
26 | #include "frame.h" | |
52575520 | 27 | #include "source.h" |
84b1e7c7 | 28 | #include <ctype.h> |
c906108c | 29 | |
d7b2e967 AC |
30 | #include "tui/tui.h" |
31 | #include "tui/tui-data.h" | |
32 | #include "tui/tui-windata.h" | |
33 | #include "tui/tui-wingeneral.h" | |
34 | #include "tui/tui-stack.h" | |
35 | #include "tui/tui-regs.h" | |
36 | #include "tui/tui-win.h" | |
37 | #include "tui/tui-winsource.h" | |
38 | #include "tui/tui-disasm.h" | |
2c0b251b | 39 | #include "tui/tui-layout.h" |
6a83354a | 40 | #include "gdb_curses.h" |
96ec9981 | 41 | |
c906108c SS |
42 | /******************************* |
43 | ** Static Local Decls | |
44 | ********************************/ | |
6ba8e26f | 45 | static void show_layout (enum tui_layout_type); |
d6ba6a11 TT |
46 | static tui_gen_win_info *init_and_make_win (tui_gen_win_info *, |
47 | enum tui_win_type, | |
17374de4 TT |
48 | int, int, int, int, |
49 | enum tui_box); | |
6ba8e26f | 50 | static void show_source_or_disasm_and_command (enum tui_layout_type); |
0ed69eda TT |
51 | static struct tui_win_info *make_source_or_disasm_window (enum tui_win_type, |
52 | int, int); | |
82432e10 | 53 | static struct tui_win_info *make_command_window (int, int); |
0ed69eda TT |
54 | static struct tui_win_info *make_source_window (int, int); |
55 | static struct tui_win_info *make_disasm_window (int, int); | |
5b6fe301 | 56 | static void make_data_window (struct tui_win_info **, int, int); |
6ba8e26f AC |
57 | static void show_source_command (void); |
58 | static void show_disasm_command (void); | |
59 | static void show_source_disasm_command (void); | |
60 | static void show_data (enum tui_layout_type); | |
61 | static enum tui_layout_type next_layout (void); | |
62 | static enum tui_layout_type prev_layout (void); | |
0b39b52e | 63 | static void tui_layout_command (const char *, int); |
13274fc3 | 64 | static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *); |
c906108c SS |
65 | |
66 | ||
67 | /*************************************** | |
68 | ** DEFINITIONS | |
69 | ***************************************/ | |
70 | ||
71 | #define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n" | |
72 | ||
c7037be1 SC |
73 | /* Show the screen layout defined. */ |
74 | static void | |
6ba8e26f | 75 | show_layout (enum tui_layout_type layout) |
c906108c | 76 | { |
6ba8e26f | 77 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 78 | |
6ba8e26f | 79 | if (layout != cur_layout) |
c906108c | 80 | { |
ef5eab5a MS |
81 | /* Since the new layout may cause changes in window size, we |
82 | should free the content and reallocate on next display of | |
83 | source/asm. */ | |
dd1abb8c AC |
84 | tui_free_all_source_wins_content (); |
85 | tui_clear_source_windows (); | |
e5908723 MS |
86 | if (layout == SRC_DATA_COMMAND |
87 | || layout == DISASSEM_DATA_COMMAND) | |
c906108c | 88 | { |
6ba8e26f | 89 | show_data (layout); |
6d012f14 | 90 | tui_refresh_all (tui_win_list); |
c906108c SS |
91 | } |
92 | else | |
93 | { | |
1cc6d956 | 94 | /* First make the current layout be invisible. */ |
ec7d9e56 | 95 | tui_make_all_invisible (); |
dd1abb8c | 96 | tui_make_invisible (tui_locator_win_info_ptr ()); |
c906108c SS |
97 | |
98 | switch (layout) | |
99 | { | |
1cc6d956 | 100 | /* Now show the new layout. */ |
c906108c | 101 | case SRC_COMMAND: |
6ba8e26f | 102 | show_source_command (); |
6d012f14 | 103 | tui_add_to_source_windows (TUI_SRC_WIN); |
c906108c SS |
104 | break; |
105 | case DISASSEM_COMMAND: | |
6ba8e26f | 106 | show_disasm_command (); |
6d012f14 | 107 | tui_add_to_source_windows (TUI_DISASM_WIN); |
c906108c SS |
108 | break; |
109 | case SRC_DISASSEM_COMMAND: | |
6ba8e26f | 110 | show_source_disasm_command (); |
6d012f14 AC |
111 | tui_add_to_source_windows (TUI_SRC_WIN); |
112 | tui_add_to_source_windows (TUI_DISASM_WIN); | |
c906108c SS |
113 | break; |
114 | default: | |
115 | break; | |
116 | } | |
117 | } | |
118 | } | |
bc712bbf | 119 | } |
c906108c SS |
120 | |
121 | ||
080ce8c0 | 122 | /* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND, |
7bd0be3a | 123 | SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND. */ |
080ce8c0 | 124 | enum tui_status |
7bd0be3a | 125 | tui_set_layout (enum tui_layout_type layout_type) |
c906108c | 126 | { |
22940a24 | 127 | enum tui_status status = TUI_SUCCESS; |
c906108c | 128 | |
7bd0be3a | 129 | if (layout_type != UNDEFINED_LAYOUT) |
c906108c | 130 | { |
e5908723 MS |
131 | enum tui_layout_type cur_layout = tui_current_layout (), |
132 | new_layout = UNDEFINED_LAYOUT; | |
6ba8e26f | 133 | int regs_populate = FALSE; |
13274fc3 UW |
134 | struct gdbarch *gdbarch; |
135 | CORE_ADDR addr; | |
5b6fe301 MS |
136 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
137 | struct tui_layout_def *layout_def = tui_layout_def (); | |
c906108c | 138 | |
13274fc3 | 139 | extract_display_start_addr (&gdbarch, &addr); |
c906108c | 140 | |
7bd0be3a | 141 | new_layout = layout_type; |
c906108c | 142 | |
7bd0be3a AB |
143 | regs_populate = (new_layout == SRC_DATA_COMMAND |
144 | || new_layout == DISASSEM_DATA_COMMAND); | |
145 | if (new_layout != cur_layout) | |
c906108c | 146 | { |
7bd0be3a | 147 | show_layout (new_layout); |
ef5eab5a | 148 | |
7bd0be3a AB |
149 | /* Now determine where focus should be. */ |
150 | if (win_with_focus != TUI_CMD_WIN) | |
151 | { | |
152 | switch (new_layout) | |
c906108c | 153 | { |
7bd0be3a AB |
154 | case SRC_COMMAND: |
155 | tui_set_win_focus_to (TUI_SRC_WIN); | |
156 | layout_def->display_mode = SRC_WIN; | |
157 | layout_def->split = FALSE; | |
158 | break; | |
159 | case DISASSEM_COMMAND: | |
160 | /* The previous layout was not showing code. | |
161 | This can happen if there is no source | |
162 | available: | |
163 | ||
164 | 1. if the source file is in another dir OR | |
165 | 2. if target was compiled without -g | |
166 | We still want to show the assembly though! */ | |
167 | ||
168 | tui_get_begin_asm_address (&gdbarch, &addr); | |
169 | tui_set_win_focus_to (TUI_DISASM_WIN); | |
170 | layout_def->display_mode = DISASSEM_WIN; | |
171 | layout_def->split = FALSE; | |
172 | break; | |
173 | case SRC_DISASSEM_COMMAND: | |
174 | /* The previous layout was not showing code. | |
175 | This can happen if there is no source | |
176 | available: | |
177 | ||
178 | 1. if the source file is in another dir OR | |
179 | 2. if target was compiled without -g | |
180 | We still want to show the assembly though! */ | |
181 | ||
182 | tui_get_begin_asm_address (&gdbarch, &addr); | |
183 | if (win_with_focus == TUI_SRC_WIN) | |
184 | tui_set_win_focus_to (TUI_SRC_WIN); | |
185 | else | |
186 | tui_set_win_focus_to (TUI_DISASM_WIN); | |
187 | layout_def->split = TRUE; | |
188 | break; | |
189 | case SRC_DATA_COMMAND: | |
190 | if (win_with_focus != TUI_DATA_WIN) | |
191 | tui_set_win_focus_to (TUI_SRC_WIN); | |
192 | else | |
193 | tui_set_win_focus_to (TUI_DATA_WIN); | |
194 | layout_def->display_mode = SRC_WIN; | |
195 | layout_def->split = FALSE; | |
196 | break; | |
197 | case DISASSEM_DATA_COMMAND: | |
198 | /* The previous layout was not showing code. | |
199 | This can happen if there is no source | |
200 | available: | |
201 | ||
202 | 1. if the source file is in another dir OR | |
203 | 2. if target was compiled without -g | |
204 | We still want to show the assembly though! */ | |
205 | ||
206 | tui_get_begin_asm_address (&gdbarch, &addr); | |
207 | if (win_with_focus != TUI_DATA_WIN) | |
208 | tui_set_win_focus_to (TUI_DISASM_WIN); | |
209 | else | |
210 | tui_set_win_focus_to (TUI_DATA_WIN); | |
211 | layout_def->display_mode = DISASSEM_WIN; | |
212 | layout_def->split = FALSE; | |
213 | break; | |
214 | default: | |
215 | break; | |
c906108c | 216 | } |
c906108c | 217 | } |
7bd0be3a AB |
218 | /* |
219 | * Now update the window content. | |
220 | */ | |
221 | if (!regs_populate | |
222 | && (new_layout == SRC_DATA_COMMAND | |
223 | || new_layout == DISASSEM_DATA_COMMAND)) | |
224 | tui_display_all_data (); | |
225 | ||
226 | tui_update_source_windows_with_addr (gdbarch, addr); | |
227 | ||
6ba8e26f | 228 | if (regs_populate) |
238eb706 | 229 | tui_show_registers (TUI_DATA_WIN->current_group); |
c906108c SS |
230 | } |
231 | } | |
232 | else | |
233 | status = TUI_FAILURE; | |
234 | ||
235 | return status; | |
bc712bbf | 236 | } |
c906108c | 237 | |
080ce8c0 AC |
238 | /* Add the specified window to the layout in a logical way. This |
239 | means setting up the most logical layout given the window to be | |
240 | added. */ | |
c906108c | 241 | void |
080ce8c0 | 242 | tui_add_win_to_layout (enum tui_win_type type) |
c906108c | 243 | { |
6ba8e26f | 244 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c SS |
245 | |
246 | switch (type) | |
247 | { | |
248 | case SRC_WIN: | |
e5908723 MS |
249 | if (cur_layout != SRC_COMMAND |
250 | && cur_layout != SRC_DISASSEM_COMMAND | |
251 | && cur_layout != SRC_DATA_COMMAND) | |
c906108c | 252 | { |
dd1abb8c | 253 | tui_clear_source_windows_detail (); |
6ba8e26f AC |
254 | if (cur_layout == DISASSEM_DATA_COMMAND) |
255 | show_layout (SRC_DATA_COMMAND); | |
c906108c | 256 | else |
6ba8e26f | 257 | show_layout (SRC_COMMAND); |
c906108c SS |
258 | } |
259 | break; | |
260 | case DISASSEM_WIN: | |
e5908723 MS |
261 | if (cur_layout != DISASSEM_COMMAND |
262 | && cur_layout != SRC_DISASSEM_COMMAND | |
263 | && cur_layout != DISASSEM_DATA_COMMAND) | |
c906108c | 264 | { |
dd1abb8c | 265 | tui_clear_source_windows_detail (); |
6ba8e26f AC |
266 | if (cur_layout == SRC_DATA_COMMAND) |
267 | show_layout (DISASSEM_DATA_COMMAND); | |
c906108c | 268 | else |
6ba8e26f | 269 | show_layout (DISASSEM_COMMAND); |
c906108c SS |
270 | } |
271 | break; | |
272 | case DATA_WIN: | |
e5908723 MS |
273 | if (cur_layout != SRC_DATA_COMMAND |
274 | && cur_layout != DISASSEM_DATA_COMMAND) | |
c906108c | 275 | { |
6ba8e26f AC |
276 | if (cur_layout == DISASSEM_COMMAND) |
277 | show_layout (DISASSEM_DATA_COMMAND); | |
c906108c | 278 | else |
6ba8e26f | 279 | show_layout (SRC_DATA_COMMAND); |
c906108c SS |
280 | } |
281 | break; | |
282 | default: | |
283 | break; | |
284 | } | |
6ba8e26f | 285 | } |
c906108c SS |
286 | |
287 | ||
6ba8e26f AC |
288 | /* Answer the height of a window. If it hasn't been created yet, |
289 | answer what the height of a window would be based upon its type and | |
290 | the layout. */ | |
c906108c | 291 | int |
08ef48c5 MS |
292 | tui_default_win_height (enum tui_win_type type, |
293 | enum tui_layout_type layout) | |
c906108c SS |
294 | { |
295 | int h; | |
296 | ||
cafb3438 | 297 | if (tui_win_list[type] != NULL) |
cb2ce893 | 298 | h = tui_win_list[type]->height; |
c906108c SS |
299 | else |
300 | { | |
301 | switch (layout) | |
302 | { | |
303 | case SRC_COMMAND: | |
304 | case DISASSEM_COMMAND: | |
6d012f14 | 305 | if (TUI_CMD_WIN == NULL) |
dd1abb8c | 306 | h = tui_term_height () / 2; |
c906108c | 307 | else |
cb2ce893 | 308 | h = tui_term_height () - TUI_CMD_WIN->height; |
c906108c SS |
309 | break; |
310 | case SRC_DISASSEM_COMMAND: | |
311 | case SRC_DATA_COMMAND: | |
312 | case DISASSEM_DATA_COMMAND: | |
6d012f14 | 313 | if (TUI_CMD_WIN == NULL) |
dd1abb8c | 314 | h = tui_term_height () / 3; |
c906108c | 315 | else |
cb2ce893 | 316 | h = (tui_term_height () - TUI_CMD_WIN->height) / 2; |
c906108c SS |
317 | break; |
318 | default: | |
319 | h = 0; | |
320 | break; | |
321 | } | |
322 | } | |
323 | ||
324 | return h; | |
6ba8e26f | 325 | } |
c906108c SS |
326 | |
327 | ||
080ce8c0 AC |
328 | /* Answer the height of a window. If it hasn't been created yet, |
329 | answer what the height of a window would be based upon its type and | |
330 | the layout. */ | |
c906108c | 331 | int |
080ce8c0 AC |
332 | tui_default_win_viewport_height (enum tui_win_type type, |
333 | enum tui_layout_type layout) | |
c906108c SS |
334 | { |
335 | int h; | |
336 | ||
6ba8e26f | 337 | h = tui_default_win_height (type, layout); |
c906108c | 338 | |
6d012f14 | 339 | if (tui_win_list[type] == TUI_CMD_WIN) |
c906108c SS |
340 | h -= 1; |
341 | else | |
342 | h -= 2; | |
343 | ||
344 | return h; | |
6ba8e26f | 345 | } |
c906108c | 346 | |
a0145030 AB |
347 | /* Complete possible layout names. TEXT is the complete text entered so |
348 | far, WORD is the word currently being completed. */ | |
349 | ||
eb3ff9a5 | 350 | static void |
a0145030 | 351 | layout_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 352 | completion_tracker &tracker, |
a0145030 AB |
353 | const char *text, const char *word) |
354 | { | |
355 | static const char *layout_names [] = | |
356 | { "src", "asm", "split", "regs", "next", "prev", NULL }; | |
357 | ||
eb3ff9a5 | 358 | complete_on_enum (tracker, layout_names, text, word); |
a0145030 AB |
359 | } |
360 | ||
6ba8e26f AC |
361 | /* Function to initialize gdb commands, for tui window layout |
362 | manipulation. */ | |
2c0b251b | 363 | |
c906108c | 364 | void |
6ba8e26f | 365 | _initialize_tui_layout (void) |
c906108c | 366 | { |
a0145030 AB |
367 | struct cmd_list_element *cmd; |
368 | ||
369 | cmd = add_com ("layout", class_tui, tui_layout_command, _("\ | |
1bedd215 | 370 | Change the layout of windows.\n\ |
bf212be1 | 371 | Usage: layout prev | next | LAYOUT-NAME\n\ |
c906108c SS |
372 | Layout names are:\n\ |
373 | src : Displays source and command windows.\n\ | |
374 | asm : Displays disassembly and command windows.\n\ | |
375 | split : Displays source, disassembly and command windows.\n\ | |
376 | regs : Displays register window. If existing layout\n\ | |
377 | is source/command or assembly/command, the \n\ | |
378 | register window is displayed. If the\n\ | |
379 | source/assembly/command (split) is displayed, \n\ | |
380 | the register window is displayed with \n\ | |
89549d7f | 381 | the window that has current logical focus.")); |
a0145030 | 382 | set_cmd_completer (cmd, layout_completer); |
41783295 | 383 | } |
c906108c SS |
384 | |
385 | ||
386 | /************************* | |
387 | ** STATIC LOCAL FUNCTIONS | |
388 | **************************/ | |
389 | ||
390 | ||
7bd0be3a AB |
391 | /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or |
392 | REGS. */ | |
22940a24 | 393 | enum tui_status |
7bd0be3a | 394 | tui_set_layout_by_name (const char *layout_name) |
c906108c | 395 | { |
22940a24 | 396 | enum tui_status status = TUI_SUCCESS; |
c906108c | 397 | |
63a33118 | 398 | if (layout_name != NULL) |
c906108c | 399 | { |
d02c80cd | 400 | int i; |
6ba8e26f | 401 | enum tui_layout_type new_layout = UNDEFINED_LAYOUT; |
6ba8e26f | 402 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 403 | |
f71c8822 TT |
404 | std::string copy = layout_name; |
405 | for (i = 0; i < copy.size (); i++) | |
406 | copy[i] = toupper (copy[i]); | |
407 | const char *buf_ptr = copy.c_str (); | |
c906108c | 408 | |
1cc6d956 | 409 | /* First check for ambiguous input. */ |
7bd0be3a | 410 | if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S') |
c906108c | 411 | { |
8a3fe4f8 | 412 | warning (_("Ambiguous command input.")); |
c906108c SS |
413 | status = TUI_FAILURE; |
414 | } | |
415 | else | |
416 | { | |
6ba8e26f AC |
417 | if (subset_compare (buf_ptr, "SRC")) |
418 | new_layout = SRC_COMMAND; | |
419 | else if (subset_compare (buf_ptr, "ASM")) | |
420 | new_layout = DISASSEM_COMMAND; | |
421 | else if (subset_compare (buf_ptr, "SPLIT")) | |
422 | new_layout = SRC_DISASSEM_COMMAND; | |
7bd0be3a | 423 | else if (subset_compare (buf_ptr, "REGS")) |
c906108c | 424 | { |
7bd0be3a | 425 | if (cur_layout == SRC_COMMAND |
e5908723 | 426 | || cur_layout == SRC_DATA_COMMAND) |
6ba8e26f | 427 | new_layout = SRC_DATA_COMMAND; |
c906108c | 428 | else |
6ba8e26f | 429 | new_layout = DISASSEM_DATA_COMMAND; |
c906108c | 430 | } |
6ba8e26f AC |
431 | else if (subset_compare (buf_ptr, "NEXT")) |
432 | new_layout = next_layout (); | |
433 | else if (subset_compare (buf_ptr, "PREV")) | |
434 | new_layout = prev_layout (); | |
c906108c SS |
435 | else |
436 | status = TUI_FAILURE; | |
c906108c | 437 | |
880d1e40 AB |
438 | if (status == TUI_SUCCESS) |
439 | { | |
440 | /* Make sure the curses mode is enabled. */ | |
441 | tui_enable (); | |
442 | tui_set_layout (new_layout); | |
443 | } | |
c906108c SS |
444 | } |
445 | } | |
446 | else | |
447 | status = TUI_FAILURE; | |
448 | ||
449 | return status; | |
e8b915dc | 450 | } |
c906108c SS |
451 | |
452 | ||
13274fc3 UW |
453 | static void |
454 | extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) | |
c906108c | 455 | { |
6ba8e26f | 456 | enum tui_layout_type cur_layout = tui_current_layout (); |
957b8b5a | 457 | struct gdbarch *gdbarch = get_current_arch (); |
c774cec6 | 458 | CORE_ADDR addr; |
84b1e7c7 | 459 | CORE_ADDR pc; |
52575520 | 460 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
c906108c | 461 | |
6ba8e26f | 462 | switch (cur_layout) |
c906108c SS |
463 | { |
464 | case SRC_COMMAND: | |
465 | case SRC_DATA_COMMAND: | |
e6e41501 | 466 | gdbarch = TUI_SRC_WIN->gdbarch; |
52575520 | 467 | find_line_pc (cursal.symtab, |
e6e41501 | 468 | TUI_SRC_WIN->start_line_or_addr.u.line_no, |
84b1e7c7 | 469 | &pc); |
c774cec6 | 470 | addr = pc; |
c906108c SS |
471 | break; |
472 | case DISASSEM_COMMAND: | |
473 | case SRC_DISASSEM_COMMAND: | |
474 | case DISASSEM_DATA_COMMAND: | |
e6e41501 TT |
475 | gdbarch = TUI_DISASM_WIN->gdbarch; |
476 | addr = TUI_DISASM_WIN->start_line_or_addr.u.addr; | |
c906108c SS |
477 | break; |
478 | default: | |
c774cec6 | 479 | addr = 0; |
c906108c SS |
480 | break; |
481 | } | |
482 | ||
13274fc3 UW |
483 | *gdbarch_p = gdbarch; |
484 | *addr_p = addr; | |
6ba8e26f | 485 | } |
c906108c SS |
486 | |
487 | ||
c906108c | 488 | static void |
0b39b52e | 489 | tui_layout_command (const char *arg, int from_tty) |
c906108c | 490 | { |
19eb139b | 491 | /* Switch to the selected layout. */ |
7bd0be3a | 492 | if (tui_set_layout_by_name (arg) != TUI_SUCCESS) |
8a3fe4f8 | 493 | warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE); |
e8b915dc | 494 | } |
c906108c | 495 | |
6ba8e26f | 496 | /* Answer the previous layout to cycle to. */ |
2a8854a7 | 497 | static enum tui_layout_type |
6ba8e26f | 498 | next_layout (void) |
c906108c | 499 | { |
570dc176 | 500 | int new_layout; |
c906108c | 501 | |
6ba8e26f AC |
502 | new_layout = tui_current_layout (); |
503 | if (new_layout == UNDEFINED_LAYOUT) | |
504 | new_layout = SRC_COMMAND; | |
c906108c SS |
505 | else |
506 | { | |
6ba8e26f AC |
507 | new_layout++; |
508 | if (new_layout == UNDEFINED_LAYOUT) | |
509 | new_layout = SRC_COMMAND; | |
c906108c SS |
510 | } |
511 | ||
570dc176 | 512 | return (enum tui_layout_type) new_layout; |
6ba8e26f | 513 | } |
c906108c SS |
514 | |
515 | ||
6ba8e26f | 516 | /* Answer the next layout to cycle to. */ |
2a8854a7 | 517 | static enum tui_layout_type |
6ba8e26f | 518 | prev_layout (void) |
c906108c | 519 | { |
570dc176 | 520 | int new_layout; |
c906108c | 521 | |
6ba8e26f AC |
522 | new_layout = tui_current_layout (); |
523 | if (new_layout == SRC_COMMAND) | |
524 | new_layout = DISASSEM_DATA_COMMAND; | |
c906108c SS |
525 | else |
526 | { | |
6ba8e26f AC |
527 | new_layout--; |
528 | if (new_layout == UNDEFINED_LAYOUT) | |
529 | new_layout = DISASSEM_DATA_COMMAND; | |
c906108c SS |
530 | } |
531 | ||
570dc176 | 532 | return (enum tui_layout_type) new_layout; |
6ba8e26f | 533 | } |
c906108c SS |
534 | |
535 | ||
536 | ||
82432e10 TT |
537 | static struct tui_win_info * |
538 | make_command_window (int height, int origin_y) | |
c906108c | 539 | { |
82432e10 TT |
540 | struct tui_win_info *result |
541 | = (struct tui_win_info *) init_and_make_win (NULL, | |
19ba03f4 SM |
542 | CMD_WIN, |
543 | height, | |
544 | tui_term_width (), | |
545 | 0, | |
546 | origin_y, | |
547 | DONT_BOX_WINDOW); | |
82432e10 | 548 | return result; |
6ba8e26f | 549 | } |
c906108c SS |
550 | |
551 | ||
ef5eab5a | 552 | /* make_source_window(). |
c5aa993b | 553 | */ |
0ed69eda TT |
554 | static struct tui_win_info * |
555 | make_source_window (int height, int origin_y) | |
c906108c | 556 | { |
0ed69eda | 557 | return make_source_or_disasm_window (SRC_WIN, height, origin_y); |
6ba8e26f | 558 | } /* make_source_window */ |
c906108c SS |
559 | |
560 | ||
ef5eab5a | 561 | /* make_disasm_window(). |
c5aa993b | 562 | */ |
0ed69eda TT |
563 | static struct tui_win_info * |
564 | make_disasm_window (int height, int origin_y) | |
c906108c | 565 | { |
0ed69eda | 566 | return make_source_or_disasm_window (DISASSEM_WIN, height, origin_y); |
6ba8e26f | 567 | } /* make_disasm_window */ |
c906108c SS |
568 | |
569 | ||
c906108c | 570 | static void |
08ef48c5 MS |
571 | make_data_window (struct tui_win_info **win_info_ptr, |
572 | int height, int origin_y) | |
c906108c | 573 | { |
19ba03f4 SM |
574 | *win_info_ptr |
575 | = (struct tui_win_info *) init_and_make_win (*win_info_ptr, | |
576 | DATA_WIN, | |
577 | height, | |
578 | tui_term_width (), | |
579 | 0, | |
580 | origin_y, | |
581 | BOX_WINDOW); | |
6ba8e26f | 582 | } |
c906108c SS |
583 | |
584 | ||
585 | ||
6ba8e26f | 586 | /* Show the Source/Command layout. */ |
c906108c | 587 | static void |
6ba8e26f | 588 | show_source_command (void) |
c906108c | 589 | { |
6ba8e26f AC |
590 | show_source_or_disasm_and_command (SRC_COMMAND); |
591 | } | |
c906108c SS |
592 | |
593 | ||
6ba8e26f | 594 | /* Show the Dissassem/Command layout. */ |
c906108c | 595 | static void |
6ba8e26f | 596 | show_disasm_command (void) |
c906108c | 597 | { |
6ba8e26f AC |
598 | show_source_or_disasm_and_command (DISASSEM_COMMAND); |
599 | } | |
c906108c SS |
600 | |
601 | ||
6ba8e26f | 602 | /* Show the Source/Disassem/Command layout. */ |
c906108c | 603 | static void |
6ba8e26f | 604 | show_source_disasm_command (void) |
c906108c | 605 | { |
dd1abb8c | 606 | if (tui_current_layout () != SRC_DISASSEM_COMMAND) |
c906108c | 607 | { |
6ba8e26f | 608 | int cmd_height, src_height, asm_height; |
c906108c | 609 | |
6d012f14 | 610 | if (TUI_CMD_WIN != NULL) |
cb2ce893 | 611 | cmd_height = TUI_CMD_WIN->height; |
c906108c | 612 | else |
6ba8e26f | 613 | cmd_height = tui_term_height () / 3; |
c906108c | 614 | |
6ba8e26f AC |
615 | src_height = (tui_term_height () - cmd_height) / 2; |
616 | asm_height = tui_term_height () - (src_height + cmd_height); | |
c906108c | 617 | |
6d012f14 | 618 | if (TUI_SRC_WIN == NULL) |
e6e41501 | 619 | tui_win_list[SRC_WIN] = make_source_window (src_height, 0); |
c906108c SS |
620 | else |
621 | { | |
d6ba6a11 TT |
622 | TUI_SRC_WIN->reset (TUI_SRC_WIN->type, |
623 | src_height, | |
624 | TUI_SRC_WIN->width, | |
625 | TUI_SRC_WIN->execution_info->width, | |
626 | 0); | |
627 | TUI_SRC_WIN->execution_info->reset (EXEC_INFO_WIN, | |
628 | src_height, | |
629 | 3, | |
630 | 0, | |
631 | 0); | |
cb2ce893 | 632 | tui_make_visible (TUI_SRC_WIN); |
e6e41501 TT |
633 | tui_make_visible (TUI_SRC_WIN->execution_info); |
634 | TUI_SRC_WIN->m_has_locator = false; | |
c906108c | 635 | } |
c906108c | 636 | |
82432e10 TT |
637 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
638 | ||
639 | tui_show_source_content (TUI_SRC_WIN); | |
640 | if (TUI_DISASM_WIN == NULL) | |
641 | { | |
e6e41501 TT |
642 | tui_win_list[DISASSEM_WIN] |
643 | = make_disasm_window (asm_height, src_height - 1); | |
82432e10 | 644 | locator |
d6ba6a11 TT |
645 | = init_and_make_win (locator, |
646 | LOCATOR_WIN, | |
647 | 2 /* 1 */ , | |
648 | tui_term_width (), | |
649 | 0, | |
650 | (src_height + asm_height) - 1, | |
651 | DONT_BOX_WINDOW); | |
82432e10 TT |
652 | } |
653 | else | |
654 | { | |
d6ba6a11 TT |
655 | locator->reset (LOCATOR_WIN, |
656 | 2 /* 1 */ , | |
657 | tui_term_width (), | |
658 | 0, | |
659 | (src_height + asm_height) - 1); | |
e6e41501 | 660 | TUI_DISASM_WIN->m_has_locator = true; |
d6ba6a11 TT |
661 | TUI_DISASM_WIN->reset (TUI_DISASM_WIN->type, |
662 | asm_height, | |
663 | TUI_DISASM_WIN->width, | |
664 | TUI_DISASM_WIN->execution_info->width, | |
665 | src_height - 1); | |
666 | TUI_DISASM_WIN->execution_info->reset (EXEC_INFO_WIN, | |
667 | asm_height, | |
668 | 3, | |
669 | 0, | |
670 | src_height - 1); | |
cb2ce893 | 671 | tui_make_visible (TUI_DISASM_WIN); |
e6e41501 | 672 | tui_make_visible (TUI_DISASM_WIN->execution_info); |
82432e10 | 673 | } |
e6e41501 TT |
674 | TUI_SRC_WIN->m_has_locator = false; |
675 | TUI_DISASM_WIN->m_has_locator = true; | |
82432e10 TT |
676 | tui_make_visible (locator); |
677 | tui_show_locator_content (); | |
678 | tui_show_source_content (TUI_DISASM_WIN); | |
679 | ||
680 | if (TUI_CMD_WIN == NULL) | |
81491aa0 TT |
681 | tui_win_list[CMD_WIN] |
682 | = make_command_window (cmd_height, tui_term_height () - cmd_height); | |
82432e10 TT |
683 | else |
684 | { | |
d6ba6a11 TT |
685 | TUI_CMD_WIN->reset (TUI_CMD_WIN->type, |
686 | TUI_CMD_WIN->height, | |
687 | TUI_CMD_WIN->width, | |
688 | 0, | |
689 | TUI_CMD_WIN->origin.y); | |
cb2ce893 | 690 | tui_make_visible (TUI_CMD_WIN); |
c906108c | 691 | } |
5b81daba | 692 | TUI_CMD_WIN->refresh_window (); |
dd1abb8c | 693 | tui_set_current_layout_to (SRC_DISASSEM_COMMAND); |
c906108c | 694 | } |
6ba8e26f | 695 | } |
c906108c SS |
696 | |
697 | ||
6ba8e26f AC |
698 | /* Show the Source/Data/Command or the Dissassembly/Data/Command |
699 | layout. */ | |
c906108c | 700 | static void |
6ba8e26f | 701 | show_data (enum tui_layout_type new_layout) |
c906108c | 702 | { |
cb2ce893 | 703 | int total_height = (tui_term_height () - TUI_CMD_WIN->height); |
6ba8e26f AC |
704 | int src_height, data_height; |
705 | enum tui_win_type win_type; | |
5b6fe301 | 706 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
c906108c SS |
707 | |
708 | ||
6ba8e26f AC |
709 | data_height = total_height / 2; |
710 | src_height = total_height - data_height; | |
ec7d9e56 AC |
711 | tui_make_all_invisible (); |
712 | tui_make_invisible (locator); | |
238eb706 | 713 | make_data_window (&tui_win_list[DATA_WIN], data_height, 0); |
6ba8e26f AC |
714 | if (new_layout == SRC_DATA_COMMAND) |
715 | win_type = SRC_WIN; | |
c906108c | 716 | else |
6ba8e26f | 717 | win_type = DISASSEM_WIN; |
e6e41501 TT |
718 | |
719 | tui_source_window_base *base; | |
6ba8e26f | 720 | if (tui_win_list[win_type] == NULL) |
c906108c | 721 | { |
6ba8e26f | 722 | if (win_type == SRC_WIN) |
0ed69eda TT |
723 | tui_win_list[win_type] |
724 | = make_source_window (src_height, data_height - 1); | |
c906108c | 725 | else |
0ed69eda TT |
726 | tui_win_list[win_type] |
727 | = make_disasm_window (src_height, data_height - 1); | |
19ba03f4 | 728 | locator |
d6ba6a11 TT |
729 | = init_and_make_win (locator, |
730 | LOCATOR_WIN, | |
731 | 2 /* 1 */ , | |
732 | tui_term_width (), | |
733 | 0, | |
734 | total_height - 1, | |
735 | DONT_BOX_WINDOW); | |
e6e41501 | 736 | base = (tui_source_window_base *) tui_win_list[win_type]; |
c906108c SS |
737 | } |
738 | else | |
739 | { | |
e6e41501 | 740 | base = (tui_source_window_base *) tui_win_list[win_type]; |
d6ba6a11 TT |
741 | tui_win_list[win_type]->reset (tui_win_list[win_type]->type, |
742 | src_height, | |
743 | tui_win_list[win_type]->width, | |
744 | base->execution_info->width, | |
745 | data_height - 1); | |
746 | base->execution_info->reset (EXEC_INFO_WIN, | |
747 | src_height, | |
748 | 3, | |
749 | 0, | |
750 | data_height - 1); | |
cb2ce893 | 751 | tui_make_visible (tui_win_list[win_type]); |
e6e41501 | 752 | tui_make_visible (base->execution_info); |
d6ba6a11 TT |
753 | locator->reset (LOCATOR_WIN, |
754 | 2 /* 1 */ , | |
755 | tui_term_width (), | |
756 | 0, | |
757 | total_height - 1); | |
c906108c | 758 | } |
e6e41501 | 759 | base->m_has_locator = true; |
ec7d9e56 | 760 | tui_make_visible (locator); |
47d3492a | 761 | tui_show_locator_content (); |
ad54d15b TT |
762 | tui_add_to_source_windows |
763 | ((tui_source_window_base *) tui_win_list[win_type]); | |
6ba8e26f AC |
764 | tui_set_current_layout_to (new_layout); |
765 | } | |
c906108c | 766 | |
d6ba6a11 TT |
767 | void |
768 | tui_gen_win_info::reset (enum tui_win_type win_type, | |
769 | int height_, int width_, | |
770 | int origin_x_, int origin_y_) | |
c906108c | 771 | { |
d6ba6a11 TT |
772 | int h = height_; |
773 | ||
774 | gdb_assert (type == win_type); | |
c906108c | 775 | |
d6ba6a11 TT |
776 | width = width_; |
777 | height = h; | |
c906108c SS |
778 | if (h > 1) |
779 | { | |
d6ba6a11 TT |
780 | viewport_height = h - 1; |
781 | if (type != CMD_WIN) | |
782 | viewport_height--; | |
c906108c SS |
783 | } |
784 | else | |
d6ba6a11 TT |
785 | viewport_height = 1; |
786 | origin.x = origin_x_; | |
787 | origin.y = origin_y_; | |
788 | } | |
c906108c | 789 | |
ef5eab5a | 790 | /* init_and_make_win(). |
c5aa993b | 791 | */ |
d6ba6a11 TT |
792 | static tui_gen_win_info * |
793 | init_and_make_win (tui_gen_win_info *win_info, | |
08ef48c5 MS |
794 | enum tui_win_type win_type, |
795 | int height, int width, | |
796 | int origin_x, int origin_y, | |
17374de4 | 797 | enum tui_box box_it) |
c906108c | 798 | { |
d6ba6a11 | 799 | if (win_info == NULL) |
c906108c | 800 | { |
6ba8e26f | 801 | if (tui_win_is_auxillary (win_type)) |
d6ba6a11 | 802 | win_info = new tui_gen_win_info (win_type); |
c906108c | 803 | else |
d6ba6a11 | 804 | win_info = tui_alloc_win_info (win_type); |
c906108c | 805 | } |
c906108c | 806 | |
d6ba6a11 TT |
807 | win_info->reset (win_type, height, width, origin_x, origin_y); |
808 | tui_make_window (win_info, box_it); | |
ec328aa5 | 809 | |
d6ba6a11 | 810 | return win_info; |
bc712bbf | 811 | } |
c906108c SS |
812 | |
813 | ||
0ed69eda TT |
814 | static struct tui_win_info * |
815 | make_source_or_disasm_window (enum tui_win_type type, | |
08ef48c5 | 816 | int height, int origin_y) |
c906108c | 817 | { |
f936bca2 TT |
818 | struct tui_gen_win_info *execution_info |
819 | = init_and_make_win (nullptr, | |
820 | EXEC_INFO_WIN, | |
821 | height, | |
822 | 3, | |
823 | 0, | |
824 | origin_y, | |
825 | DONT_BOX_WINDOW); | |
ef5eab5a MS |
826 | |
827 | /* Now create the source window. */ | |
e6e41501 TT |
828 | struct tui_source_window_base *result |
829 | = ((struct tui_source_window_base *) | |
0ed69eda | 830 | init_and_make_win (NULL, |
19ba03f4 SM |
831 | type, |
832 | height, | |
833 | tui_term_width () - execution_info->width, | |
834 | execution_info->width, | |
835 | origin_y, | |
836 | BOX_WINDOW)); | |
e6e41501 | 837 | result->execution_info = execution_info; |
0ed69eda | 838 | return result; |
6ba8e26f | 839 | } |
c906108c SS |
840 | |
841 | ||
1cc6d956 | 842 | /* Show the Source/Command or the Disassem layout. */ |
c906108c | 843 | static void |
6ba8e26f | 844 | show_source_or_disasm_and_command (enum tui_layout_type layout_type) |
c906108c | 845 | { |
6ba8e26f | 846 | if (tui_current_layout () != layout_type) |
c906108c | 847 | { |
5b6fe301 | 848 | struct tui_win_info **win_info_ptr; |
6ba8e26f | 849 | int src_height, cmd_height; |
5b6fe301 | 850 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
c906108c | 851 | |
6d012f14 | 852 | if (TUI_CMD_WIN != NULL) |
cb2ce893 | 853 | cmd_height = TUI_CMD_WIN->height; |
c906108c | 854 | else |
6ba8e26f AC |
855 | cmd_height = tui_term_height () / 3; |
856 | src_height = tui_term_height () - cmd_height; | |
c906108c | 857 | |
6ba8e26f | 858 | if (layout_type == SRC_COMMAND) |
e6e41501 | 859 | win_info_ptr = &tui_win_list[SRC_WIN]; |
c906108c | 860 | else |
e6e41501 | 861 | win_info_ptr = &tui_win_list[DISASSEM_WIN]; |
c906108c | 862 | |
e6e41501 | 863 | tui_source_window_base *base; |
6ba8e26f | 864 | if ((*win_info_ptr) == NULL) |
c906108c | 865 | { |
6ba8e26f | 866 | if (layout_type == SRC_COMMAND) |
0ed69eda | 867 | *win_info_ptr = make_source_window (src_height - 1, 0); |
c906108c | 868 | else |
0ed69eda | 869 | *win_info_ptr = make_disasm_window (src_height - 1, 0); |
19ba03f4 | 870 | locator |
d6ba6a11 TT |
871 | = init_and_make_win (locator, |
872 | LOCATOR_WIN, | |
873 | 2 /* 1 */ , | |
874 | tui_term_width (), | |
875 | 0, | |
876 | src_height - 1, | |
877 | DONT_BOX_WINDOW); | |
e6e41501 | 878 | base = (tui_source_window_base *) *win_info_ptr; |
c906108c SS |
879 | } |
880 | else | |
881 | { | |
e6e41501 | 882 | base = (tui_source_window_base *) *win_info_ptr; |
d6ba6a11 TT |
883 | locator->reset (LOCATOR_WIN, |
884 | 2 /* 1 */ , | |
885 | tui_term_width (), | |
886 | 0, | |
887 | src_height - 1); | |
e6e41501 | 888 | base->m_has_locator = true; |
d6ba6a11 TT |
889 | (*win_info_ptr)->reset ((*win_info_ptr)->type, |
890 | src_height - 1, | |
891 | (*win_info_ptr)->width, | |
892 | base->execution_info->width, | |
893 | 0); | |
894 | base->execution_info->reset (EXEC_INFO_WIN, | |
895 | src_height - 1, | |
896 | 3, | |
897 | 0, | |
898 | 0); | |
cb2ce893 | 899 | tui_make_visible (*win_info_ptr); |
e6e41501 | 900 | tui_make_visible (base->execution_info); |
c906108c | 901 | } |
c906108c | 902 | |
6a0ee02c TT |
903 | base->m_has_locator = true; |
904 | tui_make_visible (locator); | |
905 | tui_show_locator_content (); | |
906 | tui_show_source_content (*win_info_ptr); | |
907 | ||
908 | if (TUI_CMD_WIN == NULL) | |
909 | { | |
910 | tui_win_list[CMD_WIN] = make_command_window (cmd_height, | |
911 | src_height); | |
5b81daba | 912 | TUI_CMD_WIN->refresh_window (); |
6a0ee02c TT |
913 | } |
914 | else | |
915 | { | |
d6ba6a11 TT |
916 | TUI_CMD_WIN->reset (TUI_CMD_WIN->type, |
917 | TUI_CMD_WIN->height, | |
918 | TUI_CMD_WIN->width, | |
919 | TUI_CMD_WIN->origin.x, | |
920 | TUI_CMD_WIN->origin.y); | |
cb2ce893 | 921 | tui_make_visible (TUI_CMD_WIN); |
c906108c | 922 | } |
6ba8e26f | 923 | tui_set_current_layout_to (layout_type); |
c906108c | 924 | } |
6ba8e26f | 925 | } |