Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Fortran values for GDB, the GNU debugger. |
a2bd3dcd | 2 | |
6aba47ca DJ |
3 | Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005, 2006, |
4 | 2007 Free Software Foundation, Inc. | |
a2bd3dcd | 5 | |
c906108c SS |
6 | Contributed by Motorola. Adapted from the C definitions by Farooq Butt |
7 | (fmbutt@engage.sps.mot.com), additionally worked over by Stan Shebs. | |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2 of the License, or | |
14 | (at your option) any later version. | |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b JM |
21 | You should have received a copy of the GNU General Public License |
22 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
23 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
25 | |
26 | #include "defs.h" | |
27 | #include "gdb_string.h" | |
28 | #include "symtab.h" | |
29 | #include "gdbtypes.h" | |
30 | #include "expression.h" | |
31 | #include "value.h" | |
c906108c SS |
32 | #include "valprint.h" |
33 | #include "language.h" | |
c5aa993b | 34 | #include "f-lang.h" |
c906108c SS |
35 | #include "frame.h" |
36 | #include "gdbcore.h" | |
37 | #include "command.h" | |
fe898f56 | 38 | #include "block.h" |
c906108c SS |
39 | |
40 | #if 0 | |
a14ed312 | 41 | static int there_is_a_visible_common_named (char *); |
c906108c SS |
42 | #endif |
43 | ||
a14ed312 KB |
44 | extern void _initialize_f_valprint (void); |
45 | static void info_common_command (char *, int); | |
46 | static void list_all_visible_commons (char *); | |
d9fcf2fb JM |
47 | static void f77_create_arrayprint_offset_tbl (struct type *, |
48 | struct ui_file *); | |
a14ed312 | 49 | static void f77_get_dynamic_length_of_aggregate (struct type *); |
c906108c | 50 | |
c5aa993b | 51 | int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2]; |
c906108c SS |
52 | |
53 | /* Array which holds offsets to be applied to get a row's elements | |
54 | for a given array. Array also holds the size of each subarray. */ | |
55 | ||
56 | /* The following macro gives us the size of the nth dimension, Where | |
c5aa993b | 57 | n is 1 based. */ |
c906108c SS |
58 | |
59 | #define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1]) | |
60 | ||
c5aa993b | 61 | /* The following gives us the offset for row n where n is 1-based. */ |
c906108c SS |
62 | |
63 | #define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0]) | |
64 | ||
c5aa993b | 65 | int |
fba45db2 | 66 | f77_get_dynamic_lowerbound (struct type *type, int *lower_bound) |
c906108c | 67 | { |
206415a3 | 68 | struct frame_info *frame; |
c5aa993b JM |
69 | CORE_ADDR current_frame_addr; |
70 | CORE_ADDR ptr_to_lower_bound; | |
71 | ||
c906108c SS |
72 | switch (TYPE_ARRAY_LOWER_BOUND_TYPE (type)) |
73 | { | |
74 | case BOUND_BY_VALUE_ON_STACK: | |
206415a3 DJ |
75 | frame = deprecated_safe_get_selected_frame (); |
76 | current_frame_addr = get_frame_base (frame); | |
c5aa993b | 77 | if (current_frame_addr > 0) |
c906108c | 78 | { |
c5aa993b JM |
79 | *lower_bound = |
80 | read_memory_integer (current_frame_addr + | |
c906108c SS |
81 | TYPE_ARRAY_LOWER_BOUND_VALUE (type), |
82 | 4); | |
83 | } | |
84 | else | |
85 | { | |
c5aa993b JM |
86 | *lower_bound = DEFAULT_LOWER_BOUND; |
87 | return BOUND_FETCH_ERROR; | |
c906108c | 88 | } |
c5aa993b JM |
89 | break; |
90 | ||
c906108c SS |
91 | case BOUND_SIMPLE: |
92 | *lower_bound = TYPE_ARRAY_LOWER_BOUND_VALUE (type); | |
c5aa993b JM |
93 | break; |
94 | ||
95 | case BOUND_CANNOT_BE_DETERMINED: | |
8a3fe4f8 | 96 | error (_("Lower bound may not be '*' in F77")); |
c5aa993b JM |
97 | break; |
98 | ||
c906108c | 99 | case BOUND_BY_REF_ON_STACK: |
206415a3 DJ |
100 | frame = deprecated_safe_get_selected_frame (); |
101 | current_frame_addr = get_frame_base (frame); | |
c5aa993b | 102 | if (current_frame_addr > 0) |
c906108c | 103 | { |
c5aa993b | 104 | ptr_to_lower_bound = |
0d540cdf KD |
105 | read_memory_typed_address (current_frame_addr + |
106 | TYPE_ARRAY_LOWER_BOUND_VALUE (type), | |
107 | builtin_type_void_data_ptr); | |
c5aa993b | 108 | *lower_bound = read_memory_integer (ptr_to_lower_bound, 4); |
c906108c SS |
109 | } |
110 | else | |
111 | { | |
c5aa993b JM |
112 | *lower_bound = DEFAULT_LOWER_BOUND; |
113 | return BOUND_FETCH_ERROR; | |
c906108c | 114 | } |
c5aa993b JM |
115 | break; |
116 | ||
117 | case BOUND_BY_REF_IN_REG: | |
118 | case BOUND_BY_VALUE_IN_REG: | |
119 | default: | |
8a3fe4f8 | 120 | error (_("??? unhandled dynamic array bound type ???")); |
c5aa993b | 121 | break; |
c906108c SS |
122 | } |
123 | return BOUND_FETCH_OK; | |
124 | } | |
125 | ||
c5aa993b | 126 | int |
fba45db2 | 127 | f77_get_dynamic_upperbound (struct type *type, int *upper_bound) |
c906108c | 128 | { |
206415a3 | 129 | struct frame_info *frame; |
c906108c | 130 | CORE_ADDR current_frame_addr = 0; |
c5aa993b JM |
131 | CORE_ADDR ptr_to_upper_bound; |
132 | ||
c906108c SS |
133 | switch (TYPE_ARRAY_UPPER_BOUND_TYPE (type)) |
134 | { | |
135 | case BOUND_BY_VALUE_ON_STACK: | |
206415a3 DJ |
136 | frame = deprecated_safe_get_selected_frame (); |
137 | current_frame_addr = get_frame_base (frame); | |
c5aa993b | 138 | if (current_frame_addr > 0) |
c906108c | 139 | { |
c5aa993b JM |
140 | *upper_bound = |
141 | read_memory_integer (current_frame_addr + | |
c906108c SS |
142 | TYPE_ARRAY_UPPER_BOUND_VALUE (type), |
143 | 4); | |
144 | } | |
145 | else | |
146 | { | |
c5aa993b JM |
147 | *upper_bound = DEFAULT_UPPER_BOUND; |
148 | return BOUND_FETCH_ERROR; | |
c906108c | 149 | } |
c5aa993b JM |
150 | break; |
151 | ||
c906108c SS |
152 | case BOUND_SIMPLE: |
153 | *upper_bound = TYPE_ARRAY_UPPER_BOUND_VALUE (type); | |
c5aa993b JM |
154 | break; |
155 | ||
156 | case BOUND_CANNOT_BE_DETERMINED: | |
c906108c | 157 | /* we have an assumed size array on our hands. Assume that |
c5aa993b JM |
158 | upper_bound == lower_bound so that we show at least |
159 | 1 element.If the user wants to see more elements, let | |
160 | him manually ask for 'em and we'll subscript the | |
161 | array and show him */ | |
c906108c | 162 | f77_get_dynamic_lowerbound (type, upper_bound); |
c5aa993b JM |
163 | break; |
164 | ||
c906108c | 165 | case BOUND_BY_REF_ON_STACK: |
206415a3 DJ |
166 | frame = deprecated_safe_get_selected_frame (); |
167 | current_frame_addr = get_frame_base (frame); | |
c5aa993b | 168 | if (current_frame_addr > 0) |
c906108c | 169 | { |
c5aa993b | 170 | ptr_to_upper_bound = |
0d540cdf KD |
171 | read_memory_typed_address (current_frame_addr + |
172 | TYPE_ARRAY_UPPER_BOUND_VALUE (type), | |
173 | builtin_type_void_data_ptr); | |
c5aa993b | 174 | *upper_bound = read_memory_integer (ptr_to_upper_bound, 4); |
c906108c SS |
175 | } |
176 | else | |
177 | { | |
c5aa993b | 178 | *upper_bound = DEFAULT_UPPER_BOUND; |
c906108c SS |
179 | return BOUND_FETCH_ERROR; |
180 | } | |
c5aa993b JM |
181 | break; |
182 | ||
183 | case BOUND_BY_REF_IN_REG: | |
184 | case BOUND_BY_VALUE_IN_REG: | |
185 | default: | |
8a3fe4f8 | 186 | error (_("??? unhandled dynamic array bound type ???")); |
c5aa993b | 187 | break; |
c906108c SS |
188 | } |
189 | return BOUND_FETCH_OK; | |
190 | } | |
191 | ||
c5aa993b | 192 | /* Obtain F77 adjustable array dimensions */ |
c906108c SS |
193 | |
194 | static void | |
fba45db2 | 195 | f77_get_dynamic_length_of_aggregate (struct type *type) |
c906108c SS |
196 | { |
197 | int upper_bound = -1; | |
c5aa993b JM |
198 | int lower_bound = 1; |
199 | int retcode; | |
200 | ||
c906108c SS |
201 | /* Recursively go all the way down into a possibly multi-dimensional |
202 | F77 array and get the bounds. For simple arrays, this is pretty | |
203 | easy but when the bounds are dynamic, we must be very careful | |
204 | to add up all the lengths correctly. Not doing this right | |
205 | will lead to horrendous-looking arrays in parameter lists. | |
c5aa993b | 206 | |
c906108c | 207 | This function also works for strings which behave very |
c5aa993b JM |
208 | similarly to arrays. */ |
209 | ||
210 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY | |
211 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRING) | |
c906108c | 212 | f77_get_dynamic_length_of_aggregate (TYPE_TARGET_TYPE (type)); |
c5aa993b JM |
213 | |
214 | /* Recursion ends here, start setting up lengths. */ | |
215 | retcode = f77_get_dynamic_lowerbound (type, &lower_bound); | |
c906108c | 216 | if (retcode == BOUND_FETCH_ERROR) |
8a3fe4f8 | 217 | error (_("Cannot obtain valid array lower bound")); |
c5aa993b JM |
218 | |
219 | retcode = f77_get_dynamic_upperbound (type, &upper_bound); | |
c906108c | 220 | if (retcode == BOUND_FETCH_ERROR) |
8a3fe4f8 | 221 | error (_("Cannot obtain valid array upper bound")); |
c5aa993b JM |
222 | |
223 | /* Patch in a valid length value. */ | |
224 | ||
c906108c SS |
225 | TYPE_LENGTH (type) = |
226 | (upper_bound - lower_bound + 1) * TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type))); | |
c5aa993b | 227 | } |
c906108c SS |
228 | |
229 | /* Function that sets up the array offset,size table for the array | |
c5aa993b | 230 | type "type". */ |
c906108c | 231 | |
c5aa993b | 232 | static void |
fba45db2 | 233 | f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream) |
c906108c SS |
234 | { |
235 | struct type *tmp_type; | |
236 | int eltlen; | |
237 | int ndimen = 1; | |
c5aa993b JM |
238 | int upper, lower, retcode; |
239 | ||
240 | tmp_type = type; | |
241 | ||
242 | while ((TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)) | |
c906108c SS |
243 | { |
244 | if (TYPE_ARRAY_UPPER_BOUND_TYPE (tmp_type) == BOUND_CANNOT_BE_DETERMINED) | |
c5aa993b JM |
245 | fprintf_filtered (stream, "<assumed size array> "); |
246 | ||
c906108c SS |
247 | retcode = f77_get_dynamic_upperbound (tmp_type, &upper); |
248 | if (retcode == BOUND_FETCH_ERROR) | |
8a3fe4f8 | 249 | error (_("Cannot obtain dynamic upper bound")); |
c5aa993b JM |
250 | |
251 | retcode = f77_get_dynamic_lowerbound (tmp_type, &lower); | |
c906108c | 252 | if (retcode == BOUND_FETCH_ERROR) |
8a3fe4f8 | 253 | error (_("Cannot obtain dynamic lower bound")); |
c5aa993b | 254 | |
c906108c | 255 | F77_DIM_SIZE (ndimen) = upper - lower + 1; |
c5aa993b | 256 | |
c906108c | 257 | tmp_type = TYPE_TARGET_TYPE (tmp_type); |
c5aa993b | 258 | ndimen++; |
c906108c | 259 | } |
c5aa993b | 260 | |
c906108c SS |
261 | /* Now we multiply eltlen by all the offsets, so that later we |
262 | can print out array elements correctly. Up till now we | |
263 | know an offset to apply to get the item but we also | |
264 | have to know how much to add to get to the next item */ | |
c5aa993b | 265 | |
c906108c | 266 | ndimen--; |
c5aa993b | 267 | eltlen = TYPE_LENGTH (tmp_type); |
c906108c SS |
268 | F77_DIM_OFFSET (ndimen) = eltlen; |
269 | while (--ndimen > 0) | |
270 | { | |
271 | eltlen *= F77_DIM_SIZE (ndimen + 1); | |
272 | F77_DIM_OFFSET (ndimen) = eltlen; | |
273 | } | |
274 | } | |
275 | ||
b3cacbee DL |
276 | |
277 | ||
c906108c SS |
278 | /* Actual function which prints out F77 arrays, Valaddr == address in |
279 | the superior. Address == the address in the inferior. */ | |
7b0090c3 | 280 | |
c5aa993b | 281 | static void |
a2bd3dcd | 282 | f77_print_array_1 (int nss, int ndimensions, struct type *type, |
fc1a4b47 | 283 | const gdb_byte *valaddr, CORE_ADDR address, |
a2bd3dcd | 284 | struct ui_file *stream, int format, |
b3cacbee DL |
285 | int deref_ref, int recurse, enum val_prettyprint pretty, |
286 | int *elts) | |
c906108c SS |
287 | { |
288 | int i; | |
c5aa993b | 289 | |
c906108c SS |
290 | if (nss != ndimensions) |
291 | { | |
b3cacbee | 292 | for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < print_max); i++) |
c906108c SS |
293 | { |
294 | fprintf_filtered (stream, "( "); | |
295 | f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type), | |
c5aa993b JM |
296 | valaddr + i * F77_DIM_OFFSET (nss), |
297 | address + i * F77_DIM_OFFSET (nss), | |
b3cacbee | 298 | stream, format, deref_ref, recurse, pretty, elts); |
c906108c SS |
299 | fprintf_filtered (stream, ") "); |
300 | } | |
7b0090c3 | 301 | if (*elts >= print_max && i < F77_DIM_SIZE (nss)) |
b3cacbee | 302 | fprintf_filtered (stream, "..."); |
c906108c SS |
303 | } |
304 | else | |
305 | { | |
7b0090c3 DL |
306 | for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < print_max; |
307 | i++, (*elts)++) | |
c906108c SS |
308 | { |
309 | val_print (TYPE_TARGET_TYPE (type), | |
310 | valaddr + i * F77_DIM_OFFSET (ndimensions), | |
c5aa993b | 311 | 0, |
c906108c | 312 | address + i * F77_DIM_OFFSET (ndimensions), |
c5aa993b | 313 | stream, format, deref_ref, recurse, pretty); |
c906108c SS |
314 | |
315 | if (i != (F77_DIM_SIZE (nss) - 1)) | |
c5aa993b JM |
316 | fprintf_filtered (stream, ", "); |
317 | ||
7b0090c3 | 318 | if ((*elts == print_max - 1) && (i != (F77_DIM_SIZE (nss) - 1))) |
c906108c SS |
319 | fprintf_filtered (stream, "..."); |
320 | } | |
321 | } | |
322 | } | |
323 | ||
324 | /* This function gets called to print an F77 array, we set up some | |
325 | stuff and then immediately call f77_print_array_1() */ | |
326 | ||
c5aa993b | 327 | static void |
fc1a4b47 | 328 | f77_print_array (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd AC |
329 | CORE_ADDR address, struct ui_file *stream, |
330 | int format, int deref_ref, int recurse, | |
fba45db2 | 331 | enum val_prettyprint pretty) |
c906108c | 332 | { |
c5aa993b | 333 | int ndimensions; |
b3cacbee | 334 | int elts = 0; |
c5aa993b JM |
335 | |
336 | ndimensions = calc_f77_array_dims (type); | |
337 | ||
c906108c | 338 | if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0) |
8a3fe4f8 | 339 | error (_("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)"), |
c906108c | 340 | ndimensions, MAX_FORTRAN_DIMS); |
c5aa993b | 341 | |
c906108c SS |
342 | /* Since F77 arrays are stored column-major, we set up an |
343 | offset table to get at the various row's elements. The | |
c5aa993b | 344 | offset table contains entries for both offset and subarray size. */ |
c906108c | 345 | |
c5aa993b JM |
346 | f77_create_arrayprint_offset_tbl (type, stream); |
347 | ||
348 | f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, format, | |
b3cacbee | 349 | deref_ref, recurse, pretty, &elts); |
c5aa993b | 350 | } |
c906108c | 351 | \f |
c5aa993b | 352 | |
c906108c SS |
353 | /* Print data of type TYPE located at VALADDR (within GDB), which came from |
354 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
355 | FORMAT (a letter or 0 for natural format). The data at VALADDR is in | |
356 | target byte order. | |
c5aa993b | 357 | |
c906108c SS |
358 | If the data are a string pointer, returns the number of string characters |
359 | printed. | |
c5aa993b | 360 | |
c906108c SS |
361 | If DEREF_REF is nonzero, then dereference references, otherwise just print |
362 | them like pointers. | |
c5aa993b | 363 | |
c906108c SS |
364 | The PRETTY parameter controls prettyprinting. */ |
365 | ||
366 | int | |
fc1a4b47 | 367 | f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, |
fba45db2 KB |
368 | CORE_ADDR address, struct ui_file *stream, int format, |
369 | int deref_ref, int recurse, enum val_prettyprint pretty) | |
c906108c | 370 | { |
52f0bd74 | 371 | unsigned int i = 0; /* Number of characters printed */ |
c906108c SS |
372 | struct type *elttype; |
373 | LONGEST val; | |
374 | CORE_ADDR addr; | |
2a5e440c | 375 | int index; |
c5aa993b | 376 | |
c906108c SS |
377 | CHECK_TYPEDEF (type); |
378 | switch (TYPE_CODE (type)) | |
379 | { | |
c5aa993b | 380 | case TYPE_CODE_STRING: |
c906108c SS |
381 | f77_get_dynamic_length_of_aggregate (type); |
382 | LA_PRINT_STRING (stream, valaddr, TYPE_LENGTH (type), 1, 0); | |
383 | break; | |
c5aa993b | 384 | |
c906108c | 385 | case TYPE_CODE_ARRAY: |
c5aa993b JM |
386 | fprintf_filtered (stream, "("); |
387 | f77_print_array (type, valaddr, address, stream, format, | |
388 | deref_ref, recurse, pretty); | |
c906108c SS |
389 | fprintf_filtered (stream, ")"); |
390 | break; | |
7e86466e | 391 | |
c906108c SS |
392 | case TYPE_CODE_PTR: |
393 | if (format && format != 's') | |
394 | { | |
395 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
396 | break; | |
397 | } | |
398 | else | |
399 | { | |
400 | addr = unpack_pointer (type, valaddr); | |
401 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
c5aa993b | 402 | |
c906108c SS |
403 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) |
404 | { | |
405 | /* Try to print what function it points to. */ | |
406 | print_address_demangle (addr, stream, demangle); | |
407 | /* Return value is irrelevant except for string pointers. */ | |
408 | return 0; | |
409 | } | |
c5aa993b | 410 | |
c906108c | 411 | if (addressprint && format != 's') |
66bf4b3a | 412 | deprecated_print_address_numeric (addr, 1, stream); |
c5aa993b | 413 | |
c906108c SS |
414 | /* For a pointer to char or unsigned char, also print the string |
415 | pointed to, unless pointer is null. */ | |
416 | if (TYPE_LENGTH (elttype) == 1 | |
417 | && TYPE_CODE (elttype) == TYPE_CODE_INT | |
418 | && (format == 0 || format == 's') | |
419 | && addr != 0) | |
420 | i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); | |
c5aa993b | 421 | |
7e86466e RH |
422 | /* Return number of characters printed, including the terminating |
423 | '\0' if we reached the end. val_print_string takes care including | |
424 | the terminating '\0' if necessary. */ | |
425 | return i; | |
426 | } | |
427 | break; | |
428 | ||
429 | case TYPE_CODE_REF: | |
430 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
431 | if (addressprint) | |
432 | { | |
433 | CORE_ADDR addr | |
434 | = extract_typed_address (valaddr + embedded_offset, type); | |
435 | fprintf_filtered (stream, "@"); | |
66bf4b3a | 436 | deprecated_print_address_numeric (addr, 1, stream); |
7e86466e RH |
437 | if (deref_ref) |
438 | fputs_filtered (": ", stream); | |
439 | } | |
440 | /* De-reference the reference. */ | |
441 | if (deref_ref) | |
442 | { | |
443 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
444 | { | |
445 | struct value *deref_val = | |
446 | value_at | |
447 | (TYPE_TARGET_TYPE (type), | |
448 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
00a4c844 | 449 | valaddr + embedded_offset)); |
806048c6 DJ |
450 | common_val_print (deref_val, stream, format, deref_ref, recurse, |
451 | pretty); | |
7e86466e RH |
452 | } |
453 | else | |
454 | fputs_filtered ("???", stream); | |
c906108c SS |
455 | } |
456 | break; | |
c5aa993b | 457 | |
c906108c SS |
458 | case TYPE_CODE_FUNC: |
459 | if (format) | |
460 | { | |
461 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
462 | break; | |
463 | } | |
464 | /* FIXME, we should consider, at least for ANSI C language, eliminating | |
c5aa993b | 465 | the distinction made between FUNCs and POINTERs to FUNCs. */ |
c906108c SS |
466 | fprintf_filtered (stream, "{"); |
467 | type_print (type, "", stream, -1); | |
468 | fprintf_filtered (stream, "} "); | |
469 | /* Try to print what function it points to, and its address. */ | |
470 | print_address_demangle (address, stream, demangle); | |
471 | break; | |
c5aa993b | 472 | |
c906108c SS |
473 | case TYPE_CODE_INT: |
474 | format = format ? format : output_format; | |
475 | if (format) | |
476 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
477 | else | |
478 | { | |
479 | val_print_type_code_int (type, valaddr, stream); | |
480 | /* C and C++ has no single byte int type, char is used instead. | |
481 | Since we don't know whether the value is really intended to | |
482 | be used as an integer or a character, print the character | |
483 | equivalent as well. */ | |
484 | if (TYPE_LENGTH (type) == 1) | |
485 | { | |
486 | fputs_filtered (" ", stream); | |
487 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr), | |
488 | stream); | |
489 | } | |
490 | } | |
491 | break; | |
c5aa993b | 492 | |
4f2aea11 MK |
493 | case TYPE_CODE_FLAGS: |
494 | if (format) | |
495 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
496 | else | |
497 | val_print_type_code_flags (type, valaddr, stream); | |
498 | break; | |
499 | ||
c906108c SS |
500 | case TYPE_CODE_FLT: |
501 | if (format) | |
502 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
503 | else | |
504 | print_floating (valaddr, type, stream); | |
505 | break; | |
c5aa993b | 506 | |
c906108c SS |
507 | case TYPE_CODE_VOID: |
508 | fprintf_filtered (stream, "VOID"); | |
509 | break; | |
c5aa993b | 510 | |
c906108c SS |
511 | case TYPE_CODE_ERROR: |
512 | fprintf_filtered (stream, "<error type>"); | |
513 | break; | |
c5aa993b | 514 | |
c906108c SS |
515 | case TYPE_CODE_RANGE: |
516 | /* FIXME, we should not ever have to print one of these yet. */ | |
517 | fprintf_filtered (stream, "<range type>"); | |
518 | break; | |
c5aa993b | 519 | |
c906108c SS |
520 | case TYPE_CODE_BOOL: |
521 | format = format ? format : output_format; | |
522 | if (format) | |
523 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
524 | else | |
525 | { | |
c5aa993b JM |
526 | val = 0; |
527 | switch (TYPE_LENGTH (type)) | |
c906108c SS |
528 | { |
529 | case 1: | |
530 | val = unpack_long (builtin_type_f_logical_s1, valaddr); | |
c5aa993b JM |
531 | break; |
532 | ||
533 | case 2: | |
c906108c | 534 | val = unpack_long (builtin_type_f_logical_s2, valaddr); |
c5aa993b JM |
535 | break; |
536 | ||
537 | case 4: | |
c906108c | 538 | val = unpack_long (builtin_type_f_logical, valaddr); |
c5aa993b JM |
539 | break; |
540 | ||
c906108c | 541 | default: |
8a3fe4f8 | 542 | error (_("Logicals of length %d bytes not supported"), |
c906108c | 543 | TYPE_LENGTH (type)); |
c5aa993b | 544 | |
c906108c | 545 | } |
c5aa993b JM |
546 | |
547 | if (val == 0) | |
c906108c | 548 | fprintf_filtered (stream, ".FALSE."); |
c5aa993b JM |
549 | else if (val == 1) |
550 | fprintf_filtered (stream, ".TRUE."); | |
551 | else | |
552 | /* Not a legitimate logical type, print as an integer. */ | |
553 | { | |
554 | /* Bash the type code temporarily. */ | |
555 | TYPE_CODE (type) = TYPE_CODE_INT; | |
556 | f_val_print (type, valaddr, 0, address, stream, format, | |
557 | deref_ref, recurse, pretty); | |
558 | /* Restore the type code so later uses work as intended. */ | |
559 | TYPE_CODE (type) = TYPE_CODE_BOOL; | |
560 | } | |
c906108c SS |
561 | } |
562 | break; | |
c5aa993b | 563 | |
c906108c SS |
564 | case TYPE_CODE_COMPLEX: |
565 | switch (TYPE_LENGTH (type)) | |
566 | { | |
c5aa993b JM |
567 | case 8: |
568 | type = builtin_type_f_real; | |
569 | break; | |
570 | case 16: | |
571 | type = builtin_type_f_real_s8; | |
572 | break; | |
573 | case 32: | |
574 | type = builtin_type_f_real_s16; | |
575 | break; | |
c906108c | 576 | default: |
8a3fe4f8 | 577 | error (_("Cannot print out complex*%d variables"), TYPE_LENGTH (type)); |
c906108c SS |
578 | } |
579 | fputs_filtered ("(", stream); | |
580 | print_floating (valaddr, type, stream); | |
581 | fputs_filtered (",", stream); | |
9af97293 | 582 | print_floating (valaddr + TYPE_LENGTH (type), type, stream); |
c906108c SS |
583 | fputs_filtered (")", stream); |
584 | break; | |
c5aa993b | 585 | |
c906108c SS |
586 | case TYPE_CODE_UNDEF: |
587 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
c5aa993b JM |
588 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" |
589 | and no complete type for struct foo in that file. */ | |
c906108c SS |
590 | fprintf_filtered (stream, "<incomplete type>"); |
591 | break; | |
c5aa993b | 592 | |
2a5e440c WZ |
593 | case TYPE_CODE_STRUCT: |
594 | /* Starting from the Fortran 90 standard, Fortran supports derived | |
595 | types. */ | |
596 | fprintf_filtered (stream, "{ "); | |
597 | for (index = 0; index < TYPE_NFIELDS (type); index++) | |
598 | { | |
599 | int offset = TYPE_FIELD_BITPOS (type, index) / 8; | |
600 | f_val_print (TYPE_FIELD_TYPE (type, index), valaddr + offset, | |
601 | embedded_offset, address, stream, | |
602 | format, deref_ref, recurse, pretty); | |
603 | if (index != TYPE_NFIELDS (type) - 1) | |
604 | fputs_filtered (", ", stream); | |
605 | } | |
606 | fprintf_filtered (stream, "}"); | |
607 | break; | |
608 | ||
c906108c | 609 | default: |
8a3fe4f8 | 610 | error (_("Invalid F77 type code %d in symbol table."), TYPE_CODE (type)); |
c906108c SS |
611 | } |
612 | gdb_flush (stream); | |
613 | return 0; | |
614 | } | |
615 | ||
616 | static void | |
fba45db2 | 617 | list_all_visible_commons (char *funname) |
c906108c | 618 | { |
c5aa993b JM |
619 | SAVED_F77_COMMON_PTR tmp; |
620 | ||
c906108c | 621 | tmp = head_common_list; |
c5aa993b | 622 | |
a3f17187 | 623 | printf_filtered (_("All COMMON blocks visible at this level:\n\n")); |
c5aa993b | 624 | |
c906108c SS |
625 | while (tmp != NULL) |
626 | { | |
762f08a3 | 627 | if (strcmp (tmp->owning_function, funname) == 0) |
c5aa993b JM |
628 | printf_filtered ("%s\n", tmp->name); |
629 | ||
c906108c SS |
630 | tmp = tmp->next; |
631 | } | |
632 | } | |
633 | ||
634 | /* This function is used to print out the values in a given COMMON | |
635 | block. It will always use the most local common block of the | |
c5aa993b | 636 | given name */ |
c906108c | 637 | |
c5aa993b | 638 | static void |
fba45db2 | 639 | info_common_command (char *comname, int from_tty) |
c906108c | 640 | { |
c5aa993b JM |
641 | SAVED_F77_COMMON_PTR the_common; |
642 | COMMON_ENTRY_PTR entry; | |
c906108c | 643 | struct frame_info *fi; |
52f0bd74 | 644 | char *funname = 0; |
c906108c | 645 | struct symbol *func; |
c5aa993b | 646 | |
c906108c SS |
647 | /* We have been told to display the contents of F77 COMMON |
648 | block supposedly visible in this function. Let us | |
649 | first make sure that it is visible and if so, let | |
c5aa993b JM |
650 | us display its contents */ |
651 | ||
206415a3 | 652 | fi = get_selected_frame (_("No frame selected")); |
c5aa993b | 653 | |
c906108c | 654 | /* The following is generally ripped off from stack.c's routine |
c5aa993b JM |
655 | print_frame_info() */ |
656 | ||
bdd78e62 | 657 | func = find_pc_function (get_frame_pc (fi)); |
c906108c SS |
658 | if (func) |
659 | { | |
660 | /* In certain pathological cases, the symtabs give the wrong | |
c5aa993b JM |
661 | function (when we are in the first function in a file which |
662 | is compiled without debugging symbols, the previous function | |
663 | is compiled with debugging symbols, and the "foo.o" symbol | |
664 | that is supposed to tell us where the file with debugging symbols | |
665 | ends has been truncated by ar because it is longer than 15 | |
666 | characters). | |
667 | ||
668 | So look in the minimal symbol tables as well, and if it comes | |
669 | up with a larger address for the function use that instead. | |
670 | I don't think this can ever cause any problems; there shouldn't | |
671 | be any minimal symbols in the middle of a function. | |
672 | FIXME: (Not necessarily true. What about text labels) */ | |
673 | ||
bdd78e62 | 674 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi)); |
c5aa993b | 675 | |
c906108c | 676 | if (msymbol != NULL |
c5aa993b | 677 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
c906108c | 678 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
22abf04a | 679 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 680 | else |
22abf04a | 681 | funname = DEPRECATED_SYMBOL_NAME (func); |
c906108c SS |
682 | } |
683 | else | |
684 | { | |
aa1ee363 | 685 | struct minimal_symbol *msymbol = |
bdd78e62 | 686 | lookup_minimal_symbol_by_pc (get_frame_pc (fi)); |
c5aa993b | 687 | |
c906108c | 688 | if (msymbol != NULL) |
22abf04a | 689 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 690 | } |
c5aa993b | 691 | |
c906108c | 692 | /* If comname is NULL, we assume the user wishes to see the |
c5aa993b JM |
693 | which COMMON blocks are visible here and then return */ |
694 | ||
c906108c SS |
695 | if (comname == 0) |
696 | { | |
697 | list_all_visible_commons (funname); | |
c5aa993b | 698 | return; |
c906108c | 699 | } |
c5aa993b JM |
700 | |
701 | the_common = find_common_for_function (comname, funname); | |
702 | ||
c906108c SS |
703 | if (the_common) |
704 | { | |
762f08a3 | 705 | if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0) |
a3f17187 | 706 | printf_filtered (_("Contents of blank COMMON block:\n")); |
c5aa993b | 707 | else |
a3f17187 | 708 | printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname); |
c5aa993b JM |
709 | |
710 | printf_filtered ("\n"); | |
711 | entry = the_common->entries; | |
712 | ||
c906108c SS |
713 | while (entry != NULL) |
714 | { | |
22abf04a | 715 | printf_filtered ("%s = ", DEPRECATED_SYMBOL_NAME (entry->symbol)); |
c5aa993b JM |
716 | print_variable_value (entry->symbol, fi, gdb_stdout); |
717 | printf_filtered ("\n"); | |
718 | entry = entry->next; | |
c906108c SS |
719 | } |
720 | } | |
c5aa993b | 721 | else |
a3f17187 | 722 | printf_filtered (_("Cannot locate the common block %s in function '%s'\n"), |
c5aa993b | 723 | comname, funname); |
c906108c SS |
724 | } |
725 | ||
726 | /* This function is used to determine whether there is a | |
c5aa993b | 727 | F77 common block visible at the current scope called 'comname'. */ |
c906108c SS |
728 | |
729 | #if 0 | |
730 | static int | |
fba45db2 | 731 | there_is_a_visible_common_named (char *comname) |
c906108c | 732 | { |
c5aa993b | 733 | SAVED_F77_COMMON_PTR the_common; |
c906108c | 734 | struct frame_info *fi; |
52f0bd74 | 735 | char *funname = 0; |
c906108c | 736 | struct symbol *func; |
c5aa993b | 737 | |
c906108c | 738 | if (comname == NULL) |
8a3fe4f8 | 739 | error (_("Cannot deal with NULL common name!")); |
c5aa993b | 740 | |
206415a3 | 741 | fi = get_selected_frame (_("No frame selected")); |
c5aa993b | 742 | |
c906108c | 743 | /* The following is generally ripped off from stack.c's routine |
c5aa993b JM |
744 | print_frame_info() */ |
745 | ||
c906108c SS |
746 | func = find_pc_function (fi->pc); |
747 | if (func) | |
748 | { | |
749 | /* In certain pathological cases, the symtabs give the wrong | |
c5aa993b JM |
750 | function (when we are in the first function in a file which |
751 | is compiled without debugging symbols, the previous function | |
752 | is compiled with debugging symbols, and the "foo.o" symbol | |
753 | that is supposed to tell us where the file with debugging symbols | |
754 | ends has been truncated by ar because it is longer than 15 | |
755 | characters). | |
756 | ||
757 | So look in the minimal symbol tables as well, and if it comes | |
758 | up with a larger address for the function use that instead. | |
759 | I don't think this can ever cause any problems; there shouldn't | |
760 | be any minimal symbols in the middle of a function. | |
761 | FIXME: (Not necessarily true. What about text labels) */ | |
762 | ||
c906108c | 763 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); |
c5aa993b | 764 | |
c906108c | 765 | if (msymbol != NULL |
c5aa993b | 766 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
c906108c | 767 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
22abf04a | 768 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 769 | else |
22abf04a | 770 | funname = DEPRECATED_SYMBOL_NAME (func); |
c906108c SS |
771 | } |
772 | else | |
773 | { | |
aa1ee363 | 774 | struct minimal_symbol *msymbol = |
c5aa993b JM |
775 | lookup_minimal_symbol_by_pc (fi->pc); |
776 | ||
c906108c | 777 | if (msymbol != NULL) |
22abf04a | 778 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 779 | } |
c5aa993b JM |
780 | |
781 | the_common = find_common_for_function (comname, funname); | |
782 | ||
c906108c SS |
783 | return (the_common ? 1 : 0); |
784 | } | |
785 | #endif | |
786 | ||
787 | void | |
fba45db2 | 788 | _initialize_f_valprint (void) |
c906108c SS |
789 | { |
790 | add_info ("common", info_common_command, | |
1bedd215 | 791 | _("Print out the values contained in a Fortran COMMON block.")); |
c906108c | 792 | if (xdb_commands) |
c5aa993b | 793 | add_com ("lc", class_info, info_common_command, |
1bedd215 | 794 | _("Print out the values contained in a Fortran COMMON block.")); |
c906108c | 795 | } |