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