This is the mail archive of the gdb-patches@sourceware.org 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] Report available OS data types


As a lead-in to some upcoming work on "OS awareness" for Linux GDB, here is a little patch for "info os" to return the types of data available (which is currently just "processes"), instead of erroring out.

Stan

2010-06-14 Stan Shebs <stan@codesourcery.com>

   * osdata.c (get_osdata): Warn separately if target does not report
   type list.
   (info_osdata_command): Allow empty type, report error if target
   does not return available types of OS data.
   * linux-nat.c (linux_nat_xfer_osdata): Report list of OS data
   types if no annex supplied.

Index: linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-nat.c,v
retrieving revision 1.170
diff -p -r1.170 linux-nat.c
*** linux-nat.c	28 May 2010 18:23:15 -0000	1.170
--- linux-nat.c	14 Jun 2010 22:09:34 -0000
*************** linux_nat_xfer_osdata (struct target_ops
*** 4948,4953 ****
--- 4948,4992 ----
  
    gdb_assert (object == TARGET_OBJECT_OSDATA);
  
+   if (!annex)
+     {
+       if (offset == 0)
+ 	{
+ 	  if (len_avail != -1 && len_avail != 0)
+ 	    obstack_free (&obstack, NULL);
+ 	  len_avail = 0;
+ 	  buf = NULL;
+ 	  obstack_init (&obstack);
+ 	  obstack_grow_str (&obstack, "<osdata type=\"types\">\n");
+ 
+ 	  obstack_xml_printf (
+ 			      &obstack,
+ 			      "<item>"
+ 			      "<column name=\"Type\">processes</column>"
+ 			      "<column name=\"Description\">Listing of all processes</column>"
+ 			      "</item>");
+ 
+ 	  obstack_grow_str0 (&obstack, "</osdata>\n");
+ 	  buf = obstack_finish (&obstack);
+ 	  len_avail = strlen (buf);
+ 	}
+ 
+       if (offset >= len_avail)
+ 	{
+ 	  /* Done.  Get rid of the obstack.  */
+ 	  obstack_free (&obstack, NULL);
+ 	  buf = NULL;
+ 	  len_avail = 0;
+ 	  return 0;
+ 	}
+ 
+       if (len > len_avail - offset)
+ 	len = len_avail - offset;
+       memcpy (readbuf, buf + offset, len);
+ 
+       return len;
+     }
+ 
    if (strcmp (annex, "processes") != 0)
      return 0;
  
Index: osdata.c
===================================================================
RCS file: /cvs/src/src/gdb/osdata.c,v
retrieving revision 1.6
diff -p -r1.6 osdata.c
*** osdata.c	16 May 2010 00:46:46 -0000	1.6
--- osdata.c	14 Jun 2010 22:09:34 -0000
*************** get_osdata (const char *type)
*** 256,262 ****
        struct cleanup *old_chain = make_cleanup (xfree, xml);
  
        if (xml[0] == '\0')
! 	warning (_("Empty data returned by target.  Wrong osdata type?"));
        else
  	osdata = osdata_parse (xml);
  
--- 256,267 ----
        struct cleanup *old_chain = make_cleanup (xfree, xml);
  
        if (xml[0] == '\0')
! 	{
! 	  if (type)
! 	    warning (_("Empty data returned by target.  Wrong osdata type?"));
! 	  else
! 	    warning (_("Empty type list returned by target.  No type data?"));
! 	}
        else
  	osdata = osdata_parse (xml);
  
*************** info_osdata_command (char *type, int fro
*** 294,308 ****
    int ncols;
    int nprocs;
  
-   if (type == 0)
-     /* TODO: No type could mean "list availables types".  */
-     error (_("Argument required."));
- 
    osdata = get_osdata (type);
    old_chain = make_cleanup_osdata_free (osdata);
  
    nprocs = VEC_length (osdata_item_s, osdata->items);
  
    last = VEC_last (osdata_item_s, osdata->items);
    if (last && last->columns)
      ncols = VEC_length (osdata_column_s, last->columns);
--- 299,312 ----
    int ncols;
    int nprocs;
  
    osdata = get_osdata (type);
    old_chain = make_cleanup_osdata_free (osdata);
  
    nprocs = VEC_length (osdata_item_s, osdata->items);
  
+   if (!type && nprocs == 0)
+     error (_("Available types of OS data not reported."));
+ 
    last = VEC_last (osdata_item_s, osdata->items);
    if (last && last->columns)
      ncols = VEC_length (osdata_column_s, last->columns);

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