]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-windata.c
* ada-lang.c (field_alignment): Guard against NULL.
[thirdparty/binutils-gdb.git] / gdb / tui / tui-windata.c
CommitLineData
f377b406 1/* Data/register window display.
f33c6cbf 2
6aba47ca
DJ
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
4 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
12 the Free Software Foundation; either version 2 of the License, or
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
21 along with this program; if not, write to the Free Software
88d83552
EZ
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
c906108c 24
96ec9981 25#include "defs.h"
d7b2e967
AC
26#include "tui/tui.h"
27#include "tui/tui-data.h"
28#include "tui/tui-wingeneral.h"
29#include "tui/tui-regs.h"
f33c6cbf 30
88289b6e 31#include "gdb_string.h"
6a83354a 32#include "gdb_curses.h"
4e8f7a8b 33
c906108c
SS
34
35/*****************************************
36** STATIC LOCAL FUNCTIONS FORWARD DECLS **
37******************************************/
38
39
40
41/*****************************************
42** PUBLIC FUNCTIONS **
43******************************************/
44
45
6ba8e26f
AC
46/* Answer the index first element displayed. If none are displayed,
47 then return (-1). */
c906108c 48int
6ba8e26f 49tui_first_data_item_displayed (void)
c906108c 50{
6ba8e26f 51 int element_no = (-1);
c906108c
SS
52 int i;
53
6ba8e26f 54 for (i = 0; (i < TUI_DATA_WIN->generic.content_size && element_no < 0); i++)
c906108c 55 {
6ba8e26f 56 struct tui_gen_win_info * data_item_win;
c906108c 57
6ba8e26f 58 data_item_win = &((tui_win_content)
6d012f14 59 TUI_DATA_WIN->generic.content)[i]->which_element.data_window;
6ba8e26f
AC
60 if (data_item_win->handle != (WINDOW *) NULL && data_item_win->is_visible)
61 element_no = i;
c906108c
SS
62 }
63
6ba8e26f
AC
64 return element_no;
65}
c906108c
SS
66
67
6ba8e26f
AC
68/* Answer the index of the first element in line_no. If line_no is
69 past the data area (-1) is returned. */
c906108c 70int
6ba8e26f 71tui_first_data_element_no_in_line (int line_no)
c906108c 72{
6ba8e26f 73 int first_element_no = (-1);
c906108c
SS
74
75 /*
6ba8e26f 76 ** First see if there is a register on line_no, and if so, set the
c5aa993b
JM
77 ** first element number
78 */
6ba8e26f 79 if ((first_element_no = tui_first_reg_element_no_inline (line_no)) == -1)
c906108c 80 { /*
6ba8e26f 81 ** Looking at the general data, the 1st element on line_no
c5aa993b 82 */
c906108c
SS
83 }
84
6ba8e26f
AC
85 return first_element_no;
86}
c906108c
SS
87
88
6ba8e26f
AC
89/* Function to delete all the item windows in the data window. This
90 is usually done when the data window is scrolled. */
c906108c 91void
6ba8e26f 92tui_delete_data_content_windows (void)
c906108c
SS
93{
94 int i;
6ba8e26f 95 struct tui_gen_win_info * data_item_win_ptr;
c906108c 96
6d012f14 97 for (i = 0; (i < TUI_DATA_WIN->generic.content_size); i++)
c906108c 98 {
6ba8e26f 99 data_item_win_ptr = &((tui_win_content)
6d012f14 100 TUI_DATA_WIN->generic.content)[i]->which_element.data_window;
6ba8e26f
AC
101 tui_delete_win (data_item_win_ptr->handle);
102 data_item_win_ptr->handle = (WINDOW *) NULL;
103 data_item_win_ptr->is_visible = FALSE;
c906108c 104 }
6ba8e26f 105}
c906108c
SS
106
107
108void
edae1ccf 109tui_erase_data_content (char *prompt)
c906108c 110{
6d012f14
AC
111 werase (TUI_DATA_WIN->generic.handle);
112 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
c906108c
SS
113 if (prompt != (char *) NULL)
114 {
6ba8e26f
AC
115 int half_width = (TUI_DATA_WIN->generic.width - 2) / 2;
116 int x_pos;
c906108c 117
6ba8e26f
AC
118 if (strlen (prompt) >= half_width)
119 x_pos = 1;
c906108c 120 else
6ba8e26f 121 x_pos = half_width - strlen (prompt);
6d012f14
AC
122 mvwaddstr (TUI_DATA_WIN->generic.handle,
123 (TUI_DATA_WIN->generic.height / 2),
6ba8e26f 124 x_pos,
c906108c
SS
125 prompt);
126 }
6d012f14 127 wrefresh (TUI_DATA_WIN->generic.handle);
edae1ccf 128}
c906108c
SS
129
130
edae1ccf
AC
131/* This function displays the data that is in the data window's
132 content. It does not set the content. */
c906108c 133void
edae1ccf 134tui_display_all_data (void)
c906108c 135{
6d012f14 136 if (TUI_DATA_WIN->generic.content_size <= 0)
edae1ccf 137 tui_erase_data_content (NO_DATA_STRING);
c906108c
SS
138 else
139 {
edae1ccf 140 tui_erase_data_content ((char *) NULL);
6ba8e26f 141 tui_delete_data_content_windows ();
6d012f14 142 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
55fb0713 143 tui_display_registers_from (0);
c906108c 144 /*
c5aa993b
JM
145 ** Then display the other data
146 */
6d012f14 147 if (TUI_DATA_WIN->detail.data_display_info.data_content !=
2a8854a7 148 (tui_win_content) NULL &&
6d012f14 149 TUI_DATA_WIN->detail.data_display_info.data_content_count > 0)
c906108c
SS
150 {
151 }
152 }
edae1ccf 153}
c906108c
SS
154
155
6ba8e26f
AC
156/* Function to display the data starting at line, line_no, in the data
157 window. */
c906108c 158void
6ba8e26f 159tui_display_data_from_line (int line_no)
c906108c 160{
6ba8e26f 161 int _line_no = line_no;
c906108c 162
6ba8e26f
AC
163 if (line_no < 0)
164 _line_no = 0;
c906108c 165
6d012f14 166 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
c906108c
SS
167
168 /* there is no general data, force regs to display (if there are any) */
6d012f14 169 if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0)
6ba8e26f 170 tui_display_registers_from_line (_line_no, TRUE);
c906108c
SS
171 else
172 {
6ba8e26f
AC
173 int element_no, start_line_no;
174 int regs_last_line = tui_last_regs_line_no ();
c906108c
SS
175
176
177 /* display regs if we can */
6ba8e26f 178 if (tui_display_registers_from_line (_line_no, FALSE) < 0)
c906108c 179 { /*
6ba8e26f 180 ** _line_no is past the regs display, so calc where the
c5aa993b
JM
181 ** start data element is
182 */
6ba8e26f 183 if (regs_last_line < _line_no)
c906108c 184 { /* figure out how many lines each element is to obtain
6ba8e26f 185 the start element_no */
c906108c
SS
186 }
187 }
188 else
189 { /*
c5aa993b 190 ** calculate the starting element of the data display, given
6ba8e26f
AC
191 ** regs_last_line and how many lines each element is, up to
192 ** _line_no
c5aa993b 193 */
c906108c 194 }
6ba8e26f 195 /* Now display the data , starting at element_no */
c906108c 196 }
6ba8e26f 197}
c906108c
SS
198
199
6ba8e26f 200/* Display data starting at element element_no. */
c906108c 201void
6ba8e26f 202tui_display_data_from (int element_no, int reuse_windows)
c906108c 203{
6ba8e26f 204 int first_line = (-1);
c906108c 205
6ba8e26f
AC
206 if (element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
207 first_line = tui_line_from_reg_element_no (element_no);
c906108c 208 else
6ba8e26f 209 { /* calculate the first_line from the element number */
c906108c
SS
210 }
211
6ba8e26f 212 if (first_line >= 0)
c906108c 213 {
edae1ccf 214 tui_erase_data_content ((char *) NULL);
6ba8e26f
AC
215 if (!reuse_windows)
216 tui_delete_data_content_windows ();
217 tui_display_data_from_line (first_line);
c906108c 218 }
6ba8e26f 219}
c906108c
SS
220
221
edae1ccf 222/* Function to redisplay the contents of the data window. */
c906108c 223void
edae1ccf 224tui_refresh_data_win (void)
c906108c 225{
edae1ccf 226 tui_erase_data_content ((char *) NULL);
6d012f14 227 if (TUI_DATA_WIN->generic.content_size > 0)
c906108c 228 {
6ba8e26f 229 int first_element = tui_first_data_item_displayed ();
c906108c 230
6ba8e26f
AC
231 if (first_element >= 0) /* re-use existing windows */
232 tui_display_data_from (first_element, TRUE);
c906108c 233 }
edae1ccf 234}
c906108c
SS
235
236
edae1ccf 237/* Function to check the data values and hilite any that have changed. */
c906108c 238void
edae1ccf 239tui_check_data_values (struct frame_info *frame)
c906108c 240{
55fb0713 241 tui_check_register_values (frame);
c906108c
SS
242
243 /* Now check any other data values that there are */
6d012f14 244 if (TUI_DATA_WIN != NULL && TUI_DATA_WIN->generic.is_visible)
c906108c
SS
245 {
246 int i;
247
6d012f14 248 for (i = 0; TUI_DATA_WIN->detail.data_display_info.data_content_count; i++)
c906108c
SS
249 {
250#ifdef LATER
6ba8e26f
AC
251 tui_data_element_ptr data_element_ptr;
252 struct tui_gen_win_info * data_item_win_ptr;
253 Opaque new_value;
c906108c 254
6ba8e26f 255 data_item_ptr = &TUI_DATA_WIN->detail.data_display_info.
6d012f14 256 data_content[i]->which_element.data_window;
6ba8e26f
AC
257 data_element_ptr = &((tui_win_content)
258 data_item_win_ptr->content)[0]->which_element.data;
c906108c 259 if value
6ba8e26f 260 has changed (data_element_ptr, frame, &new_value)
c906108c 261 {
6ba8e26f 262 data_element_ptr->value = new_value;
c906108c
SS
263 update the display with the new value, hiliting it.
264 }
265#endif
266 }
267 }
edae1ccf 268}
c906108c
SS
269
270
edae1ccf 271/* Scroll the data window vertically forward or backward. */
c906108c 272void
6ba8e26f 273tui_vertical_data_scroll (enum tui_scroll_direction scroll_direction, int num_to_scroll)
c906108c 274{
6ba8e26f
AC
275 int first_element_no;
276 int first_line = (-1);
c906108c 277
6ba8e26f
AC
278 first_element_no = tui_first_data_item_displayed ();
279 if (first_element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
280 first_line = tui_line_from_reg_element_no (first_element_no);
c906108c
SS
281 else
282 { /* calculate the first line from the element number which is in
c5aa993b
JM
283 ** the general data content
284 */
c906108c
SS
285 }
286
6ba8e26f 287 if (first_line >= 0)
c906108c 288 {
6ba8e26f 289 int last_element_no, last_line;
c906108c 290
6ba8e26f
AC
291 if (scroll_direction == FORWARD_SCROLL)
292 first_line += num_to_scroll;
c906108c 293 else
6ba8e26f 294 first_line -= num_to_scroll;
edae1ccf 295 tui_erase_data_content ((char *) NULL);
6ba8e26f
AC
296 tui_delete_data_content_windows ();
297 tui_display_data_from_line (first_line);
c906108c 298 }
6ba8e26f 299}
c906108c
SS
300
301
302/*****************************************
303** STATIC LOCAL FUNCTIONS **
304******************************************/