From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 88209 invoked by alias); 12 Aug 2017 11:31:44 -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 87198 invoked by uid 89); 12 Aug 2017 11:30:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=fell X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 12 Aug 2017 11:30:02 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v7CBTtf7008135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 12 Aug 2017 07:30:00 -0400 Received: by simark.ca (Postfix, from userid 112) id B8BD21EA1D; Sat, 12 Aug 2017 07:29:55 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id B82A91E043; Sat, 12 Aug 2017 07:29:51 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 12 Aug 2017 11:31:00 -0000 From: Simon Marchi To: Pedro Alves Cc: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 0/3] Create arch_lwp_info class hierarchy In-Reply-To: <22f9058d-52de-293a-eef8-6af1572955d0@redhat.com> References: <1500892797-7523-1-git-send-email-simon.marchi@ericsson.com> <22f9058d-52de-293a-eef8-6af1572955d0@redhat.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 12 Aug 2017 11:29:55 +0000 X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00266.txt.bz2 On 2017-08-11 22:13, Pedro Alves wrote: > Let me just lay down some thoughts: > > We don't really need to make these types have vtable pointers / don't > really need to polymorphic, since there's only ever going to be one > arch type in a build. So we could instead move the arch-specific > definitions to arch-specific headers, still name the arch-specific > types > and then have linux-low.c etc. include it. That way, we'd use > arch_lwp_info throughout just like today. arch_lwp_info would just > be different types defined in different headers depending on arch. > > I.e., e.g., in a linux-arm-low.h: > > struct arch_lwp_info : public arch_lwp_info_base > { > // arm bits. > }; > > and then in linux-low.h we'd have > > #ifdef __arm__ > # include "linux-arm-low.h" > #elif defined __i686__ > # include "linux-x86-low.h" > #elif ... > ... > #endif > > A follow up thing that we could do is have arch_lwp_info inherit > from lwp_info and always allocate arch_lwp_info objects. > > Or for clarity, rename lwp_info to lwp_info_base and make the > arch version be The lwp_info type. I.e., e.g., in linux-arm-low.h: > > struct lwp_info : public lwp_info_base > { > // arm bits. > }; > > This would avoid the double/separate allocation of > lwp_info + arch_lwp_info. I like the idea. I tried to do this and fell in some traps, maybe you have some ideas about how to make it better. In linux-nat.c, for example, I started with this: #if defined __arm__ # include "arm-linux-nat.h" #elif defined __i686__ || defined __x86_64__ # include "nat/x86-linux.h" #else # error "Missing arch-specific include." #endif But then I realized that many arches have linux support, but don't have arch_lwp_info. So I changed to ... #else /* Define a dummy arch_lwp_info for arches that don't define one. */ struct arch_lwp_info [}; #endif But then I realized that I forgot to include the header for s390, and the compiler (when building for a s390 host) didn't warn me. This is dangerous and fragile since we end up with two definitions of arch_lwp_info (the s390 one and that fallback one), and nothing to warn about it. So I changed it to listing explicitly the architectures that don't defined their own arch_lwp_info: ... #elif defined __alpha__ || defined __powerpc__ || ... /* Define a dummy arch_lwp_info for arches that don't define one. */ struct arch_lwp_info {}; #else # error "Missing arch-specific include." #endif That would work, but requires listing all the arches that need the fallback definition of arch_lwp_info, so it gets pretty ugly. Any idea to make this simple but safe? Otherwise, I'll just go with the current version of the patch. Simon