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