From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51161 invoked by alias); 5 Apr 2017 15:47:17 -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 51147 invoked by uid 89); 5 Apr 2017 15:47:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Apr 2017 15:47:14 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 257413DBD9; Wed, 5 Apr 2017 15:47:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 257413DBD9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 257413DBD9 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DDA3A407C; Wed, 5 Apr 2017 15:47:14 +0000 (UTC) Subject: Re: [PATCH 2/2] Class-ify ptid_t To: Simon Marchi , gdb-patches@sourceware.org References: <20170404183235.10589-1-simon.marchi@ericsson.com> <20170404183235.10589-2-simon.marchi@ericsson.com> From: Pedro Alves Message-ID: <580e9a8a-d59b-095c-cf56-ee2f50fe46df@redhat.com> Date: Wed, 05 Apr 2017 15:47: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: <20170404183235.10589-2-simon.marchi@ericsson.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-04/txt/msg00112.txt.bz2 Hi Simon, Hmm, "unit tests or it didn't happen" ? :-) On 04/04/2017 07:32 PM, Simon Marchi wrote: > I grew a bit tired of using ptid_get_{lwp,pid,tid} and friends, so I > decided to make it a bit easier to use by making it a proper class. > > Because ptid_t is used in things that aren't constructed, it is not > possible to have a constructor. Instead I added a "build" static > method, which maps well to the current ptid_build anyway, and ptid_t is > basically just a plain old data type with read-only methods. The > difference with before is that the fields are private, so it's not > possible to change a ptid_t field by mistake. > > The new methods of ptid_t map to existing functions/practice like this: > > ptid_t::build (pid, lwp, tid) -> ptid_build (pid, lwp, tid) > ptid_t::build (pid) -> pid_to_ptid (pid) Not sure these two are an improvement. pid_to_ptid is the counterpart of ptid_is_pid, and that is lost with the overloading of ptid_t::build. > ptid.is_pid () -> ptid_is_pid (ptid) > ptid == other -> ptid_equal (ptid, other) > ptid.is_null () -> ptid_equal (ptid, null_ptid) > ptid.is_any () -> ptid_equal (ptid, minus_one_ptid) > ptid.pid () -> ptid_get_pid (ptid) > ptid.lwp_p () -> ptid_lwp_p (ptid) > ptid.lwp () -> ptid_get_lwp (ptid) > ptid.tid_p () -> ptid_tid_p (ptid) > ptid.tid () -> ptid_get_tid (ptid) > ptid.matches (filter) -> ptid_match (ptid, filter) > > I've replaced the implementation of the existing functions with calls to > the new methods. People are encouraged to gradually switch to using the > ptid_t methods instead of the functions (or we can change them all in > one pass eventually). > > Also, I'm not sure if it's worth it (because of ptid_t's relatively > small size), but I have made the functions and methods take ptid_t > arguments by const reference instead of by value. I'd guess that the structure is still sufficiently small that passing by value would be a benefit (plus, it avoids inefficiency caused by the compiler having to assume that the references can alias), but OTOH, this structure is likely to grow with the multi-target work. Fine with me to go with what you have. > > /* See ptid.h for these. */ > > -ptid_t null_ptid = { 0, 0, 0 }; > -ptid_t minus_one_ptid = { -1, 0, 0 }; > +ptid_t null_ptid = ptid_t::build (0, 0, 0); > +ptid_t minus_one_ptid = ptid_t::build (-1, 0, 0); It's probably going to be worth it to sprinkle "constexpr" all over the new API. Helps with static_asserts in unit testing too. *cough* :-) > -struct ptid > +class ptid_t > { > +public: > + static ptid_t build (int pid, long lwp = 0, long tid = 0) > + { > + ptid_t ptid; > + > + ptid.m_pid = pid; > + ptid.m_lwp = lwp; > + ptid.m_tid = tid; > + > + return ptid; > + } > + > + bool is_pid () const > + { > + if (is_any () || is_null()) Missing space after "null". Wonder about migrating/copying the comments API comments to the methods, if these are the entry points that people should be looking at going forward. > + return false; > + > + return m_lwp == 0 && m_tid == 0; > + } > + > diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c > index 4bc7f71b00..1287114cc1 100644 > --- a/gdb/gdbserver/server.c > +++ b/gdb/gdbserver/server.c > @@ -2654,7 +2654,9 @@ handle_v_cont (char *own_buf) > char *p, *q; > int n = 0, i = 0; > struct thread_resume *resume_info; > - struct thread_resume default_action = {{0}}; > + struct thread_resume default_action = { > + .thread = null_ptid, > + }; Note that C99 designated initializers are not valid C++11. Not sure whether any compiler _doesn't_ support them though. Thanks, Pedro Alves