public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/20] Final round of TUI refactorings
@ 2019-09-10 19:09 Tom Tromey
  2019-09-10 19:09 ` [PATCH 11/20] Set TUI locator height to 1 Tom Tromey
                   ` (20 more replies)
  0 siblings, 21 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches

This is the final set of TUI refactoring patches that I've written.
Only the final patch should change the behavior in any way.

I went back and looked, and the TUI started at 10634 LOC (as counted
by wc) before I started.  Now it is 8825 LOC -- without any loss of
functionality.  I'm pretty happy about that.  I think the code is also
cleaner and easier to understand now, too.

After this I still plan to do a bit of TUI work -- I just haven't
written anything more yet.  In particular I want to fix the resize
testing problem, and fix disassembly styling, at the very least.

Tested on x86-64 Fedora 28.

Let me know what you think.

Tom


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 03/20] Move "fullname" to tui_source_window
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (10 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 04/20] Change tui_make_status_line to return std::string Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 18/20] Remove separator comments from TUI Tom Tromey
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The "fullname" field in tui_source_window_base is only used by one
subclass.  This patch moves the field to that subclass, and changes it
to be a unique_xmalloc_ptr.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<~tui_source_window_base>: Don't declare.
	<fullname>: Remove.
	* tui/tui-winsource.c (~tui_source_window_base): Remove.
	* tui/tui-source.h (struct tui_source_window) <fullname>: New
	member.
	* tui/tui-source.c (tui_source_window::set_contents): Update.
	(tui_source_window::location_matches_p)
	(tui_source_window::maybe_update): Update.
---
 gdb/ChangeLog           | 12 ++++++++++++
 gdb/tui/tui-source.c    |  7 +++----
 gdb/tui/tui-source.h    |  3 +++
 gdb/tui/tui-winsource.c |  5 -----
 gdb/tui/tui-winsource.h |  5 +----
 5 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index c379173018d..f70e053bdb5 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -155,8 +155,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
 
 	  title = s_filename;
 
-	  xfree (fullname);
-	  fullname = xstrdup (symtab_to_fullname (s));
+	  fullname = make_unique_xstrdup (symtab_to_fullname (s));
 
 	  cur_line = 0;
 	  gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
@@ -276,7 +275,7 @@ tui_source_window::location_matches_p (struct bp_location *loc, int line_no)
   return (content[line_no].line_or_addr.loa == LOA_LINE
 	  && content[line_no].line_or_addr.u.line_no == loc->line_number
 	  && loc->symtab != NULL
-	  && filename_cmp (fullname,
+	  && filename_cmp (fullname.get (),
 			   symtab_to_fullname (loc->symtab)) == 0);
 }
 
@@ -308,7 +307,7 @@ tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal,
     start_line = 1;
 
   bool source_already_displayed = (sal.symtab != 0
-				   && showing_source_p (fullname));
+				   && showing_source_p (fullname.get ()));
 
   struct tui_line_or_address l;
 
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index a7002123c97..30728e4214e 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -76,6 +76,9 @@ private:
      in the current source window.  */
   bool line_is_displayed (int line) const;
 
+  /* It is the resolved form as returned by symtab_to_fullname.  */
+  gdb::unique_xmalloc_ptr<char> fullname;
+
   /* A token used to register and unregister an observer.  */
   gdb::observers::token m_observable;
 };
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index d5281193c0e..8b507ed9126 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -261,11 +261,6 @@ tui_source_window_base::tui_source_window_base (enum tui_win_type type)
 }
 
 
