From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18766 invoked by alias); 17 Jul 2004 18:20:14 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 18537 invoked from network); 17 Jul 2004 18:20:12 -0000 Received: from unknown (HELO burundai.radix50.net) (82.83.199.246) by sourceware.org with SMTP; 17 Jul 2004 18:20:12 -0000 Received: from burundai.radix50.net (localhost [127.0.0.1]) by burundai.radix50.net (8.12.3/8.12.3/Debian -4) with ESMTP id i6HIMUlc025811 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Sat, 17 Jul 2004 20:22:31 +0200 Received: (from ibr@localhost) by burundai.radix50.net (8.12.3/8.12.3/Debian -4) id i6HIMSOk025810 for gdb-patches@sources.redhat.com; Sat, 17 Jul 2004 20:22:28 +0200 Date: Sat, 17 Jul 2004 18:20:00 -0000 From: Baurjan Ismagulov To: gdb-patches@sources.redhat.com Subject: Re: handling of absolute source file paths Message-ID: <20040717182228.GA24895@ata.cs.hun.edu.tr> Mail-Followup-To: gdb-patches@sources.redhat.com References: <20040420154855.GD9020@ata.cs.hacettepe.edu.tr> <20040501171420.GB21679@ata.cs.hun.edu.tr> <9743-Sat01May2004211140+0300-eliz@gnu.org> <20040508212208.GA1019@ata.cs.hun.edu.tr> <6137-Tue11May2004190737+0300-eliz@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline In-Reply-To: <6137-Tue11May2004190737+0300-eliz@gnu.org> User-Agent: Mutt/1.5.6i X-SW-Source: 2004-07/txt/msg00227.txt.bz2 --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 555 Hello Eli and Andrew, On Tue, May 11, 2004 at 07:07:37PM +0200, Eli Zaretskii wrote: > I was trying to approve your patch (all of its parts). It sounds like > everything is approved now, is that true? > > Once approved, it can go in; if you don't have write access to the GDB > CVS tree, I (or someone else) could do that for you. > > Andrew, is the paperwork part covered for Baurjan? The paperwork part is completed, here are the patches (they apply cleanly on HEAD and gdb_6_2-branch). Could anyone please apply that? With kind regards, Baurjan. --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-ibr-search_in_path-20040717-1823.diff" Content-length: 10343 diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/defs.h src/gdb/defs.h --- src.orig/gdb/defs.h 2004-07-17 18:06:35.000000000 +0200 +++ src/gdb/defs.h 2004-07-17 18:22:20.000000000 +0200 @@ -610,6 +610,9 @@ extern void print_address (CORE_ADDR, st /* From source.c */ +#define OPF_TRY_CWD_FIRST 0x01 +#define OPF_SEARCH_IN_PATH 0x02 + extern int openp (const char *, int, const char *, int, int, char **); extern int source_full_path_of (char *, char **); diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/exec.c src/gdb/exec.c --- src.orig/gdb/exec.c 2004-04-24 19:11:14.000000000 +0200 +++ src/gdb/exec.c 2004-07-17 18:22:21.000000000 +0200 @@ -194,7 +194,7 @@ exec_file_attach (char *filename, int fr char *scratch_pathname; int scratch_chan; - scratch_chan = openp (getenv ("PATH"), 1, filename, + scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename, write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, &scratch_pathname); #if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__) @@ -202,8 +202,9 @@ exec_file_attach (char *filename, int fr { char *exename = alloca (strlen (filename) + 5); strcat (strcpy (exename, filename), ".exe"); - scratch_chan = openp (getenv ("PATH"), 1, exename, write_files ? - O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, &scratch_pathname); + scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename, + write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY, 0, + &scratch_pathname); } #endif if (scratch_chan < 0) diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/nto-tdep.c src/gdb/nto-tdep.c --- src.orig/gdb/nto-tdep.c 2004-04-24 19:11:15.000000000 +0200 +++ src/gdb/nto-tdep.c 2004-07-17 18:22:21.000000000 +0200 @@ -115,7 +115,7 @@ nto_find_and_open_solib (char *solib, un sprintf (buf, path_fmt, arch_path, arch_path, arch_path, arch_path, arch_path); - return openp (buf, 1, solib, o_flags, 0, temp_pathname); + return openp (buf, OPF_TRY_CWD_FIRST, solib, o_flags, 0, temp_pathname); } void diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/pa64solib.c src/gdb/pa64solib.c --- src.orig/gdb/pa64solib.c 2004-05-08 21:02:29.000000000 +0200 +++ src/gdb/pa64solib.c 2004-07-17 18:22:21.000000000 +0200 @@ -157,8 +157,8 @@ pa64_solib_sizeof_symbol_table (char *fi /* We believe that filename was handed to us by the dynamic linker, and is therefore always an absolute path. */ - desc = openp (getenv ("PATH"), 1, filename, O_RDONLY | O_BINARY, - 0, &absolute_name); + desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename, + O_RDONLY | O_BINARY, 0, &absolute_name); if (desc < 0) { perror_with_name (filename); diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/solib.c src/gdb/solib.c --- src.orig/gdb/solib.c 2004-03-11 18:04:40.000000000 +0100 +++ src/gdb/solib.c 2004-07-17 18:22:21.000000000 +0200 @@ -156,15 +156,15 @@ solib_open (char *in_pathname, char **fo /* If not found, search the solib_search_path (if any). */ if (found_file < 0 && solib_search_path != NULL) - found_file = openp (solib_search_path, - 1, in_pathname, O_RDONLY, 0, &temp_pathname); + found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, + in_pathname, O_RDONLY, 0, &temp_pathname); /* If not found, next search the solib_search_path (if any) for the basename only (ignoring the path). This is to allow reading solibs from a path that differs from the opened path. */ if (found_file < 0 && solib_search_path != NULL) - found_file = openp (solib_search_path, - 1, lbasename (in_pathname), O_RDONLY, 0, + found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST, + lbasename (in_pathname), O_RDONLY, 0, &temp_pathname); /* If not found, try to use target supplied solib search method */ @@ -175,13 +175,15 @@ solib_open (char *in_pathname, char **fo /* If not found, next search the inferior's $PATH environment variable. */ if (found_file < 0 && solib_absolute_prefix == NULL) found_file = openp (get_in_environ (inferior_environ, "PATH"), - 1, in_pathname, O_RDONLY, 0, &temp_pathname); + OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0, + &temp_pathname); /* If not found, next search the inferior's $LD_LIBRARY_PATH environment variable. */ if (found_file < 0 && solib_absolute_prefix == NULL) found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"), - 1, in_pathname, O_RDONLY, 0, &temp_pathname); + OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0, + &temp_pathname); /* Done. If not found, tough luck. Return found_file and (optionally) found_pathname. */ diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/somsolib.c src/gdb/somsolib.c --- src.orig/gdb/somsolib.c 2004-05-19 20:08:14.000000000 +0200 +++ src/gdb/somsolib.c 2004-07-17 18:22:21.000000000 +0200 @@ -216,7 +216,8 @@ som_solib_sizeof_symbol_table (char *fil /* We believe that filename was handed to us by the dynamic linker, and is therefore always an absolute path. */ - desc = openp (getenv ("PATH"), 1, filename, O_RDONLY | O_BINARY, 0, &absolute_name); + desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename, + O_RDONLY | O_BINARY, 0, &absolute_name); if (desc < 0) { perror_with_name (filename); diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/source.c src/gdb/source.c --- src.orig/gdb/source.c 2004-06-27 22:33:07.000000000 +0200 +++ src/gdb/source.c 2004-07-17 18:23:23.000000000 +0200 @@ -636,12 +636,18 @@ is_regular_file (const char *name) /* Open a file named STRING, searching path PATH (dir names sep by some char) using mode MODE and protection bits PROT in the calls to open. - If TRY_CWD_FIRST, try to open ./STRING before searching PATH. + OPTS specifies the function behaviour in specific cases. + + If OPF_TRY_CWD_FIRST, try to open ./STRING before searching PATH. (ie pretend the first element of PATH is "."). This also indicates that a slash in STRING disables searching of the path (this is so that "exec-file ./foo" or "symbol-file ./foo" insures that you get that particular version of foo or an error message). + If OPTS has OPF_SEARCH_IN_PATH set, absolute names will also be + searched in path (we usually want this for source files but not for + executables). + If FILENAME_OPENED is non-null, set it to a newly allocated string naming the actual file opened (this string will always start with a "/"). We have to take special pains to avoid doubling the "/" between the directory @@ -654,7 +660,7 @@ is_regular_file (const char *name) /* >>>> This should only allow files of certain types, >>>> eg executable, non-directory */ int -openp (const char *path, int try_cwd_first, const char *string, +openp (const char *path, int opts, const char *string, int mode, int prot, char **filename_opened) { @@ -672,7 +678,7 @@ openp (const char *path, int try_cwd_fir mode |= O_BINARY; #endif - if (try_cwd_first || IS_ABSOLUTE_PATH (string)) + if ((opts & OPF_TRY_CWD_FIRST) || IS_ABSOLUTE_PATH (string)) { int i; @@ -690,11 +696,16 @@ openp (const char *path, int try_cwd_fir fd = -1; } - for (i = 0; string[i]; i++) - if (IS_DIR_SEPARATOR (string[i])) - goto done; + if (!(opts & OPF_SEARCH_IN_PATH)) + for (i = 0; string[i]; i++) + if (IS_DIR_SEPARATOR (string[i])) + goto done; } + /* /foo => foo, to avoid multiple slashes that Emacs doesn't like. */ + while (IS_DIR_SEPARATOR(string[0])) + string++; + /* ./foo => foo */ while (string[0] == '.' && IS_DIR_SEPARATOR (string[1])) string += 2; @@ -793,7 +804,8 @@ source_full_path_of (char *filename, cha { int fd; - fd = openp (source_path, 1, filename, O_RDONLY, 0, full_pathname); + fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename, + O_RDONLY, 0, full_pathname); if (fd < 0) { *full_pathname = NULL; @@ -864,13 +876,13 @@ find_and_open_source (struct objfile *ob } } - result = openp (path, 0, filename, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, 0, fullname); if (result < 0) { /* Didn't work. Try using just the basename. */ p = lbasename (filename); if (p != filename) - result = openp (path, 0, p, OPEN_MODE, 0, fullname); + result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname); } if (result >= 0) diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/symfile.c src/gdb/symfile.c --- src.orig/gdb/symfile.c 2004-07-15 23:58:03.000000000 +0200 +++ src/gdb/symfile.c 2004-07-17 18:22:21.000000000 +0200 @@ -1221,14 +1221,15 @@ symfile_bfd_open (char *name) 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"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name); + desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, name, O_RDONLY | O_BINARY, + 0, &absolute_name); #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__) if (desc < 0) { char *exename = alloca (strlen (name) + 5); strcat (strcpy (exename, name), ".exe"); - desc = openp (getenv ("PATH"), 1, exename, O_RDONLY | O_BINARY, - 0, &absolute_name); + desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename, + O_RDONLY | O_BINARY, 0, &absolute_name); } #endif if (desc < 0) diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/wince.c src/gdb/wince.c --- src.orig/gdb/wince.c 2004-06-25 22:11:54.000000000 +0200 +++ src/gdb/wince.c 2004-07-17 18:22:21.000000000 +0200 @@ -1586,7 +1586,8 @@ upload_to_device (const char *to, const return remotefile; /* Don't bother uploading. */ /* Open the source. */ - if ((fd = openp (getenv ("PATH"), TRUE, (char *) from, O_RDONLY, 0, NULL)) < 0) + if ((fd = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, (char *) from, O_RDONLY, + 0, NULL)) < 0) error ("couldn't open %s", from); /* Get the time for later comparison. */ --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-ibr-doc_search-20040509-0926.diff" Content-length: 2497 diff -Naurp -X /home/ibr/tmp/root/prg/dontdiff.ibr src.orig/gdb/doc/gdb.texinfo src-ibr/gdb/doc/gdb.texinfo --- src.orig/gdb/doc/gdb.texinfo Sat May 8 21:02:30 2004 +++ src-ibr/gdb/doc/gdb.texinfo Sun May 9 09:26:23 2004 @@ -4517,16 +4517,30 @@ the directories could be moved between t session. @value{GDBN} has a list of directories to search for source files; this is called the @dfn{source path}. Each time @value{GDBN} wants a source file, it tries all the directories in the list, in the order they are present -in the list, until it finds a file with the desired name. Note that -the executable search path is @emph{not} used for this purpose. Neither is -the current working directory, unless it happens to be in the source -path. +in the list, until it finds a file with the desired name. -If @value{GDBN} cannot find a source file in the source path, and the -object program records a directory, @value{GDBN} tries that directory -too. If the source path is empty, and there is no record of the -compilation directory, @value{GDBN} looks in the current directory as a -last resort. +For example, suppose an executable references the file +@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is +@file{/mnt/cross}. The file is first looked up literally; if this +fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this +fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error +message is printed. @value{GDBN} does not look up the parts of the +source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}. +Likewise, the subdirectories of the source path are not searched: if +the source path is @file{/mnt/cross}, and the binary refers to +@file{foo.c}, @value{GDBN} would not find it under +@file{/mnt/cross/usr/src/foo-1.0/lib}. + +Plain file names, relative file names with leading directories, file +names containing dots, etc.@: are all treated as described above; for +instance, if the source path is @file{/mnt/cross}, and the source file +is recorded as @file{../lib/foo.c}, @value{GDBN} would first try +@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after +that---@file{/mnt/cross/foo.c}. + +Note that the executable search path is @emph{not} used to locate the +source files. Neither is the current working directory, unless it +happens to be in the source path. Whenever you reset or rearrange the source path, @value{GDBN} clears out any information it has cached about where source files are found and where --YiEDa0DAkWCtVeE4--