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