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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [gdb/] [c-valprint.c] - Blame information for rev 851

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

Line No. Rev Author Line
1 330 jeremybenn
/* Support for printing C values for GDB, the GNU debugger.
2
 
3
   Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4
   1998, 1999, 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010
5
   Free Software Foundation, Inc.
6
 
7
   This file is part of GDB.
8
 
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3 of the License, or
12
   (at your option) any later version.
13
 
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
 
22
#include "defs.h"
23
#include "gdb_string.h"
24
#include "symtab.h"
25
#include "gdbtypes.h"
26
#include "expression.h"
27
#include "value.h"
28
#include "valprint.h"
29
#include "language.h"
30
#include "c-lang.h"
31
#include "cp-abi.h"
32
#include "target.h"
33
 
34
 
35
/* Print function pointer with inferior address ADDRESS onto stdio
36
   stream STREAM.  */
37
 
38
static void
39
print_function_pointer_address (struct gdbarch *gdbarch, CORE_ADDR address,
40
                                struct ui_file *stream, int addressprint)
41
{
42
  CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
43
                                                            &current_target);
44
 
45
  /* If the function pointer is represented by a description, print the
46
     address of the description.  */
47
  if (addressprint && func_addr != address)
48
    {
49
      fputs_filtered ("@", stream);
50
      fputs_filtered (paddress (gdbarch, address), stream);
51
      fputs_filtered (": ", stream);
52
    }
53
  print_address_demangle (gdbarch, func_addr, stream, demangle);
54
}
55
 
56
 
57
/* A helper for c_textual_element_type.  This checks the name of the
58
   typedef.  This is bogus but it isn't apparent that the compiler
59
   provides us the help we may need.  */
60
 
61
static int
62
textual_name (const char *name)
63
{
64
  return (!strcmp (name, "wchar_t")
65
          || !strcmp (name, "char16_t")
66
          || !strcmp (name, "char32_t"));
67
}
68
 
69
/* Apply a heuristic to decide whether an array of TYPE or a pointer
70
   to TYPE should be printed as a textual string.  Return non-zero if
71
   it should, or zero if it should be treated as an array of integers
72
   or pointer to integers.  FORMAT is the current format letter,
73
   or 0 if none.
74
 
75
   We guess that "char" is a character.  Explicitly signed and
76
   unsigned character types are also characters.  Integer data from
77
   vector types is not.  The user can override this by using the /s
78
   format letter.  */
79
 
80
int
81
c_textual_element_type (struct type *type, char format)
82
{
83
  struct type *true_type, *iter_type;
84
 
85
  if (format != 0 && format != 's')
86
    return 0;
87
 
88
  /* We also rely on this for its side effect of setting up all the
89
     typedef pointers.  */
90
  true_type = check_typedef (type);
91
 
92
  /* TYPE_CODE_CHAR is always textual.  */
93
  if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
94
    return 1;
95
 
96
  /* Any other character-like types must be integral.  */
97
  if (TYPE_CODE (true_type) != TYPE_CODE_INT)
98
    return 0;
99
 
100
  /* We peel typedefs one by one, looking for a match.  */
101
  iter_type = type;
102
  while (iter_type)
103
    {
104
      /* Check the name of the type.  */
105
      if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
106
        return 1;
107
 
108
      if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
109
        break;
110
 
111
      /* Peel a single typedef.  If the typedef doesn't have a target
112
         type, we use check_typedef and hope the result is ok -- it
113
         might be for C++, where wchar_t is a built-in type.  */
114
      if (TYPE_TARGET_TYPE (iter_type))
115
        iter_type = TYPE_TARGET_TYPE (iter_type);
116
      else
117
        iter_type = check_typedef (iter_type);
118
    }
119
 
120
  if (format == 's')
121
    {
122
      /* Print this as a string if we can manage it.  For now, no
123
         wide character support.  */
124
      if (TYPE_CODE (true_type) == TYPE_CODE_INT
125
          && TYPE_LENGTH (true_type) == 1)
126
        return 1;
127
    }
128
  else
129
    {
130
      /* If a one-byte TYPE_CODE_INT is missing the not-a-character
131
         flag, then we treat it as text; otherwise, we assume it's
132
         being used as data.  */
133
      if (TYPE_CODE (true_type) == TYPE_CODE_INT
134
          && TYPE_LENGTH (true_type) == 1
135
          && !TYPE_NOTTEXT (true_type))
136
        return 1;
137
    }
138
 
139
  return 0;
140
}
141
 
