From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16450 invoked by alias); 1 Jul 2015 11:05: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 16435 invoked by uid 89); 1 Jul 2015 11:05:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 01 Jul 2015 11:05:44 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 82AE22C76EC; Wed, 1 Jul 2015 11:05:43 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t61B5f5c023155; Wed, 1 Jul 2015 07:05:42 -0400 Message-ID: <5593C985.7020204@redhat.com> Date: Wed, 01 Jul 2015 11:05:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Gary Benson , gdb-patches@sourceware.org CC: =?windows-1252?Q?C=E9dric_Buissart?= Subject: Re: [PATCH 1/5] Introduce build_debug_file_name References: <1434447768-17328-1-git-send-email-gbenson@redhat.com> <1434447768-17328-2-git-send-email-gbenson@redhat.com> In-Reply-To: <1434447768-17328-2-git-send-email-gbenson@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-07/txt/msg00006.txt.bz2 On 06/16/2015 10:42 AM, Gary Benson wrote: > This commit introduces a new function build_debug_file_name which > concatenates a series of filename components into a filename. > find_separate_debug_file is updated to use build_debug_file_name. > A later commit in this series will extend build_debug_file_name > to correctly handle "target:" prefixes, so it is convenient to > have filename building pulled out into one function. For now the > only functional change here is that the original code sometimes > generated filenames with repeated directory separators while the > new code does not. I'd drop the "debug" from the function's name. Sounds like a candidate for reuse elsewhere to me. > > gdb/ChangeLog: > > * gdb/symfile.c (build_debug_file_name): New function. > (find_separate_debug_file): Use the above to build filenames. > --- > gdb/ChangeLog | 5 ++ > gdb/symfile.c | 117 +++++++++++++++++++++++++++++++++++++++++--------------- > 2 files changed, 90 insertions(+), 32 deletions(-) > > diff --git a/gdb/symfile.c b/gdb/symfile.c > index 0c35ffa..799133a 100644 > --- a/gdb/symfile.c > +++ b/gdb/symfile.c > @@ -1431,6 +1431,79 @@ separate_debug_file_exists (const char *name, unsigned long crc, > return 1; > } > > +/* Build the filename of a separate debug file from an arbitrary > + number of components. Returns an xmalloc'd string that must > + be be freed by the caller. The final argument of this function > + must be NULL to mark the end the argument list. */ double "be be". > + > +static char * > +build_debug_file_name (const char *first, ...) > +{ > + va_list ap; > + const char *arg, *last; > + VEC (char_ptr) *args = NULL; > + struct cleanup *back_to = make_cleanup_free_char_ptr_vec (args); > + int bufsiz = 0; > + char *buf, *tmp; > + int i; > + > + va_start (ap, first); > + for (arg = first; arg; arg = va_arg (ap, const char *)) arg != NULL in predicate. > + last = arg; > + va_end (ap); > + > + va_start (ap, first); > + for (arg = first; arg; arg = va_arg (ap, const char *)) likewise. > + { > + if (arg == last) > + tmp = xstrdup (arg); > + else > + { > + int len; > + > + /* Strip leading separators from subdirectories. */ > + if (arg != first) > + { > + while (*arg != '\0' && IS_DIR_SEPARATOR (*arg)) > + arg++; > + } > + > + /* Strip trailing separators. */ > + len = strlen (arg); > + > + while (len > 0 && IS_DIR_SEPARATOR (arg[len - 1])) > + len--; > + > + if (len > 0) > + { > + tmp = xmalloc (len + strlen (SLASH_STRING) + 1); > + memcpy (tmp, arg, len); > + strcpy (tmp + len, SLASH_STRING); > + } > + else > + tmp = NULL; > + } > + > + if (tmp != NULL) > + { > + VEC_safe_push (char_ptr, args, tmp); > + bufsiz += strlen (tmp); Why build the temporary VEC instead of just incrementally building the final buf? I think you could simplify this much if you did that, and plus use reconcat. > + } > + } > + va_end (ap); > + > + bufsiz += 1; /* Terminator. */ > + > + buf = xmalloc (bufsiz); > + buf[0] = '\0'; > + for (i = 0; VEC_iterate (char_ptr, args, i, tmp); i++) > + strcat (buf, tmp); > + gdb_assert (bufsiz == strlen (buf) + 1); Thanks, Pedro Alves