-tui_source_window_base::~tui_source_window_base ()
-{
-  xfree (fullname);
-}  
-
 /* See tui-data.h.  */
 
 void
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 64f0739e536..eca0bde4bb8 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -78,7 +78,7 @@ struct tui_source_window_base : public tui_win_info
 {
 protected:
   explicit tui_source_window_base (enum tui_win_type type);
-  ~tui_source_window_base () override;
+
   DISABLE_COPY_AND_ASSIGN (tui_source_window_base);
 
   void do_scroll_horizontal (int num_to_scroll) override;
@@ -137,9 +137,6 @@ public:
   int horizontal_offset = 0;
   struct tui_line_or_address start_line_or_addr;
 
-  /* It is the resolved form as returned by symtab_to_fullname.  */
-  char *fullname = nullptr;
-
   /* Architecture associated with code at this location.  */
   struct gdbarch *gdbarch = nullptr;
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 09/20] Use "bool" in tui_data_window::show_register_group
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (18 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 05/20] Change tui_make_status_line to be a method Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-20 19:29 ` [PATCH 00/20] Final round of TUI refactorings Tom Tromey
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes tui_data_window::show_register_group to use "bool" rather
than "int".

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (struct tui_data_window) <show_register_group>:
	Change type of "refresh_values_only".
	* tui/tui-regs.c (tui_data_window::show_register_group): Change
	type of "refresh_values_only".
---
 gdb/ChangeLog      | 7 +++++++
 gdb/tui/tui-regs.c | 4 ++--
 gdb/tui/tui-regs.h | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 48e78fc9dbc..0485d04d25a 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -166,12 +166,12 @@ tui_data_window::show_registers (struct reggroup *group)
 
 /* Set the data window to display the registers of the register group
    using the given frame.  Values are refreshed only when
-   refresh_values_only is TRUE.  */
+   refresh_values_only is true.  */
 
 void
 tui_data_window::show_register_group (struct reggroup *group,
 				      struct frame_info *frame, 
-				      int refresh_values_only)
+				      bool refresh_values_only)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
   int nr_regs;
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index abf44c88b68..73572efdf95 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -108,7 +108,7 @@ private:
 
   void show_register_group (struct reggroup *group,
 			    struct frame_info *frame,
-			    int refresh_values_only);
+			    bool refresh_values_only);
 
   /* Answer the number of the last line in the regs display.  If there
      are no registers (-1) is returned.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 02/20] Change tui_source_element::line to be a unique_xmalloc_ptr
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (14 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 06/20] Remove some explicit re-rendering from the TUI Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 07/20] Simplify tui_source_window_base::show_source_content Tom Tromey
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes tui_source_element::line to be a unique_xmalloc_ptr,
removing some manual memory management.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (~tui_source_element): Remove.
	(tui_source_element): Update.
	(struct tui_source_element) <line>: Now a unique_xmalloc_ptr.
	* tui/tui-winsource.c (tui_show_source_line): Update.
	* tui/tui-source.c (tui_source_window::set_contents): Update.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Update.
---
 gdb/ChangeLog           |  9 +++++++++
 gdb/tui/tui-disasm.c    |  5 ++---
 gdb/tui/tui-source.c    |  4 +---
 gdb/tui/tui-winsource.c |  3 +--
 gdb/tui/tui-winsource.h | 10 ++--------
 5 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 1d019ca60c1..2a331327e77 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -231,11 +231,10 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
       strcpy (line + insn_pos, asm_lines[i].insn);
 
       /* Now copy the line taking the offset into account.  */
-      xfree (src->line);
       if (strlen (line) > offset)
-	src->line = xstrndup (&line[offset], line_width);
+	src->line.reset (xstrndup (&line[offset], line_width));
       else
-	src->line = xstrdup ("");
+	src->line.reset (xstrdup (""));
 
       src->line_or_addr.loa = LOA_ADDRESS;
       src->line_or_addr.u.addr = asm_lines[i].addr;
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 906006a4225..c379173018d 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -184,9 +184,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
 				 symtab_to_fullname (s)) == 0
 		   && cur_line_no == locator->line_no);
 
-	      xfree (content[cur_line].line);
-	      content[cur_line].line
-		= xstrdup (text.c_str ());
+	      content[cur_line].line.reset (xstrdup (text.c_str ()));
 
 	      cur_line++;
 	      cur_line_no++;
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 4520a1ac3fe..d5281193c0e 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -222,8 +222,7 @@ tui_show_source_line (struct tui_source_window_base *win_info, int lineno)
     tui_set_reverse_mode (win_info->handle, true);
 
   wmove (win_info->handle, lineno, TUI_EXECINFO_SIZE);
-  tui_puts (line->line,
-	    win_info->handle);
+  tui_puts (line->line.get (), win_info->handle);
   if (line->is_exec_point)
     tui_set_reverse_mode (win_info->handle, false);
 
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 445cc7c7357..64f0739e536 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -54,23 +54,17 @@ struct tui_source_element
     line_or_addr.u.line_no = 0;
   }
 
-  ~tui_source_element ()
-  {
-    xfree (line);
-  }
-
   DISABLE_COPY_AND_ASSIGN (tui_source_element);
 
   tui_source_element (tui_source_element &&other)
-    : line (other.line),
+    : line (std::move (other.line)),
       line_or_addr (other.line_or_addr),
       is_exec_point (other.is_exec_point),
       break_mode (other.break_mode)
   {
-    other.line = nullptr;
   }
 
-  char *line = nullptr;
+  gdb::unique_xmalloc_ptr<char> line;
   struct tui_line_or_address line_or_addr;
   bool is_exec_point = false;
   tui_bp_flags break_mode = 0;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 18/20] Remove separator comments from TUI
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (11 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 03/20] Move "fullname" to tui_source_window Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 01/20] Remove tui_clear_source_windows_detail Tom Tromey
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes various separator comments from the TUI.  These aren't
used elsewhere in gdb, and they were incorrect in some cases as well.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.c: Remove separator comments.
	* tui/tui-layout.c: Remove separator comments.
	* tui/tui-win.c: Remove separator comments.
	* tui/tui-wingeneral.c: Remove separator comments.
---
 gdb/ChangeLog            |  7 +++++++
 gdb/tui/tui-data.c       | 20 --------------------
 gdb/tui/tui-layout.c     | 11 -----------
 gdb/tui/tui-win.c        | 15 ---------------
 gdb/tui/tui-wingeneral.c |  9 ---------
 5 files changed, 7 insertions(+), 55 deletions(-)

diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index c14b1711f60..748d8978218 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -27,34 +27,19 @@
 #include "tui/tui-winsource.h"
 #include "gdb_curses.h"
 
-/****************************
-** GLOBAL DECLARATIONS
-****************************/
 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
 
-/***************************
-** Private data
-****************************/
 static int term_height, term_width;
 static struct tui_win_info *win_with_focus = NULL;
 
 static bool win_resized = false;
 
-
-/*********************************
-** PUBLIC FUNCTIONS
-**********************************/
-
 int
 tui_win_is_auxiliary (enum tui_win_type win_type)
 {
   return (win_type > MAX_MAJOR_WINDOWS);
 }
 
-/******************************************
-** ACCESSORS & MUTATORS FOR PRIVATE DATA
-******************************************/
-
 /* Answer a whether the terminal window has been resized or not.  */
 bool
 tui_win_resized ()
@@ -119,11 +104,6 @@ tui_set_term_width_to (int w)
 }
 
 
-/*****************************
-** OTHER PUBLIC FUNCTIONS
-*****************************/
-
-
 /* Answer the next window in the list, cycling back to the top if
    necessary.  */
 struct tui_win_info *
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 03115a7baa1..0f3e8d945e8 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -40,9 +40,6 @@
 #include "tui/tui-source.h"
 #include "gdb_curses.h"
 
-/*******************************
-** Static Local Decls
-********************************/
 static void show_layout (enum tui_layout_type);
 static void show_source_or_disasm_and_command (enum tui_layout_type);
 static void show_source_command (void);
@@ -64,9 +61,6 @@ tui_current_layout (void)
   return current_layout;
 }
 
-/***************************************
-** DEFINITIONS
-***************************************/
 
 /* Show the screen layout defined.  */
 static void
@@ -338,11 +332,6 @@ Layout names are:\n\
 }
 
 
-/*************************
-** STATIC LOCAL FUNCTIONS
-**************************/
-
-
 /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or
    REGS. */
 static void
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 8963da2b485..aecb7791f0a 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -53,9 +53,6 @@
 
 #include <signal.h>
 
-/*******************************
-** Static Local Decls
-********************************/
 static enum tui_status tui_adjust_win_heights (struct tui_win_info *, 
 					       int);
 static int new_height_ok (struct tui_win_info *, int);
@@ -71,16 +68,9 @@ static void parse_scrolling_args (const char *,
 				  int *);
 
 
-/***************************************
-** DEFINITIONS
-***************************************/
 #define WIN_HEIGHT_USAGE    "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
 #define FOCUS_USAGE         "Usage: focus [WINDOW-NAME | next | prev]\n"
 
-/***************************************
-** PUBLIC FUNCTIONS
-***************************************/
-
 #ifndef ACS_LRCORNER
 #  define ACS_LRCORNER '+'
 #endif
@@ -720,11 +710,6 @@ tui_initialize_win (void)
 }
 
 
-/*************************
-** STATIC LOCAL FUNCTIONS
-**************************/
-
-
 static void
 tui_scroll_forward_command (const char *arg, int from_tty)
 {
diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 235c17c5fa2..713059d6632 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -28,10 +28,6 @@
 
 #include "gdb_curses.h"
 
-/***********************
-** PUBLIC FUNCTIONS
-***********************/
-
 /* See tui-data.h.  */
 
 void
@@ -191,8 +187,3 @@ tui_refresh_all ()
   if (locator->is_visible ())
     locator->refresh_window ();
 }
-
-
-/*********************************
-** Local Static Functions
-*********************************/
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 06/20] Remove some explicit re-rendering from the TUI
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (13 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 01/20] Remove tui_clear_source_windows_detail Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 02/20] Change tui_source_element::line to be a unique_xmalloc_ptr Tom Tromey
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

A couple of spots in tui-layout.c still call the show_source_content
method.  However, now that re-rendering is done by the resize method,
these calls are no longer needed.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-layout.c (show_source_disasm_command)
	(show_source_or_disasm_and_command): Don't call
	show_source_content.
---
 gdb/ChangeLog        | 6 ++++++
 gdb/tui/tui-layout.c | 4 ----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index d331a2f25c7..33d3dd6cb87 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -505,7 +505,6 @@ show_source_disasm_command (void)
   struct tui_locator_window *locator = tui_locator_win_info_ptr ();
   gdb_assert (locator != nullptr);
 
-  TUI_SRC_WIN->show_source_content ();
   if (TUI_DISASM_WIN == NULL)
     tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
   TUI_DISASM_WIN->resize (asm_height,
@@ -516,7 +515,6 @@ show_source_disasm_command (void)
 		   tui_term_width (),
 		   0,
 		   (src_height + asm_height) - 1);
-  TUI_DISASM_WIN->show_source_content ();
 
   if (TUI_CMD_WIN == NULL)
     tui_win_list[CMD_WIN] = new tui_cmd_window ();
@@ -646,8 +644,6 @@ show_source_or_disasm_and_command (enum tui_layout_type layout_type)
 		    0,
 		    0);
 
-  win_info->show_source_content ();
-
   if (TUI_CMD_WIN == NULL)
     tui_win_list[CMD_WIN] = new tui_cmd_window ();
   TUI_CMD_WIN->resize (cmd_height,
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 12/20] Don't call refresh in tui_resize_all
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (5 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 08/20] Simplify TUI disassembly Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 19/20] Use make_unique_xstrdup in TUI Tom Tromey
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

There's no reason to call refresh in tui_resize_all.  This call
flushes the curses window contents to the terminal -- but, because
we're about the resize all the windows, we're going to be sending more
data to the terminal momentarily.  This patch removes the call.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_resize_all): Don't call refresh.
---
 gdb/ChangeLog     | 4 ++++
 gdb/tui/tui-win.c | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 77044738ef6..8963da2b485 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -561,7 +561,6 @@ tui_resize_all (void)
          AIX 5.3 does not define clear.  */
       erase ();
       clearok (curscr, TRUE);
-      refresh ();
       switch (cur_layout)
        {
 	case SRC_COMMAND:
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 08/20] Simplify TUI disassembly
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (4 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 10/20] Change "win_resized" to bool Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 12/20] Don't call refresh in tui_resize_all Tom Tromey
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This simplifies TUI disassembly somewhat, by removing manual memory
management.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-disasm.c (struct tui_asm_line) <addr_string, insn>: Now
	std::string.
	(tui_disassemble): Add "pos" parameter.
	(tui_disasm_window::set_contents): Simplify.
---
 gdb/ChangeLog        |  7 +++++
 gdb/tui/tui-disasm.c | 71 ++++++++++++++++----------------------------
 2 files changed, 33 insertions(+), 45 deletions(-)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 2a331327e77..53ea061afb6 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -44,34 +44,32 @@
 struct tui_asm_line 
 {
   CORE_ADDR addr;
-  char *addr_string;
-  char *insn;
+  std::string addr_string;
+  std::string insn;
 };
 
 /* Function to set the disassembly window's content.
    Disassemble count lines starting at pc.
    Return address of the count'th instruction after pc.  */
 static CORE_ADDR
-tui_disassemble (struct gdbarch *gdbarch, struct tui_asm_line *asm_lines,
-		 CORE_ADDR pc, int count)
+tui_disassemble (struct gdbarch *gdbarch,
+		 std::vector<tui_asm_line> &asm_lines,
+		 CORE_ADDR pc, int pos, int count)
 {
   string_file gdb_dis_out;
 
   /* Now construct each line.  */
-  for (; count > 0; count--, asm_lines++)
+  for (int i = 0; i < count; ++i)
     {
-      xfree (asm_lines->addr_string);
-      xfree (asm_lines->insn);
-      
       print_address (gdbarch, pc, &gdb_dis_out);
-      asm_lines->addr = pc;
-      asm_lines->addr_string = xstrdup (gdb_dis_out.c_str ());
+      asm_lines[pos + i].addr = pc;
+      asm_lines[pos + i].addr_string = std::move (gdb_dis_out.string ());
 
       gdb_dis_out.clear ();
 
       pc = pc + gdb_print_insn (gdbarch, pc, &gdb_dis_out, NULL);
 
-      asm_lines->insn = xstrdup (gdb_dis_out.c_str ());
+      asm_lines[pos + i].insn = std::move (gdb_dis_out.string ());
 
       /* Reset the buffer to empty.  */
       gdb_dis_out.clear ();
@@ -87,20 +85,17 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
 {
   CORE_ADDR new_low;
   int max_lines;
-  int i;
-  struct tui_asm_line *asm_lines;
 
   max_lines = (from > 0) ? from : - from;
   if (max_lines <= 1)
-     return pc;
+    return pc;
 
-  asm_lines = XALLOCAVEC (struct tui_asm_line, max_lines);
-  memset (asm_lines, 0, sizeof (struct tui_asm_line) * max_lines);
+  std::vector<tui_asm_line> asm_lines (max_lines);
 
   new_low = pc;
   if (from > 0)
     {
-      tui_disassemble (gdbarch, asm_lines, pc, max_lines);
+      tui_disassemble (gdbarch, asm_lines, pc, 0, max_lines);
       new_low = asm_lines[max_lines - 1].addr;
     }
   else
@@ -122,7 +117,7 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
          else
             new_low += 1 * max_lines;
 
-         tui_disassemble (gdbarch, asm_lines, new_low, max_lines);
+         tui_disassemble (gdbarch, asm_lines, new_low, 0, max_lines);
          last_addr = asm_lines[pos].addr;
       } while (last_addr > pc && msymbol.minsym);
 
@@ -139,8 +134,8 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
             if (pos >= max_lines)
               pos = 0;
 
-            next_addr = tui_disassemble (gdbarch, &asm_lines[pos],
-					 last_addr, 1);
+            next_addr = tui_disassemble (gdbarch, asm_lines,
+					 last_addr, pos, 1);
 
             /* If there are some problems while disassembling exit.  */
             if (next_addr <= last_addr)
@@ -152,11 +147,6 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
          pos = 0;
       new_low = asm_lines[pos].addr;
     }
-  for (i = 0; i < max_lines; i++)
-    {
-      xfree (asm_lines[i].addr_string);
-      xfree (asm_lines[i].insn);
-    }
   return new_low;
 }
 
@@ -172,10 +162,8 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
   CORE_ADDR cur_pc;
   struct tui_locator_window *locator = tui_locator_win_info_ptr ();
   int tab_len = tui_tab_width;
-  struct tui_asm_line *asm_lines;
   int insn_pos;
   int addr_size, insn_size;
-  char *line;
   
   gdb_assert (line_or_addr.loa == LOA_ADDRESS);
   CORE_ADDR pc = line_or_addr.u.addr;
@@ -192,22 +180,21 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
   line_width = width - TUI_EXECINFO_SIZE - 2;
 
   /* Get temporary table that will hold all strings (addr & insn).  */
-  asm_lines = XALLOCAVEC (struct tui_asm_line, max_lines);
-  memset (asm_lines, 0, sizeof (struct tui_asm_line) * max_lines);
+  std::vector<tui_asm_line> asm_lines (max_lines);
 
-  tui_disassemble (gdbarch, asm_lines, pc, max_lines);
+  tui_disassemble (gdbarch, asm_lines, pc, 0, max_lines);
 
   /* Determine maximum address- and instruction lengths.  */
   addr_size = 0;
   insn_size = 0;
   for (i = 0; i < max_lines; i++)
     {
-      size_t len = strlen (asm_lines[i].addr_string);
+      size_t len = asm_lines[i].addr_string.size ();
 
       if (len > addr_size)
         addr_size = len;
 
-      len = strlen (asm_lines[i].insn);
+      len = asm_lines[i].insn.size ();
       if (len > insn_size)
 	insn_size = len;
     }
@@ -215,23 +202,20 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
   /* Align instructions to the same column.  */
   insn_pos = (1 + (addr_size / tab_len)) * tab_len;
 
-  /* Allocate memory to create each line.  */
-  line = (char*) alloca (insn_pos + insn_size + 1);
-
   /* Now construct each line.  */
   content.resize (max_lines);
   for (i = 0; i < max_lines; i++)
     {
-      int cur_len;
-
       tui_source_element *src = &content[i];
-      strcpy (line, asm_lines[i].addr_string);
-      cur_len = strlen (line);
-      memset (line + cur_len, ' ', insn_pos - cur_len);
-      strcpy (line + insn_pos, asm_lines[i].insn);
+
+      std::string line
+	= (asm_lines[i].addr_string
+	   + n_spaces (insn_pos
+		       - asm_lines[i].addr_string.size ())
+	   + asm_lines[i].insn);
 
       /* Now copy the line taking the offset into account.  */
-      if (strlen (line) > offset)
+      if (line.size() > offset)
 	src->line.reset (xstrndup (&line[offset], line_width));
       else
 	src->line.reset (xstrdup (""));
@@ -239,9 +223,6 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
       src->line_or_addr.loa = LOA_ADDRESS;
       src->line_or_addr.u.addr = asm_lines[i].addr;
       src->is_exec_point = asm_lines[i].addr == cur_pc;
-
-      xfree (asm_lines[i].addr_string);
-      xfree (asm_lines[i].insn);
     }
   return TUI_SUCCESS;
 }
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 04/20] Change tui_make_status_line to return std::string
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (9 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 17/20] Remove strcat_to_buf Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 03/20] Move "fullname" to tui_source_window Tom Tromey
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes tui_make_status_line to return std::string.  This cleans
it up a bit, and removes some explicit memory management.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.c (tui_make_status_line): Return std::string.
	(tui_locator_window::rerender): Update.
---
 gdb/ChangeLog       |  5 ++++
 gdb/tui/tui-stack.c | 69 ++++++++++++++++-----------------------------
 2 files changed, 30 insertions(+), 44 deletions(-)

diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 36208d0cac0..a2e4a161bb7 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -66,14 +66,12 @@ tui_locator_win_info_ptr (void)
 /* Create the status line to display as much information as we can on
    this single line: target name, process number, current function,
    current line, current PC, SingleKey mode.  */
-static char *
+static std::string
 tui_make_status_line (struct tui_locator_window *loc)
 {
-  char *string;
   char line_buf[50], *pname;
-  char *buf;
   int status_size;
-  int i, proc_width;
+  int proc_width;
   const char *pid_name;
   int target_width;
   int pid_width;
@@ -97,8 +95,6 @@ tui_make_status_line (struct tui_locator_window *loc)
     pid_width = MAX_PID_WIDTH;
 
   status_size = tui_term_width ();
-  string = (char *) xmalloc (status_size + 1);
-  buf = (char*) alloca (status_size + 1);
 
   /* Translate line number and obtain its size.  */
   if (loc->line_no > 0)
@@ -158,61 +154,47 @@ tui_make_status_line (struct tui_locator_window *loc)
   pname = loc->proc_name;
 
   /* Now create the locator line from the string version of the
-     elements.  We could use sprintf() here but that wouldn't ensure
-     that we don't overrun the size of the allocated buffer.
-     strcat_to_buf() will.  */
-  *string = (char) 0;
+     elements.  */
+  string_file string;
 
   if (target_width > 0)
-    {
-      sprintf (buf, "%*.*s ",
-               -target_width, target_width, target_shortname);
-      strcat_to_buf (string, status_size, buf);
-    }
+    string.printf ("%*.*s ", -target_width, target_width, target_shortname);
   if (pid_width > 0)
-    {
-      sprintf (buf, "%*.*s ",
-               -pid_width, pid_width, pid_name);
-      strcat_to_buf (string, status_size, buf);
-    }
-  
+    string.printf ("%*.*s ", -pid_width, pid_width, pid_name);
+
   /* Show whether we are in SingleKey mode.  */
   if (tui_current_key_mode == TUI_SINGLE_KEY_MODE)
     {
-      strcat_to_buf (string, status_size, SINGLE_KEY);
-      strcat_to_buf (string, status_size, " ");
+      string.puts (SINGLE_KEY);
+      string.puts (" ");
     }
 
   /* Procedure/class name.  */
   if (proc_width > 0)
     {
       if (strlen (pname) > proc_width)
-        sprintf (buf, "%s%*.*s* ", PROC_PREFIX,
-                 1 - proc_width, proc_width - 1, pname);
+        string.printf ("%s%*.*s* ", PROC_PREFIX,
+		       1 - proc_width, proc_width - 1, pname);
       else
-        sprintf (buf, "%s%*.*s ", PROC_PREFIX,
-                 -proc_width, proc_width, pname);
-      strcat_to_buf (string, status_size, buf);
+        string.printf ("%s%*.*s ", PROC_PREFIX,
+		       -proc_width, proc_width, pname);
     }
 
   if (line_width > 0)
-    {
-      sprintf (buf, "%s%*.*s ", LINE_PREFIX,
-               -line_width, line_width, line_buf);
-      strcat_to_buf (string, status_size, buf);
-    }
+    string.printf ("%s%*.*s ", LINE_PREFIX,
+		   -line_width, line_width, line_buf);
   if (pc_width > 0)
     {
-      strcat_to_buf (string, status_size, PC_PREFIX);
-      strcat_to_buf (string, status_size, pc_buf);
+      string.puts (PC_PREFIX);
+      string.puts (pc_buf);
     }
-  
-  
-  for (i = strlen (string); i < status_size; i++)
-    string[i] = ' ';
-  string[status_size] = (char) 0;
 
-  return string;
+  if (string.size () < status_size)
+    string.puts (n_spaces (status_size - string.size ()));
+  else if (string.size () > status_size)
+    string.string ().erase (status_size, string.size ());
+
+  return std::move (string.string ());
 }
 
 /* Get a printable name for the function at the address.  The symbol
@@ -252,7 +234,7 @@ tui_locator_window::rerender ()
 {
   if (handle != NULL)
     {
-      char *string = tui_make_status_line (this);
+      std::string string = tui_make_status_line (this);
       wmove (handle, 0, 0);
       /* We ignore the return value from wstandout and wstandend, casting
 	 them to void in order to avoid a compiler warning.  The warning
@@ -260,12 +242,11 @@ tui_locator_window::rerender ()
 	 changing these macro to expand to code that causes the compiler
 	 to generate an unused-value warning.  */
       (void) wstandout (handle);
-      waddstr (handle, string);
+      waddstr (handle, string.c_str ());
       wclrtoeol (handle);
       (void) wstandend (handle);
       refresh_window ();
       wmove (handle, 0, 0);
-      xfree (string);
     }
 }
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 15/20] Rename private data members of tui_data_window
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
  2019-09-10 19:09 ` [PATCH 11/20] Set TUI locator height to 1 Tom Tromey
  2019-09-10 19:09 ` [PATCH 16/20] Rename a private data member in tui_source_window Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 14/20] Change members of tui_locator_window to std::string Tom Tromey
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

As Pedro suggested, this patch renames the private data members of
tui_data_window to use the "m_" prefix.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.h (struct tui_data_window) <get_current_group>:
	Update.
	<m_regs_content, m_regs_column_count, m_current_group>: Add "m_"
	prefix.
	* tui/tui-regs.c (tui_data_window::last_regs_line_no)
	(tui_data_window::line_from_reg_element_no)
	(tui_data_window::first_reg_element_no_inline)
	(tui_data_window::show_registers)
	(tui_data_window::show_register_group)
	(tui_data_window::display_registers_from)
	(tui_data_window::display_registers_from_line)
	(tui_data_window::first_data_item_displayed)
	(tui_data_window::delete_data_content_windows)
	(tui_data_window::erase_data_content)
	(tui_data_window::do_scroll_vertical)
	(tui_data_window::refresh_window)
	(tui_data_window::check_register_values): Update.
---
 gdb/ChangeLog      | 20 +++++++++++++++
 gdb/tui/tui-regs.c | 64 +++++++++++++++++++++++-----------------------
 gdb/tui/tui-regs.h |  8 +++---
 3 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 0485d04d25a..c4769cbcb43 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -96,8 +96,8 @@ tui_get_register (struct frame_info *frame,
 int
 tui_data_window::last_regs_line_no () const
 {
-  int num_lines = regs_content.size () / regs_column_count;
-  if (regs_content.size () % regs_column_count)
+  int num_lines = m_regs_content.size () / m_regs_column_count;
+  if (m_regs_content.size () % m_regs_column_count)
     num_lines++;
   return num_lines;
 }
@@ -107,14 +107,14 @@ tui_data_window::last_regs_line_no () const
 int
 tui_data_window::line_from_reg_element_no (int element_no) const
 {
-  if (element_no < regs_content.size ())
+  if (element_no < m_regs_content.size ())
     {
       int i, line = (-1);
 
       i = 1;
       while (line == (-1))
 	{
-	  if (element_no < regs_column_count * i)
+	  if (element_no < m_regs_column_count * i)
 	    line = i - 1;
 	  else
 	    i++;
@@ -131,8 +131,8 @@ tui_data_window::line_from_reg_element_no (int element_no) const
 int
 tui_data_window::first_reg_element_no_inline (int line_no) const
 {
-  if (line_no * regs_column_count <= regs_content.size ())
-    return ((line_no + 1) * regs_column_count) - regs_column_count;
+  if (line_no * m_regs_column_count <= m_regs_content.size ())
+    return ((line_no + 1) * m_regs_column_count) - m_regs_column_count;
   else
     return (-1);
 }
@@ -148,17 +148,17 @@ tui_data_window::show_registers (struct reggroup *group)
   if (target_has_registers && target_has_stack && target_has_memory)
     {
       show_register_group (group, get_selected_frame (NULL),
-			   group == current_group);
+			   group == m_current_group);
 
       /* Clear all notation of changed values.  */
-      for (auto &&data_item_win : regs_content)
+      for (auto &&data_item_win : m_regs_content)
 	data_item_win.highlight = false;
-      current_group = group;
+      m_current_group = group;
       rerender ();
     }
   else
     {
-      current_group = 0;
+      m_current_group = 0;
       erase_data_content (_("[ Register Values Unavailable ]"));
     }
 }
@@ -199,7 +199,7 @@ tui_data_window::show_register_group (struct reggroup *group,
       nr_regs++;
     }
 
-  regs_content.resize (nr_regs);
+  m_regs_content.resize (nr_regs);
 
   /* Now set the register names and values.  */
   pos = 0;
@@ -218,7 +218,7 @@ tui_data_window::show_register_group (struct reggroup *group,
       if (name == 0 || *name == '\0')
 	continue;
 
-      data_item_win = &regs_content[pos];
+      data_item_win = &m_regs_content[pos];
       if (data_item_win)
 	{
 	  if (!refresh_values_only)
@@ -241,7 +241,7 @@ tui_data_window::display_registers_from (int start_element_no)
   int j, item_win_width, cur_y;
 
   int max_len = 0;
-  for (auto &&data_item_win : regs_content)
+  for (auto &&data_item_win : m_regs_content)
     {
       const char *p;
       int len;
@@ -257,24 +257,24 @@ tui_data_window::display_registers_from (int start_element_no)
   item_win_width = max_len + 1;
   int i = start_element_no;
 
-  regs_column_count = (width - 2) / item_win_width;
-  if (regs_column_count == 0)
-    regs_column_count = 1;
-  item_win_width = (width - 2) / regs_column_count;
+  m_regs_column_count = (width - 2) / item_win_width;
+  if (m_regs_column_count == 0)
+    m_regs_column_count = 1;
+  item_win_width = (width - 2) / m_regs_column_count;
 
   /* Now create each data "sub" window, and write the display into
      it.  */
   cur_y = 1;
-  while (i < regs_content.size ()
+  while (i < m_regs_content.size ()
 	 && cur_y <= viewport_height)
     {
       for (j = 0;
-	   j < regs_column_count && i < regs_content.size ();
+	   j < m_regs_column_count && i < m_regs_content.size ();
 	   j++)
 	{
 	  /* Create the window if necessary.  */
-	  regs_content[i].resize (1, item_win_width,
-				  (item_win_width * j) + 1, cur_y);
+	  m_regs_content[i].resize (1, item_win_width,
+				    (item_win_width * j) + 1, cur_y);
 	  i++;		/* Next register.  */
 	}
       cur_y++;		/* Next row.  */
@@ -322,14 +322,14 @@ tui_data_window::display_registers_from_line (int line_no)
 	 registers.  */
       if (line_no >= last_regs_line_no ())
 	{
-	  line_no = line_from_reg_element_no (regs_content.size () - 1);
+	  line_no = line_from_reg_element_no (m_regs_content.size () - 1);
 	  if (line_no < 0)
 	    line_no = 0;
 	}
     }
 
   element_no = first_reg_element_no_inline (line_no);
-  if (element_no < regs_content.size ())
+  if (element_no < m_regs_content.size ())
     display_reg_element_at_line (element_no, line_no);
   else
     line_no = (-1);
@@ -343,11 +343,11 @@ tui_data_window::display_registers_from_line (int line_no)
 int
 tui_data_window::first_data_item_displayed ()
 {
-  for (int i = 0; i < regs_content.size (); i++)
+  for (int i = 0; i < m_regs_content.size (); i++)
     {
       struct tui_gen_win_info *data_item_win;
 
-      data_item_win = &regs_content[i];
+      data_item_win = &m_regs_content[i];
       if (data_item_win->is_visible ())
 	return i;
     }
@@ -360,7 +360,7 @@ tui_data_window::first_data_item_displayed ()
 void
 tui_data_window::delete_data_content_windows ()
 {
-  for (auto &&win : regs_content)
+  for (auto &&win : m_regs_content)
     {
       tui_delete_win (win.handle);
       win.handle = NULL;
@@ -392,7 +392,7 @@ tui_data_window::erase_data_content (const char *prompt)
 void
 tui_data_window::rerender ()
 {
-  if (regs_content.empty ())
+  if (m_regs_content.empty ())
     erase_data_content (_("[ Register Values Unavailable ]"));
   else
     {
@@ -411,7 +411,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
   int first_line = (-1);
 
   first_element_no = first_data_item_displayed ();
-  if (first_element_no < regs_content.size ())
+  if (first_element_no < m_regs_content.size ())
     first_line = line_from_reg_element_no (first_element_no);
   else
     { /* Calculate the first line from the element number which is in
@@ -433,7 +433,7 @@ void
 tui_data_window::refresh_window ()
 {
   tui_gen_win_info::refresh_window ();
-  for (auto &&win : regs_content)
+  for (auto &&win : m_regs_content)
     win.refresh_window ();
 }
 
@@ -443,11 +443,11 @@ tui_data_window::refresh_window ()
 void
 tui_data_window::check_register_values (struct frame_info *frame)
 {
-  if (regs_content.empty ())
-    show_registers (current_group);
+  if (m_regs_content.empty ())
+    show_registers (m_current_group);
   else
     {
-      for (auto &&data_item_win : regs_content)
+      for (auto &&data_item_win : m_regs_content)
 	{
 	  int was_hilighted;
 
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index 73572efdf95..e45a68f8f49 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -71,7 +71,7 @@ struct tui_data_window : public tui_win_info
 
   struct reggroup *get_current_group () const
   {
-    return current_group;
+    return m_current_group;
   }
 
 protected:
@@ -130,9 +130,9 @@ private:
   void erase_data_content (const char *prompt);
 
   /* Windows that are used to display registers.  */
-  std::vector<tui_data_item_window> regs_content;
-  int regs_column_count = 0;
-  struct reggroup *current_group = nullptr;
+  std::vector<tui_data_item_window> m_regs_content;
+  int m_regs_column_count = 0;
+  struct reggroup *m_current_group = nullptr;
 };
 
 #endif /* TUI_TUI_REGS_H */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 19/20] Use make_unique_xstrdup in TUI
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (6 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 12/20] Don't call refresh in tui_resize_all Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 13/20] Remove a call to tui_locator_win_info_ptr Tom Tromey
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a couple of spots in the TUI to use make_unique_xstrdup.
This simplifies the code slightly.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-source.c (tui_source_window::set_contents): Use
	make_unique_xstrdup.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Use
	make_unique_xstrdup.
---
 gdb/ChangeLog        | 7 +++++++
 gdb/tui/tui-disasm.c | 2 +-
 gdb/tui/tui-source.c | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 53ea061afb6..51616bcf874 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -218,7 +218,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
       if (line.size() > offset)
 	src->line.reset (xstrndup (&line[offset], line_width));
       else
-	src->line.reset (xstrdup (""));
+	src->line = make_unique_xstrdup ("");
 
       src->line_or_addr.loa = LOA_ADDRESS;
       src->line_or_addr.u.addr = asm_lines[i].addr;
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index fa6ed7893fe..bb1013bb869 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -183,7 +183,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
 				 symtab_to_fullname (s)) == 0
 		   && cur_line_no == locator->line_no);
 
-	      content[cur_line].line.reset (xstrdup (text.c_str ()));
+	      content[cur_line].line = make_unique_xstrdup (text.c_str ());
 
 	      cur_line++;
 	      cur_line_no++;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 10/20] Change "win_resized" to bool
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (3 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 14/20] Change members of tui_locator_window to std::string Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 08/20] Simplify TUI disassembly Tom Tromey
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the "win_resized" global to be a bool and then updates
the uses.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui.c (tui_enable): Update.
	* tui/tui-win.c (tui_sigwinch_handler, tui_async_resize_screen):
	Update.
	* tui/tui-data.h (tui_win_resized, tui_set_win_resized_to):
	Update.
	* tui/tui-data.c (win_resized): Now bool.
	(tui_win_resized): Return bool.
	(tui_set_win_resized_to): Accept a bool.
---
 gdb/ChangeLog      | 11 +++++++++++
 gdb/tui/tui-data.c |  8 ++++----
 gdb/tui/tui-data.h |  4 ++--
 gdb/tui/tui-win.c  |  4 ++--
 gdb/tui/tui.c      |  2 +-
 5 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 833ea49a951..c14b1711f60 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -38,7 +38,7 @@ struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
 static int term_height, term_width;
 static struct tui_win_info *win_with_focus = NULL;
 
-static int win_resized = FALSE;
+static bool win_resized = false;
 
 
 /*********************************
@@ -56,8 +56,8 @@ tui_win_is_auxiliary (enum tui_win_type win_type)
 ******************************************/
 
 /* Answer a whether the terminal window has been resized or not.  */
-int
-tui_win_resized (void)
+bool
+tui_win_resized ()
 {
   return win_resized;
 }
@@ -65,7 +65,7 @@ tui_win_resized (void)
 
 /* Set a whether the terminal window has been resized or not.  */
 void
-tui_set_win_resized_to (int resized)
+tui_set_win_resized_to (bool resized)
 {
   win_resized = resized;
 }
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index be819503cf2..264652361ef 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -297,8 +297,8 @@ 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 void tui_set_win_with_focus (struct tui_win_info *);
-extern int tui_win_resized (void);
-extern void tui_set_win_resized_to (int);
+extern bool tui_win_resized ();
+extern void tui_set_win_resized_to (bool);
 
 extern struct tui_win_info *tui_next_win (struct tui_win_info *);
 extern struct tui_win_info *tui_prev_win (struct tui_win_info *);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index bf84cdac442..d07a777360f 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -664,7 +664,7 @@ static void
 tui_sigwinch_handler (int signal)
 {
   mark_async_signal_handler (tui_sigwinch_token);
-  tui_set_win_resized_to (TRUE);
+  tui_set_win_resized_to (true);
 }
 
 /* Callback for asynchronously resizing TUI following a SIGWINCH signal.  */
@@ -685,7 +685,7 @@ tui_async_resize_screen (gdb_client_data arg)
     }
   else
     {
-      tui_set_win_resized_to (FALSE);
+      tui_set_win_resized_to (false);
       tui_resize_all ();
       tui_refresh_all_win ();
       tui_update_gdb_sizes ();
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index db34e0c0441..35a7ec70532 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -501,7 +501,7 @@ tui_enable (void)
      window.  */
   if (tui_win_resized ())
     {
-      tui_set_win_resized_to (FALSE);
+      tui_set_win_resized_to (false);
       tui_resize_all ();
     }
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 17/20] Remove strcat_to_buf
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (8 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 13/20] Remove a call to tui_locator_win_info_ptr Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 04/20] Change tui_make_status_line to return std::string Tom Tromey
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

An earlier patch in the series removed the last call to strcat_to_buf,
so this patch removes the function entirely.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui.h (strcat_to_buf): Don't declare.
	* tui/tui.c (strcat_to_buf): Remove.
---
 gdb/ChangeLog |  5 +++++
 gdb/tui/tui.c | 13 -------------
 gdb/tui/tui.h |  2 --
 3 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 35a7ec70532..e1f65f17326 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -567,19 +567,6 @@ tui_disable_command (const char *args, int from_tty)
   tui_disable ();
 }
 
-void
-strcat_to_buf (char *buf, int buflen, 
-	       const char *item_to_add)
-{
-  if (item_to_add != NULL && buf != NULL)
-    {
-      if ((strlen (buf) + strlen (item_to_add)) <= buflen)
-	strcat (buf, item_to_add);
-      else
-	strncat (buf, item_to_add, (buflen - strlen (buf)));
-    }
-}
-
 #if 0
 /* Solaris <sys/termios.h> defines CTRL.  */
 #ifndef CTRL
diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h
index 25ae0c5e471..baf4a813b60 100644
--- a/gdb/tui/tui.h
+++ b/gdb/tui/tui.h
@@ -24,8 +24,6 @@
 
 struct ui_file;
 
-extern void strcat_to_buf (char *, int, const char *);
-
 /* Types of error returns.  */
 enum tui_status
 {
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 13/20] Remove a call to tui_locator_win_info_ptr
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (7 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 19/20] Use make_unique_xstrdup in TUI Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 17/20] Remove strcat_to_buf Tom Tromey
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Commit e594a5d1 ("Turn two locator functions into methods") turned
set_locator_fullname into a method on tui_locator_window.  I missed it
at the time, but this change allows for the removal of a call to
tui_locator_win_info_ptr.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.c (tui_locator_window::set_locator_fullname):
	Don't call tui_locator_win_info_ptr.
---
 gdb/ChangeLog       | 5 +++++
 gdb/tui/tui-stack.c | 6 ++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 6bfbb0e5ea6..830187995be 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -250,10 +250,8 @@ tui_locator_window::rerender ()
 void
 tui_locator_window::set_locator_fullname (const char *fullname)
 {
-  struct tui_locator_window *locator = tui_locator_win_info_ptr ();
-
-  locator->full_name[0] = 0;
-  strcat_to_buf (locator->full_name, MAX_LOCATOR_ELEMENT_LEN, fullname);
+  full_name[0] = 0;
+  strcat_to_buf (full_name, MAX_LOCATOR_ELEMENT_LEN, fullname);
   rerender ();
 }
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 11/20] Set TUI locator height to 1
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 16/20] Rename a private data member in tui_source_window Tom Tromey
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The TUI has long had code to resize the locator, using 2 as the
height.  However the code has "1" in a comment, like:

    locator->resize (2 /* 1 */ ,

This patch fixes the resizing code to set the height to 1.  Doing this
revealed what was probably the reason for setting the height to 2 in
the first place: this caused the locator window to scroll.  However,
this is easily handled by calling scrollok on the locator window.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Use 1 as
	height for locator.
	* tui/tui-stack.c (tui_locator_window::rerender): Call scrollok.
	* tui/tui-layout.c (show_source_disasm_command, show_data)
	(show_source_or_disasm_and_command): Use 1 as height for locator.
---
 gdb/ChangeLog        |  8 ++++++++
 gdb/tui/tui-layout.c | 18 ++++++------------
 gdb/tui/tui-stack.c  |  1 +
 gdb/tui/tui-win.c    |  9 ++++-----
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 33d3dd6cb87..03115a7baa1 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -511,10 +511,8 @@ show_source_disasm_command (void)
 			  tui_term_width (),
 			  0,
 			  src_height - 1);
-  locator->resize (2 /* 1 */ ,
-		   tui_term_width (),
-		   0,
-		   (src_height + asm_height) - 1);
+  locator->resize (1, tui_term_width (),
+		   0, (src_height + asm_height) - 1);
 
   if (TUI_CMD_WIN == NULL)
     tui_win_list[CMD_WIN] = new tui_cmd_window ();
@@ -561,10 +559,8 @@ show_data (enum tui_layout_type new_layout)
 				  tui_term_width (),
 				  0,
 				  data_height - 1);
-  locator->resize (2 /* 1 */ ,
-		   tui_term_width (),
-		   0,
-		   total_height - 1);
+  locator->resize (1, tui_term_width (),
+		   0, total_height - 1);
   TUI_CMD_WIN->resize (TUI_CMD_WIN->height, tui_term_width (),
 		       0, total_height);
 
@@ -635,10 +631,8 @@ show_source_or_disasm_and_command (enum tui_layout_type layout_type)
       win_info = TUI_DISASM_WIN;
     }
 
-  locator->resize (2 /* 1 */ ,
-		   tui_term_width (),
-		   0,
-		   src_height - 1);
+  locator->resize (1, tui_term_width (),
+		   0, src_height - 1);
   win_info->resize (src_height - 1,
 		    tui_term_width (),
 		    0,
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 163a5ad7255..6bfbb0e5ea6 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -229,6 +229,7 @@ tui_locator_window::rerender ()
   if (handle != NULL)
     {
       std::string string = make_status_line ();
+      scrollok (handle, FALSE);
       wmove (handle, 0, 0);
       /* We ignore the return value from wstandout and wstandend, casting
 	 them to void in order to avoid a compiler warning.  The warning
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index d07a777360f..77044738ef6 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -580,8 +580,7 @@ tui_resize_all (void)
 
 	  src_win->resize (new_height, screenwidth, 0, 0);
 
-	  locator->resize (2 /* 1 */, screenwidth,
-			   0, new_height);
+	  locator->resize (1, screenwidth, 0, new_height);
 
 	  new_height = screenheight - (new_height + 1);
 	  TUI_CMD_WIN->resize (new_height, screenwidth,
@@ -637,7 +636,7 @@ tui_resize_all (void)
 	  second_win->resize (new_height, screenwidth,
 			      0, first_win->height - 1);
 
-	  locator->resize (2 /* 1 */, screenwidth,
+	  locator->resize (1, screenwidth,
 			   0, second_win->origin.y + new_height);
 
 	  /* Change the command window's height/width.  */
@@ -1119,7 +1118,7 @@ tui_adjust_win_heights (struct tui_win_info *primary_win_info,
 		  second_win->resize (second_win->height + second_split_diff,
 				      width,
 				      0, first_win->height - 1);
-		  locator->resize (2 /* 1 */, width,
+		  locator->resize (1, width,
 				   0, (second_win->origin.y
 				       + second_win->height + 1));
 
@@ -1155,7 +1154,7 @@ tui_adjust_win_heights (struct tui_win_info *primary_win_info,
 		  else
 		    second_win->resize (second_win->height, width,
 					0, first_win->height - 1);
-		  locator->resize (2 /* 1 */, width,
+		  locator->resize (1, width,
 				   0, (second_win->origin.y
 				       + second_win->height + 1));
 		  TUI_CMD_WIN->origin.y = locator->origin.y + 1;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 05/20] Change tui_make_status_line to be a method
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (17 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 20/20] Change TUI window commands to be case-sensitive Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 09/20] Use "bool" in tui_data_window::show_register_group Tom Tromey
  2019-09-20 19:29 ` [PATCH 00/20] Final round of TUI refactorings Tom Tromey
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes tui_make_status_line to be a method on
tui_locator_window.  This is a minor cleanup.

