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 9/9]#2 optional: #if MAX_SIGINFO_SIZE > 0 protection


Hi,

this patch brings two benefits:

 * Some mistakes of tdep/gdbarch/siginfo_t code get caught already during
   compilation.

 * Some dead code gets eliminated.  Even with LTO there are some little
   needless calls done otherwise.

But AFAIK GDB tries to avoid any conditional compilations so the benefits may
not be worth the code complication.

I would personally apply the patch but I do not mind much.


Thanks,
Jan


gdb/
2010-08-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* i386-linux-nat.c
	(i386_linux_resume) <target_signal_siginfo_p (&signal)>:
	Conditionalize it by MAX_SIGINFO_SIZE > 0.
	* linux-nat.c (linux_nat_resume) <lp->siginfo.si_signo != 0>
	(linux_handle_extended_wait) <siginfo.si_signo != 0>
	(linux_nat_wait_1)
	<lp->siginfo.si_signo != 0 && TARGET_WAITKIND_USES_SIG>
	<siginfo.si_signo != 0>
	<siginfo.si_signo != 0 && TARGET_WAITKIND_USES_SIG>: Likewise.
	(linux_xfer_siginfo): Return -1 on MAX_SIGINFO_SIZE == 0.
	* linux-tdep.c (linux_gdbarch_data_handle, struct linux_gdbarch_data)
	(init_linux_gdbarch_data, get_linux_gdbarch_data)
	(linux_get_siginfo_type)
	(_initialize_linux_tdep) <linux_gdbarch_data_handle assignment>:
	Conditionalize it by MAX_SIGINFO_SIZE > 0.
	* linux-tdep.h (linux_get_siginfo_type): Likewise.
	* rs6000-nat.c (rs6000_wait) <siginfo>
	(rs6000_wait) <TARGET_WAITKIND_USES_SIG && ptrace>: Likewise.
	* spu-linux-nat.c (spu_child_wait) <siginfo>
	(spu_child_wait) <TARGET_WAITKIND_USES_SIG && ptrace>: Likewise.
	* target.c (target_signal_siginfo_p, target_signal_siginfo_len)
	(target_signal_siginfo_get, target_signal_siginfo_set): Conditionalize
	out completely their compilation when MAX_SIGINFO_SIZE == 0.
	* target.h (target_signal_siginfo_p, target_signal_siginfo_len)
	(target_signal_siginfo_get, target_signal_siginfo_set): Conditionalize
	out completely the declarations compilation when MAX_SIGINFO_SIZE ==
	0.

--- a/gdb/i386-linux-nat.c
+++ b/gdb/i386-linux-nat.c
@@ -896,6 +896,7 @@ i386_linux_resume (struct target_ops *ops,
 	}
     }
 
