This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Improve TUI breakpoint display


Hi!

The TUI displays very basic information about breakpoints.  Only a '*' is displayed
to mark a line with a breakpoint.  It's detection of which lines have a breakpoint
is also implemented in two places and differently.

The following patch improves this to:

  - have a single place to detect if a source line has a breakpoint
  - display more info about breakpoints.
    The following type marker is displayed (only one of them):

          b    Breakpoint at line, never hit
          B    Breakpoint at line, hit > 0
          h    Hardware breakpoint, never hit
          H    Hardware breakpoint, hit > 0

    In addition, a '+' is displayed for breakpoints that are enabled
    and a '-' is displayed for those disabled.

    We can now see:  'B+' or 'b-' instead of '*' in the execution window.

This patch is not yet committed.  I'll commit it in a few days (before 5.3 branch)
unless there are objections not to do so.

	Stephane

2002-08-26  Stephane Carrez  <stcarrez@nerim.fr>

	* tuiSourceWin.h (tui_update_all_breakpoint_info): Declare.
	(tui_update_breakpoint_info): Declare.
	(tuiSetHasBreakAt, tuiAllSetHasBreakAt): Remove.
	
	* tuiSourceWin.c (tuiUpdateSourceWindowAsIs): Update breakpoint
	information using tui_update_breakpoint_info.
	(tui_update_all_breakpoint_info): New function to refresh all
	execution windows.
	(tui_update_breakpoint_info): New function to recompute the status
	of exec info window from breakpoints.
	(tuiSetHasBreakAt, tuiAllSetHasBreakAt): Remove.
	(tuiSetExecInfoContent): Use the exec info flags computed by
	tui_update_breakpoint_info to display a short status about breakpoints.

	* tuiData.h (TuiExecInfoContent): New for exec info string.
	(TuiWhichElement): Use it.
	(TUI_BP_ENABLED, TUI_BP_DISABLED, TUI_BP_HIT): New defines.
	(TUI_BP_CONDITIONAL, TUI_BP_HARDWARE): New defines.
	(TUI_BP_HIT_POS, TUI_BP_BREAK_POS, TUI_EXEC_POS): Likewise.
	(TUI_EXECINFO_SIZE): Likewise.
	* tuiData.c (initContentElement): Clear exec info string.

	* tui-hooks.c (get_breakpoint): Remove.
	(tui_event_create_breakpoint): Call tui_update_all_breakpoint_info.
	(tui_event_delete_breakpoint): Likewise.
	(tui_event_modify_breakpoint): Likewise.

Index: tui-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tui-hooks.c,v
retrieving revision 1.5
diff -u -p -r1.5 tui-hooks.c
--- tui-hooks.c	25 Aug 2002 19:19:50 -0000	1.5
+++ tui-hooks.c	25 Aug 2002 21:12:27 -0000
@@ -167,44 +167,12 @@ tui_register_changed_hook (int regno)
     }
 }
 
-extern struct breakpoint *breakpoint_chain;
-
-/* Find a breakpoint given its number.  Returns null if not found.  */
-static struct breakpoint *
-get_breakpoint (int number)
-{
-  struct breakpoint *bp;
-
-  for (bp = breakpoint_chain; bp; bp = bp->next)
-    {
-      if (bp->number == number)
-        return bp;
-    }
-  return 0;
-}
-
 /* Breakpoint creation hook.
    Update the screen to show the new breakpoint.  */
 static void
 tui_event_create_breakpoint (int number)
 {
-  struct breakpoint *bp;
-
-  bp = get_breakpoint (number);
-  if (bp)
-    {
-      switch (bp->type)
-        {
-        case bp_breakpoint:
-        case bp_hardware_breakpoint:
-          tuiAllSetHasBreakAt (bp, 1);
-          tuiUpdateAllExecInfos ();
-          break;
-
-        default:
-          break;
-        }
-    }
+  tui_update_all_breakpoint_info ();
 }
 
 /* Breakpoint deletion hook.
@@ -212,35 +180,13 @@ tui_event_create_breakpoint (int number)
 static void
 tui_event_delete_breakpoint (int number)
 {
-  struct breakpoint *bp;
-  struct breakpoint *b;
-  int clearIt;
-
-  bp = get_breakpoint (number);
-  if (bp == 0)
-    return;
-
-  /* Before turning off the visuals for the bp, check to see that
-     there are no other bps at the same address. */
-  clearIt = 0;
-  for (b = breakpoint_chain; b; b = b->next)
-    {
-      clearIt = (b == bp || b->address != bp->address);
-      if (!clearIt)
-        break;
-    }
-
-  if (clearIt)
-    {
-      tuiAllSetHasBreakAt (bp, 0);
-      tuiUpdateAllExecInfos ();
-    }
+  tui_update_all_breakpoint_info ();
 }
 
 static void
 tui_event_modify_breakpoint (int number)
 {
-  ;
+  tui_update_all_breakpoint_info ();
 }
 
 static void
