From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v12 12/32] Code cleanup: Remove openp parameter mode
Date: Fri, 21 Aug 2015 21:21:00 -0000 [thread overview]
Message-ID: <20150821212144.6673.72008.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net>
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 <jan.kratochvil@redhat.com>
* 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)
next prev parent reply other threads:[~2015-08-21 21:21 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-21 21:20 [PATCH v12 00/32] Validate binary before use Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 05/32] gdbserver build-id attribute generator Jan Kratochvil
2015-08-22 7:17 ` Eli Zaretskii
2015-08-21 21:20 ` [PATCH v12 04/32] Move linux_find_memory_regions_full & co Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 02/32] Move gdb_regex* to common/ Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 03/32] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 01/32] Create empty common/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 08/32] Permit multiple sysroot directories Jan Kratochvil
2015-08-22 7:31 ` Eli Zaretskii
2015-08-22 19:24 ` Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 10/32] Code cleanup: Add enum for openp_flags Jan Kratochvil
2015-08-21 21:21 ` Jan Kratochvil [this message]
2015-08-21 21:21 ` [PATCH v12 06/32] Validate symbol file using build-id Jan Kratochvil
2015-08-22 7:23 ` Eli Zaretskii
2015-08-22 19:19 ` Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 11/32] Code cleanup: Remove OPF_RETURN_REALPATH Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 07/32] Code cleanup: Make solib_find_1 variable const Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 19/32] solib_find: Make it use file_location Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 13/32] Code cleanup: openp parameter filename_opened is never NULL Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 15/32] gdb_bfd_open_from_target: Support real fd Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 18/32] Refactor openp() to return file_location Jan Kratochvil
2015-08-25 19:07 ` [PATCH v13 " Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 09/32] Change sysroot to ":target:" Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 17/32] Add file_location utility functions Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 16/32] gdb_bfd_open_from_target: Optionally do not close fd Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 14/32] Provide new gdb_bfd_open_from_target Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 20/32] symfile_bfd_open: Make it use openp_bfd() Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 23/32] build_id_to_bfd: Make it return file_location Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 21/32] build_id_to_debug_bfd: Make it also non-.debug capable Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 24/32] solib_find: Search also by build-id Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 22/32] Add dummy build-id params to prototypes Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 27/32] build_id_verify: Make it more verbose Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 26/32] solib_bfd_open: Optimize opening twice Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 25/32] Verify the build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 29/32] testcase: Test also locating shlibs by build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 28/32] Tests for validate symbol file using build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 30/32] Code cleanup: New hex2bin_allocate() Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 32/32] Support build-id for main executables Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 31/32] Make only user-specified executable and symbol filenames sticky Jan Kratochvil
2015-09-02 3:57 ` [PATCH v12 00/32] Validate binary before use Doug Evans
2015-09-02 7:41 ` Jan Kratochvil
2015-09-02 14:58 ` Doug Evans
2015-09-02 15:14 ` Jan Kratochvil
2015-09-02 15:22 ` Doug Evans
2015-09-02 19:12 ` Jan Kratochvil
2015-09-15 1:37 ` Doug Evans
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150821212144.6673.72008.stgit@host1.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox