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