[PATCH] Titles for OS data types

Stan Shebs stanshebs@earthlink.net
Tue Jun 26 22:40:00 GMT 2012


Per Vladimir's request in 
http://sourceware.org/ml/gdb-patches/2012-06/msg00003.html , here is a 
patch to Linux OS data that adds a new column "Title". Titles are 
arbitrary strings just like the existing type and description columns, 
but are informally understood to be short descriptions that are suitable 
for menu items, window titles, etc, in a GUI like Eclipse.  Since they 
can clutter up command-line output, the "info os" command omits the column.

Filtering by looking for a column literally named "Title" is a bit hacky 
but hard to do more cleanly, as "info os" is designed to mindlessly 
repeat whatever platform-specific xfer code delivers up.  Still, a 
general mechanism of metadata for columns is certainly overkill for this 
rather specialized case.  I've also omitted a NEWS mention since it only 
affects -info-os, which is itself new.

I'll commit this in a couple days if nobody has any objections.

Stan
stan@codesourcery.com

2012-06-26  Stan Shebs  <stan@codesourcery.com>

     * osdata.c (info_osdata_command): Filter out "Title" columns
     from non-MI uses.
     * common/linux-osdata.c (struct osdata_type): Add title field.
     (osdata_table): Add titles to each entry.
     (linux_command_xfer_osdata): Add a column for title data.

     * gdb.texinfo (Miscellaneous GDB/MI Commands): Update -info-os
     example, add note about title column.

