1 /* MI Command Set - environment commands.
3 Copyright (C) 2002, 2003, 2004, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 Contributed by Red Hat Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "mi-getopt.h"
36 #include "gdb_string.h"
39 static void env_mod_path (char *dirname
, char **which_path
);
40 extern void _initialize_mi_cmd_env (void);
42 static const char path_var_name
[] = "PATH";
43 static char *orig_path
= NULL
;
45 /* The following is copied from mi-main.c so for m1 and below we can
46 perform old behavior and use cli commands. If ARGS is non-null,
47 append it to the CMD. */
49 env_execute_cli_command (const char *cmd
, const char *args
)
53 struct cleanup
*old_cleanups
;
56 run
= xstrprintf ("%s %s", cmd
, args
);
59 old_cleanups
= make_cleanup (xfree
, run
);
60 execute_command ( /*ui */ run
, 0 /*from_tty */ );
61 do_cleanups (old_cleanups
);
67 /* Print working directory. */
69 mi_cmd_env_pwd (char *command
, char **argv
, int argc
)
72 error (_("mi_cmd_env_pwd: No arguments required"));
74 if (mi_version (uiout
) < 2)
76 env_execute_cli_command ("pwd", NULL
);
80 /* Otherwise the mi level is 2 or higher. */
82 if (! getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
)))
83 error (_("mi_cmd_env_pwd: error finding name of working directory: %s"),
84 safe_strerror (errno
));
86 ui_out_field_string (uiout
, "cwd", gdb_dirbuf
);
89 /* Change working directory. */
91 mi_cmd_env_cd (char *command
, char **argv
, int argc
)
93 if (argc
== 0 || argc
> 1)
94 error (_("mi_cmd_env_cd: Usage DIRECTORY"));
96 env_execute_cli_command ("cd", argv
[0]);
100 env_mod_path (char *dirname
, char **which_path
)
102 if (dirname
== 0 || dirname
[0] == '\0')
105 /* Call add_path with last arg 0 to indicate not to parse for
106 separator characters. */
107 add_path (dirname
, which_path
, 0);
110 /* Add one or more directories to start of executable search path. */
112 mi_cmd_env_path (char *command
, char **argv
, int argc
)
124 static struct mi_opt opts
[] =
132 if (mi_version (uiout
) < 2)
134 for (i
= argc
- 1; i
>= 0; --i
)
135 env_execute_cli_command ("path", argv
[i
]);
139 /* Otherwise the mi level is 2 or higher. */
142 int opt
= mi_getopt ("mi_cmd_env_path", argc
, argv
, opts
,
146 switch ((enum opt
) opt
)
159 /* Reset implies resetting to original path first. */
160 exec_path
= xstrdup (orig_path
);
164 /* Otherwise, get current path to modify. */
165 env
= get_in_environ (inferior_environ
, path_var_name
);
167 /* Can be null if path is not set. */
170 exec_path
= xstrdup (env
);
173 for (i
= argc
- 1; i
>= 0; --i
)
174 env_mod_path (argv
[i
], &exec_path
);
176 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
178 env
= get_in_environ (inferior_environ
, path_var_name
);
179 ui_out_field_string (uiout
, "path", env
);
182 /* Add zero or more directories to the front of the source path. */
184 mi_cmd_env_dir (char *command
, char **argv
, int argc
)
194 static struct mi_opt opts
[] =
202 if (mi_version (uiout
) < 2)
204 for (i
= argc
- 1; i
>= 0; --i
)
205 env_execute_cli_command ("dir", argv
[i
]);
209 /* Otherwise mi level is 2 or higher. */
212 int opt
= mi_getopt ("mi_cmd_env_dir", argc
, argv
, opts
,
216 switch ((enum opt
) opt
)
228 /* Reset means setting to default path first. */
233 for (i
= argc
- 1; i
>= 0; --i
)
234 env_mod_path (argv
[i
], &source_path
);
235 init_last_source_visited ();
237 ui_out_field_string (uiout
, "source-path", source_path
);
238 forget_cached_source_info ();
241 /* Set the inferior terminal device name. */
243 mi_cmd_inferior_tty_set (char *command
, char **argv
, int argc
)
245 set_inferior_io_terminal (argv
[0]);
248 /* Print the inferior terminal device name */
250 mi_cmd_inferior_tty_show (char *command
, char **argv
, int argc
)
252 const char *inferior_io_terminal
= get_inferior_io_terminal ();
254 if ( !mi_valid_noargs ("mi_cmd_inferior_tty_show", argc
, argv
))
255 error (_("mi_cmd_inferior_tty_show: Usage: No args"));
257 if (inferior_io_terminal
)
258 ui_out_field_string (uiout
, "inferior_tty_terminal", inferior_io_terminal
);
262 _initialize_mi_cmd_env (void)
266 /* We want original execution path to reset to, if desired later. */
267 env
= get_in_environ (inferior_environ
, path_var_name
);
269 /* Can be null if path is not set. */
272 orig_path
= xstrdup (env
);
This page took 0.040071 seconds and 4 git commands to generate.