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