diff mbox

Fix TUI use of "has_break" field

Message ID 20190625204718.19141-1-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey June 25, 2019, 8:47 p.m. UTC
The TUI uses the "has_break" in two different ways: sometimes as a
boolean, and sometimes as flags.

This patch changes the TUI to be more type-safe here, and fixes the
code.  I could not find a bug that this caused, so apparently this is
just cosmetic.

This deletes some code from tui_set_disassem_content.  Whenver this is
called, I believe the TUI updates the breakpoint information
afterward, so this assignment is redundant; which is good because it
is also incorrect.

gdb/ChangeLog
2019-06-25  Tom Tromey  <tom@tromey.com>

	PR tui/24724:
	* tui/tui-winsource.c (tui_clear_source_content): Update.
	(tui_source_window_base::set_is_exec_point_at): Fix comment.
	(tui_update_breakpoint_info): Update.
	(tui_set_exec_info_content): Update.
	* tui/tui-source.c (tui_set_source_content_nil): Update.
	* tui/tui-disasm.c (tui_set_disassem_content): Don't set
	has_break.
	* tui/tui-data.h (enum tui_bp_flag): New.
	(tui_bp_flags): New enum flags type.
	(struct tui_source_element) <break_mode>: Change type.  Rename
	from has_break.
	(TUI_BP_ENABLED, TUI_BP_DISABLED, TUI_BP_HIT)
	(TUI_BP_CONDITIONAL, TUI_BP_HARDWARE): Don't define.  Now enum
	constants.
---
 gdb/ChangeLog           | 18 ++++++++++++++++++
 gdb/tui/tui-data.h      | 21 +++++++++++++--------
 gdb/tui/tui-disasm.c    |  6 ------
 gdb/tui/tui-source.c    |  2 +-
 gdb/tui/tui-winsource.c | 17 ++++++++---------
 5 files changed, 40 insertions(+), 24 deletions(-)

Comments

Tom Tromey July 4, 2019, 4:36 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> The TUI uses the "has_break" in two different ways: sometimes as a
Tom> boolean, and sometimes as flags.

Tom> This patch changes the TUI to be more type-safe here, and fixes the
Tom> code.  I could not find a bug that this caused, so apparently this is
Tom> just cosmetic.

Tom> This deletes some code from tui_set_disassem_content.  Whenver this is
Tom> called, I believe the TUI updates the breakpoint information
Tom> afterward, so this assignment is redundant; which is good because it
Tom> is also incorrect.

I'm checking this in now.  The actual patch will include one trivial
change, updating a comment to refer to the new field name.

Tom
diff mbox

Patch

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 8991a4a5172..412be1ce756 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -164,6 +164,18 @@  struct tui_layout_def
   enum tui_win_type display_mode;
 };
 
+/* Flags to tell what kind of breakpoint is at current line.  */
+enum tui_bp_flag
+{
+  TUI_BP_ENABLED = 0x01,
+  TUI_BP_DISABLED = 0x02,
+  TUI_BP_HIT = 0x04,
+  TUI_BP_CONDITIONAL = 0x08,
+  TUI_BP_HARDWARE = 0x10
+};
+
+DEF_ENUM_FLAGS_TYPE (enum tui_bp_flag, tui_bp_flags);
+
 /* Elements in the Source/Disassembly Window.  */
 struct tui_source_element
 {
@@ -181,7 +193,7 @@  struct tui_source_element
   char *line = nullptr;
   struct tui_line_or_address line_or_addr;
   bool is_exec_point = false;
-  int has_break = 0;
+  tui_bp_flags break_mode = 0;
 };
 
 
@@ -191,13 +203,6 @@  struct tui_source_element
 # define MAX_LOCATOR_ELEMENT_LEN        1024
 #endif
 
