OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [gdb/] [mi/] [mi-cmd-env.c] - Blame information for rev 827

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* MI Command Set - environment commands.
2
 
3
   Copyright (C) 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
4
 
5
   Contributed by Red Hat Inc.
6
 
7
   This file is part of GDB.
8
 
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 3 of the License, or
12
   (at your option) any later version.
13
 
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.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
 
22
#include "defs.h"
23
#include "inferior.h"
24
#include "value.h"
25
#include "mi-out.h"
26
#include "mi-cmds.h"
27
#include "mi-getopt.h"
28
#include "symtab.h"
29
#include "target.h"
30
#include "environ.h"
31
#include "command.h"
32
#include "ui-out.h"
33
#include "top.h"
34
 
35
#include "gdb_string.h"
36
#include "gdb_stat.h"
37
 
38
static void env_mod_path (char *dirname, char **which_path);
39
extern void _initialize_mi_cmd_env (void);
40
 
41
static const char path_var_name[] = "PATH";
42
static char *orig_path = NULL;
43
 
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,
46
   append it to the CMD.  */
47
static void
48
env_execute_cli_command (const char *cmd, const char *args)
49
{
50
  if (cmd != 0)
51
    {
52
      struct cleanup *old_cleanups;
53
      char *run;
54
      if (args != NULL)
55
        run = xstrprintf ("%s %s", cmd, args);
56
      else
57
        run = xstrdup (cmd);
58
      old_cleanups = make_cleanup (xfree, run);
59
      execute_command ( /*ui */ run, 0 /*from_tty */ );
60
      do_cleanups (old_cleanups);
61
      return;
62
    }
63
}
64
 
65
 
66
/* Print working directory.  */
67 131 jeremybenn
/* JPB: Some picky Ubuntu GCC compilers don't like the result of getcwd being
68
   ignored (even if you cast it to void). So capture the value and ignore
69
   THAT. */
70 24 jeremybenn
enum mi_cmd_result
71
mi_cmd_env_pwd (char *command, char **argv, int argc)
72
{
73 131 jeremybenn
  char *res;                    /* For getcwd result */
74 24 jeremybenn
  if (argc > 0)
75
    error (_("mi_cmd_env_pwd: No arguments required"));
76
 
77
  if (mi_version (uiout) < 2)
78
    {
79
      env_execute_cli_command ("pwd", NULL);
80
      return MI_CMD_DONE;
81
    }
82
 
83
  /* Otherwise the mi level is 2 or higher.  */
84
 
85 131 jeremybenn
  res = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));       /* JPB */
86 24 jeremybenn
  ui_out_field_string (uiout, "cwd", gdb_dirbuf);
87
 
88
  return MI_CMD_DONE;
89
}
90
 
91
/* Change working directory.  */
92
enum mi_cmd_result
93
mi_cmd_env_cd (char *command, char **argv, int argc)
94
{
95
  if (argc == 0 || argc > 1)
96
    error (_("mi_cmd_env_cd: Usage DIRECTORY"));
97
 
98
  env_execute_cli_command ("cd", argv[0]);
99
 
100
  return MI_CMD_DONE;
101
}
102
 
103
static void
104
env_mod_path (char *dirname, char **which_path)
105
{
106
  if (dirname == 0 || dirname[0] == '\0')
107
    return;
108
 
109
  /* Call add_path with last arg 0 to indicate not to parse for
110
     separator characters.  */
111
  add_path (dirname, which_path, 0);
112
}
113
 