Index: tuiData.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tuiData.c,v
retrieving revision 1.9
diff -u -p -r1.9 tuiData.c
--- tuiData.c	25 Aug 2002 11:00:46 -0000	1.9
+++ tuiData.c	25 Aug 2002 21:12:27 -0000
@@ -888,7 +888,8 @@ initContentElement (TuiWinElementPtr ele
       element->whichElement.locator.addr = 0;
       break;
     case EXEC_INFO_WIN:
-      element->whichElement.simpleString = blankStr ();
+      memset(element->whichElement.simpleString, ' ',
+             sizeof(element->whichElement.simpleString));
       break;
     default:
       break;
Index: tuiData.h
===================================================================
RCS file: /cvs/src/src/gdb/tui/tuiData.h,v
retrieving revision 1.9
diff -u -p -r1.9 tuiData.h
--- tuiData.h	25 Aug 2002 11:00:46 -0000	1.9
+++ tuiData.h	25 Aug 2002 21:12:27 -0000
@@ -200,6 +200,20 @@ typedef struct _TuiLocatorElement
   }
 TuiLocatorElement, *TuiLocatorElementPtr;
 
+/* 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
+#define TUI_EXEC_POS        2
+#define TUI_EXECINFO_SIZE   4
+
+typedef char TuiExecInfoContent[TUI_EXECINFO_SIZE];
 
 /* An content element in a window */
 typedef union
@@ -209,7 +223,7 @@ typedef union
     TuiDataElement data;	/* elements of dataWindow */
     TuiCommandElement command;	/* command elements */
     TuiLocatorElement locator;	/* locator elements */
-    char *simpleString;		/* simple char based elements */
+    TuiExecInfoContent simpleString;	/* simple char based elements */
   }
 TuiWhichElement, *TuiWhichElementPtr;
 
