Reindented to GNU standard. No semantic changes. This checkin is to
[deliverable/binutils-gdb.git] / gdb / ch-valprint.c
1 /* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "defs.h"
21 #include "obstack.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "valprint.h"
25 #include "expression.h"
26 #include "language.h"
27
28 \f
29 /* Print data of type TYPE located at VALADDR (within GDB), which came from
30 the inferior at address ADDRESS, onto stdio stream STREAM according to
31 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
32 target byte order.
33
34 If the data are a string pointer, returns the number of string characters
35 printed.
36
37 If DEREF_REF is nonzero, then dereference references, otherwise just print
38 them like pointers.
39
40 The PRETTY parameter controls prettyprinting. */
41
42 int
43 chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
44 pretty)
45 struct type *type;
46 char *valaddr;
47 CORE_ADDR address;
48 FILE *stream;
49 int format;
50 int deref_ref;
51 int recurse;
52 enum val_prettyprint pretty;
53 {
54 LONGEST val;
55 unsigned int i = 0; /* Number of characters printed. */
56 struct type *elttype;
57 unsigned eltlen;
58 CORE_ADDR addr;
59
60 switch (TYPE_CODE (type))
61 {
62 case TYPE_CODE_ARRAY:
63 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
64 {
65 if (prettyprint_arrays)
66 {
67 print_spaces_filtered (2 + 2 * recurse, stream);
68 }
69 fprintf_filtered (stream, "[");
70 val_print_array_elements (type, valaddr, address, stream, format,
71 deref_ref, recurse, pretty, 0);
72 fprintf_filtered (stream, "]");
73 }
74 else
75 {
76 error ("unimplemented in chill_val_print; unspecified array length");
77 }
78 break;
79
80 case TYPE_CODE_INT:
81 format = format ? format : output_format;
82 if (format)
83 {
84 print_scalar_formatted (valaddr, type, format, 0, stream);
85 }
86 else
87 {
88 val_print_type_code_int (type, valaddr, stream);
89 }
90 break;
91
92 case TYPE_CODE_CHAR:
93 format = format ? format : output_format;
94 if (format)
95 {
96 print_scalar_formatted (valaddr, type, format, 0, stream);
97 }
98 else
99 {
100 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
101 stream);
102 }
103 break;
104
105 case TYPE_CODE_FLT:
106 if (format)
107 {
108 print_scalar_formatted (valaddr, type, format, 0, stream);
109 }
110 else
111 {
112 print_floating (valaddr, type, stream);
113 }
114 break;
115
116 case TYPE_CODE_BOOL:
117 format = format ? format : output_format;
118 if (format)
119 {
120 print_scalar_formatted (valaddr, type, format, 0, stream);
121 }
122 else
123 {
124 val = unpack_long (builtin_type_chill_bool, valaddr);
125 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
126 }
127 break;
128
129 case TYPE_CODE_UNDEF:
130 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
131 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
132 and no complete type for struct foo in that file. */
133 fprintf_filtered (stream, "<incomplete type>");
134 break;
135
136 case TYPE_CODE_PTR:
137 if (format && format != 's')
138 {
139 print_scalar_formatted (valaddr, type, format, 0, stream);
140 break;
141 }
142 addr = unpack_pointer (type, valaddr);
143 elttype = TYPE_TARGET_TYPE (type);
144
145 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
146 {
147 /* Try to print what function it points to. */
148 print_address_demangle (addr, stream, demangle);
149 /* Return value is irrelevant except for string pointers. */
150 return (0);
151 }
152 if (addressprint && format != 's')
153 {
154 fprintf_filtered (stream, "0x%x", addr);
155 }
156
157 /* For a pointer to char or unsigned char, also print the string
158 pointed to, unless pointer is null. */
159 if (TYPE_LENGTH (elttype) == 1
160 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
161 && (format == 0 || format == 's')
162 && addr != 0
163 && /* If print_max is UINT_MAX, the alloca below will fail.
164 In that case don't try to print the string. */
165 print_max < UINT_MAX)
166 {
167 i = val_print_string (addr, stream);
168 }
169 /* Return number of characters printed, plus one for the
170 terminating null if we have "reached the end". */
171 return (i + (print_max && i != print_max));
172 break;
173
174 case TYPE_CODE_STRING:
175 if (format && format != 's')
176 {
177 print_scalar_formatted (valaddr, type, format, 0, stream);
178 break;
179 }
180 if (addressprint && format != 's')
181 {
182 fprintf_filtered (stream, "0x%x ", addr);
183 }
184 i = TYPE_LENGTH (type);
185 LA_PRINT_STRING (stream, valaddr, i, 0);
186 /* Return number of characters printed, plus one for the terminating
187 null if we have "reached the end". */
188 return (i + (print_max && i != print_max));
189 break;
190
191 case TYPE_CODE_MEMBER:
192 case TYPE_CODE_REF:
193 case TYPE_CODE_UNION:
194 case TYPE_CODE_STRUCT:
195 case TYPE_CODE_ENUM:
196 case TYPE_CODE_FUNC:
197 case TYPE_CODE_VOID:
198 case TYPE_CODE_ERROR:
199 case TYPE_CODE_RANGE:
200 error ("Unimplemented chill_val_print support for type %d",
201 TYPE_CODE (type));
202 break;
203
204 default:
205 error ("Invalid Chill type code %d in symbol table.", TYPE_CODE (type));
206 }
207 fflush (stream);
208 return (0);
209 }
This page took 0.034129 seconds and 4 git commands to generate.