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]

Re: [RFA v2 10/17] C++ify mi_parse


On 04/12/2017 07:05 PM, Tom Tromey wrote:
> Pedro> Thanks.  Totally fine with me.  If you prefer, using in-class
> Pedro> initialization is also fine.  (We've been using it more in recent
> Pedro> patches.)
> 
> I just left it as-is, but not for any good reason.

That's totally fine with me.

FYI, I just now tried the hack below against master, and
that caught a few other cases that shouldn't have been
using memset for initialization.

struct bp_location, struct inferior, struct btrace_insn
$ make -k 2>&1 | grep "no matching.*pod_only_memset"
src/gdb/inferior.c:132:32: error: no matching function for call to ‘pod_only_memset(inferior*&, int, long unsigned int)’
src/gdb/btrace.c:1153:42: error: no matching function for call to ‘pod_only_memset(btrace_insn*, int, long unsigned int)’
src/gdb/breakpoint.c:951:53: error: no matching function for call to ‘pod_only_memset(bp_location*, int, long unsigned int)’
src/gdb/breakpoint.c:7325:32: error: no matching function for call to ‘pod_only_memset(bp_location*&, int, long unsigned int)’

I've already posted a patch to fix struct inferior:
  https://sourceware.org/ml/gdb-patches/2017-04/msg00298.html

I hadn't realized it already wasn't a POD.  Looks like that
happened because inferior has an enum_flags member, and that
one was recently made non-POD (gained a user-defined ctor to
default-zero-initialize).

I'll take a look at the others...

I wonder how bad would it be to put this hack in master.  Guess
we could always add it behind an #if 0 at least, to make it easy
to enable for quick checking?

>From f8b5c40ff07891eb607dba4233419ca4e4295d22 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 12 Apr 2017 19:28:40 +0100
Subject: [PATCH] Make the compiler error out with memset on non-POD types

---
 gdb/common/common-defs.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index af37111..fe94000 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -90,4 +90,20 @@
 /* Pull in gdb::unique_xmalloc_ptr.  */
 #include "common/gdb_unique_ptr.h"
 
+#include <type_traits>
+
+/* Redefine memset to only work with POD types.  This catches
+   initialization of structs that should have been converted to
+   ctors.  */
+template <typename T,
+	  typename = typename std::enable_if<std::is_pod<T>::value
+					     || std::is_void<T>::value>::type>
+static inline void *
+pod_only_memset (T *s, int c, size_t n)
+{
+  return memset (s, c, n);
+}
+
+#define memset pod_only_memset
+
 #endif /* COMMON_DEFS_H */
-- 
2.5.5



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