This also changes the new method to use the locator's width, rather
than the terminal width.  This is important if we ever want to allow
windows to be made more narrow.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.h (struct tui_locator_window) <make_status_line>:
	Declare.
	* tui/tui-stack.c (tui_locator_window::make_status_line): Rename
	from tui_make_status_line.
	(tui_locator_window::rerender): Update.
---
 gdb/ChangeLog       |  8 ++++++++
 gdb/tui/tui-stack.c | 30 ++++++++++++------------------
 gdb/tui/tui-stack.h |  8 ++++++++
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index a2e4a161bb7..163a5ad7255 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -63,13 +63,10 @@ tui_locator_win_info_ptr (void)
   return &_locator;
 }
 
-/* Create the status line to display as much information as we can on
-   this single line: target name, process number, current function,
-   current line, current PC, SingleKey mode.  */
-static std::string
-tui_make_status_line (struct tui_locator_window *loc)
+std::string
+tui_locator_window::make_status_line () const
 {
-  char line_buf[50], *pname;
+  char line_buf[50];
   int status_size;
   int proc_width;
   const char *pid_name;
@@ -94,11 +91,11 @@ tui_make_status_line (struct tui_locator_window *loc)
   if (pid_width > MAX_PID_WIDTH)
     pid_width = MAX_PID_WIDTH;
 
-  status_size = tui_term_width ();
+  status_size = width;
 
   /* Translate line number and obtain its size.  */
-  if (loc->line_no > 0)
-    xsnprintf (line_buf, sizeof (line_buf), "%d", loc->line_no);
+  if (line_no > 0)
+    xsnprintf (line_buf, sizeof (line_buf), "%d", line_no);
   else
     strcpy (line_buf, "??");
   line_width = strlen (line_buf);
@@ -106,8 +103,8 @@ tui_make_status_line (struct tui_locator_window *loc)
     line_width = MIN_LINE_WIDTH;
 
   /* Translate PC address.  */
-  std::string pc_out (loc->gdbarch
-		      ? paddress (loc->gdbarch, loc->addr)
+  std::string pc_out (gdbarch
+		      ? paddress (gdbarch, addr)
 		      : "??");
   const char *pc_buf = pc_out.c_str ();
   int pc_width = pc_out.size ();
@@ -150,9 +147,6 @@ tui_make_status_line (struct tui_locator_window *loc)
         }
     }
 
