Doh!
[binutils-gdb.git] / gdb / gdbtk-variable.c
1 /* Variable user interface for GDB, the GNU debugger.
2 Copyright 1999 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "defs.h"
21 #include "value.h"
22 #include "expression.h"
23 #include "frame.h"
24 #include "valprint.h"
25
26 #include <tcl.h>
27 #include <tk.h>
28 #include "gdbtk.h"
29 #include "gdbtk-wrapper.h"
30
31 #include <math.h>
32
33 /* Enumeration type defining the return values for valueChanged */
34 enum value_changed
35 {
36 VALUE_UNCHANGED, /* the variable's value is unchanged */
37 VALUE_CHANGED, /* the variable's value has changed */
38 VALUE_OUT_OF_SCOPE /* the variable is no longer in scope */
39 };
40
41 /* String representations of the value_changed enums */
42 static char *value_changed_string[] = {
43 "VARIABLE_UNCHANGED",
44 "VARIABLE_CHANGED",
45 "VARIABLE_OUT_OF_SCOPE",
46 NULL
47 };
48
49 /* Enumeration for the format types */
50 enum display_format
51 {
52 FORMAT_NATURAL, /* What gdb actually calls 'natural' */
53 FORMAT_BINARY, /* Binary display */
54 FORMAT_DECIMAL, /* Decimal display */
55 FORMAT_HEXADECIMAL, /* Hex display */
56 FORMAT_OCTAL /* Octal display */
57 };
58
59 /* Mappings of display_format enums to gdb's format codes */
60 int format_code[] = {0, 't', 'd', 'x', 'o'};
61
62 /* String representations of the format codes */
63 char *format_string[] = {"natural", "binary", "decimal", "hexadecimal", "octal"};
64
65 /* Every parent variable keeps a linked list of its children, described
66 by the following structure. */
67 struct variable_child {
68
69 /* Pointer to the child's data */
70 struct _gdb_variable *child;
71
72 /* Pointer to the next child */
73 struct variable_child *next;
74 };
75
76 /* Every variable in the system has a structure of this type defined
77 for it. This structure holds all information necessary to manipulate
78 a particular object variable. Members which must be freed are noted. */
79 struct _gdb_variable {
80
81 /* Alloc'd name of the variable for this object.. If this variable is a
82 child, then this name will be the child's source name.
83 (bar, not foo.bar) */
84 char *name;
85
86 /* The alloc'd real name of this variable. This is used to construct the
87 variable's children. It is always a valid expression. */
88 char *real_name;
89
90 /* The alloc'd name for this variable's object. This is here for
91 convenience when constructing this object's children. */
92 char *obj_name;
93
94 /* Alloc'd expression for this variable */
95 struct expression *exp;
96
97 /* Block for which this expression is valid */
98 struct block *valid_block;
99
100 /* The frame for this expression */
101 CORE_ADDR frame;
102
103 /* The value of this expression */
104 value_ptr value;
105
106 /* Did an error occur evaluating the expression or getting its value? */
107 int error;
108
109 /* The number of (immediate) children this variable has */
110 int num_children;
111
112 /* If this object is a child, this points to its parent. */
113 struct _gdb_variable *parent;
114
115 /* A list of this object's children */
116 struct variable_child *children;
117
118 /* The format of the output for this object */
119 enum display_format format;
120 };
121
122 typedef struct _gdb_variable gdb_variable;
123
124 /* This variable will hold the value of the output from gdb
125 for commands executed through call_gdb_* */
126 static Tcl_Obj *fputs_obj;
127
128 /*
129 * Public functions defined in this file
130 */
131
132 int gdb_variable_init PARAMS ((Tcl_Interp *));
133
134 /*
135 * Private functions defined in this file
136 */
137
138 /* Entries into this file */
139
140 static int gdb_variable_command PARAMS ((ClientData, Tcl_Interp *, int,
141 Tcl_Obj *CONST[]));
142
143 static int variable_create PARAMS ((Tcl_Interp *, int, Tcl_Obj *CONST[]));
144
145 static void variable_delete PARAMS ((Tcl_Interp *, gdb_variable *));
146
147 static void variable_debug PARAMS ((gdb_variable *));
148
149 static int variable_obj_command PARAMS ((ClientData, Tcl_Interp *, int,
150 Tcl_Obj *CONST[]));
151 static Tcl_Obj *variable_children PARAMS ((Tcl_Interp *, gdb_variable *));
152
153 static enum value_changed variable_value_changed PARAMS ((gdb_variable *));
154
155 static int variable_format PARAMS ((Tcl_Interp *, int, Tcl_Obj *CONST[],
156 gdb_variable *));
157
158 static int variable_type PARAMS ((Tcl_Interp *, int, Tcl_Obj *CONST[],
159 gdb_variable *));
160
161 static int variable_value PARAMS ((Tcl_Interp *, int, Tcl_Obj *CONST[],
162 gdb_variable *));
163
164 static int variable_editable PARAMS ((gdb_variable *));
165
166 /* Helper functions for the above functions. */
167
168 static gdb_variable *create_variable PARAMS ((char *, char *, CORE_ADDR));
169
170 static void delete_children PARAMS ((Tcl_Interp *, gdb_variable *, int));
171
172 static void install_variable PARAMS ((Tcl_Interp *, char *, gdb_variable *));
173
174 static void uninstall_variable PARAMS ((Tcl_Interp *, gdb_variable *));
175
176 static gdb_variable *child_exists PARAMS ((gdb_variable *, char *));
177
178 static gdb_variable *create_child PARAMS ((Tcl_Interp *, gdb_variable *,
179 char *, int));
180 static char *name_of_child PARAMS ((gdb_variable *, int));
181
182 static int number_of_children PARAMS ((gdb_variable *));
183
184 static enum display_format variable_default_display PARAMS ((gdb_variable *));
185
186 static void save_child_in_parent PARAMS ((gdb_variable *, gdb_variable *));
187
188 static void remove_child_from_parent PARAMS ((gdb_variable *, gdb_variable *));
189
190 static struct type *get_type PARAMS ((value_ptr));
191
192 static struct type *get_target_type PARAMS ((struct type *));
193
194 static Tcl_Obj *get_call_output PARAMS ((void));
195
196 static void clear_gdb_output PARAMS ((void));
197
198 static int call_gdb_type_print PARAMS ((value_ptr));
199
200 static int call_gdb_val_print PARAMS ((value_ptr, int));
201
202 static void variable_fputs PARAMS ((const char *, GDB_FILE *));
203
204 static void null_fputs PARAMS ((const char *, GDB_FILE *));
205
206 static int my_value_equal PARAMS ((gdb_variable *, value_ptr));
207
208 #define INIT_VARIABLE(x) { \
209 (x)->name = NULL; \
210 (x)->real_name = NULL; \
211 (x)->obj_name = NULL; \
212 (x)->exp = NULL; \
213 (x)->valid_block = NULL; \
214 (x)->frame = (CORE_ADDR) 0; \
215 (x)->value = NULL; \
216 (x)->error = 0; \
217 (x)->num_children = 0; \
218 (x)->parent = NULL; \
219 (x)->children = NULL; \
220 (x)->format = FORMAT_NATURAL; \
221 }
222
223 #if defined(FREEIF)
224 # undef FREEIF
225 #endif
226 #define FREEIF(x) if (x != NULL) free((char *) (x))
227
228 /* Initialize the variable code. This function should be called once
229 to install and initialize the variable code into the interpreter. */
230 int
231 gdb_variable_init (interp)
232 Tcl_Interp *interp;
233 {
234 Tcl_Command result;
235
236 result = Tcl_CreateObjCommand (interp, "gdb_variable", call_wrapper,
237 (ClientData) gdb_variable_command, NULL);
238 if (result == NULL)
239 return TCL_ERROR;
240
241 return TCL_OK;
242 }
243
244 /* This function defines the "gdb_variable" command which is used to
245 create variable objects. Its syntax includes:
246
247 gdb_variable create
248 gdb_variable create NAME
249 gdb_variable create -expr EXPR
250 gdb_variable create NAME -expr EXPR
251
252 NAME = name of object to create. If no NAME, then automatically create
253 a name
254 EXPR = the gdb expression for which to create a variable. This will
255 be the most common usage.
256 */
257 static int
258 gdb_variable_command (clientData, interp, objc, objv)
259 ClientData clientData;
260 Tcl_Interp *interp;
261 int objc;
262 Tcl_Obj *CONST objv[];
263 {
264 static char *commands[] = { "create", NULL };
265 enum commands_enum { VARIABLE_CREATE };
266 int index, result;
267
268 if (objc < 2)
269 {
270 Tcl_WrongNumArgs (interp, 1, objv, "option ?arg...?");
271 return TCL_ERROR;
272 }
273
274 if (Tcl_GetIndexFromObj (interp, objv[1], commands, "options", 0,
275 &index) != TCL_OK)
276 {
277 return TCL_ERROR;
278 }
279
280 switch ((enum commands_enum) index)
281 {
282 case VARIABLE_CREATE:
283 result = variable_create (interp, objc - 2, objv + 2);
284 break;
285
286 default:
287 return TCL_ERROR;
288 }
289
290 return result;
291 }
292
293 /* This function implements the actual object command for each
294 variable object that is created (and each of its children).
295
296 Currently the following commands are implemented:
297 - delete delete this object and its children
298 - valueChanged has the value of this object changed since the last check?
299 - numChildren how many children does this object have
300 - children create the children and return a list of their objects
301 - debug print out a little debug info for the object
302 - name print out the name of this variable
303 */
304 static int
305 variable_obj_command (clientData, interp, objc, objv)
306 ClientData clientData;
307 Tcl_Interp *interp;
308 int objc;
309 Tcl_Obj *CONST objv[];
310 {
311 enum commands_enum {
312 VARIABLE_DELETE,
313 VARIABLE_VALUE_CHANGED,
314 VARIABLE_NUM_CHILDREN,
315 VARIABLE_CHILDREN,
316 VARIABLE_DEBUG,
317 VARIABLE_FORMAT,
318 VARIABLE_TYPE,
319 VARIABLE_VALUE,
320 VARIABLE_NAME,
321 VARIABLE_EDITABLE
322 };
323 static char *commands[] = {
324 "delete",
325 "valueChanged",
326 "numChildren",
327 "children",
328 "debug",
329 "format",
330 "type",
331 "value",
332 "name",
333 "editable",
334 NULL
335 };
336 gdb_variable *var = (gdb_variable *) clientData;
337 int index, result;
338
339 if (objc < 2)
340 {
341 Tcl_WrongNumArgs (interp, 1, objv, "option ?arg...?");
342 return TCL_ERROR;
343 }
344
345 if (Tcl_GetIndexFromObj (interp, objv[1], commands, "options", 0,
346 &index) != TCL_OK)
347 return TCL_ERROR;
348
349 result = TCL_OK;
350 switch ((enum commands_enum) index)
351 {
352 case VARIABLE_DELETE:
353 if (objc > 2)
354 {
355 int len;
356 char *s = Tcl_GetStringFromObj (objv[2], &len);
357 if (*s == 'c' && strncmp (s, "children", len) == 0)
358 {
359 delete_children (interp, var, 1);
360 break;
361 }
362 }
363 variable_delete (interp, var);
364 break;
365
366 case VARIABLE_VALUE_CHANGED:
367 {
368 enum value_changed vc = variable_value_changed (var);
369 Tcl_SetObjResult (interp, Tcl_NewStringObj (value_changed_string[vc], -1));
370 }
371 break;
372
373 case VARIABLE_NUM_CHILDREN:
374 Tcl_SetObjResult (interp, Tcl_NewIntObj (var->num_children));
375 break;
376
377 case VARIABLE_CHILDREN:
378 {
379 Tcl_Obj *children = variable_children (interp, var);
380 Tcl_SetObjResult (interp, children);
381 }
382 break;
383
384 case VARIABLE_DEBUG:
385 variable_debug (var);
386 break;
387
388 case VARIABLE_FORMAT:
389 result = variable_format (interp, objc, objv, var);
390 break;
391
392 case VARIABLE_TYPE:
393 result = variable_type (interp, objc, objv, var);
394 break;
395
396 case VARIABLE_VALUE:
397 result = variable_value (interp, objc, objv, var);
398 break;
399
400 case VARIABLE_NAME:
401 Tcl_SetObjResult (interp, Tcl_NewStringObj (var->name, -1));
402 break;
403
404 case VARIABLE_EDITABLE:
405 Tcl_SetObjResult (interp, Tcl_NewIntObj (variable_editable (var)));
406 break;
407
408 default:
409 return TCL_ERROR;
410 }
411
412 return result;
413 }
414
415 /*
416 * Variable object construction/destruction
417 */
418
419 /* This function is responsible for processing the user's specifications
420 and constructing a variable object. */
421 static int
422 variable_create (interp, objc, objv)
423 Tcl_Interp *interp;
424 int objc;
425 Tcl_Obj *CONST objv[];
426 {
427 enum create_opts { CREATE_EXPR, CREATE_PC };
428 static char *create_options[] = { "-expr", "-pc", NULL };
429 gdb_variable *var;
430 char *name;
431 char obj_name[31];
432 int index;
433 static int id = 0;
434 CORE_ADDR pc = (CORE_ADDR) -1;
435
436 /* REMINDER: This command may be invoked in the following ways:
437 gdb_variable create
438 gdb_variable create NAME
439 gdb_variable create -expr EXPR
440 gdb_variable create NAME -expr EXPR
441
442 NAME = name of object to create. If no NAME, then automatically create
443 a name
444 EXPR = the gdb expression for which to create a variable. This will
445 be the most common usage.
446 */
447 name = NULL;
448 if (objc)
449 name = Tcl_GetStringFromObj (objv[0], NULL);
450 if (name == NULL || *name == '-')
451 {
452 /* generate a name for this object */
453 id++;
454 sprintf (obj_name, "var%d", id);
455 }
456 else
457 {
458 /* specified name for object */
459 strncpy (obj_name, name, 30);
460 objv++;
461 objc--;
462 }
463
464 /* Run through all the possible options for this command */
465 name = NULL;
466 while (objc > 0)
467 {
468 if (Tcl_GetIndexFromObj (interp, objv[0], create_options, "options",
469 0, &index) != TCL_OK)
470 {
471 result_ptr->flags |= GDBTK_IN_TCL_RESULT;
472 return TCL_ERROR;
473 }
474
475 switch ((enum create_opts) index)
476 {
477 case CREATE_EXPR:
478 name = Tcl_GetStringFromObj (objv[1], NULL);
479 objc--;
480 objv++;
481 break;
482
483 case CREATE_PC:
484 {
485 char *str;
486 str = Tcl_GetStringFromObj (objv[1], NULL);
487 pc = parse_and_eval_address (str);
488 objc--;
489 objv++;
490 }
491 break;
492
493 default:
494 break;
495 }
496
497 objc--;
498 objv++;
499 }
500
501 /* Create the variable */
502 {
503 /* Add parentheses to the name so that casts do
504 not confuse it. */
505 char *newname = (char *) xmalloc (strlen (name) + 3);
506 sprintf (newname, "(%s)", name);
507 var = create_variable (name, newname, pc);
508 FREEIF (newname);
509 }
510
511 if (var != NULL)
512 {
513 /* Install a command into the interpreter that represents this
514 object */
515 install_variable (interp, obj_name, var);
516 Tcl_SetObjResult (interp, Tcl_NewStringObj (obj_name, -1));
517 result_ptr->flags |= GDBTK_IN_TCL_RESULT;
518
519 return TCL_OK;
520 }
521
522 return TCL_ERROR;
523 }
524
525 /* Fill out a gdb_variable structure for the variable being constructed.
526 This function should never fail if real_name is a valid expression.
527 (That means no longjmp'ing!) */
528 static gdb_variable *
529 create_variable (name, real_name, pc)
530 char *name;
531 char *real_name;
532 CORE_ADDR pc;
533 {
534 gdb_variable *var;
535 value_ptr mark;
536 struct frame_info *fi, *old_fi;
537 struct block *block;
538 void (*old_fputs) PARAMS ((const char *, GDB_FILE *));
539 gdb_result r;
540
541 var = (gdb_variable *) xmalloc (sizeof (gdb_variable));
542 INIT_VARIABLE (var);
543
544 if (name != NULL)
545 {
546 char *p;
547
548 /* Parse and evaluate the expression, filling in as much
549 of the variable's data as possible */
550
551 /* Allow creator to specify context of variable */
552 if (pc == (CORE_ADDR) -1)
553 block = 0;
554 else
555 {
556 r = GDB_block_for_pc (pc, &block);
557 if (r != GDB_OK)
558 block = 0;
559 }
560
561 p = real_name;
562 innermost_block = NULL;
563 r = GDB_parse_exp_1 (&p, block, 0, &(var->exp));
564 if (r != GDB_OK)
565 {
566 FREEIF ((char *) var);
567 return NULL;
568 }
569
570 /* Don't allow variables to be created for types. */
571 if (var->exp->elts[0].opcode == OP_TYPE)
572 {
573 free_current_contents ((char **) &(var->exp));
574 FREEIF (var);
575 printf_unfiltered ("Attempt to use a type name as an expression.");
576 return NULL;
577 }
578
579 var->valid_block = innermost_block;
580 var->name = savestring (name, strlen (name));
581 var->real_name = savestring (real_name, strlen (real_name));
582
583 /* Several of the GDB_* calls can cause messages to be displayed. We swallow
584 those here, because we don't need them (the "value" command will
585 show them). */
586 old_fputs = fputs_unfiltered_hook;
587 fputs_unfiltered_hook = null_fputs;
588
589 /* When the PC is different from the current PC (pc == -1),
590 then we must select the appropriate frame before parsing
591 the expression, otherwise the value will not be current.
592 Since select_frame is so benign, just call it for all cases. */
593 r = GDB_block_innermost_frame (var->valid_block, &fi);
594 if (r != GDB_OK)
595 fi = NULL;
596 if (fi)
597 var->frame = FRAME_FP (fi);
598 old_fi = selected_frame;
599 GDB_select_frame (fi, -1);
600
601 mark = value_mark ();
602 if (GDB_evaluate_expression (var->exp, &var->value) == GDB_OK)
603 {
604 release_value (var->value);
605 if (VALUE_LAZY (var->value))
606 {
607 if (GDB_value_fetch_lazy (var->value) != GDB_OK)
608 var->error = 1;
609 else
610 var->error = 0;
611 }
612 }
613 else
614 var->error = 1;
615 value_free_to_mark (mark);
616
617 /* Reset the selected frame */
618 GDB_select_frame (old_fi, -1);
619
620 /* Restore the output hook to normal */
621 fputs_unfiltered_hook = old_fputs;
622
623 var->num_children = number_of_children (var);
624 var->format = variable_default_display (var);
625 }
626
627 return var;
628 }
629
630 /* Install the given variable VAR into the tcl interpreter with
631 the object name NAME. */
632 static void
633 install_variable (interp, name, var)
634 Tcl_Interp *interp;
635 char *name;
636 gdb_variable *var;
637 {
638 var->obj_name = savestring (name, strlen (name));
639 Tcl_CreateObjCommand (interp, name, variable_obj_command,
640 (ClientData) var, NULL);
641 }
642
643 /* Unistall the object VAR in the tcl interpreter. */
644 static void
645 uninstall_variable (interp, var)
646 Tcl_Interp *interp;
647 gdb_variable *var;
648 {
649 Tcl_DeleteCommand (interp, var->obj_name);
650 }
651
652 /* Delete the variable object VAR and its children */
653 static void
654 variable_delete (interp, var)
655 Tcl_Interp *interp;
656 gdb_variable *var;
657 {
658 /* Delete any children of this variable, too. */
659 delete_children (interp, var, 0);
660
661 /* If this variable has a parent, remove it from its parent's list */
662 if (var->parent != NULL)
663 {
664 remove_child_from_parent (var->parent, var);
665 }
666
667 uninstall_variable (interp, var);
668
669 /* Free memory associated with this variable */
670 FREEIF (var->name);
671 FREEIF (var->real_name);
672 FREEIF (var->obj_name);
673 if (var->exp != NULL)
674 free_current_contents ((char **) &var->exp);
675 FREEIF (var);
676 }
677
678 /* Silly debugging info */
679 static void
680 variable_debug (var)
681 gdb_variable *var;
682 {
683 Tcl_Obj *str;
684
685 str = Tcl_NewStringObj ("name=", -1);
686 Tcl_AppendStringsToObj (str, var->name, "\nreal_name=", var->real_name,
687 "\nobj_name=", var->obj_name, NULL);
688 Tcl_SetObjResult (gdbtk_interp, str);
689 }
690
691 /*
692 * Child construction/destruction
693 */
694
695 /* Delete the children associated with the object VAR. If NOTIFY is set,
696 notify the parent object that this child was deleted. This is used as
697 a small optimization when deleting variables and their children. If the
698 parent is also being deleted, don't bother notifying it that its children
699 are being deleted. */
700 static void
701 delete_children (interp, var, notify)
702 Tcl_Interp *interp;
703 gdb_variable *var;
704 int notify;
705 {
706 struct variable_child *vc;
707 struct variable_child *next;
708
709 for (vc = var->children; vc != NULL; vc = next)
710 {
711 if (!notify)
712 vc->child->parent = NULL;
713 variable_delete (interp, vc->child);
714 next = vc->next;
715 free (vc);
716 }
717 }
718
719 /* Return the number of children for a given variable.
720
721 This can get a little complicated, since we would like to make
722 certain assumptions about certain types of variables.
723
724 - struct/union *: dereference first
725 - (*)(): do not allow derefencing
726 - arrays:
727 - declared size = num of children or
728 - -1 if we don't know, i.e., int foo [];
729 - if there was an error reported constructing this object,
730 assume it has no children (and try this again later)
731 - void * and char * have no children
732 */
733 static int
734 number_of_children (var)
735 gdb_variable *var;
736 {
737 struct type *type;
738 struct type *target;
739 int children;
740
741 if (var->value != NULL)
742 {
743 type = get_type (var->value);
744 target = get_target_type (type);
745 children = 0;
746
747 switch (TYPE_CODE (type))
748 {
749 case TYPE_CODE_ARRAY:
750 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
751 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) != BOUND_CANNOT_BE_DETERMINED)
752 children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
753 else
754 children = -1;
755 break;
756
757 case TYPE_CODE_STRUCT:
758 case TYPE_CODE_UNION:
759 /* If we have a virtual table pointer, omit it. */
760 if (TYPE_VPTR_BASETYPE (type) == type
761 && !(TYPE_VPTR_FIELDNO (type) < 0))
762 children = TYPE_NFIELDS (type) - 1;
763 else
764 children = TYPE_NFIELDS (type);
765 break;
766
767 case TYPE_CODE_PTR:
768 /* This is where things get compilcated. All pointers have one child.
769 Except, of course, for struct and union ptr, which we automagically
770 dereference for the user and function ptrs, which have no children. */
771 switch (TYPE_CODE (target))
772 {
773 case TYPE_CODE_STRUCT:
774 case TYPE_CODE_UNION:
775 /* If we have a virtual table pointer, omit it. */
776 if (TYPE_VPTR_BASETYPE (target) == target
777 && !(TYPE_VPTR_FIELDNO (target) < 0))
778 children = TYPE_NFIELDS (target) - 1;
779 else
780 children = TYPE_NFIELDS (target);
781 break;
782
783 case TYPE_CODE_FUNC:
784 children = 0;
785 break;
786
787 default:
788 /* Don't dereference char* or void*. */
789 if (TYPE_NAME (target) != NULL
790 && (STREQ (TYPE_NAME (target), "char")
791 || STREQ (TYPE_NAME (target), "void")))
792 children = 0;
793 else
794 children = 1;
795 }
796 break;
797
798 default:
799 break;
800 }
801 }
802 else
803 {
804 /* var->value can be null if we tried to access non-existent or
805 protected memory. In this case, we simply do not allow any
806 children. This will be checked again when we check if its
807 value has changed. */
808 children = 0;
809 }
810
811 return children;
812 }
813
814 /* Return a list of all the children of VAR, creating them if necessary. */
815 static Tcl_Obj *
816 variable_children (interp, var)
817 Tcl_Interp *interp;
818 gdb_variable *var;
819 {
820 Tcl_Obj *list;
821 gdb_variable *child;
822 char *name;
823 int i;
824
825 list = Tcl_NewListObj (0, NULL);
826 for (i = 0; i < var->num_children; i++)
827 {
828 /* check if child exists */
829 name = name_of_child (var, i);
830 child = child_exists (var, name);
831 if (child == NULL)
832 {
833 child = create_child (interp, var, name, i);
834
835 /* name_of_child returns a malloc'd string */
836 free (name);
837 }
838 Tcl_ListObjAppendElement (NULL, list, Tcl_NewStringObj (child->obj_name, -1));
839 }
840
841 return list;
842 }
843
844 /* Does a child with the name NAME exist in VAR? If so, return its data.
845 If not, return NULL. */
846 static gdb_variable *
847 child_exists (var, name)
848 gdb_variable *var; /* Parent */
849 char *name; /* name of child */
850 {
851 struct variable_child *vc;
852
853 for (vc = var->children; vc != NULL; vc = vc->next)
854 {
855 if (STREQ (vc->child->name, name))
856 return vc->child;
857 }
858
859 return NULL;
860 }
861
862 /* Create and install a child of the parent of the given name */
863 static gdb_variable *
864 create_child (interp, parent, name, index)
865 Tcl_Interp *interp;
866 gdb_variable *parent;
867 char *name;
868 int index;
869 {
870 struct type *type;
871 struct type *target;
872 gdb_variable *child;
873 char separator[10], prefix[2048], suffix[20];
874 char *childs_name;
875 char *save_name;
876 int deref = 0;
877 int len;
878
879 /* name should never be null. For pointer derefs, it should contain "*name".
880 For arrays of a known size, the name will simply contain the index into
881 the array. */
882
883 separator[0] = '\0';
884 prefix[0] = '\0';
885 suffix[0] = '\0';;
886 save_name = name;
887
888 /* This code must contain a lot of the logic for children based on the parent's
889 type. */
890 type = get_type (parent->value);
891 target = get_target_type (type);
892
893 switch (TYPE_CODE (type))
894 {
895 case TYPE_CODE_ARRAY:
896 sprintf (suffix, "[%s]", name);
897 name = "";
898 break;
899
900 case TYPE_CODE_STRUCT:
901 case TYPE_CODE_UNION:
902 if (index < TYPE_N_BASECLASSES (type))
903 {
904 strcpy (prefix, "((");
905 strcat (prefix, name);
906 strcat (prefix, ")");
907 strcpy (suffix, ") ");
908 name = "";
909 }
910 else
911 strcpy (separator, ".");
912 break;
913
914 case TYPE_CODE_PTR:
915 switch (TYPE_CODE (target))
916 {
917 case TYPE_CODE_STRUCT:
918 case TYPE_CODE_UNION:
919 if (index < TYPE_N_BASECLASSES (target))
920 {
921 strcpy (prefix, "(*(");
922 strcat (prefix, name);
923 strcat (prefix, " *)");
924 strcpy (suffix, ")");
925 name = "";
926 }
927 else
928 strcpy (separator, "->");
929 break;
930
931 default:
932 deref = 1;
933 break;
934 }
935
936 default:
937 break;
938 }
939
940 /* When we get here, we should know how to construct a legal
941 expression for the child's name */
942 len = strlen (prefix);
943 len += strlen (parent->real_name);
944 len += strlen (separator);
945 len += strlen (name);
946 len += strlen (suffix);
947 if (deref)
948 len += 3;
949 childs_name = (char *) xmalloc ((len + 1) * sizeof (char));
950 if (deref)
951 {
952 strcpy (childs_name, "(*");
953 strcat (childs_name, parent->real_name);
954 strcat (childs_name, suffix);
955 strcat (childs_name, ")");
956 }
957 else
958 {
959 strcpy (childs_name, prefix);
960 strcat (childs_name, parent->real_name);
961 strcat (childs_name, separator);
962 strcat (childs_name, name);
963 strcat (childs_name, suffix);
964 }
965
966 /* childs_name now contains a valid expression for the child */
967 child = create_variable (save_name, childs_name, (CORE_ADDR) -1);
968 child->parent = parent;
969 free (childs_name);
970 childs_name = (char *) xmalloc ((strlen (parent->obj_name) + strlen (save_name) + 2)
971 * sizeof (char));
972 sprintf (childs_name, "%s.%s", parent->obj_name, save_name);
973 install_variable (interp, childs_name, child);
974 free (childs_name);
975
976 /* Save a pointer to this child in the parent */
977 save_child_in_parent (parent, child);
978
979 return child;
980 }
981
982 /* Save CHILD in the PARENT's data. */
983 static void
984 save_child_in_parent (parent, child)
985 gdb_variable *parent;
986 gdb_variable *child;
987 {
988 struct variable_child *vc;
989
990 /* Insert the child at the top */
991 vc = parent->children;
992 parent->children =
993 (struct variable_child *) xmalloc (sizeof (struct variable_child));
994
995 parent->children->next = vc;
996 parent->children->child = child;
997 }
998
999 /* Remove the CHILD from the PARENT's list of children. */
1000 static void
1001 remove_child_from_parent (parent, child)
1002 gdb_variable *parent;
1003 gdb_variable *child;
1004 {
1005 struct variable_child *vc, *prev;
1006
1007 /* Find the child in the parent's list */
1008 prev = NULL;
1009 for (vc = parent->children; vc != NULL; )
1010 {
1011 if (vc->child == child)
1012 break;
1013 prev = vc;
1014 vc = vc->next;
1015 }
1016
1017 if (prev == NULL)
1018 parent->children = vc->next;
1019 else
1020 prev->next = vc->next;
1021
1022 }
1023
1024 /* What is the name of the INDEX'th child of VAR? */
1025 static char *
1026 name_of_child (var, index)
1027 gdb_variable *var;
1028 int index;
1029 {
1030 struct type *type;
1031 struct type *target;
1032 char *name;
1033 char *string;
1034
1035 type = get_type (var->value);
1036 target = get_target_type (type);
1037
1038 switch (TYPE_CODE (type))
1039 {
1040 case TYPE_CODE_ARRAY:
1041 {
1042 /* We never get here unless var->num_children is greater than 0... */
1043 int len = 1;
1044 while ((int) pow ((double) 10, (double) len) < index)
1045 len++;
1046 name = (char *) xmalloc (1 + len * sizeof (char));
1047 sprintf (name, "%d", index);
1048 }
1049 break;
1050
1051 case TYPE_CODE_STRUCT:
1052 case TYPE_CODE_UNION:
1053 string = TYPE_FIELD_NAME (type, index);
1054 name = savestring (string, strlen (string));
1055 break;
1056
1057 case TYPE_CODE_PTR:
1058 switch (TYPE_CODE (target))
1059 {
1060 case TYPE_CODE_STRUCT:
1061 case TYPE_CODE_UNION:
1062 string = TYPE_FIELD_NAME (target, index);
1063 name = savestring (string, strlen (string));
1064 break;
1065
1066 default:
1067 name = (char *) xmalloc ((strlen (var->name) + 2) * sizeof (char));
1068 sprintf (name, "*%s", var->name);
1069 break;
1070 }
1071 }
1072
1073 return name;
1074 }
1075
1076 /* Has the value of this object changed since the last time we looked?
1077
1078 There are some special cases:
1079 - structs/unions/arrays. The "value" of these never changes.
1080 Only their children's values change.
1081 - if an error occurred with evaluate_expression or fetch_value_lazy,
1082 then we need to be a little more elaborate with our determination
1083 of "value changed". Specifically, the value does not change when
1084 both the previous evaluate fails and the one done here also fails.
1085 */
1086 static enum value_changed
1087 variable_value_changed (var)
1088 gdb_variable *var;
1089 {
1090 value_ptr mark, new_val;
1091 struct frame_info *fi, *old_fi;
1092 int within_scope;
1093 enum value_changed result;
1094 gdb_result r;
1095
1096 /* Save the selected stack frame, since we will need to change it
1097 in order to evaluate expressions. */
1098 old_fi = selected_frame;
1099
1100 /* Determine whether the variable is still around. */
1101 if (var->valid_block == NULL)
1102 within_scope = 1;
1103 else
1104 {
1105 GDB_reinit_frame_cache ();
1106 r = GDB_find_frame_addr_in_frame_chain (var->frame, &fi);
1107 if (r != GDB_OK)
1108 fi = NULL;
1109 within_scope = fi != NULL;
1110 /* FIXME: GDB_select_frame could fail */
1111 if (within_scope)
1112 GDB_select_frame (fi, -1);
1113 }
1114
1115 result = VALUE_OUT_OF_SCOPE;
1116 if (within_scope)
1117 {
1118 struct type *type = get_type (var->value);
1119
1120 /* Arrays, struct, classes, unions never change value */
1121 if (type != NULL && (TYPE_CODE (type) == TYPE_CODE_STRUCT
1122 || TYPE_CODE (type) == TYPE_CODE_UNION
1123 || TYPE_CODE (type) == TYPE_CODE_ARRAY))
1124 result = VALUE_UNCHANGED;
1125 else
1126 {
1127 mark = value_mark ();
1128 if (GDB_evaluate_expression (var->exp, &new_val) == GDB_OK)
1129 {
1130 if (!my_value_equal (var, new_val))
1131 {
1132 /* value changed */
1133 release_value (new_val);
1134 if (var->value == NULL)
1135 {
1136 /* This can happen if there was an error
1137 evaluating the expression (like deref NULL) */
1138 var->num_children = number_of_children (var);
1139 }
1140 value_free (var->value);
1141 var->value = new_val;
1142 result = VALUE_CHANGED;
1143 }
1144 else
1145 result = VALUE_UNCHANGED;
1146 }
1147 else
1148 {
1149 /* evaluate expression failed. If we failed before, then
1150 the value of this variable has not changed. If we
1151 succeed before, then the value did change. */
1152 if (var->value == NULL)
1153 result = VALUE_UNCHANGED;
1154 else
1155 {
1156 var->value = NULL;
1157 var->error = 1;
1158 result = VALUE_CHANGED;
1159 }
1160 }
1161
1162 value_free_to_mark (mark);
1163 }
1164 }
1165
1166 /* Restore selected frame */
1167 GDB_select_frame (old_fi, -1);
1168
1169 return result;
1170 }
1171
1172 static int
1173 variable_format (interp, objc, objv, var)
1174 Tcl_Interp *interp;
1175 int objc;
1176 Tcl_Obj *CONST objv[];
1177 gdb_variable *var;
1178 {
1179
1180 if (objc > 2)
1181 {
1182 /* Set the format of VAR to given format */
1183 int len;
1184 char *fmt = Tcl_GetStringFromObj (objv[2], &len);
1185 if (STREQN (fmt, "natural", len))
1186 var->format = FORMAT_NATURAL;
1187 else if (STREQN (fmt, "binary", len))
1188 var->format = FORMAT_NATURAL;
1189 else if (STREQN (fmt, "decimal", len))
1190 var->format = FORMAT_DECIMAL;
1191 else if (STREQN (fmt, "hexadecimal", len))
1192 var->format = FORMAT_HEXADECIMAL;
1193 else if (STREQN (fmt, "octal", len))
1194 var->format = FORMAT_OCTAL;
1195 else
1196 {
1197 Tcl_Obj *obj = Tcl_NewStringObj (NULL, 0);
1198 Tcl_AppendStringsToObj (obj, "unknown display format \"",
1199 fmt, "\": must be: \"natural\", \"binary\""
1200 ", \"decimal\", \"hexadecimal\", or \"octal\"",
1201 NULL);
1202 Tcl_SetObjResult (interp, obj);
1203 return TCL_ERROR;
1204 }
1205 }
1206 else
1207 {
1208 /* Report the current format */
1209 Tcl_Obj *fmt;
1210
1211 fmt = Tcl_NewStringObj (format_string [(int) var->format], -1);
1212 Tcl_SetObjResult (interp, fmt);
1213 }
1214
1215 return TCL_OK;
1216 }
1217
1218 /* What is the default display for this variable? We assume that
1219 everything is "natural". Any exceptions? */
1220 static enum display_format
1221 variable_default_display (var)
1222 gdb_variable *var;
1223 {
1224 return FORMAT_NATURAL;
1225 }
1226
1227 /* This function returns the type of a variable in the interpreter (or an error)
1228 and returns either TCL_OK or TCL_ERROR as appropriate. */
1229 static int
1230 variable_type (interp, objc, objv, var)
1231 Tcl_Interp *interp;
1232 int objc;
1233 Tcl_Obj *CONST objv[];
1234 gdb_variable *var;
1235 {
1236 int result;
1237 value_ptr val;
1238 char *first, *last, *string;
1239 Tcl_RegExp regexp;
1240 gdb_result r;
1241
1242 if (var->value != NULL)
1243 val = var->value;
1244 else
1245 {
1246 r = GDB_evaluate_type (var->exp, &val);
1247 if (r != GDB_OK)
1248 return TCL_ERROR;
1249 }
1250
1251 result = call_gdb_type_print (val);
1252 if (result == TCL_OK)
1253 {
1254 string = strdup (Tcl_GetStringFromObj (get_call_output (), NULL));
1255 first = string;
1256
1257 /* gdb will print things out like "struct {...}" for anonymous structs.
1258 In gui-land, we don't want the {...}, so we strip it here. */
1259 regexp = Tcl_RegExpCompile (interp, "{...}");
1260 if (Tcl_RegExpExec (interp, regexp, string, first))
1261 {
1262 /* We have an anonymous struct/union/class/enum */
1263 Tcl_RegExpRange (regexp, 0, &first, &last);
1264 if (*(first - 1) == ' ')
1265 first--;
1266 *first = '\0';
1267 }
1268
1269 Tcl_SetObjResult (interp, Tcl_NewStringObj (string, -1));
1270 FREEIF (string);
1271 return TCL_OK;
1272 }
1273
1274 Tcl_SetObjResult (interp, get_call_output ());
1275 return result;
1276 }
1277
1278 /* This function returns the value of a variable in the interpreter (or an error)
1279 and returns either TCL_OK or TCL_ERROR as appropriate. */
1280 static int
1281 variable_value (interp, objc, objv, var)
1282 Tcl_Interp *interp;
1283 int objc;
1284 Tcl_Obj *CONST objv[];
1285 gdb_variable *var;
1286 {
1287 int result;
1288 struct type *type;
1289 value_ptr val;
1290 Tcl_Obj *str;
1291 gdb_result r;
1292 int real_addressprint;
1293
1294 /* If we set the value of the variable, objv[2] will contain the
1295 variable's new value. We need to first construct a legal expression
1296 for this -- ugh! */
1297 if (objc > 2)
1298 {
1299 /* Does this cover all the bases? */
1300 struct expression *exp;
1301 value_ptr value;
1302 int saved_input_radix = input_radix;
1303
1304 if (VALUE_LVAL (var->value) != not_lval && var->value->modifiable)
1305 {
1306 char *s;
1307
1308 input_radix = 10; /* ALWAYS reset to decimal temporarily */
1309 s = Tcl_GetStringFromObj (objv[2], NULL);
1310 r = GDB_parse_exp_1 (&s, 0, 0, &exp);
1311 if (r != GDB_OK)
1312 return TCL_ERROR;
1313 if (GDB_evaluate_expression (exp, &value) != GDB_OK)
1314 return TCL_ERROR;
1315
1316 val = value_assign (var->value, value);
1317 value_free (var->value);
1318 release_value (val);
1319 var->value = val;
1320 input_radix = saved_input_radix;
1321 }
1322
1323 return TCL_OK;
1324 }
1325
1326 if (var->value != NULL)
1327 val = var->value;
1328 else
1329 {
1330 /* This can happen if we attempt to get the value of a struct
1331 member when the parent is an invalid pointer.
1332
1333 GDB reports the error as the error derived from accessing the
1334 parent, but we don't have access to that here... */
1335 Tcl_SetObjResult (interp, Tcl_NewStringObj ("???", -1));
1336 return TCL_ERROR;
1337 }
1338
1339 /* C++: addressprint causes val_print to print the
1340 address of the reference, too. So clear it to get
1341 the real value -- BUT ONLY FOR C++ REFERENCE TYPES! */
1342 real_addressprint = addressprint;
1343
1344 /* BOGUS: if val_print sees a struct/class, it will print out its
1345 children instead of "{...}" */
1346 type = get_type (val);
1347 switch (TYPE_CODE (type))
1348 {
1349 case TYPE_CODE_STRUCT:
1350 case TYPE_CODE_UNION:
1351 str = Tcl_NewStringObj ("{...}", -1);
1352 break;
1353
1354 case TYPE_CODE_ARRAY:
1355 {
1356 char number[256];
1357 str = Tcl_NewStringObj (NULL, 0);
1358 sprintf (number, "%d", var->num_children);
1359 Tcl_AppendStringsToObj (str, "[", number, "]", NULL);
1360 }
1361 break;
1362
1363 case TYPE_CODE_REF:
1364 /* Clear addressprint so that the actual value is printed */
1365 addressprint = 0;
1366
1367 /* fall through */
1368 default:
1369 result = call_gdb_val_print (val, format_code[(int) var->format]);
1370 Tcl_SetObjResult (interp, get_call_output ());
1371
1372 /* Restore addressprint */
1373 addressprint = real_addressprint;
1374 return result;
1375 }
1376
1377 /* We only get here if we encountered one of the "special types" above */
1378
1379 /* Restore addressprint */
1380 addressprint = real_addressprint;
1381
1382 Tcl_SetObjResult (interp, str);
1383 return TCL_OK;
1384 }
1385
1386 /* Is this variable editable? Use the variable's type to make
1387 this determination. */
1388 static int
1389 variable_editable (var)
1390 gdb_variable *var;
1391 {
1392 struct type *type;
1393 int result;
1394 gdb_result r;
1395
1396 type = get_type (var->value);
1397 if (type == NULL)
1398 {
1399 value_ptr val;
1400 r = GDB_evaluate_type (var->exp, &val);
1401 if (r != GDB_OK)
1402 return 0;
1403 type = get_type (val);
1404 }
1405
1406 switch (TYPE_CODE (type))
1407 {
1408 case TYPE_CODE_STRUCT:
1409 case TYPE_CODE_UNION:
1410 case TYPE_CODE_ARRAY:
1411 case TYPE_CODE_FUNC:
1412 case TYPE_CODE_MEMBER:
1413 case TYPE_CODE_METHOD:
1414 result = 0;
1415 break;
1416
1417 default:
1418 result = 1;
1419 break;
1420 }
1421
1422 return result;
1423 }
1424
1425 /*
1426 * Call stuff. These functions are used to capture the output of gdb commands
1427 * without going through the tcl interpreter.
1428 */
1429
1430 /* Retrieve gdb output in the buffer since last call. */
1431 static Tcl_Obj *
1432 get_call_output ()
1433 {
1434 /* Clear the error flags, in case we errored. */
1435 if (result_ptr != NULL)
1436 result_ptr->flags &= ~GDBTK_ERROR_ONLY;
1437 return fputs_obj;
1438 }
1439
1440 /* Clear the output of the buffer. */
1441 static void
1442 clear_gdb_output ()
1443 {
1444 if (fputs_obj != NULL)
1445 Tcl_DecrRefCount (fputs_obj);
1446
1447 fputs_obj = Tcl_NewStringObj (NULL, -1);
1448 Tcl_IncrRefCount (fputs_obj);
1449 }
1450
1451 /* Call the gdb command "type_print", retaining its output in the buffer. */
1452 static int
1453 call_gdb_type_print (val)
1454 value_ptr val;
1455 {
1456 void (*old_hook) PARAMS ((const char *, GDB_FILE *));
1457 int result;
1458
1459 /* Save the old hook and install new hook */
1460 old_hook = fputs_unfiltered_hook;
1461 fputs_unfiltered_hook = variable_fputs;
1462
1463 /* Call our command with our args */
1464 clear_gdb_output ();
1465
1466
1467 if (GDB_type_print (val, "", gdb_stdout, -1) == GDB_OK)
1468 result = TCL_OK;
1469 else
1470 result = TCL_ERROR;
1471
1472 /* Restore fputs hook */
1473 fputs_unfiltered_hook = old_hook;
1474
1475 return result;
1476 }
1477
1478 /* Call the gdb command "val_print", retaining its output in the buffer. */
1479 static int
1480 call_gdb_val_print (val, format)
1481 value_ptr val;
1482 int format;
1483 {
1484 void (*old_hook) PARAMS ((const char *, GDB_FILE *));
1485 gdb_result r;
1486 int result;
1487
1488 /* Save the old hook and install new hook */
1489 old_hook = fputs_unfiltered_hook;
1490 fputs_unfiltered_hook = variable_fputs;
1491
1492 /* Call our command with our args */
1493 clear_gdb_output ();
1494
1495 if (VALUE_LAZY (val))
1496 {
1497 r = GDB_value_fetch_lazy (val);
1498 if (r != GDB_OK)
1499 {
1500 fputs_unfiltered_hook = old_hook;
1501 return TCL_ERROR;
1502 }
1503 }
1504 r = GDB_val_print (VALUE_TYPE (val), VALUE_CONTENTS_RAW (val), VALUE_ADDRESS (val),
1505 gdb_stdout, format, 1, 0, 0);
1506 if (r == GDB_OK)
1507 result = TCL_OK;
1508 else
1509 result = TCL_ERROR;
1510
1511 /* Restore fputs hook */
1512 fputs_unfiltered_hook = old_hook;
1513
1514 return result;
1515 }
1516
1517 /* The fputs_unfiltered_hook function used to save the output from one of the
1518 call commands in this file. */
1519 static void
1520 variable_fputs (text, stream)
1521 const char *text;
1522 GDB_FILE *stream;
1523 {
1524 /* Just append everything to the fputs_obj... Issues with stderr/stdout? */
1525 Tcl_AppendToObj (fputs_obj, (char *) text, -1);
1526 }
1527
1528 /* Empty handler for the fputs_unfiltered_hook. Set the hook to this function
1529 whenever the output is irrelevent. */
1530 static void
1531 null_fputs (text, stream)
1532 const char *text;
1533 GDB_FILE *stream;
1534 {
1535 return;
1536 }
1537
1538 /*
1539 * Special wrapper-like stuff to supplement the generic wrappers
1540 */
1541
1542 /* This returns the type of the variable. This skips past typedefs
1543 and returns the real type of the variable. */
1544 static struct type *
1545 get_type (val)
1546 value_ptr val;
1547 {
1548 struct type *type = NULL;
1549
1550 if (val != NULL)
1551 {
1552 type = VALUE_TYPE (val);
1553 while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1554 type = TYPE_TARGET_TYPE (type);
1555 }
1556
1557 return type;
1558 }
1559
1560 /* This returns the target type (or NULL) of TYPE, also skipping
1561 past typedefs, just like get_type (). */
1562 static struct type *
1563 get_target_type (type)
1564 struct type *type;
1565 {
1566 if (type != NULL)
1567 {
1568 type = TYPE_TARGET_TYPE (type);
1569 while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1570 type = TYPE_TARGET_TYPE (type);
1571 }
1572
1573 return type;
1574 }
1575
1576 /* This function is a special wrap. This call never "fails".*/
1577 static int
1578 my_value_equal (var, val2)
1579 gdb_variable *var;
1580 value_ptr val2;
1581 {
1582 int err1, err2, r;
1583
1584 /* This is bogus, but unfortunately necessary. We must know
1585 exactly what caused an error -- reading var->val (which we
1586 get from var->error and/or val2, so that we can really determine
1587 if we think that something has changed. */
1588 err1 = var->error;
1589 err2 = 0;
1590 if (VALUE_LAZY (val2) && GDB_value_fetch_lazy (val2) != GDB_OK)
1591 err2 = 1;
1592
1593 /* Another special case: NULL values. If both are null, say
1594 they're equal. */
1595 if (var->value == NULL && val2 == NULL)
1596 return 1;
1597 else if (var->value == NULL || val2 == NULL)
1598 return 0;
1599
1600 if (GDB_value_equal (var->value, val2, &r) != GDB_OK)
1601 {
1602 /* An error occurred, this could have happened if
1603 either val1 or val2 errored. ERR1 and ERR2 tell
1604 us which of these it is. If both errored, then
1605 we assume nothing has changed. If one of them is
1606 valid, though, then something has changed. */
1607 if (err1 == err2)
1608 {
1609 /* both the old and new values caused errors, so
1610 we say the value did not change */
1611 /* This is indeterminate, though. Perhaps we should
1612 be safe and say, yes, it changed anyway?? */
1613 return 1;
1614 }
1615 else
1616 {
1617 /* err2 replaces var->error since this new value
1618 WILL replace the old one. */
1619 var->error = err2;
1620 return 0;
1621 }
1622 }
1623
1624 return r;
1625 }
1626 \f
1627 /* Local variables: */
1628 /* change-log-default-name: "ChangeLog-gdbtk" */
1629 /* End: */