| 1 | /* Data/register window display. |
| 2 | |
| 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
| 4 | |
| 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 |
| 11 | the Free Software Foundation; either version 3 of the License, or |
| 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 |
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "tui/tui.h" |
| 24 | #include "tui/tui-data.h" |
| 25 | #include "tui/tui-wingeneral.h" |
| 26 | #include "tui/tui-regs.h" |
| 27 | #include "tui/tui-windata.h" |
| 28 | #include "gdb_curses.h" |
| 29 | |
| 30 | |
| 31 | /***************************************** |
| 32 | ** STATIC LOCAL FUNCTIONS FORWARD DECLS ** |
| 33 | ******************************************/ |
| 34 | |
| 35 | |
| 36 | |
| 37 | /***************************************** |
| 38 | ** PUBLIC FUNCTIONS ** |
| 39 | ******************************************/ |
| 40 | |
| 41 | |
| 42 | /* Answer the index first element displayed. If none are displayed, |
| 43 | then return (-1). */ |
| 44 | int |
| 45 | tui_first_data_item_displayed (void) |
| 46 | { |
| 47 | int element_no = (-1); |
| 48 | int i; |
| 49 | |
| 50 | for (i = 0; |
| 51 | i < TUI_DATA_WIN->content_size && element_no < 0; |
| 52 | i++) |
| 53 | { |
| 54 | struct tui_gen_win_info *data_item_win; |
| 55 | |
| 56 | data_item_win |
| 57 | = TUI_DATA_WIN->content[i]->which_element.data_window; |
| 58 | if (data_item_win->handle != NULL |
| 59 | && data_item_win->is_visible) |
| 60 | element_no = i; |
| 61 | } |
| 62 | |
| 63 | return element_no; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /* Function to delete all the item windows in the data window. This |
| 68 | is usually done when the data window is scrolled. */ |
| 69 | void |
| 70 | tui_delete_data_content_windows (void) |
| 71 | { |
| 72 | int i; |
| 73 | struct tui_gen_win_info *data_item_win_ptr; |
| 74 | |
| 75 | for (i = 0; (i < TUI_DATA_WIN->content_size); i++) |
| 76 | { |
| 77 | data_item_win_ptr |
| 78 | = TUI_DATA_WIN->content[i]->which_element.data_window; |
| 79 | tui_delete_win (data_item_win_ptr->handle); |
| 80 | data_item_win_ptr->handle = NULL; |
| 81 | data_item_win_ptr->is_visible = false; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void |
| 87 | tui_erase_data_content (const char *prompt) |
| 88 | { |
| 89 | werase (TUI_DATA_WIN->handle); |
| 90 | tui_check_and_display_highlight_if_needed (TUI_DATA_WIN); |
| 91 | if (prompt != NULL) |
| 92 | { |
| 93 | int half_width = (TUI_DATA_WIN->width - 2) / 2; |
| 94 | int x_pos; |
| 95 | |
| 96 | if (strlen (prompt) >= half_width) |
| 97 | x_pos = 1; |
| 98 | else |
| 99 | x_pos = half_width - strlen (prompt); |
| 100 | mvwaddstr (TUI_DATA_WIN->handle, |
| 101 | (TUI_DATA_WIN->height / 2), |
| 102 | x_pos, |
| 103 | (char *) prompt); |
| 104 | } |
| 105 | wrefresh (TUI_DATA_WIN->handle); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /* This function displays the data that is in the data window's |
| 110 | content. It does not set the content. */ |
| 111 | void |
| 112 | tui_display_all_data (void) |
| 113 | { |
| 114 | if (TUI_DATA_WIN->content_size <= 0) |
| 115 | tui_erase_data_content (NO_DATA_STRING); |
| 116 | else |
| 117 | { |
| 118 | tui_erase_data_content (NULL); |
| 119 | tui_delete_data_content_windows (); |
| 120 | tui_check_and_display_highlight_if_needed (TUI_DATA_WIN); |
| 121 | tui_display_registers_from (0); |
| 122 | |
| 123 | /* Then display the other data. */ |
| 124 | if (TUI_DATA_WIN->data_content != NULL |
| 125 | && TUI_DATA_WIN->data_content_count > 0) |
| 126 | { |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
| 132 | /* Function to display the data starting at line, line_no, in the data |
| 133 | window. */ |
| 134 | void |
| 135 | tui_display_data_from_line (int line_no) |
| 136 | { |
| 137 | int _line_no = line_no; |
| 138 | |
| 139 | if (line_no < 0) |
| 140 | _line_no = 0; |
| 141 | |
| 142 | tui_check_and_display_highlight_if_needed (TUI_DATA_WIN); |
| 143 | |
| 144 | /* There is no general data, force regs to display (if there are |
| 145 | any). */ |
| 146 | if (TUI_DATA_WIN->data_content_count <= 0) |
| 147 | tui_display_registers_from_line (_line_no, TRUE); |
| 148 | else |
| 149 | { |
| 150 | int regs_last_line = tui_last_regs_line_no (); |
| 151 | |
| 152 | |
| 153 | /* Display regs if we can. */ |
| 154 | if (tui_display_registers_from_line (_line_no, FALSE) < 0) |
| 155 | { /* _line_no is past the regs display, so calc where the |
| 156 | start data element is. */ |
| 157 | if (regs_last_line < _line_no) |
| 158 | { /* Figure out how many lines each element is to obtain |
| 159 | the start element_no. */ |
| 160 | } |
| 161 | } |
| 162 | else |
| 163 | { /* Calculate the starting element of the data display, given |
| 164 | regs_last_line and how many lines each element is, up to |
| 165 | _line_no. */ |
| 166 | } |
| 167 | /* Now display the data , starting at element_no. */ |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /* Display data starting at element element_no. */ |
| 173 | void |
| 174 | tui_display_data_from (int element_no, int reuse_windows) |
| 175 | { |
| 176 | int first_line = (-1); |
| 177 | |
| 178 | if (element_no < TUI_DATA_WIN->regs_content_count) |
| 179 | first_line = tui_line_from_reg_element_no (element_no); |
| 180 | else |
| 181 | { /* Calculate the first_line from the element number. */ |
| 182 | } |
| 183 | |
| 184 | if (first_line >= 0) |
| 185 | { |
| 186 | tui_erase_data_content (NULL); |
| 187 | if (!reuse_windows) |
| 188 | tui_delete_data_content_windows (); |
| 189 | tui_display_data_from_line (first_line); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /* Function to redisplay the contents of the data window. */ |
| 195 | void |
| 196 | tui_data_window::refresh_all () |
| 197 | { |
| 198 | tui_erase_data_content (NULL); |
| 199 | if (content_size > 0) |
| 200 | { |
| 201 | int first_element = tui_first_data_item_displayed (); |
| 202 | |
| 203 | if (first_element >= 0) /* Re-use existing windows. */ |
| 204 | tui_display_data_from (first_element, TRUE); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /* Function to check the data values and hilite any that have |
| 210 | changed. */ |
| 211 | void |
| 212 | tui_check_data_values (struct frame_info *frame) |
| 213 | { |
| 214 | tui_check_register_values (frame); |
| 215 | |
| 216 | /* Now check any other data values that there are. */ |
| 217 | if (TUI_DATA_WIN != NULL && TUI_DATA_WIN->is_visible) |
| 218 | { |
| 219 | int i; |
| 220 | |
| 221 | for (i = 0; TUI_DATA_WIN->data_content_count; i++) |
| 222 | { |
| 223 | #ifdef LATER |
| 224 | tui_data_element_ptr data_element_ptr; |
| 225 | struct tui_gen_win_info *data_item_win_ptr; |
| 226 | Opaque new_value; |
| 227 | |
| 228 | data_item_ptr = &TUI_DATA_WIN-> |
| 229 | data_content[i]->which_element.data_window; |
| 230 | data_element_ptr = &((tui_win_content) |
| 231 | data_item_win_ptr->content)[0]->which_element.data; |
| 232 | if value |
| 233 | has changed (data_element_ptr, frame, &new_value) |
| 234 | { |
| 235 | data_element_ptr->value = new_value; |
| 236 | update the display with the newobj value, hiliting it. |
| 237 | } |
| 238 | #endif |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | |
| 244 | /* Scroll the data window vertically forward or backward. */ |
| 245 | void |
| 246 | tui_data_window::do_scroll_vertical (int num_to_scroll) |
| 247 | { |
| 248 | int first_element_no; |
| 249 | int first_line = (-1); |
| 250 | |
| 251 | first_element_no = tui_first_data_item_displayed (); |
| 252 | if (first_element_no < regs_content_count) |
| 253 | first_line = tui_line_from_reg_element_no (first_element_no); |
| 254 | else |
| 255 | { /* Calculate the first line from the element number which is in |
| 256 | the general data content. */ |
| 257 | } |
| 258 | |
| 259 | if (first_line >= 0) |
| 260 | { |
| 261 | first_line += num_to_scroll; |
| 262 | tui_erase_data_content (NULL); |
| 263 | tui_delete_data_content_windows (); |
| 264 | tui_display_data_from_line (first_line); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | |
| 269 | /***************************************** |
| 270 | ** STATIC LOCAL FUNCTIONS ** |
| 271 | ******************************************/ |