142
 
143
/* Print data of type TYPE located at VALADDR (within GDB), which came from
144
   the inferior at address ADDRESS, onto stdio stream STREAM according to
145
   OPTIONS.  The data at VALADDR is in target byte order.
146
 
147
   If the data are a string pointer, returns the number of string characters
148
   printed.  */
149
 
150
int
151
c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
152
             CORE_ADDR address, struct ui_file *stream, int recurse,
153
             const struct value *original_value,
154
             const struct value_print_options *options)
155
{
156
  struct gdbarch *gdbarch = get_type_arch (type);
157
  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
158
  unsigned int i = 0;    /* Number of characters printed */
159
  unsigned len;
160
  struct type *elttype, *unresolved_elttype;
161
  struct type *unresolved_type = type;
162
  unsigned eltlen;
163
  LONGEST val;
164
  CORE_ADDR addr;
165
 
166
  CHECK_TYPEDEF (type);
167
  switch (TYPE_CODE (type))
168
    {
169
    case TYPE_CODE_ARRAY:
170
      unresolved_elttype = TYPE_TARGET_TYPE (type);
171
      elttype = check_typedef (unresolved_elttype);
172
      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
173
        {
174
          eltlen = TYPE_LENGTH (elttype);
175
          len = TYPE_LENGTH (type) / eltlen;
176
          if (options->prettyprint_arrays)
177
            {
178
              print_spaces_filtered (2 + 2 * recurse, stream);
179
            }
180
 
181
          /* Print arrays of textual chars with a string syntax, as
182
             long as the entire array is valid.  */
183
          if (!TYPE_VECTOR (type)
184
              && c_textual_element_type (unresolved_elttype, options->format)
185
              && value_bits_valid (original_value,
186
                                   TARGET_CHAR_BIT * embedded_offset,
187
                                   TARGET_CHAR_BIT * TYPE_LENGTH (type)))
188
            {
189
              /* If requested, look for the first null char and only print
190
                 elements up to it.  */
191
              if (options->stop_print_at_null)
192
                {
193
                  unsigned int temp_len;
194
 
195
                  for (temp_len = 0;
196
                       (temp_len < len
197
                        && temp_len < options->print_max
198
                        && extract_unsigned_integer (valaddr + embedded_offset
199
                                                     + temp_len * eltlen,
200
                                                     eltlen, byte_order) != 0);
201
                       ++temp_len)
202
                    ;
203
                  len = temp_len;
204
                }
205
 
206
              LA_PRINT_STRING (stream, unresolved_elttype,
207
                               valaddr + embedded_offset, len,
208
                               NULL, 0, options);
209
              i = len;
210
            }
211
          else
212
            {
213
              fprintf_filtered (stream, "{");
214
              /* If this is a virtual function table, print the 0th
215
                 entry specially, and the rest of the members normally.  */
216
              if (cp_is_vtbl_ptr_type (elttype))
217
                {
218
                  i = 1;
219
                  fprintf_filtered (stream, _("%d vtable entries"), len - 1);
220
                }
221
              else
222
                {
223
                  i = 0;
224
                }
225
              val_print_array_elements (type, valaddr + embedded_offset,
226
                                        address + embedded_offset, stream,
227
                                        recurse, original_value, options, i);
228
              fprintf_filtered (stream, "}");
229
            }
230
          break;
231
        }
232
      /* Array of unspecified length: treat like pointer to first elt.  */
233
      addr = address;
234
      goto print_unpacked_pointer;
235
 
236
    case TYPE_CODE_MEMBERPTR:
237
      if (options->format)
238
        {
239
          print_scalar_formatted (valaddr + embedded_offset, type,
240
                                  options, 0, stream);
241
          break;
242
        }
243
      cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
244
      break;
245
 
246
    case TYPE_CODE_METHODPTR:
247
      cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
248
      break;
249
 
250
    case TYPE_CODE_PTR:
251
      if (options->format && options->format != 's')
252
        {
253
          print_scalar_formatted (valaddr + embedded_offset, type,
254
                                  options, 0, stream);
255
          break;
256
        }
257
      if (options->vtblprint && cp_is_vtbl_ptr_type (type))
258
        {
259
          /* Print the unmangled name if desired.  */
260
          /* Print vtable entry - we only get here if we ARE using
261
             -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
262
          CORE_ADDR addr
263
            = extract_typed_address (valaddr + embedded_offset, type);
264
 
265
          print_function_pointer_address (gdbarch, addr, stream,
266
                                          options->addressprint);
267
          break;
268
        }
269
      unresolved_elttype = TYPE_TARGET_TYPE (type);
270
      elttype = check_typedef (unresolved_elttype);
271
        {
272
          addr = unpack_pointer (type, valaddr + embedded_offset);
273
        print_unpacked_pointer:
274
 
275
          if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
276
            {
277
              /* Try to print what function it points to.  */
278
              print_function_pointer_address (gdbarch, addr, stream,
279
                                              options->addressprint);
280
              /* Return value is irrelevant except for string pointers.  */
281
              return (0);
282
            }
283
 
284
          if (options->addressprint)
285
            fputs_filtered (paddress (gdbarch, addr), stream);
286
 
287
          /* For a pointer to a textual type, also print the string
288
             pointed to, unless pointer is null.  */
289
 
290
          if (c_textual_element_type (unresolved_elttype, options->format)
291
              && addr != 0)
292
            {
293
              i = val_print_string (unresolved_elttype, addr, -1, stream,
294
                                    options);
295
            }
296
          else if (cp_is_vtbl_member (type))
297
            {
298
              /* print vtbl's nicely */
299
              CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
300
 
301
              struct minimal_symbol *msymbol =
302
              lookup_minimal_symbol_by_pc (vt_address);
303
              if ((msymbol != NULL)
304
                  && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
305
                {
306
                  fputs_filtered (" <", stream);
307
                  fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
308
                  fputs_filtered (">", stream);
309
                }
310
              if (vt_address && options->vtblprint)
311
                {
312
                  struct value *vt_val;
313
                  struct symbol *wsym = (struct symbol *) NULL;
314
                  struct type *wtype;
315
                  struct block *block = (struct block *) NULL;
316
                  int is_this_fld;
317
 
318
                  if (msymbol != NULL)
319
                    wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
320
                                          VAR_DOMAIN, &is_this_fld);
321
 
322
                  if (wsym)
323
                    {
324
                      wtype = SYMBOL_TYPE (wsym);
325
                    }
326
                  else
327
                    {
328
                      wtype = unresolved_elttype;
329
                    }
330
                  vt_val = value_at (wtype, vt_address);
331
                  common_val_print (vt_val, stream, recurse + 1, options,
332
                                    current_language);
333
                  if (options->pretty)
334
                    {
335
                      fprintf_filtered (stream, "\n");
336
                      print_spaces_filtered (2 + 2 * recurse, stream);
337
                    }
338
                }
339
            }
340
 
341
          /* Return number of characters printed, including the terminating
342
             '\0' if we reached the end.  val_print_string takes care including
343
             the terminating '\0' if necessary.  */
344
          return i;
345
        }
346
      break;
347
 
348
    case TYPE_CODE_REF:
349
      elttype = check_typedef (TYPE_TARGET_TYPE (type));
350
      if (options->addressprint)
351
        {
352
          CORE_ADDR addr
353
            = extract_typed_address (valaddr + embedded_offset, type);
354
 
355
          fprintf_filtered (stream, "@");
356
          fputs_filtered (paddress (gdbarch, addr), stream);
357
          if (options->deref_ref)
358
            fputs_filtered (": ", stream);
359
        }
360
      /* De-reference the reference.  */
361
      if (options->deref_ref)
362
        {
363
          if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
364
            {
365
              struct value *deref_val =
366
                value_at
367
                (TYPE_TARGET_TYPE (type),
368
                 unpack_pointer (type, valaddr + embedded_offset));
369
 
370
              common_val_print (deref_val, stream, recurse, options,
371
                                current_language);
372
            }
373
          else
374
            fputs_filtered ("???", stream);
375
        }
376
      break;
377
 
378
    case TYPE_CODE_UNION:
379
      if (recurse && !options->unionprint)
380
        {
381
          fprintf_filtered (stream, "{...}");
382
          break;
383
        }
384
      /* Fall through.  */
385
    case TYPE_CODE_STRUCT:
386
      /*FIXME: Abstract this away */
387
      if (options->vtblprint && cp_is_vtbl_ptr_type (type))
388
        {
389
          /* Print the unmangled name if desired.  */
390
          /* Print vtable entry - we only get here if NOT using
391
             -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.) */
392
          int offset = (embedded_offset +
393
                        TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8);
394
          struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
395
          CORE_ADDR addr
396
            = extract_typed_address (valaddr + offset, field_type);
397
 
398
          print_function_pointer_address (gdbarch, addr, stream,
399
                                          options->addressprint);
400
        }
401
      else
402
        cp_print_value_fields_rtti (type, valaddr,
403
                                    embedded_offset, address, stream,
404
                                    recurse, original_value, options, NULL, 0);
405
      break;
406
 
407
    case TYPE_CODE_ENUM:
408
      if (options->format)
409
        {
410
          print_scalar_formatted (valaddr + embedded_offset, type,
411
                                  options, 0, stream);
412
          break;
413
        }
414
      len = TYPE_NFIELDS (type);
415
      val = unpack_long (type, valaddr + embedded_offset);
416
      for (i = 0; i < len; i++)
417
        {
418
          QUIT;
419
          if (val == TYPE_FIELD_BITPOS (type, i))
420
            {
421
              break;
422
            }
423
        }
424
      if (i < len)
425
        {
426
          fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
427
        }
428
      else
429
        {
430
          print_longest (stream, 'd', 0, val);
431
        }
432
      break;
433
 
434
    case TYPE_CODE_FLAGS:
435
      if (options->format)
436
          print_scalar_formatted (valaddr + embedded_offset, type,
437
                                  options, 0, stream);
438
      else
439
        val_print_type_code_flags (type, valaddr + embedded_offset, stream);
440
      break;
441
 
442
    case TYPE_CODE_FUNC:
443
    case TYPE_CODE_METHOD:
444
      if (options->format)
445
        {
446
          print_scalar_formatted (valaddr + embedded_offset, type,
447
                                  options, 0, stream);
448
          break;
449
        }
450
      /* FIXME, we should consider, at least for ANSI C language, eliminating
451
         the distinction made between FUNCs and POINTERs to FUNCs.  */
452
      fprintf_filtered (stream, "{");
453
      type_print (type, "", stream, -1);
454
      fprintf_filtered (stream, "} ");
455
      /* Try to print what function it points to, and its address.  */
456
      print_address_demangle (gdbarch, address, stream, demangle);
457
      break;
458
 
459
    case TYPE_CODE_BOOL:
460
      if (options->format || options->output_format)
461
        {
462
          struct value_print_options opts = *options;
463
          opts.format = (options->format ? options->format
464
                         : options->output_format);
465
          print_scalar_formatted (valaddr + embedded_offset, type,
466
                                  &opts, 0, stream);
467
        }
468
      else
469
        {
470
          val = unpack_long (type, valaddr + embedded_offset);
471
          if (val == 0)
472
            fputs_filtered ("false", stream);
473
          else if (val == 1)
474
            fputs_filtered ("true", stream);
475
          else
476
            print_longest (stream, 'd', 0, val);
477
        }
478
      break;
479
 
480
    case TYPE_CODE_RANGE:
481
      /* FIXME: create_range_type does not set the unsigned bit in a
482
         range type (I think it probably should copy it from the target
483
         type), so we won't print values which are too large to
484
         fit in a signed integer correctly.  */
485
      /* FIXME: Doesn't handle ranges of enums correctly.  (Can't just
486
         print with the target type, though, because the size of our type
487
         and the target type might differ).  */
488
      /* FALLTHROUGH */
489
 
490
    case TYPE_CODE_INT:
491
      if (options->format || options->output_format)
492
        {
493
          struct value_print_options opts = *options;
494
 
495
          opts.format = (options->format ? options->format
496
                         : options->output_format);
497
          print_scalar_formatted (valaddr + embedded_offset, type,
498
                                  &opts, 0, stream);
499
        }
500
      else
501
        {
502
          val_print_type_code_int (type, valaddr + embedded_offset, stream);
503
          /* C and C++ has no single byte int type, char is used instead.
504
             Since we don't know whether the value is really intended to
505
             be used as an integer or a character, print the character
506
             equivalent as well.  */
507
          if (c_textual_element_type (unresolved_type, options->format))
508
            {
509
              fputs_filtered (" ", stream);
510
              LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
511
                             unresolved_type, stream);
512
            }
513
        }
