diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2002-12-13 17:00:22 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2002-12-13 17:00:22 +0000 |
commit | 068890be59b98a2f5e269cbc070f6d3f36676aca (patch) | |
tree | dc5e7aebf79574e2b9f44da2a30b15bc91d3f112 /gdb/mi | |
parent | c689142becccac9fa3b1f9833243048a50396ffe (diff) | |
download | gdb-068890be59b98a2f5e269cbc070f6d3f36676aca.zip gdb-068890be59b98a2f5e269cbc070f6d3f36676aca.tar.gz gdb-068890be59b98a2f5e269cbc070f6d3f36676aca.tar.bz2 |
2002-12-13 Jeff Johnston <jjohnstn@redhat.com>
* mi-cmds.c (-environment-directory) Change to use mi_cmd_env_dir,
(-environment-cd): Change to use mi_cmd_env_cd,.
(-environment-pwd): Change to use mi_cmd_env_pwd.
(-environment-path): Change to use mi_cmd_env_path.
* mi-cmds.h (mi_cmd_env_cd, mi_cmd_env_dir): New prototypes.
(mi_cmd_env_path, mi_cmd_env_pwd): Ditto.
* mi-cmd-env.c: New file. Part of fix for PR gdb/741.
* gdbmi.texinfo (environment-cd): Update output and example.
(environment-pwd): Ditto.
(environment-dir): Update output, description, and examples.
(environment-path): Ditto.
Diffstat (limited to 'gdb/mi')
-rw-r--r-- | gdb/mi/ChangeLog | 14 | ||||
-rw-r--r-- | gdb/mi/gdbmi.texinfo | 62 | ||||
-rw-r--r-- | gdb/mi/mi-cmd-env.c | 254 | ||||
-rw-r--r-- | gdb/mi/mi-cmds.c | 8 | ||||
-rw-r--r-- | gdb/mi/mi-cmds.h | 4 |
5 files changed, 330 insertions, 12 deletions
diff --git a/gdb/mi/ChangeLog b/gdb/mi/ChangeLog index f7e91b6..18f50bb 100644 --- a/gdb/mi/ChangeLog +++ b/gdb/mi/ChangeLog @@ -1,3 +1,17 @@ +2002-12-13 Jeff Johnston <jjohnstn@redhat.com> + + * mi-cmds.c (-environment-directory) Change to use mi_cmd_env_dir, + (-environment-cd): Change to use mi_cmd_env_cd,. + (-environment-pwd): Change to use mi_cmd_env_pwd. + (-environment-path): Change to use mi_cmd_env_path. + * mi-cmds.h (mi_cmd_env_cd, mi_cmd_env_dir): New prototypes. + (mi_cmd_env_path, mi_cmd_env_pwd): Ditto. + * mi-cmd-env.c: New file. Part of fix for PR gdb/741. + * gdbmi.texinfo (environment-cd): Update output and example. + (environment-pwd): Ditto. + (environment-dir): Update output, description, and examples. + (environment-path): Ditto. + 2002-11-29 Andrew Cagney <ac131313@redhat.com> * mi/mi-cmd-stack.c, mi/mi-main.c: Update to use diff --git a/gdb/mi/gdbmi.texinfo b/gdb/mi/gdbmi.texinfo index d64328c..4cf34c2 100644 --- a/gdb/mi/gdbmi.texinfo +++ b/gdb/mi/gdbmi.texinfo @@ -1665,10 +1665,25 @@ The corresponding @value{GDBN} command is @samp{cd}. @subsubheading Synopsis @example - -environment-directory @var{pathdir} + -environment-directory [ -r ] [ @var{pathdir} ]+ @end example -Add directory @var{pathdir} to beginning of search path for source files. +Add directories @var{pathdir} to beginning of search path for source files. +If the @samp{-r} option is used, the search path is reset to the default +search path. If directories @var{pathdir} are supplied in addition to the +@samp{-r} option, the search path is first reset and then addition +occurs as normal. +Multiple directories may be specified, separated by blanks. Specifying +multiple directories in a single command +results in the directories added to the beginning of the +search path in the same order they were presented in the command. +If blanks are needed as +part of a directory name, double-quotes should be used around +the name. In the command output, the path will show up separated +by the system directory-separator character. The directory-seperator +character must not be used +in any directory name. +If no directories are specified, the current search path is displayed. @subsubheading @value{GDBN} Command @@ -1679,7 +1694,16 @@ The corresponding @value{GDBN} command is @samp{dir}. @smallexample (@value{GDBP}) -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb -^done +^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd" +(@value{GDBP}) +-environment-directory "" +^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd" +(@value{GDBP}) +-environment-directory -r /home/jjohnstn/src/gdb /usr/src +^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd" +(@value{GDBP}) +-environment-directory -r +^done,source-path="$cdir:$cwd" (@value{GDBP}) @end smallexample @@ -1690,10 +1714,27 @@ The corresponding @value{GDBN} command is @samp{dir}. @subsubheading Synopsis @example - -environment-path ( @var{pathdir} )+ + -environment-path [ -r ] [ @var{pathdir} ]+ @end example Add directories @var{pathdir} to beginning of search path for object files. +If the @samp{-r} option is used, the search path is reset to the original +search path that existed at gdb start-up. If directories @var{pathdir} are +supplied in addition to the +@samp{-r} option, the search path is first reset and then addition +occurs as normal. +Multiple directories may be specified, separated by blanks. Specifying +multiple directories in a single command +results in the directories added to the beginning of the +search path in the same order they were presented in the command. +If blanks are needed as +part of a directory name, double-quotes should be used around +the name. In the command output, the path will show up separated +by the system directory-separator character. The directory-seperator +character must not be used +in any directory name. +If no directories are specified, the current path is displayed. + @subsubheading @value{GDBN} Command @@ -1703,8 +1744,14 @@ The corresponding @value{GDBN} command is @samp{path}. @smallexample (@value{GDBP}) --environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb -^done +-environment-path +^done,path="/usr/bin" +(@value{GDBP}) +-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin +^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin" +(@value{GDBP}) +-environment-path -r /usr/local/bin +^done,path="/usr/local/bin:/usr/bin" (@value{GDBP}) @end smallexample @@ -1729,8 +1776,7 @@ The corresponding @value{GDBN} command is @samp{pwd}. @smallexample (@value{GDBP}) -environment-pwd -~Working directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb. -^done +^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb" (@value{GDBP}) @end smallexample diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c new file mode 100644 index 0000000..104a73b --- /dev/null +++ b/gdb/mi/mi-cmd-env.c @@ -0,0 +1,254 @@ +/* MI Command Set - environment commands. + Copyright 2002 Free Software Foundation, Inc. + Contributed by Red Hat Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <string.h> +#include <sys/stat.h> + +#include "defs.h" +#include "inferior.h" +#include "value.h" +#include "mi-out.h" +#include "mi-cmds.h" +#include "mi-getopt.h" +#include "symtab.h" +#include "target.h" +#include "environ.h" +#include "command.h" +#include "ui-out.h" +#include "top.h" + +static void env_cli_command (const char *cli, char *args); +static void env_mod_path (char *dirname, char **which_path); +extern void _initialize_mi_cmd_env (void); + +static const char path_var_name[] = "PATH"; +static char *orig_path = NULL; + +/* The following is copied from mi-main.c so for m1 and below we + can perform old behavior and use cli commands. */ +static void +env_execute_cli_command (const char *cli, char *args) +{ + if (cli != 0) + { + struct cleanup *old_cleanups; + char *run; + xasprintf (&run, cli, args); + old_cleanups = make_cleanup (xfree, run); + execute_command ( /*ui */ run, 0 /*from_tty */ ); + do_cleanups (old_cleanups); + return; + } +} + + +/* Print working directory. */ +enum mi_cmd_result +mi_cmd_env_pwd (char *command, char **argv, int argc) +{ + if (argc > 0) + error ("mi_cmd_env_pwd: No arguments required"); + + if (mi_version (uiout) < 2) + { + env_execute_cli_command ("pwd", NULL); + return MI_CMD_DONE; + } + + /* Otherwise the mi level is 2 or higher. */ + + getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); + ui_out_field_string (uiout, "cwd", gdb_dirbuf); + + return MI_CMD_DONE; +} + +/* Change working directory. */ +enum mi_cmd_result +mi_cmd_env_cd (char *command, char **argv, int argc) +{ + if (argc == 0 || argc > 1) + error ("mi_cmd_env_cd: Usage DIRECTORY"); + + env_execute_cli_command ("cd %s", argv[0]); + + return MI_CMD_DONE; +} + +static void +env_mod_path (char *dirname, char **which_path) +{ + if (dirname == 0 || dirname[0] == '\0') + return; + + /* Call add_path with last arg 0 to indicate not to parse for + separator characters. */ + add_path (dirname, which_path, 0); +} + +/* Add one or more directories to start of executable search path. */ +enum mi_cmd_result +mi_cmd_env_path (char *command, char **argv, int argc) +{ + char *exec_path; + char *env; + int reset = 0; + int optind = 0; + int i; + char *optarg; + enum opt + { + RESET_OPT + }; + static struct mi_opt opts[] = + { + {"r", RESET_OPT, 0}, + 0 + }; + + dont_repeat (); + + if (mi_version (uiout) < 2) + { + for (i = argc - 1; i >= 0; --i) + env_execute_cli_command ("path %s", argv[i]); + return MI_CMD_DONE; + } + + /* Otherwise the mi level is 2 or higher. */ + while (1) + { + int opt = mi_getopt ("mi_cmd_env_path", argc, argv, opts, + &optind, &optarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case RESET_OPT: + reset = 1; + break; + } + } + argv += optind; + argc -= optind; + + + if (reset) + { + /* Reset implies resetting to original path first. */ + exec_path = xstrdup (orig_path); + } + else + { + /* Otherwise, get current path to modify. */ + env = get_in_environ (inferior_environ, path_var_name); + + /* Can be null if path is not set. */ + if (!env) + env = ""; + exec_path = xstrdup (env); + } + + for (i = argc - 1; i >= 0; --i) + env_mod_path (argv[i], &exec_path); + + set_in_environ (inferior_environ, path_var_name, exec_path); + xfree (exec_path); + env = get_in_environ (inferior_environ, path_var_name); + ui_out_field_string (uiout, "path", env); + + return MI_CMD_DONE; +} + +/* Add zero or more directories to the front of the source path. */ +enum mi_cmd_result +mi_cmd_env_dir (char *command, char **argv, int argc) +{ + int i; + int optind = 0; + int reset = 0; + char *optarg; + enum opt + { + RESET_OPT + }; + static struct mi_opt opts[] = + { + {"r", RESET_OPT, 0}, + 0 + }; + + dont_repeat (); + + if (mi_version (uiout) < 2) + { + for (i = argc - 1; i >= 0; --i) + env_execute_cli_command ("dir %s", argv[i]); + return MI_CMD_DONE; + } + + /* Otherwise mi level is 2 or higher. */ + while (1) + { + int opt = mi_getopt ("mi_cmd_env_dir", argc, argv, opts, + &optind, &optarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case RESET_OPT: + reset = 1; + break; + } + } + argv += optind; + argc -= optind; + + if (reset) + { + /* Reset means setting to default path first. */ + xfree (source_path); + init_source_path (); + } + + for (i = argc - 1; i >= 0; --i) + env_mod_path (argv[i], &source_path); + init_last_source_visited (); + + ui_out_field_string (uiout, "source-path", source_path); + forget_cached_source_info (); + + return MI_CMD_DONE; +} + +void +_initialize_mi_cmd_env (void) +{ + char *env; + + /* We want original execution path to reset to, if desired later. */ + env = get_in_environ (inferior_environ, path_var_name); + + /* Can be null if path is not set. */ + if (!env) + env = ""; + orig_path = xstrdup (env); +} diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 233d06b..699937d 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -56,10 +56,10 @@ struct mi_cmd mi_cmds[] = {"display-enable", 0, 0}, {"display-insert", 0, 0}, {"display-list", 0, 0}, - {"environment-cd", "cd %s", 0}, - {"environment-directory", "dir %s", 0}, - {"environment-path", "path %s", 0}, - {"environment-pwd", "pwd", 0}, + {"environment-cd", 0, 0, mi_cmd_env_cd}, + {"environment-directory", 0, 0, mi_cmd_env_dir}, + {"environment-path", 0, 0, mi_cmd_env_path}, + {"environment-pwd", 0, 0, mi_cmd_env_pwd}, {"exec-abort", 0, 0}, {"exec-arguments", "set args %s", 0}, {"exec-continue", 0, mi_cmd_exec_continue}, diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h index 88775e6..f4fe64d 100644 --- a/gdb/mi/mi-cmds.h +++ b/gdb/mi/mi-cmds.h @@ -64,6 +64,10 @@ extern mi_cmd_argv_ftype mi_cmd_data_list_changed_registers; extern mi_cmd_argv_ftype mi_cmd_data_read_memory; extern mi_cmd_argv_ftype mi_cmd_data_write_memory; extern mi_cmd_argv_ftype mi_cmd_data_write_register_values; +extern mi_cmd_argv_ftype mi_cmd_env_cd; +extern mi_cmd_argv_ftype mi_cmd_env_dir; +extern mi_cmd_argv_ftype mi_cmd_env_path; +extern mi_cmd_argv_ftype mi_cmd_env_pwd; extern mi_cmd_args_ftype mi_cmd_exec_continue; extern mi_cmd_args_ftype mi_cmd_exec_finish; extern mi_cmd_args_ftype mi_cmd_exec_next; |