gdb/tui: remove special handling of locator/status window

The locator window, or status window as it is sometimes called is
handled differently to all the other windows.

The reason for this is that the class representing this
window (tui_locator_window) does two jobs, first this class represents
a window just like any other that has space on the screen and fills
the space with content.  The second job is that this class serves as a
storage area to hold information about the current location that the
TUI windows represent, so the class has members like 'addr' and
'line_no', for example which are used within this class, and others
when they want to know which line/address the TUI windows should be
showing to the user.

Because of this dual purpose we must always have an instance of the
tui_locator_window so that there is somewhere to store this location
information.

The result of this is that the locator window must never be deleted
like other windows, which results in some special case code.

In this patch I propose splitting the two roles of the
tui_locator_window class.  The tui_locator_window class will retain
just its window drawing parts, and will be treated just like any other
window.  This should allow all special case code for this window to be
deleted.

The other role, that of tracking the current tui location will be
moved into a new class (tui_location_tracker), of which there will be
a single global instance.  All of the places where we previously use
the locator window to get location information will now be updated to
get this from the tui_location_tracker.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* 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.
This commit is contained in:
Andrew Burgess 2021-01-25 18:43:19 +00:00
parent cdeba395cf
commit f237f998d1
13 changed files with 269 additions and 137 deletions

View File

@ -1,3 +1,54 @@
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...

View File

@ -310,6 +310,7 @@ SUBDIR_TUI_SRCS = \
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 \
@ -1541,6 +1542,7 @@ HFILES_NO_SRCDIR = \
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 \

View File

@ -180,6 +180,7 @@ extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
#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. */
@ -197,7 +198,6 @@ extern int tui_term_height (void);
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);

View File

@ -40,6 +40,7 @@
#include "progspace.h"
#include "objfiles.h"
#include "cli/cli-style.h"
#include "tui/tui-location.h"
#include "gdb_curses.h"
@ -320,7 +321,6 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
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;
@ -331,7 +331,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
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;
@ -384,13 +384,10 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
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 ())
{
@ -411,8 +408,8 @@ tui_get_begin_asm_address (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
}
else /* The target is executing. */
{
gdbarch = locator->gdbarch;
addr = locator->addr;
gdbarch = tui_location.gdbarch ();
addr = tui_location.addr ();
}
*gdbarch_p = gdbarch;

View File

@ -98,15 +98,12 @@ tui_apply_current_layout ()
/* 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;
}
}
@ -331,15 +328,6 @@ make_standard_window (const char *)
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.
@ -386,7 +374,9 @@ initialize_known_windows ()
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. */

81
gdb/tui/tui-location.c Normal file
View File

@ -0,0 +1,81 @@
/* 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;
}

93
gdb/tui/tui-location.h Normal file
View File

@ -0,0 +1,93 @@
/* 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 */

View File

@ -37,6 +37,7 @@
#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. */
@ -62,8 +63,6 @@ tui_source_window::set_contents (struct gdbarch *arch,
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;
@ -104,9 +103,9 @@ tui_source_window::set_contents (struct gdbarch *arch,
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);
@ -124,7 +123,7 @@ bool
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));
}

View File

@ -36,6 +36,7 @@
#include "tui/tui-source.h"
#include "tui/tui-winsource.h"
#include "tui/tui-file.h"
#include "tui/tui-location.h"
#include "gdb_curses.h"
@ -54,18 +55,8 @@
#define MAX_TARGET_WIDTH 10
#define MAX_PID_WIDTH 19
static struct tui_locator_window _locator;
/* 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
{
@ -97,6 +88,7 @@ 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
@ -106,6 +98,8 @@ tui_locator_window::make_status_line () const
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)
: "??");
@ -169,6 +163,7 @@ tui_locator_window::make_status_line () const
/* 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 ());
@ -229,76 +224,22 @@ tui_get_function_from_frame (struct frame_info *fi)
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);
}
}
gdb_assert (handle != NULL);
/* 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);
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
@ -311,9 +252,8 @@ bool
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);
@ -325,8 +265,8 @@ tui_show_frame_info (struct frame_info *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'
@ -344,7 +284,7 @@ tui_show_frame_info (struct frame_info *fi)
{
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;
@ -359,8 +299,8 @@ tui_show_frame_info (struct frame_info *fi)
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. */

View File

@ -59,24 +59,6 @@ struct tui_locator_window : public tui_win_info
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
@ -96,7 +78,6 @@ private:
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 *);

View File

@ -200,13 +200,9 @@ tui_win_info::make_visible (bool visible)
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 ();
}

View File

@ -39,6 +39,7 @@
#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. */
@ -58,7 +59,7 @@ tui_display_main ()
tui_update_source_windows_with_addr (gdbarch, addr);
s = find_pc_line_symtab (addr);
tui_update_locator_fullname (s);
tui_location.set_location (s);
}
}
}

View File

@ -38,6 +38,7 @@ enum tui_win_type
DISASSEM_WIN,
DATA_WIN,
CMD_WIN,
STATUS_WIN,
/* This must ALWAYS be AFTER the major windows last. */
MAX_MAJOR_WINDOWS,
};