]>
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, | |
50 | enum val_prettyprint); | |
51 | static void f77_create_arrayprint_offset_tbl (struct type *, | |
52 | struct ui_file *); | |
a14ed312 | 53 | static void f77_get_dynamic_length_of_aggregate (struct type *); |
c906108c | 54 | |
c5aa993b | 55 | int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2]; |
c906108c SS |
56 | |
57 | /* Array which holds offsets to be applied to get a row's elements | |
58 | for a given array. Array also holds the size of each subarray. */ | |
59 | ||
60 | /* The following macro gives us the size of the nth dimension, Where | |
c5aa993b | 61 | n is 1 based. */ |
c906108c SS |
62 | |
63 | #define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1]) | |
64 | ||
c5aa993b | 65 | /* The following gives us the offset for row n where n is 1-based. */ |
c906108c SS |
66 | |
67 | #define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0]) | |
68 | ||
c5aa993b | 69 | int |
fba45db2 | 70 | f77_get_dynamic_lowerbound (struct type *type, int *lower_bound) |
c906108c | 71 | { |
c5aa993b JM |
72 | CORE_ADDR current_frame_addr; |
73 | CORE_ADDR ptr_to_lower_bound; | |
74 | ||
c906108c SS |
75 | switch (TYPE_ARRAY_LOWER_BOUND_TYPE (type)) |
76 | { | |
77 | case BOUND_BY_VALUE_ON_STACK: | |
8b36eed8 | 78 | current_frame_addr = get_frame_base (deprecated_selected_frame); |
c5aa993b | 79 | if (current_frame_addr > 0) |
c906108c | 80 | { |
c5aa993b JM |
81 | *lower_bound = |
82 | read_memory_integer (current_frame_addr + | |
c906108c SS |
83 | TYPE_ARRAY_LOWER_BOUND_VALUE (type), |
84 | 4); | |
85 | } | |
86 | else | |
87 | { | |
c5aa993b JM |
88 | *lower_bound = DEFAULT_LOWER_BOUND; |
89 | return BOUND_FETCH_ERROR; | |
c906108c | 90 | } |
c5aa993b JM |
91 | break; |
92 | ||
c906108c SS |
93 | case BOUND_SIMPLE: |
94 | *lower_bound = TYPE_ARRAY_LOWER_BOUND_VALUE (type); | |
c5aa993b JM |
95 | break; |
96 | ||
97 | case BOUND_CANNOT_BE_DETERMINED: | |
98 | error ("Lower bound may not be '*' in F77"); | |
99 | break; | |
100 | ||
c906108c | 101 | case BOUND_BY_REF_ON_STACK: |
8b36eed8 | 102 | current_frame_addr = get_frame_base (deprecated_selected_frame); |
c5aa993b | 103 | if (current_frame_addr > 0) |
c906108c | 104 | { |
c5aa993b | 105 | ptr_to_lower_bound = |
0d540cdf KD |
106 | read_memory_typed_address (current_frame_addr + |
107 | TYPE_ARRAY_LOWER_BOUND_VALUE (type), | |
108 | builtin_type_void_data_ptr); | |
c5aa993b | 109 | *lower_bound = read_memory_integer (ptr_to_lower_bound, 4); |
c906108c SS |
110 | } |
111 | else | |
112 | { | |
c5aa993b JM |
113 | *lower_bound = DEFAULT_LOWER_BOUND; |
114 | return BOUND_FETCH_ERROR; | |
c906108c | 115 | } |
c5aa993b JM |
116 | break; |
117 | ||
118 | case BOUND_BY_REF_IN_REG: | |
119 | case BOUND_BY_VALUE_IN_REG: | |
120 | default: | |
c906108c | 121 | error ("??? unhandled dynamic array bound type ???"); |
c5aa993b | 122 | break; |
c906108c SS |
123 | } |
124 | return BOUND_FETCH_OK; | |
125 | } | |
126 | ||
c5aa993b | 127 | int |
fba45db2 | 128 | f77_get_dynamic_upperbound (struct type *type, int *upper_bound) |
c906108c SS |
129 | { |
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: | |
8b36eed8 | 136 | current_frame_addr = get_frame_base (deprecated_selected_frame); |
c5aa993b | 137 | if (current_frame_addr > 0) |
c906108c | 138 | { |
c5aa993b JM |
139 | *upper_bound = |
140 | read_memory_integer (current_frame_addr + | |
c906108c SS |
141 | TYPE_ARRAY_UPPER_BOUND_VALUE (type), |
142 | 4); | |
143 | } | |
144 | else | |
145 | { | |
c5aa993b JM |
146 | *upper_bound = DEFAULT_UPPER_BOUND; |
147 | return BOUND_FETCH_ERROR; | |
c906108c | 148 | } |
c5aa993b JM |
149 | break; |
150 | ||
c906108c SS |
151 | case BOUND_SIMPLE: |
152 | *upper_bound = TYPE_ARRAY_UPPER_BOUND_VALUE (type); | |
c5aa993b JM |
153 | break; |
154 | ||
155 | case BOUND_CANNOT_BE_DETERMINED: | |
c906108c | 156 | /* we have an assumed size array on our hands. Assume that |
c5aa993b JM |
157 | upper_bound == lower_bound so that we show at least |
158 | 1 element.If the user wants to see more elements, let | |
159 | him manually ask for 'em and we'll subscript the | |
160 | array and show him */ | |
c906108c | 161 | f77_get_dynamic_lowerbound (type, upper_bound); |
c5aa993b JM |
162 | break; |
163 | ||
c906108c | 164 | case BOUND_BY_REF_ON_STACK: |
8b36eed8 | 165 | current_frame_addr = get_frame_base (deprecated_selected_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: | |
c906108c | 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) |
c5aa993b JM |
215 | error ("Cannot obtain valid array lower bound"); |
216 | ||
217 | retcode = f77_get_dynamic_upperbound (type, &upper_bound); | |
c906108c | 218 | if (retcode == BOUND_FETCH_ERROR) |
c5aa993b JM |
219 | error ("Cannot obtain valid array upper bound"); |
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) | |
c5aa993b JM |
247 | error ("Cannot obtain dynamic upper bound"); |
248 | ||
249 | retcode = f77_get_dynamic_lowerbound (tmp_type, &lower); | |
c906108c | 250 | if (retcode == BOUND_FETCH_ERROR) |
c5aa993b JM |
251 | error ("Cannot obtain dynamic lower bound"); |
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 | ||
274 | /* Actual function which prints out F77 arrays, Valaddr == address in | |
275 | the superior. Address == the address in the inferior. */ | |
276 | ||
c5aa993b | 277 | static void |
fba45db2 KB |
278 | f77_print_array_1 (int nss, int ndimensions, struct type *type, char *valaddr, |
279 | CORE_ADDR address, struct ui_file *stream, int format, | |
280 | int deref_ref, int recurse, enum val_prettyprint pretty) | |
c906108c SS |
281 | { |
282 | int i; | |
c5aa993b | 283 | |
c906108c SS |
284 | if (nss != ndimensions) |
285 | { | |
c5aa993b | 286 | for (i = 0; i < F77_DIM_SIZE (nss); i++) |
c906108c SS |
287 | { |
288 | fprintf_filtered (stream, "( "); | |
289 | f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type), | |
c5aa993b JM |
290 | valaddr + i * F77_DIM_OFFSET (nss), |
291 | address + i * F77_DIM_OFFSET (nss), | |
292 | stream, format, deref_ref, recurse, pretty); | |
c906108c SS |
293 | fprintf_filtered (stream, ") "); |
294 | } | |
295 | } | |
296 | else | |
297 | { | |
298 | for (i = 0; (i < F77_DIM_SIZE (nss) && i < print_max); i++) | |
299 | { | |
300 | val_print (TYPE_TARGET_TYPE (type), | |
301 | valaddr + i * F77_DIM_OFFSET (ndimensions), | |
c5aa993b | 302 | 0, |
c906108c | 303 | address + i * F77_DIM_OFFSET (ndimensions), |
c5aa993b | 304 | stream, format, deref_ref, recurse, pretty); |
c906108c SS |
305 | |
306 | if (i != (F77_DIM_SIZE (nss) - 1)) | |
c5aa993b JM |
307 | fprintf_filtered (stream, ", "); |
308 | ||
c906108c SS |
309 | if (i == print_max - 1) |
310 | fprintf_filtered (stream, "..."); | |
311 | } | |
312 | } | |
313 | } | |
314 | ||
315 | /* This function gets called to print an F77 array, we set up some | |
316 | stuff and then immediately call f77_print_array_1() */ | |
317 | ||
c5aa993b | 318 | static void |
fba45db2 KB |
319 | f77_print_array (struct type *type, char *valaddr, CORE_ADDR address, |
320 | struct ui_file *stream, int format, int deref_ref, int recurse, | |
321 | enum val_prettyprint pretty) | |
c906108c | 322 | { |
c5aa993b JM |
323 | int ndimensions; |
324 | ||
325 | ndimensions = calc_f77_array_dims (type); | |
326 | ||
c906108c SS |
327 | if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0) |
328 | error ("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)", | |
329 | ndimensions, MAX_FORTRAN_DIMS); | |
c5aa993b | 330 | |
c906108c SS |
331 | /* Since F77 arrays are stored column-major, we set up an |
332 | offset table to get at the various row's elements. The | |
c5aa993b | 333 | offset table contains entries for both offset and subarray size. */ |
c906108c | 334 | |
c5aa993b JM |
335 | f77_create_arrayprint_offset_tbl (type, stream); |
336 | ||
337 | f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, format, | |
338 | deref_ref, recurse, pretty); | |
339 | } | |
c906108c | 340 | \f |
c5aa993b | 341 | |
c906108c SS |
342 | /* Print data of type TYPE located at VALADDR (within GDB), which came from |
343 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
344 | FORMAT (a letter or 0 for natural format). The data at VALADDR is in | |
345 | target byte order. | |
c5aa993b | 346 | |
c906108c SS |
347 | If the data are a string pointer, returns the number of string characters |
348 | printed. | |
c5aa993b | 349 | |
c906108c SS |
350 | If DEREF_REF is nonzero, then dereference references, otherwise just print |
351 | them like pointers. | |
c5aa993b | 352 | |
c906108c SS |
353 | The PRETTY parameter controls prettyprinting. */ |
354 | ||
355 | int | |
fba45db2 KB |
356 | f_val_print (struct type *type, char *valaddr, int embedded_offset, |
357 | CORE_ADDR address, struct ui_file *stream, int format, | |
358 | int deref_ref, int recurse, enum val_prettyprint pretty) | |
c906108c | 359 | { |
c5aa993b | 360 | register unsigned int i = 0; /* Number of characters printed */ |
c906108c SS |
361 | struct type *elttype; |
362 | LONGEST val; | |
363 | CORE_ADDR addr; | |
c5aa993b | 364 | |
c906108c SS |
365 | CHECK_TYPEDEF (type); |
366 | switch (TYPE_CODE (type)) | |
367 | { | |
c5aa993b | 368 | case TYPE_CODE_STRING: |
c906108c SS |
369 | f77_get_dynamic_length_of_aggregate (type); |
370 | LA_PRINT_STRING (stream, valaddr, TYPE_LENGTH (type), 1, 0); | |
371 | break; | |
c5aa993b | 372 | |
c906108c | 373 | case TYPE_CODE_ARRAY: |
c5aa993b JM |
374 | fprintf_filtered (stream, "("); |
375 | f77_print_array (type, valaddr, address, stream, format, | |
376 | deref_ref, recurse, pretty); | |
c906108c SS |
377 | fprintf_filtered (stream, ")"); |
378 | break; | |
379 | #if 0 | |
380 | /* Array of unspecified length: treat like pointer to first elt. */ | |
381 | valaddr = (char *) &address; | |
382 | /* FALL THROUGH */ | |
c5aa993b | 383 | #endif |
c906108c SS |
384 | case TYPE_CODE_PTR: |
385 | if (format && format != 's') | |
386 | { | |
387 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
388 | break; | |
389 | } | |
390 | else | |
391 | { | |
392 | addr = unpack_pointer (type, valaddr); | |
393 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
c5aa993b | 394 | |
c906108c SS |
395 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) |
396 | { | |
397 | /* Try to print what function it points to. */ | |
398 | print_address_demangle (addr, stream, demangle); | |
399 | /* Return value is irrelevant except for string pointers. */ | |
400 | return 0; | |
401 | } | |
c5aa993b | 402 | |
c906108c | 403 | if (addressprint && format != 's') |
d4f3574e | 404 | fprintf_filtered (stream, "0x%s", paddr_nz (addr)); |
c5aa993b | 405 | |
c906108c SS |
406 | /* For a pointer to char or unsigned char, also print the string |
407 | pointed to, unless pointer is null. */ | |
408 | if (TYPE_LENGTH (elttype) == 1 | |
409 | && TYPE_CODE (elttype) == TYPE_CODE_INT | |
410 | && (format == 0 || format == 's') | |
411 | && addr != 0) | |
412 | i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream); | |
c5aa993b | 413 | |
c906108c SS |
414 | /* Return number of characters printed, plus one for the |
415 | terminating null if we have "reached the end". */ | |
416 | return (i + (print_max && i != print_max)); | |
417 | } | |
418 | break; | |
c5aa993b | 419 | |
c906108c SS |
420 | case TYPE_CODE_FUNC: |
421 | if (format) | |
422 | { | |
423 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
424 | break; | |
425 | } | |
426 | /* FIXME, we should consider, at least for ANSI C language, eliminating | |
c5aa993b | 427 | the distinction made between FUNCs and POINTERs to FUNCs. */ |
c906108c SS |
428 | fprintf_filtered (stream, "{"); |
429 | type_print (type, "", stream, -1); | |
430 | fprintf_filtered (stream, "} "); | |
431 | /* Try to print what function it points to, and its address. */ | |
432 | print_address_demangle (address, stream, demangle); | |
433 | break; | |
c5aa993b | 434 | |
c906108c SS |
435 | case TYPE_CODE_INT: |
436 | format = format ? format : output_format; | |
437 | if (format) | |
438 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
439 | else | |
440 | { | |
441 | val_print_type_code_int (type, valaddr, stream); | |
442 | /* C and C++ has no single byte int type, char is used instead. | |
443 | Since we don't know whether the value is really intended to | |
444 | be used as an integer or a character, print the character | |
445 | equivalent as well. */ | |
446 | if (TYPE_LENGTH (type) == 1) | |
447 | { | |
448 | fputs_filtered (" ", stream); | |
449 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr), | |
450 | stream); | |
451 | } | |
452 | } | |
453 | break; | |
c5aa993b | 454 | |
c906108c SS |
455 | case TYPE_CODE_FLT: |
456 | if (format) | |
457 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
458 | else | |
459 | print_floating (valaddr, type, stream); | |
460 | break; | |
c5aa993b | 461 | |
c906108c SS |
462 | case TYPE_CODE_VOID: |
463 | fprintf_filtered (stream, "VOID"); | |
464 | break; | |
c5aa993b | 465 | |
c906108c SS |
466 | case TYPE_CODE_ERROR: |
467 | fprintf_filtered (stream, "<error type>"); | |
468 | break; | |
c5aa993b | 469 | |
c906108c SS |
470 | case TYPE_CODE_RANGE: |
471 | /* FIXME, we should not ever have to print one of these yet. */ | |
472 | fprintf_filtered (stream, "<range type>"); | |
473 | break; | |
c5aa993b | 474 | |
c906108c SS |
475 | case TYPE_CODE_BOOL: |
476 | format = format ? format : output_format; | |
477 | if (format) | |
478 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
479 | else | |
480 | { | |
c5aa993b JM |
481 | val = 0; |
482 | switch (TYPE_LENGTH (type)) | |
c906108c SS |
483 | { |
484 | case 1: | |
485 | val = unpack_long (builtin_type_f_logical_s1, valaddr); | |
c5aa993b JM |
486 | break; |
487 | ||
488 | case 2: | |
c906108c | 489 | val = unpack_long (builtin_type_f_logical_s2, valaddr); |
c5aa993b JM |
490 | break; |
491 | ||
492 | case 4: | |
c906108c | 493 | val = unpack_long (builtin_type_f_logical, valaddr); |
c5aa993b JM |
494 | break; |
495 | ||
c906108c SS |
496 | default: |
497 | error ("Logicals of length %d bytes not supported", | |
498 | TYPE_LENGTH (type)); | |
c5aa993b | 499 | |
c906108c | 500 | } |
c5aa993b JM |
501 | |
502 | if (val == 0) | |
c906108c | 503 | fprintf_filtered (stream, ".FALSE."); |
c5aa993b JM |
504 | else if (val == 1) |
505 | fprintf_filtered (stream, ".TRUE."); | |
506 | else | |
507 | /* Not a legitimate logical type, print as an integer. */ | |
508 | { | |
509 | /* Bash the type code temporarily. */ | |
510 | TYPE_CODE (type) = TYPE_CODE_INT; | |
511 | f_val_print (type, valaddr, 0, address, stream, format, | |
512 | deref_ref, recurse, pretty); | |
513 | /* Restore the type code so later uses work as intended. */ | |
514 | TYPE_CODE (type) = TYPE_CODE_BOOL; | |
515 | } | |
c906108c SS |
516 | } |
517 | break; | |
c5aa993b | 518 | |
c906108c SS |
519 | case TYPE_CODE_COMPLEX: |
520 | switch (TYPE_LENGTH (type)) | |
521 | { | |
c5aa993b JM |
522 | case 8: |
523 | type = builtin_type_f_real; | |
524 | break; | |
525 | case 16: | |
526 | type = builtin_type_f_real_s8; | |
527 | break; | |
528 | case 32: | |
529 | type = builtin_type_f_real_s16; | |
530 | break; | |
c906108c | 531 | default: |
c5aa993b | 532 | error ("Cannot print out complex*%d variables", TYPE_LENGTH (type)); |
c906108c SS |
533 | } |
534 | fputs_filtered ("(", stream); | |
535 | print_floating (valaddr, type, stream); | |
536 | fputs_filtered (",", stream); | |
9af97293 | 537 | print_floating (valaddr + TYPE_LENGTH (type), type, stream); |
c906108c SS |
538 | fputs_filtered (")", stream); |
539 | break; | |
c5aa993b | 540 | |
c906108c SS |
541 | case TYPE_CODE_UNDEF: |
542 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
c5aa993b JM |
543 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" |
544 | and no complete type for struct foo in that file. */ | |
c906108c SS |
545 | fprintf_filtered (stream, "<incomplete type>"); |
546 | break; | |
c5aa993b | 547 | |
c906108c SS |
548 | default: |
549 | error ("Invalid F77 type code %d in symbol table.", TYPE_CODE (type)); | |
550 | } | |
551 | gdb_flush (stream); | |
552 | return 0; | |
553 | } | |
554 | ||
555 | static void | |
fba45db2 | 556 | list_all_visible_commons (char *funname) |
c906108c | 557 | { |
c5aa993b JM |
558 | SAVED_F77_COMMON_PTR tmp; |
559 | ||
c906108c | 560 | tmp = head_common_list; |
c5aa993b | 561 | |
c906108c | 562 | printf_filtered ("All COMMON blocks visible at this level:\n\n"); |
c5aa993b | 563 | |
c906108c SS |
564 | while (tmp != NULL) |
565 | { | |
762f08a3 | 566 | if (strcmp (tmp->owning_function, funname) == 0) |
c5aa993b JM |
567 | printf_filtered ("%s\n", tmp->name); |
568 | ||
c906108c SS |
569 | tmp = tmp->next; |
570 | } | |
571 | } | |
572 | ||
573 | /* This function is used to print out the values in a given COMMON | |
574 | block. It will always use the most local common block of the | |
c5aa993b | 575 | given name */ |
c906108c | 576 | |
c5aa993b | 577 | static void |
fba45db2 | 578 | info_common_command (char *comname, int from_tty) |
c906108c | 579 | { |
c5aa993b JM |
580 | SAVED_F77_COMMON_PTR the_common; |
581 | COMMON_ENTRY_PTR entry; | |
c906108c SS |
582 | struct frame_info *fi; |
583 | register char *funname = 0; | |
584 | struct symbol *func; | |
c5aa993b | 585 | |
c906108c SS |
586 | /* We have been told to display the contents of F77 COMMON |
587 | block supposedly visible in this function. Let us | |
588 | first make sure that it is visible and if so, let | |
c5aa993b JM |
589 | us display its contents */ |
590 | ||
6e7f8b9c | 591 | fi = deprecated_selected_frame; |
c5aa993b | 592 | |
c906108c | 593 | if (fi == NULL) |
c5aa993b JM |
594 | error ("No frame selected"); |
595 | ||
c906108c | 596 | /* The following is generally ripped off from stack.c's routine |
c5aa993b JM |
597 | print_frame_info() */ |
598 | ||
bdd78e62 | 599 | func = find_pc_function (get_frame_pc (fi)); |
c906108c SS |
600 | if (func) |
601 | { | |
602 | /* In certain pathological cases, the symtabs give the wrong | |
c5aa993b JM |
603 | function (when we are in the first function in a file which |
604 | is compiled without debugging symbols, the previous function | |
605 | is compiled with debugging symbols, and the "foo.o" symbol | |
606 | that is supposed to tell us where the file with debugging symbols | |
607 | ends has been truncated by ar because it is longer than 15 | |
608 | characters). | |
609 | ||
610 | So look in the minimal symbol tables as well, and if it comes | |
611 | up with a larger address for the function use that instead. | |
612 | I don't think this can ever cause any problems; there shouldn't | |
613 | be any minimal symbols in the middle of a function. | |
614 | FIXME: (Not necessarily true. What about text labels) */ | |
615 | ||
bdd78e62 | 616 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi)); |
c5aa993b | 617 | |
c906108c | 618 | if (msymbol != NULL |
c5aa993b | 619 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
c906108c | 620 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
22abf04a | 621 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 622 | else |
22abf04a | 623 | funname = DEPRECATED_SYMBOL_NAME (func); |
c906108c SS |
624 | } |
625 | else | |
626 | { | |
627 | register struct minimal_symbol *msymbol = | |
bdd78e62 | 628 | lookup_minimal_symbol_by_pc (get_frame_pc (fi)); |
c5aa993b | 629 | |
c906108c | 630 | if (msymbol != NULL) |
22abf04a | 631 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 632 | } |
c5aa993b | 633 | |
c906108c | 634 | /* If comname is NULL, we assume the user wishes to see the |
c5aa993b JM |
635 | which COMMON blocks are visible here and then return */ |
636 | ||
c906108c SS |
637 | if (comname == 0) |
638 | { | |
639 | list_all_visible_commons (funname); | |
c5aa993b | 640 | return; |
c906108c | 641 | } |
c5aa993b JM |
642 | |
643 | the_common = find_common_for_function (comname, funname); | |
644 | ||
c906108c SS |
645 | if (the_common) |
646 | { | |
762f08a3 | 647 | if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0) |
c906108c | 648 | printf_filtered ("Contents of blank COMMON block:\n"); |
c5aa993b JM |
649 | else |
650 | printf_filtered ("Contents of F77 COMMON block '%s':\n", comname); | |
651 | ||
652 | printf_filtered ("\n"); | |
653 | entry = the_common->entries; | |
654 | ||
c906108c SS |
655 | while (entry != NULL) |
656 | { | |
22abf04a | 657 | printf_filtered ("%s = ", DEPRECATED_SYMBOL_NAME (entry->symbol)); |
c5aa993b JM |
658 | print_variable_value (entry->symbol, fi, gdb_stdout); |
659 | printf_filtered ("\n"); | |
660 | entry = entry->next; | |
c906108c SS |
661 | } |
662 | } | |
c5aa993b | 663 | else |
c906108c | 664 | printf_filtered ("Cannot locate the common block %s in function '%s'\n", |
c5aa993b | 665 | comname, funname); |
c906108c SS |
666 | } |
667 | ||
668 | /* This function is used to determine whether there is a | |
c5aa993b | 669 | F77 common block visible at the current scope called 'comname'. */ |
c906108c SS |
670 | |
671 | #if 0 | |
672 | static int | |
fba45db2 | 673 | there_is_a_visible_common_named (char *comname) |
c906108c | 674 | { |
c5aa993b | 675 | SAVED_F77_COMMON_PTR the_common; |
c906108c SS |
676 | struct frame_info *fi; |
677 | register char *funname = 0; | |
678 | struct symbol *func; | |
c5aa993b | 679 | |
c906108c | 680 | if (comname == NULL) |
c5aa993b JM |
681 | error ("Cannot deal with NULL common name!"); |
682 | ||
6e7f8b9c | 683 | fi = deprecated_selected_frame; |
c5aa993b | 684 | |
c906108c | 685 | if (fi == NULL) |
c5aa993b JM |
686 | error ("No frame selected"); |
687 | ||
c906108c | 688 | /* The following is generally ripped off from stack.c's routine |
c5aa993b JM |
689 | print_frame_info() */ |
690 | ||
c906108c SS |
691 | func = find_pc_function (fi->pc); |
692 | if (func) | |
693 | { | |
694 | /* In certain pathological cases, the symtabs give the wrong | |
c5aa993b JM |
695 | function (when we are in the first function in a file which |
696 | is compiled without debugging symbols, the previous function | |
697 | is compiled with debugging symbols, and the "foo.o" symbol | |
698 | that is supposed to tell us where the file with debugging symbols | |
699 | ends has been truncated by ar because it is longer than 15 | |
700 | characters). | |
701 | ||
702 | So look in the minimal symbol tables as well, and if it comes | |
703 | up with a larger address for the function use that instead. | |
704 | I don't think this can ever cause any problems; there shouldn't | |
705 | be any minimal symbols in the middle of a function. | |
706 | FIXME: (Not necessarily true. What about text labels) */ | |
707 | ||
c906108c | 708 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); |
c5aa993b | 709 | |
c906108c | 710 | if (msymbol != NULL |
c5aa993b | 711 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
c906108c | 712 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
22abf04a | 713 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 714 | else |
22abf04a | 715 | funname = DEPRECATED_SYMBOL_NAME (func); |
c906108c SS |
716 | } |
717 | else | |
718 | { | |
c5aa993b JM |
719 | register struct minimal_symbol *msymbol = |
720 | lookup_minimal_symbol_by_pc (fi->pc); | |
721 | ||
c906108c | 722 | if (msymbol != NULL) |
22abf04a | 723 | funname = DEPRECATED_SYMBOL_NAME (msymbol); |
c906108c | 724 | } |
c5aa993b JM |
725 | |
726 | the_common = find_common_for_function (comname, funname); | |
727 | ||
c906108c SS |
728 | return (the_common ? 1 : 0); |
729 | } | |
730 | #endif | |
731 | ||
732 | void | |
fba45db2 | 733 | _initialize_f_valprint (void) |
c906108c SS |
734 | { |
735 | add_info ("common", info_common_command, | |
736 | "Print out the values contained in a Fortran COMMON block."); | |
737 | if (xdb_commands) | |
c5aa993b JM |
738 | add_com ("lc", class_info, info_common_command, |
739 | "Print out the values contained in a Fortran COMMON block."); | |
c906108c | 740 | } |