GDB (xrefs)

/tmp/gdb-8.1/gdb/d-valprint.c
Go to the documentation of this file.
1 /* Support for printing D values for GDB, the GNU debugger.
2
3 Copyright (C) 2008-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "gdbtypes.h"
22 #include "gdbcore.h"
23 #include "d-lang.h"
24 #include "c-lang.h"
25
26 /* Assuming that TYPE is a TYPE_CODE_STRUCT, verify that TYPE is a
27 dynamic array, and then print its value to STREAM. Return zero if
28 TYPE is a dynamic array, non-zero otherwise. */
29
30 static int
31 dynamic_array_type (struct type *type,
32 LONGEST embedded_offset, CORE_ADDR address,
33 struct ui_file *stream, int recurse,
34 struct value *val,
35 const struct value_print_options *options)
36 {
37 if (TYPE_NFIELDS (type) == 2
38 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
39 && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
40 && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
41 && !value_bits_any_optimized_out (val,
42 TARGET_CHAR_BIT * embedded_offset,
43 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
44 {
45 CORE_ADDR addr;
46 struct type *elttype;
47 struct type *true_type;
48 struct type *ptr_type;
49 struct value *ival;
50 int length;
51 const gdb_byte *valaddr = value_contents_for_printing (val);
52
53 length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
54
55 ptr_type = TYPE_FIELD_TYPE (type, 1);
56 elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
57 addr = unpack_pointer (ptr_type,
58 valaddr + TYPE_FIELD_BITPOS (type, 1) / 8
59 + embedded_offset);
60 true_type = check_typedef (elttype);
61
62 true_type = lookup_array_range_type (true_type, 0, length - 1);
63 ival = value_at (true_type, addr);
64 true_type = value_type (ival);
65
66 d_val_print (true_type,
67 value_embedded_offset (ival), addr,
68 stream, recurse + 1, ival, options);
69 return 0;
70 }
71 return 1;
72 }
73
74 /* Implements the la_val_print routine for language D. */
75 void
76 d_val_print (struct type *type, int embedded_offset,
77 CORE_ADDR address, struct ui_file *stream, int recurse,
78 struct value *val,
79 const struct value_print_options *options)
80 {
81 int ret;
82
83 type = check_typedef (type);
84 switch (TYPE_CODE (type))
85 {
86 case TYPE_CODE_STRUCT:
87 ret = dynamic_array_type (type, embedded_offset, address,
88 stream, recurse, val, options);
89 if (ret == 0)
90 break;
91 default:
92 c_val_print (type, embedded_offset, address, stream,
93 recurse, val, options);
94 }
95 }
lookup_array_range_type
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
Definition: gdbtypes.c:1232
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
TYPE_FIELD_NAME
#define TYPE_FIELD_NAME(thistype, n)
Definition: gdbtypes.h:1372
value::embedded_offset
LONGEST embedded_offset
Definition: value.c:309
unpack_pointer
CORE_ADDR unpack_pointer(struct type *type, const gdb_byte *valaddr)
Definition: value.c:2934
value_embedded_offset
LONGEST value_embedded_offset(const struct value *value)
Definition: value.c:1477
value_at
struct value * value_at(struct type *type, CORE_ADDR addr)
Definition: valops.c:933
TYPE_CODE_INT
Definition: gdbtypes.h:111
value_contents_for_printing
const gdb_byte * value_contents_for_printing(struct value *value)
Definition: value.c:1250
ui_file
Definition: ui-file.h:26
defs.h
value_bits_any_optimized_out
int value_bits_any_optimized_out(const struct value *value, int bit_offset, int bit_length)
Definition: value.c:366
TYPE_FIELD_TYPE
#define TYPE_FIELD_TYPE(thistype, n)
Definition: gdbtypes.h:1371
check_typedef
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:2421
value_print_options
Definition: valprint.h:25
unpack_field_as_long
LONGEST unpack_field_as_long(struct type *type, const gdb_byte *valaddr, int fieldno)
Definition: value.c:3318
TARGET_CHAR_BIT
#define TARGET_CHAR_BIT
Definition: host-defs.h:29
d_val_print
void d_val_print(struct type *type, int embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, struct value *val, const struct value_print_options *options)
Definition: d-valprint.c:76
type
Definition: gdbtypes.h:749
c_val_print
void c_val_print(struct type *, int, CORE_ADDR, struct ui_file *, int, struct value *, const struct value_print_options *)
Definition: c-valprint.c:500
TYPE_CODE_STRUCT
Definition: gdbtypes.h:106
TYPE_FIELD_BITPOS
#define TYPE_FIELD_BITPOS(thistype, n)
Definition: gdbtypes.h:1374
value
Definition: value.c:169
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
TYPE_TARGET_TYPE
#define TYPE_TARGET_TYPE(thistype)
Definition: gdbtypes.h:1226
gdbcore.h
TYPE_CODE
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1238
d-lang.h
c-lang.h
TYPE_NFIELDS
#define TYPE_NFIELDS(thistype)
Definition: gdbtypes.h:1239
gdbtypes.h
dynamic_array_type
static int dynamic_array_type(struct type *type, LONGEST embedded_offset, CORE_ADDR address, struct ui_file *stream, int recurse, struct value *val, const struct value_print_options *options)
Definition: d-valprint.c:31
value_type
struct type * value_type(const struct value *value)
Definition: value.c:1095
TYPE_LENGTH
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1235
value::address
CORE_ADDR address
Definition: value.c:208
LONGEST
long long LONGEST
Definition: common-types.h:52