514
      break;
515
 
516
    case TYPE_CODE_CHAR:
517
      if (options->format || options->output_format)
518
        {
519
          struct value_print_options opts = *options;
520
          opts.format = (options->format ? options->format
521
                         : options->output_format);
522
          print_scalar_formatted (valaddr + embedded_offset, type,
523
                                  &opts, 0, stream);
524
        }
525
      else
526
        {
527
          val = unpack_long (type, valaddr + embedded_offset);
528
          if (TYPE_UNSIGNED (type))
529
            fprintf_filtered (stream, "%u", (unsigned int) val);
530
          else
531
            fprintf_filtered (stream, "%d", (int) val);
532
          fputs_filtered (" ", stream);
533
          LA_PRINT_CHAR ((unsigned char) val, unresolved_type, stream);
534
        }
535
      break;
536
 
537
    case TYPE_CODE_FLT:
538
      if (options->format)
539
        {
540
          print_scalar_formatted (valaddr + embedded_offset, type,
541
                                  options, 0, stream);
542
        }
543
      else
544
        {
545
          print_floating (valaddr + embedded_offset, type, stream);
546
        }
547
      break;
548
 
549
    case TYPE_CODE_DECFLOAT:
550
      if (options->format)
551
        print_scalar_formatted (valaddr + embedded_offset, type,
552
                                options, 0, stream);