-  /* Now convert elements to string form.  */
-  pname = loc->proc_name;
-
   /* Now create the locator line from the string version of the
      elements.  */
   string_file string;
@@ -172,12 +166,12 @@ tui_make_status_line (struct tui_locator_window *loc)
   /* Procedure/class name.  */
   if (proc_width > 0)
     {
-      if (strlen (pname) > proc_width)
+      if (strlen (proc_name) > proc_width)
         string.printf ("%s%*.*s* ", PROC_PREFIX,
-		       1 - proc_width, proc_width - 1, pname);
+		       1 - proc_width, proc_width - 1, proc_name);
       else
         string.printf ("%s%*.*s ", PROC_PREFIX,
-		       -proc_width, proc_width, pname);
+		       -proc_width, proc_width, proc_name);
     }
 
   if (line_width > 0)
@@ -234,7 +228,7 @@ tui_locator_window::rerender ()
 {
   if (handle != NULL)
     {
-      std::string string = tui_make_status_line (this);
+      std::string string = make_status_line ();
       wmove (handle, 0, 0);
       /* We ignore the return value from wstandout and wstandend, casting
 	 them to void in order to avoid a compiler warning.  The warning
diff --git a/gdb/tui/tui-stack.h b/gdb/tui/tui-stack.h
index 86239b0d284..b6ffa986a6f 100644
--- a/gdb/tui/tui-stack.h
+++ b/gdb/tui/tui-stack.h
@@ -63,6 +63,14 @@ struct tui_locator_window : public tui_gen_win_info
   CORE_ADDR addr = 0;
   /* Architecture associated with code at this location.  */
   struct gdbarch *gdbarch = nullptr;
+
+private:
+
+  /* Create the status line to display as much information as we can
+     on this single line: target name, process number, current
+     function, current line, current PC, SingleKey mode.  */
+
+  std::string make_status_line () const;
 };
 
 extern void tui_update_locator_fullname (const char *);
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/20] Remove tui_clear_source_windows_detail
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (12 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 18/20] Remove separator comments from TUI Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 06/20] Remove some explicit re-rendering from the TUI Tom Tromey
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The calls to tui_clear_source_windows_detail in tui_add_win_to_layout
aren't needed, because (after the resize unification) resizing will
update the window contents.  Removing these calls lets us remove
several other things as well.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-data.h (tui_clear_source_windows_detail): Don't
	declare.
	* tui/tui-layout.c (tui_add_win_to_layout): Don't call
	tui_clear_source_windows_detail.
	* tui/tui-winsource.h (struct tui_source_window_base)
	<clear_detail>: Don't declare.
	* tui/tui-winsource.c (tui_source_window_base::clear_detail):
	Remove.
	* tui/tui-data.c (tui_clear_source_windows_detail): Remove.
