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]

[patchv2] Fix crash on process name "(sd-pam)" (PR 16594)


Hi,

I have added two other cases not handling it well.

It can IMO never work perfectly, the file format is ambiguous.
Or maybe one could parse it in opposite direction, from the end.

------------------------------------------------------------------------------
(gdb) info proc stat
process 6680
Process: 6680
Exec file: (sd-pam
State: )
Parent process: 0
Process group: 0
Session id: 0
TTY: 0
TTY owner process group: 0
Flags: 0x0
Minor faults (no memory page): 0
Minor faults, children: 0
Major faults (memory page faults): 0
Major faults, children: 0
utime: 0
stime: 0
utime, children: 0
stime, children: 0
jiffies remaining in current time slice: 0
'nice' value: 0
jiffies until next timeout: 0
jiffies until next SIGALRM: 0
start time (jiffies since system boot): 0
Virtual memory size: 0
Resident set size: 0
rlim: 0
Start of text: 0x0
End of text: 0x0
Start of stack: 0x0

->


(gdb) info proc stat
process 6680
Process: 6680
Exec file: (sd-pam)
State: t
Parent process: 6678
Process group: 6678
Session id: 6678
TTY: 0
TTY owner process group: 18446744073709551615
Flags: 0x40406140
Minor faults (no memory page): 46
Minor faults, children: 0
Major faults (memory page faults): 7
Major faults, children: 0
utime: 0
stime: 0
utime, children: 0
stime, children: 0
jiffies remaining in current time slice: 20
'nice' value: 0
jiffies until next timeout: 1
jiffies until next SIGALRM: 0
start time (jiffies since system boot): 18568
Virtual memory size: 73768960
Resident set size: 554
rlim: 18446744073709551615
Start of text: 0x7f0294f7d000
End of text: 0x7f0295085ba3
Start of stack: 0x7fff3e302b30
------------------------------------------------------------------------------
+
------------------------------------------------------------------------------
(gdb) gcore ...
debug dump: n_fields=1 pr_sname=) ppid=0
->
debug dump: n_fields=6 pr_sname=t ppid=6678
Saved corefile ...
------------------------------------------------------------------------------

Maybe it would be worth a testcase.


Thanks,
Jan
gdb/
2014-02-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR gdb/16594
	* common/linux-osdata.c (linux_common_core_of_thread): Find the end of
	process name.
	(get_cores_used_by_process): New parameter num_cores, use it.
	(linux_xfer_osdata_processes): Pass num_cores to it.
	* linux-tdep.c (linux_info_proc, linux_fill_prpsinfo): Find the end of
	process name.

diff --git a/gdb/common/linux-osdata.c b/gdb/common/linux-osdata.c
index 805850c..37d78a0 100644
--- a/gdb/common/linux-osdata.c
+++ b/gdb/common/linux-osdata.c
@@ -98,10 +98,10 @@ linux_common_core_of_thread (ptid_t ptid)
 
   p = strchr (content, '(');
 
-  /* Skip ")".  */
+  /* Skip ")".  Handle also process names like "((sd-pam))".  */
   if (p != NULL)
     p = strchr (p, ')');
-  if (p != NULL)
+  while (p != NULL && *p != 0 && *p != ' ')
     p++;
 
   /* If the first field after program name has index 0, then core number is
@@ -258,11 +258,10 @@ get_process_owner (uid_t *owner, PID_T pid)
 }
 
 /* Find the CPU cores used by process PID and return them in CORES.
-   CORES points to an array of at least sysconf(_SC_NPROCESSOR_ONLN)
-   elements.  */
+   CORES points to an array of NUM_CORES elements.  */
 
 static int
-get_cores_used_by_process (PID_T pid, int *cores)
+get_cores_used_by_process (PID_T pid, int *cores, const int num_cores)
 {
   char taskdir[sizeof ("/proc/") + MAX_PID_T_STRLEN + sizeof ("/task") - 1];
   DIR *dir;
@@ -286,7 +285,7 @@ get_cores_used_by_process (PID_T pid, int *cores)
 	  core = linux_common_core_of_thread (ptid_build ((pid_t) pid,
 							  (pid_t) tid, 0));
 
-	  if (core >= 0)
+	  if (core >= 0 && core < num_cores)
 	    {
 	      ++cores[core];
 	      ++task_count;
@@ -350,7 +349,7 @@ linux_xfer_osdata_processes (gdb_byte *readbuf,
 
 	      /* Find CPU cores used by the process.  */
 	      cores = (int *) xcalloc (num_cores, sizeof (int));
-	      task_count = get_cores_used_by_process (pid, cores);
+	      task_count = get_cores_used_by_process (pid, cores, num_cores);
 	      cores_str = (char *) xcalloc (task_count, sizeof ("4294967295") + 1);
 
 	      for (i = 0; i < num_cores && task_count > 0; ++i)
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index bd1e5a2..24229bf 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -479,9 +479,12 @@ linux_info_proc (struct gdbarch *gdbarch, char *args,
 	      const char *ep = strchr (p, ')');
 	      if (ep != NULL)
 		{
+		  /* Handle also process names like "((sd-pam))".  */
+		  while (*ep != 0 && *ep != ' ')
+		    ep++;
 		  printf_filtered ("Exec file: %.*s\n",
-				   (int) (ep - p - 1), p + 1);
-		  p = ep + 1;
+				   (int) (ep - p - 2), p + 1);
+		  p = ep;
 		}
 	    }
 
@@ -1333,10 +1336,11 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p)
 
   /* Getting rid of the executable name, since we already have it.  We
      know that this name will be in parentheses, so we can safely look
-     for the close-paren.  */
+     for the close-paren.  Handle also process names like "((sd-pam))".  */
   while (*proc_stat != ')')
     ++proc_stat;
-  ++proc_stat;
+  while (*proc_stat != 0 && *proc_stat != ' ')
+    ++proc_stat;
 
   proc_stat = skip_spaces (proc_stat);
 

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