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