From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53188 invoked by alias); 9 Nov 2018 16:31:29 -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 53172 invoked by uid 89); 9 Nov 2018 16:31:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=dtd 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; Fri, 09 Nov 2018 16:31:24 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 038ED308FB9B; Fri, 9 Nov 2018 16:31:23 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E7FD608C3; Fri, 9 Nov 2018 16:31:22 +0000 (UTC) Subject: Re: [PATCH v2 2/3] Add an optional "alias" attribute to syscall entries. To: John Baldwin , gdb-patches@sourceware.org References: <20181106175431.59832-1-jhb@FreeBSD.org> <20181106175431.59832-3-jhb@FreeBSD.org> From: Pedro Alves Message-ID: <2ab3f4b5-cc23-8b3d-dd55-66646cdffff1@redhat.com> Date: Fri, 09 Nov 2018 16:31:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181106175431.59832-3-jhb@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-11/txt/msg00159.txt.bz2 Hi, On 11/06/2018 05:54 PM, John Baldwin wrote: > --- a/gdb/syscalls/gdb-syscalls.dtd > +++ b/gdb/syscalls/gdb-syscalls.dtd > @@ -12,4 +12,5 @@ > name CDATA #REQUIRED > number CDATA #REQUIRED > + alias CDATA #IMPLIED > groups CDATA #IMPLIED> I think there should be a NEWS entry for this. I'd think there should be a docs update as well, but it looks like this dtd isn't documented in the manual. :-/ > + /* We have a name. Let's check if it's valid and fetch a > + list of matching numbers. */ > + std::vector numbers = get_syscalls_by_name (gdbarch, cur_name); > > - if (s.number == UNKNOWN_SYSCALL) > + if (numbers.empty ()) > /* Here we have to issue an error instead of a warning, > because GDB cannot do anything useful if there's no > syscall number to be caught. */ > error (_("Unknown syscall name '%s'."), cur_name); > > /* Ok, it's valid. */ > - result.push_back (s.number); > + for (int number : numbers) > + result.push_back (number); Nit: this return-vector interface seems like leads to a bit of unnecessary work, and double the number of necessary vector/heap allocations -- if get_syscalls_by_name were passed RESULT instead of returning a new vector, it could add to RESULT directly? The code above would like something like this instead with get_syscalls_by_name returning true/false to indicate whether something was added: /* We have a name. Let's check if it's valid and fetch a list of matching numbers. */ if (!get_syscalls_by_name (gdbarch, cur_name, result)) /* Here we have to issue an error instead of a warning, because GDB cannot do anything useful if there's no syscall number to be caught. */ error (_("Unknown syscall name '%s'."), cur_name); That means there's no need to copy numbers between the vectors (since there's only one vector). Same for get_syscalls_by_group. Note that instead of: > + for (int number : numbers) > + result.push_back (number); You could write: result.insert (result.end (), numbers.begin (), numbers.end ()); which may be more efficient assuming insert is smart enough to call std::vector::reserve to allocate space in one go. Thanks, Pedro Alves