Index: tuiSourceWin.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tuiSourceWin.c,v
retrieving revision 1.17
diff -u -p -r1.17 tuiSourceWin.c
--- tuiSourceWin.c	25 Aug 2002 19:19:50 -0000	1.17
+++ tuiSourceWin.c	25 Aug 2002 21:12:28 -0000
@@ -120,7 +120,7 @@ tuiUpdateSourceWindowAsIs (TuiWinInfoPtr
     }
   else
     {
-      tuiEraseSourceContent (winInfo, NO_EMPTY_SOURCE_PROMPT);
+      tui_update_breakpoint_info (winInfo, 0);
       tuiShowSourceContent (winInfo);
       tuiUpdateExecInfo (winInfo);
       if (winInfo->generic.type == SRC_WIN)
@@ -398,67 +398,85 @@ tuiSetIsExecPointAt (TuiLineOrAddress l,
   return;
 }				/* tuiSetIsExecPointAt */
 
-/*
-   ** tuiSetHasBreakAt().
-   **        Set or clear the hasBreak flag in the line whose line is lineNo.
- */
+/* Update the execution windows to show the active breakpoints.
+   This is called whenever a breakpoint is inserted, removed or
+   has its state changed.  */
 void
-tuiSetHasBreakAt (struct breakpoint *bp, TuiWinInfoPtr winInfo, int hasBreak)
+tui_update_all_breakpoint_info ()
 {
+  TuiList* list = sourceWindows ();
   int i;
-  TuiWinContent content = (TuiWinContent) winInfo->generic.content;
 
-  i = 0;
-  while (i < winInfo->generic.contentSize)
+  for (i = 0; i < list->count; i++)
     {
-      int gotIt;
-      TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
-
-      if (winInfo == srcWin)
-	{
-          TuiSourceInfoPtr src = &winInfo->detail.sourceInfo;
+      TuiWinInfoPtr win = (TuiWinInfoPtr) list->list[i];
 
-	  gotIt = (src->filename != (char *) NULL &&
-                   bp->source_file != NULL &&
-		   (strcmp (bp->source_file, src->filename) == 0) &&
-		   content[i]->whichElement.source.lineOrAddr.lineNo ==
-		   bp->line_number);
-	}
-      else
-	gotIt = (content[i]->whichElement.source.lineOrAddr.addr
-		 == bp->address);
-      if (gotIt)
-	{
-	  content[i]->whichElement.source.hasBreak = hasBreak;
-	  break;
-	}
-      i++;
+      if (tui_update_breakpoint_info (win, FALSE))
+        {
+          tuiUpdateExecInfo (win);
+        }
     }
-
-  return;
-}				/* tuiSetHasBreakAt */
+}
 
 
-/*
-   ** tuiAllSetHasBreakAt().
-   **        Set or clear the hasBreak flag in all displayed source windows.
- */
-void
-tuiAllSetHasBreakAt (struct breakpoint *bp, int hasBreak)
+/* Scan the source window and the breakpoints to update the
+   hasBreak information for each line.
+   Returns 1 if something changed and the execution window
+   must be refreshed.  */
+int
+tui_update_breakpoint_info (TuiWinInfoPtr win, int current_only)
 {
   int i;
+  int need_refresh = 0;
+  TuiSourceInfoPtr src = &win->detail.sourceInfo;
 
-  for (i = 0; i < (sourceWindows ())->count; i++)
-    tuiSetHasBreakAt (bp,
-		      (TuiWinInfoPtr) (sourceWindows ())->list[i], hasBreak);
-
-  return;
-}				/* tuiAllSetHasBreakAt */
-
+  for (i = 0; i < win->generic.contentSize; i++)
+    {
+      struct breakpoint *bp;
+      extern struct breakpoint *breakpoint_chain;
+      int mode;
+      TuiSourceElement* line;
+
+      line = &((TuiWinElementPtr) win->generic.content[i])->whichElement.source;
+      if (current_only && !line->isExecPoint)
+         continue;
+
+      /* 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;
+      for (bp = breakpoint_chain;
+           bp != (struct breakpoint *) NULL;
+           bp = bp->next)
+        {
+          if ((win == srcWin
+               && bp->source_file
+               && (strcmp (src->filename, bp->source_file) == 0)
+               && bp->line_number == line->lineOrAddr.lineNo)
+              || (win == disassemWin
+                  && bp->address == line->lineOrAddr.addr))
+            {
+              if (bp->enable_state == bp_disabled)
+                mode |= TUI_BP_DISABLED;
+              else
+                mode |= TUI_BP_ENABLED;
+              if (bp->hit_count)
+                mode |= TUI_BP_HIT;
+              if (bp->cond)
+                mode |= TUI_BP_CONDITIONAL;
+              if (bp->type == bp_hardware_breakpoint)
+                mode |= TUI_BP_HARDWARE;
+            }
+        }
+      if (line->hasBreak != mode)
+        {
+          line->hasBreak = mode;
+          need_refresh = 1;
+        }
+    }
+  return need_refresh;
+}
 
-/*********************************
-** EXECUTION INFO FUNCTIONS        **
-*********************************/
 
 /*
    ** tuiSetExecInfoContent().
@@ -483,56 +501,37 @@ tuiSetExecInfoContent (TuiWinInfoPtr win
 	{
 	  int i;
 
+          tui_update_breakpoint_info (winInfo, 1);
 	  for (i = 0; i < winInfo->generic.contentSize; i++)
 	    {
 	      TuiWinElementPtr element;
 	      TuiWinElementPtr srcElement;
+              int mode;
 
 	      element = (TuiWinElementPtr) execInfoPtr->content[i];
 	      srcElement = (TuiWinElementPtr) winInfo->generic.content[i];
-	      /*
-	         ** First check to see if we have a breakpoint that is
-	         ** temporary.  If so, and this is our current execution point,
-	         ** then clear the break indicator.
-	       */
-	      if (srcElement->whichElement.source.hasBreak &&
-		  srcElement->whichElement.source.isExecPoint)
-		{
-		  struct breakpoint *bp;
-		  int found = FALSE;
-		  extern struct breakpoint *breakpoint_chain;
-
-		  for (bp = breakpoint_chain;
-		       (bp != (struct breakpoint *) NULL && !found);
-		       bp = bp->next)
-		    {
-		      found =
-			(winInfo == srcWin &&
-			 bp->line_number ==
-		       srcElement->whichElement.source.lineOrAddr.lineNo) ||
-			(winInfo == disassemWin &&
-			 bp->address == (CORE_ADDR)
-			 srcElement->whichElement.source.lineOrAddr.addr);
-		      if (found)
-			srcElement->whichElement.source.hasBreak =
-			  (bp->disposition != disp_del || bp->hit_count <= 0);
-		    }
-		  if (!found)
-		    srcElement->whichElement.source.hasBreak = FALSE;
-		}
-	      /*
-	         ** Now update the exec info content based upon the state
-	         ** of each line as indicated by the source content.
-	       */
-	      if (srcElement->whichElement.source.hasBreak &&
-		  srcElement->whichElement.source.isExecPoint)
-		element->whichElement.simpleString = breakLocationStr ();
-	      else if (srcElement->whichElement.source.hasBreak)
-		element->whichElement.simpleString = breakStr ();
-	      else if (srcElement->whichElement.source.isExecPoint)
-		element->whichElement.simpleString = locationStr ();
-	      else
-		element->whichElement.simpleString = blankStr ();
+
+              memset(element->whichElement.simpleString, ' ',
+                     sizeof(element->whichElement.simpleString));
+              element->whichElement.simpleString[TUI_EXECINFO_SIZE - 1] = 0;
+
+	      /* Now update the exec info content based upon the state
+                 of each line as indicated by the source content.  */
+              mode = srcElement->whichElement.source.hasBreak;
+              if (mode & TUI_BP_HIT)
+                element->whichElement.simpleString[TUI_BP_HIT_POS] =
+                  (mode & TUI_BP_HARDWARE) ? 'H' : 'B';
+              else if (mode & (TUI_BP_ENABLED | TUI_BP_DISABLED))
+                element->whichElement.simpleString[TUI_BP_HIT_POS] =
+                  (mode & TUI_BP_HARDWARE) ? 'h' : 'b';
+
+              if (mode & TUI_BP_ENABLED)
+                element->whichElement.simpleString[TUI_BP_BREAK_POS] = '+';
+              else if (mode & TUI_BP_DISABLED)
+                element->whichElement.simpleString[TUI_BP_BREAK_POS] = '-';
+
+              if (srcElement->whichElement.source.isExecPoint)
+                element->whichElement.simpleString[TUI_EXEC_POS] = '>';
 	    }
 	  execInfoPtr->contentSize = winInfo->generic.contentSize;
 	}
