Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
e2882c85 | 3 | Copyright (C) 1998-2018 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 | |
8d749320 | 427 | if (win != NULL) |
dd1abb8c | 428 | tui_init_generic_part (win); |
c906108c SS |
429 | |
430 | return win; | |
6ba8e26f | 431 | } |
c906108c SS |
432 | |
433 | ||
c906108c | 434 | void |
5b6fe301 | 435 | tui_init_generic_part (struct tui_gen_win_info *win) |
c906108c SS |
436 | { |
437 | win->width = | |
438 | win->height = | |
439 | win->origin.x = | |
440 | win->origin.y = | |
6d012f14 AC |
441 | win->viewport_height = |
442 | win->content_size = | |
443 | win->last_visible_line = 0; | |
e65b5245 | 444 | win->handle = NULL; |
22940a24 | 445 | win->content = NULL; |
6d012f14 AC |
446 | win->content_in_use = |
447 | win->is_visible = FALSE; | |
bc6b7f04 SC |
448 | win->title = 0; |
449 | } | |
c906108c SS |
450 | |
451 | ||
ef5eab5a | 452 | /* init_content_element(). |
c5aa993b | 453 | */ |
2c0b251b | 454 | static void |
08ef48c5 MS |
455 | init_content_element (struct tui_win_element *element, |
456 | enum tui_win_type type) | |
c906108c | 457 | { |
c906108c SS |
458 | switch (type) |
459 | { | |
460 | case SRC_WIN: | |
461 | case DISASSEM_WIN: | |
e65b5245 | 462 | element->which_element.source.line = NULL; |
362c05fe AS |
463 | element->which_element.source.line_or_addr.loa = LOA_LINE; |
464 | element->which_element.source.line_or_addr.u.line_no = 0; | |
6d012f14 AC |
465 | element->which_element.source.is_exec_point = FALSE; |
466 | element->which_element.source.has_break = FALSE; | |
c906108c SS |
467 | break; |
468 | case DATA_WIN: | |
6d012f14 AC |
469 | tui_init_generic_part (&element->which_element.data_window); |
470 | element->which_element.data_window.type = DATA_ITEM_WIN; | |
63ed8182 PP |
471 | element->which_element.data_window.content = |
472 | tui_alloc_content (1, DATA_ITEM_WIN); | |
473 | element->which_element.data_window.content_size = 1; | |
c906108c SS |
474 | break; |
475 | case CMD_WIN: | |
e65b5245 | 476 | element->which_element.command.line = NULL; |
c906108c SS |
477 | break; |
478 | case DATA_ITEM_WIN: | |
e65b5245 | 479 | element->which_element.data.name = NULL; |
6d012f14 AC |
480 | element->which_element.data.type = TUI_REGISTER; |
481 | element->which_element.data.item_no = UNDEFINED_ITEM; | |
482 | element->which_element.data.value = NULL; | |
483 | element->which_element.data.highlight = FALSE; | |
e65b5245 | 484 | element->which_element.data.content = NULL; |
c906108c SS |
485 | break; |
486 | case LOCATOR_WIN: | |
56d397a3 | 487 | element->which_element.locator.full_name[0] = |
6d012f14 AC |
488 | element->which_element.locator.proc_name[0] = (char) 0; |
489 | element->which_element.locator.line_no = 0; | |
490 | element->which_element.locator.addr = 0; | |
c906108c SS |
491 | break; |
492 | case EXEC_INFO_WIN: | |
6d012f14 AC |
493 | memset(element->which_element.simple_string, ' ', |
494 | sizeof(element->which_element.simple_string)); | |
c906108c SS |
495 | break; |
496 | default: | |
497 | break; | |
498 | } | |
6ba8e26f | 499 | } |
c906108c | 500 | |
2c0b251b | 501 | static void |
5b6fe301 | 502 | init_win_info (struct tui_win_info *win_info) |
c906108c | 503 | { |
6d012f14 AC |
504 | tui_init_generic_part (&win_info->generic); |
505 | win_info->can_highlight = | |
506 | win_info->is_highlighted = FALSE; | |
507 | switch (win_info->generic.type) | |
c906108c SS |
508 | { |
509 | case SRC_WIN: | |
510 | case DISASSEM_WIN: | |
9a2b4c1b MS |
511 | win_info->detail.source_info.execution_info |
512 | = (struct tui_gen_win_info *) NULL; | |
6d012f14 AC |
513 | win_info->detail.source_info.has_locator = FALSE; |
514 | win_info->detail.source_info.horizontal_offset = 0; | |
13274fc3 | 515 | win_info->detail.source_info.gdbarch = NULL; |
362c05fe AS |
516 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
517 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
aa079c93 | 518 | win_info->detail.source_info.fullname = NULL; |
c906108c SS |
519 | break; |
520 | case DATA_WIN: | |
6d012f14 AC |
521 | win_info->detail.data_display_info.data_content = (tui_win_content) NULL; |
522 | win_info->detail.data_display_info.data_content_count = 0; | |
523 | win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; | |
524 | win_info->detail.data_display_info.regs_content_count = 0; | |
6d012f14 AC |
525 | win_info->detail.data_display_info.regs_column_count = 1; |
526 | win_info->detail.data_display_info.display_regs = FALSE; | |
10f59415 | 527 | win_info->detail.data_display_info.current_group = 0; |
c906108c SS |
528 | break; |
529 | case CMD_WIN: | |
c906108c | 530 | break; |
c906108c | 531 | } |
6ba8e26f | 532 | } |
c906108c SS |
533 | |
534 | ||
2a8854a7 | 535 | struct tui_win_info * |
22940a24 | 536 | tui_alloc_win_info (enum tui_win_type type) |
c906108c | 537 | { |
8d749320 | 538 | struct tui_win_info *win_info = XNEW (struct tui_win_info); |
c906108c | 539 | |
c0645fb5 | 540 | if (win_info != NULL) |
c906108c | 541 | { |
6d012f14 | 542 | win_info->generic.type = type; |
6ba8e26f | 543 | init_win_info (win_info); |
c906108c SS |
544 | } |
545 | ||
6d012f14 | 546 | return win_info; |
6ba8e26f | 547 | } |
c906108c SS |
548 | |
549 | ||
6ba8e26f | 550 | /* Allocates the content and elements in a block. */ |
2a8854a7 | 551 | tui_win_content |
6ba8e26f | 552 | tui_alloc_content (int num_elements, enum tui_win_type type) |
c906108c | 553 | { |
c0645fb5 | 554 | tui_win_content content; |
7acd011b | 555 | struct tui_win_element *element_block_ptr; |
c906108c SS |
556 | int i; |
557 | ||
8d749320 | 558 | content = XNEWVEC (struct tui_win_element *, num_elements); |
7acd011b SM |
559 | |
560 | /* | |
561 | * All windows, except the data window, can allocate the | |
562 | * elements in a chunk. The data window cannot because items | |
563 | * can be added/removed from the data display by the user at any | |
564 | * time. | |
565 | */ | |
566 | if (type != DATA_WIN) | |
c0645fb5 | 567 | { |
7acd011b SM |
568 | element_block_ptr = XNEWVEC (struct tui_win_element, num_elements); |
569 | for (i = 0; i < num_elements; i++) | |
c906108c | 570 | { |
7acd011b SM |
571 | content[i] = element_block_ptr; |
572 | init_content_element (content[i], type); | |
573 | element_block_ptr++; | |
c906108c SS |
574 | } |
575 | } | |
576 | ||
577 | return content; | |
6ba8e26f | 578 | } |
c906108c SS |
579 | |
580 | ||
dd1abb8c | 581 | /* Adds the input number of elements to the windows's content. If no |
6ba8e26f | 582 | content has been allocated yet, alloc_content() is called to do |
dd1abb8c AC |
583 | this. The index of the first element added is returned, unless |
584 | there is a memory allocation error, in which case, (-1) is | |
585 | returned. */ | |
c906108c | 586 | int |
08ef48c5 MS |
587 | tui_add_content_elements (struct tui_gen_win_info *win_info, |
588 | int num_elements) | |
c906108c | 589 | { |
5b6fe301 | 590 | struct tui_win_element *element_ptr; |
6ba8e26f | 591 | int i, index_start; |
c906108c | 592 | |
6d012f14 | 593 | if (win_info->content == NULL) |
c906108c | 594 | { |
63ed8182 | 595 | win_info->content = tui_alloc_content (num_elements, win_info->type); |
6ba8e26f | 596 | index_start = 0; |
c906108c SS |
597 | } |
598 | else | |
6ba8e26f | 599 | index_start = win_info->content_size; |
6d012f14 | 600 | if (win_info->content != NULL) |
c906108c | 601 | { |
6ba8e26f | 602 | for (i = index_start; (i < num_elements + index_start); i++) |
c906108c | 603 | { |
8d749320 SM |
604 | element_ptr = XNEW (struct tui_win_element); |
605 | if (element_ptr != NULL) | |
c906108c | 606 | { |
f4ee58bd | 607 | win_info->content[i] = element_ptr; |
6ba8e26f | 608 | init_content_element (element_ptr, win_info->type); |
6d012f14 | 609 | win_info->content_size++; |
c906108c | 610 | } |
1cc6d956 MS |
611 | else /* Things must be really hosed now! We ran out of |
612 | memory!? */ | |
c906108c SS |
613 | return (-1); |
614 | } | |
615 | } | |
616 | ||
6ba8e26f AC |
617 | return index_start; |
618 | } | |
c906108c SS |
619 | |
620 | ||
1cc6d956 MS |
621 | /* Delete all curses windows associated with win_info, leaving |
622 | everything else intact. */ | |
c906108c | 623 | void |
5b6fe301 | 624 | tui_del_window (struct tui_win_info *win_info) |
c906108c | 625 | { |
5b6fe301 | 626 | struct tui_gen_win_info *generic_win; |
c906108c | 627 | |
6d012f14 | 628 | switch (win_info->generic.type) |
c906108c SS |
629 | { |
630 | case SRC_WIN: | |
631 | case DISASSEM_WIN: | |
6ba8e26f AC |
632 | generic_win = tui_locator_win_info_ptr (); |
633 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 634 | { |
6ba8e26f | 635 | tui_delete_win (generic_win->handle); |
e65b5245 | 636 | generic_win->handle = NULL; |
6ba8e26f | 637 | generic_win->is_visible = FALSE; |
c906108c | 638 | } |
aa079c93 | 639 | if (win_info->detail.source_info.fullname) |
bc6b7f04 | 640 | { |
aa079c93 JK |
641 | xfree (win_info->detail.source_info.fullname); |
642 | win_info->detail.source_info.fullname = NULL; | |
bc6b7f04 | 643 | } |
6ba8e26f AC |
644 | generic_win = win_info->detail.source_info.execution_info; |
645 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 646 | { |
6ba8e26f | 647 | tui_delete_win (generic_win->handle); |
e65b5245 | 648 | generic_win->handle = NULL; |
6ba8e26f | 649 | generic_win->is_visible = FALSE; |
c906108c SS |
650 | } |
651 | break; | |
652 | case DATA_WIN: | |
6d012f14 | 653 | if (win_info->generic.content != NULL) |
c906108c | 654 | { |
6d012f14 AC |
655 | tui_del_data_windows (win_info->detail.data_display_info.regs_content, |
656 | win_info->detail.data_display_info.regs_content_count); | |
657 | tui_del_data_windows (win_info->detail.data_display_info.data_content, | |
658 | win_info->detail.data_display_info.data_content_count); | |
c906108c SS |
659 | } |
660 | break; | |
661 | default: | |
662 | break; | |
663 | } | |
6d012f14 | 664 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 665 | { |
6d012f14 | 666 | tui_delete_win (win_info->generic.handle); |
e65b5245 | 667 | win_info->generic.handle = NULL; |
6d012f14 | 668 | win_info->generic.is_visible = FALSE; |
c906108c | 669 | } |
bc6b7f04 | 670 | } |
c906108c SS |
671 | |
672 | ||
c906108c | 673 | void |
5b6fe301 | 674 | tui_free_window (struct tui_win_info *win_info) |
c906108c | 675 | { |
5b6fe301 | 676 | struct tui_gen_win_info *generic_win; |
c906108c | 677 | |
6d012f14 | 678 | switch (win_info->generic.type) |
c906108c SS |
679 | { |
680 | case SRC_WIN: | |
681 | case DISASSEM_WIN: | |
aa079c93 | 682 | if (win_info->detail.source_info.fullname) |
bc6b7f04 | 683 | { |
aa079c93 JK |
684 | xfree (win_info->detail.source_info.fullname); |
685 | win_info->detail.source_info.fullname = NULL; | |
bc6b7f04 | 686 | } |
6ba8e26f AC |
687 | generic_win = win_info->detail.source_info.execution_info; |
688 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 689 | { |
6ba8e26f | 690 | tui_delete_win (generic_win->handle); |
e65b5245 | 691 | generic_win->handle = NULL; |
6ba8e26f | 692 | tui_free_win_content (generic_win); |
c906108c SS |
693 | } |
694 | break; | |
695 | case DATA_WIN: | |
6d012f14 | 696 | if (win_info->generic.content != NULL) |
c906108c | 697 | { |
6d012f14 AC |
698 | tui_free_data_content (win_info->detail.data_display_info.regs_content, |
699 | win_info->detail.data_display_info.regs_content_count); | |
700 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 701 | (tui_win_content) NULL; |
6d012f14 AC |
702 | win_info->detail.data_display_info.regs_content_count = 0; |
703 | tui_free_data_content (win_info->detail.data_display_info.data_content, | |
704 | win_info->detail.data_display_info.data_content_count); | |
705 | win_info->detail.data_display_info.data_content = | |
2a8854a7 | 706 | (tui_win_content) NULL; |
6d012f14 | 707 | win_info->detail.data_display_info.data_content_count = 0; |
6d012f14 AC |
708 | win_info->detail.data_display_info.regs_column_count = 1; |
709 | win_info->detail.data_display_info.display_regs = FALSE; | |
710 | win_info->generic.content = NULL; | |
711 | win_info->generic.content_size = 0; | |
c906108c SS |
712 | } |
713 | break; | |
714 | default: | |
715 | break; | |
716 | } | |
6d012f14 | 717 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 718 | { |
6d012f14 | 719 | tui_delete_win (win_info->generic.handle); |
e65b5245 | 720 | win_info->generic.handle = NULL; |
6d012f14 | 721 | tui_free_win_content (&win_info->generic); |
c906108c | 722 | } |
6d012f14 AC |
723 | if (win_info->generic.title) |
724 | xfree (win_info->generic.title); | |
725 | xfree (win_info); | |
bc6b7f04 | 726 | } |
c906108c SS |
727 | |
728 | ||
c906108c | 729 | void |
dd1abb8c | 730 | tui_free_all_source_wins_content (void) |
c906108c SS |
731 | { |
732 | int i; | |
733 | ||
dd1abb8c | 734 | for (i = 0; i < (tui_source_windows ())->count; i++) |
c906108c | 735 | { |
5b6fe301 | 736 | struct tui_win_info *win_info = (tui_source_windows ())->list[i]; |
c906108c | 737 | |
6d012f14 | 738 | if (win_info != NULL) |
c906108c | 739 | { |
6d012f14 AC |
740 | tui_free_win_content (&(win_info->generic)); |
741 | tui_free_win_content (win_info->detail.source_info.execution_info); | |
c906108c SS |
742 | } |
743 | } | |
dd1abb8c | 744 | } |
c906108c SS |
745 | |
746 | ||
c906108c | 747 | void |
5b6fe301 | 748 | tui_free_win_content (struct tui_gen_win_info *win_info) |
c906108c | 749 | { |
6d012f14 | 750 | if (win_info->content != NULL) |
c906108c | 751 | { |
63a33118 | 752 | free_content (win_info->content, |
6d012f14 AC |
753 | win_info->content_size, |
754 | win_info->type); | |
755 | win_info->content = NULL; | |
c906108c | 756 | } |
6d012f14 | 757 | win_info->content_size = 0; |
6ba8e26f | 758 | } |
c906108c SS |
759 | |
760 | ||
c906108c | 761 | void |
08ef48c5 MS |
762 | tui_del_data_windows (tui_win_content content, |
763 | int content_size) | |
c906108c SS |
764 | { |
765 | int i; | |
766 | ||
ef5eab5a MS |
767 | /* Remember that data window content elements are of type struct |
768 | tui_gen_win_info *, each of which whose single element is a data | |
769 | element. */ | |
6ba8e26f | 770 | for (i = 0; i < content_size; i++) |
c906108c | 771 | { |
9a2b4c1b MS |
772 | struct tui_gen_win_info *generic_win |
773 | = &content[i]->which_element.data_window; | |
c906108c | 774 | |
6ba8e26f | 775 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 776 | { |
6ba8e26f | 777 | tui_delete_win (generic_win->handle); |
e65b5245 | 778 | generic_win->handle = NULL; |
6ba8e26f | 779 | generic_win->is_visible = FALSE; |
c906108c SS |
780 | } |
781 | } | |
dd1abb8c | 782 | } |
c906108c SS |
783 | |
784 | ||
785 | void | |
08ef48c5 MS |
786 | tui_free_data_content (tui_win_content content, |
787 | int content_size) | |
c906108c SS |
788 | { |
789 | int i; | |
790 | ||
ef5eab5a MS |
791 | /* Remember that data window content elements are of type struct |
792 | tui_gen_win_info *, each of which whose single element is a data | |
793 | element. */ | |
6ba8e26f | 794 | for (i = 0; i < content_size; i++) |
c906108c | 795 | { |
9a2b4c1b MS |
796 | struct tui_gen_win_info *generic_win |
797 | = &content[i]->which_element.data_window; | |
c906108c | 798 | |
6ba8e26f | 799 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 800 | { |
6ba8e26f | 801 | tui_delete_win (generic_win->handle); |
e65b5245 | 802 | generic_win->handle = NULL; |
6ba8e26f | 803 | tui_free_win_content (generic_win); |
c906108c SS |
804 | } |
805 | } | |
6ba8e26f | 806 | free_content (content, |
08ef48c5 MS |
807 | content_size, |
808 | DATA_WIN); | |
6ba8e26f | 809 | } |
c906108c SS |
810 | |
811 | ||
812 | /********************************** | |
813 | ** LOCAL STATIC FUNCTIONS ** | |
814 | **********************************/ | |
815 | ||
816 | ||
c906108c | 817 | static void |
08ef48c5 MS |
818 | free_content (tui_win_content content, |
819 | int content_size, | |
820 | enum tui_win_type win_type) | |
c906108c | 821 | { |
2a8854a7 | 822 | if (content != (tui_win_content) NULL) |
c906108c | 823 | { |
6ba8e26f | 824 | free_content_elements (content, content_size, win_type); |
22940a24 | 825 | xfree (content); |
c906108c | 826 | } |
6ba8e26f | 827 | } |
c906108c SS |
828 | |
829 | ||
ef5eab5a | 830 | /* free_content_elements(). |
c5aa993b | 831 | */ |
c906108c | 832 | static void |
08ef48c5 MS |
833 | free_content_elements (tui_win_content content, |
834 | int content_size, | |
835 | enum tui_win_type type) | |
c906108c | 836 | { |
2a8854a7 | 837 | if (content != (tui_win_content) NULL) |
c906108c SS |
838 | { |
839 | int i; | |
840 | ||
62f29fda | 841 | if (type == DISASSEM_WIN) |
c906108c | 842 | { |
1cc6d956 | 843 | /* Free whole source block. */ |
6d012f14 | 844 | xfree (content[0]->which_element.source.line); |
c906108c SS |
845 | } |
846 | else | |
847 | { | |
6ba8e26f | 848 | for (i = 0; i < content_size; i++) |
c906108c | 849 | { |
5b6fe301 | 850 | struct tui_win_element *element; |
c906108c SS |
851 | |
852 | element = content[i]; | |
2a8854a7 | 853 | if (element != (struct tui_win_element *) NULL) |
c906108c SS |
854 | { |
855 | switch (type) | |
856 | { | |
62f29fda TT |
857 | case SRC_WIN: |
858 | xfree (element->which_element.source.line); | |
859 | break; | |
c906108c | 860 | case DATA_WIN: |
22940a24 | 861 | xfree (element); |
c906108c SS |
862 | break; |
863 | case DATA_ITEM_WIN: | |
ef5eab5a MS |
864 | /* Note that data elements are not allocated in |
865 | a single block, but individually, as | |
866 | needed. */ | |
6d012f14 AC |
867 | if (element->which_element.data.type != TUI_REGISTER) |
868 | xfree ((void *)element->which_element.data.name); | |
869 | xfree (element->which_element.data.value); | |
10f59415 | 870 | xfree (element->which_element.data.content); |
22940a24 | 871 | xfree (element); |
c906108c SS |
872 | break; |
873 | case CMD_WIN: | |
6d012f14 | 874 | xfree (element->which_element.command.line); |
c906108c SS |
875 | break; |
876 | default: | |
877 | break; | |
878 | } | |
879 | } | |
880 | } | |
881 | } | |
882 | if (type != DATA_WIN && type != DATA_ITEM_WIN) | |
1cc6d956 | 883 | xfree (content[0]); /* Free the element block. */ |
c906108c | 884 | } |
6ba8e26f | 885 | } |