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