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: | |
d04b44a1 | 201 | win_info->detail.data_display_info.data_content = NULL; |
6d012f14 | 202 | win_info->detail.data_display_info.data_content_count = 0; |
d04b44a1 | 203 | win_info->detail.data_display_info.regs_content = NULL; |
6d012f14 | 204 | win_info->detail.data_display_info.regs_content_count = 0; |
6d012f14 AC |
205 | win_info->detail.data_display_info.regs_column_count = 1; |
206 | win_info->detail.data_display_info.display_regs = FALSE; | |
c906108c SS |
207 | break; |
208 | default: | |
209 | break; | |
210 | } | |
211 | } | |
6ba8e26f | 212 | } |
c906108c SS |
213 | |
214 | ||
6ba8e26f | 215 | /* Accessor for the source execution info ptr. */ |
2a8854a7 | 216 | struct tui_gen_win_info * |
dd1abb8c | 217 | tui_source_exec_info_win_ptr (void) |
c906108c | 218 | { |
6ba8e26f AC |
219 | return &exec_info[0]; |
220 | } | |
c906108c SS |
221 | |
222 | ||
6ba8e26f | 223 | /* Accessor for the disassem execution info ptr. */ |
2a8854a7 | 224 | struct tui_gen_win_info * |
dd1abb8c | 225 | tui_disassem_exec_info_win_ptr (void) |
c906108c | 226 | { |
6ba8e26f AC |
227 | return &exec_info[1]; |
228 | } | |
c906108c SS |
229 | |
230 | ||
dd1abb8c AC |
231 | /* Accessor for the locator win info. Answers a pointer to the static |
232 | locator win info struct. */ | |
2a8854a7 | 233 | struct tui_gen_win_info * |
dd1abb8c | 234 | tui_locator_win_info_ptr (void) |
c906108c SS |
235 | { |
236 | return &_locator; | |
2a8854a7 | 237 | } |
c906108c SS |
238 | |
239 | ||
6ba8e26f | 240 | /* Accessor for the term_height. */ |
c906108c | 241 | int |
dd1abb8c | 242 | tui_term_height (void) |
c906108c | 243 | { |
6ba8e26f | 244 | return term_height; |
dd1abb8c | 245 | } |
c906108c SS |
246 | |
247 | ||
1cc6d956 | 248 | /* Mutator for the term height. */ |
c906108c | 249 | void |
dd1abb8c | 250 | tui_set_term_height_to (int h) |
c906108c | 251 | { |
6ba8e26f | 252 | term_height = h; |
dd1abb8c | 253 | } |
c906108c SS |
254 | |
255 | ||
1cc6d956 | 256 | /* Accessor for the term_width. */ |
c906108c | 257 | int |
dd1abb8c | 258 | tui_term_width (void) |
c906108c | 259 | { |
6ba8e26f | 260 | return term_width; |
dd1abb8c | 261 | } |
c906108c SS |
262 | |
263 | ||
6ba8e26f | 264 | /* Mutator for the term_width. */ |
c906108c | 265 | void |
dd1abb8c | 266 | tui_set_term_width_to (int w) |
c906108c | 267 | { |
6ba8e26f | 268 | term_width = w; |
dd1abb8c | 269 | } |
c906108c SS |
270 | |
271 | ||
1cc6d956 | 272 | /* Accessor for the current layout. */ |
2a8854a7 | 273 | enum tui_layout_type |
dd1abb8c | 274 | tui_current_layout (void) |
c906108c | 275 | { |
6ba8e26f | 276 | return current_layout; |
dd1abb8c | 277 | } |
c906108c SS |
278 | |
279 | ||
dd1abb8c | 280 | /* Mutator for the current layout. */ |
c906108c | 281 | void |
6ba8e26f | 282 | tui_set_current_layout_to (enum tui_layout_type new_layout) |
c906108c | 283 | { |
6ba8e26f | 284 | current_layout = new_layout; |
dd1abb8c | 285 | } |
c906108c SS |
286 | |
287 | ||
c906108c SS |
288 | /***************************** |
289 | ** OTHER PUBLIC FUNCTIONS | |
290 | *****************************/ | |
291 | ||
292 | ||
dd1abb8c AC |
293 | /* Answer the next window in the list, cycling back to the top if |
294 | necessary. */ | |
2a8854a7 | 295 | struct tui_win_info * |
5b6fe301 | 296 | tui_next_win (struct tui_win_info *cur_win) |
c906108c | 297 | { |
570dc176 | 298 | int type = cur_win->generic.type; |
e65b5245 | 299 | struct tui_win_info *next_win = NULL; |
c906108c | 300 | |
6ba8e26f | 301 | if (cur_win->generic.type == CMD_WIN) |
c906108c SS |
302 | type = SRC_WIN; |
303 | else | |
6ba8e26f AC |
304 | type = cur_win->generic.type + 1; |
305 | while (type != cur_win->generic.type && (next_win == NULL)) | |
c906108c | 306 | { |
e5908723 MS |
307 | if (tui_win_list[type] |
308 | && tui_win_list[type]->generic.is_visible) | |
6ba8e26f | 309 | next_win = tui_win_list[type]; |
c906108c SS |
310 | else |
311 | { | |
312 | if (type == CMD_WIN) | |
313 | type = SRC_WIN; | |
314 | else | |
315 | type++; | |
316 | } | |
317 | } | |
318 | ||
6ba8e26f AC |
319 | return next_win; |
320 | } | |
c906108c SS |
321 | |
322 | ||
dd1abb8c AC |
323 | /* Answer the prev window in the list, cycling back to the bottom if |
324 | necessary. */ | |
2a8854a7 | 325 | struct tui_win_info * |
5b6fe301 | 326 | tui_prev_win (struct tui_win_info *cur_win) |
c906108c | 327 | { |
570dc176 | 328 | int type = cur_win->generic.type; |
e65b5245 | 329 | struct tui_win_info *prev = NULL; |
c906108c | 330 | |
6ba8e26f | 331 | if (cur_win->generic.type == SRC_WIN) |
c906108c SS |
332 | type = CMD_WIN; |
333 | else | |
6ba8e26f AC |
334 | type = cur_win->generic.type - 1; |
335 | while (type != cur_win->generic.type && (prev == NULL)) | |
c906108c | 336 | { |
37715c4c TJB |
337 | if (tui_win_list[type] |
338 | && tui_win_list[type]->generic.is_visible) | |
6d012f14 | 339 | prev = tui_win_list[type]; |
c906108c SS |
340 | else |
341 | { | |
342 | if (type == SRC_WIN) | |
343 | type = CMD_WIN; | |
344 | else | |
345 | type--; | |
346 | } | |
347 | } | |
348 | ||
349 | return prev; | |
cb50eddd | 350 | } |
c906108c SS |
351 | |
352 | ||
1cc6d956 | 353 | /* Answer the window represented by name. */ |
2a8854a7 | 354 | struct tui_win_info * |
a121b7c1 | 355 | tui_partial_win_by_name (const char *name) |
c906108c | 356 | { |
e65b5245 | 357 | struct tui_win_info *win_info = NULL; |
c906108c | 358 | |
63a33118 | 359 | if (name != NULL) |
c906108c SS |
360 | { |
361 | int i = 0; | |
362 | ||
6d012f14 | 363 | while (i < MAX_MAJOR_WINDOWS && win_info == NULL) |
c906108c | 364 | { |
6d012f14 | 365 | if (tui_win_list[i] != 0) |
a4b99e53 | 366 | { |
f41cbf58 AB |
367 | const char *cur_name = |
368 | tui_win_name (&tui_win_list[i]->generic); | |
1c5313c5 | 369 | |
e5908723 | 370 | if (strlen (name) <= strlen (cur_name) |
61012eef | 371 | && startswith (cur_name, name)) |
6d012f14 | 372 | win_info = tui_win_list[i]; |
a4b99e53 | 373 | } |
c906108c SS |
374 | i++; |
375 | } | |
376 | } | |
377 | ||
6d012f14 | 378 | return win_info; |
6ba8e26f | 379 | } |
c906108c SS |
380 | |
381 | ||
6ba8e26f | 382 | /* Answer the name of the window. */ |
f41cbf58 AB |
383 | const char * |
384 | tui_win_name (const struct tui_gen_win_info *win_info) | |
c906108c | 385 | { |
136765ea | 386 | const char *name = NULL; |
c906108c | 387 | |
6d012f14 | 388 | switch (win_info->type) |
c906108c SS |
389 | { |
390 | case SRC_WIN: | |
391 | name = SRC_NAME; | |
392 | break; | |
393 | case CMD_WIN: | |
394 | name = CMD_NAME; | |
395 | break; | |
396 | case DISASSEM_WIN: | |
397 | name = DISASSEM_NAME; | |
398 | break; | |
399 | case DATA_WIN: | |
400 | name = DATA_NAME; | |
401 | break; | |
402 | default: | |
403 | name = ""; | |
404 | break; | |
405 | } | |
406 | ||
407 | return name; | |
6ba8e26f | 408 | } |
c906108c SS |
409 | |
410 | ||
c906108c | 411 | void |
dd1abb8c | 412 | tui_initialize_static_data (void) |
c906108c | 413 | { |
dd1abb8c AC |
414 | tui_init_generic_part (tui_source_exec_info_win_ptr ()); |
415 | tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); | |
416 | tui_init_generic_part (tui_locator_win_info_ptr ()); | |
417 | } | |
c906108c SS |
418 | |
419 | ||
2a8854a7 | 420 | struct tui_gen_win_info * |
dd1abb8c | 421 | tui_alloc_generic_win_info (void) |
c906108c | 422 | { |
8d749320 | 423 | struct tui_gen_win_info *win = XNEW (struct tui_gen_win_info); |
c906108c | 424 | |
730ead81 | 425 | tui_init_generic_part (win); |
c906108c SS |
426 | |
427 | return win; | |
6ba8e26f | 428 | } |
c906108c SS |
429 | |
430 | ||
c906108c | 431 | void |
5b6fe301 | 432 | tui_init_generic_part (struct tui_gen_win_info *win) |
c906108c SS |
433 | { |
434 | win->width = | |
435 | win->height = | |
436 | win->origin.x = | |
437 | win->origin.y = | |
6d012f14 AC |
438 | win->viewport_height = |
439 | win->content_size = | |
440 | win->last_visible_line = 0; | |
e65b5245 | 441 | win->handle = NULL; |
22940a24 | 442 | win->content = NULL; |
6d012f14 AC |
443 | win->content_in_use = |
444 | win->is_visible = FALSE; | |
bc6b7f04 SC |
445 | win->title = 0; |
446 | } | |
c906108c SS |
447 | |
448 | ||
ef5eab5a | 449 | /* init_content_element(). |
c5aa993b | 450 | */ |
2c0b251b | 451 | static void |
08ef48c5 MS |
452 | init_content_element (struct tui_win_element *element, |
453 | enum tui_win_type type) | |
c906108c | 454 | { |
c906108c SS |
455 | switch (type) |
456 | { | |
457 | case SRC_WIN: | |
458 | case DISASSEM_WIN: | |
e65b5245 | 459 | element->which_element.source.line = NULL; |
362c05fe AS |
460 | element->which_element.source.line_or_addr.loa = LOA_LINE; |
461 | element->which_element.source.line_or_addr.u.line_no = 0; | |
6d012f14 AC |
462 | element->which_element.source.is_exec_point = FALSE; |
463 | element->which_element.source.has_break = FALSE; | |
c906108c SS |
464 | break; |
465 | case DATA_WIN: | |
6d012f14 AC |
466 | tui_init_generic_part (&element->which_element.data_window); |
467 | element->which_element.data_window.type = DATA_ITEM_WIN; | |
63ed8182 PP |
468 | element->which_element.data_window.content = |
469 | tui_alloc_content (1, DATA_ITEM_WIN); | |
470 | element->which_element.data_window.content_size = 1; | |
c906108c SS |
471 | break; |
472 | case CMD_WIN: | |
e65b5245 | 473 | element->which_element.command.line = NULL; |
c906108c SS |
474 | break; |
475 | case DATA_ITEM_WIN: | |
e65b5245 | 476 | element->which_element.data.name = NULL; |
6d012f14 AC |
477 | element->which_element.data.type = TUI_REGISTER; |
478 | element->which_element.data.item_no = UNDEFINED_ITEM; | |
479 | element->which_element.data.value = NULL; | |
480 | element->which_element.data.highlight = FALSE; | |
e65b5245 | 481 | element->which_element.data.content = NULL; |
c906108c SS |
482 | break; |
483 | case LOCATOR_WIN: | |
56d397a3 | 484 | element->which_element.locator.full_name[0] = |
6d012f14 AC |
485 | element->which_element.locator.proc_name[0] = (char) 0; |
486 | element->which_element.locator.line_no = 0; | |
487 | element->which_element.locator.addr = 0; | |
c906108c SS |
488 | break; |
489 | case EXEC_INFO_WIN: | |
6d012f14 AC |
490 | memset(element->which_element.simple_string, ' ', |
491 | sizeof(element->which_element.simple_string)); | |
c906108c SS |
492 | break; |
493 | default: | |
494 | break; | |
495 | } | |
6ba8e26f | 496 | } |
c906108c | 497 | |
2c0b251b | 498 | static void |
5b6fe301 | 499 | init_win_info (struct tui_win_info *win_info) |
c906108c | 500 | { |
6d012f14 AC |
501 | tui_init_generic_part (&win_info->generic); |
502 | win_info->can_highlight = | |
503 | win_info->is_highlighted = FALSE; | |
504 | switch (win_info->generic.type) | |
c906108c SS |
505 | { |
506 | case SRC_WIN: | |
507 | case DISASSEM_WIN: | |
cafb3438 | 508 | win_info->detail.source_info.execution_info = NULL; |
6d012f14 AC |
509 | win_info->detail.source_info.has_locator = FALSE; |
510 | win_info->detail.source_info.horizontal_offset = 0; | |
13274fc3 | 511 | win_info->detail.source_info.gdbarch = NULL; |
362c05fe AS |
512 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
513 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
aa079c93 | 514 | win_info->detail.source_info.fullname = NULL; |
c906108c SS |
515 | break; |
516 | case DATA_WIN: | |
d04b44a1 | 517 | win_info->detail.data_display_info.data_content = NULL; |
6d012f14 | 518 | win_info->detail.data_display_info.data_content_count = 0; |
d04b44a1 | 519 | win_info->detail.data_display_info.regs_content = NULL; |
6d012f14 | 520 | win_info->detail.data_display_info.regs_content_count = 0; |
6d012f14 AC |
521 | win_info->detail.data_display_info.regs_column_count = 1; |
522 | win_info->detail.data_display_info.display_regs = FALSE; | |
10f59415 | 523 | win_info->detail.data_display_info.current_group = 0; |
c906108c SS |
524 | break; |
525 | case CMD_WIN: | |
c906108c | 526 | break; |
c906108c | 527 | } |
6ba8e26f | 528 | } |
c906108c SS |
529 | |
530 | ||
2a8854a7 | 531 | struct tui_win_info * |
22940a24 | 532 | tui_alloc_win_info (enum tui_win_type type) |
c906108c | 533 | { |
6792b55e | 534 | struct tui_win_info *win_info = new struct tui_win_info (type); |
c906108c | 535 | |
730ead81 | 536 | init_win_info (win_info); |
c906108c | 537 | |
6d012f14 | 538 | return win_info; |
6ba8e26f | 539 | } |
c906108c SS |
540 | |
541 | ||
6ba8e26f | 542 | /* Allocates the content and elements in a block. */ |
2a8854a7 | 543 | tui_win_content |
6ba8e26f | 544 | tui_alloc_content (int num_elements, enum tui_win_type type) |
c906108c | 545 | { |
c0645fb5 | 546 | tui_win_content content; |
7acd011b | 547 | struct tui_win_element *element_block_ptr; |
c906108c SS |
548 | int i; |
549 | ||
8d749320 | 550 | content = XNEWVEC (struct tui_win_element *, num_elements); |
7acd011b SM |
551 | |
552 | /* | |
553 | * All windows, except the data window, can allocate the | |
554 | * elements in a chunk. The data window cannot because items | |
555 | * can be added/removed from the data display by the user at any | |
556 | * time. | |
557 | */ | |
558 | if (type != DATA_WIN) | |
c0645fb5 | 559 | { |
7acd011b SM |
560 | element_block_ptr = XNEWVEC (struct tui_win_element, num_elements); |
561 | for (i = 0; i < num_elements; i++) | |
c906108c | 562 | { |
7acd011b SM |
563 | content[i] = element_block_ptr; |
564 | init_content_element (content[i], type); | |
565 | element_block_ptr++; | |
c906108c SS |
566 | } |
567 | } | |
568 | ||
569 | return content; | |
6ba8e26f | 570 | } |
c906108c SS |
571 | |
572 | ||
dd1abb8c | 573 | /* Adds the input number of elements to the windows's content. If no |
6ba8e26f | 574 | content has been allocated yet, alloc_content() is called to do |
dd1abb8c AC |
575 | this. The index of the first element added is returned, unless |
576 | there is a memory allocation error, in which case, (-1) is | |
577 | returned. */ | |
c906108c | 578 | int |
08ef48c5 MS |
579 | tui_add_content_elements (struct tui_gen_win_info *win_info, |
580 | int num_elements) | |
c906108c | 581 | { |
5b6fe301 | 582 | struct tui_win_element *element_ptr; |
6ba8e26f | 583 | int i, index_start; |
c906108c | 584 | |
6d012f14 | 585 | if (win_info->content == NULL) |
c906108c | 586 | { |
63ed8182 | 587 | win_info->content = tui_alloc_content (num_elements, win_info->type); |
6ba8e26f | 588 | index_start = 0; |
c906108c SS |
589 | } |
590 | else | |
6ba8e26f | 591 | index_start = win_info->content_size; |
6d012f14 | 592 | if (win_info->content != NULL) |
c906108c | 593 | { |
6ba8e26f | 594 | for (i = index_start; (i < num_elements + index_start); i++) |
c906108c | 595 | { |
8d749320 | 596 | element_ptr = XNEW (struct tui_win_element); |
730ead81 TT |
597 | win_info->content[i] = element_ptr; |
598 | init_content_element (element_ptr, win_info->type); | |
599 | win_info->content_size++; | |
c906108c SS |
600 | } |
601 | } | |
602 | ||
6ba8e26f AC |
603 | return index_start; |
604 | } | |
c906108c | 605 | |
e7e11af4 | 606 | tui_win_info::~tui_win_info () |
c906108c | 607 | { |
5b6fe301 | 608 | struct tui_gen_win_info *generic_win; |
c906108c | 609 | |
e7e11af4 | 610 | switch (generic.type) |
c906108c SS |
611 | { |
612 | case SRC_WIN: | |
613 | case DISASSEM_WIN: | |
e7e11af4 | 614 | if (detail.source_info.fullname) |
bc6b7f04 | 615 | { |
e7e11af4 TT |
616 | xfree (detail.source_info.fullname); |
617 | detail.source_info.fullname = NULL; | |
bc6b7f04 | 618 | } |
e7e11af4 | 619 | generic_win = detail.source_info.execution_info; |
cafb3438 | 620 | if (generic_win != NULL) |
c906108c | 621 | { |
6ba8e26f | 622 | tui_delete_win (generic_win->handle); |
e65b5245 | 623 | generic_win->handle = NULL; |
6ba8e26f | 624 | tui_free_win_content (generic_win); |
c906108c SS |
625 | } |
626 | break; | |
627 | case DATA_WIN: | |
e7e11af4 | 628 | if (generic.content != NULL) |
c906108c | 629 | { |
e7e11af4 TT |
630 | tui_free_data_content (detail.data_display_info.regs_content, |
631 | detail.data_display_info.regs_content_count); | |
632 | detail.data_display_info.regs_content = NULL; | |
633 | detail.data_display_info.regs_content_count = 0; | |
634 | tui_free_data_content (detail.data_display_info.data_content, | |
635 | detail.data_display_info.data_content_count); | |
636 | detail.data_display_info.data_content = NULL; | |
637 | detail.data_display_info.data_content_count = 0; | |
638 | detail.data_display_info.regs_column_count = 1; | |
639 | detail.data_display_info.display_regs = FALSE; | |
640 | generic.content = NULL; | |
641 | generic.content_size = 0; | |
c906108c SS |
642 | } |
643 | break; | |
644 | default: | |
645 | break; | |
646 | } | |
e7e11af4 | 647 | if (generic.handle != NULL) |
c906108c | 648 | { |
e7e11af4 TT |
649 | tui_delete_win (generic.handle); |
650 | generic.handle = NULL; | |
651 | tui_free_win_content (&generic); | |
c906108c | 652 | } |
e7e11af4 TT |
653 | if (generic.title) |
654 | xfree (generic.title); | |
bc6b7f04 | 655 | } |
c906108c SS |
656 | |
657 | ||
c906108c | 658 | void |
dd1abb8c | 659 | tui_free_all_source_wins_content (void) |
c906108c SS |
660 | { |
661 | int i; | |
662 | ||
dd1abb8c | 663 | for (i = 0; i < (tui_source_windows ())->count; i++) |
c906108c | 664 | { |
5b6fe301 | 665 | struct tui_win_info *win_info = (tui_source_windows ())->list[i]; |
c906108c | 666 | |
6d012f14 | 667 | if (win_info != NULL) |
c906108c | 668 | { |
6d012f14 AC |
669 | tui_free_win_content (&(win_info->generic)); |
670 | tui_free_win_content (win_info->detail.source_info.execution_info); | |
c906108c SS |
671 | } |
672 | } | |
dd1abb8c | 673 | } |
c906108c SS |
674 | |
675 | ||
c906108c | 676 | void |
5b6fe301 | 677 | tui_free_win_content (struct tui_gen_win_info *win_info) |
c906108c | 678 | { |
6d012f14 | 679 | if (win_info->content != NULL) |
c906108c | 680 | { |
63a33118 | 681 | free_content (win_info->content, |
6d012f14 AC |
682 | win_info->content_size, |
683 | win_info->type); | |
684 | win_info->content = NULL; | |
c906108c | 685 | } |
6d012f14 | 686 | win_info->content_size = 0; |
6ba8e26f | 687 | } |
c906108c SS |
688 | |
689 | ||
c906108c | 690 | void |
08ef48c5 MS |
691 | tui_free_data_content (tui_win_content content, |
692 | int content_size) | |
c906108c SS |
693 | { |
694 | int i; | |
695 | ||
ef5eab5a MS |
696 | /* Remember that data window content elements are of type struct |
697 | tui_gen_win_info *, each of which whose single element is a data | |
698 | element. */ | |
6ba8e26f | 699 | for (i = 0; i < content_size; i++) |
c906108c | 700 | { |
9a2b4c1b MS |
701 | struct tui_gen_win_info *generic_win |
702 | = &content[i]->which_element.data_window; | |
c906108c | 703 | |
cafb3438 | 704 | if (generic_win != NULL) |
c906108c | 705 | { |
6ba8e26f | 706 | tui_delete_win (generic_win->handle); |
e65b5245 | 707 | generic_win->handle = NULL; |
6ba8e26f | 708 | tui_free_win_content (generic_win); |
c906108c SS |
709 | } |
710 | } | |
6ba8e26f | 711 | free_content (content, |
08ef48c5 MS |
712 | content_size, |
713 | DATA_WIN); | |
6ba8e26f | 714 | } |
c906108c SS |
715 | |
716 | ||
717 | /********************************** | |
718 | ** LOCAL STATIC FUNCTIONS ** | |
719 | **********************************/ | |
720 | ||
721 | ||
c906108c | 722 | static void |
08ef48c5 MS |
723 | free_content (tui_win_content content, |
724 | int content_size, | |
725 | enum tui_win_type win_type) | |
c906108c | 726 | { |
d04b44a1 | 727 | if (content != NULL) |
c906108c | 728 | { |
6ba8e26f | 729 | free_content_elements (content, content_size, win_type); |
22940a24 | 730 | xfree (content); |
c906108c | 731 | } |
6ba8e26f | 732 | } |
c906108c SS |
733 | |
734 | ||
ef5eab5a | 735 | /* free_content_elements(). |
c5aa993b | 736 | */ |
c906108c | 737 | static void |
08ef48c5 MS |
738 | free_content_elements (tui_win_content content, |
739 | int content_size, | |
740 | enum tui_win_type type) | |
c906108c | 741 | { |
d04b44a1 | 742 | if (content != NULL) |
c906108c SS |
743 | { |
744 | int i; | |
745 | ||
62f29fda | 746 | if (type == DISASSEM_WIN) |
c906108c | 747 | { |
1cc6d956 | 748 | /* Free whole source block. */ |
6d012f14 | 749 | xfree (content[0]->which_element.source.line); |
c906108c SS |
750 | } |
751 | else | |
752 | { | |
6ba8e26f | 753 | for (i = 0; i < content_size; i++) |
c906108c | 754 | { |
5b6fe301 | 755 | struct tui_win_element *element; |
c906108c SS |
756 | |
757 | element = content[i]; | |
cafb3438 | 758 | if (element != NULL) |
c906108c SS |
759 | { |
760 | switch (type) | |
761 | { | |
62f29fda TT |
762 | case SRC_WIN: |
763 | xfree (element->which_element.source.line); | |
764 | break; | |
c906108c | 765 | case DATA_WIN: |
22940a24 | 766 | xfree (element); |
c906108c SS |
767 | break; |
768 | case DATA_ITEM_WIN: | |
ef5eab5a MS |
769 | /* Note that data elements are not allocated in |
770 | a single block, but individually, as | |
771 | needed. */ | |
6d012f14 AC |
772 | if (element->which_element.data.type != TUI_REGISTER) |
773 | xfree ((void *)element->which_element.data.name); | |
774 | xfree (element->which_element.data.value); | |
10f59415 | 775 | xfree (element->which_element.data.content); |
22940a24 | 776 | xfree (element); |
c906108c SS |
777 | break; |
778 | case CMD_WIN: | |
6d012f14 | 779 | xfree (element->which_element.command.line); |
c906108c SS |
780 | break; |
781 | default: | |
782 | break; | |
783 | } | |
784 | } | |
785 | } | |
786 | } | |
787 | if (type != DATA_WIN && type != DATA_ITEM_WIN) | |
1cc6d956 | 788 | xfree (content[0]); /* Free the element block. */ |
c906108c | 789 | } |
6ba8e26f | 790 | } |