---
 gdb/ChangeLog           | 12 ++++++++++++
 gdb/tui/tui-data.c      |  9 ---------
 gdb/tui/tui-data.h      |  1 -
 gdb/tui/tui-layout.c    |  2 --
 gdb/tui/tui-winsource.c | 11 -----------
 gdb/tui/tui-winsource.h |  2 --
 6 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index c11aa43340c..833ea49a951 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -87,15 +87,6 @@ tui_set_win_with_focus (struct tui_win_info *win_info)
 }
 
 
-/* Clear the pertinent detail in the source windows.  */
-void
-tui_clear_source_windows_detail ()
-{
-  for (tui_source_window_base *win : tui_source_windows ())
-    win->clear_detail ();
-}
-
-
 /* Accessor for the term_height.  */
 int
 tui_term_height (void)
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 23f769f6ba5..be819503cf2 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -295,7 +295,6 @@ 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 void tui_clear_source_windows_detail (void);
 extern struct tui_win_info *tui_win_with_focus (void);
 extern void tui_set_win_with_focus (struct tui_win_info *);
 extern int tui_win_resized (void);
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index df7056ae97b..d331a2f25c7 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -207,7 +207,6 @@ tui_add_win_to_layout (enum tui_win_type type)
 	  && cur_layout != SRC_DISASSEM_COMMAND
 	  && cur_layout != SRC_DATA_COMMAND)
 	{
-	  tui_clear_source_windows_detail ();
 	  if (cur_layout == DISASSEM_DATA_COMMAND)
 	    show_layout (SRC_DATA_COMMAND);
 	  else
@@ -219,7 +218,6 @@ tui_add_win_to_layout (enum tui_win_type type)
 	  && cur_layout != SRC_DISASSEM_COMMAND
 	  && cur_layout != DISASSEM_DATA_COMMAND)
 	{
-	  tui_clear_source_windows_detail ();
 	  if (cur_layout == SRC_DATA_COMMAND)
 	    show_layout (DISASSEM_DATA_COMMAND);
 	  else
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 7a4821dc52c..4520a1ac3fe 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -253,17 +253,6 @@ tui_source_window_base::show_source_content ()
   refresh_window ();
 }
 
