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