]> Git Repo - binutils.git/blob - gdb/ch-valprint.c
Thu Apr 22 14:50:05 1993 Jim Kingdon ([email protected])
[binutils.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 "value.h"
27 #include "language.h"
28 #include "demangle.h"
29
30 static void
31 chill_print_value_fields PARAMS ((struct type *, char *, FILE *, int, int,
32                                   enum val_prettyprint, struct type **));
33
34 \f
35 /* Print data of type TYPE located at VALADDR (within GDB), which came from
36    the inferior at address ADDRESS, onto stdio stream STREAM according to
37    FORMAT (a letter or 0 for natural format).  The data at VALADDR is in
38    target byte order.
39
40    If the data are a string pointer, returns the number of string characters
41    printed.
42
43    If DEREF_REF is nonzero, then dereference references, otherwise just print
44    them like pointers.
45
46    The PRETTY parameter controls prettyprinting.  */
47
48 int
49 chill_val_print (type, valaddr, address, stream, format, deref_ref, recurse,
50                  pretty)
51      struct type *type;
52      char *valaddr;
53      CORE_ADDR address;
54      FILE *stream;
55      int format;
56      int deref_ref;
57      int recurse;
58      enum val_prettyprint pretty;
59 {
60   LONGEST val;
61   unsigned int i = 0;           /* Number of characters printed.  */
62   struct type *elttype;
63   unsigned eltlen;
64   CORE_ADDR addr;
65
66   switch (TYPE_CODE (type))
67     {
68     case TYPE_CODE_ARRAY:
69       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
70         {
71           if (prettyprint_arrays)
72             {
73               print_spaces_filtered (2 + 2 * recurse, stream);
74             }
75           fprintf_filtered (stream, "[");
76           val_print_array_elements (type, valaddr, address, stream, format,
77                                     deref_ref, recurse, pretty, 0);
78           fprintf_filtered (stream, "]");
79         }
80       else
81         {
82           error ("unimplemented in chill_val_print; unspecified array length");
83         }
84       break;
85
86     case TYPE_CODE_INT:
87       format = format ? format : output_format;
88       if (format)
89         {
90           print_scalar_formatted (valaddr, type, format, 0, stream);
91         }
92       else
93         {
94           val_print_type_code_int (type, valaddr, stream);
95         }
96       break;
97
98     case TYPE_CODE_CHAR:
99       format = format ? format : output_format;
100       if (format)
101         {
102           print_scalar_formatted (valaddr, type, format, 0, stream);
103         }
104       else
105         {
106           LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
107                          stream);
108         }
109       break;
110
111     case TYPE_CODE_FLT:
112       if (format)
113         {
114           print_scalar_formatted (valaddr, type, format, 0, stream);
115         }
116       else
117         {
118           print_floating (valaddr, type, stream);
119         }
120       break;
121
122     case TYPE_CODE_BOOL:
123       format = format ? format : output_format;
124       if (format)
125         {
126           print_scalar_formatted (valaddr, type, format, 0, stream);
127         }
128       else
129         {
130           val = unpack_long (builtin_type_chill_bool, valaddr);
131           fprintf_filtered (stream, val ? "TRUE" : "FALSE");
132         }
133       break;
134
135     case TYPE_CODE_UNDEF:
136       /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
137          dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
138          and no complete type for struct foo in that file.  */
139       fprintf_filtered (stream, "<incomplete type>");
140       break;
141
142     case TYPE_CODE_PTR:
143       if (format && format != 's')
144         {
145           print_scalar_formatted (valaddr, type, format, 0, stream);
146           break;
147         }
148       addr = unpack_pointer (type, valaddr);
149       elttype = TYPE_TARGET_TYPE (type);
150       
151       if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
152         {
153           /* Try to print what function it points to.  */
154           print_address_demangle (addr, stream, demangle);
155           /* Return value is irrelevant except for string pointers.  */
156           return (0);
157         }
158       if (addressprint && format != 's')
159         {
160           fprintf_filtered (stream, "H'%x", addr);
161         }
162       
163       /* For a pointer to char or unsigned char, also print the string
164          pointed to, unless pointer is null.  */
165       if (TYPE_LENGTH (elttype) == 1
166           && TYPE_CODE (elttype) == TYPE_CODE_CHAR
167           && (format == 0 || format == 's')
168           && addr != 0
169           && /* If print_max is UINT_MAX, the alloca below will fail.
170                 In that case don't try to print the string.  */
171           print_max < UINT_MAX)
172           {
173             i = val_print_string (addr, 0, stream);
174           }
175       /* Return number of characters printed, plus one for the
176          terminating null if we have "reached the end".  */
177       return (i + (print_max && i != print_max));
178       break;
179
180     case TYPE_CODE_STRING:
181       if (format && format != 's')
182         {
183           print_scalar_formatted (valaddr, type, format, 0, stream);
184           break;
185         }
186       if (addressprint && format != 's')
187         {
188           fprintf_filtered (stream, "H'%x ", addr);
189         }
190       i = TYPE_LENGTH (type);
191       LA_PRINT_STRING (stream, valaddr, i, 0);
192       /* Return number of characters printed, plus one for the terminating
193          null if we have "reached the end".  */
194       return (i + (print_max && i != print_max));
195       break;
196
197     case TYPE_CODE_STRUCT:
198       chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
199                                 0);
200       break;
201
202     case TYPE_CODE_REF:
203       if (addressprint)
204         {
205           fprintf_filtered (stream, "LOC(H'%lx)",
206                             unpack_long (builtin_type_int, valaddr));
207           if (deref_ref)
208             fputs_filtered (": ", stream);
209         }
210       /* De-reference the reference.  */
211       if (deref_ref)
212         {
213           if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
214             {
215               value deref_val =
216                 value_at
217                   (TYPE_TARGET_TYPE (type),
218                    unpack_pointer (lookup_pointer_type (builtin_type_void),
219                                    valaddr));
220               val_print (VALUE_TYPE (deref_val),
221                          VALUE_CONTENTS (deref_val),
222                          VALUE_ADDRESS (deref_val), stream, format,
223                          deref_ref, recurse + 1, pretty);
224             }
225           else
226             fputs_filtered ("???", stream);
227         }
228       break;
229
230     case TYPE_CODE_ENUM:
231       c_val_print (type, valaddr, address, stream, format,
232                    deref_ref, recurse, pretty);
233       break;
234
235     case TYPE_CODE_MEMBER:
236     case TYPE_CODE_UNION:
237     case TYPE_CODE_FUNC:
238     case TYPE_CODE_VOID:
239     case TYPE_CODE_ERROR:
240     case TYPE_CODE_RANGE:
241     default:
242       /* Let's derfer printing to the C printer, rather than
243          print an error message.  FIXME! */
244       c_val_print (type, valaddr, address, stream, format,
245                    deref_ref, recurse, pretty);
246     }
247   fflush (stream);
248   return (0);
249 }
250
251 /* Mutually recursive subroutines of cplus_print_value and c_val_print to
252    print out a structure's fields: cp_print_value_fields and cplus_print_value.
253
254    TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
255    same meanings as in cplus_print_value and c_val_print.
256
257    DONT_PRINT is an array of baseclass types that we
258    should not print, or zero if called from top level.  */
259
260 static void
261 chill_print_value_fields (type, valaddr, stream, format, recurse, pretty,
262                           dont_print)
263      struct type *type;
264      char *valaddr;
265      FILE *stream;
266      int format;
267      int recurse;
268      enum val_prettyprint pretty;
269      struct type **dont_print;
270 {
271   int i, len;
272   int fields_seen = 0;
273
274   check_stub_type (type);
275
276   fprintf_filtered (stream, "[");
277   len = TYPE_NFIELDS (type);
278   if (len == 0)
279     {
280       fprintf_filtered (stream, "<No data fields>");
281     }
282   else
283     {
284       for (i = 0; i < len; i++)
285         {
286           if (fields_seen)
287             {
288               fprintf_filtered (stream, ", ");
289             }
290           fields_seen = 1;
291           if (pretty)
292             {
293               fprintf_filtered (stream, "\n");
294               print_spaces_filtered (2 + 2 * recurse, stream);
295             }
296           else 
297             {
298               wrap_here (n_spaces (2 + 2 * recurse));
299             }
300           fputs_filtered (".", stream);
301           fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
302                                    language_chill, DMGL_NO_OPTS);
303           fputs_filtered (": ", stream);
304           if (TYPE_FIELD_PACKED (type, i))
305             {
306               value v;
307
308               /* Bitfields require special handling, especially due to byte
309                  order problems.  */
310               v = value_from_longest (TYPE_FIELD_TYPE (type, i),
311                                       unpack_field_as_long (type, valaddr, i));
312
313               chill_val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
314                                stream, format, 0, recurse + 1, pretty);
315             }
316           else
317             {
318               chill_val_print (TYPE_FIELD_TYPE (type, i), 
319                                valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
320                                0, stream, format, 0, recurse + 1, pretty);
321             }
322         }
323       if (pretty)
324         {
325           fprintf_filtered (stream, "\n");
326           print_spaces_filtered (2 * recurse, stream);
327         }
328     }
329   fprintf_filtered (stream, "]");
330 }
331
This page took 0.043012 seconds and 4 git commands to generate.