From patchwork Wed Mar 25 17:50:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tremblay X-Patchwork-Id: 5810 Received: (qmail 77221 invoked by alias); 25 Mar 2015 17:50:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 77208 invoked by uid 89); 25 Mar 2015 17:50:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 25 Mar 2015 17:50:09 +0000 Received: from EUSAAHC008.ericsson.se (Unknown_Domain [147.117.188.96]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id 51.F1.12456.48F92155; Wed, 25 Mar 2015 12:44:04 +0100 (CET) Received: from elxa4wqvvz1.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.96) with Microsoft SMTP Server (TLS) id 14.3.210.2; Wed, 25 Mar 2015 13:50:05 -0400 From: Antoine Tremblay To: CC: Antoine Tremblay Subject: [PATCH] Add cpu information to the info os command on linux. Date: Wed, 25 Mar 2015 13:50:00 -0400 Message-ID: <1427305800-21116-1-git-send-email-antoine.tremblay@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes 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. gdb/ChangeLog: * gdb/nat/linux-osdata.c (linux_xfer_osdata_cpus): New function. (struct osdata_type): Add cpus entry. --- gdb/nat/linux-osdata.c | 132 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 120 insertions(+), 12 deletions(-) diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 0ed5d34..ba281cc 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -662,6 +662,112 @@ linux_xfer_osdata_threads (gdb_byte *readbuf, return len; } +/* 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, "\n"); + + fp = gdb_fopen_cloexec ("/proc/cpuinfo", "r"); + if (fp) + { + 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') + { + i++; + } + key[i] = '\0'; + + i = 0; + while (value[i] != '\t' && value [i] != '\0') + { + i++; + } + value[i] = '\0'; + + if (strcmp (key, "processor") == 0) + { + if (first_item == 1) + { + buffer_grow_str (&buffer, ""); + } + else + { + buffer_grow_str (&buffer, ""); + } + first_item = 0; + } + + buffer_xml_printf ( + &buffer, + "%s", + key, + value); + } + } + while (!feof (fp)); + + if (first_item == 0) + { + buffer_grow_str (&buffer, ""); + } + + fclose (fp); + } + + buffer_grow_str0 (&buffer, "\n"); + buf = buffer_finish (&buffer); + len_avail = strlen (buf); + } + + if (offset >= len_avail) + { + /* Done. Get rid of the buffer. */ + buffer_free (&buffer); + buf = NULL; + len_avail = 0; + return 0; + } + + if (len > len_avail - offset) + len = len_avail - offset; + memcpy (readbuf, buf + offset, len); + + return len; +} + /* Collect all the open file descriptors found in /proc and put the details found about them into READBUF. */ @@ -1532,24 +1638,26 @@ struct osdata_type { char *description; LONGEST (*getter) (gdb_byte *readbuf, ULONGEST offset, ULONGEST len); } osdata_table[] = { + { "cpus", "CPUs", "Listing of all cpus/cores on the system", + linux_xfer_osdata_cpus }, + { "files", "File descriptors", "Listing of all file descriptors", + linux_xfer_osdata_fds }, + { "modules", "Kernel modules", "Listing of all loaded kernel modules", + linux_xfer_osdata_modules }, + { "msg", "Message queues", "Listing of all message queues", + linux_xfer_osdata_msg }, { "processes", "Processes", "Listing of all processes", linux_xfer_osdata_processes }, { "procgroups", "Process groups", "Listing of all process groups", linux_xfer_osdata_processgroups }, - { "threads", "Threads", "Listing of all threads", - linux_xfer_osdata_threads }, - { "files", "File descriptors", "Listing of all file descriptors", - linux_xfer_osdata_fds }, - { "sockets", "Sockets", "Listing of all internet-domain sockets", - linux_xfer_osdata_isockets }, - { "shm", "Shared-memory regions", "Listing of all shared-memory regions", - linux_xfer_osdata_shm }, { "semaphores", "Semaphores", "Listing of all semaphores", linux_xfer_osdata_sem }, - { "msg", "Message queues", "Listing of all message queues", - linux_xfer_osdata_msg }, - { "modules", "Kernel modules", "Listing of all loaded kernel modules", - linux_xfer_osdata_modules }, + { "shm", "Shared-memory regions", "Listing of all shared-memory regions", + linux_xfer_osdata_shm }, + { "sockets", "Sockets", "Listing of all internet-domain sockets", + linux_xfer_osdata_isockets }, + { "threads", "Threads", "Listing of all threads", + linux_xfer_osdata_threads }, { NULL, NULL, NULL } };