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] Fix 'info os' crashes on sparc.


The get_number_of_cpu_cores() function really needs to be split out
into a target cpu specific helper function.  Every single Linux
architecture has a different layout for this file, and the amount
of commonality between architectures approaches zero.

Furthermore, the failure mode when this function can't find the number
of cpus properly makes for extremely difficult diagnosis.  Because we
return with zero, malloc() a zero sized area, and immediately write
past the end and corrupt the malloc() pools.

Anyways, for now, ok to commit this?

gdb/

2012-11-19  David S. Miller  <davem@davemloft.net>

	* common/linux-osdata.c (get_number_of_cpu_cores): Add support
	for parsing the layout of sparc /proc/cpuinfo files.

diff --git a/gdb/common/linux-osdata.c b/gdb/common/linux-osdata.c
index afe3e75..5db286b 100644
--- a/gdb/common/linux-osdata.c
+++ b/gdb/common/linux-osdata.c
@@ -266,8 +266,16 @@ get_number_of_cpu_cores (void)
       char buf[512];
       char *p = fgets (buf, sizeof (buf), f);
 
-      if (p && strncmp (buf, "processor", 9) == 0)
-	++cores;
+      if (p)
+	{
+	  if (strncmp (buf, "processor", 9) == 0)
+	    ++cores;
+	  else if (strncmp (buf, "ncpus active\t: ", 15) == 0)
+	    {
+	      sscanf (p + 15, "%d", &cores);
+	      break;
+	    }
+	}
     }
 
   fclose (f);


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