1 /* MI Command Set - environment commands.
3 Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
5 Contributed by Red Hat Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
29 #include "mi-getopt.h"
37 #include "gdb_string.h"
40 static void env_mod_path (char *dirname
, char **which_path
);
41 extern void _initialize_mi_cmd_env (void);
43 static const char path_var_name
[] = "PATH";
44 static char *orig_path
= NULL
;
46 /* The following is copied from mi-main.c so for m1 and below we can
47 perform old behavior and use cli commands. If ARGS is non-null,
48 append it to the CMD. */
50 env_execute_cli_command (const char *cmd
, const char *args
)
54 struct cleanup
*old_cleanups
;
57 run
= xstrprintf ("%s %s", cmd
, args
);
60 old_cleanups
= make_cleanup (xfree
, run
);
61 execute_command ( /*ui */ run
, 0 /*from_tty */ );
62 do_cleanups (old_cleanups
);
68 /* Print working directory. */
70 mi_cmd_env_pwd (char *command
, char **argv
, int argc
)
73 error (_("mi_cmd_env_pwd: No arguments required"));
75 if (mi_version (uiout
) < 2)
77 env_execute_cli_command ("pwd", NULL
);
81 /* Otherwise the mi level is 2 or higher. */
83 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
84 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]);
102 env_mod_path (char *dirname
, char **which_path
)
104 if (dirname
== 0 || dirname
[0] == '\0')
107 /* Call add_path with last arg 0 to indicate not to parse for
108 separator characters. */
109 add_path (dirname
, which_path
, 0);
112 /* Add one or more directories to start of executable search path. */
114 mi_cmd_env_path (char *command
, char **argv
, int argc
)
126 static struct mi_opt opts
[] =
134 if (mi_version (uiout
) < 2)
136 for (i
= argc
- 1; i
>= 0; --i
)
137 env_execute_cli_command ("path", argv
[i
]);
141 /* Otherwise the mi level is 2 or higher. */
144 int opt
= mi_getopt ("mi_cmd_env_path", argc
, argv
, opts
,
148 switch ((enum opt
) opt
)
161 /* Reset implies resetting to original path first. */
162 exec_path
= xstrdup (orig_path
);
166 /* Otherwise, get current path to modify. */
167 env
= get_in_environ (inferior_environ
, path_var_name
);
169 /* Can be null if path is not set. */
172 exec_path
= xstrdup (env
);
175 for (i
= argc
- 1; i
>= 0; --i
)
176 env_mod_path (argv
[i
], &exec_path
);
178 set_in_environ (inferior_environ
, path_var_name
, exec_path
);
180 env
= get_in_environ (inferior_environ
, path_var_name
);
181 ui_out_field_string (uiout
, "path", env
);
186 /* Add zero or more directories to the front of the source path. */
188 mi_cmd_env_dir (char *command
, char **argv
, int argc
)
198 static struct mi_opt opts
[] =
206 if (mi_version (uiout
) < 2)
208 for (i
= argc
- 1; i
>= 0; --i
)
209 env_execute_cli_command ("dir", argv
[i
]);
213 /* Otherwise mi level is 2 or higher. */
216 int opt
= mi_getopt ("mi_cmd_env_dir", argc
, argv
, opts
,
220 switch ((enum opt
) opt
)
232 /* Reset means setting to default path first. */
237 for (i
= argc
- 1; i
>= 0; --i
)
238 env_mod_path (argv
[i
], &source_path
);
239 init_last_source_visited ();
241 ui_out_field_string (uiout
, "source-path", source_path
);
242 forget_cached_source_info ();
247 /* Set the inferior terminal device name. */
249 mi_cmd_inferior_tty_set (char *command
, char **argv
, int argc
)
251 set_inferior_io_terminal (argv
[0]);
256 /* Print the inferior terminal device name */
258 mi_cmd_inferior_tty_show (char *command
, char **argv
, int argc
)
260 const char *inferior_io_terminal
= get_inferior_io_terminal ();
262 if ( !mi_valid_noargs ("mi_cmd_inferior_tty_show", argc
, argv
))
263 error (_("mi_cmd_inferior_tty_show: Usage: No args"));
265 if (inferior_io_terminal
)
266 ui_out_field_string (uiout
, "inferior_tty_terminal", inferior_io_terminal
);
272 _initialize_mi_cmd_env (void)
276 /* We want original execution path to reset to, if desired later. */
277 env
= get_in_environ (inferior_environ
, path_var_name
);
279 /* Can be null if path is not set. */
282 orig_path
= xstrdup (env
);
This page took 0.034249 seconds and 4 git commands to generate.