Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
5 | Contributed by Hewlett-Packard Company. |
6 | ||
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 | 21 | |
96ec9981 DJ |
22 | #include "defs.h" |
23 | #include "symtab.h" | |
d7b2e967 AC |
24 | #include "tui/tui.h" |
25 | #include "tui/tui-data.h" | |
26 | #include "tui/tui-wingeneral.h" | |
6a83354a | 27 | #include "gdb_curses.h" |
4e8f7a8b | 28 | |
c906108c SS |
29 | /**************************** |
30 | ** GLOBAL DECLARATIONS | |
31 | ****************************/ | |
7fa29be9 | 32 | struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; |
c906108c | 33 | |
c906108c SS |
34 | /*************************** |
35 | ** Private data | |
36 | ****************************/ | |
6ba8e26f AC |
37 | static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; |
38 | static int term_height, term_width; | |
2a8854a7 | 39 | static struct tui_gen_win_info _locator; |
6ba8e26f | 40 | static struct tui_gen_win_info exec_info[2]; |
5b6fe301 | 41 | static struct tui_win_info *src_win_list[2]; |
96c1eda2 | 42 | static struct tui_list source_windows = {src_win_list, 0}; |
e65b5245 | 43 | static struct tui_win_info *win_with_focus = NULL; |
08ef48c5 MS |
44 | static struct tui_layout_def layout_def = { |
45 | SRC_WIN, /* DISPLAY_MODE */ | |
7bd0be3a | 46 | FALSE}; /* SPLIT */ |
08ef48c5 | 47 | |
6ba8e26f | 48 | static int win_resized = FALSE; |
c906108c SS |
49 | |
50 | ||
51 | /********************************* | |
52 | ** Static function forward decls | |
53 | **********************************/ | |
08ef48c5 MS |
54 | static void free_content (tui_win_content, |
55 | int, | |
56 | enum tui_win_type); | |
57 | static void free_content_elements (tui_win_content, | |
58 | int, | |
59 | enum tui_win_type); | |
c906108c SS |
60 | |
61 | ||
62 | ||
63 | /********************************* | |
64 | ** PUBLIC FUNCTIONS | |
65 | **********************************/ | |
66 | ||
6d012f14 AC |
67 | int |
68 | tui_win_is_source_type (enum tui_win_type win_type) | |
69 | { | |
70 | return (win_type == SRC_WIN || win_type == DISASSEM_WIN); | |
71 | } | |
72 | ||
73 | int | |
74 | tui_win_is_auxillary (enum tui_win_type win_type) | |
75 | { | |
76 | return (win_type > MAX_MAJOR_WINDOWS); | |
77 | } | |
78 | ||
79 | int | |
80 | tui_win_has_locator (struct tui_win_info *win_info) | |
81 | { | |
08ef48c5 | 82 | return (win_info != NULL |
6d012f14 AC |
83 | && win_info->detail.source_info.has_locator); |
84 | } | |
85 | ||
86 | void | |
08ef48c5 MS |
87 | tui_set_win_highlight (struct tui_win_info *win_info, |
88 | int highlight) | |
6d012f14 AC |
89 | { |
90 | if (win_info != NULL) | |
91 | win_info->is_highlighted = highlight; | |
92 | } | |
93 | ||
c906108c SS |
94 | /****************************************** |
95 | ** ACCESSORS & MUTATORS FOR PRIVATE DATA | |
96 | ******************************************/ | |
97 | ||
1cc6d956 | 98 | /* Answer a whether the terminal window has been resized or not. */ |
c906108c | 99 | int |
dd1abb8c | 100 | tui_win_resized (void) |
c906108c | 101 | { |
6ba8e26f | 102 | return win_resized; |
dd1abb8c | 103 | } |
c906108c SS |
104 | |
105 | ||
1cc6d956 | 106 | /* Set a whether the terminal window has been resized or not. */ |
c906108c | 107 | void |
dd1abb8c | 108 | tui_set_win_resized_to (int resized) |
c906108c | 109 | { |
6ba8e26f | 110 | win_resized = resized; |
dd1abb8c | 111 | } |
c906108c SS |
112 | |
113 | ||
1cc6d956 | 114 | /* Answer a pointer to the current layout definition. */ |
2a8854a7 | 115 | struct tui_layout_def * |
dd1abb8c | 116 | tui_layout_def (void) |
c906108c | 117 | { |
6ba8e26f | 118 | return &layout_def; |
dd1abb8c | 119 | } |
c906108c SS |
120 | |
121 | ||
1cc6d956 | 122 | /* Answer the window with the logical focus. */ |
2a8854a7 | 123 | struct tui_win_info * |
dd1abb8c | 124 | tui_win_with_focus (void) |
c906108c | 125 | { |
6ba8e26f | 126 | return win_with_focus; |
dd1abb8c | 127 | } |
c906108c SS |
128 | |
129 | ||
1cc6d956 | 130 | /* Set the window that has the logical focus. */ |
c906108c | 131 | void |
5b6fe301 | 132 | tui_set_win_with_focus (struct tui_win_info *win_info) |
c906108c | 133 | { |
6ba8e26f | 134 | win_with_focus = win_info; |
dd1abb8c | 135 | } |
c906108c SS |
136 | |
137 | ||
6ba8e26f AC |
138 | /* Accessor for the current source window. Usually there is only one |
139 | source window (either source or disassembly), but both can be | |
140 | displayed at the same time. */ | |
2a8854a7 | 141 | struct tui_list * |
dd1abb8c | 142 | tui_source_windows (void) |
c906108c | 143 | { |
6ba8e26f | 144 | return &source_windows; |
dd1abb8c | 145 | } |
c906108c SS |
146 | |
147 | ||
dd1abb8c AC |
148 | /* Clear the list of source windows. Usually there is only one source |
149 | window (either source or disassembly), but both can be displayed at | |
150 | the same time. */ | |
c906108c | 151 | void |
dd1abb8c | 152 | tui_clear_source_windows (void) |
c906108c | 153 | { |
6ba8e26f AC |
154 | source_windows.list[0] = NULL; |
155 | source_windows.list[1] = NULL; | |
156 | source_windows.count = 0; | |
dd1abb8c | 157 | } |
c906108c SS |
158 | |
159 | ||
1cc6d956 | 160 | /* Clear the pertinant detail in the source windows. */ |
c906108c | 161 | void |
dd1abb8c | 162 | tui_clear_source_windows_detail (void) |
c906108c SS |
163 | { |
164 | int i; | |
165 | ||
dd1abb8c | 166 | for (i = 0; i < (tui_source_windows ())->count; i++) |
96c1eda2 | 167 | tui_clear_win_detail ((tui_source_windows ())->list[i]); |
dd1abb8c | 168 | } |
c906108c SS |
169 | |
170 | ||
dd1abb8c AC |
171 | /* Add a window to the list of source windows. Usually there is only |
172 | one source window (either source or disassembly), but both can be | |
173 | displayed at the same time. */ | |
c906108c | 174 | void |
5b6fe301 | 175 | tui_add_to_source_windows (struct tui_win_info *win_info) |
c906108c | 176 | { |
6ba8e26f | 177 | if (source_windows.count < 2) |
f4ee58bd | 178 | source_windows.list[source_windows.count++] = win_info; |
dd1abb8c | 179 | } |
c906108c SS |
180 | |
181 | ||
1cc6d956 | 182 | /* Clear the pertinant detail in the windows. */ |
c906108c | 183 | void |
5b6fe301 | 184 | tui_clear_win_detail (struct tui_win_info *win_info) |
c906108c | 185 | { |
6d012f14 | 186 | if (win_info != NULL) |
c906108c | 187 | { |
6d012f14 | 188 | switch (win_info->generic.type) |
c906108c SS |
189 | { |
190 | case SRC_WIN: | |
191 | case DISASSEM_WIN: | |
13274fc3 | 192 | win_info->detail.source_info.gdbarch = NULL; |
362c05fe AS |
193 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
194 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
6d012f14 | 195 | win_info->detail.source_info.horizontal_offset = 0; |
c906108c SS |
196 | break; |
197 | case CMD_WIN: | |
6f1cb6ea | 198 | wmove (win_info->generic.handle, 0, 0); |
c906108c SS |
199 | break; |
200 | case DATA_WIN: | |
6d012f14 | 201 | win_info->detail.data_display_info.data_content = |
2a8854a7 | 202 | (tui_win_content) NULL; |
6d012f14 AC |
203 | win_info->detail.data_display_info.data_content_count = 0; |
204 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 205 | (tui_win_content) NULL; |
6d012f14 | 206 | win_info->detail.data_display_info.regs_content_count = 0; |
6d012f14 AC |
207 | win_info->detail.data_display_info.regs_column_count = 1; |
208 | win_info->detail.data_display_info.display_regs = FALSE; | |
c906108c SS |
209 | break; |
210 | default: | |
211 | break; | |
212 | } | |
213 | } | |
6ba8e26f | 214 | } |
c906108c SS |
215 | |
216 | ||
6ba8e26f | 217 | /* Accessor for the source execution info ptr. */ |
2a8854a7 | 218 | struct tui_gen_win_info * |
dd1abb8c | 219 | tui_source_exec_info_win_ptr (void) |
c906108c | 220 | { |
6ba8e26f AC |
221 | return &exec_info[0]; |
222 | } | |
c906108c SS |
223 | |
224 | ||
6ba8e26f | 225 | /* Accessor for the disassem execution info ptr. */ |
2a8854a7 | 226 | struct tui_gen_win_info * |
dd1abb8c | 227 | tui_disassem_exec_info_win_ptr (void) |
c906108c | 228 | { |
6ba8e26f AC |
229 | return &exec_info[1]; |
230 | } | |
c906108c SS |
231 | |
232 | ||
dd1abb8c AC |
233 | /* Accessor for the locator win info. Answers a pointer to the static |
234 | locator win info struct. */ | |
2a8854a7 | 235 | struct tui_gen_win_info * |
dd1abb8c | 236 | tui_locator_win_info_ptr (void) |
c906108c SS |
237 | { |
238 | return &_locator; | |
2a8854a7 | 239 | } |
c906108c SS |
240 | |
241 | ||
6ba8e26f | 242 | /* Accessor for the term_height. */ |
c906108c | 243 | int |
dd1abb8c | 244 | tui_term_height (void) |
c906108c | 245 | { |
6ba8e26f | 246 | return term_height; |
dd1abb8c | 247 | } |
c906108c SS |
248 | |
249 | ||
1cc6d956 | 250 | /* Mutator for the term height. */ |
c906108c | 251 | void |
dd1abb8c | 252 | tui_set_term_height_to (int h) |
c906108c | 253 | { |
6ba8e26f | 254 | term_height = h; |
dd1abb8c | 255 | } |
c906108c SS |
256 | |
257 | ||
1cc6d956 | 258 | /* Accessor for the term_width. */ |
c906108c | 259 | int |
dd1abb8c | 260 | tui_term_width (void) |
c906108c | 261 | { |
6ba8e26f | 262 | return term_width; |
dd1abb8c | 263 | } |
c906108c SS |
264 | |
265 | ||
6ba8e26f | 266 | /* Mutator for the term_width. */ |
c906108c | 267 | void |
dd1abb8c | 268 | tui_set_term_width_to (int w) |
c906108c | 269 | { |
6ba8e26f | 270 | term_width = w; |
dd1abb8c | 271 | } |
c906108c SS |
272 | |
273 | ||
1cc6d956 | 274 | /* Accessor for the current layout. */ |
2a8854a7 | 275 | enum tui_layout_type |
dd1abb8c | 276 | tui_current_layout (void) |
c906108c | 277 | { |
6ba8e26f | 278 | return current_layout; |
dd1abb8c | 279 | } |
c906108c SS |
280 | |
281 | ||
dd1abb8c | 282 | /* Mutator for the current layout. */ |
c906108c | 283 | void |
6ba8e26f | 284 | tui_set_current_layout_to (enum tui_layout_type new_layout) |
c906108c | 285 | { |
6ba8e26f | 286 | current_layout = new_layout; |
dd1abb8c | 287 | } |
c906108c SS |
288 | |
289 | ||
c906108c SS |
290 | /***************************** |
291 | ** OTHER PUBLIC FUNCTIONS | |
292 | *****************************/ | |
293 | ||
294 | ||
dd1abb8c AC |
295 | /* Answer the next window in the list, cycling back to the top if |
296 | necessary. */ | |
2a8854a7 | 297 | struct tui_win_info * |
5b6fe301 | 298 | tui_next_win (struct tui_win_info *cur_win) |
c906108c | 299 | { |
570dc176 | 300 | int type = cur_win->generic.type; |
e65b5245 | 301 | struct tui_win_info *next_win = NULL; |
c906108c | 302 | |
6ba8e26f | 303 | if (cur_win->generic.type == CMD_WIN) |
c906108c SS |
304 | type = SRC_WIN; |
305 | else | |
6ba8e26f AC |
306 | type = cur_win->generic.type + 1; |
307 | while (type != cur_win->generic.type && (next_win == NULL)) | |
c906108c | 308 | { |
e5908723 MS |
309 | if (tui_win_list[type] |
310 | && tui_win_list[type]->generic.is_visible) | |
6ba8e26f | 311 | next_win = tui_win_list[type]; |
c906108c SS |
312 | else |
313 | { | |
314 | if (type == CMD_WIN) | |
315 | type = SRC_WIN; | |
316 | else | |
317 | type++; | |
318 | } | |
319 | } | |
320 | ||
6ba8e26f AC |
321 | return next_win; |
322 | } | |
c906108c SS |
323 | |
324 | ||
dd1abb8c AC |
325 | /* Answer the prev window in the list, cycling back to the bottom if |
326 | necessary. */ | |
2a8854a7 | 327 | struct tui_win_info * |
5b6fe301 | 328 | tui_prev_win (struct tui_win_info *cur_win) |
c906108c | 329 | { |
570dc176 | 330 | int type = cur_win->generic.type; |
e65b5245 | 331 | struct tui_win_info *prev = NULL; |
c906108c | 332 | |
6ba8e26f | 333 | if (cur_win->generic.type == SRC_WIN) |
c906108c SS |
334 | type = CMD_WIN; |
335 | else | |
6ba8e26f AC |
336 | type = cur_win->generic.type - 1; |
337 | while (type != cur_win->generic.type && (prev == NULL)) | |
c906108c | 338 | { |
37715c4c TJB |
339 | if (tui_win_list[type] |
340 | && tui_win_list[type]->generic.is_visible) | |
6d012f14 | 341 | prev = tui_win_list[type]; |
c906108c SS |
342 | else |
343 | { | |
344 | if (type == SRC_WIN) | |
345 | type = CMD_WIN; | |
346 | else | |
347 | type--; | |
348 | } | |
349 | } | |
350 | ||
351 | return prev; | |
cb50eddd | 352 | } |
c906108c SS |
353 | |
354 | ||
1cc6d956 | 355 | /* Answer the window represented by name. */ |
2a8854a7 | 356 | struct tui_win_info * |
a121b7c1 | 357 | tui_partial_win_by_name (const char *name) |
c906108c | 358 | { |
e65b5245 | 359 | struct tui_win_info *win_info = NULL; |
c906108c | 360 | |
63a33118 | 361 | if (name != NULL) |
c906108c SS |
362 | { |
363 | int i = 0; | |
364 | ||
6d012f14 | 365 | while (i < MAX_MAJOR_WINDOWS && win_info == NULL) |
c906108c | 366 | { |
6d012f14 | 367 | if (tui_win_list[i] != 0) |
a4b99e53 | 368 | { |
f41cbf58 AB |
369 | const char *cur_name = |
370 | tui_win_name (&tui_win_list[i]->generic); | |
1c5313c5 | 371 | |
e5908723 | 372 | if (strlen (name) <= strlen (cur_name) |
61012eef | 373 | && startswith (cur_name, name)) |
6d012f14 | 374 | win_info = tui_win_list[i]; |
a4b99e53 | 375 | } |
c906108c SS |
376 | i++; |
377 | } | |
378 | } | |
379 | ||
6d012f14 | 380 | return win_info; |
6ba8e26f | 381 | } |
c906108c SS |
382 | |
383 | ||
6ba8e26f | 384 | /* Answer the name of the window. */ |
f41cbf58 AB |
385 | const char * |
386 | tui_win_name (const struct tui_gen_win_info *win_info) | |
c906108c | 387 | { |
136765ea | 388 | const char *name = NULL; |
c906108c | 389 | |
6d012f14 | 390 | switch (win_info->type) |
c906108c SS |
391 | { |
392 | case SRC_WIN: | |
393 | name = SRC_NAME; | |
394 | break; | |
395 | case CMD_WIN: | |
396 | name = CMD_NAME; | |
397 | break; | |
398 | case DISASSEM_WIN: | |
399 | name = DISASSEM_NAME; | |
400 | break; | |
401 | case DATA_WIN: | |
402 | name = DATA_NAME; | |
403 | break; | |
404 | default: | |
405 | name = ""; | |
406 | break; | |
407 | } | |
408 | ||
409 | return name; | |
6ba8e26f | 410 | } |
c906108c SS |
411 | |
412 | ||
c906108c | 413 | void |
dd1abb8c | 414 | tui_initialize_static_data (void) |
c906108c | 415 | { |
dd1abb8c AC |
416 | tui_init_generic_part (tui_source_exec_info_win_ptr ()); |
417 | tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); | |
418 | tui_init_generic_part (tui_locator_win_info_ptr ()); | |
419 | } | |
c906108c SS |
420 | |
421 | ||
2a8854a7 | 422 | struct tui_gen_win_info * |
dd1abb8c | 423 | tui_alloc_generic_win_info (void) |
c906108c | 424 | { |
8d749320 | 425 | struct tui_gen_win_info *win = XNEW (struct tui_gen_win_info); |
c906108c | 426 | |
730ead81 | 427 | tui_init_generic_part (win); |
c906108c SS |
428 | |
429 | return win; | |
6ba8e26f | 430 | } |
c906108c SS |
431 | |
432 | ||
c906108c | 433 | void |
5b6fe301 | 434 | tui_init_generic_part (struct tui_gen_win_info *win) |
c906108c SS |
435 | { |
436 | win->width = | |
437 | win->height = | |
438 | win->origin.x = | |
439 | win->origin.y = | |
6d012f14 AC |
440 | win->viewport_height = |
441 | win->content_size = | |
442 | win->last_visible_line = 0; | |
e65b5245 | 443 | win->handle = NULL; |
22940a24 | 444 | win->content = NULL; |
6d012f14 AC |
445 | win->content_in_use = |
446 | win->is_visible = FALSE; | |
bc6b7f04 SC |
447 | win->title = 0; |
448 | } | |
c906108c SS |
449 | |
450 | ||
ef5eab5a | 451 | /* init_content_element(). |
c5aa993b | 452 | */ |
2c0b251b | 453 | static void |
08ef48c5 MS |
454 | init_content_element (struct tui_win_element *element, |
455 | enum tui_win_type type) | |
c906108c | 456 | { |
c906108c SS |
457 | switch (type) |
458 | { | |
459 | case SRC_WIN: | |
460 | case DISASSEM_WIN: | |
e65b5245 | 461 | element->which_element.source.line = NULL; |
362c05fe AS |
462 | element->which_element.source.line_or_addr.loa = LOA_LINE; |
463 | element->which_element.source.line_or_addr.u.line_no = 0; | |
6d012f14 AC |
464 | element->which_element.source.is_exec_point = FALSE; |
465 | element->which_element.source.has_break = FALSE; | |
c906108c SS |
466 | break; |
467 | case DATA_WIN: | |
6d012f14 AC |
468 | tui_init_generic_part (&element->which_element.data_window); |
469 | element->which_element.data_window.type = DATA_ITEM_WIN; | |
63ed8182 PP |
470 | element->which_element.data_window.content = |
471 | tui_alloc_content (1, DATA_ITEM_WIN); | |
472 | element->which_element.data_window.content_size = 1; | |
c906108c SS |
473 | break; |
474 | case CMD_WIN: | |
e65b5245 | 475 | element->which_element.command.line = NULL; |
c906108c SS |
476 | break; |
477 | case DATA_ITEM_WIN: | |
e65b5245 | 478 | element->which_element.data.name = NULL; |
6d012f14 AC |
479 | element->which_element.data.type = TUI_REGISTER; |
480 | element->which_element.data.item_no = UNDEFINED_ITEM; | |
481 | element->which_element.data.value = NULL; | |
482 | element->which_element.data.highlight = FALSE; | |
e65b5245 | 483 | element->which_element.data.content = NULL; |
c906108c SS |
484 | break; |
485 | case LOCATOR_WIN: | |
56d397a3 | 486 | element->which_element.locator.full_name[0] = |
6d012f14 AC |
487 | element->which_element.locator.proc_name[0] = (char) 0; |
488 | element->which_element.locator.line_no = 0; | |
489 | element->which_element.locator.addr = 0; | |
c906108c SS |
490 | break; |
491 | case EXEC_INFO_WIN: | |
6d012f14 AC |
492 | memset(element->which_element.simple_string, ' ', |
493 | sizeof(element->which_element.simple_string)); | |
c906108c SS |
494 | break; |
495 | default: | |
496 | break; | |
497 | } | |
6ba8e26f | 498 | } |
c906108c | 499 | |
2c0b251b | 500 | static void |
5b6fe301 | 501 | init_win_info (struct tui_win_info *win_info) |
c906108c | 502 | { |
6d012f14 AC |
503 | tui_init_generic_part (&win_info->generic); |
504 | win_info->can_highlight = | |
505 | win_info->is_highlighted = FALSE; | |
506 | switch (win_info->generic.type) | |
c906108c SS |
507 | { |
508 | case SRC_WIN: | |
509 | case DISASSEM_WIN: | |
9a2b4c1b MS |
510 | win_info->detail.source_info.execution_info |
511 | = (struct tui_gen_win_info *) NULL; | |
6d012f14 AC |
512 | win_info->detail.source_info.has_locator = FALSE; |
513 | win_info->detail.source_info.horizontal_offset = 0; | |
13274fc3 | 514 | win_info->detail.source_info.gdbarch = NULL; |
362c05fe AS |
515 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
516 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
aa079c93 | 517 | win_info->detail.source_info.fullname = NULL; |
c906108c SS |
518 | break; |
519 | case DATA_WIN: | |
6d012f14 AC |
520 | win_info->detail.data_display_info.data_content = (tui_win_content) NULL; |
521 | win_info->detail.data_display_info.data_content_count = 0; | |
522 | win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; | |
523 | win_info->detail.data_display_info.regs_content_count = 0; | |
6d012f14 AC |
524 | win_info->detail.data_display_info.regs_column_count = 1; |
525 | win_info->detail.data_display_info.display_regs = FALSE; | |
10f59415 | 526 | win_info->detail.data_display_info.current_group = 0; |
c906108c SS |
527 | break; |
528 | case CMD_WIN: | |
c906108c | 529 | break; |
c906108c | 530 | } |
6ba8e26f | 531 | } |
c906108c SS |
532 | |
533 | ||
2a8854a7 | 534 | struct tui_win_info * |
22940a24 | 535 | tui_alloc_win_info (enum tui_win_type type) |
c906108c | 536 | { |
8d749320 | 537 | struct tui_win_info *win_info = XNEW (struct tui_win_info); |
c906108c | 538 | |
730ead81 TT |
539 | win_info->generic.type = type; |
540 | init_win_info (win_info); | |
c906108c | 541 | |
6d012f14 | 542 | return win_info; |
6ba8e26f | 543 | } |
c906108c SS |
544 | |
545 | ||
6ba8e26f | 546 | /* Allocates the content and elements in a block. */ |
2a8854a7 | 547 | tui_win_content |
6ba8e26f | 548 | tui_alloc_content (int num_elements, enum tui_win_type type) |
c906108c | 549 | { |
c0645fb5 | 550 | tui_win_content content; |
7acd011b | 551 | struct tui_win_element *element_block_ptr; |
c906108c SS |
552 | int i; |
553 | ||
8d749320 | 554 | content = XNEWVEC (struct tui_win_element *, num_elements); |
7acd011b SM |
555 | |
556 | /* | |
557 | * All windows, except the data window, can allocate the | |
558 | * elements in a chunk. The data window cannot because items | |
559 | * can be added/removed from the data display by the user at any | |
560 | * time. | |
561 | */ | |
562 | if (type != DATA_WIN) | |
c0645fb5 | 563 | { |
7acd011b SM |
564 | element_block_ptr = XNEWVEC (struct tui_win_element, num_elements); |
565 | for (i = 0; i < num_elements; i++) | |
c906108c | 566 | { |
7acd011b SM |
567 | content[i] = element_block_ptr; |
568 | init_content_element (content[i], type); | |
569 | element_block_ptr++; | |
c906108c SS |
570 | } |
571 | } | |
572 | ||
573 | return content; | |
6ba8e26f | 574 | } |
c906108c SS |
575 | |
576 | ||
dd1abb8c | 577 | /* Adds the input number of elements to the windows's content. If no |
6ba8e26f | 578 | content has been allocated yet, alloc_content() is called to do |
dd1abb8c AC |
579 | this. The index of the first element added is returned, unless |
580 | there is a memory allocation error, in which case, (-1) is | |
581 | returned. */ | |
c906108c | 582 | int |
08ef48c5 MS |
583 | tui_add_content_elements (struct tui_gen_win_info *win_info, |
584 | int num_elements) | |
c906108c | 585 | { |
5b6fe301 | 586 | struct tui_win_element *element_ptr; |
6ba8e26f | 587 | int i, index_start; |
c906108c | 588 | |
6d012f14 | 589 | if (win_info->content == NULL) |
c906108c | 590 | { |
63ed8182 | 591 | win_info->content = tui_alloc_content (num_elements, win_info->type); |
6ba8e26f | 592 | index_start = 0; |
c906108c SS |
593 | } |
594 | else | |
6ba8e26f | 595 | index_start = win_info->content_size; |
6d012f14 | 596 | if (win_info->content != NULL) |
c906108c | 597 | { |
6ba8e26f | 598 | for (i = index_start; (i < num_elements + index_start); i++) |
c906108c | 599 | { |
8d749320 | 600 | element_ptr = XNEW (struct tui_win_element); |
730ead81 TT |
601 | win_info->content[i] = element_ptr; |
602 | init_content_element (element_ptr, win_info->type); | |
603 | win_info->content_size++; | |
c906108c SS |
604 | } |
605 | } | |
606 | ||
6ba8e26f AC |
607 | return index_start; |
608 | } | |
c906108c SS |
609 | |
610 | ||
1cc6d956 MS |
611 | /* Delete all curses windows associated with win_info, leaving |
612 | everything else intact. */ | |
c906108c | 613 | void |
5b6fe301 | 614 | tui_del_window (struct tui_win_info *win_info) |
c906108c | 615 | { |
5b6fe301 | 616 | struct tui_gen_win_info *generic_win; |
c906108c | 617 | |
6d012f14 | 618 | switch (win_info->generic.type) |
c906108c SS |
619 | { |
620 | case SRC_WIN: | |
621 | case DISASSEM_WIN: | |
6ba8e26f AC |
622 | generic_win = tui_locator_win_info_ptr (); |
623 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 624 | { |
6ba8e26f | 625 | tui_delete_win (generic_win->handle); |
e65b5245 | 626 | generic_win->handle = NULL; |
6ba8e26f | 627 | generic_win->is_visible = FALSE; |
c906108c | 628 | } |
aa079c93 | 629 | if (win_info->detail.source_info.fullname) |
bc6b7f04 | 630 | { |
aa079c93 JK |
631 | xfree (win_info->detail.source_info.fullname); |
632 | win_info->detail.source_info.fullname = NULL; | |
bc6b7f04 | 633 | } |
6ba8e26f AC |
634 | generic_win = win_info->detail.source_info.execution_info; |
635 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 636 | { |
6ba8e26f | 637 | tui_delete_win (generic_win->handle); |
e65b5245 | 638 | generic_win->handle = NULL; |
6ba8e26f | 639 | generic_win->is_visible = FALSE; |
c906108c SS |
640 | } |
641 | break; | |
642 | case DATA_WIN: | |
6d012f14 | 643 | if (win_info->generic.content != NULL) |
c906108c | 644 | { |
6d012f14 AC |
645 | tui_del_data_windows (win_info->detail.data_display_info.regs_content, |
646 | win_info->detail.data_display_info.regs_content_count); | |
647 | tui_del_data_windows (win_info->detail.data_display_info.data_content, | |
648 | win_info->detail.data_display_info.data_content_count); | |
c906108c SS |
649 | } |
650 | break; | |
651 | default: | |
652 | break; | |
653 | } | |
6d012f14 | 654 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 655 | { |
6d012f14 | 656 | tui_delete_win (win_info->generic.handle); |
e65b5245 | 657 | win_info->generic.handle = NULL; |
6d012f14 | 658 | win_info->generic.is_visible = FALSE; |
c906108c | 659 | } |
bc6b7f04 | 660 | } |
c906108c SS |
661 | |
662 | ||
c906108c | 663 | void |
5b6fe301 | 664 | tui_free_window (struct tui_win_info *win_info) |
c906108c | 665 | { |
5b6fe301 | 666 | struct tui_gen_win_info *generic_win; |
c906108c | 667 | |
6d012f14 | 668 | switch (win_info->generic.type) |
c906108c SS |
669 | { |
670 | case SRC_WIN: | |
671 | case DISASSEM_WIN: | |
aa079c93 | 672 | if (win_info->detail.source_info.fullname) |
bc6b7f04 | 673 | { |
aa079c93 JK |
674 | xfree (win_info->detail.source_info.fullname); |
675 | win_info->detail.source_info.fullname = NULL; | |
bc6b7f04 | 676 | } |
6ba8e26f AC |
677 | generic_win = win_info->detail.source_info.execution_info; |
678 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 679 | { |
6ba8e26f | 680 | tui_delete_win (generic_win->handle); |
e65b5245 | 681 | generic_win->handle = NULL; |
6ba8e26f | 682 | tui_free_win_content (generic_win); |
c906108c SS |
683 | } |
684 | break; | |
685 | case DATA_WIN: | |
6d012f14 | 686 | if (win_info->generic.content != NULL) |
c906108c | 687 | { |
6d012f14 AC |
688 | tui_free_data_content (win_info->detail.data_display_info.regs_content, |
689 | win_info->detail.data_display_info.regs_content_count); | |
690 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 691 | (tui_win_content) NULL; |
6d012f14 AC |
692 | win_info->detail.data_display_info.regs_content_count = 0; |
693 | tui_free_data_content (win_info->detail.data_display_info.data_content, | |
694 | win_info->detail.data_display_info.data_content_count); | |
695 | win_info->detail.data_display_info.data_content = | |
2a8854a7 | 696 | (tui_win_content) NULL; |
6d012f14 | 697 | win_info->detail.data_display_info.data_content_count = 0; |
6d012f14 AC |
698 | win_info->detail.data_display_info.regs_column_count = 1; |
699 | win_info->detail.data_display_info.display_regs = FALSE; | |
700 | win_info->generic.content = NULL; | |
701 | win_info->generic.content_size = 0; | |
c906108c SS |
702 | } |
703 | break; | |
704 | default: | |
705 | break; | |
706 | } | |
6d012f14 | 707 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 708 | { |
6d012f14 | 709 | tui_delete_win (win_info->generic.handle); |
e65b5245 | 710 | win_info->generic.handle = NULL; |
6d012f14 | 711 | tui_free_win_content (&win_info->generic); |
c906108c | 712 | } |
6d012f14 AC |
713 | if (win_info->generic.title) |
714 | xfree (win_info->generic.title); | |
715 | xfree (win_info); | |
bc6b7f04 | 716 | } |
c906108c SS |
717 | |
718 | ||
c906108c | 719 | void |
dd1abb8c | 720 | tui_free_all_source_wins_content (void) |
c906108c SS |
721 | { |
722 | int i; | |
723 | ||
dd1abb8c | 724 | for (i = 0; i < (tui_source_windows ())->count; i++) |
c906108c | 725 | { |
5b6fe301 | 726 | struct tui_win_info *win_info = (tui_source_windows ())->list[i]; |
c906108c | 727 | |
6d012f14 | 728 | if (win_info != NULL) |
c906108c | 729 | { |
6d012f14 AC |
730 | tui_free_win_content (&(win_info->generic)); |
731 | tui_free_win_content (win_info->detail.source_info.execution_info); | |
c906108c SS |
732 | } |
733 | } | |
dd1abb8c | 734 | } |
c906108c SS |
735 | |
736 | ||
c906108c | 737 | void |
5b6fe301 | 738 | tui_free_win_content (struct tui_gen_win_info *win_info) |
c906108c | 739 | { |
6d012f14 | 740 | if (win_info->content != NULL) |
c906108c | 741 | { |
63a33118 | 742 | free_content (win_info->content, |
6d012f14 AC |
743 | win_info->content_size, |
744 | win_info->type); | |
745 | win_info->content = NULL; | |
c906108c | 746 | } |
6d012f14 | 747 | win_info->content_size = 0; |
6ba8e26f | 748 | } |
c906108c SS |
749 | |
750 | ||
c906108c | 751 | void |
08ef48c5 MS |
752 | tui_del_data_windows (tui_win_content content, |
753 | int content_size) | |
c906108c SS |
754 | { |
755 | int i; | |
756 | ||
ef5eab5a MS |
757 | /* Remember that data window content elements are of type struct |
758 | tui_gen_win_info *, each of which whose single element is a data | |
759 | element. */ | |
6ba8e26f | 760 | for (i = 0; i < content_size; i++) |
c906108c | 761 | { |
9a2b4c1b MS |
762 | struct tui_gen_win_info *generic_win |
763 | = &content[i]->which_element.data_window; | |
c906108c | 764 | |
6ba8e26f | 765 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 766 | { |
6ba8e26f | 767 | tui_delete_win (generic_win->handle); |
e65b5245 | 768 | generic_win->handle = NULL; |
6ba8e26f | 769 | generic_win->is_visible = FALSE; |
c906108c SS |
770 | } |
771 | } | |
dd1abb8c | 772 | } |
c906108c SS |
773 | |
774 | ||
775 | void | |
08ef48c5 MS |
776 | tui_free_data_content (tui_win_content content, |
777 | int content_size) | |
c906108c SS |
778 | { |
779 | int i; | |
780 | ||
ef5eab5a MS |
781 | /* Remember that data window content elements are of type struct |
782 | tui_gen_win_info *, each of which whose single element is a data | |
783 | element. */ | |
6ba8e26f | 784 | for (i = 0; i < content_size; i++) |
c906108c | 785 | { |
9a2b4c1b MS |
786 | struct tui_gen_win_info *generic_win |
787 | = &content[i]->which_element.data_window; | |
c906108c | 788 | |
6ba8e26f | 789 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 790 | { |
6ba8e26f | 791 | tui_delete_win (generic_win->handle); |
e65b5245 | 792 | generic_win->handle = NULL; |
6ba8e26f | 793 | tui_free_win_content (generic_win); |
c906108c SS |
794 | } |
795 | } | |
6ba8e26f | 796 | free_content (content, |
08ef48c5 MS |
797 | content_size, |
798 | DATA_WIN); | |
6ba8e26f | 799 | } |
c906108c SS |
800 | |
801 | ||
802 | /********************************** | |
803 | ** LOCAL STATIC FUNCTIONS ** | |
804 | **********************************/ | |
805 | ||
806 | ||
c906108c | 807 | static void |
08ef48c5 MS |
808 | free_content (tui_win_content content, |
809 | int content_size, | |
810 | enum tui_win_type win_type) | |
c906108c | 811 | { |
2a8854a7 | 812 | if (content != (tui_win_content) NULL) |
c906108c | 813 | { |
6ba8e26f | 814 | free_content_elements (content, content_size, win_type); |
22940a24 | 815 | xfree (content); |
c906108c | 816 | } |
6ba8e26f | 817 | } |
c906108c SS |
818 | |
819 | ||
ef5eab5a | 820 | /* free_content_elements(). |
c5aa993b | 821 | */ |
c906108c | 822 | static void |
08ef48c5 MS |
823 | free_content_elements (tui_win_content content, |
824 | int content_size, | |
825 | enum tui_win_type type) | |
c906108c | 826 | { |
2a8854a7 | 827 | if (content != (tui_win_content) NULL) |
c906108c SS |
828 | { |
829 | int i; | |
830 | ||
62f29fda | 831 | if (type == DISASSEM_WIN) |
c906108c | 832 | { |
1cc6d956 | 833 | /* Free whole source block. */ |
6d012f14 | 834 | xfree (content[0]->which_element.source.line); |
c906108c SS |
835 | } |
836 | else | |
837 | { | |
6ba8e26f | 838 | for (i = 0; i < content_size; i++) |
c906108c | 839 | { |
5b6fe301 | 840 | struct tui_win_element *element; |
c906108c SS |
841 | |
842 | element = content[i]; | |
2a8854a7 | 843 | if (element != (struct tui_win_element *) NULL) |
c906108c SS |
844 | { |
845 | switch (type) | |
846 | { | |
62f29fda TT |
847 | case SRC_WIN: |
848 | xfree (element->which_element.source.line); | |
849 | break; | |
c906108c | 850 | case DATA_WIN: |
22940a24 | 851 | xfree (element); |
c906108c SS |
852 | break; |
853 | case DATA_ITEM_WIN: | |
ef5eab5a MS |
854 | /* Note that data elements are not allocated in |
855 | a single block, but individually, as | |
856 | needed. */ | |
6d012f14 AC |
857 | if (element->which_element.data.type != TUI_REGISTER) |
858 | xfree ((void *)element->which_element.data.name); | |
859 | xfree (element->which_element.data.value); | |
10f59415 | 860 | xfree (element->which_element.data.content); |
22940a24 | 861 | xfree (element); |
c906108c SS |
862 | break; |
863 | case CMD_WIN: | |
6d012f14 | 864 | xfree (element->which_element.command.line); |
c906108c SS |
865 | break; |
866 | default: | |
867 | break; | |
868 | } | |
869 | } | |
870 | } | |
871 | } | |
872 | if (type != DATA_WIN && type != DATA_ITEM_WIN) | |
1cc6d956 | 873 | xfree (content[0]); /* Free the element block. */ |
c906108c | 874 | } |
6ba8e26f | 875 | } |