From patchwork Fri Aug 21 21:21:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 8360 Received: (qmail 109083 invoked by alias); 21 Aug 2015 21:21:59 -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 109068 invoked by uid 89); 21 Aug 2015 21:21:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, 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:57 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 6AA5891E9D for ; Fri, 21 Aug 2015 21:21:56 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7LLLsup020081 for ; Fri, 21 Aug 2015 17:21:54 -0400 Subject: [PATCH v12 12/32] Code cleanup: Remove openp parameter mode From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 21 Aug 2015 23:21:44 +0200 Message-ID: <20150821212144.6673.72008.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, simplify the code, make it also suitable for more code refactorings. The new flag OPF_OPEN_RW_TMP is removed later in this patch series. Jan gdb/ChangeLog 2015-08-18 Jan Kratochvil * cli/cli-cmds.c (find_and_open_script): Update openp caller. * defs.h (enum openp_flags): Add OPF_OPEN_RW_TMP. (openp): Remove parameter mode. * dwarf2read.c (try_open_dwop_file): Update openp caller. * exec.c (exec_file_attach): Likewise. * nto-tdep.c (nto_find_and_open_solib): Remove parameter o_flags, update openp caller. * nto-tdep.h (nto_find_and_open_solib): Remove parameter o_flags. * solib.c (solib_find_2): Update openp and find_and_open_solib caller. * solist.h (struct target_so_ops): Remove parameter o_flags from find_and_open_solib method. * source.c (openp): Change parameter mode to a new variable. (source_full_path_of, find_and_open_source): Update openp caller. * symfile.c (symfile_bfd_open): Likewise. --- 0 files changed diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 5b90d4e..d495463 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -510,8 +510,7 @@ find_and_open_script (const char *script_file, int search_path, /* Search for and open 'file' on the search path used for source files. Put the full location in *FULL_PATHP. */ - fd = openp (source_path, search_flags, - file, O_RDONLY, full_pathp); + fd = openp (source_path, search_flags, file, full_pathp); if (fd == -1) { diff --git a/gdb/defs.h b/gdb/defs.h index ca95634..7795b4a 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -337,9 +337,12 @@ 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), + + /* Open the file in read/write mode if WRITE_FILES says so. */ + OPF_OPEN_RW_TMP = (1 << 3), }; -extern int openp (const char *, enum openp_flags, const char *, int, char **); +extern int openp (const char *, enum openp_flags, const char *, char **); extern int source_full_path_of (const char *, char **); diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 835ba4f..ae06e14 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10473,8 +10473,7 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd) flags = OPF_NONE; if (is_dwp) flags |= OPF_SEARCH_IN_PATH; - desc = openp (search_path, flags, file_name, - O_RDONLY | O_BINARY, &absolute_name); + desc = openp (search_path, flags, file_name, &absolute_name); xfree (search_path); if (desc < 0) return NULL; diff --git a/gdb/exec.c b/gdb/exec.c index f1b1049..e87d154 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -247,21 +247,18 @@ exec_file_attach (const char *filename, int from_tty) } else { - scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, - filename, write_files ? - O_RDWR | O_BINARY : O_RDONLY | O_BINARY, - &scratch_pathname); + scratch_chan = openp (getenv ("PATH"), + OPF_TRY_CWD_FIRST | OPF_OPEN_RW_TMP, + filename, &scratch_pathname); #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__) if (scratch_chan < 0) { char *exename = alloca (strlen (filename) + 5); strcat (strcpy (exename, filename), ".exe"); - scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, - exename, write_files ? - O_RDWR | O_BINARY - : O_RDONLY | O_BINARY, - &scratch_pathname); + scratch_chan = openp (getenv ("PATH"), + OPF_TRY_CWD_FIRST | OPF_OPEN_RW_TMP, + exename, &scratch_pathname); } #endif if (scratch_chan < 0) diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c index 72909fd..7c8b4ce 100644 --- a/gdb/nto-tdep.c +++ b/gdb/nto-tdep.c @@ -82,7 +82,7 @@ nto_map_arch_to_cputype (const char *arch) } int -nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname) +nto_find_and_open_solib (char *solib, char **temp_pathname) { char *buf, *arch_path, *nto_root; const char *endian; @@ -127,12 +127,11 @@ 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, base, o_flags, - temp_pathname); + ret = openp (buf, OPF_TRY_CWD_FIRST, base, temp_pathname); if (ret < 0 && base != solib) { xsnprintf (arch_path, arch_len, "/%s", solib); - ret = open (arch_path, o_flags, 0); + ret = open (arch_path, O_RDONLY | O_BINARY); if (temp_pathname) { if (ret >= 0) diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h index bd85d2a..1f8045a 100644 --- a/gdb/nto-tdep.h +++ b/gdb/nto-tdep.h @@ -154,7 +154,7 @@ void nto_relocate_section_addresses (struct so_list *, int nto_map_arch_to_cputype (const char *); -int nto_find_and_open_solib (char *, unsigned, char **); +int nto_find_and_open_solib (char *, char **); enum gdb_osabi nto_elf_osabi_sniffer (bfd *abfd); diff --git a/gdb/solib.c b/gdb/solib.c index 1c408c0..b16f47b 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -337,7 +337,7 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) 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, - in_pathname, O_RDONLY | O_BINARY, &temp_pathname); + in_pathname, &temp_pathname); /* If not found, and we're looking for a solib, next search the solib_search_path (if any) for the basename only (ignoring the @@ -345,29 +345,25 @@ solib_find_2 (char *in_pathname, int *fd, int is_solib, const char *sysroot) from the opened path. */ if (is_solib && found_file < 0 && solib_search_path != NULL) found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, - target_lbasename (fskind, in_pathname), - O_RDONLY | O_BINARY, &temp_pathname); + target_lbasename (fskind, in_pathname), &temp_pathname); /* If not found, and we're looking for a solib, try to use target supplied solib search method. */ if (is_solib && found_file < 0 && ops->find_and_open_solib) - found_file = ops->find_and_open_solib (in_pathname, O_RDONLY | O_BINARY, - &temp_pathname); + found_file = ops->find_and_open_solib (in_pathname, &temp_pathname); /* If not found, next search the inferior's $PATH environment variable. */ if (found_file < 0 && sysroot == NULL) found_file = openp (get_in_environ (current_inferior ()->environment, "PATH"), - OPF_TRY_CWD_FIRST, in_pathname, - O_RDONLY | O_BINARY, &temp_pathname); + OPF_TRY_CWD_FIRST, in_pathname, &temp_pathname); /* If not found, and we're looking for a solib, next search the inferior's $LD_LIBRARY_PATH environment variable. */ if (is_solib && found_file < 0 && sysroot == NULL) found_file = openp (get_in_environ (current_inferior ()->environment, "LD_LIBRARY_PATH"), - OPF_TRY_CWD_FIRST, in_pathname, - O_RDONLY | O_BINARY, &temp_pathname); + OPF_TRY_CWD_FIRST, in_pathname, &temp_pathname); if (found_file >= 0 && temp_pathname_is_realpath) temp_pathname = gdb_realpath_and_xfree (temp_pathname); diff --git a/gdb/solist.h b/gdb/solist.h index af9acc2..47e9d88 100644 --- a/gdb/solist.h +++ b/gdb/solist.h @@ -146,8 +146,7 @@ struct target_so_ops If TEMP_PATHNAME is non-NULL: If the file is successfully opened a pointer to a malloc'd and realpath'd copy of SONAME is stored there, otherwise NULL is stored there. */ - int (*find_and_open_solib) (char *soname, - unsigned o_flags, char **temp_pathname); + int (*find_and_open_solib) (char *soname, char **temp_pathname); /* Hook for looking up global symbols in a library-specific way. */ struct block_symbol (*lookup_lib_global_symbol) diff --git a/gdb/source.c b/gdb/source.c index 97849f8..8dfe580 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -737,9 +737,8 @@ dirnames_to_char_ptr_vec_target_exc (const char *string) return vec; } -/* Open a file named STRING, searching path PATH (dir names sep by some char) - using mode MODE in the calls to open. You cannot use this function to - create files (O_CREAT). +/* Open a file named STRING, searching path PATH (dir names sep by some char). + You cannot use this function to create files. OPTS specifies the function behaviour in specific cases. @@ -756,18 +755,16 @@ dirnames_to_char_ptr_vec_target_exc (const char *string) >>>> eg executable, non-directory. */ int openp (const char *path, enum openp_flags opts, const char *string, - int mode, char **filename_opened) + char **filename_opened) { int fd; char *filename; int alloclen; VEC (char_ptr) *dir_vec; struct cleanup *back_to; - int ix; + int ix, mode; char *dir; - /* The open syscall MODE parameter is not specified. */ - gdb_assert ((mode & O_CREAT) == 0); gdb_assert (string != NULL); /* A file with an empty name cannot possibly exist. Report a failure @@ -786,7 +783,8 @@ openp (const char *path, enum openp_flags opts, const char *string, if (!path) path = "."; - mode |= O_BINARY; + mode = (O_BINARY | (((opts & OPF_OPEN_RW_TMP) && write_files) + ? O_RDWR : O_RDONLY)); if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string)) { @@ -932,7 +930,7 @@ source_full_path_of (const char *filename, char **full_pathname) int fd; fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, - filename, O_RDONLY, full_pathname); + filename, full_pathname); if (fd < 0) { *full_pathname = NULL; @@ -1106,13 +1104,17 @@ find_and_open_source (const char *filename, } } - result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname); + gdb_assert (OPEN_MODE == (O_RDONLY | O_BINARY)); + result = openp (path, OPF_SEARCH_IN_PATH, filename, 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, p, OPEN_MODE, fullname); + { + gdb_assert (OPEN_MODE == (O_RDONLY | O_BINARY)); + result = openp (path, OPF_SEARCH_IN_PATH, p, fullname); + } } if (result >= 0) diff --git a/gdb/symfile.c b/gdb/symfile.c index 40f0451..c0eb4ce 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1732,7 +1732,7 @@ symfile_bfd_open (const char *name) /* Look down path for it, allocate 2nd new malloc'd copy. */ desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, - expanded_name, O_RDONLY | O_BINARY, &absolute_name); + expanded_name, &absolute_name); #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__) if (desc < 0) { @@ -1740,7 +1740,7 @@ symfile_bfd_open (const char *name) strcat (strcpy (exename, expanded_name), ".exe"); desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, - exename, O_RDONLY | O_BINARY, &absolute_name); + exename, &absolute_name); } #endif if (desc < 0)