From patchwork Fri Aug 18 20:00:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22231 Received: (qmail 99873 invoked by alias); 18 Aug 2017 20:01:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 88955 invoked by uid 89); 18 Aug 2017 20:00:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Aug 2017 20:00:31 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy6.mail.unifiedlayer.com (Postfix) with ESMTP id 0EBF21E08A9 for ; Fri, 18 Aug 2017 14:00:30 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id yk0T1v00D2f2jeq01k0Wug; Fri, 18 Aug 2017 14:00:30 -0600 X-Authority-Analysis: v=2.2 cv=ELV26xRC c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=uMeos_ro0raR1SIMv3AA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-24-97.hlrn.qwest.net ([75.166.24.97]:49122 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dinRS-001KNP-SO; Fri, 18 Aug 2017 14:00:26 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/5] Change rewrite_source_path to return a unique_xmalloc_ptr Date: Fri, 18 Aug 2017 14:00:23 -0600 Message-Id: <20170818200024.4948-5-tom@tromey.com> In-Reply-To: <20170818200024.4948-1-tom@tromey.com> References: <20170818200024.4948-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dinRS-001KNP-SO X-Source-Sender: 75-166-24-97.hlrn.qwest.net (bapiya.Home) [75.166.24.97]:49122 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes rewrite_source_path to return a unique_xmalloc_ptr and fixes up the callers. This allows removing some cleanups. ChangeLog 2017-08-18 Tom Tromey * source.h (rewrite_source_path): Return a unique_xmalloc_ptr. * source.c (rewrite_source_path): Return a unique_xmalloc_ptr. (find_and_open_source, symtab_to_fullname): Update. * psymtab.c (psymtab_to_fullname): Update. --- gdb/ChangeLog | 7 +++++++ gdb/psymtab.c | 15 ++++++--------- gdb/source.c | 50 +++++++++++++++++++------------------------------- gdb/source.h | 2 +- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0257189..a15df78 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2017-08-18 Tom Tromey + * source.h (rewrite_source_path): Return a unique_xmalloc_ptr. + * source.c (rewrite_source_path): Return a unique_xmalloc_ptr. + (find_and_open_source, symtab_to_fullname): Update. + * psymtab.c (psymtab_to_fullname): Update. + +2017-08-18 Tom Tromey + * exec.c (exec_file_attach): Update. * linux-thread-db.c (try_thread_db_load): Update. * guile/scm-safe-call.c (gdbscm_safe_source_script): Update. diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 8283545..6307d6e 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1199,23 +1199,20 @@ psymtab_to_fullname (struct partial_symtab *ps) close (fd); else { - char *fullname; - struct cleanup *back_to; + gdb::unique_xmalloc_ptr fullname; /* rewrite_source_path would be applied by find_and_open_source, we should report the pathname where GDB tried to find the file. */ if (ps->dirname == NULL || IS_ABSOLUTE_PATH (ps->filename)) - fullname = xstrdup (ps->filename); + fullname.reset (xstrdup (ps->filename)); else - fullname = concat (ps->dirname, SLASH_STRING, - ps->filename, (char *) NULL); + fullname.reset (concat (ps->dirname, SLASH_STRING, + ps->filename, (char *) NULL)); - back_to = make_cleanup (xfree, fullname); - ps->fullname = rewrite_source_path (fullname); + ps->fullname = rewrite_source_path (fullname.get ()).release (); if (ps->fullname == NULL) - ps->fullname = xstrdup (fullname); - do_cleanups (back_to); + ps->fullname = fullname.release (); } } diff --git a/gdb/source.c b/gdb/source.c index 0453f92..5403715 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -994,13 +994,12 @@ get_substitute_path_rule (const char *path) } /* If the user specified a source path substitution rule that applies - to PATH, then apply it and return the new path. This new path must - be deallocated afterwards. - + to PATH, then apply it and return the new path. + Return NULL if no substitution rule was specified by the user, or if no rule applied to the given PATH. */ - -char * + +gdb::unique_xmalloc_ptr rewrite_source_path (const char *path) { const struct substitute_path_rule *rule = get_substitute_path_rule (path); @@ -1019,7 +1018,7 @@ rewrite_source_path (const char *path) strcpy (new_path, rule->to); strcat (new_path, path + from_len); - return new_path; + return gdb::unique_xmalloc_ptr (new_path); } int @@ -1030,7 +1029,6 @@ find_and_open_source (const char *filename, char *path = source_path; const char *p; int result; - struct cleanup *cleanup; /* Quick way out if we already know its full name. */ @@ -1039,7 +1037,7 @@ find_and_open_source (const char *filename, /* The user may have requested that source paths be rewritten according to substitution rules he provided. If a substitution rule applies to this path, then apply it. */ - char *rewritten_fullname = rewrite_source_path (*fullname); + char *rewritten_fullname = rewrite_source_path (*fullname).release (); if (rewritten_fullname != NULL) { @@ -1062,21 +1060,17 @@ find_and_open_source (const char *filename, *fullname = NULL; } - cleanup = make_cleanup (null_cleanup, NULL); - + gdb::unique_xmalloc_ptr rewritten_dirname; if (dirname != NULL) { /* If necessary, rewrite the compilation directory name according to the source path substitution rules specified by the user. */ - char *rewritten_dirname = rewrite_source_path (dirname); + rewritten_dirname = rewrite_source_path (dirname); if (rewritten_dirname != NULL) - { - make_cleanup (xfree, rewritten_dirname); - dirname = rewritten_dirname; - } - + dirname = rewritten_dirname.get (); + /* Replace a path entry of $cdir with the compilation directory name. */ #define cdir_len 5 @@ -1098,17 +1092,15 @@ find_and_open_source (const char *filename, } } + gdb::unique_xmalloc_ptr rewritten_filename; if (IS_ABSOLUTE_PATH (filename)) { /* If filename is absolute path, try the source path substitution on it. */ - char *rewritten_filename = rewrite_source_path (filename); + rewritten_filename = rewrite_source_path (filename); if (rewritten_filename != NULL) - { - make_cleanup (xfree, rewritten_filename); - filename = rewritten_filename; - } + filename = rewritten_filename.get (); } result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename, @@ -1122,7 +1114,6 @@ find_and_open_source (const char *filename, OPEN_MODE, fullname); } - do_cleanups (cleanup); return result; } @@ -1164,23 +1155,20 @@ symtab_to_fullname (struct symtab *s) close (fd); else { - char *fullname; - struct cleanup *back_to; + gdb::unique_xmalloc_ptr fullname; /* rewrite_source_path would be applied by find_and_open_source, we should report the pathname where GDB tried to find the file. */ if (SYMTAB_DIRNAME (s) == NULL || IS_ABSOLUTE_PATH (s->filename)) - fullname = xstrdup (s->filename); + fullname.reset (xstrdup (s->filename)); else - fullname = concat (SYMTAB_DIRNAME (s), SLASH_STRING, - s->filename, (char *) NULL); + fullname.reset (concat (SYMTAB_DIRNAME (s), SLASH_STRING, + s->filename, (char *) NULL)); - back_to = make_cleanup (xfree, fullname); - s->fullname = rewrite_source_path (fullname); + s->fullname = rewrite_source_path (fullname.get ()).release (); if (s->fullname == NULL) - s->fullname = xstrdup (fullname); - do_cleanups (back_to); + s->fullname = fullname.release (); } } diff --git a/gdb/source.h b/gdb/source.h index ee9f3fa..263715a 100644 --- a/gdb/source.h +++ b/gdb/source.h @@ -48,7 +48,7 @@ extern int find_and_open_source (const char *filename, negative number for error. */ extern int open_source_file (struct symtab *s); -extern char *rewrite_source_path (const char *path); +extern gdb::unique_xmalloc_ptr rewrite_source_path (const char *path); extern const char *symtab_to_fullname (struct symtab *s);