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

Subversion Repositories or1k

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

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

Line No. Rev Author Line
1 578 markom
/* MI Command Set - varobj commands.
2
   Copyright 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
      /*      xasprintf (&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 (free_current_contents, &name);
65
 
66
  frame = xstrdup (argv[1]);
67
  old_cleanups = make_cleanup (xfree, frame);
68
 
69
  expr = xstrdup (argv[2]);
70
 
71
  if (strcmp (name, "-") == 0)
72
    {
73
      xfree (name);
74
      name = varobj_gen_name ();
75
    }
76
  else if (!isalpha (*name))
77
    error ("mi_cmd_var_create: name of object must begin with a letter");
78
 
79
  if (strcmp (frame, "*") == 0)
80
    var_type = USE_CURRENT_FRAME;
81
  else if (strcmp (frame, "@") == 0)
82
    var_type = USE_SELECTED_FRAME;
83
  else
84
    {
85
      var_type = USE_SPECIFIED_FRAME;
86
      frameaddr = parse_and_eval_address (frame);
87
    }
88
 
89
  if (varobjdebug)
90
    fprintf_unfiltered (gdb_stdlog,
91
                    "Name=\"%s\", Frame=\"%s\" (0x%s), Expression=\"%s\"\n",
92
                        name, frame, paddr (frameaddr), expr);
93
 
94
  var = varobj_create (name, expr, frameaddr, var_type);
95
 
96
  if (var == NULL)
97
    error ("mi_cmd_var_create: unable to create variable object");
98
 
99
  ui_out_field_string (uiout, "name", name);
100
  ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
101
  type = varobj_get_type (var);
102
  if (type == NULL)
103
    ui_out_field_string (uiout, "type", "");
104
  else
105
    {
106
      ui_out_field_string (uiout, "type", type);
107
      xfree (type);
108
    }
109
 
110
  do_cleanups (old_cleanups);
111
  return MI_CMD_DONE;
112
}
113
 
114
enum mi_cmd_result
115
mi_cmd_var_delete (char *command, char **argv, int argc)
116
{
117
  char *name;
118
  char *expr;
119
  struct varobj *var;
120
  int numdel;
121
  int children_only_p = 0;
122
  struct cleanup *old_cleanups;
123
 
124
  if (argc < 1 || argc > 2)
125
    error ("mi_cmd_var_delete: Usage: [-c] EXPRESSION.");
126
 
127
  name = xstrdup (argv[0]);
128
  /* Add cleanup for name. Must be free_current_contents as
129
     name can be reallocated */
130
  old_cleanups = make_cleanup (free_current_contents, &name);
131
 
132
  /* If we have one single argument it cannot be '-c' or any string
133
     starting with '-'. */
134
  if (argc == 1)
135
    {
136
      if (strcmp (name, "-c") == 0)
137
        error ("mi_cmd_var_delete: Missing required argument after '-c': variable object name");
138
      if (*name == '-')
139
        error ("mi_cmd_var_delete: Illegal variable object name");
140
    }
141
 
142
  /* If we have 2 arguments they must be '-c' followed by a string
143
     which would be the variable name. */
144
  if (argc == 2)
145
    {
146
      expr = xstrdup (argv[1]);
147
      if (strcmp (name, "-c") != 0)
148
        error ("mi_cmd_var_delete: Invalid option.");
149
      children_only_p = 1;
150
      xfree (name);
151
      name = xstrdup (expr);
152
      xfree (expr);
153
    }
154
 
155
  /* If we didn't error out, now NAME contains the name of the
156
     variable. */
157
 
158
  var = varobj_get_handle (name);
159
 
160
  if (var == NULL)
161
    error ("mi_cmd_var_delete: Variable object not found.");
162
 
163
  numdel = varobj_delete (var, NULL, children_only_p);
164
 
165
  ui_out_field_int (uiout, "ndeleted", numdel);
166
 
167
  do_cleanups (old_cleanups);