553
      else
554
        print_decimal_floating (valaddr + embedded_offset, type, stream);
555
      break;
556
 
557
    case TYPE_CODE_VOID:
558
      fprintf_filtered (stream, "void");
559
      break;
560
 
561
    case TYPE_CODE_ERROR:
562
      fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
563
      break;
564
 
565
    case TYPE_CODE_UNDEF:
566
      /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
567
         dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
568
         and no complete type for struct foo in that file.  */
569
      fprintf_filtered (stream, _("<incomplete type>"));
570
      break;
571
 
572
    case TYPE_CODE_COMPLEX:
573
      if (options->format)
574
        print_scalar_formatted (valaddr + embedded_offset,
575
                                TYPE_TARGET_TYPE (type),
576
                                options, 0, stream);
577
      else
578
        print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
579
                        stream);
580
      fprintf_filtered (stream, " + ");
581
      if (options->format)
582
        print_scalar_formatted (valaddr + embedded_offset
583
                                + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
584
                                TYPE_TARGET_TYPE (type),
585
                                options, 0, stream);
586
      else
587
        print_floating (valaddr + embedded_offset
588
                        + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
589
                        TYPE_TARGET_TYPE (type),
590
                        stream);
591
      fprintf_filtered (stream, " * I");
592
      break;
