* [PATCH] Use search path for scripts
@ 2005-11-16 19:36 Andrew STUBBS
2005-11-17 0:04 ` Eli Zaretskii
0 siblings, 1 reply; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-16 19:36 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 959 bytes --]
Hi all,
This is my last new patch for a while, I promise!
This patch adjusts the source command such that it uses the search path
(normally used to find sources) to find scripts.
This allows script files to be placed in a standard place and/or allow
them to source one-another without knowing an absolute path. We use this
mechanism to load all out target configuration routines from a toolchain
installation.
The search strategy employed is the one we have found most useful. If
the path contains '/' then search relative to current directory first,
otherwise search the path first. This way users do not get a nasty
surprise if they happen to have a script with a similar name to a
standard one (perhaps sourced indirectly). They can use ./ if they
really want a local file. If it were the other way around then the
standard scripts would not work as intended and users would need to find
an absolute path to use them by hand.
Andrew Stubbs
[-- Attachment #2: search-path.patch --]
[-- Type: text/plain, Size: 3738 bytes --]
2005-11-16 Andrew Stubbs <andrew.stubbs@st.com>
* cli-cmds.c: Include fcntl.h.
(source_command): Use the GDB search path to find script files.
doc/
* gdb.texinfo (Choosing files): Mention that -directory is used
for script files.
(Specifying source directories): Likewise.
(Command files): Explain how script files are found.
Index: src/gdb/cli/cli-cmds.c
===================================================================
--- src.orig/gdb/cli/cli-cmds.c 2005-11-14 17:37:07.000000000 +0000
+++ src/gdb/cli/cli-cmds.c 2005-11-14 17:39:24.000000000 +0000
@@ -50,6 +50,8 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#include <fcntl.h>
+
/* Prototypes for local command functions */
static void complete_command (char *, int);
@@ -433,6 +435,8 @@ source_command (char *args, int from_tty
char *file = args;
char *minusv=NULL;
int old_source_verbose = source_verbose;
+ char *full_pathname = NULL;
+ int fd;
/* -v causes the source command to run in verbose mode.
We still have to be able to handle filenames with spaces. */
@@ -486,8 +490,21 @@ source_command (char *args, int from_tty
file = tilde_expand (file);
old_cleanups = make_cleanup (xfree, file);
- stream = fopen (file, FOPEN_RT);
- if (!stream)
+ /* Search for and open 'file' on the search path used for source
+ files. Put the full location in 'full_pathname'. */
+ /* Search the current directory first if the filename has a directory
+ separtor in it - it might be a relative path. */
+ fd = openp (source_path,
+ strchr (file, '/') != NULL ? OPF_TRY_CWD_FIRST : 0,
+ file, O_RDONLY, 0, &full_pathname);
+
+ /* Use the full path name, if it is found. */
+ if (full_pathname != NULL && fd != -1)
+ {
+ file = full_pathname;
+ }
+
+ if (fd == -1)
{
source_verbose = old_source_verbose;
if (from_tty)
@@ -496,6 +513,7 @@ source_command (char *args, int from_tty
return;
}
+ stream = fdopen (fd, "r");
script_from_file (stream, file);
do_cleanups (old_cleanups);
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2005-11-14 17:37:07.000000000 +0000
+++ src/gdb/doc/gdb.texinfo 2005-11-14 17:39:24.000000000 +0000
@@ -951,7 +951,7 @@ also be interleaved with @samp{-command}
@itemx -d @var{directory}
@cindex @code{--directory}
@cindex @code{-d}
-Add @var{directory} to the path to search for source files.
+Add @var{directory} to the path to search for source and script files.
@item -r
@itemx -readnow
@@ -4824,6 +4824,9 @@ When you start @value{GDBN}, its source
and @samp{cwd}, in that order.
To add other directories, use the @code{directory} command.
+The search path is used to find both program source files and @value{GDBN}
+script files (read using the @samp{-command} option and @samp{source} command).
+
@table @code
@item directory @var{dirname} @dots{}
@item dir @var{dirname} @dots{}
@@ -15991,6 +15994,11 @@ The lines in a command file are executed
printed as they are executed. An error in any command terminates
execution of the command file and control is returned to the console.
+@value{GDBN} searches for @var{filename} on the search path (specified with the
+@samp{directory} command), unless @var{filename} is specified with a relative
+path, in which case it searches the current directory first, and then the
+search path. Absolute paths are not affected by the search path.
+
If @code{-v}, for verbose mode, is given then then each command will
be displayed as it is executed. The option may be given before or after
@var{filename}, but will be interpreted as part of the filename anywhere else.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-16 19:36 [PATCH] Use search path for scripts Andrew STUBBS
@ 2005-11-17 0:04 ` Eli Zaretskii
2005-11-17 12:41 ` Andrew STUBBS
0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2005-11-17 0:04 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: gdb-patches
> Date: Wed, 16 Nov 2005 17:06:32 +0000
> From: Andrew STUBBS <andrew.stubbs@st.com>
>
> The search strategy employed is the one we have found most useful. If
> the path contains '/' then search relative to current directory first,
> otherwise search the path first.
How about trying in the current directory if the file name does not
have any slash characters? That sounds like the least surprising
behavior, and also keeps backward compatibility.
> doc/
> * gdb.texinfo (Choosing files): Mention that -directory is used
> for script files.
> (Specifying source directories): Likewise.
> (Command files): Explain how script files are found.
This part is approved (but if we decide to change the behavior, please
post a modified patch).
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-17 0:04 ` Eli Zaretskii
@ 2005-11-17 12:41 ` Andrew STUBBS
2005-11-17 19:42 ` Eli Zaretskii
0 siblings, 1 reply; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-17 12:41 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Eli Zaretskii wrote:
>>Date: Wed, 16 Nov 2005 17:06:32 +0000
>>From: Andrew STUBBS <andrew.stubbs@st.com>
>>
>>The search strategy employed is the one we have found most useful. If
>>the path contains '/' then search relative to current directory first,
>>otherwise search the path first.
>
>
> How about trying in the current directory if the file name does not
> have any slash characters? That sounds like the least surprising
> behavior, and also keeps backward compatibility.
We have a selection of scripts kept in the toolchain installation. These
scripts are used to connect to and configure targets boards and
simulators of many varieties. The scripts often reference one-another
(sort of like an include statement) and in some cases are loaded lazily
as required to keep the number of user-defined commands to a minimum.
For these scripts to find each other they would either have to have
absolute paths hard-coded in - not a possibility because we do not
mandate any particular install location - or else add the directory to
the search path and reference the files by base name.
If the current directory was searched first then a users own scripts may
accidentally (and silently) override the intended script causing a
support headache.
In short, the chosen strategy ensures that our product always works as
our customers expect.
In addition, this way round you can always specify which file you mean
by adding './' whereas the other way round requires a lot more typing to
say what you mean when it doesn't do what you expect. It would also
require that the user search for the script themselves, and that isn't
something your average customer is capable of (or so it seems). It
certainly isn't something they want to do.
I do see what you mean about backwards compatibility though.
Andrew
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-17 12:41 ` Andrew STUBBS
@ 2005-11-17 19:42 ` Eli Zaretskii
2005-11-18 13:23 ` Andrew STUBBS
0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2005-11-17 19:42 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: gdb-patches
> Date: Thu, 17 Nov 2005 11:45:45 +0000
> From: Andrew STUBBS <andrew.stubbs@st.com>
> Cc: gdb-patches@sources.redhat.com
>
> If the current directory was searched first then a users own scripts may
> accidentally (and silently) override the intended script causing a
> support headache.
>
> In short, the chosen strategy ensures that our product always works as
> our customers expect.
Sorry, I don't think that the peculiar setup on your systems is a
reason good enough to change the current behavior in an incompatible
fashion. Your specific problem could have been solved in a different
way, for example by having all your system-wide scripts begin with a
reserved string (you could make that string include some unusual
characters to minimize the possibility of a name clash with user
scripts).
> In addition, this way round you can always specify which file you mean
> by adding './' whereas the other way round requires a lot more typing to
> say what you mean when it doesn't do what you expect.
That could very well be so, but what you see as a disadvantage is what
happens today. No doubt users are used to that extra typing when they
need it (which I suppose happens fairly rarely in most debugging
setups).
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-17 19:42 ` Eli Zaretskii
@ 2005-11-18 13:23 ` Andrew STUBBS
2005-11-18 14:53 ` Eli Zaretskii
0 siblings, 1 reply; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-18 13:23 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 646 bytes --]
Eli Zaretskii wrote:
> Sorry, I don't think that the peculiar setup on your systems is a
> reason good enough to change the current behavior in an incompatible
> fashion. Your specific problem could have been solved in a different
> way, for example by having all your system-wide scripts begin with a
> reserved string (you could make that string include some unusual
> characters to minimize the possibility of a name clash with user
> scripts).
Fair enough. As you say, I can probably solve this part of the problem a
different way, or else just keep a (much smaller) local patch.
Here is the patch adjusted as you request.
Andrew Stubbs
[-- Attachment #2: search-path.patch --]
[-- Type: text/plain, Size: 3404 bytes --]
2005-11-17 Andrew Stubbs <andrew.stubbs@st.com>
* cli-cmds.c: Include fcntl.h.
(source_command): Use the GDB search path to find script files.
doc/
* gdb.texinfo (Choosing files): Mention that -directory is used
for script files.
(Specifying source directories): Likewise.
(Command files): Explain how script files are found.
Index: src/gdb/cli/cli-cmds.c
===================================================================
--- src.orig/gdb/cli/cli-cmds.c 2005-11-18 11:22:08.000000000 +0000
+++ src/gdb/cli/cli-cmds.c 2005-11-18 11:23:27.000000000 +0000
@@ -50,6 +50,8 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#include <fcntl.h>
+
/* Prototypes for local command functions */
static void complete_command (char *, int);
@@ -433,6 +435,8 @@ source_command (char *args, int from_tty
char *file = args;
char *minusv=NULL;
int old_source_verbose = source_verbose;
+ char *full_pathname = NULL;
+ int fd;
/* -v causes the source command to run in verbose mode.
We still have to be able to handle filenames with spaces. */
@@ -486,8 +490,18 @@ source_command (char *args, int from_tty
file = tilde_expand (file);
old_cleanups = make_cleanup (xfree, file);
- stream = fopen (file, FOPEN_RT);
- if (!stream)
+ /* Search for and open 'file' on the search path used for source
+ files. Put the full location in 'full_pathname'. */
+ fd = openp (source_path, OPF_TRY_CWD_FIRST,
+ file, O_RDONLY, 0, &full_pathname);
+
+ /* Use the full path name, if it is found. */
+ if (full_pathname != NULL && fd != -1)
+ {
+ file = full_pathname;
+ }
+
+ if (fd == -1)
{
source_verbose = old_source_verbose;
if (from_tty)
@@ -496,6 +510,7 @@ source_command (char *args, int from_tty
return;
}
+ stream = fdopen (fd, "r");
script_from_file (stream, file);
do_cleanups (old_cleanups);
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2005-11-18 11:22:09.000000000 +0000
+++ src/gdb/doc/gdb.texinfo 2005-11-18 12:31:33.000000000 +0000
@@ -951,7 +951,7 @@ also be interleaved with @samp{-command}
@itemx -d @var{directory}
@cindex @code{--directory}
@cindex @code{-d}
-Add @var{directory} to the path to search for source files.
+Add @var{directory} to the path to search for source and script files.
@item -r
@itemx -readnow
@@ -4830,6 +4830,9 @@ When you start @value{GDBN}, its source
and @samp{cwd}, in that order.
To add other directories, use the @code{directory} command.
+The search path is used to find both program source files and @value{GDBN}
+script files (read using the @samp{-command} option and @samp{source} command).
+
@table @code
@item directory @var{dirname} @dots{}
@item dir @var{dirname} @dots{}
@@ -15997,6 +16000,9 @@ The lines in a command file are executed
printed as they are executed. An error in any command terminates
execution of the command file and control is returned to the console.
+@value{GDBN} searches for @var{filename} in the current directory and then
+on the search path (specified with the @samp{directory} command).
+
If @code{-v}, for verbose mode, is given then each command will
be displayed as it is executed. The option may be given before or after
@var{filename}, but will be interpreted as part of the filename anywhere else.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-18 13:23 ` Andrew STUBBS
@ 2005-11-18 14:53 ` Eli Zaretskii
2005-11-18 15:54 ` Andrew STUBBS
0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2005-11-18 14:53 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: gdb-patches
> Date: Fri, 18 Nov 2005 12:30:03 +0000
> From: Andrew STUBBS <andrew.stubbs@st.com>
> Cc: gdb-patches@sources.redhat.com
>
> Fair enough. As you say, I can probably solve this part of the problem a
> different way, or else just keep a (much smaller) local patch.
>
> Here is the patch adjusted as you request.
This is fine with me, thanks.
> - stream = fopen (file, FOPEN_RT);
> - if (!stream)
> + /* Search for and open 'file' on the search path used for source
> + files. Put the full location in 'full_pathname'. */
> + fd = openp (source_path, OPF_TRY_CWD_FIRST,
> + file, O_RDONLY, 0, &full_pathname);
> +
> + /* Use the full path name, if it is found. */
> + if (full_pathname != NULL && fd != -1)
> + {
> + file = full_pathname;
> + }
> +
> + if (fd == -1)
> {
> source_verbose = old_source_verbose;
> if (from_tty)
> @@ -496,6 +510,7 @@ source_command (char *args, int from_tty
> return;
> }
>
> + stream = fdopen (fd, "r");
^^^
Shouldn't this be FOPEN_RT, like what was used in the call to fopen in
the original code?
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-18 14:53 ` Eli Zaretskii
@ 2005-11-18 15:54 ` Andrew STUBBS
2005-11-25 18:02 ` Andrew STUBBS
` (2 more replies)
0 siblings, 3 replies; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-18 15:54 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 261 bytes --]
Eli Zaretskii wrote:
>>+ stream = fdopen (fd, "r");
>
> ^^^
> Shouldn't this be FOPEN_RT, like what was used in the call to fopen in
> the original code?
Quite so. I don't know where that came from.
Update attached.
Andrew Stubbs
[-- Attachment #2: search-path.patch --]
[-- Type: text/plain, Size: 3409 bytes --]
2005-11-17 Andrew Stubbs <andrew.stubbs@st.com>
* cli-cmds.c: Include fcntl.h.
(source_command): Use the GDB search path to find script files.
doc/
* gdb.texinfo (Choosing files): Mention that -directory is used
for script files.
(Specifying source directories): Likewise.
(Command files): Explain how script files are found.
Index: src/gdb/cli/cli-cmds.c
===================================================================
--- src.orig/gdb/cli/cli-cmds.c 2005-11-18 11:22:08.000000000 +0000
+++ src/gdb/cli/cli-cmds.c 2005-11-18 14:43:08.000000000 +0000
@@ -50,6 +50,8 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#include <fcntl.h>
+
/* Prototypes for local command functions */
static void complete_command (char *, int);
@@ -433,6 +435,8 @@ source_command (char *args, int from_tty
char *file = args;
char *minusv=NULL;
int old_source_verbose = source_verbose;
+ char *full_pathname = NULL;
+ int fd;
/* -v causes the source command to run in verbose mode.
We still have to be able to handle filenames with spaces. */
@@ -486,8 +490,18 @@ source_command (char *args, int from_tty
file = tilde_expand (file);
old_cleanups = make_cleanup (xfree, file);
- stream = fopen (file, FOPEN_RT);
- if (!stream)
+ /* Search for and open 'file' on the search path used for source
+ files. Put the full location in 'full_pathname'. */
+ fd = openp (source_path, OPF_TRY_CWD_FIRST,
+ file, O_RDONLY, 0, &full_pathname);
+
+ /* Use the full path name, if it is found. */
+ if (full_pathname != NULL && fd != -1)
+ {
+ file = full_pathname;
+ }
+
+ if (fd == -1)
{
source_verbose = old_source_verbose;
if (from_tty)
@@ -496,6 +510,7 @@ source_command (char *args, int from_tty
return;
}
+ stream = fdopen (fd, FOPEN_RT);
script_from_file (stream, file);
do_cleanups (old_cleanups);
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2005-11-18 11:22:09.000000000 +0000
+++ src/gdb/doc/gdb.texinfo 2005-11-18 12:31:33.000000000 +0000
@@ -951,7 +951,7 @@ also be interleaved with @samp{-command}
@itemx -d @var{directory}
@cindex @code{--directory}
@cindex @code{-d}
-Add @var{directory} to the path to search for source files.
+Add @var{directory} to the path to search for source and script files.
@item -r
@itemx -readnow
@@ -4830,6 +4830,9 @@ When you start @value{GDBN}, its source
and @samp{cwd}, in that order.
To add other directories, use the @code{directory} command.
+The search path is used to find both program source files and @value{GDBN}
+script files (read using the @samp{-command} option and @samp{source} command).
+
@table @code
@item directory @var{dirname} @dots{}
@item dir @var{dirname} @dots{}
@@ -15997,6 +16000,9 @@ The lines in a command file are executed
printed as they are executed. An error in any command terminates
execution of the command file and control is returned to the console.
+@value{GDBN} searches for @var{filename} in the current directory and then
+on the search path (specified with the @samp{directory} command).
+
If @code{-v}, for verbose mode, is given then each command will
be displayed as it is executed. The option may be given before or after
@var{filename}, but will be interpreted as part of the filename anywhere else.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-18 15:54 ` Andrew STUBBS
@ 2005-11-25 18:02 ` Andrew STUBBS
2005-11-25 18:12 ` Daniel Jacobowitz
2006-01-12 0:09 ` Andrew STUBBS
2 siblings, 0 replies; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-25 18:02 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Andrew Stubbs wrote:
> Update attached.
OK?
Andrew
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-18 15:54 ` Andrew STUBBS
2005-11-25 18:02 ` Andrew STUBBS
@ 2005-11-25 18:12 ` Daniel Jacobowitz
2005-11-25 18:33 ` Andrew STUBBS
2005-11-25 21:43 ` Eli Zaretskii
2006-01-12 0:09 ` Andrew STUBBS
2 siblings, 2 replies; 21+ messages in thread
From: Daniel Jacobowitz @ 2005-11-25 18:12 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: Eli Zaretskii, gdb-patches
On Fri, Nov 18, 2005 at 02:45:13PM +0000, Andrew STUBBS wrote:
> * cli-cmds.c: Include fcntl.h.
> (source_command): Use the GDB search path to find script files.
>
> doc/
> * gdb.texinfo (Choosing files): Mention that -directory is used
> for script files.
> (Specifying source directories): Likewise.
> (Command files): Explain how script files are found.
Could you explain why you used the source path to search for scripts,
instead of a separate search path? Was it just because it was handy?
Are scripts likely to be in manually-added directories on the source
search path?
I don't see the correspondence.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 18:12 ` Daniel Jacobowitz
@ 2005-11-25 18:33 ` Andrew STUBBS
2005-11-25 18:39 ` Daniel Jacobowitz
2005-11-25 21:56 ` Eli Zaretskii
2005-11-25 21:43 ` Eli Zaretskii
1 sibling, 2 replies; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-25 18:33 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Eli Zaretskii, gdb-patches
Daniel Jacobowitz wrote:
> On Fri, Nov 18, 2005 at 02:45:13PM +0000, Andrew STUBBS wrote:
>
>> * cli-cmds.c: Include fcntl.h.
>> (source_command): Use the GDB search path to find script files.
>>
>>doc/
>> * gdb.texinfo (Choosing files): Mention that -directory is used
>> for script files.
>> (Specifying source directories): Likewise.
>> (Command files): Explain how script files are found.
>
>
> Could you explain why you used the source path to search for scripts,
> instead of a separate search path? Was it just because it was handy?
> Are scripts likely to be in manually-added directories on the source
> search path?
>
> I don't see the correspondence.
Because it was handy, but who says it is the 'source search path'? It's
just that that's all it's been used for up till now.
The source directory is as likely a place as any for script files
(perhaps with some commands to help visualise the data). As it happens
we *always* add a directory (via -d in a wrapper) which contains nothing
but scripts, but since there are no sources that causes no problems.
Conversely, there's no technical reason why they couldn't have different
search paths. However, having more may lead to confusion, command/option
bloat, and the possibility that the user will have to add the same path
twice - once to each path.
If you wish I can split it out into a new list, with new commands, new
command-line options and new documentation. It solves the same problems
in the end.
Thanks
Andrew Stubbs
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 18:33 ` Andrew STUBBS
@ 2005-11-25 18:39 ` Daniel Jacobowitz
2005-11-25 20:12 ` Andrew STUBBS
2005-11-25 22:33 ` Eli Zaretskii
2005-11-25 21:56 ` Eli Zaretskii
1 sibling, 2 replies; 21+ messages in thread
From: Daniel Jacobowitz @ 2005-11-25 18:39 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: Eli Zaretskii, gdb-patches
On Fri, Nov 25, 2005 at 06:07:58PM +0000, Andrew STUBBS wrote:
> Daniel Jacobowitz wrote:
> >Could you explain why you used the source path to search for scripts,
> >instead of a separate search path? Was it just because it was handy?
> >Are scripts likely to be in manually-added directories on the source
> >search path?
> >
> >I don't see the correspondence.
>
> Because it was handy, but who says it is the 'source search path'? It's
> just that that's all it's been used for up till now.
... what?
It's the source search path because that's what it's used for. It's
also documented that way:
`-directory DIRECTORY'
`-d DIRECTORY'
Add DIRECTORY to the path to search for source files.
and
7.4 Specifying source directories
=================================
> The source directory is as likely a place as any for script files
> (perhaps with some commands to help visualise the data). As it happens
> we *always* add a directory (via -d in a wrapper) which contains nothing
> but scripts, but since there are no sources that causes no problems.
>
> Conversely, there's no technical reason why they couldn't have different
> search paths. However, having more may lead to confusion, command/option
> bloat, and the possibility that the user will have to add the same path
> twice - once to each path.
>
> If you wish I can split it out into a new list, with new commands, new
> command-line options and new documentation. It solves the same problems
> in the end.
Most users don't ever have to add a source path. If you're using a
modern compiler, and debugging something built locally, and not using
certain kinds of include path constructs (which is unambiguously an
open, and recently discussed, bug in GDB) then GDB will Just Find
Things.
I don't find it intuitive that the same path should be overloaded this
way, and it makes changing the source searching algorithm even more
complicated. However, I'd like to know if any other GDB maintainers
have an opinion on this before I ask you to modify the patch.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 18:39 ` Daniel Jacobowitz
@ 2005-11-25 20:12 ` Andrew STUBBS
2005-11-25 21:26 ` Daniel Jacobowitz
2005-11-25 22:33 ` Eli Zaretskii
1 sibling, 1 reply; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-25 20:12 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Eli Zaretskii, gdb-patches
Daniel Jacobowitz wrote:
> ... what?
>
> It's the source search path because that's what it's used for. It's
> also documented that way:
>
> `-directory DIRECTORY'
> `-d DIRECTORY'
> Add DIRECTORY to the path to search for source files.
My patch includes a modification to this documentation to reflect it's
update purpose.
> Most users don't ever have to add a source path. If you're using a
> modern compiler, and debugging something built locally, and not using
> certain kinds of include path constructs (which is unambiguously an
> open, and recently discussed, bug in GDB) then GDB will Just Find
> Things.
That hasn't changed. The compiler can't tell the debugger where to find
its script files though.
> I don't find it intuitive that the same path should be overloaded this
> way, and it makes changing the source searching algorithm even more
> complicated. However, I'd like to know if any other GDB maintainers
> have an opinion on this before I ask you to modify the patch.
I'm not sure a users find it intuitive when they tell a tool to search a
directory and then it ignores that directory because there was another
way to tell the tool to search that directory, IYSWIM.
I see your point about changing the search algorithm though. Although
even then, it might be more intuitive to always use the same algorithm
for both. Is it likely to change?
Whatever though, as long as I get a way to search for script files I'm
not that fussed.
Andrew
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 20:12 ` Andrew STUBBS
@ 2005-11-25 21:26 ` Daniel Jacobowitz
0 siblings, 0 replies; 21+ messages in thread
From: Daniel Jacobowitz @ 2005-11-25 21:26 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: Eli Zaretskii, gdb-patches
On Fri, Nov 25, 2005 at 06:30:54PM +0000, Andrew STUBBS wrote:
> I see your point about changing the search algorithm though. Although
> even then, it might be more intuitive to always use the same algorithm
> for both. Is it likely to change?
Very. That search algorithm has (should have) more concepts of
"directory" to deal with than apply to scripts:
- compilation directory can be absolute or relative
- filename can be absolute, relative, or basename
- Paths to include files can be relative to compilation directory
or including file in some cases.
As said, I'll come back to this patch in a couple of days; let's see if
anyone else has a preference.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 18:12 ` Daniel Jacobowitz
2005-11-25 18:33 ` Andrew STUBBS
@ 2005-11-25 21:43 ` Eli Zaretskii
1 sibling, 0 replies; 21+ messages in thread
From: Eli Zaretskii @ 2005-11-25 21:43 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: gdb-patches
> Date: Fri, 25 Nov 2005 12:57:35 -0500
> From: Daniel Jacobowitz <drow@false.org>
> Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sources.redhat.com
>
> Could you explain why you used the source path to search for scripts,
> instead of a separate search path? Was it just because it was handy?
> Are scripts likely to be in manually-added directories on the source
> search path?
Scripts are likely to be where the sources are. .gdbinit, for one, is
frequently found there.
Whether manually-added source directories match that description is
another question.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 18:33 ` Andrew STUBBS
2005-11-25 18:39 ` Daniel Jacobowitz
@ 2005-11-25 21:56 ` Eli Zaretskii
1 sibling, 0 replies; 21+ messages in thread
From: Eli Zaretskii @ 2005-11-25 21:56 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: drow, gdb-patches
> Date: Fri, 25 Nov 2005 18:07:58 +0000
> From: Andrew STUBBS <andrew.stubbs@st.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sources.redhat.com
>
> If you wish I can split it out into a new list, with new commands, new
> command-line options and new documentation.
I don't like the idea of adding yet another search path.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 18:39 ` Daniel Jacobowitz
2005-11-25 20:12 ` Andrew STUBBS
@ 2005-11-25 22:33 ` Eli Zaretskii
2005-11-28 19:34 ` Andrew STUBBS
1 sibling, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2005-11-25 22:33 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew STUBBS
> Date: Fri, 25 Nov 2005 13:17:35 -0500
> From: Daniel Jacobowitz <drow@false.org>
> Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sources.redhat.com
>
> Most users don't ever have to add a source path. If you're using a
> modern compiler, and debugging something built locally, and not using
> certain kinds of include path constructs (which is unambiguously an
> open, and recently discussed, bug in GDB) then GDB will Just Find
> Things.
Would it be reasonable to make GDB look for scripts in the source file
directories recorded in the debug info? Assuming you accept the
argument that scripts are usually in the source tree, that sounds
plausible, no?
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-25 22:33 ` Eli Zaretskii
@ 2005-11-28 19:34 ` Andrew STUBBS
0 siblings, 0 replies; 21+ messages in thread
From: Andrew STUBBS @ 2005-11-28 19:34 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Eli Zaretskii wrote:
>>Date: Fri, 25 Nov 2005 13:17:35 -0500
>>From: Daniel Jacobowitz <drow@false.org>
>>Cc: Eli Zaretskii <eliz@gnu.org>, gdb-patches@sources.redhat.com
>>
>>Most users don't ever have to add a source path. If you're using a
>>modern compiler, and debugging something built locally, and not using
>>certain kinds of include path constructs (which is unambiguously an
>>open, and recently discussed, bug in GDB) then GDB will Just Find
>>Things.
>
>
> Would it be reasonable to make GDB look for scripts in the source file
> directories recorded in the debug info? Assuming you accept the
> argument that scripts are usually in the source tree, that sounds
> plausible, no?
>
The scripts I am interested in finding are *not* in the source tree.
They are in a 'manually added' directory added from the command line
with the -d switch.
Andrew
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2005-11-18 15:54 ` Andrew STUBBS
2005-11-25 18:02 ` Andrew STUBBS
2005-11-25 18:12 ` Daniel Jacobowitz
@ 2006-01-12 0:09 ` Andrew STUBBS
2006-01-22 20:40 ` Daniel Jacobowitz
2 siblings, 1 reply; 21+ messages in thread
From: Andrew STUBBS @ 2006-01-12 0:09 UTC (permalink / raw)
To: gdb-patches
Hi,
This one has been on hold for some time now.
IIRC, Daniel wasn't happy about it sharing the same search path and Eli
didn't want yet another one.
I am happy to go either way, as long as it works. Which should it be?
May I check it in as it is or add another search path with another
command and option to go with it?
Thanks
Andrew
Andrew Stubbs wrote:
> Eli Zaretskii wrote:
>
>>> + stream = fdopen (fd, "r");
>>
>>
>> ^^^
>> Shouldn't this be FOPEN_RT, like what was used in the call to fopen in
>> the original code?
>
>
> Quite so. I don't know where that came from.
>
> Update attached.
>
> Andrew Stubbs
>
>
> ------------------------------------------------------------------------
>
> 2005-11-17 Andrew Stubbs <andrew.stubbs@st.com>
>
> * cli-cmds.c: Include fcntl.h.
> (source_command): Use the GDB search path to find script files.
>
> doc/
> * gdb.texinfo (Choosing files): Mention that -directory is used
> for script files.
> (Specifying source directories): Likewise.
> (Command files): Explain how script files are found.
>
>
> Index: src/gdb/cli/cli-cmds.c
> ===================================================================
> --- src.orig/gdb/cli/cli-cmds.c 2005-11-18 11:22:08.000000000 +0000
> +++ src/gdb/cli/cli-cmds.c 2005-11-18 14:43:08.000000000 +0000
> @@ -50,6 +50,8 @@
> #include "tui/tui.h" /* For tui_active et.al. */
> #endif
>
> +#include <fcntl.h>
> +
> /* Prototypes for local command functions */
>
> static void complete_command (char *, int);
> @@ -433,6 +435,8 @@ source_command (char *args, int from_tty
> char *file = args;
> char *minusv=NULL;
> int old_source_verbose = source_verbose;
> + char *full_pathname = NULL;
> + int fd;
>
> /* -v causes the source command to run in verbose mode.
> We still have to be able to handle filenames with spaces. */
> @@ -486,8 +490,18 @@ source_command (char *args, int from_tty
> file = tilde_expand (file);
> old_cleanups = make_cleanup (xfree, file);
>
> - stream = fopen (file, FOPEN_RT);
> - if (!stream)
> + /* Search for and open 'file' on the search path used for source
> + files. Put the full location in 'full_pathname'. */
> + fd = openp (source_path, OPF_TRY_CWD_FIRST,
> + file, O_RDONLY, 0, &full_pathname);
> +
> + /* Use the full path name, if it is found. */
> + if (full_pathname != NULL && fd != -1)
> + {
> + file = full_pathname;
> + }
> +
> + if (fd == -1)
> {
> source_verbose = old_source_verbose;
> if (from_tty)
> @@ -496,6 +510,7 @@ source_command (char *args, int from_tty
> return;
> }
>
> + stream = fdopen (fd, FOPEN_RT);
> script_from_file (stream, file);
>
> do_cleanups (old_cleanups);
> Index: src/gdb/doc/gdb.texinfo
> ===================================================================
> --- src.orig/gdb/doc/gdb.texinfo 2005-11-18 11:22:09.000000000 +0000
> +++ src/gdb/doc/gdb.texinfo 2005-11-18 12:31:33.000000000 +0000
> @@ -951,7 +951,7 @@ also be interleaved with @samp{-command}
> @itemx -d @var{directory}
> @cindex @code{--directory}
> @cindex @code{-d}
> -Add @var{directory} to the path to search for source files.
> +Add @var{directory} to the path to search for source and script files.
>
> @item -r
> @itemx -readnow
> @@ -4830,6 +4830,9 @@ When you start @value{GDBN}, its source
> and @samp{cwd}, in that order.
> To add other directories, use the @code{directory} command.
>
> +The search path is used to find both program source files and @value{GDBN}
> +script files (read using the @samp{-command} option and @samp{source} command).
> +
> @table @code
> @item directory @var{dirname} @dots{}
> @item dir @var{dirname} @dots{}
> @@ -15997,6 +16000,9 @@ The lines in a command file are executed
> printed as they are executed. An error in any command terminates
> execution of the command file and control is returned to the console.
>
> +@value{GDBN} searches for @var{filename} in the current directory and then
> +on the search path (specified with the @samp{directory} command).
> +
> If @code{-v}, for verbose mode, is given then each command will
> be displayed as it is executed. The option may be given before or after
> @var{filename}, but will be interpreted as part of the filename anywhere else.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2006-01-12 0:09 ` Andrew STUBBS
@ 2006-01-22 20:40 ` Daniel Jacobowitz
2006-01-23 16:29 ` Andrew STUBBS
0 siblings, 1 reply; 21+ messages in thread
From: Daniel Jacobowitz @ 2006-01-22 20:40 UTC (permalink / raw)
To: gdb-patches
On Wed, Jan 11, 2006 at 07:11:08PM +0000, Andrew STUBBS wrote:
> Hi,
>
> This one has been on hold for some time now.
>
> IIRC, Daniel wasn't happy about it sharing the same search path and Eli
> didn't want yet another one.
>
> I am happy to go either way, as long as it works. Which should it be?
> May I check it in as it is or add another search path with another
> command and option to go with it?
The patch is OK as-is. Thanks.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2006-01-22 20:40 ` Daniel Jacobowitz
@ 2006-01-23 16:29 ` Andrew STUBBS
2006-01-23 17:41 ` Andrew STUBBS
0 siblings, 1 reply; 21+ messages in thread
From: Andrew STUBBS @ 2006-01-23 16:29 UTC (permalink / raw)
To: gdb-patches
Daniel Jacobowitz wrote:
> The patch is OK as-is. Thanks.
Thanks, committed.
Andrew
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Use search path for scripts
2006-01-23 16:29 ` Andrew STUBBS
@ 2006-01-23 17:41 ` Andrew STUBBS
0 siblings, 0 replies; 21+ messages in thread
From: Andrew STUBBS @ 2006-01-23 17:41 UTC (permalink / raw)
Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 238 bytes --]
Andrew Stubbs wrote:
> Daniel Jacobowitz wrote:
>> The patch is OK as-is. Thanks.
>
> Thanks, committed.
I should probably post the final patch since I had to modify it slightly
to apply cleanly to the updated tree.
Attached
Andrew
[-- Attachment #2: search-path.patch --]
[-- Type: text/plain, Size: 3282 bytes --]
2006-01-23 Andrew Stubbs <andrew.stubbs@st.com>
* cli/cli-cmds.c: Include fcntl.h.
(source_command): Use the GDB search path to find script files.
doc/
* gdb.texinfo (Choosing files): Mention that -directory is used
for script files.
(Specifying source directories): Likewise.
(Command files): Explain how script files are found.
Index: src/gdb/cli/cli-cmds.c
===================================================================
--- src.orig/gdb/cli/cli-cmds.c 2006-01-23 15:54:23.000000000 +0000
+++ src/gdb/cli/cli-cmds.c 2006-01-23 15:56:11.000000000 +0000
@@ -51,6 +51,8 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#include <fcntl.h>
+
/* Prototypes for local command functions */
static void complete_command (char *, int);
@@ -427,6 +429,8 @@ source_command (char *args, int from_tty
FILE *stream;
struct cleanup *old_cleanups;
char *file = args;
+ char *full_pathname = NULL;
+ int fd;
if (file == NULL)
{
@@ -436,8 +440,18 @@ source_command (char *args, int from_tty
file = tilde_expand (file);
old_cleanups = make_cleanup (xfree, file);
- stream = fopen (file, FOPEN_RT);
- if (!stream)
+ /* Search for and open 'file' on the search path used for source
+ files. Put the full location in 'full_pathname'. */
+ fd = openp (source_path, OPF_TRY_CWD_FIRST,
+ file, O_RDONLY, 0, &full_pathname);
+
+ /* Use the full path name, if it is found. */
+ if (full_pathname != NULL && fd != -1)
+ {
+ file = full_pathname;
+ }
+
+ if (fd == -1)
{
if (from_tty)
perror_with_name (file);
@@ -445,6 +459,7 @@ source_command (char *args, int from_tty
return;
}
+ stream = fdopen (fd, FOPEN_RT);
script_from_file (stream, file);
do_cleanups (old_cleanups);
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo 2006-01-23 15:54:24.000000000 +0000
+++ src/gdb/doc/gdb.texinfo 2006-01-23 15:57:28.000000000 +0000
@@ -950,7 +950,7 @@ also be interleaved with @samp{-command}
@itemx -d @var{directory}
@cindex @code{--directory}
@cindex @code{-d}
-Add @var{directory} to the path to search for source files.
+Add @var{directory} to the path to search for source and script files.
@item -r
@itemx -readnow
@@ -5018,6 +5018,9 @@ When you start @value{GDBN}, its source
and @samp{cwd}, in that order.
To add other directories, use the @code{directory} command.
+The search path is used to find both program source files and @value{GDBN}
+script files (read using the @samp{-command} option and @samp{source} command).
+
@table @code
@item directory @var{dirname} @dots{}
@item dir @var{dirname} @dots{}
@@ -16210,6 +16213,9 @@ unless the order of execution is changed
printed as they are executed. An error in any command terminates
execution of the command file and control is returned to the console.
+@value{GDBN} searches for @var{filename} in the current directory and then
+on the search path (specified with the @samp{directory} command).
+
Commands that would ask for confirmation if used interactively proceed
without asking when used in a command file. Many @value{GDBN} commands that
normally print messages to say what they are doing omit the messages
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2006-01-23 17:41 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-16 19:36 [PATCH] Use search path for scripts Andrew STUBBS
2005-11-17 0:04 ` Eli Zaretskii
2005-11-17 12:41 ` Andrew STUBBS
2005-11-17 19:42 ` Eli Zaretskii
2005-11-18 13:23 ` Andrew STUBBS
2005-11-18 14:53 ` Eli Zaretskii
2005-11-18 15:54 ` Andrew STUBBS
2005-11-25 18:02 ` Andrew STUBBS
2005-11-25 18:12 ` Daniel Jacobowitz
2005-11-25 18:33 ` Andrew STUBBS
2005-11-25 18:39 ` Daniel Jacobowitz
2005-11-25 20:12 ` Andrew STUBBS
2005-11-25 21:26 ` Daniel Jacobowitz
2005-11-25 22:33 ` Eli Zaretskii
2005-11-28 19:34 ` Andrew STUBBS
2005-11-25 21:56 ` Eli Zaretskii
2005-11-25 21:43 ` Eli Zaretskii
2006-01-12 0:09 ` Andrew STUBBS
2006-01-22 20:40 ` Daniel Jacobowitz
2006-01-23 16:29 ` Andrew STUBBS
2006-01-23 17:41 ` Andrew STUBBS
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox