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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [mi/] [mi-cmd-var.c] - Blame information for rev 106

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

Line No. Rev Author Line
1 106 markom
/* MI Command Set - varobj commands.
2
   Copyright (C) 2000, Free Software Foundation, Inc.
3
   Contributed by Cygnus Solutions (a Red Hat company).
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
#include "defs.h"
23
#include "mi-cmds.h"
24
#include "ui-out.h"
25
#include "mi-out.h"
26
#include "varobj.h"
27
#include "value.h"
28
#include <ctype.h>
29
 
30
/* Convenience macro for allocting typesafe memory. */
31
 
32
#undef XMALLOC
33
#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
34
 
35
extern int varobjdebug;         /* defined in varobj.c */
36
 
37
static int varobj_update_one (struct varobj *var);
38
 
39
/* VAROBJ operations */
40
 
41
enum mi_cmd_result
42
mi_cmd_var_create (char *command, char **argv, int argc)
43
{
44
  CORE_ADDR frameaddr = 0;
45
  struct varobj *var;
46
  char *name;
47
  char *frame;
48
  char *expr;
49
  char *type;
50
  struct cleanup *old_cleanups;
51
  enum varobj_type var_type;
52
 
53
  if (argc != 3)
54
    {
55
      /*      asprintf (&mi_error_message,
56
         "mi_cmd_var_create: Usage: .");
57
         return MI_CMD_ERROR; */
58
      error ("mi_cmd_var_create: Usage: NAME FRAME EXPRESSION.");
59
    }
60
 
61
  name = xstrdup (argv[0]);
62
  /* Add cleanup for name. Must be free_current_contents as
63
     name can be reallocated */
64
  old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents,
65
                               &name);
66
 
67
  frame = xstrdup (argv[1]);
68
  old_cleanups = make_cleanup (free, frame);
69
 
70
  expr = xstrdup (argv[2]);
71
 
72
  if (strcmp (name, "-") == 0)
73
    {
74
      free (name);
75
      name = varobj_gen_name ();
76
    }
77
  else if (!isalpha (*name))
78
    error ("mi_cmd_var_create: name of object must begin with a letter");
79
 
80
  if (strcmp (frame, "*") == 0)
81
    var_type = USE_CURRENT_FRAME;
82
  else if (strcmp (frame, "@") == 0)
83
    var_type = USE_SELECTED_FRAME;
84
  else
85
    {
86
      var_type = USE_SPECIFIED_FRAME;
87
      frameaddr = parse_and_eval_address (frame);
88
    }
89
 
90
  if (varobjdebug)
91
    fprintf_unfiltered (gdb_stdlog,
92
                    "Name=\"%s\", Frame=\"%s\" (0x%s), Expression=\"%s\"\n",
93
                        name, frame, paddr (frameaddr), expr);
94
 
95
  var = varobj_create (name, expr, frameaddr, var_type);
96
 
97
  if (var == NULL)
98
    error ("mi_cmd_var_create: unable to create variable object");
99
 
100
  ui_out_field_string (uiout, "name", name);
101
  ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
102
  type = varobj_get_type (var);
103
  if (type == NULL)
104
    ui_out_field_string (uiout, "type", "");
105
  else
106
    {
107
      ui_out_field_string (uiout, "type", type);
108
      free (type);
109
    }
110
 
111
  do_cleanups (old_cleanups);
112
  return MI_CMD_DONE;
113
}
114
 
