[RFA] Add -s option to source command.

H.J. Lu hjl.tools@gmail.com
Sat Apr 17 15:20:00 GMT 2010


On Tue, Apr 6, 2010 at 2:57 PM, Doug Evans <dje@google.com> wrote:
> Hi.
>
> In a big source tree with multiple disparate components it's useful to be
> able to load scripts without having to type full path names.
>
> This patch adds a -s option to the source command to make it search
> for the script in the source search path even if the script name specifies
> a directory.
> For example, adding the top level source directory to the source search path
> lets one load scripts from any component by only typing the path from
> the top directory.
>
> I thought of simply extending the source command to do the search anyway
> but the current code explicitly doesn't do that to make "./foo" only mean
> "foo" in the current directory.  Granted, the comment (see openp) is
> referring to executables, but it's not clear to me it shouldn't also
> apply to scripts.  Plus, "source /absolute/path" should probably not
> scan the search path by default.
> So I went with adding an option.
>
> This patch also does a minor reorg of find_and_open_script so that
> it's useful in a subsequent patch I'll be submitting.
> I think the reorg is useful in itself, e.g. removing the from_tty
> arg to find_and_open_script, so I've including it here.
>
> Included are doc and testcase additions.
>
> Ok to check in?
>
> 2010-04-06  Doug Evans  <dje@google.com>
>
>        Add -s option to source command.
>        * cli/cli-cmds.c (find_and_open_script): Add function comment.
>        Delete from_tty and cleanupp args.  Split filep arg into file and
>        full_pathp.  New arg search_path.
>        (source_script_from_stream): New function.
>        (source_script_with_search): New function.
>        (source_script): Rewrite.
>        (source_command): Parse "-s" option.
>        (init_cli_cmds): Add "-s" docs to source command help.
>        * python/python.c (source_python_script): Make file arg a const char *.
>        Don't call fclose, leave for caller.
>        * python/python.h (source_python_script): Update.
>
>        testsuite/
>        * gdb.base/source-test.gdb: New file.
>        * gdb.base/source.exp: Add tests for "source -v" and "source -s".
>
>        doc/
>        * gdb.texinfo (Command Files): Add docs for new "source -s" option.
>

This caused:

help source^M
Read commands from a file named FILE.^M
^M
Usage: source [-s] [-v] FILE^M
-s: search for the script in the source search path,^M
    even if FILE contains directories.^M
-v: each command in FILE is echoed as it is executed.^M
^M
Note that the file ".gdbinit" is read automatically in this way^M
when GDB is started.^M
(gdb) FAIL: gdb.base/help.exp: help source



-- 
H.J.



More information about the Gdb-patches mailing list