Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: gdb/mi/mi-cmd-env.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/mi/mi-cmd-disas.c ('k') | gdb/mi/mi-cmd-file.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* MI Command Set - environment commands. 1 /* MI Command Set - environment commands.
2
3 Copyright (C) 2002-2004, 2007-2012 Free Software Foundation, Inc. 2 Copyright (C) 2002-2004, 2007-2012 Free Software Foundation, Inc.
4 3
5 Contributed by Red Hat Inc. 4 Contributed by Red Hat Inc.
6 5
7 This file is part of GDB. 6 This file is part of GDB.
8 7
9 This program is free software; you can redistribute it and/or modify 8 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 9 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or 10 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version. 11 (at your option) any later version.
(...skipping 16 matching lines...) Expand all
29 #include "target.h" 28 #include "target.h"
30 #include "environ.h" 29 #include "environ.h"
31 #include "command.h" 30 #include "command.h"
32 #include "ui-out.h" 31 #include "ui-out.h"
33 #include "top.h" 32 #include "top.h"
34 33
35 #include "gdb_string.h" 34 #include "gdb_string.h"
36 #include "gdb_stat.h" 35 #include "gdb_stat.h"
37 36
38 static void env_mod_path (char *dirname, char **which_path); 37 static void env_mod_path (char *dirname, char **which_path);
38
39 extern void _initialize_mi_cmd_env (void); 39 extern void _initialize_mi_cmd_env (void);
40 40
41 static const char path_var_name[] = "PATH"; 41 static const char path_var_name[] = "PATH";
42 static char *orig_path = NULL; 42 static char *orig_path = NULL;
43 43
44 /* The following is copied from mi-main.c so for m1 and below we can 44 /* The following is copied from mi-main.c so for m1 and below we can
45 perform old behavior and use cli commands. If ARGS is non-null, 45 perform old behavior and use cli commands. If ARGS is non-null,
46 append it to the CMD. */ 46 append it to the CMD. */
47
47 static void 48 static void
48 env_execute_cli_command (const char *cmd, const char *args) 49 env_execute_cli_command (const char *cmd, const char *args)
49 { 50 {
50 if (cmd != 0) 51 if (cmd != 0)
51 { 52 {
52 struct cleanup *old_cleanups; 53 struct cleanup *old_cleanups;
53 char *run; 54 char *run;
54 55
55 if (args != NULL) 56 if (args != NULL)
56 run = xstrprintf ("%s %s", cmd, args); 57 run = xstrprintf ("%s %s", cmd, args);
57 else 58 else
58 run = xstrdup (cmd); 59 run = xstrdup (cmd);
59 old_cleanups = make_cleanup (xfree, run); 60 old_cleanups = make_cleanup (xfree, run);
60 execute_command ( /*ui */ run, 0 /*from_tty */ ); 61 execute_command ( /*ui */ run, 0 /*from_tty */ );
61 do_cleanups (old_cleanups); 62 do_cleanups (old_cleanups);
62 return; 63 return;
63 } 64 }
64 } 65 }
65 66
67 /* Print working directory. */
66 68
67 /* Print working directory. */
68 void 69 void
69 mi_cmd_env_pwd (char *command, char **argv, int argc) 70 mi_cmd_env_pwd (char *command, char **argv, int argc)
70 { 71 {
71 struct ui_out *uiout = current_uiout; 72 struct ui_out *uiout = current_uiout;
72 73
73 if (argc > 0) 74 if (argc > 0)
74 error (_("-environment-pwd: No arguments required")); 75 error (_("-environment-pwd: No arguments allowed"));
75 76
76 if (mi_version (uiout) < 2) 77 if (mi_version (uiout) < 2)
77 { 78 {
78 env_execute_cli_command ("pwd", NULL); 79 env_execute_cli_command ("pwd", NULL);
79 return; 80 return;
80 } 81 }
81 82
82 /* Otherwise the mi level is 2 or higher. */ 83 /* Otherwise the mi level is 2 or higher. */
83 84
84 if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf))) 85 if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
85 error (_("-environment-pwd: error finding name of working directory: %s"), 86 error (_("-environment-pwd: error finding name of working directory: %s"),
86 safe_strerror (errno)); 87 safe_strerror (errno));
87 88
88 ui_out_field_string (uiout, "cwd", gdb_dirbuf); 89 ui_out_field_string (uiout, "cwd", gdb_dirbuf);
89 } 90 }
90 91
91 /* Change working directory. */ 92 /* Change working directory. */
93
92 void 94 void
93 mi_cmd_env_cd (char *command, char **argv, int argc) 95 mi_cmd_env_cd (char *command, char **argv, int argc)
94 { 96 {
95 if (argc == 0 || argc > 1) 97 if (argc == 0 || argc > 1)
96 error (_("-environment-cd: Usage DIRECTORY")); 98 error (_("-environment-cd: Usage DIRECTORY"));
97 99
98 env_execute_cli_command ("cd", argv[0]); 100 env_execute_cli_command ("cd", argv[0]);
99 } 101 }
100 102
101 static void 103 static void
102 env_mod_path (char *dirname, char **which_path) 104 env_mod_path (char *dirname, char **which_path)
103 { 105 {
104 if (dirname == 0 || dirname[0] == '\0') 106 if (dirname == 0 || dirname[0] == '\0')
105 return; 107 return;
106 108
107 /* Call add_path with last arg 0 to indicate not to parse for 109 /* Call add_path with last arg 0 to indicate not to parse for
108 separator characters. */ 110 separator characters. */
109 add_path (dirname, which_path, 0); 111 add_path (dirname, which_path, 0);
110 } 112 }
111 113
112 /* Add one or more directories to start of executable search path. */ 114 /* Add one or more directories to start of executable search path. */
115
113 void 116 void
114 mi_cmd_env_path (char *command, char **argv, int argc) 117 mi_cmd_env_path (char *command, char **argv, int argc)
115 { 118 {
116 struct ui_out *uiout = current_uiout; 119 struct ui_out *uiout = current_uiout;
117 char *exec_path; 120 char *exec_path;
118 char *env; 121 char *env;
119 int reset = 0; 122 int reset = 0;
120 int optind = 0; 123 int oind = 0;
121 int i; 124 int i;
122 char *optarg; 125 char *oarg;
123 enum opt 126 enum opt
124 { 127 {
125 RESET_OPT 128 RESET_OPT
126 }; 129 };
127 static const struct mi_opt opts[] = 130 static const struct mi_opt opts[] =
128 { 131 {
129 {"r", RESET_OPT, 0}, 132 {"r", RESET_OPT, 0},
130 { 0, 0, 0 } 133 { 0, 0, 0 }
131 }; 134 };
132 135
133 dont_repeat (); 136 dont_repeat ();
134 137
135 if (mi_version (uiout) < 2) 138 if (mi_version (uiout) < 2)
136 { 139 {
137 for (i = argc - 1; i >= 0; --i) 140 for (i = argc - 1; i >= 0; --i)
138 env_execute_cli_command ("path", argv[i]); 141 env_execute_cli_command ("path", argv[i]);
139 return; 142 return;
140 } 143 }
141 144
142 /* Otherwise the mi level is 2 or higher. */ 145 /* Otherwise the mi level is 2 or higher. */
143 while (1) 146 while (1)
144 { 147 {
145 int opt = mi_getopt ("-environment-path", argc, argv, opts, 148 int opt = mi_getopt ("-environment-path", argc, argv, opts,
146 &optind, &optarg); 149 &oind, &oarg);
147 150
148 if (opt < 0) 151 if (opt < 0)
149 break; 152 break;
150 switch ((enum opt) opt) 153 switch ((enum opt) opt)
151 { 154 {
152 case RESET_OPT: 155 case RESET_OPT:
153 reset = 1; 156 reset = 1;
154 break; 157 break;
155 } 158 }
156 } 159 }
157 argv += optind; 160 argv += oind;
158 argc -= optind; 161 argc -= oind;
159 162
160 163
161 if (reset) 164 if (reset)
162 { 165 {
163 /* Reset implies resetting to original path first. */ 166 /* Reset implies resetting to original path first. */
164 exec_path = xstrdup (orig_path); 167 exec_path = xstrdup (orig_path);
165 } 168 }
166 else 169 else
167 { 170 {
168 /* Otherwise, get current path to modify. */ 171 /* Otherwise, get current path to modify. */
169 env = get_in_environ (current_inferior ()->environment, path_var_name); 172 env = get_in_environ (current_inferior ()->environment, path_var_name);
170 173
171 /* Can be null if path is not set. */ 174 /* Can be null if path is not set. */
172 if (!env) 175 if (!env)
173 env = ""; 176 env = "";
174 exec_path = xstrdup (env); 177 exec_path = xstrdup (env);
175 } 178 }
176 179
177 for (i = argc - 1; i >= 0; --i) 180 for (i = argc - 1; i >= 0; --i)
178 env_mod_path (argv[i], &exec_path); 181 env_mod_path (argv[i], &exec_path);
179 182
180 set_in_environ (current_inferior ()->environment, path_var_name, exec_path); 183 set_in_environ (current_inferior ()->environment, path_var_name, exec_path);
181 xfree (exec_path); 184 xfree (exec_path);
182 env = get_in_environ (current_inferior ()->environment, path_var_name); 185 env = get_in_environ (current_inferior ()->environment, path_var_name);
183 ui_out_field_string (uiout, "path", env); 186 ui_out_field_string (uiout, "path", env);
184 } 187 }
185 188
186 /* Add zero or more directories to the front of the source path. */ 189 /* Add zero or more directories to the front of the source path. */
190
187 void 191 void
188 mi_cmd_env_dir (char *command, char **argv, int argc) 192 mi_cmd_env_dir (char *command, char **argv, int argc)
189 { 193 {
190 struct ui_out *uiout = current_uiout; 194 struct ui_out *uiout = current_uiout;
191 int i; 195 int i;
192 int optind = 0; 196 int oind = 0;
193 int reset = 0; 197 int reset = 0;
194 char *optarg; 198 char *oarg;
195 enum opt 199 enum opt
196 { 200 {
197 RESET_OPT 201 RESET_OPT
198 }; 202 };
199 static const struct mi_opt opts[] = 203 static const struct mi_opt opts[] =
200 { 204 {
201 {"r", RESET_OPT, 0}, 205 {"r", RESET_OPT, 0},
202 { 0, 0, 0 } 206 { 0, 0, 0 }
203 }; 207 };
204 208
205 dont_repeat (); 209 dont_repeat ();
206 210
207 if (mi_version (uiout) < 2) 211 if (mi_version (uiout) < 2)
208 { 212 {
209 for (i = argc - 1; i >= 0; --i) 213 for (i = argc - 1; i >= 0; --i)
210 env_execute_cli_command ("dir", argv[i]); 214 env_execute_cli_command ("dir", argv[i]);
211 return; 215 return;
212 } 216 }
213 217
214 /* Otherwise mi level is 2 or higher. */ 218 /* Otherwise mi level is 2 or higher. */
215 while (1) 219 while (1)
216 { 220 {
217 int opt = mi_getopt ("-environment-directory", argc, argv, opts, 221 int opt = mi_getopt ("-environment-directory", argc, argv, opts,
218 &optind, &optarg); 222 &oind, &oarg);
219 223
220 if (opt < 0) 224 if (opt < 0)
221 break; 225 break;
222 switch ((enum opt) opt) 226 switch ((enum opt) opt)
223 { 227 {
224 case RESET_OPT: 228 case RESET_OPT:
225 reset = 1; 229 reset = 1;
226 break; 230 break;
227 } 231 }
228 } 232 }
229 argv += optind; 233 argv += oind;
230 argc -= optind; 234 argc -= oind;
231 235
232 if (reset) 236 if (reset)
233 { 237 {
234 /* Reset means setting to default path first. */ 238 /* Reset means setting to default path first. */
235 xfree (source_path); 239 xfree (source_path);
236 init_source_path (); 240 init_source_path ();
237 } 241 }
238 242
239 for (i = argc - 1; i >= 0; --i) 243 for (i = argc - 1; i >= 0; --i)
240 env_mod_path (argv[i], &source_path); 244 env_mod_path (argv[i], &source_path);
241 245
242 ui_out_field_string (uiout, "source-path", source_path); 246 ui_out_field_string (uiout, "source-path", source_path);
243 forget_cached_source_info (); 247 forget_cached_source_info ();
244 } 248 }
245 249
246 /* Set the inferior terminal device name. */ 250 /* Set the inferior terminal device name. */
251
247 void 252 void
248 mi_cmd_inferior_tty_set (char *command, char **argv, int argc) 253 mi_cmd_inferior_tty_set (char *command, char **argv, int argc)
249 { 254 {
250 set_inferior_io_terminal (argv[0]); 255 set_inferior_io_terminal (argv[0]);
251 } 256 }
252 257
253 /* Print the inferior terminal device name */ 258 /* Print the inferior terminal device name. */
259
254 void 260 void
255 mi_cmd_inferior_tty_show (char *command, char **argv, int argc) 261 mi_cmd_inferior_tty_show (char *command, char **argv, int argc)
256 { 262 {
257 const char *inferior_io_terminal = get_inferior_io_terminal (); 263 const char *inferior_io_terminal = get_inferior_io_terminal ();
258 264
259 if ( !mi_valid_noargs ("-inferior-tty-show", argc, argv)) 265 if ( !mi_valid_noargs ("-inferior-tty-show", argc, argv))
260 error (_("-inferior-tty-show: Usage: No args")); 266 error (_("-inferior-tty-show: Usage: No args"));
261 267
262 if (inferior_io_terminal) 268 if (inferior_io_terminal)
263 ui_out_field_string (current_uiout, 269 ui_out_field_string (current_uiout,
264 "inferior_tty_terminal", inferior_io_terminal); 270 "inferior_tty_terminal", inferior_io_terminal);
265 } 271 }
266 272
267 void 273 void
268 _initialize_mi_cmd_env (void) 274 _initialize_mi_cmd_env (void)
269 { 275 {
270 struct gdb_environ *environment; 276 struct gdb_environ *environment;
271 char *env; 277 char *env;
272 278
273 /* We want original execution path to reset to, if desired later. 279 /* We want original execution path to reset to, if desired later.
274 At this point, current inferior is not created, so cannot use 280 At this point, current inferior is not created, so cannot use
275 current_inferior ()->environment. Also, there's no obvious 281 current_inferior ()->environment. Also, there's no obvious
276 place where this code can be moved suchs that it surely run 282 place where this code can be moved such that it surely run
277 before any code possibly mangles original PATH. */ 283 before any code possibly mangles original PATH. */
278 environment = make_environ (); 284 environment = make_environ ();
279 init_environ (environment); 285 init_environ (environment);
280 env = get_in_environ (environment, path_var_name); 286 env = get_in_environ (environment, path_var_name);
281 287
282 /* Can be null if path is not set. */ 288 /* Can be null if path is not set. */
283 if (!env) 289 if (!env)
284 env = ""; 290 env = "";
285 orig_path = xstrdup (env); 291 orig_path = xstrdup (env);
286 free_environ (environment); 292 free_environ (environment);
287 } 293 }
OLDNEW
« no previous file with comments | « gdb/mi/mi-cmd-disas.c ('k') | gdb/mi/mi-cmd-file.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698