593
 
594
    default:
595
      error (_("Invalid C/C++ type code %d in symbol table."), TYPE_CODE (type));
596
    }
597
  gdb_flush (stream);
598
  return (0);
599
}
600
 
601
int
602
c_value_print (struct value *val, struct ui_file *stream,
603
               const struct value_print_options *options)
604
{
605
  struct type *type, *real_type, *val_type;
606
  int full, top, using_enc;
607
  struct value_print_options opts = *options;
608
 
609
  opts.deref_ref = 1;
610
 
611
  /* If it is a pointer, indicate what it points to.
612
 
613
     Print type also if it is a reference.
614
 
615
     C++: if it is a member pointer, we will take care
616
     of that when we print it.  */
617
 
618
  /* Preserve the original type before stripping typedefs.  We prefer
619
     to pass down the original type when possible, but for local
620
     checks it is better to look past the typedefs.  */
621
  val_type = value_type (val);
622
  type = check_typedef (val_type);
623
 
624
  if (TYPE_CODE (type) == TYPE_CODE_PTR
625
      || TYPE_CODE (type) == TYPE_CODE_REF)
626
    {
627
      /* Hack:  remove (char *) for char strings.  Their
628
         type is indicated by the quoted string anyway.
629
         (Don't use c_textual_element_type here; quoted strings
630
         are always exactly (char *), (wchar_t *), or the like.  */
631
      if (TYPE_CODE (val_type) == TYPE_CODE_PTR
632
          && TYPE_NAME (val_type) == NULL
633
          && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
634
          && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)), "char") == 0
