GDB (API)
|
00001 /* Support for printing Fortran types for GDB, the GNU debugger. 00002 00003 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00004 00005 Contributed by Motorola. Adapted from the C version by Farooq Butt 00006 (fmbutt@engage.sps.mot.com). 00007 00008 This file is part of GDB. 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00022 00023 #include "defs.h" 00024 #include "gdb_obstack.h" 00025 #include "bfd.h" 00026 #include "symtab.h" 00027 #include "gdbtypes.h" 00028 #include "expression.h" 00029 #include "value.h" 00030 #include "gdbcore.h" 00031 #include "target.h" 00032 #include "f-lang.h" 00033 00034 #include "gdb_string.h" 00035 #include <errno.h> 00036 00037 #if 0 /* Currently unused. */ 00038 static void f_type_print_args (struct type *, struct ui_file *); 00039 #endif 00040 00041 static void f_type_print_varspec_suffix (struct type *, struct ui_file *, int, 00042 int, int, int); 00043 00044 void f_type_print_varspec_prefix (struct type *, struct ui_file *, 00045 int, int); 00046 00047 void f_type_print_base (struct type *, struct ui_file *, int, int); 00048 00049 00050 /* LEVEL is the depth to indent lines by. */ 00051 00052 void 00053 f_print_type (struct type *type, const char *varstring, struct ui_file *stream, 00054 int show, int level, const struct type_print_options *flags) 00055 { 00056 enum type_code code; 00057 int demangled_args; 00058 00059 f_type_print_base (type, stream, show, level); 00060 code = TYPE_CODE (type); 00061 if ((varstring != NULL && *varstring != '\0') 00062 /* Need a space if going to print stars or brackets; 00063 but not if we will print just a type name. */ 00064 || ((show > 0 || TYPE_NAME (type) == 0) 00065 && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC 00066 || code == TYPE_CODE_METHOD 00067 || code == TYPE_CODE_ARRAY 00068 || code == TYPE_CODE_REF))) 00069 fputs_filtered (" ", stream); 00070 f_type_print_varspec_prefix (type, stream, show, 0); 00071 00072 if (varstring != NULL) 00073 { 00074 fputs_filtered (varstring, stream); 00075 00076 /* For demangled function names, we have the arglist as part of the name, 00077 so don't print an additional pair of ()'s. */ 00078 00079 demangled_args = varstring[strlen (varstring) - 1] == ')'; 00080 f_type_print_varspec_suffix (type, stream, show, 0, demangled_args, 0); 00081 } 00082 } 00083 00084 /* Print any asterisks or open-parentheses needed before the 00085 variable name (to describe its type). 00086 00087 On outermost call, pass 0 for PASSED_A_PTR. 00088 On outermost call, SHOW > 0 means should ignore 00089 any typename for TYPE and show its details. 00090 SHOW is always zero on recursive calls. */ 00091 00092 void 00093 f_type_print_varspec_prefix (struct type *type, struct ui_file *stream, 00094 int show, int passed_a_ptr) 00095 { 00096 if (type == 0) 00097 return; 00098 00099 if (TYPE_NAME (type) && show <= 0) 00100 return; 00101 00102 QUIT; 00103 00104 switch (TYPE_CODE (type)) 00105 { 00106 case TYPE_CODE_PTR: 00107 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); 00108 break; 00109 00110 case TYPE_CODE_FUNC: 00111 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); 00112 if (passed_a_ptr) 00113 fprintf_filtered (stream, "("); 00114 break; 00115 00116 case TYPE_CODE_ARRAY: 00117 f_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0); 00118 break; 00119 00120 case TYPE_CODE_UNDEF: 00121 case TYPE_CODE_STRUCT: 00122 case TYPE_CODE_UNION: 00123 case TYPE_CODE_ENUM: 00124 case TYPE_CODE_INT: 00125 case TYPE_CODE_FLT: 00126 case TYPE_CODE_VOID: 00127 case TYPE_CODE_ERROR: 00128 case TYPE_CODE_CHAR: 00129 case TYPE_CODE_BOOL: 00130 case TYPE_CODE_SET: 00131 case TYPE_CODE_RANGE: 00132 case TYPE_CODE_STRING: 00133 case TYPE_CODE_METHOD: 00134 case TYPE_CODE_REF: 00135 case TYPE_CODE_COMPLEX: 00136 case TYPE_CODE_TYPEDEF: 00137 /* These types need no prefix. They are listed here so that 00138 gcc -Wall will reveal any types that haven't been handled. */ 00139 break; 00140 } 00141 } 00142 00143 /* Print any array sizes, function arguments or close parentheses 00144 needed after the variable name (to describe its type). 00145 Args work like c_type_print_varspec_prefix. */ 00146 00147 static void 00148 f_type_print_varspec_suffix (struct type *type, struct ui_file *stream, 00149 int show, int passed_a_ptr, int demangled_args, 00150 int arrayprint_recurse_level) 00151 { 00152 int upper_bound, lower_bound; 00153 00154 /* No static variables are permitted as an error call may occur during 00155 execution of this function. */ 00156 00157 if (type == 0) 00158 return; 00159 00160 if (TYPE_NAME (type) && show <= 0) 00161 return; 00162 00163 QUIT; 00164 00165 switch (TYPE_CODE (type)) 00166 { 00167 case TYPE_CODE_ARRAY: 00168 arrayprint_recurse_level++; 00169 00170 if (arrayprint_recurse_level == 1) 00171 fprintf_filtered (stream, "("); 00172 00173 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY) 00174 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0, 00175 arrayprint_recurse_level); 00176 00177 lower_bound = f77_get_lowerbound (type); 00178 if (lower_bound != 1) /* Not the default. */ 00179 fprintf_filtered (stream, "%d:", lower_bound); 00180 00181 /* Make sure that, if we have an assumed size array, we 00182 print out a warning and print the upperbound as '*'. */ 00183 00184 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) 00185 fprintf_filtered (stream, "*"); 00186 else 00187 { 00188 upper_bound = f77_get_upperbound (type); 00189 fprintf_filtered (stream, "%d", upper_bound); 00190 } 00191 00192 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY) 00193 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0, 00194 arrayprint_recurse_level); 00195 if (arrayprint_recurse_level == 1) 00196 fprintf_filtered (stream, ")"); 00197 else 00198 fprintf_filtered (stream, ","); 00199 arrayprint_recurse_level--; 00200 break; 00201 00202 case TYPE_CODE_PTR: 00203 case TYPE_CODE_REF: 00204 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0, 00205 arrayprint_recurse_level); 00206 fprintf_filtered (stream, ")"); 00207 break; 00208 00209 case TYPE_CODE_FUNC: 00210 f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 00211 passed_a_ptr, 0, arrayprint_recurse_level); 00212 if (passed_a_ptr) 00213 fprintf_filtered (stream, ")"); 00214 00215 fprintf_filtered (stream, "()"); 00216 break; 00217 00218 case TYPE_CODE_UNDEF: 00219 case TYPE_CODE_STRUCT: 00220 case TYPE_CODE_UNION: 00221 case TYPE_CODE_ENUM: 00222 case TYPE_CODE_INT: 00223 case TYPE_CODE_FLT: 00224 case TYPE_CODE_VOID: 00225 case TYPE_CODE_ERROR: 00226 case TYPE_CODE_CHAR: 00227 case TYPE_CODE_BOOL: 00228 case TYPE_CODE_SET: 00229 case TYPE_CODE_RANGE: 00230 case TYPE_CODE_STRING: 00231 case TYPE_CODE_METHOD: 00232 case TYPE_CODE_COMPLEX: 00233 case TYPE_CODE_TYPEDEF: 00234 /* These types do not need a suffix. They are listed so that 00235 gcc -Wall will report types that may not have been considered. */ 00236 break; 00237 } 00238 } 00239 00240 /* Print the name of the type (or the ultimate pointer target, 00241 function value or array element), or the description of a 00242 structure or union. 00243 00244 SHOW nonzero means don't print this type as just its name; 00245 show its real definition even if it has a name. 00246 SHOW zero means print just typename or struct tag if there is one 00247 SHOW negative means abbreviate structure elements. 00248 SHOW is decremented for printing of structure elements. 00249 00250 LEVEL is the depth to indent by. 00251 We increase it for some recursive calls. */ 00252 00253 void 00254 f_type_print_base (struct type *type, struct ui_file *stream, int show, 00255 int level) 00256 { 00257 int upper_bound; 00258 int index; 00259 00260 QUIT; 00261 00262 wrap_here (" "); 00263 if (type == NULL) 00264 { 00265 fputs_filtered ("<type unknown>", stream); 00266 return; 00267 } 00268 00269 /* When SHOW is zero or less, and there is a valid type name, then always 00270 just print the type name directly from the type. */ 00271 00272 if ((show <= 0) && (TYPE_NAME (type) != NULL)) 00273 { 00274 fputs_filtered (TYPE_NAME (type), stream); 00275 return; 00276 } 00277 00278 if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF) 00279 CHECK_TYPEDEF (type); 00280 00281 switch (TYPE_CODE (type)) 00282 { 00283 case TYPE_CODE_TYPEDEF: 00284 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); 00285 break; 00286 00287 case TYPE_CODE_ARRAY: 00288 case TYPE_CODE_FUNC: 00289 f_type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); 00290 break; 00291 00292 case TYPE_CODE_PTR: 00293 fprintf_filtered (stream, "PTR TO -> ( "); 00294 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); 00295 break; 00296 00297 case TYPE_CODE_REF: 00298 fprintf_filtered (stream, "REF TO -> ( "); 00299 f_type_print_base (TYPE_TARGET_TYPE (type), stream, 0, level); 00300 break; 00301 00302 case TYPE_CODE_VOID: 00303 fprintfi_filtered (level, stream, "VOID"); 00304 break; 00305 00306 case TYPE_CODE_UNDEF: 00307 fprintfi_filtered (level, stream, "struct <unknown>"); 00308 break; 00309 00310 case TYPE_CODE_ERROR: 00311 fprintfi_filtered (level, stream, "%s", TYPE_ERROR_NAME (type)); 00312 break; 00313 00314 case TYPE_CODE_RANGE: 00315 /* This should not occur. */ 00316 fprintfi_filtered (level, stream, "<range type>"); 00317 break; 00318 00319 case TYPE_CODE_CHAR: 00320 case TYPE_CODE_INT: 00321 /* There may be some character types that attempt to come 00322 through as TYPE_CODE_INT since dbxstclass.h is so 00323 C-oriented, we must change these to "character" from "char". */ 00324 00325 if (strcmp (TYPE_NAME (type), "char") == 0) 00326 fprintfi_filtered (level, stream, "character"); 00327 else 00328 goto default_case; 00329 break; 00330 00331 case TYPE_CODE_STRING: 00332 /* Strings may have dynamic upperbounds (lengths) like arrays. */ 00333 00334 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)) 00335 fprintfi_filtered (level, stream, "character*(*)"); 00336 else 00337 { 00338 upper_bound = f77_get_upperbound (type); 00339 fprintf_filtered (stream, "character*%d", upper_bound); 00340 } 00341 break; 00342 00343 case TYPE_CODE_STRUCT: 00344 case TYPE_CODE_UNION: 00345 if (TYPE_CODE (type) == TYPE_CODE_UNION) 00346 fprintfi_filtered (level, stream, "Type, C_Union :: "); 00347 else 00348 fprintfi_filtered (level, stream, "Type "); 00349 fputs_filtered (TYPE_TAG_NAME (type), stream); 00350 fputs_filtered ("\n", stream); 00351 for (index = 0; index < TYPE_NFIELDS (type); index++) 00352 { 00353 f_type_print_base (TYPE_FIELD_TYPE (type, index), stream, show, 00354 level + 4); 00355 fputs_filtered (" :: ", stream); 00356 fputs_filtered (TYPE_FIELD_NAME (type, index), stream); 00357 f_type_print_varspec_suffix (TYPE_FIELD_TYPE (type, index), 00358 stream, 0, 0, 0, 0); 00359 fputs_filtered ("\n", stream); 00360 } 00361 fprintfi_filtered (level, stream, "End Type "); 00362 fputs_filtered (TYPE_TAG_NAME (type), stream); 00363 break; 00364 00365 case TYPE_CODE_MODULE: 00366 fprintfi_filtered (level, stream, "module %s", TYPE_TAG_NAME (type)); 00367 break; 00368 00369 default_case: 00370 default: 00371 /* Handle types not explicitly handled by the other cases, 00372 such as fundamental types. For these, just print whatever 00373 the type name is, as recorded in the type itself. If there 00374 is no type name, then complain. */ 00375 if (TYPE_NAME (type) != NULL) 00376 fprintfi_filtered (level, stream, "%s", TYPE_NAME (type)); 00377 else 00378 error (_("Invalid type code (%d) in symbol table."), TYPE_CODE (type)); 00379 break; 00380 } 00381 }