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