Tue Jan 19 09:06:14 1993 Ian Lance Taylor (ian@cygnus.com)
[deliverable/binutils-gdb.git] / gdb / ch-valprint.c
CommitLineData
a8a69e63
FF
1/* Support for printing Chill values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, 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
42int
43chill_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{
a8a69e63 54 LONGEST val;
c7da3ed3
FF
55 unsigned int i;
56 struct type *elttype;
57 unsigned eltlen;
58 CORE_ADDR addr;
a8a69e63
FF
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 {
a8a69e63
FF
65 if (prettyprint_arrays)
66 {
67 print_spaces_filtered (2 + 2 * recurse, stream);
68 }
69 fprintf_filtered (stream, "[");
a9b37611
FF
70 val_print_array_elements (type, valaddr, address, stream, format,
71 deref_ref, recurse, pretty, 0);
a8a69e63
FF
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:
c7da3ed3
FF
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 i = 0; /* Number of characters printed. */
160 if (TYPE_LENGTH (elttype) == 1
161 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
162 && (format == 0 || format == 's')
163 && addr != 0
164 && /* If print_max is UINT_MAX, the alloca below will fail.
165 In that case don't try to print the string. */
166 print_max < UINT_MAX)
167 {
168 i = val_print_string (addr, stream);
169 }
170 /* Return number of characters printed, plus one for the
171 terminating null if we have "reached the end". */
172 return (i + (print_max && i != print_max));
173 break;
174
c4413e2c
FF
175 case TYPE_CODE_STRING:
176 if (format && format != 's')
177 {
178 print_scalar_formatted (valaddr, type, format, 0, stream);
179 break;
180 }
181 addr = unpack_pointer (lookup_pointer_type (builtin_type_char), valaddr);
182 if (addressprint && format != 's')
183 {
184 fprintf_filtered (stream, "0x%x", addr);
185 }
186 if (addr != 0)
187 {
188 i = val_print_string (addr, TYPE_LENGTH (type), stream);
189 }
190 /* Return number of characters printed, plus one for the terminating
191 null if we have "reached the end". */
192 return (i + (print_max && i != print_max));
193 break;
194
a8a69e63
FF
195 case TYPE_CODE_MEMBER:
196 case TYPE_CODE_REF:
197 case TYPE_CODE_UNION:
198 case TYPE_CODE_STRUCT:
199 case TYPE_CODE_ENUM:
200 case TYPE_CODE_FUNC:
201 case TYPE_CODE_VOID:
202 case TYPE_CODE_ERROR:
203 case TYPE_CODE_RANGE:
204 error ("Unimplemented chill_val_print support for type %d",
205 TYPE_CODE (type));
206 break;
207
208 default:
209 error ("Invalid Chill type code %d in symbol table.", TYPE_CODE (type));
210 }
211 fflush (stream);
212 return (0);
213}
This page took 0.031886 seconds and 4 git commands to generate.