168
  return MI_CMD_DONE;
169
}
170
 
171
enum mi_cmd_result
172
mi_cmd_var_set_format (char *command, char **argv, int argc)
173
{
174
  enum varobj_display_formats format;
175
  int len;
176
  struct varobj *var;
177
  char *formspec;
178
 
179
  if (argc != 2)
180
    error ("mi_cmd_var_set_format: Usage: NAME FORMAT.");
181
 
182
  /* Get varobj handle, if a valid var obj name was specified */
183
  var = varobj_get_handle (argv[0]);
184
 
185
  if (var == NULL)
186
    error ("mi_cmd_var_set_format: Variable object not found");
187
 
188
  formspec = xstrdup (argv[1]);
189
  if (formspec == NULL)
190
    error ("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"");
191
 
192
  len = strlen (formspec);
193
 
194
  if (STREQN (formspec, "natural", len))
195
    format = FORMAT_NATURAL;
196
  else if (STREQN (formspec, "binary", len))
197
    format = FORMAT_BINARY;
198
  else if (STREQN (formspec, "decimal", len))
199
    format = FORMAT_DECIMAL;
200
  else if (STREQN (formspec, "hexadecimal", len))
201
    format = FORMAT_HEXADECIMAL;
202
  else if (STREQN (formspec, "octal", len))
203
    format = FORMAT_OCTAL;
204
  else
205
    error ("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"");
206
 
207
  /* Set the format of VAR to given format */
208
  varobj_set_display_format (var, format);
209
 
210
  /* Report the new current format */
211
  ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
212
  return MI_CMD_DONE;
213
}
214
 
215
enum mi_cmd_result
216
mi_cmd_var_show_format (char *command, char **argv, int argc)
217
{
218
  enum varobj_display_formats format;
219
  struct varobj *var;
220
 
221
  if (argc != 1)
222
    error ("mi_cmd_var_show_format: Usage: NAME.");
223
 
224
  /* Get varobj handle, if a valid var obj name was specified */
225
  var = varobj_get_handle (argv[0]);
226
  if (var == NULL)
227
    error ("mi_cmd_var_show_format: Variable object not found");
228
 
229
  format = varobj_get_display_format (var);
230
 
231
  /* Report the current format */
232
  ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
233
  return MI_CMD_DONE;
234
}
235
 
236
enum mi_cmd_result
237
mi_cmd_var_info_num_children (char *command, char **argv, int argc)
238
{
239
  struct varobj *var;
240
 
241
  if (argc != 1)
242
    error ("mi_cmd_var_info_num_children: Usage: NAME.");
243
 
244
  /* Get varobj handle, if a valid var obj name was specified */
245
  var = varobj_get_handle (argv[0]);
246
  if (var == NULL)
247
    error ("mi_cmd_var_info_num_children: Variable object not found");
248
 
249
  ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
250
  return MI_CMD_DONE;
251
}
252
 
253
enum mi_cmd_result
254
mi_cmd_var_list_children (char *command, char **argv, int argc)
255
{
256
  struct varobj *var;
257
  struct varobj **childlist;
258
  struct varobj **cc;
259
  int numchild;
260
  char *type;
261
 
262
  if (argc != 1)
263
    error ("mi_cmd_var_list_children: Usage: NAME.");
264
 
265
  /* Get varobj handle, if a valid var obj name was specified */
266
  var = varobj_get_handle (argv[0]);
267
  if (var == NULL)
268
    error ("mi_cmd_var_list_children: Variable object not found");
269
 
270
  numchild = varobj_list_children (var, &childlist);
271
  ui_out_field_int (uiout, "numchild", numchild);
272
 
273
  if (numchild <= 0)
274
    return MI_CMD_DONE;
275
 
276
  ui_out_tuple_begin (uiout, "children");
277
  cc = childlist;
278
  while (*cc != NULL)
279
    {
280
      ui_out_tuple_begin (uiout, "child");
281
      ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
282
      ui_out_field_string (uiout, "exp", varobj_get_expression (*cc));
283
      ui_out_field_int (uiout, "numchild", varobj_get_num_children (*cc));
284
      type = varobj_get_type (*cc);
285
      /* C++ pseudo-variables (public, private, protected) do not have a type */
286
      if (type)
287
        ui_out_field_string (uiout, "type", varobj_get_type (*cc));
288
      ui_out_tuple_end (uiout);
289
      cc++;
290
    }
291
  ui_out_tuple_end (uiout);
292
  xfree (childlist);
293
  return MI_CMD_DONE;
294
}
295
 
296
enum mi_cmd_result
297
mi_cmd_var_info_type (char *command, char **argv, int argc)
298
{
299
  struct varobj *var;
300
 
301
  if (argc != 1)
302
    error ("mi_cmd_var_info_type: Usage: NAME.");
303
 
304
  /* Get varobj handle, if a valid var obj name was specified */
305
  var = varobj_get_handle (argv[0]);
306
  if (var == NULL)
307
    error ("mi_cmd_var_info_type: Variable object not found");
308
 
309
  ui_out_field_string (uiout, "type", varobj_get_type (var));
310
  return MI_CMD_DONE;
311
}
312
 
313
enum mi_cmd_result
314
mi_cmd_var_info_expression (char *command, char **argv, int argc)
315
{
316
  enum varobj_languages lang;
317
  struct varobj *var;
318
 
319
  if (argc != 1)
320
    error ("mi_cmd_var_info_expression: Usage: NAME.");
321
 
322
  /* Get varobj handle, if a valid var obj name was specified */
323
  var = varobj_get_handle (argv[0]);
324
  if (var == NULL)
325
    error ("mi_cmd_var_info_expression: Variable object not found");
326
 
327
  lang = varobj_get_language (var);
328
 
329
  ui_out_field_string (uiout, "lang", varobj_language_string[(int) lang]);
330
  ui_out_field_string (uiout, "exp", varobj_get_expression (var));
331
  return MI_CMD_DONE;
332
}
333
 
334
enum mi_cmd_result
335
mi_cmd_var_show_attributes (char *command, char **argv, int argc)
336
{
337
  int attr;
338
  char *attstr;
339
  struct varobj *var;
340
 
341
  if (argc != 1)
342
    error ("mi_cmd_var_show_attributes: Usage: NAME.");
343
 
344
  /* Get varobj handle, if a valid var obj name was specified */
345
  var = varobj_get_handle (argv[0]);
346
  if (var == NULL)
347
    error ("mi_cmd_var_show_attributes: Variable object not found");
348
 
349
  attr = varobj_get_attributes (var);
350
  /* FIXME: define masks for attributes */
351
  if (attr & 0x00000001)
352
    attstr = "editable";
353
  else
354
    attstr = "noneditable";
355
 
356
  ui_out_field_string (uiout, "attr", attstr);
357
  return MI_CMD_DONE;
358
}
359
 
360
enum mi_cmd_result
361
mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
362
{
363
  struct varobj *var;
364
 
365
  if (argc != 1)
366
    error ("mi_cmd_var_evaluate_expression: Usage: NAME.");
367
 
368
  /* Get varobj handle, if a valid var obj name was specified */
369
  var = varobj_get_handle (argv[0]);
370
  if (var == NULL)
371
    error ("mi_cmd_var_evaluate_expression: Variable object not found");
372
 
373
  ui_out_field_string (uiout, "value", varobj_get_value (var));
374
  return MI_CMD_DONE;
375
}
376
 
377
enum mi_cmd_result
378
mi_cmd_var_assign (char *command, char **argv, int argc)
379
{
380
  struct varobj *var;
381
  char *expression;
382
 
383
  if (argc != 2)
384
    error ("mi_cmd_var_assign: Usage: NAME EXPRESSION.");
385
 
386
  /* Get varobj handle, if a valid var obj name was specified */
387
  var = varobj_get_handle (argv[0]);
388
  if (var == NULL)
389
    error ("mi_cmd_var_assign: Variable object not found");
390
 
391
  /* FIXME: define masks for attributes */
392
  if (!(varobj_get_attributes (var) & 0x00000001))
393
    error ("mi_cmd_var_assign: Variable object is not editable");
394
 
395
  expression = xstrdup (argv[1]);
396
 
397
  if (!varobj_set_value (var, expression))
398
    error ("mi_cmd_var_assign: Could not assign expression to varible object");
399
 
400
  ui_out_field_string (uiout, "value", varobj_get_value (var));
401
  return MI_CMD_DONE;
402
}
403
 
404
enum mi_cmd_result
405
mi_cmd_var_update (char *command, char **argv, int argc)
406
{
407
  struct varobj *var;
408
  struct varobj **rootlist;
409
  struct varobj **cr;
410
  char *name;
411
  int nv;
412
 
413
  if (argc != 1)
414
    error ("mi_cmd_var_update: Usage: NAME.");
415
 
416
  name = argv[0];
417
 
418
  /* Check if the parameter is a "*" which means that we want
419
     to update all variables */
420
 
421
  if ((*name == '*') && (*(name + 1) == '\0'))
422
    {
423
      nv = varobj_list (&rootlist);
424
      ui_out_tuple_begin (uiout, "changelist");
425
      if (nv <= 0)
426
        {
427
          ui_out_tuple_end (uiout);
428
          return MI_CMD_DONE;
429
        }
430
      cr = rootlist;
431
      while (*cr != NULL)
432
        {
433
          varobj_update_one (*cr);
434
          cr++;
435
        }
436
      xfree (rootlist);
437
      ui_out_tuple_end (uiout);
438
    }
439
  else
440
    {
441
      /* Get varobj handle, if a valid var obj name was specified */
442
      var = varobj_get_handle (name);
443
      if (var == NULL)
444
        error ("mi_cmd_var_update: Variable object not found");
445
 
446
      ui_out_tuple_begin (uiout, "changelist");
447
      varobj_update_one (var);
448
      ui_out_tuple_end (uiout);
449
    }
450
    return MI_CMD_DONE;
451
}
452
 
453
/* Helper for mi_cmd_var_update() Returns 0 if the update for
454
   the variable fails (usually because the variable is out of
455
   scope), and 1 if it succeeds. */
456
 
457
static int
458
varobj_update_one (struct varobj *var)
459
{
460
  struct varobj **changelist;
461
  struct varobj **cc;
462
  int nc;
463
 
464
  nc = varobj_update (var, &changelist);
465
 
466
  /* nc == 0 means that nothing has changed.
467
     nc == -1 means that an error occured in updating the variable.
468
     nc == -2 means the variable has changed type. */
469
 
470
  if (nc == 0)
471
    return 1;
472
  else if (nc == -1)
473
    {
474
      ui_out_field_string (uiout, "name", varobj_get_objname(var));
475
      ui_out_field_string (uiout, "in_scope", "false");
476
      return -1;
477
    }
478
  else if (nc == -2)
479
    {
480
      ui_out_field_string (uiout, "name", varobj_get_objname (var));
481
      ui_out_field_string (uiout, "in_scope", "true");
482
      ui_out_field_string (uiout, "new_type", varobj_get_type(var));
483
      ui_out_field_int (uiout, "new_num_children",
484
                           varobj_get_num_children(var));
485
    }
486
  else
487
    {
488
 
489
      cc = changelist;
490
      while (*cc != NULL)
491
        {
492
          ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
493
          ui_out_field_string (uiout, "in_scope", "true");
494
          ui_out_field_string (uiout, "type_changed", "false");
495
          cc++;
496
        }
497
      xfree (changelist);
498
      return 1;
499
    }
500
  return 1;
501
}

powered by: WebSVN 2.1.0

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