+2021-01-28 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * Makefile.in (SUBDIR_TUI_SRCS): Add tui/tui-location.c.
+ (HFILES_NO_SRCDIR): Add tui/tui-location.h.
+ * tui/tui-data.h (TUI_STATUS_WIN): Define.
+ (tui_locator_win_info_ptr): Delete declaration.
+ * tui/tui-disasm.c: Add 'tui/tui-location.h' include.
+ (tui_disasm_window::set_contents): Fetch state from tui_location
+ global.
+ (tui_get_begin_asm_address): Likewise.
+ * tui/tui-layout.c (tui_apply_current_layout): Remove special case
+ for locator window.
+ (get_locator_window): Delete.
+ (initialize_known_windows): Treat locator window just like all the
+ rest.
+ * tui/tui-source.c: Add 'tui/tui-location.h' include.
+ (tui_source_window::set_contents): Fetch state from tui_location
+ global.
+ (tui_source_window::showing_source_p): Likewise.
+ * tui/tui-stack.c: Add 'tui/tui-location.h' include.
+ (_locator): Delete.
+ (tui_locator_win_info_ptr): Delete.
+ (tui_locator_window::make_status_line): Fetch state from
+ tui_location global.
+ (tui_locator_window::rerender): Remove check of 'handle',
+ reindent function body.
+ (tui_locator_window::set_locator_fullname): Delete.
+ (tui_locator_window::set_locator_info): Delete.
+ (tui_update_locator_fullname): Delete.
+ (tui_show_frame_info): Likewise.
+ (tui_show_locator_content): Access window through TUI_STATUS_WIN.
+ * tui/tui-stack.h (tui_locator_window::set_locator_info): Moved to
+ tui/tui-location.h and renamed to
+ tui_location_tracker::set_location.
+ (tui_locator_window::set_locator_fullname): Moved to
+ tui/tui-location.h and renamed to
+ tui_location_tracker::set_fullname.
+ (tui_locator_window::full_name): Delete.
+ (tui_locator_window::proc_name): Delete.
+ (tui_locator_window::line_no): Delete.
+ (tui_locator_window::addr): Delete.
+ (tui_locator_window::gdbarch): Delete.
+ (tui_update_locator_fullname): Delete declaration.
+ * tui/tui-wingeneral.c (tui_refresh_all): Removed special handling
+ for locator window.
+ * tui/tui-winsource.c: Add 'tui/tui-location.h' include.
+ (tui_display_main): Call function on tui_location directly.
+ * tui/tui.h (enum tui_win_type): Add STATUS_WIN.
+ * tui/tui-location.c: New file.
+ * tui/tui-location.h: New file.
+
2021-01-28 Simon Marchi <simon.marchi@polymtl.ca>
* gdbtypes.h (get_type_arch): Rename to...
tui/tui-interp.c \
tui/tui-io.c \
tui/tui-layout.c \
+ tui/tui-location.c \
tui/tui-out.c \
tui/tui-regs.c \
tui/tui-source.c \
tui/tui-hooks.h \
tui/tui-io.h \
tui/tui-layout.h \
+ tui/tui-location.h \
tui/tui-out.h \
tui/tui-regs.h \
tui/tui-source.h \
#define TUI_DISASM_WIN ((tui_disasm_window *) tui_win_list[DISASSEM_WIN])
#define TUI_DATA_WIN ((tui_data_window *) tui_win_list[DATA_WIN])
#define TUI_CMD_WIN ((tui_cmd_window *) tui_win_list[CMD_WIN])
+#define TUI_STATUS_WIN ((tui_locator_window *) tui_win_list[STATUS_WIN])
/* All the windows that are currently instantiated, in layout
order. */
extern void tui_set_term_height_to (int);
extern int tui_term_width (void);
extern void tui_set_term_width_to (int);
-extern struct tui_locator_window *tui_locator_win_info_ptr (void);
extern struct tui_win_info *tui_win_with_focus (void);
extern bool tui_win_resized ();
extern void tui_set_win_resized_to (bool);
#include "progspace.h"
#include "objfiles.h"
#include "cli/cli-style.h"
+#include "tui/tui-location.h"
#include "gdb_curses.h"
int i;
int max_lines;
CORE_ADDR cur_pc;
- struct tui_locator_window *locator = tui_locator_win_info_ptr ();
int tab_len = tui_tab_width;
int insn_pos;
m_gdbarch = arch;
m_start_line_or_addr.loa = LOA_ADDRESS;
m_start_line_or_addr.u.addr = pc;
- cur_pc = locator->addr;
+ cur_pc = tui_location.addr ();
/* Window size, excluding highlight box. */
max_lines = height - 2;
void
tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
{
- struct tui_locator_window *locator;
struct gdbarch *gdbarch = get_current_arch ();
CORE_ADDR addr = 0;
- locator = tui_locator_win_info_ptr ();
-
- if (locator->addr == 0)
+ if (tui_location.addr () == 0)
{
if (have_full_symbols () || have_partial_symbols ())
{
}
else /* The target is executing. */
{
- gdbarch = locator->gdbarch;
- addr = locator->addr;
+ gdbarch = tui_location.gdbarch ();
+ addr = tui_location.addr ();
}
*gdbarch_p = gdbarch;
/* Now delete any window that was not re-applied. */
tui_win_info *focus = tui_win_with_focus ();
- tui_win_info *locator = tui_locator_win_info_ptr ();
for (tui_win_info *win_info : saved_tui_windows)
{
if (!win_info->is_visible ())
{
if (focus == win_info)
tui_set_win_focus_to (tui_windows[0]);
- if (win_info != locator)
- delete win_info;
}
}
return tui_win_list[V];
}
-/* Helper function to wrap tui_locator_win_info_ptr for
- tui_get_window_by_name. */
-
-static tui_win_info *
-get_locator_window (const char *)
-{
- return tui_locator_win_info_ptr ();
-}
-
/* A map holding all the known window types, keyed by name. Note that
this is heap-allocated and "leaked" at gdb exit. This avoids
ordering issues with destroying elements in the map at shutdown.
known_window_types->emplace (DISASSEM_NAME,
make_standard_window<DISASSEM_WIN,
tui_disasm_window>);
- known_window_types->emplace (STATUS_NAME, get_locator_window);
+ known_window_types->emplace (STATUS_NAME,
+ make_standard_window<STATUS_WIN,
+ tui_locator_window>);
}
/* See tui-layout.h. */
--- /dev/null
+/* Copyright (C) 2021 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "tui/tui.h"
+#include "tui/tui-stack.h"
+#include "tui/tui-data.h"
+#include "tui/tui-location.h"
+#include "symtab.h"
+#include "source.h"
+
+/* See tui/tui-location.h. */
+
+tui_location_tracker tui_location;
+
+/* See tui/tui-location.h. */
+
+bool
+tui_location_tracker::set_location (struct gdbarch *gdbarch,
+ const struct symtab_and_line &sal,
+ const char *procname)
+{
+ gdb_assert (procname != nullptr);
+
+ bool location_changed_p = set_fullname (sal.symtab);
+ location_changed_p |= procname != m_proc_name;
+ location_changed_p |= sal.line != m_line_no;
+ location_changed_p |= sal.pc != m_addr;
+ location_changed_p |= gdbarch != m_gdbarch;
+
+ m_proc_name = procname;
+ m_line_no = sal.line;
+ m_addr = sal.pc;
+ m_gdbarch = gdbarch;
+
+ if (location_changed_p)
+ tui_show_locator_content ();
+
+ return location_changed_p;
+}
+
+/* See tui/tui-location.h. */
+
+bool
+tui_location_tracker::set_location (struct symtab *symtab)
+{
+ bool location_changed_p = set_fullname (symtab);
+
+ if (location_changed_p)
+ tui_show_locator_content ();
+
+ return location_changed_p;
+}
+
+/* See tui/tui-location.h. */
+
+bool
+tui_location_tracker::set_fullname (struct symtab *symtab)
+{
+ const char *fullname = (symtab == nullptr
+ ? "??"
+ : symtab_to_fullname (symtab));
+ bool location_changed_p = fullname != m_full_name;
+ m_full_name = std::string (fullname);
+
+ return location_changed_p;
+}
--- /dev/null
+/* Copyright (C) 2021 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef TUI_TUI_LOCATION_H
+#define TUI_TUI_LOCATION_H
+
+#include "tui/tui.h"
+#include "tui/tui.h"
+#include "gdb_curses.h" /* For WINDOW. */
+#include "observable.h"
+
+/* Class used to track the current location that the TUI is displaying. An
+ instance of this class will be created; as events occur within GDB the
+ location information within this instance will be updated. As windows
+ like the status window, source window, or disassembler window need to
+ update themselves, they will ask this instance which location they
+ should be displaying. */
+
+struct tui_location_tracker
+{
+ /* Update the current location with the provided arguments. Returns true
+ if any of the locator's fields were actually changed, and false
+ otherwise. */
+ bool set_location (struct gdbarch *gdbarch,
+ const struct symtab_and_line &sal,
+ const char *procname);
+
+ /* Update the current location with the with the provided argument.
+ Return true if any of the fields actually changed, otherwise false. */
+ bool set_location (struct symtab *symtab);
+
+ /* Return the address of the current location. */
+ CORE_ADDR addr () const
+ { return m_addr; }
+
+ /* Return the architecture for the current location. */
+ struct gdbarch *gdbarch () const
+ { return m_gdbarch; }
+
+ /* Return the full name of the file containing the current location. */
+ const std::string &full_name () const
+ { return m_full_name; }
+
+ /* Return the name of the function containing the current location. */
+ const std::string &proc_name () const
+ { return m_proc_name; }
+
+ /* Return the line number for the current location. */
+ int line_no () const
+ { return m_line_no; }
+
+private:
+
+ /* Update M_FULL_NAME from SYMTAB. Return true if M_FULL_NAME actually
+ changed, otherwise, return false. */
+ bool set_fullname (struct symtab *symtab);
+
+ /* The full name for the file containing the current location. */
+ std::string m_full_name;
+
+ /* The name of the function we're currently within. */
+ std::string m_proc_name;
+
+ /* The line number for the current location. */
+ int m_line_no = 0;
+
+ /* The address of the current location. */
+ CORE_ADDR m_addr = 0;
+
+ /* Architecture associated with code at this location. */
+ struct gdbarch *m_gdbarch = nullptr;
+};
+
+/* The single global instance of the location tracking class. Tracks the
+ current location that the TUI windows are displaying. */
+
+extern tui_location_tracker tui_location;
+
+#endif /* TUI_TUI_LOCATION_H */
#include "tui/tui-win.h"
#include "tui/tui-winsource.h"
#include "tui/tui-source.h"
+#include "tui/tui-location.h"
#include "gdb_curses.h"
/* Function to display source in the source window. */
return false;
int cur_line_no, cur_line;
- struct tui_locator_window *locator
- = tui_locator_win_info_ptr ();
const char *s_filename = symtab_to_filename_for_display (s);
title = s_filename;
element->line_or_addr.loa = LOA_LINE;
element->line_or_addr.u.line_no = cur_line_no;
element->is_exec_point
- = (filename_cmp (locator->full_name.c_str (),
+ = (filename_cmp (tui_location.full_name ().c_str (),
symtab_to_fullname (s)) == 0
- && cur_line_no == locator->line_no);
+ && cur_line_no == tui_location.line_no ());
m_content[cur_line].line = std::move (text);
tui_source_window::showing_source_p (const char *fullname) const
{
return (!m_content.empty ()
- && (filename_cmp (tui_locator_win_info_ptr ()->full_name.c_str (),
+ && (filename_cmp (tui_location.full_name ().c_str (),
fullname) == 0));
}
#include "tui/tui-source.h"
#include "tui/tui-winsource.h"
#include "tui/tui-file.h"
+#include "tui/tui-location.h"
#include "gdb_curses.h"
#define MAX_TARGET_WIDTH 10
#define MAX_PID_WIDTH 19
-static struct tui_locator_window _locator;
-
\f
-/* Accessor for the locator win info. Answers a pointer to the static
- locator win info struct. */
-struct tui_locator_window *
-tui_locator_win_info_ptr (void)
-{
- return &_locator;
-}
-
std::string
tui_locator_window::make_status_line () const
{
status_size = width;
/* Translate line number and obtain its size. */
+ int line_no = tui_location.line_no ();
if (line_no > 0)
xsnprintf (line_buf, sizeof (line_buf), "%d", line_no);
else
line_width = MIN_LINE_WIDTH;
/* Translate PC address. */
+ struct gdbarch *gdbarch = tui_location.gdbarch ();
+ CORE_ADDR addr = tui_location.addr ();
std::string pc_out (gdbarch
? paddress (gdbarch, addr)
: "??");
/* Procedure/class name. */
if (proc_width > 0)
{
+ const std::string &proc_name = tui_location.proc_name ();
if (proc_name.size () > proc_width)
string.printf ("%s%*.*s* ", PROC_PREFIX,
1 - proc_width, proc_width - 1, proc_name.c_str ());
void
tui_locator_window::rerender ()
{
- if (handle != NULL)
- {
- std::string string = make_status_line ();
- scrollok (handle.get (), FALSE);
- wmove (handle.get (), 0, 0);
- /* We ignore the return value from wstandout and wstandend, casting
- them to void in order to avoid a compiler warning. The warning
- itself was introduced by a patch to ncurses 5.7 dated 2009-08-29,
- changing these macro to expand to code that causes the compiler
- to generate an unused-value warning. */
- (void) wstandout (handle.get ());
- waddstr (handle.get (), string.c_str ());
- wclrtoeol (handle.get ());
- (void) wstandend (handle.get ());
- refresh_window ();
- wmove (handle.get (), 0, 0);
- }
-}
-
-/* See tui-stack.h. */
-
-void
-tui_locator_window::set_locator_fullname (const char *fullname)
-{
- full_name = fullname;
- rerender ();
-}
-
-/* See tui-stack.h. */
-
-bool
-tui_locator_window::set_locator_info (struct gdbarch *gdbarch_in,
- const struct symtab_and_line &sal,
- const char *procname)
-{
- bool locator_changed_p = false;
-
- gdb_assert (procname != NULL);
-
- const char *fullname = (sal.symtab == nullptr
- ? "??"
- : symtab_to_fullname (sal.symtab));
-
- locator_changed_p |= proc_name != procname;
- locator_changed_p |= sal.line != line_no;
- locator_changed_p |= sal.pc != addr;
- locator_changed_p |= gdbarch_in != gdbarch;
- locator_changed_p |= full_name != fullname;
-
- proc_name = procname;
- line_no = sal.line;
- addr = sal.pc;
- gdbarch = gdbarch_in;
- set_locator_fullname (fullname);
-
- return locator_changed_p;
-}
-
-/* Update only the full_name portion of the locator. */
-void
-tui_update_locator_fullname (struct symtab *symtab)
-{
- struct tui_locator_window *locator = tui_locator_win_info_ptr ();
-
- const char *fullname;
- if (symtab != nullptr)
- fullname = symtab_to_fullname (symtab);
- else
- fullname = "??";
- locator->set_locator_fullname (fullname);
+ gdb_assert (handle != NULL);
+
+ std::string string = make_status_line ();
+ scrollok (handle.get (), FALSE);
+ wmove (handle.get (), 0, 0);
+ /* We ignore the return value from wstandout and wstandend, casting them
+ to void in order to avoid a compiler warning. The warning itself was
+ introduced by a patch to ncurses 5.7 dated 2009-08-29, changing these
+ macro to expand to code that causes the compiler to generate an
+ unused-value warning. */
+ (void) wstandout (handle.get ());
+ waddstr (handle.get (), string.c_str ());
+ wclrtoeol (handle.get ());
+ (void) wstandend (handle.get ());
+ refresh_window ();
+ wmove (handle.get (), 0, 0);
}
/* Function to print the frame information for the TUI. The windows are
tui_show_frame_info (struct frame_info *fi)
{
bool locator_changed_p;
- struct tui_locator_window *locator = tui_locator_win_info_ptr ();
- if (fi)
+ if (fi != nullptr)
{
symtab_and_line sal = find_frame_sal (fi);
else
func_name = _("<unavailable>");
- locator_changed_p = locator->set_locator_info (get_frame_arch (fi),
- sal, func_name);
+ locator_changed_p
+ = tui_location.set_location (get_frame_arch (fi), sal, func_name);
/* If the locator information has not changed, then frame information has
not changed. If frame information has not changed, then the windows'
{
symtab_and_line sal {};
- locator_changed_p = locator->set_locator_info (NULL, sal, "");
+ locator_changed_p = tui_location.set_location (NULL, sal, "");
if (!locator_changed_p)
return false;
void
tui_show_locator_content ()
{
- struct tui_locator_window *locator = tui_locator_win_info_ptr ();
- locator->rerender ();
+ if (tui_is_window_visible (STATUS_WIN))
+ TUI_STATUS_WIN->rerender ();
}
/* Command to update the display with the current execution point. */
void rerender () override;
- /* Update the locator, with the provided arguments.
-
- Returns true if any of the locator's fields were actually
- changed, and false otherwise. */
- bool set_locator_info (struct gdbarch *gdbarch,
- const struct symtab_and_line &sal,
- const char *procname);
-
- /* Set the full_name portion of the locator. */
- void set_locator_fullname (const char *fullname);
-
- std::string full_name;
- std::string proc_name;
- int line_no = 0;
- CORE_ADDR addr = 0;
- /* Architecture associated with code at this location. */
- struct gdbarch *gdbarch = nullptr;
-
protected:
void do_scroll_vertical (int n) override
std::string make_status_line () const;
};
-extern void tui_update_locator_fullname (struct symtab *symtab);
extern void tui_show_locator_content (void);
extern bool tui_show_frame_info (struct frame_info *);
void
tui_refresh_all ()
{
- struct tui_locator_window *locator = tui_locator_win_info_ptr ();
-
for (tui_win_info *win_info : all_tui_windows ())
{
if (win_info->is_visible ())
win_info->refresh_window ();
}
- if (locator->is_visible ())
- locator->refresh_window ();
}
#include "tui/tui-winsource.h"
#include "tui/tui-source.h"
#include "tui/tui-disasm.h"
+#include "tui/tui-location.h"
#include "gdb_curses.h"
/* Function to display the "main" routine. */
tui_update_source_windows_with_addr (gdbarch, addr);
s = find_pc_line_symtab (addr);
- tui_update_locator_fullname (s);
+ tui_location.set_location (s);
}
}
}
DISASSEM_WIN,
DATA_WIN,
CMD_WIN,
+ STATUS_WIN,
/* This must ALWAYS be AFTER the major windows last. */
MAX_MAJOR_WINDOWS,
};