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); |
6ba8e26f | 46 | static void show_source_or_disasm_and_command (enum tui_layout_type); |
82432e10 | 47 | static struct tui_win_info *make_command_window (int, int); |
0ed69eda TT |
48 | static struct tui_win_info *make_source_window (int, int); |
49 | static struct tui_win_info *make_disasm_window (int, int); | |
6ba8e26f AC |
50 | static void show_source_command (void); |
51 | static void show_disasm_command (void); | |
52 | static void show_source_disasm_command (void); | |
53 | static void show_data (enum tui_layout_type); | |
54 | static enum tui_layout_type next_layout (void); | |
55 | static enum tui_layout_type prev_layout (void); | |
0b39b52e | 56 | static void tui_layout_command (const char *, int); |
13274fc3 | 57 | static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *); |
c906108c SS |
58 | |
59 | ||
60 | /*************************************** | |
61 | ** DEFINITIONS | |
62 | ***************************************/ | |
63 | ||
64 | #define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n" | |
65 | ||
c7037be1 SC |
66 | /* Show the screen layout defined. */ |
67 | static void | |
6ba8e26f | 68 | show_layout (enum tui_layout_type layout) |
c906108c | 69 | { |
6ba8e26f | 70 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 71 | |
6ba8e26f | 72 | if (layout != cur_layout) |
c906108c | 73 | { |
ef5eab5a MS |
74 | /* Since the new layout may cause changes in window size, we |
75 | should free the content and reallocate on next display of | |
76 | source/asm. */ | |
dd1abb8c | 77 | tui_clear_source_windows (); |
e5908723 MS |
78 | if (layout == SRC_DATA_COMMAND |
79 | || layout == DISASSEM_DATA_COMMAND) | |
c906108c | 80 | { |
6ba8e26f | 81 | show_data (layout); |
1ce3e844 | 82 | tui_refresh_all (); |
c906108c SS |
83 | } |
84 | else | |
85 | { | |
1cc6d956 | 86 | /* First make the current layout be invisible. */ |
ec7d9e56 | 87 | tui_make_all_invisible (); |
dd1abb8c | 88 | tui_make_invisible (tui_locator_win_info_ptr ()); |
c906108c SS |
89 | |
90 | switch (layout) | |
91 | { | |
1cc6d956 | 92 | /* Now show the new layout. */ |
c906108c | 93 | case SRC_COMMAND: |
6ba8e26f | 94 | show_source_command (); |
6d012f14 | 95 | tui_add_to_source_windows (TUI_SRC_WIN); |
c906108c SS |
96 | break; |
97 | case DISASSEM_COMMAND: | |
6ba8e26f | 98 | show_disasm_command (); |
6d012f14 | 99 | tui_add_to_source_windows (TUI_DISASM_WIN); |
c906108c SS |
100 | break; |
101 | case SRC_DISASSEM_COMMAND: | |
6ba8e26f | 102 | show_source_disasm_command (); |
6d012f14 AC |
103 | tui_add_to_source_windows (TUI_SRC_WIN); |
104 | tui_add_to_source_windows (TUI_DISASM_WIN); | |
c906108c SS |
105 | break; |
106 | default: | |
107 | break; | |
108 | } | |
109 | } | |
110 | } | |
bc712bbf | 111 | } |
c906108c SS |
112 | |
113 | ||
080ce8c0 | 114 | /* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND, |
7bd0be3a | 115 | SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND. */ |
080ce8c0 | 116 | enum tui_status |
7bd0be3a | 117 | tui_set_layout (enum tui_layout_type layout_type) |
c906108c | 118 | { |
22940a24 | 119 | enum tui_status status = TUI_SUCCESS; |
c906108c | 120 | |
7bd0be3a | 121 | if (layout_type != UNDEFINED_LAYOUT) |
c906108c | 122 | { |
80110957 | 123 | enum tui_layout_type cur_layout = tui_current_layout (); |
13274fc3 UW |
124 | struct gdbarch *gdbarch; |
125 | CORE_ADDR addr; | |
5b6fe301 MS |
126 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
127 | struct tui_layout_def *layout_def = tui_layout_def (); | |
c906108c | 128 | |
13274fc3 | 129 | extract_display_start_addr (&gdbarch, &addr); |
c906108c | 130 | |
80110957 | 131 | enum tui_layout_type new_layout = layout_type; |
c906108c | 132 | |
7bd0be3a | 133 | if (new_layout != cur_layout) |
c906108c | 134 | { |
7bd0be3a | 135 | show_layout (new_layout); |
ef5eab5a | 136 | |
7bd0be3a AB |
137 | /* Now determine where focus should be. */ |
138 | if (win_with_focus != TUI_CMD_WIN) | |
139 | { | |
140 | switch (new_layout) | |
c906108c | 141 | { |
7bd0be3a AB |
142 | case SRC_COMMAND: |
143 | tui_set_win_focus_to (TUI_SRC_WIN); | |
144 | layout_def->display_mode = SRC_WIN; | |
7bd0be3a AB |
145 | break; |
146 | case DISASSEM_COMMAND: | |
147 | /* The previous layout was not showing code. | |
148 | This can happen if there is no source | |
149 | available: | |
150 | ||
151 | 1. if the source file is in another dir OR | |
152 | 2. if target was compiled without -g | |
153 | We still want to show the assembly though! */ | |
154 | ||
155 | tui_get_begin_asm_address (&gdbarch, &addr); | |
156 | tui_set_win_focus_to (TUI_DISASM_WIN); | |
157 | layout_def->display_mode = DISASSEM_WIN; | |
7bd0be3a AB |
158 | break; |
159 | case SRC_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 | if (win_with_focus == TUI_SRC_WIN) | |
170 | tui_set_win_focus_to (TUI_SRC_WIN); | |
171 | else | |
172 | tui_set_win_focus_to (TUI_DISASM_WIN); | |
7bd0be3a AB |
173 | break; |
174 | case SRC_DATA_COMMAND: | |
175 | if (win_with_focus != TUI_DATA_WIN) | |
176 | tui_set_win_focus_to (TUI_SRC_WIN); | |
177 | else | |
178 | tui_set_win_focus_to (TUI_DATA_WIN); | |
179 | layout_def->display_mode = SRC_WIN; | |
7bd0be3a AB |
180 | break; |
181 | case DISASSEM_DATA_COMMAND: | |
182 | /* The previous layout was not showing code. | |
183 | This can happen if there is no source | |
184 | available: | |
185 | ||
186 | 1. if the source file is in another dir OR | |
187 | 2. if target was compiled without -g | |
188 | We still want to show the assembly though! */ | |
189 | ||
190 | tui_get_begin_asm_address (&gdbarch, &addr); | |
191 | if (win_with_focus != TUI_DATA_WIN) | |
192 | tui_set_win_focus_to (TUI_DISASM_WIN); | |
193 | else | |
194 | tui_set_win_focus_to (TUI_DATA_WIN); | |
195 | layout_def->display_mode = DISASSEM_WIN; | |
7bd0be3a AB |
196 | break; |
197 | default: | |
198 | break; | |
c906108c | 199 | } |
c906108c | 200 | } |
7bd0be3a AB |
201 | /* |
202 | * Now update the window content. | |
203 | */ | |
7bd0be3a | 204 | tui_update_source_windows_with_addr (gdbarch, addr); |
80110957 TT |
205 | if (new_layout == SRC_DATA_COMMAND |
206 | || new_layout == DISASSEM_DATA_COMMAND) | |
238eb706 | 207 | tui_show_registers (TUI_DATA_WIN->current_group); |
c906108c SS |
208 | } |
209 | } | |
210 | else | |
211 | status = TUI_FAILURE; | |
212 | ||
213 | return status; | |
bc712bbf | 214 | } |
c906108c | 215 | |
080ce8c0 AC |
216 | /* Add the specified window to the layout in a logical way. This |
217 | means setting up the most logical layout given the window to be | |
218 | added. */ | |
c906108c | 219 | void |
080ce8c0 | 220 | tui_add_win_to_layout (enum tui_win_type type) |
c906108c | 221 | { |
6ba8e26f | 222 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c SS |
223 | |
224 | switch (type) | |
225 | { | |
226 | case SRC_WIN: | |
e5908723 MS |
227 | if (cur_layout != SRC_COMMAND |
228 | && cur_layout != SRC_DISASSEM_COMMAND | |
229 | && cur_layout != SRC_DATA_COMMAND) | |
c906108c | 230 | { |
dd1abb8c | 231 | tui_clear_source_windows_detail (); |
6ba8e26f AC |
232 | if (cur_layout == DISASSEM_DATA_COMMAND) |
233 | show_layout (SRC_DATA_COMMAND); | |
c906108c | 234 | else |
6ba8e26f | 235 | show_layout (SRC_COMMAND); |
c906108c SS |
236 | } |
237 | break; | |
238 | case DISASSEM_WIN: | |
e5908723 MS |
239 | if (cur_layout != DISASSEM_COMMAND |
240 | && cur_layout != SRC_DISASSEM_COMMAND | |
241 | && cur_layout != DISASSEM_DATA_COMMAND) | |
c906108c | 242 | { |
dd1abb8c | 243 | tui_clear_source_windows_detail (); |
6ba8e26f AC |
244 | if (cur_layout == SRC_DATA_COMMAND) |
245 | show_layout (DISASSEM_DATA_COMMAND); | |
c906108c | 246 | else |
6ba8e26f | 247 | show_layout (DISASSEM_COMMAND); |
c906108c SS |
248 | } |
249 | break; | |
250 | case DATA_WIN: | |
e5908723 MS |
251 | if (cur_layout != SRC_DATA_COMMAND |
252 | && cur_layout != DISASSEM_DATA_COMMAND) | |
c906108c | 253 | { |
6ba8e26f AC |
254 | if (cur_layout == DISASSEM_COMMAND) |
255 | show_layout (DISASSEM_DATA_COMMAND); | |
c906108c | 256 | else |
6ba8e26f | 257 | show_layout (SRC_DATA_COMMAND); |
c906108c SS |
258 | } |
259 | break; | |
260 | default: | |
261 | break; | |
262 | } | |
6ba8e26f | 263 | } |
c906108c SS |
264 | |
265 | ||
6ba8e26f AC |
266 | /* Answer the height of a window. If it hasn't been created yet, |
267 | answer what the height of a window would be based upon its type and | |
268 | the layout. */ | |
c906108c | 269 | int |
08ef48c5 MS |
270 | tui_default_win_height (enum tui_win_type type, |
271 | enum tui_layout_type layout) | |
c906108c SS |
272 | { |
273 | int h; | |
274 | ||
cafb3438 | 275 | if (tui_win_list[type] != NULL) |
cb2ce893 | 276 | h = tui_win_list[type]->height; |
c906108c SS |
277 | else |
278 | { | |
279 | switch (layout) | |
280 | { | |
281 | case SRC_COMMAND: | |
282 | case DISASSEM_COMMAND: | |
6d012f14 | 283 | if (TUI_CMD_WIN == NULL) |
dd1abb8c | 284 | h = tui_term_height () / 2; |
c906108c | 285 | else |
cb2ce893 | 286 | h = tui_term_height () - TUI_CMD_WIN->height; |
c906108c SS |
287 | break; |
288 | case SRC_DISASSEM_COMMAND: | |
289 | case SRC_DATA_COMMAND: | |
290 | case DISASSEM_DATA_COMMAND: | |
6d012f14 | 291 | if (TUI_CMD_WIN == NULL) |
dd1abb8c | 292 | h = tui_term_height () / 3; |
c906108c | 293 | else |
cb2ce893 | 294 | h = (tui_term_height () - TUI_CMD_WIN->height) / 2; |
c906108c SS |
295 | break; |
296 | default: | |
297 | h = 0; | |
298 | break; | |
299 | } | |
300 | } | |
301 | ||
302 | return h; | |
6ba8e26f | 303 | } |
c906108c SS |
304 | |
305 | ||
080ce8c0 AC |
306 | /* Answer the height of a window. If it hasn't been created yet, |
307 | answer what the height of a window would be based upon its type and | |
308 | the layout. */ | |
c906108c | 309 | int |
080ce8c0 AC |
310 | tui_default_win_viewport_height (enum tui_win_type type, |
311 | enum tui_layout_type layout) | |
c906108c SS |
312 | { |
313 | int h; | |
314 | ||
6ba8e26f | 315 | h = tui_default_win_height (type, layout); |
c906108c | 316 | |
6d012f14 | 317 | if (tui_win_list[type] == TUI_CMD_WIN) |
c906108c SS |
318 | h -= 1; |
319 | else | |
320 | h -= 2; | |
321 | ||
322 | return h; | |
6ba8e26f | 323 | } |
c906108c | 324 | |
a0145030 AB |
325 | /* Complete possible layout names. TEXT is the complete text entered so |
326 | far, WORD is the word currently being completed. */ | |
327 | ||
eb3ff9a5 | 328 | static void |
a0145030 | 329 | layout_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 330 | completion_tracker &tracker, |
a0145030 AB |
331 | const char *text, const char *word) |
332 | { | |
333 | static const char *layout_names [] = | |
334 | { "src", "asm", "split", "regs", "next", "prev", NULL }; | |
335 | ||
eb3ff9a5 | 336 | complete_on_enum (tracker, layout_names, text, word); |
a0145030 AB |
337 | } |
338 | ||
6ba8e26f AC |
339 | /* Function to initialize gdb commands, for tui window layout |
340 | manipulation. */ | |
2c0b251b | 341 | |
c906108c | 342 | void |
6ba8e26f | 343 | _initialize_tui_layout (void) |
c906108c | 344 | { |
a0145030 AB |
345 | struct cmd_list_element *cmd; |
346 | ||
347 | cmd = add_com ("layout", class_tui, tui_layout_command, _("\ | |
1bedd215 | 348 | Change the layout of windows.\n\ |
bf212be1 | 349 | Usage: layout prev | next | LAYOUT-NAME\n\ |
c906108c SS |
350 | Layout names are:\n\ |
351 | src : Displays source and command windows.\n\ | |
352 | asm : Displays disassembly and command windows.\n\ | |
353 | split : Displays source, disassembly and command windows.\n\ | |
354 | regs : Displays register window. If existing layout\n\ | |
355 | is source/command or assembly/command, the \n\ | |
356 | register window is displayed. If the\n\ | |
357 | source/assembly/command (split) is displayed, \n\ | |
358 | the register window is displayed with \n\ | |
89549d7f | 359 | the window that has current logical focus.")); |
a0145030 | 360 | set_cmd_completer (cmd, layout_completer); |
41783295 | 361 | } |
c906108c SS |
362 | |
363 | ||
364 | /************************* | |
365 | ** STATIC LOCAL FUNCTIONS | |
366 | **************************/ | |
367 | ||
368 | ||
7bd0be3a AB |
369 | /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or |
370 | REGS. */ | |
22940a24 | 371 | enum tui_status |
7bd0be3a | 372 | tui_set_layout_by_name (const char *layout_name) |
c906108c | 373 | { |
22940a24 | 374 | enum tui_status status = TUI_SUCCESS; |
c906108c | 375 | |
63a33118 | 376 | if (layout_name != NULL) |
c906108c | 377 | { |
d02c80cd | 378 | int i; |
6ba8e26f | 379 | enum tui_layout_type new_layout = UNDEFINED_LAYOUT; |
6ba8e26f | 380 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 381 | |
f71c8822 TT |
382 | std::string copy = layout_name; |
383 | for (i = 0; i < copy.size (); i++) | |
384 | copy[i] = toupper (copy[i]); | |
385 | const char *buf_ptr = copy.c_str (); | |
c906108c | 386 | |
1cc6d956 | 387 | /* First check for ambiguous input. */ |
7bd0be3a | 388 | if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S') |
c906108c | 389 | { |
8a3fe4f8 | 390 | warning (_("Ambiguous command input.")); |
c906108c SS |
391 | status = TUI_FAILURE; |
392 | } | |
393 | else | |
394 | { | |
6ba8e26f AC |
395 | if (subset_compare (buf_ptr, "SRC")) |
396 | new_layout = SRC_COMMAND; | |
397 | else if (subset_compare (buf_ptr, "ASM")) | |
398 | new_layout = DISASSEM_COMMAND; | |
399 | else if (subset_compare (buf_ptr, "SPLIT")) | |
400 | new_layout = SRC_DISASSEM_COMMAND; | |
7bd0be3a | 401 | else if (subset_compare (buf_ptr, "REGS")) |
c906108c | 402 | { |
7bd0be3a | 403 | if (cur_layout == SRC_COMMAND |
e5908723 | 404 | || cur_layout == SRC_DATA_COMMAND) |
6ba8e26f | 405 | new_layout = SRC_DATA_COMMAND; |
c906108c | 406 | else |
6ba8e26f | 407 | new_layout = DISASSEM_DATA_COMMAND; |
c906108c | 408 | } |
6ba8e26f AC |
409 | else if (subset_compare (buf_ptr, "NEXT")) |
410 | new_layout = next_layout (); | |
411 | else if (subset_compare (buf_ptr, "PREV")) | |
412 | new_layout = prev_layout (); | |
c906108c SS |
413 | else |
414 | status = TUI_FAILURE; | |
c906108c | 415 | |
880d1e40 AB |
416 | if (status == TUI_SUCCESS) |
417 | { | |
418 | /* Make sure the curses mode is enabled. */ | |
419 | tui_enable (); | |
420 | tui_set_layout (new_layout); | |
421 | } | |
c906108c SS |
422 | } |
423 | } | |
424 | else | |
425 | status = TUI_FAILURE; | |
426 | ||
427 | return status; | |
e8b915dc | 428 | } |
c906108c SS |
429 | |
430 | ||
13274fc3 UW |
431 | static void |
432 | extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) | |
c906108c | 433 | { |
6ba8e26f | 434 | enum tui_layout_type cur_layout = tui_current_layout (); |
957b8b5a | 435 | struct gdbarch *gdbarch = get_current_arch (); |
c774cec6 | 436 | CORE_ADDR addr; |
84b1e7c7 | 437 | CORE_ADDR pc; |
52575520 | 438 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
c906108c | 439 | |
6ba8e26f | 440 | switch (cur_layout) |
c906108c SS |
441 | { |
442 | case SRC_COMMAND: | |
443 | case SRC_DATA_COMMAND: | |
e6e41501 | 444 | gdbarch = TUI_SRC_WIN->gdbarch; |
52575520 | 445 | find_line_pc (cursal.symtab, |
e6e41501 | 446 | TUI_SRC_WIN->start_line_or_addr.u.line_no, |
84b1e7c7 | 447 | &pc); |
c774cec6 | 448 | addr = pc; |
c906108c SS |
449 | break; |
450 | case DISASSEM_COMMAND: | |
451 | case SRC_DISASSEM_COMMAND: | |
452 | case DISASSEM_DATA_COMMAND: | |
e6e41501 TT |
453 | gdbarch = TUI_DISASM_WIN->gdbarch; |
454 | addr = TUI_DISASM_WIN->start_line_or_addr.u.addr; | |
c906108c SS |
455 | break; |
456 | default: | |
c774cec6 | 457 | addr = 0; |
c906108c SS |
458 | break; |
459 | } | |
460 | ||
13274fc3 UW |
461 | *gdbarch_p = gdbarch; |
462 | *addr_p = addr; | |
6ba8e26f | 463 | } |
c906108c SS |
464 | |
465 | ||
c906108c | 466 | static void |
0b39b52e | 467 | tui_layout_command (const char *arg, int from_tty) |
c906108c | 468 | { |
19eb139b | 469 | /* Switch to the selected layout. */ |
7bd0be3a | 470 | if (tui_set_layout_by_name (arg) != TUI_SUCCESS) |
8a3fe4f8 | 471 | warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE); |
e8b915dc | 472 | } |
c906108c | 473 | |
6ba8e26f | 474 | /* Answer the previous layout to cycle to. */ |
2a8854a7 | 475 | static enum tui_layout_type |
6ba8e26f | 476 | next_layout (void) |
c906108c | 477 | { |
570dc176 | 478 | int new_layout; |
c906108c | 479 | |
6ba8e26f AC |
480 | new_layout = tui_current_layout (); |
481 | if (new_layout == UNDEFINED_LAYOUT) | |
482 | new_layout = SRC_COMMAND; | |
c906108c SS |
483 | else |
484 | { | |
6ba8e26f AC |
485 | new_layout++; |
486 | if (new_layout == UNDEFINED_LAYOUT) | |
487 | new_layout = SRC_COMMAND; | |
c906108c SS |
488 | } |
489 | ||
570dc176 | 490 | return (enum tui_layout_type) new_layout; |
6ba8e26f | 491 | } |
c906108c SS |
492 | |
493 | ||
6ba8e26f | 494 | /* Answer the next layout to cycle to. */ |
2a8854a7 | 495 | static enum tui_layout_type |
6ba8e26f | 496 | prev_layout (void) |
c906108c | 497 | { |
570dc176 | 498 | int new_layout; |
c906108c | 499 | |
6ba8e26f AC |
500 | new_layout = tui_current_layout (); |
501 | if (new_layout == SRC_COMMAND) | |
502 | new_layout = DISASSEM_DATA_COMMAND; | |
c906108c SS |
503 | else |
504 | { | |
6ba8e26f AC |
505 | new_layout--; |
506 | if (new_layout == UNDEFINED_LAYOUT) | |
507 | new_layout = DISASSEM_DATA_COMMAND; | |
c906108c SS |
508 | } |
509 | ||
570dc176 | 510 | return (enum tui_layout_type) new_layout; |
6ba8e26f | 511 | } |
c906108c SS |
512 | |
513 | ||
514 | ||
82432e10 TT |
515 | static struct tui_win_info * |
516 | make_command_window (int height, int origin_y) | |
c906108c | 517 | { |
098f9ed4 | 518 | struct tui_win_info *result = new tui_cmd_window (); |
1e0c09ba | 519 | result->reset (height, tui_term_width (), 0, origin_y); |
098f9ed4 | 520 | tui_make_window (result, DONT_BOX_WINDOW); |
82432e10 | 521 | return result; |
6ba8e26f | 522 | } |
c906108c SS |
523 | |
524 | ||
ef5eab5a | 525 | /* make_source_window(). |
c5aa993b | 526 | */ |
0ed69eda TT |
527 | static struct tui_win_info * |
528 | make_source_window (int height, int origin_y) | |
c906108c | 529 | { |
098f9ed4 | 530 | tui_win_info *result = new tui_source_window (); |
1e0c09ba | 531 | result->reset (height, tui_term_width (), 0, origin_y); |
098f9ed4 TT |
532 | result->make_visible (true); |
533 | return result; | |
534 | } | |
c906108c SS |
535 | |
536 | ||
ef5eab5a | 537 | /* make_disasm_window(). |
c5aa993b | 538 | */ |
0ed69eda TT |
539 | static struct tui_win_info * |
540 | make_disasm_window (int height, int origin_y) | |
c906108c | 541 | { |
098f9ed4 | 542 | tui_win_info *result = new tui_disasm_window (); |
1e0c09ba | 543 | result->reset (height, tui_term_width (), 0, origin_y); |
098f9ed4 TT |
544 | result->make_visible (true); |
545 | return result; | |
546 | } | |
c906108c SS |
547 | |
548 | ||
098f9ed4 TT |
549 | static tui_win_info * |
550 | make_data_window (int height, int origin_y) | |
c906108c | 551 | { |
098f9ed4 | 552 | tui_win_info *result = new tui_data_window (); |
1e0c09ba | 553 | result->reset (height, tui_term_width (), 0, origin_y); |
098f9ed4 TT |
554 | result->make_visible (true); |
555 | return result; | |
6ba8e26f | 556 | } |
c906108c SS |
557 | |
558 | ||
559 | ||
6ba8e26f | 560 | /* Show the Source/Command layout. */ |
c906108c | 561 | static void |
6ba8e26f | 562 | show_source_command (void) |
c906108c | 563 | { |
6ba8e26f AC |
564 | show_source_or_disasm_and_command (SRC_COMMAND); |
565 | } | |
c906108c SS |
566 | |
567 | ||
6ba8e26f | 568 | /* Show the Dissassem/Command layout. */ |
c906108c | 569 | static void |
6ba8e26f | 570 | show_disasm_command (void) |
c906108c | 571 | { |
6ba8e26f AC |
572 | show_source_or_disasm_and_command (DISASSEM_COMMAND); |
573 | } | |
c906108c SS |
574 | |
575 | ||
6ba8e26f | 576 | /* Show the Source/Disassem/Command layout. */ |
c906108c | 577 | static void |
6ba8e26f | 578 | show_source_disasm_command (void) |
c906108c | 579 | { |
dd1abb8c | 580 | if (tui_current_layout () != SRC_DISASSEM_COMMAND) |
c906108c | 581 | { |
6ba8e26f | 582 | int cmd_height, src_height, asm_height; |
c906108c | 583 | |
6d012f14 | 584 | if (TUI_CMD_WIN != NULL) |
cb2ce893 | 585 | cmd_height = TUI_CMD_WIN->height; |
c906108c | 586 | else |
6ba8e26f | 587 | cmd_height = tui_term_height () / 3; |
c906108c | 588 | |
6ba8e26f AC |
589 | src_height = (tui_term_height () - cmd_height) / 2; |
590 | asm_height = tui_term_height () - (src_height + cmd_height); | |
c906108c | 591 | |
6d012f14 | 592 | if (TUI_SRC_WIN == NULL) |
e6e41501 | 593 | tui_win_list[SRC_WIN] = make_source_window (src_height, 0); |
c906108c SS |
594 | else |
595 | { | |
1e0c09ba | 596 | TUI_SRC_WIN->reset (src_height, |
098f9ed4 TT |
597 | tui_term_width (), |
598 | 0, | |
d6ba6a11 | 599 | 0); |
cb2ce893 | 600 | tui_make_visible (TUI_SRC_WIN); |
e6e41501 | 601 | TUI_SRC_WIN->m_has_locator = false; |
c906108c | 602 | } |
c906108c | 603 | |
3add462f TT |
604 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
605 | gdb_assert (locator != nullptr); | |
82432e10 TT |
606 | |
607 | tui_show_source_content (TUI_SRC_WIN); | |
608 | if (TUI_DISASM_WIN == NULL) | |
609 | { | |
e6e41501 TT |
610 | tui_win_list[DISASSEM_WIN] |
611 | = make_disasm_window (asm_height, src_height - 1); | |
4e1e56b9 TT |
612 | locator->reset (2 /* 1 */ , |
613 | tui_term_width (), | |
614 | 0, | |
615 | (src_height + asm_height) - 1); | |
82432e10 TT |
616 | } |
617 | else | |
618 | { | |
1e0c09ba | 619 | locator->reset (2 /* 1 */ , |
d6ba6a11 TT |
620 | tui_term_width (), |
621 | 0, | |
622 | (src_height + asm_height) - 1); | |
e6e41501 | 623 | TUI_DISASM_WIN->m_has_locator = true; |
1e0c09ba | 624 | TUI_DISASM_WIN->reset (asm_height, |
098f9ed4 TT |
625 | tui_term_width (), |
626 | 0, | |
d6ba6a11 | 627 | src_height - 1); |
cb2ce893 | 628 | tui_make_visible (TUI_DISASM_WIN); |
82432e10 | 629 | } |
e6e41501 TT |
630 | TUI_SRC_WIN->m_has_locator = false; |
631 | TUI_DISASM_WIN->m_has_locator = true; | |
82432e10 TT |
632 | tui_make_visible (locator); |
633 | tui_show_locator_content (); | |
634 | tui_show_source_content (TUI_DISASM_WIN); | |
635 | ||
636 | if (TUI_CMD_WIN == NULL) | |
81491aa0 TT |
637 | tui_win_list[CMD_WIN] |
638 | = make_command_window (cmd_height, tui_term_height () - cmd_height); | |
82432e10 TT |
639 | else |
640 | { | |
1e0c09ba | 641 | TUI_CMD_WIN->reset (TUI_CMD_WIN->height, |
d6ba6a11 TT |
642 | TUI_CMD_WIN->width, |
643 | 0, | |
644 | TUI_CMD_WIN->origin.y); | |
cb2ce893 | 645 | tui_make_visible (TUI_CMD_WIN); |
c906108c | 646 | } |
dd1abb8c | 647 | tui_set_current_layout_to (SRC_DISASSEM_COMMAND); |
c906108c | 648 | } |
6ba8e26f | 649 | } |
c906108c SS |
650 | |
651 | ||
6ba8e26f AC |
652 | /* Show the Source/Data/Command or the Dissassembly/Data/Command |
653 | layout. */ | |
c906108c | 654 | static void |
6ba8e26f | 655 | show_data (enum tui_layout_type new_layout) |
c906108c | 656 | { |
cb2ce893 | 657 | int total_height = (tui_term_height () - TUI_CMD_WIN->height); |
6ba8e26f AC |
658 | int src_height, data_height; |
659 | enum tui_win_type win_type; | |
c906108c | 660 | |
3add462f TT |
661 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
662 | gdb_assert (locator != nullptr); | |
c906108c | 663 | |
6ba8e26f AC |
664 | data_height = total_height / 2; |
665 | src_height = total_height - data_height; | |
ec7d9e56 AC |
666 | tui_make_all_invisible (); |
667 | tui_make_invisible (locator); | |
098f9ed4 TT |
668 | if (tui_win_list[DATA_WIN] == nullptr) |
669 | tui_win_list[DATA_WIN] = make_data_window (data_height, 0); | |
670 | else | |
671 | tui_win_list[DATA_WIN]->reset (data_height, tui_term_width (), 0, 0); | |
672 | tui_win_list[DATA_WIN]->make_visible (true); | |
673 | ||
6ba8e26f AC |
674 | if (new_layout == SRC_DATA_COMMAND) |
675 | win_type = SRC_WIN; | |
c906108c | 676 | else |
6ba8e26f | 677 | win_type = DISASSEM_WIN; |
e6e41501 TT |
678 | |
679 | tui_source_window_base *base; | |
6ba8e26f | 680 | if (tui_win_list[win_type] == NULL) |
c906108c | 681 | { |
6ba8e26f | 682 | if (win_type == SRC_WIN) |
0ed69eda TT |
683 | tui_win_list[win_type] |
684 | = make_source_window (src_height, data_height - 1); | |
c906108c | 685 | else |
0ed69eda TT |
686 | tui_win_list[win_type] |
687 | = make_disasm_window (src_height, data_height - 1); | |
4e1e56b9 TT |
688 | locator->reset (2 /* 1 */ , |
689 | tui_term_width (), | |
690 | 0, | |
691 | total_height - 1); | |
e6e41501 | 692 | base = (tui_source_window_base *) tui_win_list[win_type]; |
c906108c SS |
693 | } |
694 | else | |
695 | { | |
e6e41501 | 696 | base = (tui_source_window_base *) tui_win_list[win_type]; |
1e0c09ba | 697 | tui_win_list[win_type]->reset (src_height, |
098f9ed4 TT |
698 | tui_term_width (), |
699 | 0, | |
d6ba6a11 | 700 | data_height - 1); |
cb2ce893 | 701 | tui_make_visible (tui_win_list[win_type]); |
1e0c09ba | 702 | locator->reset (2 /* 1 */ , |
d6ba6a11 TT |
703 | tui_term_width (), |
704 | 0, | |
705 | total_height - 1); | |
c906108c | 706 | } |
e6e41501 | 707 | base->m_has_locator = true; |
ec7d9e56 | 708 | tui_make_visible (locator); |
47d3492a | 709 | tui_show_locator_content (); |
ad54d15b TT |
710 | tui_add_to_source_windows |
711 | ((tui_source_window_base *) tui_win_list[win_type]); | |
6ba8e26f AC |
712 | tui_set_current_layout_to (new_layout); |
713 | } | |
c906108c | 714 | |
d6ba6a11 | 715 | void |
1e0c09ba | 716 | tui_gen_win_info::reset (int height_, int width_, |
d6ba6a11 | 717 | int origin_x_, int origin_y_) |
c906108c | 718 | { |
d6ba6a11 TT |
719 | int h = height_; |
720 | ||
d6ba6a11 TT |
721 | width = width_; |
722 | height = h; | |
c906108c SS |
723 | if (h > 1) |
724 | { | |
d6ba6a11 TT |
725 | viewport_height = h - 1; |
726 | if (type != CMD_WIN) | |
727 | viewport_height--; | |
c906108c SS |
728 | } |
729 | else | |
d6ba6a11 TT |
730 | viewport_height = 1; |
731 | origin.x = origin_x_; | |
732 | origin.y = origin_y_; | |
733 | } | |
c906108c | 734 | |
1cc6d956 | 735 | /* Show the Source/Command or the Disassem layout. */ |
c906108c | 736 | static void |
6ba8e26f | 737 | show_source_or_disasm_and_command (enum tui_layout_type layout_type) |
c906108c | 738 | { |
6ba8e26f | 739 | if (tui_current_layout () != layout_type) |
c906108c | 740 | { |
5b6fe301 | 741 | struct tui_win_info **win_info_ptr; |
6ba8e26f | 742 | int src_height, cmd_height; |
3add462f TT |
743 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
744 | gdb_assert (locator != nullptr); | |
c906108c | 745 | |
6d012f14 | 746 | if (TUI_CMD_WIN != NULL) |
cb2ce893 | 747 | cmd_height = TUI_CMD_WIN->height; |
c906108c | 748 | else |
6ba8e26f AC |
749 | cmd_height = tui_term_height () / 3; |
750 | src_height = tui_term_height () - cmd_height; | |
c906108c | 751 | |
6ba8e26f | 752 | if (layout_type == SRC_COMMAND) |
e6e41501 | 753 | win_info_ptr = &tui_win_list[SRC_WIN]; |
c906108c | 754 | else |
e6e41501 | 755 | win_info_ptr = &tui_win_list[DISASSEM_WIN]; |
c906108c | 756 | |
e6e41501 | 757 | tui_source_window_base *base; |
6ba8e26f | 758 | if ((*win_info_ptr) == NULL) |
c906108c | 759 | { |
6ba8e26f | 760 | if (layout_type == SRC_COMMAND) |
0ed69eda | 761 | *win_info_ptr = make_source_window (src_height - 1, 0); |
c906108c | 762 | else |
0ed69eda | 763 | *win_info_ptr = make_disasm_window (src_height - 1, 0); |
4e1e56b9 TT |
764 | locator->reset (2 /* 1 */ , |
765 | tui_term_width (), | |
766 | 0, | |
767 | src_height - 1); | |
e6e41501 | 768 | base = (tui_source_window_base *) *win_info_ptr; |
c906108c SS |
769 | } |
770 | else | |
771 | { | |
e6e41501 | 772 | base = (tui_source_window_base *) *win_info_ptr; |
1e0c09ba | 773 | locator->reset (2 /* 1 */ , |
d6ba6a11 TT |
774 | tui_term_width (), |
775 | 0, | |
776 | src_height - 1); | |
e6e41501 | 777 | base->m_has_locator = true; |
1e0c09ba | 778 | (*win_info_ptr)->reset (src_height - 1, |
098f9ed4 TT |
779 | tui_term_width (), |
780 | 0, | |
d6ba6a11 | 781 | 0); |
cb2ce893 | 782 | tui_make_visible (*win_info_ptr); |
c906108c | 783 | } |
c906108c | 784 | |
6a0ee02c TT |
785 | base->m_has_locator = true; |
786 | tui_make_visible (locator); | |
787 | tui_show_locator_content (); | |
7908abbf | 788 | tui_show_source_content (base); |
6a0ee02c TT |
789 | |
790 | if (TUI_CMD_WIN == NULL) | |
791 | { | |
792 | tui_win_list[CMD_WIN] = make_command_window (cmd_height, | |
793 | src_height); | |
6a0ee02c TT |
794 | } |
795 | else | |
796 | { | |
1e0c09ba | 797 | TUI_CMD_WIN->reset (TUI_CMD_WIN->height, |
d6ba6a11 TT |
798 | TUI_CMD_WIN->width, |
799 | TUI_CMD_WIN->origin.x, | |
800 | TUI_CMD_WIN->origin.y); | |
cb2ce893 | 801 | tui_make_visible (TUI_CMD_WIN); |
c906108c | 802 | } |
6ba8e26f | 803 | tui_set_current_layout_to (layout_type); |
c906108c | 804 | } |
6ba8e26f | 805 | } |