More Solaris procfs cleanup

Message ID yddzhwdfrz1.fsf@CeBiTec.Uni-Bielefeld.DE
State New
Headers show
Series
  • More Solaris procfs cleanup
Related show

Commit Message

Rainer Orth Sept. 19, 2018, 3:05 p.m.
This procfs.c (and friends) cleanup patch grew along a couple of lines:

* First I noticed that PR_MODEL_NATIVE is always defined now that
  Solaris 10 is the minimum supported version.

* Then there was a cleanup that I'd missed when removing support for
  !NEW_PROC_API, IRIX, and Tru64 UNIX: given that sysset_t is no longer
  dynamic, there's no need for the special sysset_t_alloc, but we can
  just use XNEW instead.

* Then I found one of those ARI warning mails on gdb-patches, discovered
  how to run it myself and fixed a large number of the warnings, among
  them all uses of sprintf.

  I had to silence the warnings in only 3 instances of the same issue,
  namely references to LDT in function names which are due to the
  libthread_db API.

* Even so, there were several formatting glitches, like braces around
  single statements in an if, which I chose to fix while I was at it.

The result has been tested on amd64-pc-solaris2.11 and
amd64-pc-solaris2.11.  Ok for master?

Thanks.
        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2018-07-05  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* proc-utils.h (PROC_CTL_WORD_TYPE): Remove.

	* procfs.c: Don't check for PR_MODEL_NATIVE definition.
	* sparc-sol2-nat.c: Likewise.  Remove Linux, __arch64__ references.
	* sol-thread.c (ps_pdmodel): Don't guard definition.

	* procfs.c: Fix formatting.

	* procfs.c (sysset_t_alloc): Remove.
	(create_procinfo): Use XNEW instead of sysset_t_alloc.
	(procfs_debug_inferior): Likewise.
	(procfs_set_exec_trap): Likewise.
	(proc_set_traced_sysentry): Don't allocate argp dynamically.
	(proc_set_traced_sysexit): Likewise.

	* procfs.c (create_procinfo): Use xsnprintf to fix ARI warning.
	(dead_procinfo): Likewise.
	(proc_warn): Likewise.
	(proc_error): Likewise.
	(proc_get_LDT_entry): Likewise.
	(do_attach): Likewise.
	(procfs_target::pid_to_str): Likewise.
	(iterate_over_mappings): Likewise.

	* procfs.c (create_procinfo): Fix ARI warning.
	(proc_get_status): Likewise.
	(proc_stop_process): Likewise.
	(proc_run_process): Likewise.
	(proc_kill): Likewise.
	(proc_get_LDT_entry): Likewise.
	(procfs_find_LDT_entry): Likewise.
	(proc_update_threads): Likewise.
	(proc_iterate_over_threads): Likewise.
	(do_attach): Likewise.
	(procfs_xfer_memory): Likewise.
	(invalidate_cache): Likewise.
	(procfs_target::resume): Likewise.
	(procfs_init_inferior): Likewise.
	(procfs_set_exec_trap): Likewise.
	(procfs_target::thread_alive): Likewise.
	(procfs_target::pid_to_exec_file): Likewise.
	(iterate_over_mappings): Likewise.
	(procfs_target::make_corefile_notes): Likewise.
	* sol-thread.c (sol_thread_target::thread_alive): Likewise.

	* procfs.c (procfs_find_LDT_entry): Silence ARI warning.
	(procfs_find_LDT_entry): Likewise.
	* sol-thread.c (ps_lgetLDT): Likewise.

Comments

Kevin Buettner Sept. 20, 2018, 5:29 p.m. | #1
On Wed, 19 Sep 2018 17:05:06 +0200
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> wrote:

> This procfs.c (and friends) cleanup patch grew along a couple of lines:

> 

> * First I noticed that PR_MODEL_NATIVE is always defined now that

>   Solaris 10 is the minimum supported version.

> 

> * Then there was a cleanup that I'd missed when removing support for

>   !NEW_PROC_API, IRIX, and Tru64 UNIX: given that sysset_t is no longer

>   dynamic, there's no need for the special sysset_t_alloc, but we can

>   just use XNEW instead.

> 

> * Then I found one of those ARI warning mails on gdb-patches, discovered

>   how to run it myself and fixed a large number of the warnings, among

>   them all uses of sprintf.

> 

>   I had to silence the warnings in only 3 instances of the same issue,

>   namely references to LDT in function names which are due to the

>   libthread_db API.

> 

