Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA v2 10/17] C++ify mi_parse
Date: Wed, 12 Apr 2017 18:37:00 -0000	[thread overview]
Message-ID: <77601650-1ad9-dc6e-b7a2-814a08f9348d@redhat.com> (raw)
In-Reply-To: <87tw5t5wnl.fsf@tromey.com>

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



  reply	other threads:[~2017-04-12 18:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-11 15:02 [RFA v2 00/17] miscellaneous C++-ification Tom Tromey
2017-04-11 15:01 ` [RFA v2 16/17] Add a constructor and destructor to linespec_result Tom Tromey
2017-04-12  2:25   ` Simon Marchi
2017-04-12 14:30     ` Tom Tromey
2017-04-11 15:01 ` [RFA v2 09/17] Remove some cleanups from location.c Tom Tromey
2017-04-11 15:01 ` [RFA v2 11/17] Use scoped_restore in more places Tom Tromey
2017-04-11 15:01 ` [RFA v2 01/17] Introduce event_location_up Tom Tromey
2017-04-11 15:01 ` [RFA v2 10/17] C++ify mi_parse Tom Tromey
2017-04-12 11:26   ` Pedro Alves
2017-04-12 16:15     ` Tom Tromey
2017-04-12 16:19       ` Pedro Alves
2017-04-12 18:05         ` Tom Tromey
2017-04-12 18:37           ` Pedro Alves [this message]
2017-04-12 19:25             ` Tom Tromey
2017-04-13  2:36               ` Pedro Alves
2017-04-13 13:44                 ` Tom Tromey
2017-04-11 15:01 ` [RFA v2 04/17] Introduce gdb_dlhandle_up Tom Tromey
2017-04-11 15:01 ` [RFA v2 17/17] Change linespec_result::location to be an event_location_up Tom Tromey
2017-04-12  2:39   ` Simon Marchi
2017-04-11 15:01 ` [RFA v2 12/17] Use std::vector in reread_symbols Tom Tromey
2017-04-11 15:01 ` [RFA v2 05/17] Change increment_reading_symtab to return a scoped_restore Tom Tromey
2017-04-12 11:16   ` Pedro Alves
2017-04-12 14:31     ` Tom Tromey
2017-04-11 15:01 ` [RFA v2 02/17] Introduce command_line_up Tom Tromey
2017-04-11 15:02 ` [RFA v2 08/17] Remove some cleanups from gnu-v3-abi.c Tom Tromey
2017-04-11 15:02 ` [RFA v2 13/17] Use std::vector in find_instruction_backward Tom Tromey
2017-04-11 15:02 ` [RFA v2 07/17] Fix up wchar_iterator comment Tom Tromey
2017-04-11 15:21 ` [RFA v2 06/17] Remove cleanup_iconv Tom Tromey
2017-04-12 11:19   ` Pedro Alves
2017-04-12 15:05     ` Tom Tromey
2017-04-11 15:21 ` [RFA v2 03/17] Change find_pcs_for_symtab_line to return a std::vector Tom Tromey
2017-04-11 15:22 ` [RFA v2 14/17] Use std::vector in compile-loc2c.c Tom Tromey
2017-04-11 15:23 ` [RFA v2 15/17] Change breakpoint event locations to event_location_up Tom Tromey
2017-04-12  2:25   ` Simon Marchi
2017-04-12  2:49 ` [RFA v2 00/17] miscellaneous C++-ification Simon Marchi
2017-04-12 11:38   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=77601650-1ad9-dc6e-b7a2-814a08f9348d@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox