15796c8dcSSimon Schubert /* Data/register window display.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1998-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert Contributed by Hewlett-Packard Company.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This file is part of GDB.
85796c8dcSSimon Schubert
95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert (at your option) any later version.
135796c8dcSSimon Schubert
145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175796c8dcSSimon Schubert GNU General Public License for more details.
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
215796c8dcSSimon Schubert
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include "tui/tui.h"
245796c8dcSSimon Schubert #include "tui/tui-data.h"
255796c8dcSSimon Schubert #include "tui/tui-wingeneral.h"
265796c8dcSSimon Schubert #include "tui/tui-regs.h"
275796c8dcSSimon Schubert #include "tui/tui-windata.h"
285796c8dcSSimon Schubert
295796c8dcSSimon Schubert #include "gdb_string.h"
305796c8dcSSimon Schubert #include "gdb_curses.h"
315796c8dcSSimon Schubert
325796c8dcSSimon Schubert
335796c8dcSSimon Schubert /*****************************************
345796c8dcSSimon Schubert ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
355796c8dcSSimon Schubert ******************************************/
365796c8dcSSimon Schubert
375796c8dcSSimon Schubert
385796c8dcSSimon Schubert
395796c8dcSSimon Schubert /*****************************************
405796c8dcSSimon Schubert ** PUBLIC FUNCTIONS **
415796c8dcSSimon Schubert ******************************************/
425796c8dcSSimon Schubert
435796c8dcSSimon Schubert
445796c8dcSSimon Schubert /* Answer the index first element displayed. If none are displayed,
455796c8dcSSimon Schubert then return (-1). */
465796c8dcSSimon Schubert int
tui_first_data_item_displayed(void)475796c8dcSSimon Schubert tui_first_data_item_displayed (void)
485796c8dcSSimon Schubert {
495796c8dcSSimon Schubert int element_no = (-1);
505796c8dcSSimon Schubert int i;
515796c8dcSSimon Schubert
525796c8dcSSimon Schubert for (i = 0;
535796c8dcSSimon Schubert i < TUI_DATA_WIN->generic.content_size && element_no < 0;
545796c8dcSSimon Schubert i++)
555796c8dcSSimon Schubert {
565796c8dcSSimon Schubert struct tui_gen_win_info *data_item_win;
575796c8dcSSimon Schubert
585796c8dcSSimon Schubert data_item_win = &((tui_win_content)
595796c8dcSSimon Schubert TUI_DATA_WIN->generic.content)[i]->which_element.data_window;
605796c8dcSSimon Schubert if (data_item_win->handle != (WINDOW *) NULL
615796c8dcSSimon Schubert && data_item_win->is_visible)
625796c8dcSSimon Schubert element_no = i;
635796c8dcSSimon Schubert }
645796c8dcSSimon Schubert
655796c8dcSSimon Schubert return element_no;
665796c8dcSSimon Schubert }
675796c8dcSSimon Schubert
685796c8dcSSimon Schubert
695796c8dcSSimon Schubert /* Answer the index of the first element in line_no. If line_no is
705796c8dcSSimon Schubert past the data area (-1) is returned. */
715796c8dcSSimon Schubert int
tui_first_data_element_no_in_line(int line_no)725796c8dcSSimon Schubert tui_first_data_element_no_in_line (int line_no)
735796c8dcSSimon Schubert {
745796c8dcSSimon Schubert int first_element_no = (-1);
755796c8dcSSimon Schubert
765796c8dcSSimon Schubert /* First see if there is a register on line_no, and if so, set the
775796c8dcSSimon Schubert first element number. */
785796c8dcSSimon Schubert if ((first_element_no = tui_first_reg_element_no_inline (line_no)) == -1)
795796c8dcSSimon Schubert { /* Looking at the general data, the 1st element on line_no. */
805796c8dcSSimon Schubert }
815796c8dcSSimon Schubert
825796c8dcSSimon Schubert return first_element_no;
835796c8dcSSimon Schubert }
845796c8dcSSimon Schubert
855796c8dcSSimon Schubert
865796c8dcSSimon Schubert /* Function to delete all the item windows in the data window. This
875796c8dcSSimon Schubert is usually done when the data window is scrolled. */
885796c8dcSSimon Schubert void
tui_delete_data_content_windows(void)895796c8dcSSimon Schubert tui_delete_data_content_windows (void)
905796c8dcSSimon Schubert {
915796c8dcSSimon Schubert int i;
925796c8dcSSimon Schubert struct tui_gen_win_info *data_item_win_ptr;
935796c8dcSSimon Schubert
945796c8dcSSimon Schubert for (i = 0; (i < TUI_DATA_WIN->generic.content_size); i++)
955796c8dcSSimon Schubert {
965796c8dcSSimon Schubert data_item_win_ptr = &((tui_win_content)
975796c8dcSSimon Schubert TUI_DATA_WIN->generic.content)[i]->which_element.data_window;
985796c8dcSSimon Schubert tui_delete_win (data_item_win_ptr->handle);
995796c8dcSSimon Schubert data_item_win_ptr->handle = (WINDOW *) NULL;
1005796c8dcSSimon Schubert data_item_win_ptr->is_visible = FALSE;
1015796c8dcSSimon Schubert }
1025796c8dcSSimon Schubert }
1035796c8dcSSimon Schubert
1045796c8dcSSimon Schubert
1055796c8dcSSimon Schubert void
tui_erase_data_content(char * prompt)1065796c8dcSSimon Schubert tui_erase_data_content (char *prompt)
1075796c8dcSSimon Schubert {
1085796c8dcSSimon Schubert werase (TUI_DATA_WIN->generic.handle);
1095796c8dcSSimon Schubert tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
1105796c8dcSSimon Schubert if (prompt != (char *) NULL)
1115796c8dcSSimon Schubert {
1125796c8dcSSimon Schubert int half_width = (TUI_DATA_WIN->generic.width - 2) / 2;
1135796c8dcSSimon Schubert int x_pos;
1145796c8dcSSimon Schubert
1155796c8dcSSimon Schubert if (strlen (prompt) >= half_width)
1165796c8dcSSimon Schubert x_pos = 1;
1175796c8dcSSimon Schubert else
1185796c8dcSSimon Schubert x_pos = half_width - strlen (prompt);
1195796c8dcSSimon Schubert mvwaddstr (TUI_DATA_WIN->generic.handle,
1205796c8dcSSimon Schubert (TUI_DATA_WIN->generic.height / 2),
1215796c8dcSSimon Schubert x_pos,
1225796c8dcSSimon Schubert prompt);
1235796c8dcSSimon Schubert }
1245796c8dcSSimon Schubert wrefresh (TUI_DATA_WIN->generic.handle);
1255796c8dcSSimon Schubert }
1265796c8dcSSimon Schubert
1275796c8dcSSimon Schubert
1285796c8dcSSimon Schubert /* This function displays the data that is in the data window's
1295796c8dcSSimon Schubert content. It does not set the content. */
1305796c8dcSSimon Schubert void
tui_display_all_data(void)1315796c8dcSSimon Schubert tui_display_all_data (void)
1325796c8dcSSimon Schubert {
1335796c8dcSSimon Schubert if (TUI_DATA_WIN->generic.content_size <= 0)
1345796c8dcSSimon Schubert tui_erase_data_content (NO_DATA_STRING);
1355796c8dcSSimon Schubert else
1365796c8dcSSimon Schubert {
1375796c8dcSSimon Schubert tui_erase_data_content ((char *) NULL);
1385796c8dcSSimon Schubert tui_delete_data_content_windows ();
1395796c8dcSSimon Schubert tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
1405796c8dcSSimon Schubert tui_display_registers_from (0);
1415796c8dcSSimon Schubert
1425796c8dcSSimon Schubert /* Then display the other data. */
1435796c8dcSSimon Schubert if (TUI_DATA_WIN->detail.data_display_info.data_content !=
1445796c8dcSSimon Schubert (tui_win_content) NULL
1455796c8dcSSimon Schubert && TUI_DATA_WIN->detail.data_display_info.data_content_count > 0)
1465796c8dcSSimon Schubert {
1475796c8dcSSimon Schubert }
1485796c8dcSSimon Schubert }
1495796c8dcSSimon Schubert }
1505796c8dcSSimon Schubert
1515796c8dcSSimon Schubert
1525796c8dcSSimon Schubert /* Function to display the data starting at line, line_no, in the data
1535796c8dcSSimon Schubert window. */
1545796c8dcSSimon Schubert void
tui_display_data_from_line(int line_no)1555796c8dcSSimon Schubert tui_display_data_from_line (int line_no)
1565796c8dcSSimon Schubert {
1575796c8dcSSimon Schubert int _line_no = line_no;
1585796c8dcSSimon Schubert
1595796c8dcSSimon Schubert if (line_no < 0)
1605796c8dcSSimon Schubert _line_no = 0;
1615796c8dcSSimon Schubert
1625796c8dcSSimon Schubert tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
1635796c8dcSSimon Schubert
1645796c8dcSSimon Schubert /* There is no general data, force regs to display (if there are
1655796c8dcSSimon Schubert any). */
1665796c8dcSSimon Schubert if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0)
1675796c8dcSSimon Schubert tui_display_registers_from_line (_line_no, TRUE);
1685796c8dcSSimon Schubert else
1695796c8dcSSimon Schubert {
1705796c8dcSSimon Schubert int regs_last_line = tui_last_regs_line_no ();
1715796c8dcSSimon Schubert
1725796c8dcSSimon Schubert
1735796c8dcSSimon Schubert /* Display regs if we can. */
1745796c8dcSSimon Schubert if (tui_display_registers_from_line (_line_no, FALSE) < 0)
1755796c8dcSSimon Schubert { /* _line_no is past the regs display, so calc where the
1765796c8dcSSimon Schubert start data element is. */
1775796c8dcSSimon Schubert if (regs_last_line < _line_no)
1785796c8dcSSimon Schubert { /* Figure out how many lines each element is to obtain
1795796c8dcSSimon Schubert the start element_no. */
1805796c8dcSSimon Schubert }
1815796c8dcSSimon Schubert }
1825796c8dcSSimon Schubert else
1835796c8dcSSimon Schubert { /* Calculate the starting element of the data display, given
1845796c8dcSSimon Schubert regs_last_line and how many lines each element is, up to
1855796c8dcSSimon Schubert _line_no. */
1865796c8dcSSimon Schubert }
1875796c8dcSSimon Schubert /* Now display the data , starting at element_no. */
1885796c8dcSSimon Schubert }
1895796c8dcSSimon Schubert }
1905796c8dcSSimon Schubert
1915796c8dcSSimon Schubert
1925796c8dcSSimon Schubert /* Display data starting at element element_no. */
1935796c8dcSSimon Schubert void
tui_display_data_from(int element_no,int reuse_windows)1945796c8dcSSimon Schubert tui_display_data_from (int element_no, int reuse_windows)
1955796c8dcSSimon Schubert {
1965796c8dcSSimon Schubert int first_line = (-1);
1975796c8dcSSimon Schubert
1985796c8dcSSimon Schubert if (element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
1995796c8dcSSimon Schubert first_line = tui_line_from_reg_element_no (element_no);
2005796c8dcSSimon Schubert else
2015796c8dcSSimon Schubert { /* Calculate the first_line from the element number. */
2025796c8dcSSimon Schubert }
2035796c8dcSSimon Schubert
2045796c8dcSSimon Schubert if (first_line >= 0)
2055796c8dcSSimon Schubert {
2065796c8dcSSimon Schubert tui_erase_data_content ((char *) NULL);
2075796c8dcSSimon Schubert if (!reuse_windows)
2085796c8dcSSimon Schubert tui_delete_data_content_windows ();
2095796c8dcSSimon Schubert tui_display_data_from_line (first_line);
2105796c8dcSSimon Schubert }
2115796c8dcSSimon Schubert }
2125796c8dcSSimon Schubert
2135796c8dcSSimon Schubert
2145796c8dcSSimon Schubert /* Function to redisplay the contents of the data window. */
2155796c8dcSSimon Schubert void
tui_refresh_data_win(void)2165796c8dcSSimon Schubert tui_refresh_data_win (void)
2175796c8dcSSimon Schubert {
2185796c8dcSSimon Schubert tui_erase_data_content ((char *) NULL);
2195796c8dcSSimon Schubert if (TUI_DATA_WIN->generic.content_size > 0)
2205796c8dcSSimon Schubert {
2215796c8dcSSimon Schubert int first_element = tui_first_data_item_displayed ();
2225796c8dcSSimon Schubert
2235796c8dcSSimon Schubert if (first_element >= 0) /* Re-use existing windows. */
2245796c8dcSSimon Schubert tui_display_data_from (first_element, TRUE);
2255796c8dcSSimon Schubert }
2265796c8dcSSimon Schubert }
2275796c8dcSSimon Schubert
2285796c8dcSSimon Schubert
2295796c8dcSSimon Schubert /* Function to check the data values and hilite any that have
2305796c8dcSSimon Schubert changed. */
2315796c8dcSSimon Schubert void
tui_check_data_values(struct frame_info * frame)2325796c8dcSSimon Schubert tui_check_data_values (struct frame_info *frame)
2335796c8dcSSimon Schubert {
2345796c8dcSSimon Schubert tui_check_register_values (frame);
2355796c8dcSSimon Schubert
2365796c8dcSSimon Schubert /* Now check any other data values that there are. */
2375796c8dcSSimon Schubert if (TUI_DATA_WIN != NULL && TUI_DATA_WIN->generic.is_visible)
2385796c8dcSSimon Schubert {
2395796c8dcSSimon Schubert int i;
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert for (i = 0;
2425796c8dcSSimon Schubert TUI_DATA_WIN->detail.data_display_info.data_content_count;
2435796c8dcSSimon Schubert i++)
2445796c8dcSSimon Schubert {
2455796c8dcSSimon Schubert #ifdef LATER
2465796c8dcSSimon Schubert tui_data_element_ptr data_element_ptr;
2475796c8dcSSimon Schubert struct tui_gen_win_info *data_item_win_ptr;
2485796c8dcSSimon Schubert Opaque new_value;
2495796c8dcSSimon Schubert
2505796c8dcSSimon Schubert data_item_ptr = &TUI_DATA_WIN->detail.data_display_info.
2515796c8dcSSimon Schubert data_content[i]->which_element.data_window;
2525796c8dcSSimon Schubert data_element_ptr = &((tui_win_content)
2535796c8dcSSimon Schubert data_item_win_ptr->content)[0]->which_element.data;
2545796c8dcSSimon Schubert if value
2555796c8dcSSimon Schubert has changed (data_element_ptr, frame, &new_value)
2565796c8dcSSimon Schubert {
2575796c8dcSSimon Schubert data_element_ptr->value = new_value;
2585796c8dcSSimon Schubert update the display with the new value, hiliting it.
2595796c8dcSSimon Schubert }
2605796c8dcSSimon Schubert #endif
2615796c8dcSSimon Schubert }
2625796c8dcSSimon Schubert }
2635796c8dcSSimon Schubert }
2645796c8dcSSimon Schubert
2655796c8dcSSimon Schubert
2665796c8dcSSimon Schubert /* Scroll the data window vertically forward or backward. */
2675796c8dcSSimon Schubert void
tui_vertical_data_scroll(enum tui_scroll_direction scroll_direction,int num_to_scroll)2685796c8dcSSimon Schubert tui_vertical_data_scroll (enum tui_scroll_direction scroll_direction,
2695796c8dcSSimon Schubert int num_to_scroll)
2705796c8dcSSimon Schubert {
2715796c8dcSSimon Schubert int first_element_no;
2725796c8dcSSimon Schubert int first_line = (-1);
2735796c8dcSSimon Schubert
2745796c8dcSSimon Schubert first_element_no = tui_first_data_item_displayed ();
275c50c785cSJohn Marino if (first_element_no
276c50c785cSJohn Marino < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
2775796c8dcSSimon Schubert first_line = tui_line_from_reg_element_no (first_element_no);
2785796c8dcSSimon Schubert else
2795796c8dcSSimon Schubert { /* Calculate the first line from the element number which is in
2805796c8dcSSimon Schubert the general data content. */
2815796c8dcSSimon Schubert }
2825796c8dcSSimon Schubert
2835796c8dcSSimon Schubert if (first_line >= 0)
2845796c8dcSSimon Schubert {
2855796c8dcSSimon Schubert if (scroll_direction == FORWARD_SCROLL)
2865796c8dcSSimon Schubert first_line += num_to_scroll;
2875796c8dcSSimon Schubert else
2885796c8dcSSimon Schubert first_line -= num_to_scroll;
2895796c8dcSSimon Schubert tui_erase_data_content ((char *) NULL);
2905796c8dcSSimon Schubert tui_delete_data_content_windows ();
2915796c8dcSSimon Schubert tui_display_data_from_line (first_line);
2925796c8dcSSimon Schubert }
2935796c8dcSSimon Schubert }
2945796c8dcSSimon Schubert
2955796c8dcSSimon Schubert
2965796c8dcSSimon Schubert /*****************************************
2975796c8dcSSimon Schubert ** STATIC LOCAL FUNCTIONS **
2985796c8dcSSimon Schubert ******************************************/
299