> * Even so, there were several formatting glitches, like braces around

>   single statements in an if, which I chose to fix while I was at it.

> 

> The result has been tested on amd64-pc-solaris2.11 and

> amd64-pc-solaris2.11.  Ok for master?


This is okay.

Thanks for doing this cleanup.

Kevin

Patch

# HG changeset patch
# Parent  8ab09c9ba9277ba7c7f09517e2dc24d045f1cb73
More Solaris procfs cleanup

diff --git a/gdb/proc-utils.h b/gdb/proc-utils.h
--- a/gdb/proc-utils.h
+++ b/gdb/proc-utils.h
@@ -112,8 +112,4 @@  extern  void  procfs_note      (const ch
 
 /* Define the type (and more importantly the width) of the control
    word used to write to the /proc/PID/ctl file.  */
-#if defined (PROC_CTL_WORD_TYPE)
-typedef PROC_CTL_WORD_TYPE procfs_ctl_t;
-#else
 typedef long procfs_ctl_t;
-#endif
diff --git a/gdb/procfs.c b/gdb/procfs.c
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -141,7 +141,7 @@  public:
 
   bool info_proc (const char *, enum info_proc_what) override;
 
-#if defined(PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
+#if PR_MODEL_NATIVE == PR_MODEL_LP64
   int auxv_parse (gdb_byte **readptr,
 		  gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
     override;
@@ -163,7 +163,7 @@  public:
 
 static procfs_target the_procfs_target;
 
-#if defined (PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)
+#if PR_MODEL_NATIVE == PR_MODEL_LP64
 /* When GDB is built as 64-bit application on Solaris, the auxv data
    is presented in 64-bit format.  We need to provide a custom parser
    to handle that.  */
@@ -278,7 +278,6 @@  static void do_destroy_procinfo_cleanup 
 static void dead_procinfo (procinfo *p, const char *msg, int killp);
 static int open_procinfo_files (procinfo *p, int which);
 static void close_procinfo_files (procinfo *p);
-static sysset_t *sysset_t_alloc (procinfo *pi);
 
 static int iterate_over_mappings
   (procinfo *pi, find_memory_region_ftype child_func, void *data,
@@ -457,7 +456,8 @@  create_procinfo (int pid, int tid)
 {
   procinfo *pi, *parent = NULL;
 
-  if ((pi = find_procinfo (pid, tid)))
+  pi = find_procinfo (pid, tid);
+  if (pi != NULL)
     return pi;			/* Already exists, nothing to do.  */
 
   /* Find parent before doing malloc, to save having to cleanup.  */
@@ -471,19 +471,20 @@  create_procinfo (int pid, int tid)
   pi->pid = pid;
   pi->tid = tid;
 
-  pi->saved_entryset = sysset_t_alloc (pi);
-  pi->saved_exitset = sysset_t_alloc (pi);
+  pi->saved_entryset = XNEW (sysset_t);
+  pi->saved_exitset = XNEW(sysset_t);
 
   /* Chain into list.  */
   if (tid == 0)
     {
-      sprintf (pi->pathname, MAIN_PROC_NAME_FMT, pid);
+      xsnprintf (pi->pathname, sizeof (pi->pathname), MAIN_PROC_NAME_FMT, pid);
       pi->next = procinfo_list;
       procinfo_list = pi;
     }
   else
     {
-      sprintf (pi->pathname, "/proc/%d/lwp/%d", pid, tid);
+      xsnprintf (pi->pathname, sizeof (pi->pathname), "/proc/%d/lwp/%d",
+		 pid, tid);
       pi->next = parent->thread_list;
       parent->thread_list = pi;
     }
@@ -569,12 +570,10 @@  dead_procinfo (procinfo *pi, const char 
   char procfile[80];
 
   if (pi->pathname)
-    {
-      print_sys_errmsg (pi->pathname, errno);
-    }
+    print_sys_errmsg (pi->pathname, errno);
   else
     {
-      sprintf (procfile, "process %d", pi->pid);
+      xsnprintf (procfile, sizeof (procfile), "process %d", pi->pid);
       print_sys_errmsg (procfile, errno);
     }
   if (kill_p == KILL)
@@ -584,14 +583,6 @@  dead_procinfo (procinfo *pi, const char 
   error ("%s", msg);
 }
 
-/* Allocate and (partially) initialize a sysset_t struct.  */
-
-static sysset_t *
-sysset_t_alloc (procinfo *pi)
-{
-  return (sysset_t *) xmalloc (sizeof (sysset_t));
-}
-
 /* =================== END, STRUCT PROCINFO "MODULE" =================== */
 
 /* ===================  /proc  "MODULE" =================== */
@@ -619,14 +610,16 @@  static int proc_iterate_over_threads
 static void
 proc_warn (procinfo *pi, const char *func, int line)
 {
-  sprintf (errmsg, "procfs: %s line %d, %s", func, line, pi->pathname);
+  xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s",
+	     func, line, pi->pathname);
   print_sys_errmsg (errmsg, errno);
 }
 
 static void
 proc_error (procinfo *pi, const char *func, int line)
 {
-  sprintf (errmsg, "procfs: %s line %d, %s", func, line, pi->pathname);
+  xsnprintf (errmsg, sizeof (errmsg), "procfs: %s line %d, %s",
+	     func, line, pi->pathname);
   perror_with_name (errmsg);
 }
 
@@ -640,8 +633,7 @@  static int
 proc_get_status (procinfo *pi)
 {
   /* Status file descriptor is opened "lazily".  */
-  if (pi->status_fd == 0 &&
-      open_procinfo_files (pi, FD_STATUS) == 0)
+  if (pi->status_fd == 0 && open_procinfo_files (pi, FD_STATUS) == 0)
     {
       pi->status_valid = 0;
       return 0;
@@ -882,8 +874,7 @@  proc_stop_process (procinfo *pi)
   /* We might conceivably apply this operation to an LWP, and the
      LWP's ctl file descriptor might not be open.  */
 
-  if (pi->ctl_fd == 0 &&
-      open_procinfo_files (pi, FD_CTL) == 0)
+  if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
     return 0;
   else
     {
@@ -948,11 +939,8 @@  proc_run_process (procinfo *pi, int step
   /* We will probably have to apply this operation to individual
      threads, so make sure the control file descriptor is open.  */
 
-  if (pi->ctl_fd == 0 &&
-      open_procinfo_files (pi, FD_CTL) == 0)
-    {
-      return 0;
-    }
+  if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
+    return 0;
 
   runflags    = PRCFAULT;	/* Always clear current fault.  */
   if (step)
@@ -1055,20 +1043,16 @@  proc_set_traced_sysentry (procinfo *pi, 
   if (pi->tid != 0)
     pi = find_procinfo_or_die (pi->pid, 0);
 
-  struct gdb_proc_ctl_pcsentry {
+  struct {
     procfs_ctl_t cmd;
     /* Use char array to avoid alignment issues.  */
     char sysset[sizeof (sysset_t)];
-  } *argp;
-  int argp_size = sizeof (struct gdb_proc_ctl_pcsentry);
-
-  argp = (struct gdb_proc_ctl_pcsentry *) xmalloc (argp_size);
-
-  argp->cmd = PCSENTRY;
-  memcpy (&argp->sysset, sysset, sizeof (sysset_t));
-
-  win = (write (pi->ctl_fd, (char *) argp, argp_size) == argp_size);
-  xfree (argp);
+  } arg;
+
+  arg.cmd = PCSENTRY;
+  memcpy (&arg.sysset, sysset, sizeof (sysset_t));
+
+  win = (write (pi->ctl_fd, (char *) &arg, sizeof (arg)) == sizeof (arg));
 
   /* The above operation renders the procinfo's cached pstatus
      obsolete.  */
@@ -1097,16 +1081,12 @@  proc_set_traced_sysexit (procinfo *pi, s
     procfs_ctl_t cmd;
     /* Use char array to avoid alignment issues.  */
     char sysset[sizeof (sysset_t)];
-  } *argp;
-  int argp_size = sizeof (struct gdb_proc_ctl_pcsexit);
-
-  argp = (struct gdb_proc_ctl_pcsexit *) xmalloc (argp_size);
-
-  argp->cmd = PCSEXIT;
-  memcpy (&argp->sysset, sysset, sizeof (sysset_t));
-
-  win = (write (pi->ctl_fd, (char *) argp, argp_size) == argp_size);
-  xfree (argp);
+  } arg;
+
+  arg.cmd = PCSEXIT;
+  memcpy (&arg.sysset, sysset, sizeof (sysset_t));
+
+  win = (write (pi->ctl_fd, (char *) &arg, sizeof (arg)) == sizeof (arg));
 
   /* The above operation renders the procinfo's cached pstatus
      obsolete.  */
@@ -1441,9 +1421,7 @@  proc_set_gregs (procinfo *pi)
     return 0;			/* proc_get_regs has already warned.  */
 
   if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
-    {
-      return 0;
-    }
+    return 0;
   else
     {
       struct {
@@ -1477,9 +1455,7 @@  proc_set_fpregs (procinfo *pi)
     return 0;			/* proc_get_fpregs has already warned.  */
 
   if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
-    {
-      return 0;
-    }
+    return 0;
   else
     {
       struct {
@@ -1509,11 +1485,8 @@  proc_kill (procinfo *pi, int signo)
   /* We might conceivably apply this operation to an LWP, and the
      LWP's ctl file descriptor might not be open.  */
 
-  if (pi->ctl_fd == 0 &&
-      open_procinfo_files (pi, FD_CTL) == 0)
-    {
-      return 0;
-    }
+  if (pi->ctl_fd == 0 && open_procinfo_files (pi, FD_CTL) == 0)
+    return 0;
   else
     {
       procfs_ctl_t cmd[2];
@@ -1591,7 +1564,7 @@  proc_set_watchpoint (procinfo *pi, CORE_
    matching ssh struct (LDT entry).  */
 
 static struct ssd *
-proc_get_LDT_entry (procinfo *pi, int key)
+proc_get_LDT_entry (procinfo *pi, int key)	/* ARI: editCase function */
 {
   static struct ssd *ldt_entry = NULL;
   char pathname[MAX_PROC_NAME_SIZE];
@@ -1602,7 +1575,7 @@  proc_get_LDT_entry (procinfo *pi, int ke
     ldt_entry = XNEW (struct ssd);
 
   /* Open the file descriptor for the LDT table.  */
-  sprintf (pathname, "/proc/%d/ldt", pi->pid);
+  xsnprintf (pathname, sizeof (pathname), "/proc/%d/ldt", pi->pid);
   scoped_fd fd (open_with_retry (pathname, O_RDONLY));
   if (fd.get () < 0)
     {
@@ -1614,10 +1587,10 @@  proc_get_LDT_entry (procinfo *pi, int ke
   while (read (fd.get (), ldt_entry, sizeof (struct ssd))
 	 == sizeof (struct ssd))
     {
-      if (ldt_entry->sel == 0 &&
-	  ldt_entry->bo  == 0 &&
-	  ldt_entry->acc1 == 0 &&
-	  ldt_entry->acc2 == 0)
+      if (ldt_entry->sel == 0
+	  && ldt_entry->bo  == 0
+	  && ldt_entry->acc1 == 0
+	  && ldt_entry->acc2 == 0)
 	break;	/* end of table */
       /* If key matches, return this entry.  */
       if (ldt_entry->sel == key)
@@ -1630,21 +1603,23 @@  proc_get_LDT_entry (procinfo *pi, int ke
 /* Returns the pointer to the LDT entry of PTID.  */
 
 struct ssd *
-procfs_find_LDT_entry (ptid_t ptid)
+procfs_find_LDT_entry (ptid_t ptid)	/* ARI: editCase function */
 {
   gdb_gregset_t *gregs;
   int            key;
   procinfo      *pi;
 
   /* Find procinfo for the lwp.  */
-  if ((pi = find_procinfo (ptid.pid (), ptid.lwp ())) == NULL)
+  pi = find_procinfo (ptid.pid (), ptid.lwp ());
+  if (pi == NULL)
     {
       warning (_("procfs_find_LDT_entry: could not find procinfo for %d:%ld."),
 	       ptid.pid (), ptid.lwp ());
       return NULL;
     }
   /* get its general registers.  */
-  if ((gregs = proc_get_gregs (pi)) == NULL)
+  gregs = proc_get_gregs (pi);
+  if (gregs == NULL)
     {
       warning (_("procfs_find_LDT_entry: could not read gregs for %d:%ld."),
 	       ptid.pid (), ptid.lwp ());
@@ -1759,7 +1734,8 @@  proc_update_threads (procinfo *pi)
     if (direntry->d_name[0] != '.')		/* skip '.' and '..' */
       {
 	lwpid = atoi (&direntry->d_name[0]);
-	if ((thread = create_procinfo (pi->pid, lwpid)) == NULL)
+	thread = create_procinfo (pi->pid, lwpid);
+	if (thread == NULL)
 	  proc_error (pi, "update_threads, create_procinfo", __LINE__);
       }
   pi->threads_valid = 1;
@@ -1798,7 +1774,8 @@  proc_iterate_over_threads (procinfo *pi,
   for (thread = pi->thread_list; thread != NULL; thread = next)
     {
       next = thread->next;	/* In case thread is destroyed.  */
-      if ((retval = (*func) (pi, thread, ptr)) != 0)
+      retval = (*func) (pi, thread, ptr);
+      if (retval != 0)
 	break;
     }
 
@@ -1847,7 +1824,7 @@  procfs_debug_inferior (procinfo *pi)
 
 
   /* Register to trace the 'exit' system call (on entry).  */
-  traced_syscall_entries = sysset_t_alloc (pi);
+  traced_syscall_entries = XNEW (sysset_t);
   premptyset (traced_syscall_entries);
   praddset (traced_syscall_entries, SYS_exit);
   praddset (traced_syscall_entries, SYS_lwp_exit);
@@ -1863,7 +1840,7 @@  procfs_debug_inferior (procinfo *pi)
      names.  On the SGI, for example, there is no SYS_exec, but there
      *is* a SYS_execv.  So, we try to account for that.  */
 
-  traced_syscall_exits = sysset_t_alloc (pi);
+  traced_syscall_exits = XNEW (sysset_t);
   premptyset (traced_syscall_exits);
 #ifdef SYS_exec
   praddset (traced_syscall_exits, SYS_exec);
@@ -1942,14 +1919,16 @@  do_attach (ptid_t ptid)
   int fail;
   int lwpid;
 
-  if ((pi = create_procinfo (ptid.pid (), 0)) == NULL)
+  pi = create_procinfo (ptid.pid (), 0);
+  if (pi == NULL)
     perror (_("procfs: out of memory in 'attach'"));
 
   if (!open_procinfo_files (pi, FD_CTL))
     {
       fprintf_filtered (gdb_stderr, "procfs:%d -- ", __LINE__);
-      sprintf (errmsg, "do_attach: couldn't open /proc file for process %d",
-	       ptid.pid ());
+      xsnprintf (errmsg, sizeof (errmsg),
+		 "do_attach: couldn't open /proc file for process %d",
+		 ptid.pid ());
       dead_procinfo (pi, errmsg, NOKILL);
     }
 
@@ -1985,7 +1964,8 @@  do_attach (ptid_t ptid)
   if (!proc_get_held_signals    (pi, &pi->saved_sighold))
     dead_procinfo (pi, "do_attach: couldn't save held signals.", NOKILL);
 
-  if ((fail = procfs_debug_inferior (pi)) != 0)
+  fail = procfs_debug_inferior (pi);
+  if (fail != 0)
     dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
 
   inf = current_inferior ();
@@ -2228,8 +2208,8 @@  wait_again:
 	pi->status_valid = 0;	/* re-read again, IMMEDIATELY...  */
 #endif
       /* If child is not stopped, wait for it to stop.  */
-      if (!(proc_flags (pi) & (PR_STOPPED | PR_ISTOP)) &&
-	  !proc_wait_for_stop (pi))
+      if (!(proc_flags (pi) & (PR_STOPPED | PR_ISTOP))
+	  && !proc_wait_for_stop (pi))
 	{
 	  /* wait_for_stop failed: has the child terminated?  */
 	  if (errno == ENOENT)
@@ -2353,8 +2333,10 @@  wait_again:
 
 		    long i, nsysargs, *sysargs;
 
-		    if ((nsysargs = proc_nsysarg (pi)) > 0 &&
-			(sysargs  = proc_sysargs (pi)) != NULL)
+		    nsysargs = proc_nsysarg (pi);
+		    sysargs  = proc_sysargs (pi);
+
+		    if (nsysargs > 0 && sysargs != NULL)
 		      {
 			printf_filtered (_("%ld syscall arguments:\n"),
 					 nsysargs);
@@ -2437,8 +2419,10 @@  wait_again:
 
 		    long i, nsysargs, *sysargs;
 
-		    if ((nsysargs = proc_nsysarg (pi)) > 0 &&
-			(sysargs  = proc_sysargs (pi)) != NULL)
+		    nsysargs = proc_nsysarg (pi);
+		    sysargs = proc_sysargs (pi);
+
+		    if (nsysargs > 0 && sysargs != NULL)
 		      {
 			printf_filtered (_("%ld syscall arguments:\n"),
 					 nsysargs);
@@ -2526,9 +2510,9 @@  wait_again:
 	      }
 	      /* Got this far without error: If retval isn't in the
 		 threads database, add it.  */
-	      if (retval.pid () > 0 &&
-		  retval != inferior_ptid &&
-		  !in_thread_list (retval))
+	      if (retval.pid () > 0
+		  && retval != inferior_ptid
+		  && !in_thread_list (retval))
 		{
 		  /* We have a new thread.  We need to add it both to
 		     GDB's list and to our own.  If we don't create a
@@ -2594,8 +2578,7 @@  procfs_xfer_memory (gdb_byte *readbuf, c
 
   /* Find procinfo for main process.  */
   pi = find_procinfo_or_die (inferior_ptid.pid (), 0);
-  if (pi->as_fd == 0 &&
-      open_procinfo_files (pi, FD_AS) == 0)
+  if (pi->as_fd == 0 && open_procinfo_files (pi, FD_AS) == 0)
     {
       proc_warn (pi, "xfer_memory, open_proc_files", __LINE__);
       return TARGET_XFER_E_IO;
@@ -2643,15 +2626,13 @@  invalidate_cache (procinfo *parent, proc
 
 #if 0
   if (pi->gregs_dirty)
-    if (parent == NULL ||
-	proc_get_current_thread (parent) != pi->tid)
+    if (parent == NULL || proc_get_current_thread (parent) != pi->tid)
       if (!proc_set_gregs (pi))	/* flush gregs cache */
 	proc_warn (pi, "target_resume, set_gregs",
 		   __LINE__);
   if (gdbarch_fp0_regnum (target_gdbarch ()) >= 0)
     if (pi->fpregs_dirty)
-      if (parent == NULL ||
-	  proc_get_current_thread (parent) != pi->tid)
+      if (parent == NULL || proc_get_current_thread (parent) != pi->tid)
 	if (!proc_set_fpregs (pi))	/* flush fpregs cache */
 	  proc_warn (pi, "target_resume, set_fpregs",
 		     __LINE__);
@@ -2736,8 +2717,7 @@  procfs_target::resume (ptid_t ptid, int 
   errno = 0;
 
   /* Convert signal to host numbering.  */
-  if (signo == 0 ||
-      (signo == GDB_SIGNAL_STOP && pi->ignore_next_sigstop))
+  if (signo == 0 || (signo == GDB_SIGNAL_STOP && pi->ignore_next_sigstop))
     native_signo = 0;
   else
     native_signo = gdb_signal_to_host (signo);
@@ -2903,7 +2883,8 @@  procfs_init_inferior (struct target_ops 
   if (!target_is_pushed (ops))
     push_target (ops);
 
-  if ((pi = create_procinfo (pid, 0)) == NULL)
+  pi = create_procinfo (pid, 0);
+  if (pi == NULL)
     perror (_("procfs: out of memory in 'init_inferior'"));
 
   if (!open_procinfo_files (pi, FD_CTL))
@@ -2922,8 +2903,7 @@  procfs_init_inferior (struct target_ops 
     */
 
   /* If not stopped yet, wait for it to stop.  */
-  if (!(proc_flags (pi) & PR_STOPPED) &&
-      !(proc_wait_for_stop (pi)))
+  if (!(proc_flags (pi) & PR_STOPPED) && !(proc_wait_for_stop (pi)))
     dead_procinfo (pi, "init_inferior: wait_for_stop failed", KILL);
 
   /* Save some of the /proc state to be restored if we detach.  */
@@ -2940,7 +2920,8 @@  procfs_init_inferior (struct target_ops 
   if (!proc_get_traced_sysexit  (pi, pi->saved_exitset))
     proc_error (pi, "init_inferior, get_traced_sysexit", __LINE__);
 
-  if ((fail = procfs_debug_inferior (pi)) != 0)
+  fail = procfs_debug_inferior (pi);
+  if (fail != 0)
     proc_error (pi, "init_inferior (procfs_debug_inferior)", fail);
 
   /* FIXME: logically, we should really be turning OFF run-on-last-close,
@@ -2985,7 +2966,8 @@  procfs_set_exec_trap (void)
   procinfo *pi;
   sysset_t *exitset;
 
-  if ((pi = create_procinfo (getpid (), 0)) == NULL)
+  pi = create_procinfo (getpid (), 0);
+  if (pi == NULL)
     perror_with_name (_("procfs: create_procinfo failed in child."));
 
   if (open_procinfo_files (pi, FD_CTL) == 0)
@@ -3003,7 +2985,7 @@  procfs_set_exec_trap (void)
      names.  On the SGI, for example, there is no SYS_exec, but there
      *is* a SYS_execv.  So, we try to account for that.  */
 
-  exitset = sysset_t_alloc (pi);
+  exitset = XNEW (sysset_t);
   premptyset (exitset);
 #ifdef SYS_exec
   praddset (exitset, SYS_exec);
@@ -3106,7 +3088,8 @@  procfs_target::thread_alive (ptid_t ptid
   proc    = ptid.pid ();
   thread  = ptid.lwp ();
   /* If I don't know it, it ain't alive!  */
-  if ((pi = find_procinfo (proc, thread)) == NULL)
+  pi = find_procinfo (proc, thread);
+  if (pi == NULL)
     return false;
 
   /* If I can't get its status, it ain't alive!
@@ -3130,9 +3113,9 @@  procfs_target::pid_to_str (ptid_t ptid)
   static char buf[80];
 
   if (ptid.lwp () == 0)
-    sprintf (buf, "process %d", ptid.pid ());
+    xsnprintf (buf, sizeof (buf), "process %d", ptid.pid ());
   else
-    sprintf (buf, "LWP %ld", ptid.lwp ());
+    xsnprintf (buf, sizeof (buf), "LWP %ld", ptid.lwp ());
 
   return buf;
 }
@@ -3147,7 +3130,7 @@  procfs_target::pid_to_exec_file (int pid
   char name[PATH_MAX];
 
   /* Solaris 11 introduced /proc/<proc-id>/execname.  */
-  xsnprintf (name, PATH_MAX, "/proc/%d/execname", pid);
+  xsnprintf (name, sizeof (name), "/proc/%d/execname", pid);
   scoped_fd fd (open (name, O_RDONLY));
   if (fd.get () < 0 || read (fd.get (), buf, PATH_MAX - 1) < 0)
     {
@@ -3155,7 +3138,7 @@  procfs_target::pid_to_exec_file (int pid
 	 Solaris 10.  */
       ssize_t len;
 
-      xsnprintf (name, PATH_MAX, "/proc/%d/path/a.out", pid);
+      xsnprintf (name, sizeof (name), "/proc/%d/path/a.out", pid);
       len = readlink (name, buf, PATH_MAX - 1);
       if (len <= 0)
 	strcpy (buf, name);
@@ -3256,13 +3239,9 @@  procfs_target::stopped_by_watchpoint ()
   pi = find_procinfo_or_die (inferior_ptid.pid (), 0);
 
   if (proc_flags (pi) & (PR_STOPPED | PR_ISTOP))
-    {
-      if (proc_why (pi) == PR_FAULTED)
-	{
-	  if (proc_what (pi) == FLTWATCH)
-	    return true;
-	}
-    }
+    if (proc_why (pi) == PR_FAULTED)
+      if (proc_what (pi) == FLTWATCH)
+	return true;
   return false;
 }
 
@@ -3288,20 +3267,16 @@  procfs_target::insert_watchpoint (CORE_A
 {
   if (!target_have_steppable_watchpoint
       && !gdbarch_have_nonsteppable_watchpoint (target_gdbarch ()))
-    {
-      /* When a hardware watchpoint fires off the PC will be left at
-	 the instruction following the one which caused the
-	 watchpoint.  It will *NOT* be necessary for GDB to step over
-	 the watchpoint.  */
-      return procfs_set_watchpoint (inferior_ptid, addr, len, type, 1);
-    }
+    /* When a hardware watchpoint fires off the PC will be left at
+       the instruction following the one which caused the
+       watchpoint.  It will *NOT* be necessary for GDB to step over
+       the watchpoint.  */
+    return procfs_set_watchpoint (inferior_ptid, addr, len, type, 1);
   else
-    {
-      /* When a hardware watchpoint fires off the PC will be left at
-	 the instruction which caused the watchpoint.  It will be
-	 necessary for GDB to step over the watchpoint.  */
-      return procfs_set_watchpoint (inferior_ptid, addr, len, type, 0);
-    }
+    /* When a hardware watchpoint fires off the PC will be left at
+       the instruction which caused the watchpoint.  It will be
+       necessary for GDB to step over the watchpoint.  */
+    return procfs_set_watchpoint (inferior_ptid, addr, len, type, 0);
 }
 
 int
@@ -3354,7 +3329,7 @@  iterate_over_mappings (procinfo *pi, fin
   /* Get the number of mappings, allocate space,
      and read the mappings into prmaps.  */
   /* Open map fd.  */
-  sprintf (pathname, "/proc/%d/map", pi->pid);
+  xsnprintf (pathname, sizeof (pathname), "/proc/%d/map", pi->pid);
 
   scoped_fd map_fd (open (pathname, O_RDONLY));
   if (map_fd.get () < 0)
@@ -3372,8 +3347,11 @@  iterate_over_mappings (procinfo *pi, fin
     proc_error (pi, "iterate_over_mappings (read)", __LINE__);
 
   for (prmap = prmaps; nmap > 0; prmap++, nmap--)
-    if ((funcstat = (*func) (prmap, child_func, data)) != 0)
-      return funcstat;
+    {
+      funcstat = (*func) (prmap, child_func, data);
+      if (funcstat != 0)
+	return funcstat;
+    }
 
   return 0;
 }
@@ -3579,9 +3557,7 @@  procfs_target::info_proc (const char *ar
     }
 
   if (mappings)
-    {
-      info_proc_mappings (process, 0);
-    }
+    info_proc_mappings (process, 0);
 
   do_cleanups (old_chain);
 
@@ -3816,8 +3792,9 @@  procfs_target::make_corefile_notes (bfd 
       psargs[sizeof (psargs) - 1] = 0;
 
       inf_args = get_inferior_args ();
-      if (inf_args && *inf_args &&
-	  strlen (inf_args) < ((int) sizeof (psargs) - (int) strlen (psargs)))
+      if (inf_args && *inf_args
+	  && (strlen (inf_args)
+	      < ((int) sizeof (psargs) - (int) strlen (psargs))))
 	{
 	  strncat (psargs, " ",
 		   sizeof (psargs) - strlen (psargs));
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -705,9 +705,11 @@  sol_thread_target::thread_alive (ptid_t 
       int pid;
 
       pid = ptid.tid ();
-      if ((val = p_td_ta_map_id2thr (main_ta, pid, &th)) != TD_OK)
+      val = p_td_ta_map_id2thr (main_ta, pid, &th);
+      if (val != TD_OK)
 	return false;		/* Thread not found.  */
-      if ((val = p_td_thr_validate (&th)) != TD_OK)
+      val = p_td_thr_validate (&th);
+      if (val != TD_OK)
 	return false;		/* Thread not valid.  */
       return true;		/* Known thread.  */
     }
@@ -943,7 +945,6 @@  ps_lsetfpregs (struct ps_prochandle *ph,
   return PS_OK;
 }
 
-#ifdef PR_MODEL_LP64
 /* Identify process as 32-bit or 64-bit.  At the moment we're using
    BFD to do this.  There might be a more Solaris-specific
    (e.g. procfs) method, but this ought to work.  */
@@ -960,7 +961,6 @@  ps_pdmodel (struct ps_prochandle *ph, in
 
   return PS_OK;
 }
-#endif /* PR_MODEL_LP64 */
 
 #if (defined(__i386__) || defined(__x86_64__)) && defined (sun)
 
@@ -970,8 +970,7 @@  ps_pdmodel (struct ps_prochandle *ph, in
    of libthread_db would fail because of ps_lgetLDT being undefined.  */
 
 ps_err_e
-ps_lgetLDT (struct ps_prochandle *ph, lwpid_t lwpid,
-	    struct ssd *pldt)
+ps_lgetLDT (struct ps_prochandle *ph, lwpid_t lwpid, struct ssd *pldt)	/* ARI: editCase function */
 {
   /* NOTE: only used on Solaris, therefore OK to refer to procfs.c.  */
   struct ssd *ret;
diff --git a/gdb/sparc-sol2-nat.c b/gdb/sparc-sol2-nat.c
--- a/gdb/sparc-sol2-nat.c
+++ b/gdb/sparc-sol2-nat.c
@@ -40,16 +40,10 @@ 
    PR_MODEL_LP64, we know that GDB is being compiled as a 64-bit
    program.
 
-   GNU/Linux uses the same formats as Solaris for its core files (but
-   not for ptrace(2)).  The GNU/Linux headers don't define
-   PR_MODEL_NATIVE though.  Therefore we rely on the __arch64__ define
-   provided by GCC to determine the appropriate data model.
-
    Note that a 32-bit GDB won't be able to debug a 64-bit target
    process using /proc on Solaris.  */
 
-#if (defined (__arch64__) || \
-     (defined (PR_MODEL_NATIVE) && (PR_MODEL_NATIVE == PR_MODEL_LP64)))
+#if PR_MODEL_NATIVE == PR_MODEL_LP64
 
 #include "sparc64-tdep.h"