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