115
enum mi_cmd_result
116
mi_cmd_var_delete (char *command, char **argv, int argc)
117
{
118
  char *name;
119
  char *expr;
120
  struct varobj *var;
121
  int numdel;
122
  int children_only_p = 0;
123
  struct cleanup *old_cleanups;
124
 
125
  if (argc < 1 || argc > 2)
126
    error ("mi_cmd_var_delete: Usage: [-c] EXPRESSION.");
127
 
128
  name = xstrdup (argv[0]);
129
  /* Add cleanup for name. Must be free_current_contents as
130
     name can be reallocated */
131
  old_cleanups = make_cleanup ((make_cleanup_func) free_current_contents,
132
                               &name);
133
 
134
  /* If we have one single argument it cannot be '-c' or any string
135
     starting with '-'. */
136
  if (argc == 1)
137
    {
138
      if (strcmp (name, "-c") == 0)
139
        error ("mi_cmd_var_delete: Missing required argument after '-c': variable object name");
140
      if (*name == '-')
141
        error ("mi_cmd_var_delete: Illegal variable object name");
142
    }
143
 
144
  /* If we have 2 arguments they must be '-c' followed by a string
145
     which would be the variable name. */
146
  if (argc == 2)
147
    {
148
      expr = xstrdup (argv[1]);
149
      if (strcmp (name, "-c") != 0)
150
        error ("mi_cmd_var_delete: Invalid option.");
151
      children_only_p = 1;
152
      free (name);
153
      name = xstrdup (expr);
154
      free (expr);
155
    }
156
 
157
  /* If we didn't error out, now NAME contains the name of the
158
     variable. */
159
 
160
  var = varobj_get_handle (name);
161
 
162
  if (var == NULL)
163
    error ("mi_cmd_var_delete: Variable object not found.");
164
 
165
  numdel = varobj_delete (var, NULL, children_only_p);
166
 
167
  ui_out_field_int (uiout, "ndeleted", numdel);
168
 
169
  do_cleanups (old_cleanups);
170
  return MI_CMD_DONE;
171
}
172
 