@@ -541,7 +540,7 @@ tuiSetExecInfoContent (TuiWinInfoPtr win
     }
 
   return ret;
-}				/* tuiSetExecInfoContent */
+}
 
 
 /*
Index: tuiSourceWin.h
===================================================================
RCS file: /cvs/src/src/gdb/tui/tuiSourceWin.h,v
retrieving revision 1.11
diff -u -p -r1.11 tuiSourceWin.h
--- tuiSourceWin.h	25 Aug 2002 19:19:50 -0000	1.11
+++ tuiSourceWin.h	25 Aug 2002 21:12:28 -0000
@@ -22,6 +22,17 @@
 #ifndef _TUI_SOURCEWIN_H
 #define _TUI_SOURCEWIN_H
 
+/* Update the execution windows to show the active breakpoints.
+   This is called whenever a breakpoint is inserted, removed or
+   has its state changed.  */
+extern void tui_update_all_breakpoint_info (void);
+
+/* Scan the source window and the breakpoints to update the
+   hasBreak information for each line.
+   Returns 1 if something changed and the execution window
+   must be refreshed.  */
+extern int tui_update_breakpoint_info (TuiWinInfoPtr win, int current_only);
+
 /* Function to display the "main" routine.  */
 extern void tui_display_main (void);
 extern void tuiUpdateSourceWindow (TuiWinInfoPtr, struct symtab *, TuiLineOrAddress,
@@ -47,8 +58,6 @@ extern void tuiUpdateExecInfo (TuiWinInf
 extern void tuiUpdateAllExecInfos (void);
 
 extern void tuiSetIsExecPointAt (TuiLineOrAddress, TuiWinInfoPtr);
-extern void tuiSetHasBreakAt (struct breakpoint *, TuiWinInfoPtr, int);
-extern void tuiAllSetHasBreakAt (struct breakpoint *, int);
 extern TuiStatus tuiAllocSourceBuffer (TuiWinInfoPtr);
 extern int tuiLineIsDisplayed (int, TuiWinInfoPtr, int);
 extern int tuiAddrIsDisplayed (CORE_ADDR, TuiWinInfoPtr, int);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]