+#if MAX_SIGINFO_SIZE > 0
   if (target_signal_siginfo_p (&signal))
     {
       struct gdbarch *gdbarch;
@@ -911,6 +912,7 @@ i386_linux_resume (struct target_ops *ops,
 	  != 0)
 	perror_with_name (("ptrace (PTRACE_SETSIGINFO)"));
     }
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
   if (ptrace (request, pid, 0, target_signal_to_host (signal)) == -1)
     perror_with_name (("ptrace"));
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1936,6 +1936,7 @@ linux_nat_resume (struct target_ops *ops,
       inf = find_inferior_pid (ptid_get_pid (lp->ptid));
       gdb_assert (inf);
       saved_signo = target_signal_from_host (WSTOPSIG (lp->status));
+#if MAX_SIGINFO_SIZE > 0
       if (lp->siginfo.si_signo != 0)
 	{
 	  struct gdbarch *gdbarch;
@@ -1945,6 +1946,7 @@ linux_nat_resume (struct target_ops *ops,
 	  siginfo_fixup (&lp->siginfo, inf_siginfo, 0, gdbarch);
 	  target_signal_siginfo_set (&saved_signo, gdbarch, inf_siginfo);
 	}
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
       /* Defer to common code if we're gaining control of the
 	 inferior.  */
@@ -2373,6 +2375,7 @@ linux_handle_extended_wait (struct lwp_info *lp, int status,
 	      else
 		{
 		  signo = target_signal_from_host (WSTOPSIG (status));
+#if MAX_SIGINFO_SIZE > 0
 		  if (siginfo.si_signo != 0)
 		    {
 		      struct gdbarch *gdbarch;
@@ -2383,6 +2386,7 @@ linux_handle_extended_wait (struct lwp_info *lp, int status,
 		      target_signal_siginfo_set (&signo, gdbarch,
 						 inf_siginfo);
 		    }
+#endif /* MAX_SIGINFO_SIZE > 0 */
 		}
 
 	      linux_ops->to_resume (linux_ops, pid_to_ptid (new_pid),
@@ -3617,6 +3621,7 @@ retry:
 		  /* Store the pending event in the waitstatus as
 		     well, because W_EXITCODE(0,0) == 0.  */
 		  store_waitstatus (&lp->waitstatus, lp->status);
+#if MAX_SIGINFO_SIZE > 0
 		  if (lp->siginfo.si_signo != 0
 		      && TARGET_WAITKIND_USES_SIG (lp->waitstatus.kind))
 		    {
@@ -3629,6 +3634,7 @@ retry:
 		      target_signal_siginfo_set (&lp->waitstatus.value.sig,
 						 gdbarch, inf_siginfo);
 		    }
+#endif /* MAX_SIGINFO_SIZE > 0 */
 		}
 
 	      /* Keep looking.  */
@@ -3713,6 +3719,7 @@ retry:
       struct inferior *inf;
 
       signo = target_signal_from_host (WSTOPSIG (status));
+#if MAX_SIGINFO_SIZE > 0
       if (siginfo.si_signo != 0)
 	{
 	  struct gdbarch *gdbarch;
@@ -3722,6 +3729,7 @@ retry:
 	  siginfo_fixup (&siginfo, inf_siginfo, 0, gdbarch);
 	  target_signal_siginfo_set (&signo, gdbarch, inf_siginfo);
 	}
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
       inf = find_inferior_pid (ptid_get_pid (lp->ptid));
       gdb_assert (inf);
@@ -3829,6 +3837,7 @@ retry:
   else
     {
       store_waitstatus (ourstatus, status);
+#if MAX_SIGINFO_SIZE > 0
       if (siginfo.si_signo != 0 && TARGET_WAITKIND_USES_SIG (ourstatus->kind))
 	{
 	  struct gdbarch *gdbarch;
@@ -3839,6 +3848,7 @@ retry:
 	  target_signal_siginfo_set (&ourstatus->value.sig, gdbarch,
 				     inf_siginfo);
 	}
+#endif /* MAX_SIGINFO_SIZE > 0 */
     }
 
   if (debug_linux_nat_async)
@@ -4069,6 +4079,9 @@ linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
                     const char *annex, gdb_byte *readbuf,
 		    const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
 {
+#if MAX_SIGINFO_SIZE == 0
+  return -1;
+#else /* MAX_SIGINFO_SIZE > 0 */
   gdb_byte *siginfop;
   size_t siginfop_len;
   struct gdbarch *gdbarch;
@@ -4096,6 +4109,7 @@ linux_xfer_siginfo (struct target_ops *ops, enum target_object object,
     memcpy (siginfop + offset, writebuf, len);
 
   return len;
+#endif /* MAX_SIGINFO_SIZE > 0 */
 }
 
 static LONGEST
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -25,6 +25,8 @@
 #include "elf/common.h"
 #include "inferior.h"
 
+#if MAX_SIGINFO_SIZE > 0
+
 static struct gdbarch_data *linux_gdbarch_data_handle;
 
 struct linux_gdbarch_data
@@ -166,6 +168,8 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
   return siginfo_type;
 }
 
+#endif /* MAX_SIGINFO_SIZE > 0 */
+
 int
 linux_has_shared_address_space (void)
 {
@@ -209,6 +213,8 @@ linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 void
 _initialize_linux_tdep (void)
 {
+#if MAX_SIGINFO_SIZE > 0
   linux_gdbarch_data_handle =
     gdbarch_data_register_post_init (init_linux_gdbarch_data);
+#endif /* MAX_SIGINFO_SIZE > 0 */
 }
--- a/gdb/linux-tdep.h
+++ b/gdb/linux-tdep.h
@@ -20,7 +20,9 @@
 #ifndef LINUX_TDEP_H
 #define LINUX_TDEP_H
 
+#if MAX_SIGINFO_SIZE > 0
 struct type *linux_get_siginfo_type (struct gdbarch *);
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
 extern void linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch);
 
--- a/gdb/rs6000-nat.c
+++ b/gdb/rs6000-nat.c
@@ -572,10 +572,13 @@ rs6000_wait (struct target_ops *ops,
   /* A normal waitstatus.  Let the usual macros deal with it.  */
   else
     {
+#if MAX_SIGINFO_SIZE > 0
       siginfo_t siginfo;
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
       store_waitstatus (ourstatus, status);
 
+#if MAX_SIGINFO_SIZE > 0
       /* We could also use waitid.  */
       if (TARGET_WAITKIND_USES_SIG (ourstatus->kind)
 	  && (ptrace (PTRACE_GETSIGINFO, pid, (PTRACE_TYPE_ARG3) 0, &siginfo)
@@ -589,6 +592,7 @@ rs6000_wait (struct target_ops *ops,
 	  target_signal_siginfo_set (&ourstatus->value.sig, gdbarch,
 				     inf_siginfo);
 	}
+#endif /* MAX_SIGINFO_SIZE > 0 */
     }
 
   return pid_to_ptid (pid);
--- a/gdb/spu-linux-nat.c
+++ b/gdb/spu-linux-nat.c
@@ -432,7 +432,9 @@ spu_child_wait (struct target_ops *ops,
   int save_errno;
   int status;
   pid_t pid;
+#if MAX_SIGINFO_SIZE > 0
   siginfo_t siginfo;
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
   do
     {
@@ -471,6 +473,7 @@ spu_child_wait (struct target_ops *ops,
 
   store_waitstatus (ourstatus, status);
 
+#if MAX_SIGINFO_SIZE > 0
   /* We could also use waitid.  */
   if (TARGET_WAITKIND_USES_SIG (ourstatus->kind)
       && ptrace (PTRACE_GETSIGINFO, ret, (PTRACE_TYPE_ARG3) 0, &siginfo) == 0)
@@ -482,6 +485,7 @@ spu_child_wait (struct target_ops *ops,
       siginfo_fixup (&siginfo, inf_siginfo, 0, gdbarch);
       target_signal_siginfo_set (&ourstatus->value.sig, gdbarch, inf_siginfo);
     }
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
   return pid_to_ptid (pid);
 }
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2985,23 +2985,17 @@ store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
     }
 }
 
+#if MAX_SIGINFO_SIZE > 0
+
 int
 target_signal_siginfo_p (const target_signal_t *sigp)
 {
-#if MAX_SIGINFO_SIZE == 0
-  return 0;
-#else /* MAX_SIGINFO_SIZE > 0 */
   return sigp->siginfo_gdbarch != NULL;
-#endif /* MAX_SIGINFO_SIZE > 0 */
 }
 
 size_t
 target_signal_siginfo_len (struct gdbarch *siginfo_gdbarch)
 {
-#if MAX_SIGINFO_SIZE == 0
-  gdb_assert_not_reached ("no siginfo target is configured");
-#else /* MAX_SIGINFO_SIZE > 0 */
-
   gdb_assert (siginfo_gdbarch != NULL);
   
   if (gdbarch_get_siginfo_type_p (siginfo_gdbarch))
@@ -3030,23 +3024,17 @@ target_signal_siginfo_len (struct gdbarch *siginfo_gdbarch)
 		  gdbarch_bfd_arch_info (siginfo_gdbarch)->printable_name);
 
 #endif /* ! HAVE_SIGINFO_T */
-
-#endif /* MAX_SIGINFO_SIZE > 0 */
 }
 
 void *
 target_signal_siginfo_get (target_signal_t *sigp,
 			   struct gdbarch *siginfo_gdbarch)
 {
-#if MAX_SIGINFO_SIZE == 0
-  gdb_assert_not_reached ("no siginfo target is configured");
-#else /* MAX_SIGINFO_SIZE > 0 */
   gdb_assert (sigp->siginfo_gdbarch != NULL);
   gdb_assert (siginfo_gdbarch != NULL);
   gdb_assert (siginfo_gdbarch == sigp->siginfo_gdbarch);
 
   return sigp->siginfo;
-#endif /* MAX_SIGINFO_SIZE > 0 */
 }
 
 void
@@ -3054,7 +3042,6 @@ target_signal_siginfo_set (target_signal_t *sig,
 			   struct gdbarch *siginfo_gdbarch,
 			   const void *siginfo)
 {
-#if MAX_SIGINFO_SIZE > 0
   size_t len;
 
   gdb_assert (siginfo != NULL);
@@ -3071,9 +3058,10 @@ target_signal_siginfo_set (target_signal_t *sig,
 
   sig->siginfo_gdbarch = siginfo_gdbarch;
   memcpy (sig->siginfo, siginfo, len);
-#endif /* MAX_SIGINFO_SIZE > 0 */
 }
 
+#endif /* MAX_SIGINFO_SIZE > 0 */
+
 /* Convert a normal process ID to a string.  Returns the string in a
    static buffer.  */
 
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1592,6 +1592,7 @@ extern int remote_timeout;
 /* This is for native targets which use a unix/POSIX-style waitstatus.  */
 extern void store_waitstatus (struct target_waitstatus *, int);
 
+#if MAX_SIGINFO_SIZE > 0
 extern int target_signal_siginfo_p (const target_signal_t *sigp);
 extern size_t target_signal_siginfo_len (struct gdbarch *siginfo_gdbarch);
 extern void *target_signal_siginfo_get (target_signal_t *sigp,
@@ -1599,6 +1600,7 @@ extern void *target_signal_siginfo_get (target_signal_t *sigp,
 extern void target_signal_siginfo_set (target_signal_t *sigp,
 				       struct gdbarch *siginfo_gdbarch,
 				       const void *siginfo);
+#endif /* MAX_SIGINFO_SIZE > 0 */
 
 /* These are in common/signals.c, but they're only used by gdb.  */
 extern target_signal_t default_target_signal_from_host (struct gdbarch *,


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