From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101435 invoked by alias); 12 Apr 2017 18:37:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 101063 invoked by uid 89); 12 Apr 2017 18:37:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=Guess, 9020 X-HELO: mail-wr0-f178.google.com Received: from mail-wr0-f178.google.com (HELO mail-wr0-f178.google.com) (209.85.128.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Apr 2017 18:37:44 +0000 Received: by mail-wr0-f178.google.com with SMTP id c55so22861990wrc.3 for ; Wed, 12 Apr 2017 11:37:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=fAq+Ep+bt7ATgXvEX1fo7nfnxu3lsX4ugzoej66O8EQ=; b=bR6RMfOqmy6aUrvT04y+EZoMooixDcmmOErBkLCs6+CsD0nV1hPTw9Xq+OBJHkxwqH K/qiQ+Iz29V5D3yv6bHPeofR2MgDtPRci6m4nDfluE3hinHwm2ajGSA0rnBD4H6PyzIi wKH/XgQNfcZj29D2KTe/69/E6iwvaR0fyagosKMj3jGb0MY9A0OzzYa3Ysx0adoc9c6S /6vZNG1FOOwb293vGcR+zpnuaR5vDxewCJzyYYbjT86PPFk+CnqsafUgG+vc3wZP64c0 g5qsZZDIwTPbQeMNBIgTbNmKerbH3vMuID1KjPxKGANNNhnSJIpDmL3qk41ifGBLbu3B +x/g== X-Gm-Message-State: AN3rC/7s5QplQUmzty8zDnC4OL64/4dnsL7h19wY7E6YmutitLowv/Mf8hvWAu1r8sKzGNK0 X-Received: by 10.223.173.74 with SMTP id p68mr4107950wrc.137.1492022263292; Wed, 12 Apr 2017 11:37:43 -0700 (PDT) Received: from [192.168.0.101] ([37.189.166.198]) by smtp.gmail.com with ESMTPSA id p60sm3967666wrc.66.2017.04.12.11.37.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 11:37:42 -0700 (PDT) Subject: Re: [RFA v2 10/17] C++ify mi_parse To: Tom Tromey References: <20170411150112.23207-1-tom@tromey.com> <20170411150112.23207-11-tom@tromey.com> <56430d1d-abb1-5e22-87dd-14158939d842@redhat.com> <87y3v561rm.fsf@tromey.com> <59b6549f-3232-64c0-2f3c-5469f1f3ca6f@redhat.com> <87tw5t5wnl.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <77601650-1ad9-dc6e-b7a2-814a08f9348d@redhat.com> Date: Wed, 12 Apr 2017 18:37:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <87tw5t5wnl.fsf@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-SW-Source: 2017-04/txt/msg00357.txt.bz2 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 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 + +/* Redefine memset to only work with POD types. This catches + initialization of structs that should have been converted to + ctors. */ +template ::value + || std::is_void::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