114
/* Add one or more directories to start of executable search path.  */
115
enum mi_cmd_result
116
mi_cmd_env_path (char *command, char **argv, int argc)
117
{
118
  char *exec_path;
119
  char *env;
120
  int reset = 0;
121
  int optind = 0;
122
  int i;
123
  char *optarg;
124
  enum opt
125
    {
126
      RESET_OPT
127
    };
128
  static struct mi_opt opts[] =
129
  {
130
    {"r", RESET_OPT, 0},
131
    { 0, 0, 0 }
132
  };
133
 
134
  dont_repeat ();
135
 
136
  if (mi_version (uiout) < 2)
137
    {
138
      for (i = argc - 1; i >= 0; --i)
139
        env_execute_cli_command ("path", argv[i]);
140
      return MI_CMD_DONE;
141
    }
142
 
143
  /* Otherwise the mi level is 2 or higher.  */
144
  while (1)
145
    {
146
      int opt = mi_getopt ("mi_cmd_env_path", argc, argv, opts,
147
                           &optind, &optarg);
148
      if (opt < 0)
149
        break;
150
      switch ((enum opt) opt)
151
        {
152
        case RESET_OPT:
153
          reset = 1;
154
          break;
155
        }
156
    }
157
  argv += optind;
158
  argc -= optind;
159
 
160
 
161
  if (reset)
162
    {
163
      /* Reset implies resetting to original path first.  */
164
      exec_path = xstrdup (orig_path);
165
    }
166
  else
167
    {
168
      /* Otherwise, get current path to modify.  */
169
      env = get_in_environ (inferior_environ, path_var_name);
170
 
171
      /* Can be null if path is not set.  */
172
      if (!env)
173
        env = "";
174
      exec_path = xstrdup (env);
175
    }
176
 
177
  for (i = argc - 1; i >= 0; --i)
178
    env_mod_path (argv[i], &exec_path);
179
 
180
  set_in_environ (inferior_environ, path_var_name, exec_path);
181
  xfree (exec_path);
182
  env = get_in_environ (inferior_environ, path_var_name);
183
  ui_out_field_string (uiout, "path", env);
184
 
185
  return MI_CMD_DONE;
186
}
187
 
188
/* Add zero or more directories to the front of the source path.  */
189
enum mi_cmd_result
190
mi_cmd_env_dir (char *command, char **argv, int argc)
191
{
192
  int i;
193
  int optind = 0;
194
  int reset = 0;
195
  char *optarg;
196
  enum opt
197
    {
198
      RESET_OPT
199
    };
200
  static struct mi_opt opts[] =
201
  {
202
    {"r", RESET_OPT, 0},
203
    { 0, 0, 0 }
204
  };
205
 
206
  dont_repeat ();
207
 
208
  if (mi_version (uiout) < 2)
209
    {
210
      for (i = argc - 1; i >= 0; --i)
211
        env_execute_cli_command ("dir", argv[i]);
212
      return MI_CMD_DONE;
213
    }
214
 
215
  /* Otherwise mi level is 2 or higher.  */
216
  while (1)
217
    {
218
      int opt = mi_getopt ("mi_cmd_env_dir", argc, argv, opts,
219
                           &optind, &optarg);
220
      if (opt < 0)
221
        break;
222
      switch ((enum opt) opt)
223
        {
224
        case RESET_OPT:
225
          reset = 1;
226
          break;
227
        }
228
    }
229
  argv += optind;
230
  argc -= optind;
231
 
232
  if (reset)
233
    {
234
      /* Reset means setting to default path first.  */
235
      xfree (source_path);
236
      init_source_path ();
237
    }
238
 
239
  for (i = argc - 1; i >= 0; --i)
240
    env_mod_path (argv[i], &source_path);
241
  init_last_source_visited ();
242
 
243
  ui_out_field_string (uiout, "source-path", source_path);
244
  forget_cached_source_info ();
245
 
246
  return MI_CMD_DONE;
247
}
248
 
249
/* Set the inferior terminal device name.  */
250
enum mi_cmd_result
251
mi_cmd_inferior_tty_set (char *command, char **argv, int argc)
252
{
253
  set_inferior_io_terminal (argv[0]);
254
 
255
  return MI_CMD_DONE;
256
}
257
 
258
/* Print the inferior terminal device name  */
259
enum mi_cmd_result
260
mi_cmd_inferior_tty_show (char *command, char **argv, int argc)
261
{
262
  const char *inferior_io_terminal = get_inferior_io_terminal ();
263
 
264
  if ( !mi_valid_noargs ("mi_cmd_inferior_tty_show", argc, argv))
265
    error (_("mi_cmd_inferior_tty_show: Usage: No args"));
266
 
267
  if (inferior_io_terminal)
268
    ui_out_field_string (uiout, "inferior_tty_terminal", inferior_io_terminal);
269
 
270
  return MI_CMD_DONE;
271
}
272
 
273
void
274
_initialize_mi_cmd_env (void)
275
{
276
  char *env;
277
 
278
  /* We want original execution path to reset to, if desired later.  */
279
  env = get_in_environ (inferior_environ, path_var_name);
280
 
281
  /* Can be null if path is not set.  */
282
  if (!env)
283
    env = "";
284
  orig_path = xstrdup (env);
285
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.