aboutsummaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
authorDavid S. Miller <davem@redhat.com>2012-11-20 17:40:28 +0000
committerDavid S. Miller <davem@redhat.com>2012-11-20 17:40:28 +0000
commitb245bdfc672e8e9232e16205999f7e71ac9208b3 (patch)
tree9004896e435a0aa6459b733cab6b9bd9f3f63e22 /gdb/common
parent6bb11ab3b2e75cc4db2c2f63b0ba903c92313406 (diff)
downloadgdb-b245bdfc672e8e9232e16205999f7e71ac9208b3.zip
gdb-b245bdfc672e8e9232e16205999f7e71ac9208b3.tar.gz
gdb-b245bdfc672e8e9232e16205999f7e71ac9208b3.tar.bz2
Fix 'info os' crashes on sparc.
* common/linux-osdata.c (get_number_of_cpu_cores): Delete. (linux_xfer_osdata_processes): Fetch _SC_NPROCESSORS_ONLN via sysconf. (get_cores_used_by_process): Update comment.
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/linux-osdata.c27
1 files changed, 3 insertions, 24 deletions
diff --git a/gdb/common/linux-osdata.c b/gdb/common/linux-osdata.c
index afe3e75..d54f9d3 100644
--- a/gdb/common/linux-osdata.c
+++ b/gdb/common/linux-osdata.c
@@ -26,6 +26,7 @@
#include "linux-osdata.h"
#include <sys/types.h>
+#include <sys/sysinfo.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -253,30 +254,8 @@ get_process_owner (uid_t *owner, PID_T pid)
return -1;
}
-/* Returns the number of CPU cores found on the system. */
-
-static int
-get_number_of_cpu_cores (void)
-{
- int cores = 0;
- FILE *f = fopen ("/proc/cpuinfo", "r");
-
- while (!feof (f))
- {
- char buf[512];
- char *p = fgets (buf, sizeof (buf), f);
-
- if (p && strncmp (buf, "processor", 9) == 0)
- ++cores;
- }
-
- fclose (f);
-
- return cores;
-}
-
/* Find the CPU cores used by process PID and return them in CORES.
- CORES points to an array of at least get_number_of_cpu_cores ()
+ CORES points to an array of at least sysconf(_SC_NPROCESSOR_ONLN)
elements. */
static int
@@ -340,7 +319,7 @@ linux_xfer_osdata_processes (gdb_byte *readbuf,
dirp = opendir ("/proc");
if (dirp)
{
- const int num_cores = get_number_of_cpu_cores ();
+ const int num_cores = sysconf (_SC_NPROCESSORS_ONLN);
struct dirent *dp;
while ((dp = readdir (dirp)) != NULL)