From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123058 invoked by alias); 13 Feb 2019 12:59:15 -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 123009 invoked by uid 89); 13 Feb 2019 12:59:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ignores X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.123) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Feb 2019 12:59:12 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 3DA62E8C072 for ; Wed, 13 Feb 2019 06:59:10 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id tu86gzy3Y2PzOtu86gUXEl; Wed, 13 Feb 2019 06:59:10 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JgiKxSW63hWEpDIfUfbpIHg+fL4s8/QFCuvSctiQ3dI=; b=RroYbdOrppEFpTNN63KdRDsb2O cWDqiqvXSjdtKGRCEPI1jxaxLoGsQWqXjvU+iYq3A0uugzcgtxNMxgiwxp9H5k+qYma40y2A2DzfO 8ZAjSxK4GrpcbmSt1zxhFdZMb; Received: from 75-166-72-210.hlrn.qwest.net ([75.166.72.210]:41148 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gtu86-0040IS-10; Wed, 13 Feb 2019 06:59:10 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Change macro_source_fullname to return a std::string Date: Wed, 13 Feb 2019 12:59:00 -0000 Message-Id: <20190213125907.8571-3-tom@tromey.com> In-Reply-To: <20190213125907.8571-1-tom@tromey.com> References: <20190213125907.8571-1-tom@tromey.com> X-SW-Source: 2019-02/txt/msg00174.txt.bz2 While working on the previous patch, I noticed that if macro_source_fullname returned a std::string, then the callers would be simplified. This patch implements this idea. gdb/ChangeLog 2019-02-13 Tom Tromey * macrotab.h (macro_source_fullname): Return a std::string. * macrotab.c (macro_include, check_for_redefinition) (macro_undef, macro_lookup_definition, foreach_macro) (foreach_macro_in_scope): Update. (macro_source_fullname): Return a std::string. * macrocmd.c (show_pp_source_pos): Update. --- gdb/ChangeLog | 9 ++++++++ gdb/macrocmd.c | 10 +++----- gdb/macrotab.c | 63 ++++++++++++++++++-------------------------------- gdb/macrotab.h | 5 ++-- 4 files changed, 37 insertions(+), 50 deletions(-) diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c index 3313e65f929..0f81c3d5da4 100644 --- a/gdb/macrocmd.c +++ b/gdb/macrocmd.c @@ -119,20 +119,16 @@ show_pp_source_pos (struct ui_file *stream, struct macro_source_file *file, int line) { - char *fullname; - - fullname = macro_source_fullname (file); - fputs_styled (fullname, file_name_style.style (), stream); + std::string fullname = macro_source_fullname (file); + fputs_styled (fullname.c_str (), file_name_style.style (), stream); fprintf_filtered (stream, ":%d\n", line); - xfree (fullname); while (file->included_by) { fullname = macro_source_fullname (file->included_by); fputs_filtered (_(" included at "), stream); - fputs_styled (fullname, file_name_style.style (), stream); + fputs_styled (fullname.c_str (), file_name_style.style (), stream); fprintf_filtered (stream, ":%d\n", file->included_at_line); - xfree (fullname); file = file->included_by; } } diff --git a/gdb/macrotab.c b/gdb/macrotab.c index f7ce26f850d..fa3061616bd 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -466,8 +466,6 @@ macro_include (struct macro_source_file *source, the new one? */ if (*link && line == (*link)->included_at_line) { - char *link_fullname, *source_fullname; - /* This means the compiler is emitting bogus debug info. (GCC circa March 2002 did this.) It also means that the splay tree ordering function, macro_tree_compare, will abort, @@ -476,12 +474,11 @@ macro_include (struct macro_source_file *source, First, squawk. */ - link_fullname = macro_source_fullname (*link); - source_fullname = macro_source_fullname (source); + std::string link_fullname = macro_source_fullname (*link); + std::string source_fullname = macro_source_fullname (source); complaint (_("both `%s' and `%s' allegedly #included at %s:%d"), - included, link_fullname, source_fullname, line); - xfree (source_fullname); - xfree (link_fullname); + included, link_fullname.c_str (), source_fullname.c_str (), + line); /* Now, choose a new, unoccupied line number for this #inclusion, after the alleged #inclusion line. */ @@ -725,16 +722,14 @@ check_for_redefinition (struct macro_source_file *source, int line, if (! same) { - char *source_fullname, *found_key_fullname; - - source_fullname = macro_source_fullname (source); - found_key_fullname = macro_source_fullname (found_key->start_file); + std::string source_fullname = macro_source_fullname (source); + std::string found_key_fullname + = macro_source_fullname (found_key->start_file); complaint (_("macro `%s' redefined at %s:%d; " "original definition at %s:%d"), - name, source_fullname, line, found_key_fullname, + name, source_fullname.c_str (), line, + found_key_fullname.c_str (), found_key->start_line); - xfree (found_key_fullname); - xfree (source_fullname); } return found_key; @@ -854,16 +849,13 @@ macro_undef (struct macro_source_file *source, int line, #definition. */ if (key->end_file) { - char *source_fullname, *key_fullname; - - source_fullname = macro_source_fullname (source); - key_fullname = macro_source_fullname (key->end_file); + std::string source_fullname = macro_source_fullname (source); + std::string key_fullname = macro_source_fullname (key->end_file); complaint (_("macro '%s' is #undefined twice," " at %s:%d and %s:%d"), - name, source_fullname, line, key_fullname, + name, source_fullname.c_str (), line, + key_fullname.c_str (), key->end_line); - xfree (key_fullname); - xfree (source_fullname); } /* Whether or not we've seen a prior #undefinition, wipe out @@ -923,14 +915,9 @@ macro_lookup_definition (struct macro_source_file *source, if (n) { - struct macro_definition *retval; - char *source_fullname; - - source_fullname = macro_source_fullname (source); - retval = fixup_definition (source_fullname, line, - (struct macro_definition *) n->value); - xfree (source_fullname); - return retval; + std::string source_fullname = macro_source_fullname (source); + return fixup_definition (source_fullname.c_str (), line, + (struct macro_definition *) n->value); } else return 0; @@ -974,12 +961,10 @@ foreach_macro (splay_tree_node node, void *arg) struct macro_for_each_data *datum = (struct macro_for_each_data *) arg; struct macro_key *key = (struct macro_key *) node->key; struct macro_definition *def; - char *key_fullname; - key_fullname = macro_source_fullname (key->start_file); - def = fixup_definition (key_fullname, key->start_line, + std::string key_fullname = macro_source_fullname (key->start_file); + def = fixup_definition (key_fullname.c_str (), key->start_line, (struct macro_definition *) node->value); - xfree (key_fullname); datum->fn (key->name, def, key->start_file, key->start_line); return 0; @@ -1004,12 +989,10 @@ foreach_macro_in_scope (splay_tree_node node, void *info) struct macro_for_each_data *datum = (struct macro_for_each_data *) info; struct macro_key *key = (struct macro_key *) node->key; struct macro_definition *def; - char *datum_fullname; - datum_fullname = macro_source_fullname (datum->file); - def = fixup_definition (datum_fullname, datum->line, + std::string datum_fullname = macro_source_fullname (datum->file); + def = fixup_definition (datum_fullname.c_str (), datum->line, (struct macro_definition *) node->value); - xfree (datum_fullname); /* See if this macro is defined before the passed-in line, and extends past that line. */ @@ -1083,7 +1066,7 @@ free_macro_table (struct macro_table *table) /* See macrotab.h for the comment. */ -char * +std::string macro_source_fullname (struct macro_source_file *file) { const char *comp_dir = NULL; @@ -1092,7 +1075,7 @@ macro_source_fullname (struct macro_source_file *file) comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab); if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename)) - return xstrdup (file->filename); + return file->filename; - return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL); + return std::string (comp_dir) + SLASH_STRING + file->filename; } diff --git a/gdb/macrotab.h b/gdb/macrotab.h index d14449e2f2e..d1e14537bd3 100644 --- a/gdb/macrotab.h +++ b/gdb/macrotab.h @@ -351,12 +351,11 @@ void macro_for_each_in_scope (struct macro_source_file *file, int line, /* Return FILE->filename with possibly prepended compilation directory name. This is raw concatenation without the "set substitute-path" and gdb_realpath - applications done by symtab_to_fullname. Returned string must be freed by - xfree. + applications done by symtab_to_fullname. THis function ignores the "set filename-display" setting. Its default setting is "relative" which is backward compatible but the former behavior of macro filenames printing was "absolute". */ -extern char *macro_source_fullname (struct macro_source_file *file); +extern std::string macro_source_fullname (struct macro_source_file *file); #endif /* MACROTAB_H */ -- 2.17.2