-/* See tui-data.h.  */
-
-void
-tui_source_window_base::clear_detail ()
-{
-  gdbarch = NULL;
-  start_line_or_addr.loa = LOA_ADDRESS;
-  start_line_or_addr.u.addr = 0;
-  horizontal_offset = 0;
-}
-
 tui_source_window_base::tui_source_window_base (enum tui_win_type type)
   : tui_win_info (type)
 {
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 4c98ca3ceb2..445cc7c7357 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -101,8 +101,6 @@ protected:
 
 public:
 
-  void clear_detail ();
-
   /* Refill the source window's source cache and update it.  If this
      is a disassembly window, then just update it.  */
   void refill ();
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 16/20] Rename a private data member in tui_source_window
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
  2019-09-10 19:09 ` [PATCH 11/20] Set TUI locator height to 1 Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 15/20] Rename private data members of tui_data_window Tom Tromey
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This renames tui_source_window::fullname to add the "m_" prefix, as it
is a private data member.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-source.h (struct tui_source_window) <m_fullname>: Rename
	from "fullname".
	* tui/tui-source.c (tui_source_window::set_contents)
	(tui_source_window::location_matches_p)
	(tui_source_window::maybe_update): Update.
---
 gdb/ChangeLog        | 8 ++++++++
 gdb/tui/tui-source.c | 6 +++---
 gdb/tui/tui-source.h | 2 +-
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index e6cc0dbc1a3..fa6ed7893fe 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -155,7 +155,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
 
 	  title = s_filename;
 
-	  fullname = make_unique_xstrdup (symtab_to_fullname (s));
+	  m_fullname = make_unique_xstrdup (symtab_to_fullname (s));
 
 	  cur_line = 0;
 	  gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
@@ -275,7 +275,7 @@ tui_source_window::location_matches_p (struct bp_location *loc, int line_no)
   return (content[line_no].line_or_addr.loa == LOA_LINE
 	  && content[line_no].line_or_addr.u.line_no == loc->line_number
 	  && loc->symtab != NULL
-	  && filename_cmp (fullname.get (),
+	  && filename_cmp (m_fullname.get (),
 			   symtab_to_fullname (loc->symtab)) == 0);
 }
 
@@ -307,7 +307,7 @@ tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal,
     start_line = 1;
 
   bool source_already_displayed = (sal.symtab != 0
-				   && showing_source_p (fullname.get ()));
+				   && showing_source_p (m_fullname.get ()));
 
   struct tui_line_or_address l;
 
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 30728e4214e..3ef737c56e9 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -77,7 +77,7 @@ private:
   bool line_is_displayed (int line) const;
 
   /* It is the resolved form as returned by symtab_to_fullname.  */
-  gdb::unique_xmalloc_ptr<char> fullname;
+  gdb::unique_xmalloc_ptr<char> m_fullname;
 
   /* A token used to register and unregister an observer.  */
   gdb::observers::token m_observable;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 14/20] Change members of tui_locator_window to std::string
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (2 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 15/20] Rename private data members of tui_data_window Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 10/20] Change "win_resized" to bool Tom Tromey
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes two members of tui_locator_window to have type
std::string.  This removes a static limit.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-stack.h (MAX_LOCATOR_ELEMENT_LEN): Remove define.
	(struct tui_locator_window) <full_name, proc_name>: Now
	std::string.
	* tui/tui-stack.c (tui_locator_window::make_status_line)
	(tui_locator_window::set_locator_fullname)
	(tui_locator_window::set_locator_info): Update.
	* tui/tui-source.c (tui_source_window::set_contents)
	(tui_source_window::showing_source_p): Update.
---
 gdb/ChangeLog        | 11 +++++++++++
 gdb/tui/tui-source.c |  4 ++--
 gdb/tui/tui-stack.c  | 18 +++++++-----------
 gdb/tui/tui-stack.h  | 10 ++--------
 4 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index f70e053bdb5..e6cc0dbc1a3 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -179,7 +179,7 @@ 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,
+		= (filename_cmp (locator->full_name.c_str (),
 				 symtab_to_fullname (s)) == 0
 		   && cur_line_no == locator->line_no);
 
@@ -213,7 +213,7 @@ bool
 tui_source_window::showing_source_p (const char *fullname) const
 {
   return (!content.empty ()
-	  && (filename_cmp (tui_locator_win_info_ptr ()->full_name,
+	  && (filename_cmp (tui_locator_win_info_ptr ()->full_name.c_str (),
 			    fullname) == 0));
 }
 
diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index 830187995be..d66e3589e42 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -166,12 +166,12 @@ tui_locator_window::make_status_line () const
   /* Procedure/class name.  */
   if (proc_width > 0)
     {
-      if (strlen (proc_name) > proc_width)
+      if (proc_name.size () > proc_width)
         string.printf ("%s%*.*s* ", PROC_PREFIX,
-		       1 - proc_width, proc_width - 1, proc_name);
+		       1 - proc_width, proc_width - 1, proc_name.c_str ());
       else
         string.printf ("%s%*.*s ", PROC_PREFIX,
-		       -proc_width, proc_width, proc_name);
+		       -proc_width, proc_width, proc_name.c_str ());
     }
 
   if (line_width > 0)
@@ -250,8 +250,7 @@ tui_locator_window::rerender ()
 void
 tui_locator_window::set_locator_fullname (const char *fullname)
 {
-  full_name[0] = 0;
-  strcat_to_buf (full_name, MAX_LOCATOR_ELEMENT_LEN, fullname);
+  full_name = fullname;
   rerender ();
 }
 
@@ -272,16 +271,13 @@ tui_locator_window::set_locator_info (struct gdbarch *gdbarch_in,
   if (fullname == NULL)
     fullname = "";
 
-  locator_changed_p |= strncmp (proc_name, procname,
-				MAX_LOCATOR_ELEMENT_LEN) != 0;
+  locator_changed_p |= proc_name != procname;
   locator_changed_p |= lineno != line_no;
   locator_changed_p |= addr_in != addr;
   locator_changed_p |= gdbarch_in != gdbarch;
-  locator_changed_p |= strncmp (full_name, fullname,
-				MAX_LOCATOR_ELEMENT_LEN) != 0;
+  locator_changed_p |= full_name != fullname;
 
-  proc_name[0] = (char) 0;
-  strcat_to_buf (proc_name, MAX_LOCATOR_ELEMENT_LEN, procname);
+  proc_name = procname;
   line_no = lineno;
   addr = addr_in;
   gdbarch = gdbarch_in;
diff --git a/gdb/tui/tui-stack.h b/gdb/tui/tui-stack.h
index b6ffa986a6f..93a79fbd799 100644
--- a/gdb/tui/tui-stack.h
+++ b/gdb/tui/tui-stack.h
@@ -26,12 +26,6 @@
 
 struct frame_info;
 
-#ifdef PATH_MAX
-# define MAX_LOCATOR_ELEMENT_LEN        PATH_MAX
-#else
-# define MAX_LOCATOR_ELEMENT_LEN        1024
-#endif
-
 /* Locator window class.  */
 
 struct tui_locator_window : public tui_gen_win_info
@@ -57,8 +51,8 @@ struct tui_locator_window : public tui_gen_win_info
   /* Set the full_name portion of the locator.  */
   void set_locator_fullname (const char *fullname);
 
-  char full_name[MAX_LOCATOR_ELEMENT_LEN];
-  char proc_name[MAX_LOCATOR_ELEMENT_LEN];
+  std::string full_name;
+  std::string proc_name;
   int line_no = 0;
   CORE_ADDR addr = 0;
   /* Architecture associated with code at this location.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 07/20] Simplify tui_source_window_base::show_source_content
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (15 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 02/20] Change tui_source_element::line to be a unique_xmalloc_ptr Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-10 19:09 ` [PATCH 20/20] Change TUI window commands to be case-sensitive Tom Tromey
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

tui_source_window_base::show_source_content is not used outside the
class any more, so this makes it private.  Examining the callers shows
that it can't be called without source contents, so it can be
simplified as well.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<show_source_content>: Now private.
	* tui/tui-winsource.c
	(tui_source_window_base::show_source_content): Don't handle empty
	content case.
