Introduce tui_source_window_base::location_matches_p method
authorTom Tromey <tom@tromey.com>
Fri, 28 Jun 2019 21:19:10 +0000 (15:19 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 17 Jul 2019 18:19:05 +0000 (12:19 -0600)
This introduces the location_matches_p method, removing a spot that
explicitly examines a window's type.

gdb/ChangeLog
2019-07-17  Tom Tromey  <tom@tromey.com>

* tui/tui-winsource.c (tui_update_breakpoint_info): Use
location_matches_p.
* tui/tui-source.c (tui_source_window::location_matches_p): New
method.
* tui/tui-disasm.c (tui_disasm_window::location_matches_p): New
method.
* tui/tui-data.h (struct tui_source_window_base)
<location_matches_p>: New method.
(struct tui_source_window, struct tui_disasm_window)
<location_matches_p>: Likewise.

gdb/ChangeLog
gdb/tui/tui-data.h
gdb/tui/tui-disasm.c
gdb/tui/tui-source.c
gdb/tui/tui-winsource.c

index 9844ec1c1aca15104f1781f70fc73ffaceeaab4f..496819da47a058a38769a2661ec45caf55f2dbc6 100644 (file)
@@ -1,3 +1,16 @@
+2019-07-17  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui-winsource.c (tui_update_breakpoint_info): Use
+       location_matches_p.
+       * tui/tui-source.c (tui_source_window::location_matches_p): New
+       method.
+       * tui/tui-disasm.c (tui_disasm_window::location_matches_p): New
+       method.
+       * tui/tui-data.h (struct tui_source_window_base)
+       <location_matches_p>: New method.
+       (struct tui_source_window, struct tui_disasm_window)
+       <location_matches_p>: Likewise.
+
 2019-07-17  Tom Tromey  <tom@tromey.com>
 
        * tui/tui-win.c (tui_set_win_height_command): Rename from
index be951b4c840b0216fc532120bafb438af37d438c..472fa2ed7f6335c34284156d7f3120c2c0d72f97 100644 (file)
@@ -404,6 +404,10 @@ public:
 
   void update_tab_width () override;
 
+  /* Return true if the location LOC corresponds to the line number
+     LINE_NO in this source window; false otherwise.  */
+  virtual bool location_matches_p (struct bp_location *loc, int line_no) = 0;
+
   /* Does the locator belong to this window?  */
   bool m_has_locator = false;
   /* Execution information window.  */
@@ -435,6 +439,8 @@ struct tui_source_window : public tui_source_window_base
     return SRC_NAME;
   }
 
+  bool location_matches_p (struct bp_location *loc, int line_no) override;
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
@@ -463,6 +469,8 @@ struct tui_disasm_window : public tui_source_window_base
     return DISASSEM_NAME;
   }
 
+  bool location_matches_p (struct bp_location *loc, int line_no) override;
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
index b22368eccf7f9908b7db5f1d2caa5b62d314ea4e..af1a7406be8faca3ff034c7b350f9bccdcdac67f 100644 (file)
@@ -375,3 +375,10 @@ tui_disasm_window::do_scroll_vertical (int num_to_scroll)
                                      NULL, val, FALSE);
     }
 }
+
+bool
+tui_disasm_window::location_matches_p (struct bp_location *loc, int line_no)
+{
+  return (content[line_no].line_or_addr.loa == LOA_ADDRESS
+         && content[line_no].line_or_addr.u.addr == loc->address);
+}
index 34cb38b31afc25f1398dae89e4e3aa70d6e89982..2ca21dcc84507257b5c9b6ef6cf6505260009d5d 100644 (file)
@@ -345,3 +345,13 @@ tui_source_window::style_changed ()
   if (tui_active && is_visible)
     refill ();
 }
+
+bool
+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,
+                          symtab_to_fullname (loc->symtab)) == 0);
+}
index 22cd54ee9b8ade2a682f4d98e835f29db3b87070..03dd1b4af81b8782ca8794a28be24ec946c402c3 100644 (file)
@@ -410,7 +410,6 @@ tui_update_breakpoint_info (struct tui_source_window_base *win,
 {
   int i;
   bool need_refresh = false;
-  tui_source_window_base *src = (tui_source_window_base *) win;
 
   for (i = 0; i < win->content.size (); i++)
     {
@@ -440,15 +439,7 @@ tui_update_breakpoint_info (struct tui_source_window_base *win,
 
          for (loc = bp->loc; loc != NULL; loc = loc->next)
            {
-             if ((win == TUI_SRC_WIN
-                  && loc->symtab != NULL
-                  && filename_cmp (src->fullname,
-                                   symtab_to_fullname (loc->symtab)) == 0
-                  && line->line_or_addr.loa == LOA_LINE
-                  && loc->line_number == line->line_or_addr.u.line_no)
-                 || (win == TUI_DISASM_WIN
-                     && line->line_or_addr.loa == LOA_ADDRESS
-                     && loc->address == line->line_or_addr.u.addr))
+             if (win->location_matches_p (loc, i))
                {
                  if (bp->enable_state == bp_disabled)
                    mode |= TUI_BP_DISABLED;