635
              || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
636
        {
637
          /* Print nothing */
638
        }
639
      else if (options->objectprint
640
               && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
641
        {
642
 
643
          if (TYPE_CODE(type) == TYPE_CODE_REF)
644
            {
645
              /* Copy value, change to pointer, so we don't get an
646
               * error about a non-pointer type in value_rtti_target_type
647
               */
648
              struct value *temparg;
649
              temparg=value_copy(val);
650
              deprecated_set_value_type (temparg, lookup_pointer_type (TYPE_TARGET_TYPE(type)));
651
              val=temparg;
652
            }
653
          /* Pointer to class, check real type of object */
654
          fprintf_filtered (stream, "(");
655
          real_type = value_rtti_target_type (val, &full, &top, &using_enc);
656
          if (real_type)
657
            {
658
              /* RTTI entry found */
659
              if (TYPE_CODE (type) == TYPE_CODE_PTR)
660
                {
661
                  /* create a pointer type pointing to the real type */
662
                  type = lookup_pointer_type (real_type);
663
                }
664
              else
665
                {
666
                  /* create a reference type referencing the real type */
667
                  type = lookup_reference_type (real_type);
668
                }
669
              /* JYG: Need to adjust pointer value. */
670
              /* NOTE: cagney/2005-01-02: THIS IS BOGUS.  */
671
              value_contents_writeable (val)[0] -= top;
672
 
673
              /* Note: When we look up RTTI entries, we don't get any
674
                 information on const or volatile attributes */
675
            }
676
          type_print (type, "", stream, -1);
677
          fprintf_filtered (stream, ") ");
678
          val_type = type;
679
        }
680
      else
681
        {
682
          /* normal case */
683
          fprintf_filtered (stream, "(");
684
          type_print (value_type (val), "", stream, -1);
685
          fprintf_filtered (stream, ") ");
686
        }
687
    }
688
 
689
  if (!value_initialized (val))
690
    fprintf_filtered (stream, " [uninitialized] ");
691
 
692
  if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
693
    {
694
      /* Attempt to determine real type of object */
695
      real_type = value_rtti_type (val, &full, &top, &using_enc);
696
      if (real_type)
697
        {
698
          /* We have RTTI information, so use it */
699
          val = value_full_object (val, real_type, full, top, using_enc);
700
          fprintf_filtered (stream, "(%s%s) ",
701
                            TYPE_NAME (real_type),
702
                            full ? "" : _(" [incomplete object]"));
703
          /* Print out object: enclosing type is same as real_type if full */
704
          return val_print (value_enclosing_type (val),
705
                            value_contents_for_printing (val), 0,
706
                            value_address (val), stream, 0,
707
                            val, &opts, current_language);
708
          /* Note: When we look up RTTI entries, we don't get any information on
709
             const or volatile attributes */
710
        }
711
      else if (type != check_typedef (value_enclosing_type (val)))
712
        {
713
          /* No RTTI information, so let's do our best */
714
          fprintf_filtered (stream, "(%s ?) ",
715
                            TYPE_NAME (value_enclosing_type (val)));
716
          return val_print (value_enclosing_type (val),
717
                            value_contents_for_printing (val), 0,
718
                            value_address (val), stream, 0,
719
                            val, &opts, current_language);
720
        }
721
      /* Otherwise, we end up at the return outside this "if" */
722
    }
723
 
724
  return val_print (val_type, value_contents_for_printing (val),
725
                    value_embedded_offset (val),
726
                    value_address (val),
727
                    stream, 0,
728
                    val, &opts, current_language);
729
}

powered by: WebSVN 2.1.0

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