From patchwork Fri Aug 21 21:21:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 8359 Received: (qmail 108145 invoked by alias); 21 Aug 2015 21:21:45 -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 108127 invoked by uid 89); 21 Aug 2015 21:21:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no 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; Fri, 21 Aug 2015 21:21:40 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 525368CF77 for ; Fri, 21 Aug 2015 21:21:39 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7LLLawU030157 for ; Fri, 21 Aug 2015 17:21:37 -0400 Subject: [PATCH v12 11/32] Code cleanup: Remove OPF_RETURN_REALPATH From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 21 Aug 2015 23:21:36 +0200 Message-ID: <20150821212136.6673.16580.stgit@host1.jankratochvil.net> In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> References: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, OPF_RETURN_REALPATH is used only at the end of openp() to convert the returned values. That is not useful, code can be simplified if callers that passed OPF_RETURN_REALPATH adjust the returned values on their own. Or at least it helps further refactorizations. Jan gdb/ChangeLog 2015-08-18 Jan Kratochvil * cli/cli-cmds.c (find_and_open_script): Remove OPF_RETURN_REALPATH. Call gdb_realpath_and_xfree. * defs.h (enum openp_flags): Add OPF_NONE, remove OPF_RETURN_REALPATH. * dwarf2read.c (try_open_dwop_file): Remove OPF_RETURN_REALPATH. Call gdb_realpath_and_xfree. * nto-tdep.c (nto_find_and_open_solib): Remove OPF_RETURN_REALPATH. Call gdb_realpath_and_xfree and xstrdup. * solib.c (solib_find_2): New variable temp_pathname_is_realpath. Remove OPF_RETURN_REALPATH. Conditionally call gdb_realpath_and_xfree. * source.c (openp): Remove OPF_RETURN_REALPATH processing. (source_full_path_of, find_and_open_source): Remove OPF_RETURN_REALPATH. Call gdb_realpath_and_xfree. * symfile.c (symfile_bfd_open): Likewise. * utils.c (gdb_realpath_and_xfree): New function. * utils.h (gdb_realpath_and_xfree): New prototype. --- 0 files changed diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index a5a4c7c..5b90d4e 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -500,7 +500,7 @@ find_and_open_script (const char *script_file, int search_path, char *file; int fd; struct cleanup *old_cleanups; - enum openp_flags search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH; + enum openp_flags search_flags = OPF_TRY_CWD_FIRST; file = tilde_expand (script_file); old_cleanups = make_cleanup (xfree, file); @@ -523,6 +523,8 @@ find_and_open_script (const char *script_file, int search_path, do_cleanups (old_cleanups); + *full_pathp = gdb_realpath_and_xfree (*full_pathp); + *streamp = fdopen (fd, FOPEN_RT); if (*streamp == NULL) { diff --git a/gdb/defs.h b/gdb/defs.h index 3d248f6..ca95634 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -323,6 +323,9 @@ extern const char *pc_prefix (CORE_ADDR); /* See openp function definition for their description. */ enum openp_flags { + /* No options specified, type-compatibile with the enum. */ + OPF_NONE = 0, + /* Try to open ./STRING before searching PATH (ie pretend the first element of PATH is "."). This also indicates that, unless OPF_SEARCH_IN_PATH is also specified, a slash in STRING disables @@ -334,9 +337,6 @@ enum openp_flags /* Absolute names will also be searched in path (we usually want this for source files but not for executables). */ OPF_SEARCH_IN_PATH = (1 << 1), - - /* See openp, to be removed. */ - OPF_RETURN_REALPATH = (1 << 2), }; extern int openp (const char *, enum openp_flags, const char *, int, char **); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 23b60f9..835ba4f 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10470,7 +10470,7 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd) else search_path = xstrdup (debug_file_directory); - flags = OPF_RETURN_REALPATH; + flags = OPF_NONE; if (is_dwp) flags |= OPF_SEARCH_IN_PATH; desc = openp (search_path, flags, file_name, @@ -10478,6 +10478,7 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd) xfree (search_path); if (desc < 0) return NULL; + absolute_name = gdb_realpath_and_xfree (absolute_name); sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc); xfree (absolute_name); diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c index ba3c845..72909fd 100644 --- a/gdb/nto-tdep.c +++ b/gdb/nto-tdep.c @@ -127,7 +127,7 @@ nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname) arch_path); base = lbasename (solib); - ret = openp (buf, OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, base, o_flags, + ret = openp (buf, OPF_TRY_CWD_FIRST, base, o_flags, temp_pathname); if (ret < 0 && base != solib) { @@ -136,11 +136,13 @@ nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname) if (temp_pathname) { if (ret >= 0) - *temp_pathname = gdb_realpath (arch_path); + *temp_pathname = xstrdup (arch_path); else *temp_pathname = NULL; } } + if (ret >= 0) + *temp_pathname = gdb_realpath_and_xfree (*temp_pathname); return ret; } diff --git a/gdb/solib.c b/gdb/solib.c index 98af2c0..1c408c0 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -158,7 +158,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) char *temp_pathname = NULL; const char *fskind = effective_target_file_system_kind (); struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); - int prefix_len, orig_prefix_len; + int prefix_len, orig_prefix_len, temp_pathname_is_realpath; /* If the absolute prefix starts with "target:" but the filesystem accessed by the target_fileio_* methods is the local filesystem @@ -311,7 +311,12 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) needs to be freed. */ if (found_file < 0) - temp_pathname = NULL; + { + temp_pathname = NULL; + temp_pathname_is_realpath = 1; + } + else + temp_pathname_is_realpath = 0; /* If the search in gdb_sysroot failed, and the path name is absolute at this point, make it relative. (openp will try and open the @@ -331,8 +336,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) /* If not found, and we're looking for a solib, search the solib_search_path (if any). */ if (is_solib && found_file < 0 && solib_search_path != NULL) - found_file = openp (solib_search_path, - OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, + found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, &temp_pathname); /* If not found, and we're looking for a solib, next search the @@ -340,8 +344,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) path). This is to allow reading solibs from a path that differs from the opened path. */ if (is_solib && found_file < 0 && solib_search_path != NULL) - found_file = openp (solib_search_path, - OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, + found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, target_lbasename (fskind, in_pathname), O_RDONLY | O_BINARY, &temp_pathname); @@ -355,7 +358,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) if (found_file < 0 && sysroot == NULL) found_file = openp (get_in_environ (current_inferior ()->environment, "PATH"), - OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname, + OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, &temp_pathname); /* If not found, and we're looking for a solib, next search the @@ -363,9 +366,12 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) if (is_solib && found_file < 0 && sysroot == NULL) found_file = openp (get_in_environ (current_inferior ()->environment, "LD_LIBRARY_PATH"), - OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname, + OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, &temp_pathname); + if (found_file >= 0 && temp_pathname_is_realpath) + temp_pathname = gdb_realpath_and_xfree (temp_pathname); + if (fd == NULL) { if (found_file >= 0) diff --git a/gdb/source.c b/gdb/source.c index 888ed2b..97849f8 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -749,11 +749,6 @@ dirnames_to_char_ptr_vec_target_exc (const char *string) and the file, sigh! Emacs gets confuzzed by this when we print the source file name!!! - If OPTS has OPF_RETURN_REALPATH set return FILENAME_OPENED resolved by - gdb_realpath. Even without OPF_RETURN_REALPATH this function still returns - filename starting with "/". If FILENAME_OPENED is NULL this option has no - effect. - If a file is found, return the descriptor. Otherwise, return -1, with errno set for the last name we tried to open. */ @@ -910,13 +905,10 @@ openp (const char *path, enum openp_flags opts, const char *string, done: if (filename_opened) { - /* If a file was opened, canonicalize its filename. */ if (fd < 0) *filename_opened = NULL; - else if ((opts & OPF_RETURN_REALPATH) != 0) - *filename_opened = gdb_realpath (filename); else - *filename_opened = gdb_abspath (filename); + *filename_opened = xstrdup (filename); } return fd; @@ -939,14 +931,15 @@ source_full_path_of (const char *filename, char **full_pathname) { int fd; - fd = openp (source_path, - OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, + fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename, O_RDONLY, full_pathname); if (fd < 0) { *full_pathname = NULL; return 0; } + + *full_pathname = gdb_realpath_and_xfree (*full_pathname); close (fd); return 1; @@ -1113,17 +1106,18 @@ find_and_open_source (const char *filename, } } - result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename, - OPEN_MODE, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ p = lbasename (filename); if (p != filename) - result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, p, - OPEN_MODE, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, fullname); } + if (result >= 0) + *fullname = gdb_realpath_and_xfree (*fullname); + do_cleanups (cleanup); return result; } diff --git a/gdb/symfile.c b/gdb/symfile.c index 856572a..40f0451 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1731,8 +1731,7 @@ symfile_bfd_open (const char *name) expanded_name = tilde_expand (name); /* Returns 1st new malloc'd copy. */ /* Look down path for it, allocate 2nd new malloc'd copy. */ - desc = openp (getenv ("PATH"), - OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, + desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, expanded_name, O_RDONLY | O_BINARY, &absolute_name); #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__) if (desc < 0) @@ -1740,8 +1739,7 @@ symfile_bfd_open (const char *name) char *exename = alloca (strlen (expanded_name) + 5); strcat (strcpy (exename, expanded_name), ".exe"); - desc = openp (getenv ("PATH"), - OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, + desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename, O_RDONLY | O_BINARY, &absolute_name); } #endif @@ -1752,6 +1750,7 @@ symfile_bfd_open (const char *name) } xfree (expanded_name); + absolute_name = gdb_realpath_and_xfree (absolute_name); make_cleanup (xfree, absolute_name); name = absolute_name; } diff --git a/gdb/utils.c b/gdb/utils.c index 41dca7f..1bd273a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2820,6 +2820,17 @@ gdb_realpath (const char *filename) return xstrdup (filename); } +/* Wrap gdb_realpath by also calling xfree for the FILENAME parameter. */ + +char * +gdb_realpath_and_xfree (char *filename) +{ + char *retval = gdb_realpath (filename); + + xfree (filename); + return retval; +} + /* Return a copy of FILENAME, with its directory prefix canonicalized by gdb_realpath. */ diff --git a/gdb/utils.h b/gdb/utils.h index 995a1cf..e15ff6d 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -124,6 +124,8 @@ extern struct cleanup *make_bpstat_clear_actions_cleanup (void); extern char *gdb_realpath (const char *); +extern char *gdb_realpath_and_xfree (char *filename); + extern char *gdb_realpath_keepfile (const char *); extern char *gdb_abspath (const char *);