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

Side by Side Diff: gdb/varobj.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 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/varobj.h ('k') | gdb/vax-nat.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
None
OLDNEW
1 /* Implementation of the GDB variable objects API. 1 /* Implementation of the GDB variable objects API.
2 2
3 Copyright (C) 1999-2012 Free Software Foundation, Inc. 3 Copyright (C) 1999-2013 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or 7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 17
18 #include "defs.h" 18 #include "defs.h"
19 #include "exceptions.h" 19 #include "exceptions.h"
20 #include "value.h" 20 #include "value.h"
21 #include "expression.h" 21 #include "expression.h"
22 #include "frame.h" 22 #include "frame.h"
23 #include "language.h" 23 #include "language.h"
24 #include "gdbcmd.h" 24 #include "gdbcmd.h"
25 #include "block.h" 25 #include "block.h"
26 #include "valprint.h" 26 #include "valprint.h"
27 27
28 #include "gdb_assert.h" 28 #include "gdb_assert.h"
29 #include "gdb_string.h" 29 #include <string.h>
30 #include "gdb_regex.h" 30 #include "gdb_regex.h"
31 31
32 #include "varobj.h" 32 #include "varobj.h"
33 #include "vec.h" 33 #include "vec.h"
34 #include "gdbthread.h" 34 #include "gdbthread.h"
35 #include "inferior.h" 35 #include "inferior.h"
36 #include "ada-varobj.h"
37 #include "ada-lang.h"
38 36
39 #if HAVE_PYTHON 37 #if HAVE_PYTHON
40 #include "python/python.h" 38 #include "python/python.h"
41 #include "python/python-internal.h" 39 #include "python/python-internal.h"
42 #else 40 #else
43 typedef int PyObject; 41 typedef int PyObject;
44 #endif 42 #endif
45 43
46 /* The names of varobjs representing anonymous structs or unions. */
47 #define ANONYMOUS_STRUCT_NAME _("<anonymous struct>")
48 #define ANONYMOUS_UNION_NAME _("<anonymous union>")
49
50 /* Non-zero if we want to see trace of varobj level stuff. */ 44 /* Non-zero if we want to see trace of varobj level stuff. */
51 45
52 int varobjdebug = 0; 46 unsigned int varobjdebug = 0;
53 static void 47 static void
54 show_varobjdebug (struct ui_file *file, int from_tty, 48 show_varobjdebug (struct ui_file *file, int from_tty,
55 struct cmd_list_element *c, const char *value) 49 struct cmd_list_element *c, const char *value)
56 { 50 {
57 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value); 51 fprintf_filtered (file, _("Varobj debugging is %s.\n"), value);
58 } 52 }
59 53
60 /* String representations of gdb's format codes. */ 54 /* String representations of gdb's format codes. */
61 char *varobj_format_string[] = 55 char *varobj_format_string[] =
62 { "natural", "binary", "decimal", "hexadecimal", "octal" }; 56 { "natural", "binary", "decimal", "hexadecimal", "octal" };
63 57
64 /* String representations of gdb's known languages. */
65 char *varobj_language_string[] = { "unknown", "C", "C++", "Java" };
66
67 /* True if we want to allow Python-based pretty-printing. */ 58 /* True if we want to allow Python-based pretty-printing. */
68 static int pretty_printing = 0; 59 static int pretty_printing = 0;
69 60
70 void 61 void
71 varobj_enable_pretty_printing (void) 62 varobj_enable_pretty_printing (void)
72 { 63 {
73 pretty_printing = 1; 64 pretty_printing = 1;
74 } 65 }
75 66
76 /* Data structures */ 67 /* Data structures */
77 68
78 /* Every root variable has one of these structures saved in its 69 /* Every root variable has one of these structures saved in its
79 varobj. Members which must be free'd are noted. */ 70 varobj. Members which must be free'd are noted. */
80 struct varobj_root 71 struct varobj_root
81 { 72 {
82 73
83 /* Alloc'd expression for this parent. */ 74 /* Alloc'd expression for this parent. */
84 struct expression *exp; 75 struct expression *exp;
85 76
86 /* Block for which this expression is valid. */ 77 /* Block for which this expression is valid. */
87 struct block *valid_block; 78 const struct block *valid_block;
88 79
89 /* The frame for this expression. This field is set iff valid_block is 80 /* The frame for this expression. This field is set iff valid_block is
90 not NULL. */ 81 not NULL. */
91 struct frame_id frame; 82 struct frame_id frame;
92 83
93 /* The thread ID that this varobj_root belong to. This field 84 /* The thread ID that this varobj_root belong to. This field
94 is only valid if valid_block is not NULL. 85 is only valid if valid_block is not NULL.
95 When not 0, indicates which thread 'frame' belongs to. 86 When not 0, indicates which thread 'frame' belongs to.
96 When 0, indicates that the thread list was empty when the varobj_root 87 When 0, indicates that the thread list was empty when the varobj_root
97 was created. */ 88 was created. */
98 int thread_id; 89 int thread_id;
99 90
100 /* If 1, the -var-update always recomputes the value in the 91 /* If 1, the -var-update always recomputes the value in the
101 current thread and frame. Otherwise, variable object is 92 current thread and frame. Otherwise, variable object is
102 always updated in the specific scope/thread/frame. */ 93 always updated in the specific scope/thread/frame. */
103 int floating; 94 int floating;
104 95
105 /* Flag that indicates validity: set to 0 when this varobj_root refers 96 /* Flag that indicates validity: set to 0 when this varobj_root refers
106 to symbols that do not exist anymore. */ 97 to symbols that do not exist anymore. */
107 int is_valid; 98 int is_valid;
108 99
109 /* Language info for this variable and its children. */ 100 /* Language-related operations for this variable and its
110 struct language_specific *lang; 101 children. */
102 const struct lang_varobj_ops *lang_ops;
111 103
112 /* The varobj for this root node. */ 104 /* The varobj for this root node. */
113 struct varobj *rootvar; 105 struct varobj *rootvar;
114 106
115 /* Next root variable */ 107 /* Next root variable */
116 struct varobj_root *next; 108 struct varobj_root *next;
117 }; 109 };
118 110
119 /* Every variable in the system has a structure of this type defined 111 /* Dynamic part of varobj. */
120 for it. This structure holds all information necessary to manipulate 112
121 a particular object variable. Members which must be freed are noted. */ 113 struct varobj_dynamic
122 struct varobj
123 { 114 {
124
125 /* Alloc'd name of the variable for this object. If this variable is a
126 child, then this name will be the child's source name.
127 (bar, not foo.bar). */
128 /* NOTE: This is the "expression". */
129 char *name;
130
131 /* Alloc'd expression for this child. Can be used to create a
132 root variable corresponding to this child. */
133 char *path_expr;
134
135 /* The alloc'd name for this variable's object. This is here for
136 convenience when constructing this object's children. */
137 char *obj_name;
138
139 /* Index of this variable in its parent or -1. */
140 int index;
141
142 /* The type of this variable. This can be NULL
143 for artifial variable objects -- currently, the "accessibility"
144 variable objects in C++. */
145 struct type *type;
146
147 /* The value of this expression or subexpression. A NULL value
148 indicates there was an error getting this value.
149 Invariant: if varobj_value_is_changeable_p (this) is non-zero,
150 the value is either NULL, or not lazy. */
151 struct value *value;
152
153 /* The number of (immediate) children this variable has. */
154 int num_children;
155
156 /* If this object is a child, this points to its immediate parent. */
157 struct varobj *parent;
158
159 /* Children of this object. */
160 VEC (varobj_p) *children;
161
162 /* Whether the children of this varobj were requested. This field is 115 /* Whether the children of this varobj were requested. This field is
163 used to decide if dynamic varobj should recompute their children. 116 used to decide if dynamic varobj should recompute their children.
164 In the event that the frontend never asked for the children, we 117 In the event that the frontend never asked for the children, we
165 can avoid that. */ 118 can avoid that. */
166 int children_requested; 119 int children_requested;
167 120
168 /* Description of the root variable. Points to root variable for
169 children. */
170 struct varobj_root *root;
171
172 /* The format of the output for this object. */
173 enum varobj_display_formats format;
174
175 /* Was this variable updated via a varobj_set_value operation. */
176 int updated;
177
178 /* Last print value. */
179 char *print_value;
180
181 /* Is this variable frozen. Frozen variables are never implicitly
182 updated by -var-update *
183 or -var-update <direct-or-indirect-parent>. */
184 int frozen;
185
186 /* Is the value of this variable intentionally not fetched? It is
187 not fetched if either the variable is frozen, or any parents is
188 frozen. */
189 int not_fetched;
190
191 /* Sub-range of children which the MI consumer has requested. If
192 FROM < 0 or TO < 0, means that all children have been
193 requested. */
194 int from;
195 int to;
196
197 /* The pretty-printer constructor. If NULL, then the default 121 /* The pretty-printer constructor. If NULL, then the default
198 pretty-printer will be looked up. If None, then no 122 pretty-printer will be looked up. If None, then no
199 pretty-printer will be installed. */ 123 pretty-printer will be installed. */
200 PyObject *constructor; 124 PyObject *constructor;
201 125
202 /* The pretty-printer that has been constructed. If NULL, then a 126 /* The pretty-printer that has been constructed. If NULL, then a
203 new printer object is needed, and one will be constructed. */ 127 new printer object is needed, and one will be constructed. */
204 PyObject *pretty_printer; 128 PyObject *pretty_printer;
205 129
206 /* The iterator returned by the printer's 'children' method, or NULL 130 /* The iterator returned by the printer's 'children' method, or NULL
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 static void delete_variable_1 (struct cpstack **, int *, 162 static void delete_variable_1 (struct cpstack **, int *,
239 struct varobj *, int, int); 163 struct varobj *, int, int);
240 164
241 static int install_variable (struct varobj *); 165 static int install_variable (struct varobj *);
242 166
243 static void uninstall_variable (struct varobj *); 167 static void uninstall_variable (struct varobj *);
244 168
245 static struct varobj *create_child (struct varobj *, int, char *); 169 static struct varobj *create_child (struct varobj *, int, char *);
246 170
247 static struct varobj * 171 static struct varobj *
248 create_child_with_value (struct varobj *parent, int index, const char *name, 172 create_child_with_value (struct varobj *parent, int index, char *name,
249 struct value *value); 173 struct value *value);
250 174
251 /* Utility routines */ 175 /* Utility routines */
252 176
253 static struct varobj *new_variable (void); 177 static struct varobj *new_variable (void);
254 178
255 static struct varobj *new_root_variable (void); 179 static struct varobj *new_root_variable (void);
256 180
257 static void free_variable (struct varobj *var); 181 static void free_variable (struct varobj *var);
258 182
259 static struct cleanup *make_cleanup_free_variable (struct varobj *var); 183 static struct cleanup *make_cleanup_free_variable (struct varobj *var);
260 184
261 static struct type *get_type (struct varobj *var);
262
263 static struct type *get_value_type (struct varobj *var);
264
265 static struct type *get_target_type (struct type *);
266
267 static enum varobj_display_formats variable_default_display (struct varobj *); 185 static enum varobj_display_formats variable_default_display (struct varobj *);
268 186
269 static void cppush (struct cpstack **pstack, char *name); 187 static void cppush (struct cpstack **pstack, char *name);
270 188
271 static char *cppop (struct cpstack **pstack); 189 static char *cppop (struct cpstack **pstack);
272 190
273 static int update_type_if_necessary (struct varobj *var, 191 static int update_type_if_necessary (struct varobj *var,
274 struct value *new_value); 192 struct value *new_value);
275 193
276 static int install_new_value (struct varobj *var, struct value *value, 194 static int install_new_value (struct varobj *var, struct value *value,
277 int initial); 195 int initial);
278 196
279 /* Language-specific routines. */ 197 /* Language-specific routines. */
280 198
281 static enum varobj_languages variable_language (struct varobj *var);
282
283 static int number_of_children (struct varobj *); 199 static int number_of_children (struct varobj *);
284 200
285 static char *name_of_variable (struct varobj *); 201 static char *name_of_variable (struct varobj *);
286 202
287 static char *name_of_child (struct varobj *, int); 203 static char *name_of_child (struct varobj *, int);
288 204
289 static struct value *value_of_root (struct varobj **var_handle, int *); 205 static struct value *value_of_root (struct varobj **var_handle, int *);
290 206
291 static struct value *value_of_child (struct varobj *parent, int index); 207 static struct value *value_of_child (struct varobj *parent, int index);
292 208
293 static char *my_value_of_variable (struct varobj *var, 209 static char *my_value_of_variable (struct varobj *var,
294 enum varobj_display_formats format); 210 enum varobj_display_formats format);
295 211
296 static char *value_get_print_value (struct value *value,
297 enum varobj_display_formats format,
298 struct varobj *var);
299
300 static int varobj_value_is_changeable_p (struct varobj *var);
301
302 static int is_root_p (struct varobj *var); 212 static int is_root_p (struct varobj *var);
303 213
304 #if HAVE_PYTHON 214 #if HAVE_PYTHON
305 215
306 static struct varobj *varobj_add_child (struct varobj *var, 216 static struct varobj *varobj_add_child (struct varobj *var,
307 » » » » » const char *name, 217 » » » » » char *name,
308 struct value *value); 218 struct value *value);
309 219
310 #endif /* HAVE_PYTHON */ 220 #endif /* HAVE_PYTHON */
311 221
312 static int default_value_is_changeable_p (struct varobj *var);
313
314 /* C implementation */
315
316 static int c_number_of_children (struct varobj *var);
317
318 static char *c_name_of_variable (struct varobj *parent);
319
320 static char *c_name_of_child (struct varobj *parent, int index);
321
322 static char *c_path_expr_of_child (struct varobj *child);
323
324 static struct value *c_value_of_root (struct varobj **var_handle);
325
326 static struct value *c_value_of_child (struct varobj *parent, int index);
327
328 static struct type *c_type_of_child (struct varobj *parent, int index);
329
330 static char *c_value_of_variable (struct varobj *var,
331 enum varobj_display_formats format);
332
333 /* C++ implementation */
334
335 static int cplus_number_of_children (struct varobj *var);
336
337 static void cplus_class_num_children (struct type *type, int children[3]);
338
339 static char *cplus_name_of_variable (struct varobj *parent);
340
341 static char *cplus_name_of_child (struct varobj *parent, int index);
342
343 static char *cplus_path_expr_of_child (struct varobj *child);
344
345 static struct value *cplus_value_of_root (struct varobj **var_handle);
346
347 static struct value *cplus_value_of_child (struct varobj *parent, int index);
348
349 static struct type *cplus_type_of_child (struct varobj *parent, int index);
350
351 static char *cplus_value_of_variable (struct varobj *var,
352 enum varobj_display_formats format);
353
354 /* Java implementation */
355
356 static int java_number_of_children (struct varobj *var);
357
358 static char *java_name_of_variable (struct varobj *parent);
359
360 static char *java_name_of_child (struct varobj *parent, int index);
361
362 static char *java_path_expr_of_child (struct varobj *child);
363
364 static struct value *java_value_of_root (struct varobj **var_handle);
365
366 static struct value *java_value_of_child (struct varobj *parent, int index);
367
368 static struct type *java_type_of_child (struct varobj *parent, int index);
369
370 static char *java_value_of_variable (struct varobj *var,
371 enum varobj_display_formats format);
372
373 /* Ada implementation */
374
375 static int ada_number_of_children (struct varobj *var);
376
377 static char *ada_name_of_variable (struct varobj *parent);
378
379 static char *ada_name_of_child (struct varobj *parent, int index);
380
381 static char *ada_path_expr_of_child (struct varobj *child);
382
383 static struct value *ada_value_of_root (struct varobj **var_handle);
384
385 static struct value *ada_value_of_child (struct varobj *parent, int index);
386
387 static struct type *ada_type_of_child (struct varobj *parent, int index);
388
389 static char *ada_value_of_variable (struct varobj *var,
390 enum varobj_display_formats format);
391
392 static int ada_value_is_changeable_p (struct varobj *var);
393
394 static int ada_value_has_mutated (struct varobj *var, struct value *new_val,
395 struct type *new_type);
396
397 /* The language specific vector */
398
399 struct language_specific
400 {
401
402 /* The language of this variable. */
403 enum varobj_languages language;
404
405 /* The number of children of PARENT. */
406 int (*number_of_children) (struct varobj * parent);
407
408 /* The name (expression) of a root varobj. */
409 char *(*name_of_variable) (struct varobj * parent);
410
411 /* The name of the INDEX'th child of PARENT. */
412 char *(*name_of_child) (struct varobj * parent, int index);
413
414 /* Returns the rooted expression of CHILD, which is a variable
415 obtain that has some parent. */
416 char *(*path_expr_of_child) (struct varobj * child);
417
418 /* The ``struct value *'' of the root variable ROOT. */
419 struct value *(*value_of_root) (struct varobj ** root_handle);
420
421 /* The ``struct value *'' of the INDEX'th child of PARENT. */
422 struct value *(*value_of_child) (struct varobj * parent, int index);
423
424 /* The type of the INDEX'th child of PARENT. */
425 struct type *(*type_of_child) (struct varobj * parent, int index);
426
427 /* The current value of VAR. */
428 char *(*value_of_variable) (struct varobj * var,
429 enum varobj_display_formats format);
430
431 /* Return non-zero if changes in value of VAR must be detected and
432 reported by -var-update. Return zero if -var-update should never
433 report changes of such values. This makes sense for structures
434 (since the changes in children values will be reported separately),
435 or for artifical objects (like 'public' pseudo-field in C++).
436
437 Return value of 0 means that gdb need not call value_fetch_lazy
438 for the value of this variable object. */
439 int (*value_is_changeable_p) (struct varobj *var);
440
441 /* Return nonzero if the type of VAR has mutated.
442
443 VAR's value is still the varobj's previous value, while NEW_VALUE
444 is VAR's new value and NEW_TYPE is the var's new type. NEW_VALUE
445 may be NULL indicating that there is no value available (the varobj
446 may be out of scope, of may be the child of a null pointer, for
447 instance). NEW_TYPE, on the other hand, must never be NULL.
448
449 This function should also be able to assume that var's number of
450 children is set (not < 0).
451
452 Languages where types do not mutate can set this to NULL. */
453 int (*value_has_mutated) (struct varobj *var, struct value *new_value,
454 struct type *new_type);
455 };
456
457 /* Array of known source language routines. */
458 static struct language_specific languages[vlang_end] = {
459 /* Unknown (try treating as C). */
460 {
461 vlang_unknown,
462 c_number_of_children,
463 c_name_of_variable,
464 c_name_of_child,
465 c_path_expr_of_child,
466 c_value_of_root,
467 c_value_of_child,
468 c_type_of_child,
469 c_value_of_variable,
470 default_value_is_changeable_p,
471 NULL /* value_has_mutated */}
472 ,
473 /* C */
474 {
475 vlang_c,
476 c_number_of_children,
477 c_name_of_variable,
478 c_name_of_child,
479 c_path_expr_of_child,
480 c_value_of_root,
481 c_value_of_child,
482 c_type_of_child,
483 c_value_of_variable,
484 default_value_is_changeable_p,
485 NULL /* value_has_mutated */}
486 ,
487 /* C++ */
488 {
489 vlang_cplus,
490 cplus_number_of_children,
491 cplus_name_of_variable,
492 cplus_name_of_child,
493 cplus_path_expr_of_child,
494 cplus_value_of_root,
495 cplus_value_of_child,
496 cplus_type_of_child,
497 cplus_value_of_variable,
498 default_value_is_changeable_p,
499 NULL /* value_has_mutated */}
500 ,
501 /* Java */
502 {
503 vlang_java,
504 java_number_of_children,
505 java_name_of_variable,
506 java_name_of_child,
507 java_path_expr_of_child,
508 java_value_of_root,
509 java_value_of_child,
510 java_type_of_child,
511 java_value_of_variable,
512 default_value_is_changeable_p,
513 NULL /* value_has_mutated */},
514 /* Ada */
515 {
516 vlang_ada,
517 ada_number_of_children,
518 ada_name_of_variable,
519 ada_name_of_child,
520 ada_path_expr_of_child,
521 ada_value_of_root,
522 ada_value_of_child,
523 ada_type_of_child,
524 ada_value_of_variable,
525 ada_value_is_changeable_p,
526 ada_value_has_mutated}
527 };
528
529 /* A little convenience enum for dealing with C++/Java. */
530 enum vsections
531 {
532 v_public = 0, v_private, v_protected
533 };
534
535 /* Private data */ 222 /* Private data */
536 223
537 /* Mappings of varobj_display_formats enums to gdb's format codes. */ 224 /* Mappings of varobj_display_formats enums to gdb's format codes. */
538 static int format_code[] = { 0, 't', 'd', 'x', 'o' }; 225 static int format_code[] = { 0, 't', 'd', 'x', 'o' };
539 226
540 /* Header of the list of root variable objects. */ 227 /* Header of the list of root variable objects. */
541 static struct varobj_root *rootlist; 228 static struct varobj_root *rootlist;
542 229
543 /* Prime number indicating the number of buckets in the hash table. */ 230 /* Prime number indicating the number of buckets in the hash table. */
544 /* A prime large enough to avoid too many colisions. */ 231 /* A prime large enough to avoid too many colisions. */
545 #define VAROBJ_TABLE_SIZE 227 232 #define VAROBJ_TABLE_SIZE 227
546 233

error: old chunk mismatch

OLDNEW
« no previous file with comments | « gdb/varobj.h ('k') | gdb/vax-nat.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698