---
 gdb/ChangeLog           |  8 ++++++++
 gdb/tui/tui-winsource.c | 11 +++--------
 gdb/tui/tui-winsource.h |  5 +++--
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 8b507ed9126..683856de817 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -238,15 +238,10 @@ tui_show_source_line (struct tui_source_window_base *win_info, int lineno)
 void
 tui_source_window_base::show_source_content ()
 {
-  if (!content.empty ())
-    {
-      int lineno;
+  gdb_assert (!content.empty ());
 
-      for (lineno = 1; lineno <= content.size (); lineno++)
-        tui_show_source_line (this, lineno);
-    }
-  else
-    erase_source_content ();
+  for (int lineno = 1; lineno <= content.size (); lineno++)
+    tui_show_source_line (this, lineno);
 
   check_and_display_highlight_if_needed ();
   refresh_window ();
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index eca0bde4bb8..a66c63597e7 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -76,6 +76,9 @@ struct tui_source_element
 
 struct tui_source_window_base : public tui_win_info
 {
+private:
+  void show_source_content ();
+
 protected:
   explicit tui_source_window_base (enum tui_win_type type);
 
@@ -106,8 +109,6 @@ public:
 
   virtual bool location_matches_p (struct bp_location *loc, int line_no) = 0;
 
-  void show_source_content ();
-
   void update_exec_info ();
 
   /* Update the window to display the given location.  Does nothing if
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 20/20] Change TUI window commands to be case-sensitive
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (16 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 07/20] Simplify tui_source_window_base::show_source_content Tom Tromey
@ 2019-09-10 19:09 ` Tom Tromey
  2019-09-11  2:34   ` Eli Zaretskii
  2019-09-10 19:09 ` [PATCH 05/20] Change tui_make_status_line to be a method Tom Tromey
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 25+ messages in thread
From: Tom Tromey @ 2019-09-10 19:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The TUI window-related commands like "focus" are case insensitive.
This is not the norm in gdb, and I don't see a good reason to have it
here.  This patch changes the TUI to be case sensitive, like the rest
of gdb.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_set_focus_command): Now case-sensitive.
	(tui_set_win_height_command, parse_scrolling_args): Likewise.
	* tui/tui-layout.c (tui_layout_command): Now case-sensitive.
---
 gdb/ChangeLog        |   6 ++
 gdb/tui/tui-layout.c |  22 +++----
 gdb/tui/tui-win.c    | 140 ++++++++++++++++++-------------------------
 3 files changed, 73 insertions(+), 95 deletions(-)

diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 0f3e8d945e8..7aa670ec69d 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -337,29 +337,23 @@ Layout names are:\n\
 static void
 tui_layout_command (const char *layout_name, int from_tty)
 {
-  int i;
   enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
   enum tui_layout_type cur_layout = tui_current_layout ();
 
-  if (layout_name == NULL)
+  if (layout_name == NULL || *layout_name == '\0')
     error (_("Usage: layout prev | next | LAYOUT-NAME"));
 
-  std::string copy = layout_name;
-  for (i = 0; i < copy.size (); i++)
-    copy[i] = toupper (copy[i]);
-  const char *buf_ptr = copy.c_str ();
-
   /* First check for ambiguous input.  */
-  if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
+  if (strcmp (layout_name, "s") == 0)
     error (_("Ambiguous command input."));
 
-  if (subset_compare (buf_ptr, "SRC"))
+  if (subset_compare (layout_name, "src"))
     new_layout = SRC_COMMAND;
-  else if (subset_compare (buf_ptr, "ASM"))
+  else if (subset_compare (layout_name, "asm"))
     new_layout = DISASSEM_COMMAND;
-  else if (subset_compare (buf_ptr, "SPLIT"))
+  else if (subset_compare (layout_name, "split"))
     new_layout = SRC_DISASSEM_COMMAND;
-  else if (subset_compare (buf_ptr, "REGS"))
+  else if (subset_compare (layout_name, "regs"))
     {
       if (cur_layout == SRC_COMMAND
 	  || cur_layout == SRC_DATA_COMMAND)
@@ -367,9 +361,9 @@ tui_layout_command (const char *layout_name, int from_tty)
       else
 	new_layout = DISASSEM_DATA_COMMAND;
     }
-  else if (subset_compare (buf_ptr, "NEXT"))
+  else if (subset_compare (layout_name, "next"))
     new_layout = next_layout ();
-  else if (subset_compare (buf_ptr, "PREV"))
+  else if (subset_compare (layout_name, "prev"))
     new_layout = prev_layout ();
   else
     error (_("Unrecognized layout: %s"), layout_name);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index aecb7791f0a..37e22c550f9 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -776,35 +776,27 @@ tui_set_focus_command (const char *arg, int from_tty)
 
   if (arg != NULL)
     {
-      char *buf_ptr = xstrdup (arg);
-      int i;
       struct tui_win_info *win_info = NULL;
 
-      for (i = 0; (i < strlen (buf_ptr)); i++)
-	buf_ptr[i] = tolower (arg[i]);
-
-      if (subset_compare (buf_ptr, "next"))
+      if (subset_compare (arg, "next"))
 	win_info = tui_next_win (tui_win_with_focus ());
-      else if (subset_compare (buf_ptr, "prev"))
+      else if (subset_compare (arg, "prev"))
 	win_info = tui_prev_win (tui_win_with_focus ());
       else
-	win_info = tui_partial_win_by_name (buf_ptr);
+	win_info = tui_partial_win_by_name (arg);
 
-      if (win_info == NULL || !win_info->is_visible ())
-	warning (_("Invalid window specified. \n\
-The window name specified must be valid and visible.\n"));
-      else
-	{
-	  tui_set_win_focus_to (win_info);
-	  keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
-	}
+      if (win_info == NULL)
+	error (_("Unrecognized window name \"%s\""), arg);
+      if (!win_info->is_visible ())
+	error (_("Window \"%s\" is not visible"), arg);
 
-      xfree (buf_ptr);
+      tui_set_win_focus_to (win_info);
+      keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
       printf_filtered (_("Focus set to %s window.\n"),
 		       tui_win_with_focus ()->name ());
     }
   else
-    warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
+    error (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
 }
 
 static void
@@ -927,65 +919,61 @@ tui_set_win_height_command (const char *arg, int from_tty)
       char *buf = &copy[0];
       char *buf_ptr = buf;
       char *wname = NULL;
-      int new_height, i;
+      int new_height;
       struct tui_win_info *win_info;
 
       wname = buf_ptr;
       buf_ptr = strchr (buf_ptr, ' ');
       if (buf_ptr != NULL)
 	{
-	  *buf_ptr = (char) 0;
+	  *buf_ptr = '\0';
 
 	  /* Validate the window name.  */
-	  for (i = 0; i < strlen (wname); i++)
-	    wname[i] = tolower (wname[i]);
 	  win_info = tui_partial_win_by_name (wname);
 
-	  if (win_info == NULL || !win_info->is_visible ())
-	    warning (_("Invalid window specified. \n\
-The window name specified must be valid and visible.\n"));
-	  else
+	  if (win_info == NULL)
+	    error (_("Unrecognized window name \"%s\""), arg);
+	  if (!win_info->is_visible ())
+	    error (_("Window \"%s\" is not visible"), arg);
+
+	  /* Process the size.  */
+	  buf_ptr = skip_spaces (buf_ptr);
+
+	  if (*buf_ptr != '\0')
 	    {
-	      /* Process the size.  */
-	      while (*(++buf_ptr) == ' ')
-		;
+	      bool negate = false;
+	      bool fixed_size = true;
+	      int input_no;;
 
-	      if (*buf_ptr != (char) 0)
+	      if (*buf_ptr == '+' || *buf_ptr == '-')
 		{
-		  int negate = FALSE;
-		  int fixed_size = TRUE;
-		  int input_no;;
-
-		  if (*buf_ptr == '+' || *buf_ptr == '-')
-		    {
-		      if (*buf_ptr == '-')
-			negate = TRUE;
-		      fixed_size = FALSE;
-		      buf_ptr++;
-		    }
-		  input_no = atoi (buf_ptr);
-		  if (input_no > 0)
-		    {
-		      if (negate)
-			input_no *= (-1);
-		      if (fixed_size)
-			new_height = input_no;
-		      else
-			new_height = win_info->height + input_no;
-
-		      /* Now change the window's height, and adjust
-		         all other windows around it.  */
-		      if (tui_adjust_win_heights (win_info,
-						new_height) == TUI_FAILURE)
-			warning (_("Invalid window height specified.\n%s"),
-				 WIN_HEIGHT_USAGE);
-		      else
-                        tui_update_gdb_sizes ();
-		    }
+		  if (*buf_ptr == '-')
+		    negate = true;
+		  fixed_size = false;
+		  buf_ptr++;
+		}
+	      input_no = atoi (buf_ptr);
+	      if (input_no > 0)
+		{
+		  if (negate)
+		    input_no *= (-1);
+		  if (fixed_size)
+		    new_height = input_no;
 		  else
+		    new_height = win_info->height + input_no;
+
+		  /* Now change the window's height, and adjust
+		     all other windows around it.  */
+		  if (tui_adjust_win_heights (win_info,
+					      new_height) == TUI_FAILURE)
 		    warning (_("Invalid window height specified.\n%s"),
 			     WIN_HEIGHT_USAGE);
+		  else
+		    tui_update_gdb_sizes ();
 		}
+	      else
+		warning (_("Invalid window height specified.\n%s"),
+			 WIN_HEIGHT_USAGE);
 	    }
 	}
       else
@@ -1299,7 +1287,7 @@ parse_scrolling_args (const char *arg,
 	  buf_ptr = strchr (buf_ptr, ' ');
 	  if (buf_ptr != NULL)
 	    {
-	      *buf_ptr = (char) 0;
+	      *buf_ptr = '\0';
 	      if (num_to_scroll)
 		*num_to_scroll = atoi (num_str);
 	      buf_ptr++;
@@ -1313,29 +1301,19 @@ parse_scrolling_args (const char *arg,
 	{
 	  const char *wname;
 
-	  if (*buf_ptr == ' ')
-	    while (*(++buf_ptr) == ' ')
-	      ;
+	  wname = skip_spaces (buf_ptr);
 
-	  if (*buf_ptr != (char) 0)
+	  if (*wname != '\0')
 	    {
-	      /* Validate the window name.  */
-	      for (char *p = buf_ptr; *p != '\0'; p++)
-		*p = tolower (*p);
-
-	      wname = buf_ptr;
+	      *win_to_scroll = tui_partial_win_by_name (wname);
+
+	      if (*win_to_scroll == NULL)
+		error (_("Unrecognized window `%s'"), wname);
+	      if (!(*win_to_scroll)->is_visible ())
+		error (_("Window is not visible"));
+	      else if (*win_to_scroll == TUI_CMD_WIN)
+		*win_to_scroll = *(tui_source_windows ().begin ());
 	    }
-	  else
-	    wname = "?";
-	  
-	  *win_to_scroll = tui_partial_win_by_name (wname);
-
-	  if (*win_to_scroll == NULL)
-	    error (_("Unrecognized window `%s'"), wname);
-	  if (!(*win_to_scroll)->is_visible ())
-	    error (_("Window is not visible"));
-	  else if (*win_to_scroll == TUI_CMD_WIN)
-	    *win_to_scroll = *(tui_source_windows ().begin ());
 	}
     }
 }
-- 
2.17.2

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 20/20] Change TUI window commands to be case-sensitive
  2019-09-10 19:09 ` [PATCH 20/20] Change TUI window commands to be case-sensitive Tom Tromey
@ 2019-09-11  2:34   ` Eli Zaretskii
  2019-09-11 21:57     ` Tom Tromey
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2019-09-11  2:34 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>
> Date: Tue, 10 Sep 2019 13:08:57 -0600
> 
> The TUI window-related commands like "focus" are case insensitive.
> This is not the norm in gdb, and I don't see a good reason to have it
> here.  This patch changes the TUI to be case sensitive, like the rest
> of gdb.

Shouldn't this be in NEWS?  It's an incompatible behavior change.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 20/20] Change TUI window commands to be case-sensitive
  2019-09-11  2:34   ` Eli Zaretskii
@ 2019-09-11 21:57     ` Tom Tromey
  2019-09-12  3:29       ` Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Tom Tromey @ 2019-09-11 21:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Tom Tromey, gdb-patches

>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

>> From: Tom Tromey <tom@tromey.com>
>> Cc: Tom Tromey <tom@tromey.com>
>> Date: Tue, 10 Sep 2019 13:08:57 -0600
>> 
>> The TUI window-related commands like "focus" are case insensitive.
>> This is not the norm in gdb, and I don't see a good reason to have it
>> here.  This patch changes the TUI to be case sensitive, like the rest
>> of gdb.

Eli> Shouldn't this be in NEWS?  It's an incompatible behavior change.

Good idea, here's an updated patch.

Tom

commit db427ce6225a1fc795261f5f5428cf1a7e99be52
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Jul 23 16:01:03 2019 -0600

    Change TUI window commands to be case-sensitive
    
    The TUI window-related commands like "focus" are case insensitive.
    This is not the norm in gdb, and I don't see a good reason to have it
    here.  This patch changes the TUI to be case sensitive, like the rest
    of gdb.
    
    gdb/ChangeLog
    2019-09-11  Tom Tromey  <tom@tromey.com>
    
            * NEWS: Mention case-sensitivity of TUI commands.
            * tui/tui-win.c (tui_set_focus_command): Now case-sensitive.
            (tui_set_win_height_command, parse_scrolling_args): Likewise.
            * tui/tui-layout.c (tui_layout_command): Now case-sensitive.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 59ae111336f..b5ccdc3b8e2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2019-09-11  Tom Tromey  <tom@tromey.com>
+
+	* NEWS: Mention case-sensitivity of TUI commands.
+	* tui/tui-win.c (tui_set_focus_command): Now case-sensitive.
+	(tui_set_win_height_command, parse_scrolling_args): Likewise.
+	* tui/tui-layout.c (tui_layout_command): Now case-sensitive.
+
 2019-09-10  Tom Tromey  <tom@tromey.com>
 
 	* tui/tui-source.c (tui_source_window::set_contents): Use
diff --git a/gdb/NEWS b/gdb/NEWS
index f382e887c0c..1b2f616e7fb 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -181,6 +181,9 @@ maint show test-options-completion-result
   Commands used by the testsuite to validate the command options
   framework.
 
+focus, winheight, +, -, >, <
+  These commands are now case-sensitive.
+
 * New command options, command completion
 
   GDB now has a standard infrastructure to support dash-style command
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 0f3e8d945e8..7aa670ec69d 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -337,29 +337,23 @@ Layout names are:\n\
 static void
 tui_layout_command (const char *layout_name, int from_tty)
 {
-  int i;
   enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
   enum tui_layout_type cur_layout = tui_current_layout ();
 
-  if (layout_name == NULL)
+  if (layout_name == NULL || *layout_name == '\0')
     error (_("Usage: layout prev | next | LAYOUT-NAME"));
 
-  std::string copy = layout_name;
-  for (i = 0; i < copy.size (); i++)
-    copy[i] = toupper (copy[i]);
-  const char *buf_ptr = copy.c_str ();
-
   /* First check for ambiguous input.  */
-  if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
+  if (strcmp (layout_name, "s") == 0)
     error (_("Ambiguous command input."));
 
-  if (subset_compare (buf_ptr, "SRC"))
+  if (subset_compare (layout_name, "src"))
     new_layout = SRC_COMMAND;
-  else if (subset_compare (buf_ptr, "ASM"))
+  else if (subset_compare (layout_name, "asm"))
     new_layout = DISASSEM_COMMAND;
-  else if (subset_compare (buf_ptr, "SPLIT"))
+  else if (subset_compare (layout_name, "split"))
     new_layout = SRC_DISASSEM_COMMAND;
-  else if (subset_compare (buf_ptr, "REGS"))
+  else if (subset_compare (layout_name, "regs"))
     {
       if (cur_layout == SRC_COMMAND
 	  || cur_layout == SRC_DATA_COMMAND)
@@ -367,9 +361,9 @@ tui_layout_command (const char *layout_name, int from_tty)
       else
 	new_layout = DISASSEM_DATA_COMMAND;
     }
-  else if (subset_compare (buf_ptr, "NEXT"))
+  else if (subset_compare (layout_name, "next"))
     new_layout = next_layout ();
-  else if (subset_compare (buf_ptr, "PREV"))
+  else if (subset_compare (layout_name, "prev"))
     new_layout = prev_layout ();
   else
     error (_("Unrecognized layout: %s"), layout_name);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index aecb7791f0a..37e22c550f9 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -776,35 +776,27 @@ tui_set_focus_command (const char *arg, int from_tty)
 
   if (arg != NULL)
     {
-      char *buf_ptr = xstrdup (arg);
-      int i;
       struct tui_win_info *win_info = NULL;
 
-      for (i = 0; (i < strlen (buf_ptr)); i++)
-	buf_ptr[i] = tolower (arg[i]);
-
-      if (subset_compare (buf_ptr, "next"))
+      if (subset_compare (arg, "next"))
 	win_info = tui_next_win (tui_win_with_focus ());
-      else if (subset_compare (buf_ptr, "prev"))
+      else if (subset_compare (arg, "prev"))
 	win_info = tui_prev_win (tui_win_with_focus ());
       else
-	win_info = tui_partial_win_by_name (buf_ptr);
+	win_info = tui_partial_win_by_name (arg);
 
-      if (win_info == NULL || !win_info->is_visible ())
-	warning (_("Invalid window specified. \n\
-The window name specified must be valid and visible.\n"));
-      else
-	{
-	  tui_set_win_focus_to (win_info);
-	  keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
-	}
+      if (win_info == NULL)
+	error (_("Unrecognized window name \"%s\""), arg);
+      if (!win_info->is_visible ())
+	error (_("Window \"%s\" is not visible"), arg);
 
-      xfree (buf_ptr);
+      tui_set_win_focus_to (win_info);
+      keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
       printf_filtered (_("Focus set to %s window.\n"),
 		       tui_win_with_focus ()->name ());
     }
   else
-    warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
+    error (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
 }
 
 static void
@@ -927,65 +919,61 @@ tui_set_win_height_command (const char *arg, int from_tty)
       char *buf = &copy[0];
       char *buf_ptr = buf;
       char *wname = NULL;
-      int new_height, i;
+      int new_height;
       struct tui_win_info *win_info;
 
       wname = buf_ptr;
       buf_ptr = strchr (buf_ptr, ' ');
       if (buf_ptr != NULL)
 	{
-	  *buf_ptr = (char) 0;
+	  *buf_ptr = '\0';
 
 	  /* Validate the window name.  */
-	  for (i = 0; i < strlen (wname); i++)
-	    wname[i] = tolower (wname[i]);
 	  win_info = tui_partial_win_by_name (wname);
 
-	  if (win_info == NULL || !win_info->is_visible ())
-	    warning (_("Invalid window specified. \n\
-The window name specified must be valid and visible.\n"));
-	  else
+	  if (win_info == NULL)
+	    error (_("Unrecognized window name \"%s\""), arg);
+	  if (!win_info->is_visible ())
+	    error (_("Window \"%s\" is not visible"), arg);
+
+	  /* Process the size.  */
+	  buf_ptr = skip_spaces (buf_ptr);
+
+	  if (*buf_ptr != '\0')
 	    {
-	      /* Process the size.  */
-	      while (*(++buf_ptr) == ' ')
-		;
+	      bool negate = false;
+	      bool fixed_size = true;
+	      int input_no;;
 
-	      if (*buf_ptr != (char) 0)
+	      if (*buf_ptr == '+' || *buf_ptr == '-')
 		{
-		  int negate = FALSE;
-		  int fixed_size = TRUE;
-		  int input_no;;
-
-		  if (*buf_ptr == '+' || *buf_ptr == '-')
-		    {
-		      if (*buf_ptr == '-')
-			negate = TRUE;
-		      fixed_size = FALSE;
-		      buf_ptr++;
-		    }
-		  input_no = atoi (buf_ptr);
-		  if (input_no > 0)
-		    {
-		      if (negate)
-			input_no *= (-1);
-		      if (fixed_size)
-			new_height = input_no;
-		      else
-			new_height = win_info->height + input_no;
-
-		      /* Now change the window's height, and adjust
-		         all other windows around it.  */
-		      if (tui_adjust_win_heights (win_info,
-						new_height) == TUI_FAILURE)
-			warning (_("Invalid window height specified.\n%s"),
-				 WIN_HEIGHT_USAGE);
-		      else
-                        tui_update_gdb_sizes ();
-		    }
+		  if (*buf_ptr == '-')
+		    negate = true;
+		  fixed_size = false;
+		  buf_ptr++;
+		}
+	      input_no = atoi (buf_ptr);
+	      if (input_no > 0)
+		{
+		  if (negate)
+		    input_no *= (-1);
+		  if (fixed_size)
+		    new_height = input_no;
 		  else
+		    new_height = win_info->height + input_no;
+
+		  /* Now change the window's height, and adjust
+		     all other windows around it.  */
+		  if (tui_adjust_win_heights (win_info,
+					      new_height) == TUI_FAILURE)
 		    warning (_("Invalid window height specified.\n%s"),
 			     WIN_HEIGHT_USAGE);
+		  else
+		    tui_update_gdb_sizes ();
 		}
+	      else
+		warning (_("Invalid window height specified.\n%s"),
+			 WIN_HEIGHT_USAGE);
 	    }
 	}
       else
@@ -1299,7 +1287,7 @@ parse_scrolling_args (const char *arg,
 	  buf_ptr = strchr (buf_ptr, ' ');
 	  if (buf_ptr != NULL)
 	    {
-	      *buf_ptr = (char) 0;
+	      *buf_ptr = '\0';
 	      if (num_to_scroll)
 		*num_to_scroll = atoi (num_str);
 	      buf_ptr++;
@@ -1313,29 +1301,19 @@ parse_scrolling_args (const char *arg,
 	{
 	  const char *wname;
 
-	  if (*buf_ptr == ' ')
-	    while (*(++buf_ptr) == ' ')
-	      ;
+	  wname = skip_spaces (buf_ptr);
 
-	  if (*buf_ptr != (char) 0)
+	  if (*wname != '\0')
 	    {
-	      /* Validate the window name.  */
-	      for (char *p = buf_ptr; *p != '\0'; p++)
-		*p = tolower (*p);
-
-	      wname = buf_ptr;
+	      *win_to_scroll = tui_partial_win_by_name (wname);
+
+	      if (*win_to_scroll == NULL)
+		error (_("Unrecognized window `%s'"), wname);
+	      if (!(*win_to_scroll)->is_visible ())
+		error (_("Window is not visible"));
+	      else if (*win_to_scroll == TUI_CMD_WIN)
+		*win_to_scroll = *(tui_source_windows ().begin ());
 	    }
-	  else
-	    wname = "?";
-	  
-	  *win_to_scroll = tui_partial_win_by_name (wname);
-
-	  if (*win_to_scroll == NULL)
-	    error (_("Unrecognized window `%s'"), wname);
-	  if (!(*win_to_scroll)->is_visible ())
-	    error (_("Window is not visible"));
-	  else if (*win_to_scroll == TUI_CMD_WIN)
-	    *win_to_scroll = *(tui_source_windows ().begin ());
 	}
     }
 }

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 20/20] Change TUI window commands to be case-sensitive
  2019-09-11 21:57     ` Tom Tromey
@ 2019-09-12  3:29       ` Eli Zaretskii
  0 siblings, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2019-09-12  3:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
> Date: Wed, 11 Sep 2019 15:57:09 -0600
> 
> >>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Tom Tromey <tom@tromey.com>
> >> Cc: Tom Tromey <tom@tromey.com>
> >> Date: Tue, 10 Sep 2019 13:08:57 -0600
> >> 
> >> The TUI window-related commands like "focus" are case insensitive.
> >> This is not the norm in gdb, and I don't see a good reason to have it
> >> here.  This patch changes the TUI to be case sensitive, like the rest
> >> of gdb.
> 
> Eli> Shouldn't this be in NEWS?  It's an incompatible behavior change.
> 
> Good idea, here's an updated patch.

The NEWS part is OK, thanks.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/20] Final round of TUI refactorings
  2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
                   ` (19 preceding siblings ...)
  2019-09-10 19:09 ` [PATCH 09/20] Use "bool" in tui_data_window::show_register_group Tom Tromey
@ 2019-09-20 19:29 ` Tom Tromey
  20 siblings, 0 replies; 25+ messages in thread
From: Tom Tromey @ 2019-09-20 19:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> This is the final set of TUI refactoring patches that I've written.
Tom> Only the final patch should change the behavior in any way.

I'm going to check these in now.  This should unblock some other TUI
things I'm working on.

Tom

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2019-09-20 19:29 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-10 19:09 [PATCH 00/20] Final round of TUI refactorings Tom Tromey
2019-09-10 19:09 ` [PATCH 11/20] Set TUI locator height to 1 Tom Tromey
2019-09-10 19:09 ` [PATCH 16/20] Rename a private data member in tui_source_window Tom Tromey
2019-09-10 19:09 ` [PATCH 15/20] Rename private data members of tui_data_window Tom Tromey
2019-09-10 19:09 ` [PATCH 14/20] Change members of tui_locator_window to std::string Tom Tromey
2019-09-10 19:09 ` [PATCH 10/20] Change "win_resized" to bool Tom Tromey
2019-09-10 19:09 ` [PATCH 08/20] Simplify TUI disassembly Tom Tromey
2019-09-10 19:09 ` [PATCH 12/20] Don't call refresh in tui_resize_all Tom Tromey
2019-09-10 19:09 ` [PATCH 19/20] Use make_unique_xstrdup in TUI Tom Tromey
2019-09-10 19:09 ` [PATCH 13/20] Remove a call to tui_locator_win_info_ptr Tom Tromey
2019-09-10 19:09 ` [PATCH 17/20] Remove strcat_to_buf Tom Tromey
2019-09-10 19:09 ` [PATCH 04/20] Change tui_make_status_line to return std::string Tom Tromey
2019-09-10 19:09 ` [PATCH 03/20] Move "fullname" to tui_source_window Tom Tromey
2019-09-10 19:09 ` [PATCH 18/20] Remove separator comments from TUI Tom Tromey
2019-09-10 19:09 ` [PATCH 01/20] Remove tui_clear_source_windows_detail Tom Tromey
2019-09-10 19:09 ` [PATCH 06/20] Remove some explicit re-rendering from the TUI Tom Tromey
2019-09-10 19:09 ` [PATCH 02/20] Change tui_source_element::line to be a unique_xmalloc_ptr Tom Tromey
2019-09-10 19:09 ` [PATCH 07/20] Simplify tui_source_window_base::show_source_content Tom Tromey
2019-09-10 19:09 ` [PATCH 20/20] Change TUI window commands to be case-sensitive Tom Tromey
2019-09-11  2:34   ` Eli Zaretskii
2019-09-11 21:57     ` Tom Tromey
2019-09-12  3:29       ` Eli Zaretskii
2019-09-10 19:09 ` [PATCH 05/20] Change tui_make_status_line to be a method Tom Tromey
2019-09-10 19:09 ` [PATCH 09/20] Use "bool" in tui_data_window::show_register_group Tom Tromey
2019-09-20 19:29 ` [PATCH 00/20] Final round of TUI refactorings Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).