-------------- next part --------------
Index: osdata.c
===================================================================
RCS file: /cvs/src/src/gdb/osdata.c,v
retrieving revision 1.16
diff -u -p -r1.16 osdata.c
--- osdata.c	24 May 2012 00:33:45 -0000	1.16
+++ osdata.c	26 Jun 2012 22:16:40 -0000
@@ -297,6 +297,7 @@ info_osdata_command (char *type, int fro
   struct cleanup *old_chain;
   int ncols = 0;
   int nrows;
+  int col_to_skip = -1;
 
   osdata = get_osdata (type);
   old_chain = make_cleanup_osdata_free (osdata);
@@ -311,6 +312,28 @@ info_osdata_command (char *type, int fro
       last = VEC_last (osdata_item_s, osdata->items);
       if (last->columns)
         ncols = VEC_length (osdata_column_s, last->columns);
+
+      /* As a special case, scan the listing of available data types
+	 for a column named "Title", and only include it with MI
+	 output; this column's normal use is for titles for interface
+	 elements like menus, and it clutters up CLI output.  */
+      if (!type && !ui_out_is_mi_like_p (uiout))
+	{
+	  struct osdata_column *col;
+	  int ix;
+
+	  for (ix = 0;
+	       VEC_iterate (osdata_column_s, last->columns, ix, col);
+	       ix++)
+	    {
+	      if (strcmp (col->name, "Title") == 0)
+		col_to_skip = ix;
+	    }
+	  /* Be sure to reduce the total column count, otherwise
+	     internal errors ensue.  */
+	  if (col_to_skip >= 0)
+	    --ncols;
+	}
     }
 
   make_cleanup_ui_out_table_begin_end (uiout, ncols, nrows,
@@ -335,7 +358,10 @@ info_osdata_command (char *type, int fro
           ix++)
 	{
 	  char col_name[32];
-	  
+
+	  if (ix == col_to_skip)
+	    continue;
+
 	  snprintf (col_name, 32, "col%d", ix);
 	  ui_out_table_header (uiout, 10, ui_left,
 			       col_name, col->name);
@@ -366,7 +392,10 @@ info_osdata_command (char *type, int fro
               ix_cols++)
 	   {
 	     char col_name[32];
-	     
+
+	     if (ix_cols == col_to_skip)
+	       continue;
+
 	     snprintf (col_name, 32, "col%d", ix_cols);
 	     ui_out_field_string (uiout, col_name, col->value);
 	   }
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.981
diff -u -p -r1.981 gdb.texinfo
--- doc/gdb.texinfo	26 Jun 2012 20:14:03 -0000	1.981
+++ doc/gdb.texinfo	26 Jun 2012 22:16:41 -0000
@@ -32660,18 +32660,28 @@ like this:
 @smallexample
 @value{GDBP}
 -info-os
-^done,OSDataTable=@{nr_rows="9",nr_cols="2",
+^done,OSDataTable=@{nr_rows="9",nr_cols="3",
 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
-     @{width="10",alignment="-1",col_name="col1",colhdr="Description"@}],
-body=[item=@{col0="processes",col1="Listing of all processes"@},
-      item=@{col0="procgroups",col1="Listing of all process groups"@},
-      item=@{col0="threads",col1="Listing of all threads"@},
-      item=@{col0="files",col1="Listing of all file descriptors"@},
-      item=@{col0="sockets",col1="Listing of all internet-domain sockets"@},
-      item=@{col0="shm",col1="Listing of all shared-memory regions"@},
-      item=@{col0="semaphores",col1="Listing of all semaphores"@},
-      item=@{col0="msg",col1="Listing of all message queues"@},
-      item=@{col0="modules",col1="Listing of all loaded kernel modules"@}]@}
+     @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
+     @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
+body=[item=@{col0="processes",col1="Listing of all processes",
+            col2="Processes"@},
+      item=@{col0="procgroups",col1="Listing of all process groups",
+            col2="Process groups"@},
+      item=@{col0="threads",col1="Listing of all threads",
+            col2="Threads"@},
+      item=@{col0="files",col1="Listing of all file descriptors",
+            col2="File descriptors"@},
+      item=@{col0="sockets",col1="Listing of all internet-domain sockets",
+            col2="Sockets"@},
+      item=@{col0="shm",col1="Listing of all shared-memory regions",
+            col2="Shared-memory regions"@},
+      item=@{col0="semaphores",col1="Listing of all semaphores",
+            col2="Semaphores"@},
+      item=@{col0="msg",col1="Listing of all message queues",
+            col2="Message queues"@},
+      item=@{col0="modules",col1="Listing of all loaded kernel modules",
+            col2="Kernel modules"@}]@}
 @value{GDBP}
 -info-os processes
 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
@@ -32688,6 +32698,12 @@ body=[item=@{col0="1",col1="root",col2="
 (gdb)
 @end smallexample
 
+(Note that the MI output here includes a @code{"Title"} column that
+does not appear in command-line @code{info os}; this column is useful
+for MI clients that want to enumerate the types of data, such as in a
+popup menu, but is needless clutter on the command line, and
+@code{info os} omits it.)
+
 @subheading The @code{-add-inferior} Command
 @findex -add-inferior
 
Index: common/linux-osdata.c
===================================================================
RCS file: /cvs/src/src/gdb/common/linux-osdata.c,v
retrieving revision 1.5
diff -u -p -r1.5 linux-osdata.c
--- common/linux-osdata.c	11 May 2012 22:24:22 -0000	1.5
+++ common/linux-osdata.c	26 Jun 2012 22:16:41 -0000
@@ -1543,26 +1543,27 @@ linux_xfer_osdata_modules (gdb_byte *rea
 
 struct osdata_type {
   char *type;
+  char *title;
   char *description;
   LONGEST (*getter) (gdb_byte *readbuf, ULONGEST offset, LONGEST len);
 } osdata_table[] = {
-  { "processes", "Listing of all processes",
+  { "processes", "Processes", "Listing of all processes",
     linux_xfer_osdata_processes },
-  { "procgroups", "Listing of all process groups",
+  { "procgroups", "Process groups", "Listing of all process groups",
     linux_xfer_osdata_processgroups },
-  { "threads", "Listing of all threads",
+  { "threads", "Threads", "Listing of all threads",
     linux_xfer_osdata_threads },
-  { "files", "Listing of all file descriptors",
+  { "files", "File descriptors", "Listing of all file descriptors",
     linux_xfer_osdata_fds },
-  { "sockets", "Listing of all internet-domain sockets",
+  { "sockets", "Sockets", "Listing of all internet-domain sockets",
     linux_xfer_osdata_isockets },
-  { "shm", "Listing of all shared-memory regions",
+  { "shm", "Shared-memory regions", "Listing of all shared-memory regions",
     linux_xfer_osdata_shm },
-  { "semaphores", "Listing of all semaphores",
+  { "semaphores", "Semaphores", "Listing of all semaphores",
     linux_xfer_osdata_sem },
-  { "msg", "Listing of all message queues",
+  { "msg", "Message queues", "Listing of all message queues",
     linux_xfer_osdata_msg },
-  { "modules", "Listing of all loaded kernel modules",
+  { "modules", "Kernel modules", "Listing of all loaded kernel modules",
     linux_xfer_osdata_modules },
   { NULL, NULL, NULL }
 };
@@ -1594,9 +1595,11 @@ linux_common_xfer_osdata (const char *an
 			       "<item>"
 			       "<column name=\"Type\">%s</column>"
 			       "<column name=\"Description\">%s</column>"
+			       "<column name=\"Title\">%s</column>"
 			       "</item>",
 			       osdata_table[i].type,
-			       osdata_table[i].description);
+			       osdata_table[i].description,
+			       osdata_table[i].title);
 
 	  buffer_grow_str0 (&buffer, "</osdata>\n");
 	  buf = buffer_finish (&buffer);


More information about the Gdb-patches mailing list