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