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

Side by Side Diff: gdb/cp-valprint.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/cp-support.c ('k') | gdb/cris-linux-tdep.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Support for printing C++ values for GDB, the GNU debugger. 1 /* Support for printing C++ values for GDB, the GNU debugger.
2 2
3 Copyright (C) 1986, 1988-1989, 1991-1997, 2000-2003, 2005-2012 Free 3 Copyright (C) 1986-2013 Free Software Foundation, Inc.
4 Software Foundation, Inc.
5 4
6 This file is part of GDB. 5 This file is part of GDB.
7 6
8 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or 9 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version. 10 (at your option) any later version.
12 11
13 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 15 GNU General Public License for more details.
17 16
18 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 19
21 #include "defs.h" 20 #include "defs.h"
22 #include "gdb_obstack.h" 21 #include "gdb_obstack.h"
23 #include "symtab.h" 22 #include "symtab.h"
24 #include "gdbtypes.h" 23 #include "gdbtypes.h"
25 #include "expression.h" 24 #include "expression.h"
26 #include "value.h" 25 #include "value.h"
27 #include "command.h" 26 #include "command.h"
28 #include "gdbcmd.h" 27 #include "gdbcmd.h"
29 #include "demangle.h" 28 #include "demangle.h"
30 #include "annotate.h" 29 #include "annotate.h"
31 #include "gdb_string.h" 30 #include <string.h>
32 #include "c-lang.h" 31 #include "c-lang.h"
33 #include "target.h" 32 #include "target.h"
34 #include "cp-abi.h" 33 #include "cp-abi.h"
35 #include "valprint.h" 34 #include "valprint.h"
36 #include "cp-support.h" 35 #include "cp-support.h"
37 #include "language.h" 36 #include "language.h"
38 #include "python/python.h" 37 #include "python/python.h"
39 #include "exceptions.h" 38 #include "exceptions.h"
39 #include "typeprint.h"
40 40
41 /* Controls printing of vtbl's. */ 41 /* Controls printing of vtbl's. */
42 static void 42 static void
43 show_vtblprint (struct ui_file *file, int from_tty, 43 show_vtblprint (struct ui_file *file, int from_tty,
44 struct cmd_list_element *c, const char *value) 44 struct cmd_list_element *c, const char *value)
45 { 45 {
46 fprintf_filtered (file, _("\ 46 fprintf_filtered (file, _("\
47 Printing of C++ virtual function tables is %s.\n"), 47 Printing of C++ virtual function tables is %s.\n"),
48 value); 48 value);
49 } 49 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 /* Second, print out data fields */ 204 /* Second, print out data fields */
205 205
206 /* If there are no data fields, skip this part */ 206 /* If there are no data fields, skip this part */
207 if (len == n_baseclasses || !len) 207 if (len == n_baseclasses || !len)
208 fprintf_filtered (stream, "<No data fields>"); 208 fprintf_filtered (stream, "<No data fields>");
209 else 209 else
210 { 210 {
211 int statmem_obstack_initial_size = 0; 211 int statmem_obstack_initial_size = 0;
212 int stat_array_obstack_initial_size = 0; 212 int stat_array_obstack_initial_size = 0;
213 213 struct type *vptr_basetype = NULL;
214 int vptr_fieldno;
215
214 if (dont_print_statmem == 0) 216 if (dont_print_statmem == 0)
215 { 217 {
216 statmem_obstack_initial_size = 218 statmem_obstack_initial_size =
217 obstack_object_size (&dont_print_statmem_obstack); 219 obstack_object_size (&dont_print_statmem_obstack);
218 220
219 if (last_set_recurse != recurse) 221 if (last_set_recurse != recurse)
220 { 222 {
221 stat_array_obstack_initial_size = 223 stat_array_obstack_initial_size =
222 obstack_object_size (&dont_print_stat_array_obstack); 224 obstack_object_size (&dont_print_stat_array_obstack);
223 225
224 last_set_recurse = recurse; 226 last_set_recurse = recurse;
225 } 227 }
226 } 228 }
227 229
230 vptr_fieldno = get_vptr_fieldno (type, &vptr_basetype);
228 for (i = n_baseclasses; i < len; i++) 231 for (i = n_baseclasses; i < len; i++)
229 { 232 {
230 /* If requested, skip printing of static fields. */ 233 /* If requested, skip printing of static fields. */
231 if (!options->static_field_print 234 if (!options->static_field_print
232 && field_is_static (&TYPE_FIELD (type, i))) 235 && field_is_static (&TYPE_FIELD (type, i)))
233 continue; 236 continue;
234 237
235 if (fields_seen) 238 if (fields_seen)
236 fprintf_filtered (stream, ", "); 239 fprintf_filtered (stream, ", ");
237 else if (n_baseclasses > 0) 240 else if (n_baseclasses > 0)
238 { 241 {
239 » if (options->pretty) 242 » if (options->prettyformat)
240 { 243 {
241 fprintf_filtered (stream, "\n"); 244 fprintf_filtered (stream, "\n");
242 print_spaces_filtered (2 + 2 * recurse, stream); 245 print_spaces_filtered (2 + 2 * recurse, stream);
243 fputs_filtered ("members of ", stream); 246 fputs_filtered ("members of ", stream);
244 fputs_filtered (type_name_no_tag (type), stream); 247 fputs_filtered (type_name_no_tag (type), stream);
245 fputs_filtered (": ", stream); 248 fputs_filtered (": ", stream);
246 } 249 }
247 } 250 }
248 fields_seen = 1; 251 fields_seen = 1;
249 252
250 » if (options->pretty) 253 » if (options->prettyformat)
251 { 254 {
252 fprintf_filtered (stream, "\n"); 255 fprintf_filtered (stream, "\n");
253 print_spaces_filtered (2 + 2 * recurse, stream); 256 print_spaces_filtered (2 + 2 * recurse, stream);
254 } 257 }
255 else 258 else
256 { 259 {
257 wrap_here (n_spaces (2 + 2 * recurse)); 260 wrap_here (n_spaces (2 + 2 * recurse));
258 } 261 }
259 if (options->inspect_it)
260 {
261 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
262 fputs_filtered ("\"( ptr \"", stream);
263 else
264 fputs_filtered ("\"( nodef \"", stream);
265 if (field_is_static (&TYPE_FIELD (type, i)))
266 fputs_filtered ("static ", stream);
267 fprintf_symbol_filtered (stream,
268 TYPE_FIELD_NAME (type, i),
269 current_language->la_language,
270 DMGL_PARAMS | DMGL_ANSI);
271 fputs_filtered ("\" \"", stream);
272 fprintf_symbol_filtered (stream,
273 TYPE_FIELD_NAME (type, i),
274 current_language->la_language,
275 DMGL_PARAMS | DMGL_ANSI);
276 fputs_filtered ("\") \"", stream);
277 }
278 else
279 {
280 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
281 262
282 » if (field_is_static (&TYPE_FIELD (type, i))) 263 » annotate_field_begin (TYPE_FIELD_TYPE (type, i));
283 » » fputs_filtered ("static ", stream); 264
284 » fprintf_symbol_filtered (stream, 265 » if (field_is_static (&TYPE_FIELD (type, i)))
285 » » » » TYPE_FIELD_NAME (type, i), 266 » fputs_filtered ("static ", stream);
286 » » » » current_language->la_language, 267 » fprintf_symbol_filtered (stream,
287 » » » » DMGL_PARAMS | DMGL_ANSI); 268 » » » » TYPE_FIELD_NAME (type, i),
288 » annotate_field_name_end (); 269 » » » » current_language->la_language,
289 » /* Do not print leading '=' in case of anonymous 270 » » » » DMGL_PARAMS | DMGL_ANSI);
290 » » unions. */ 271 » annotate_field_name_end ();
291 » if (strcmp (TYPE_FIELD_NAME (type, i), "")) 272 » /* Do not print leading '=' in case of anonymous
292 » » fputs_filtered (" = ", stream); 273 » unions. */
293 » annotate_field_value (); 274 » if (strcmp (TYPE_FIELD_NAME (type, i), ""))
294 » } 275 » fputs_filtered (" = ", stream);
276 » annotate_field_value ();
295 277
296 if (!field_is_static (&TYPE_FIELD (type, i)) 278 if (!field_is_static (&TYPE_FIELD (type, i))
297 && TYPE_FIELD_PACKED (type, i)) 279 && TYPE_FIELD_PACKED (type, i))
298 { 280 {
299 struct value *v; 281 struct value *v;
300 282
301 /* Bitfields require special handling, especially due to 283 /* Bitfields require special handling, especially due to
302 byte order problems. */ 284 byte order problems. */
303 if (TYPE_FIELD_IGNORE (type, i)) 285 if (TYPE_FIELD_IGNORE (type, i))
304 { 286 {
305 fputs_filtered ("<optimized out or zero length>", stream); 287 fputs_filtered ("<optimized out or zero length>", stream);
306 } 288 }
307 else if (value_bits_synthetic_pointer (val, 289 else if (value_bits_synthetic_pointer (val,
308 TYPE_FIELD_BITPOS (type, 290 TYPE_FIELD_BITPOS (type,
309 i), 291 i),
310 TYPE_FIELD_BITSIZE (type, 292 TYPE_FIELD_BITSIZE (type,
311 i))) 293 i)))
312 { 294 {
313 fputs_filtered (_("<synthetic pointer>"), stream); 295 fputs_filtered (_("<synthetic pointer>"), stream);
314 } 296 }
315 else if (!value_bits_valid (val, 297 else if (!value_bits_valid (val,
316 TYPE_FIELD_BITPOS (type, i), 298 TYPE_FIELD_BITPOS (type, i),
317 TYPE_FIELD_BITSIZE (type, i))) 299 TYPE_FIELD_BITSIZE (type, i)))
318 { 300 {
319 » » val_print_optimized_out (stream); 301 » » val_print_optimized_out (val, stream);
320 } 302 }
321 else 303 else
322 { 304 {
323 struct value_print_options opts = *options; 305 struct value_print_options opts = *options;
324 306
325 opts.deref_ref = 0; 307 opts.deref_ref = 0;
326 308
327 v = value_field_bitfield (type, i, valaddr, offset, val); 309 v = value_field_bitfield (type, i, valaddr, offset, val);
328 310
329 common_val_print (v, stream, recurse + 1, &opts, 311 common_val_print (v, stream, recurse + 1, &opts,
(...skipping 14 matching lines...) Expand all
344 326
345 TRY_CATCH (ex, RETURN_MASK_ERROR) 327 TRY_CATCH (ex, RETURN_MASK_ERROR)
346 { 328 {
347 v = value_static_field (type, i); 329 v = value_static_field (type, i);
348 } 330 }
349 331
350 if (ex.reason < 0) 332 if (ex.reason < 0)
351 fprintf_filtered (stream, 333 fprintf_filtered (stream,
352 _("<error reading variable: %s>"), 334 _("<error reading variable: %s>"),
353 ex.message); 335 ex.message);
354 » » else if (v == NULL) 336 » » cp_print_static_field (TYPE_FIELD_TYPE (type, i),
355 » » val_print_optimized_out (stream); 337 » » » » » v, stream, recurse + 1,
356 » » else 338 » » » » » options);
357 » » cp_print_static_field (TYPE_FIELD_TYPE (type, i),
358 » » » » » v, stream, recurse + 1,
359 » » » » » options);
360 } 339 }
361 » else if (i == TYPE_VPTR_FIELDNO (type)) 340 » else if (i == vptr_fieldno && type == vptr_basetype)
362 { 341 {
363 int i_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; 342 int i_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
364 struct type *i_type = TYPE_FIELD_TYPE (type, i); 343 struct type *i_type = TYPE_FIELD_TYPE (type, i);
365 344
366 if (valprint_check_validity (stream, i_type, i_offset, val)) 345 if (valprint_check_validity (stream, i_type, i_offset, val))
367 { 346 {
368 CORE_ADDR addr; 347 CORE_ADDR addr;
369 348
370 addr = extract_typed_address (valaddr + i_offset, i_type); 349 addr = extract_typed_address (valaddr + i_offset, i_type);
371 print_function_pointer_address (options, 350 print_function_pointer_address (options,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 - (obstack_final_size 397 - (obstack_final_size
419 - stat_array_obstack_initial_size); 398 - stat_array_obstack_initial_size);
420 399
421 obstack_free (&dont_print_stat_array_obstack, 400 obstack_free (&dont_print_stat_array_obstack,
422 free_to_ptr); 401 free_to_ptr);
423 } 402 }
424 last_set_recurse = -1; 403 last_set_recurse = -1;
425 } 404 }
426 } 405 }
427 406
428 if (options->pretty) 407 if (options->prettyformat)
429 { 408 {
430 fprintf_filtered (stream, "\n"); 409 fprintf_filtered (stream, "\n");
431 print_spaces_filtered (2 * recurse, stream); 410 print_spaces_filtered (2 * recurse, stream);
432 } 411 }
433 } /* if there are data fields */ 412 } /* if there are data fields */
434 413
435 fprintf_filtered (stream, "}"); 414 fprintf_filtered (stream, "}");
436 } 415 }
437 416
438 /* Like cp_print_value_fields, but find the runtime type of the object 417 /* Like cp_print_value_fields, but find the runtime type of the object
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 558 }
580 } 559 }
581 else 560 else
582 { 561 {
583 base_valaddr = valaddr; 562 base_valaddr = valaddr;
584 base_val = val; 563 base_val = val;
585 } 564 }
586 } 565 }
587 566
588 /* Now do the printing. */ 567 /* Now do the printing. */
589 if (options->pretty) 568 if (options->prettyformat)
590 { 569 {
591 fprintf_filtered (stream, "\n"); 570 fprintf_filtered (stream, "\n");
592 print_spaces_filtered (2 * recurse, stream); 571 print_spaces_filtered (2 * recurse, stream);
593 } 572 }
594 fputs_filtered ("<", stream); 573 fputs_filtered ("<", stream);
595 /* Not sure what the best notation is in the case where there is 574 /* Not sure what the best notation is in the case where there is
596 no baseclass name. */ 575 no baseclass name. */
597 fputs_filtered (basename ? basename : "", stream); 576 fputs_filtered (basename ? basename : "", stream);
598 fputs_filtered ("> = ", stream); 577 fputs_filtered ("> = ", stream);
599 578
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 have the same meanings as in c_val_print. */ 630 have the same meanings as in c_val_print. */
652 631
653 static void 632 static void
654 cp_print_static_field (struct type *type, 633 cp_print_static_field (struct type *type,
655 struct value *val, 634 struct value *val,
656 struct ui_file *stream, 635 struct ui_file *stream,
657 int recurse, 636 int recurse,
658 const struct value_print_options *options) 637 const struct value_print_options *options)
659 { 638 {
660 struct value_print_options opts; 639 struct value_print_options opts;
661 640
641 if (value_entirely_optimized_out (val))
642 {
643 val_print_optimized_out (val, stream);
644 return;
645 }
646
662 if (TYPE_CODE (type) == TYPE_CODE_STRUCT) 647 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
663 { 648 {
664 CORE_ADDR *first_dont_print; 649 CORE_ADDR *first_dont_print;
665 CORE_ADDR addr; 650 CORE_ADDR addr;
666 int i; 651 int i;
667 652
668 first_dont_print 653 first_dont_print
669 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack); 654 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
670 i = obstack_object_size (&dont_print_statmem_obstack) 655 i = obstack_object_size (&dont_print_statmem_obstack)
671 / sizeof (CORE_ADDR); 656 / sizeof (CORE_ADDR);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 cp_print_class_member (const gdb_byte *valaddr, struct type *type, 764 cp_print_class_member (const gdb_byte *valaddr, struct type *type,
780 struct ui_file *stream, char *prefix) 765 struct ui_file *stream, char *prefix)
781 { 766 {
782 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); 767 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
783 768
784 /* VAL is a byte offset into the structure type DOMAIN. 769 /* VAL is a byte offset into the structure type DOMAIN.
785 Find the name of the field for that offset and 770 Find the name of the field for that offset and
786 print it. */ 771 print it. */
787 struct type *domain = TYPE_DOMAIN_TYPE (type); 772 struct type *domain = TYPE_DOMAIN_TYPE (type);
788 LONGEST val; 773 LONGEST val;
789 unsigned int fieldno; 774 int fieldno;
790 775
791 val = extract_signed_integer (valaddr, 776 val = extract_signed_integer (valaddr,
792 TYPE_LENGTH (type), 777 TYPE_LENGTH (type),
793 byte_order); 778 byte_order);
794 779
795 /* Pointers to data members are usually byte offsets into an object. 780 /* Pointers to data members are usually byte offsets into an object.
796 Because a data member can have offset zero, and a NULL pointer to 781 Because a data member can have offset zero, and a NULL pointer to
797 member must be distinct from any valid non-NULL pointer to 782 member must be distinct from any valid non-NULL pointer to
798 member, either the value is biased or the NULL value has a 783 member, either the value is biased or the NULL value has a
799 special representation; both are permitted by ISO C++. HP aCC 784 special representation; both are permitted by ISO C++. HP aCC
(...skipping 12 matching lines...) Expand all
812 797
813 if (domain != NULL) 798 if (domain != NULL)
814 { 799 {
815 const char *name; 800 const char *name;
816 801
817 fputs_filtered (prefix, stream); 802 fputs_filtered (prefix, stream);
818 name = type_name_no_tag (domain); 803 name = type_name_no_tag (domain);
819 if (name) 804 if (name)
820 fputs_filtered (name, stream); 805 fputs_filtered (name, stream);
821 else 806 else
822 » c_type_print_base (domain, stream, 0, 0); 807 » c_type_print_base (domain, stream, 0, 0, &type_print_raw_options);
823 fprintf_filtered (stream, "::"); 808 fprintf_filtered (stream, "::");
824 fputs_filtered (TYPE_FIELD_NAME (domain, fieldno), stream); 809 fputs_filtered (TYPE_FIELD_NAME (domain, fieldno), stream);
825 } 810 }
826 else 811 else
827 fprintf_filtered (stream, "%ld", (long) val); 812 fprintf_filtered (stream, "%ld", (long) val);
828 } 813 }
829 814
830 815
831 void 816 void
832 _initialize_cp_valprint (void) 817 _initialize_cp_valprint (void)
(...skipping 22 matching lines...) Expand all
855 show_objectprint, 840 show_objectprint,
856 &setprintlist, &showprintlist); 841 &setprintlist, &showprintlist);
857 842
858 obstack_begin (&dont_print_stat_array_obstack, 843 obstack_begin (&dont_print_stat_array_obstack,
859 32 * sizeof (struct type *)); 844 32 * sizeof (struct type *));
860 obstack_begin (&dont_print_statmem_obstack, 845 obstack_begin (&dont_print_statmem_obstack,
861 32 * sizeof (CORE_ADDR)); 846 32 * sizeof (CORE_ADDR));
862 obstack_begin (&dont_print_vb_obstack, 847 obstack_begin (&dont_print_vb_obstack,
863 32 * sizeof (struct type *)); 848 32 * sizeof (struct type *));
864 } 849 }
OLDNEW
« no previous file with comments | « gdb/cp-support.c ('k') | gdb/cris-linux-tdep.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698