[PATCH] Add cpu information to the info os command on linux.
Pedro Alves
palves@redhat.com
Fri Mar 27 11:38:00 GMT 2015
On 03/25/2015 05:50 PM, Antoine Tremblay wrote:
> This patch adds cpu information on linux based on /proc/cpuinfo as :
> cpus Listing of all cpus/cores on the system
>
> This patch also reorders the info os commands so that they are listed
> in alphabetical order.
Please mention this new field in NEWS, and update the manual as well,
where it reads:
"On @sc{gnu}/Linux, the following values of @var{infotype} are valid:"
and also the example given in the "-info-os" section.
>
> gdb/ChangeLog:
> * gdb/nat/linux-osdata.c (linux_xfer_osdata_cpus): New function.
> (struct osdata_type): Add cpus entry.
Mention the resorting too.
> +/* Collect data about the cpus/cores on the system */
> +
> +static LONGEST
> +linux_xfer_osdata_cpus (gdb_byte *readbuf,
> + ULONGEST offset, ULONGEST len)
> +{
> + static const char *buf;
> + static LONGEST len_avail = -1;
> + static struct buffer buffer;
> +
> + if (offset == 0)
> + {
> + FILE *fp;
> + int first_item = 1;
> +
> + if (len_avail != -1 && len_avail != 0)
> + buffer_free (&buffer);
> + len_avail = 0;
> + buf = NULL;
> + buffer_init (&buffer);
> + buffer_grow_str (&buffer, "<osdata type=\"cpus\">\n");
> +
> + fp = gdb_fopen_cloexec ("/proc/cpuinfo", "r");
> + if (fp)
if (fp != NULL)
> + {
> + char buf[8192];
> +
> + do
> + {
> + if (fgets (buf, sizeof (buf), fp))
> + {
> + char *key, *value;
> + int i = 0;
> +
> + key = strtok (buf, ":");
> + if (key == NULL)
> + continue;
> +
> + value = strtok (NULL, ":");
> + if (value == NULL)
> + continue;
> +
> + while (key[i] != '\t' && key [i] != '\0')
Spurious space in "key [".
> + {
> + i++;
> + }
Unneeded braces. Many cases in the patch.
> + key[i] = '\0';
> +
> + i = 0;
> + while (value[i] != '\t' && value [i] != '\0')
Ditto.
> + {
> + i++;
> + }
> + value[i] = '\0';
> +
> + if (strcmp (key, "processor") == 0)
> + {
> + if (first_item == 1)
> + {
> + buffer_grow_str (&buffer, "<item>");
> + }
> + else
> + {
> + buffer_grow_str (&buffer, "</item><item>");
> + }
Unneeded braces. No need to explicitly compare to 1, AFAICS, this
is treated as boolean:
if (first_item)
buffer_grow_str (&buffer, "<item>");
else
buffer_grow_str (&buffer, "</item><item>");
first_item = 0;
> + first_item = 0;
> + }
> +
> + buffer_xml_printf (
> + &buffer,
Merge these two lines into one.
> + "<column name=\"%s\">%s</column>",
> + key,
> + value);
> + }
> + }
> + while (!feof (fp));
> +
> + if (first_item == 0)
> + {
> + buffer_grow_str (&buffer, "</item>");
> + }
Drop braces.
Thanks,
Pedro Alves
More information about the Gdb-patches
mailing list