-/* Flags to tell what kind of breakpoint is at current line.  */
-#define TUI_BP_ENABLED      0x01
-#define TUI_BP_DISABLED     0x02
-#define TUI_BP_HIT          0x04
-#define TUI_BP_CONDITIONAL  0x08
-#define TUI_BP_HARDWARE     0x10
-
 /* Position of breakpoint markers in the exec info string.  */
 #define TUI_BP_HIT_POS      0
 #define TUI_BP_BREAK_POS    1
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 4899b1d03cf..b22368eccf7 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -239,12 +239,6 @@  tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc)
       src->line_or_addr.u.addr = asm_lines[i].addr;
       src->is_exec_point = asm_lines[i].addr == cur_pc;
 
-      /* See whether there is a breakpoint installed.  */
-      src->has_break = (!src->is_exec_point
-			&& breakpoint_here_p (current_program_space->aspace,
-					      pc)
-			!= no_breakpoint_here);
-
       xfree (asm_lines[i].addr_string);
       xfree (asm_lines[i].insn);
     }
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 889b9509fec..81ede061570 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -240,7 +240,7 @@  tui_set_source_content_nil (struct tui_source_window_base *win_info,
       element->line_or_addr.loa = LOA_LINE;
       element->line_or_addr.u.line_no = 0;
       element->is_exec_point = false;
-      element->has_break = FALSE;
+      element->break_mode = 0;
 
       /* Set the contents of the line to blank.  */
       element->line[0] = (char) 0;
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 6ec1f1bc0b6..dbede410278 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -217,7 +217,7 @@  tui_clear_source_content (struct tui_source_window_base *win_info,
 	{
 	  struct tui_source_element *element = &win_info->content[i];
 
-	  element->has_break = FALSE;
+	  element->break_mode = 0;
 	  element->is_exec_point = false;
 	}
     }
@@ -344,7 +344,7 @@  tui_source_window_base::do_scroll_horizontal (int num_to_scroll)
 }
 
 
-/* Set or clear the has_break flag in the line whose line is
+/* Set or clear the is_exec_point flag in the line whose line is
    line_no.  */
 
 void
@@ -415,7 +415,6 @@  tui_update_breakpoint_info (struct tui_source_window_base *win,
     {
       struct breakpoint *bp;
       extern struct breakpoint *breakpoint_chain;
-      int mode;
       struct tui_source_element *line;
 
       line = &win->content[i];
@@ -425,7 +424,7 @@  tui_update_breakpoint_info (struct tui_source_window_base *win,
       /* Scan each breakpoint to see if the current line has something to
          do with it.  Identify enable/disabled breakpoints as well as
          those that we already hit.  */
-      mode = 0;
+      tui_bp_flags mode = 0;
       for (bp = breakpoint_chain;
            bp != NULL;
            bp = bp->next)
@@ -460,10 +459,10 @@  tui_update_breakpoint_info (struct tui_source_window_base *win,
 		}
 	    }
         }
-      if (line->has_break != mode)
+      if (line->break_mode != mode)
         {
-          line->has_break = mode;
-          need_refresh = 1;
+          line->break_mode = mode;
+          need_refresh = true;
         }
     }
   return need_refresh;
@@ -496,7 +495,7 @@  tui_set_exec_info_content (struct tui_source_window_base *win_info)
 	{
 	  tui_exec_info_content &element = content[i];
 	  struct tui_source_element *src_element;
-	  int mode;
+	  tui_bp_flags mode;
 
 	  src_element = &win_info->content[i];
 
@@ -505,7 +504,7 @@  tui_set_exec_info_content (struct tui_source_window_base *win_info)
 
 	  /* Now update the exec info content based upon the state
 	     of each line as indicated by the source content.  */
-	  mode = src_element->has_break;
+	  mode = src_element->break_mode;
 	  if (mode & TUI_BP_HIT)
 	    element[TUI_BP_HIT_POS] = (mode & TUI_BP_HARDWARE) ? 'H' : 'B';
 	  else if (mode & (TUI_BP_ENABLED | TUI_BP_DISABLED))