173
enum mi_cmd_result
174
mi_cmd_var_set_format (char *command, char **argv, int argc)
175
{
176
  enum varobj_display_formats format;
177
  int len;
178
  struct varobj *var;
179
  char *formspec;
180
 
181
  if (argc != 2)
182
    error ("mi_cmd_var_set_format: Usage: NAME FORMAT.");
183
 
184
  /* Get varobj handle, if a valid var obj name was specified */
185
  var = varobj_get_handle (argv[0]);
186
 
187
  if (var == NULL)
188
    error ("mi_cmd_var_set_format: Variable object not found");
189
 
190
  formspec = xstrdup (argv[1]);
191
  if (formspec == NULL)
192
    error ("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"");
193
 
194
  len = strlen (formspec);
195
 
196
  if (STREQN (formspec, "natural", len))
197
    format = FORMAT_NATURAL;
198
  else if (STREQN (formspec, "binary", len))
199
    format = FORMAT_BINARY;
200
  else if (STREQN (formspec, "decimal", len))
201
    format = FORMAT_DECIMAL;
202
  else if (STREQN (formspec, "hexadecimal", len))
203
    format = FORMAT_HEXADECIMAL;
204
  else if (STREQN (formspec, "octal", len))
205
    format = FORMAT_OCTAL;
206
  else
207
    error ("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"");
208
 
209
  /* Set the format of VAR to given format */
210
  varobj_set_display_format (var, format);
211
 
212
  /* Report the new current format */
213
  ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
214
  return MI_CMD_DONE;
215
}
216
 
217
enum mi_cmd_result
218
mi_cmd_var_show_format (char *command, char **argv, int argc)
219
{
220
  enum varobj_display_formats format;
221
  struct varobj *var;
222
 
223
  if (argc != 1)
224
    error ("mi_cmd_var_show_format: Usage: NAME.");
225
 
226
  /* Get varobj handle, if a valid var obj name was specified */
227
  var = varobj_get_handle (argv[0]);
228
  if (var == NULL)
229
    error ("mi_cmd_var_show_format: Variable object not found");
230
 
231
  format = varobj_get_display_format (var);
232
 
233
  /* Report the current format */
234
  ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
235
  return MI_CMD_DONE;
236
}
237
 
238
enum mi_cmd_result
239
mi_cmd_var_info_num_children (char *command, char **argv, int argc)
240
{
241
  struct varobj *var;
242
 
243
  if (argc != 1)
244
    error ("mi_cmd_var_info_num_children: Usage: NAME.");
245
 
246
  /* Get varobj handle, if a valid var obj name was specified */
247
  var = varobj_get_handle (argv[0]);
248
  if (var == NULL)
249
    error ("mi_cmd_var_info_num_children: Variable object not found");
250
 
251
  ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
252
  return MI_CMD_DONE;
253
}
254
 
255
enum mi_cmd_result
256
mi_cmd_var_list_children (char *command, char **argv, int argc)
257
{
258
  struct varobj *var;
259
  struct varobj **childlist;
260
  struct varobj **cc;
261
  int numchild;
262
  char *type;
263
 
264
  if (argc != 1)
265
    error ("mi_cmd_var_list_children: Usage: NAME.");
266
 
267
  /* Get varobj handle, if a valid var obj name was specified */
268
  var = varobj_get_handle (argv[0]);
269
  if (var == NULL)
270
    error ("mi_cmd_var_list_children: Variable object not found");
271
 
272
  numchild = varobj_list_children (var, &childlist);
273
  ui_out_field_int (uiout, "numchild", numchild);
274
 
275
  if (numchild <= 0)
276
    return MI_CMD_DONE;
277
 
278
  ui_out_list_begin (uiout, "children");
279
  cc = childlist;
280
  while (*cc != NULL)
281
    {
282
      ui_out_list_begin (uiout, "child");
283
      ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
284
      ui_out_field_string (uiout, "exp", varobj_get_expression (*cc));
285
      ui_out_field_int (uiout, "numchild", varobj_get_num_children (*cc));
286
      type = varobj_get_type (*cc);
287
      /* C++ pseudo-variables (public, private, protected) do not have a type */
288
      if (type)
289
        ui_out_field_string (uiout, "type", varobj_get_type (*cc));
290
      ui_out_list_end (uiout);
291
      cc++;
292
    }
293
  ui_out_list_end (uiout);
294
  free (childlist);
295
  return MI_CMD_DONE;
296
}
297
 
298
enum mi_cmd_result
299
mi_cmd_var_info_type (char *command, char **argv, int argc)
300
{
301
  struct varobj *var;
302
 
303
  if (argc != 1)
304
    error ("mi_cmd_var_info_type: Usage: NAME.");
305
 
306
  /* Get varobj handle, if a valid var obj name was specified */
307
  var = varobj_get_handle (argv[0]);
308
  if (var == NULL)
309
    error ("mi_cmd_var_info_type: Variable object not found");
310
 
311
  ui_out_field_string (uiout, "type", varobj_get_type (var));
312
  return MI_CMD_DONE;
313
}
314
 
315
enum mi_cmd_result
316
mi_cmd_var_info_expression (char *command, char **argv, int argc)
317
{
318
  enum varobj_languages lang;
319
  struct varobj *var;
320
 
321
  if (argc != 1)
322
    error ("mi_cmd_var_info_expression: Usage: NAME.");
323
 
324
  /* Get varobj handle, if a valid var obj name was specified */
325
  var = varobj_get_handle (argv[0]);
326
  if (var == NULL)
327
    error ("mi_cmd_var_info_expression: Variable object not found");
328
 
329
  lang = varobj_get_language (var);
330
 
331
  ui_out_field_string (uiout, "lang", varobj_language_string[(int) lang]);
332
  ui_out_field_string (uiout, "exp", varobj_get_expression (var));
333
  return MI_CMD_DONE;
334
}
335
 
336
enum mi_cmd_result
337
mi_cmd_var_show_attributes (char *command, char **argv, int argc)
338
{
339
  int attr;
340
  char *attstr;
341
  struct varobj *var;
342
 
343
  if (argc != 1)
344
    error ("mi_cmd_var_show_attributes: Usage: NAME.");
345
 
346
  /* Get varobj handle, if a valid var obj name was specified */
347
  var = varobj_get_handle (argv[0]);
348
  if (var == NULL)
349
    error ("mi_cmd_var_show_attributes: Variable object not found");
350
 
351
  attr = varobj_get_attributes (var);
352
  /* FIXME: define masks for attributes */
353
  if (attr & 0x00000001)
354
    attstr = "editable";
355
  else
356
    attstr = "noneditable";
357
 
358
  ui_out_field_string (uiout, "attr", attstr);
359
  return MI_CMD_DONE;
360
}
361
 
362
enum mi_cmd_result
363
mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
364
{
365
  struct varobj *var;
366
 
367
  if (argc != 1)
368
    error ("mi_cmd_var_evaluate_expression: Usage: NAME.");
369
 
370
  /* Get varobj handle, if a valid var obj name was specified */
371
  var = varobj_get_handle (argv[0]);
372
  if (var == NULL)
373
    error ("mi_cmd_var_evaluate_expression: Variable object not found");
374
 
375
  ui_out_field_string (uiout, "value", varobj_get_value (var));
376
  return MI_CMD_DONE;
377
}
378
 
379
enum mi_cmd_result
380
mi_cmd_var_assign (char *command, char **argv, int argc)
381
{
382
  struct varobj *var;
383
  char *expression;
384
 
385
  if (argc != 2)
386
    error ("mi_cmd_var_assign: Usage: NAME EXPRESSION.");
387
 
388
  /* Get varobj handle, if a valid var obj name was specified */
389
  var = varobj_get_handle (argv[0]);
390
  if (var == NULL)
391
    error ("mi_cmd_var_assign: Variable object not found");
392
 
393
  /* FIXME: define masks for attributes */
394
  if (!(varobj_get_attributes (var) & 0x00000001))
395
    error ("mi_cmd_var_assign: Variable object is not editable");
396
 
397
  expression = xstrdup (argv[1]);
398
 
399
  if (!varobj_set_value (var, expression))
400
    error ("mi_cmd_var_assign: Could not assign expression to varible object");
401
 
402
  ui_out_field_string (uiout, "value", varobj_get_value (var));
403
  return MI_CMD_DONE;
404
}
405
 
406
enum mi_cmd_result
407
mi_cmd_var_update (char *command, char **argv, int argc)
408
{
409
  struct varobj *var;
410
  struct varobj **rootlist;
411
  struct varobj **cr;
412
  char *name;
413
  int nv;
414
 
415
  if (argc != 1)
416
    error ("mi_cmd_var_update: Usage: NAME.");
417
 
418
  name = argv[0];
419
 
420
  /* Check if the parameter is a "*" which means that we want
421
     to update all variables */
422
 
423
  if ((*name == '*') && (*(name + 1) == '\0'))
424
    {
425
      nv = varobj_list (&rootlist);
426
      ui_out_list_begin (uiout, "changelist");
427
      if (nv <= 0)
428
        {
429
          ui_out_list_end (uiout);
430
          return MI_CMD_DONE;
431
        }
432
      cr = rootlist;
433
      while (*cr != NULL)
434
        {
435
          varobj_update_one (*cr);
436
          cr++;
437
        }
438
      free (rootlist);
439
      ui_out_list_end (uiout);
440
    }
441
  else
442
    {
443
      /* Get varobj handle, if a valid var obj name was specified */
444
      var = varobj_get_handle (name);
445
      if (var == NULL)
446
        error ("mi_cmd_var_update: Variable object not found");
447
 
448
      ui_out_list_begin (uiout, "changelist");
449
      varobj_update_one (var);
450
      ui_out_list_end (uiout);
451
    }
452
    return MI_CMD_DONE;
453
}
454
 
455
/* Helper for mi_cmd_var_update() Returns 0 if the update for
456
   the variable fails (usually because the variable is out of
457
   scope), and 1 if it succeeds. */
458
 
459
static int
460
varobj_update_one (struct varobj *var)
461
{
462
  struct varobj **changelist;
463
  struct varobj **cc;
464
  int nc;
465
 
466
  nc = varobj_update (var, &changelist);
467
 
468
  /* nc == 0 means that nothing has changed.
469
     nc == -1 means that an error occured in updating the variable.
470
     nc == -2 means the variable has changed type. */
471
 
472
  if (nc == 0)
473
    return 1;
474
  else if (nc == -1)
475
    {
476
      ui_out_field_string (uiout, "name", varobj_get_objname(var));
477
      ui_out_field_string (uiout, "in_scope", "false");
478
      return -1;
479
    }
480
  else if (nc == -2)
481
    {
482
      ui_out_field_string (uiout, "name", varobj_get_objname (var));
483
      ui_out_field_string (uiout, "in_scope", "true");
484
      ui_out_field_string (uiout, "new_type", varobj_get_type(var));
485
      ui_out_field_int (uiout, "new_num_children",
486
                           varobj_get_num_children(var));
487
    }
488
  else
489
    {
490
 
491
      cc = changelist;
492
      while (*cc != NULL)
493
        {
494
          ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
495
          ui_out_field_string (uiout, "in_scope", "true");
496
          ui_out_field_string (uiout, "type_changed", "false");
497
          cc++;
498
        }
499
      free (changelist);
500
      return 1;
501
    }
502
  return 1;
503
}
504
 
505
/* Local variables: */
506
/* change-log-default-name: "ChangeLog-mi" */
507
/* End: */

powered by: WebSVN 2.1.0

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