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