1 /* Multiple source language support for GDB.
2 Copyright 1991, 1992 Free Software Foundation, Inc.
3 Contributed by the Department of Computer Science at the State University
4 of New York at Buffalo.
6 This file is part of GDB.
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.
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.
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. */
23 /* This file contains functions that return things that are specific
24 to languages. Each function should examine current_language if necessary,
25 and return the appropriate result. */
27 /* FIXME: Most of these would be better organized as macros which
28 return data out of a "language-specific" struct pointer that is set
29 whenever the working language changes. That would be a lot faster. */
33 #include "gdb_string.h"
40 #include "expression.h"
43 #include "parser-defs.h"
45 extern void _initialize_language
PARAMS ((void));
48 show_language_command
PARAMS ((char *, int));
51 set_language_command
PARAMS ((char *, int));
54 show_type_command
PARAMS ((char *, int));
57 set_type_command
PARAMS ((char *, int));
60 show_range_command
PARAMS ((char *, int));
63 set_range_command
PARAMS ((char *, int));
66 set_range_str
PARAMS ((void));
69 set_type_str
PARAMS ((void));
72 set_lang_str
PARAMS ((void));
75 unk_lang_error
PARAMS ((char *));
78 unk_lang_parser
PARAMS ((void));
81 show_check
PARAMS ((char *, int));
84 set_check
PARAMS ((char *, int));
87 set_type_range
PARAMS ((void));
90 unk_lang_emit_char
PARAMS ((int c
, GDB_FILE
* stream
, int quoter
));
93 unk_lang_printchar
PARAMS ((int c
, GDB_FILE
* stream
));
96 unk_lang_printstr
PARAMS ((GDB_FILE
* stream
, char *string
, unsigned int length
, int width
, int force_ellipses
));
99 unk_lang_create_fundamental_type
PARAMS ((struct objfile
*, int));
102 unk_lang_print_type
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int));
105 unk_lang_val_print
PARAMS ((struct type
*, char *, int, CORE_ADDR
, GDB_FILE
*,
106 int, int, int, enum val_prettyprint
));
109 unk_lang_value_print
PARAMS ((value_ptr
, GDB_FILE
*, int, enum val_prettyprint
));
111 /* Forward declaration */
112 extern const struct language_defn unknown_language_defn
;
113 extern char *warning_pre_print
;
115 /* The current (default at startup) state of type and range checking.
116 (If the modes are set to "auto", though, these are changed based
117 on the default language at startup, and then again based on the
118 language of the first source file. */
120 enum range_mode range_mode
= range_mode_auto
;
121 enum range_check range_check
= range_check_off
;
122 enum type_mode type_mode
= type_mode_auto
;
123 enum type_check type_check
= type_check_off
;
125 /* The current language and language_mode (see language.h) */
127 const struct language_defn
*current_language
= &unknown_language_defn
;
128 enum language_mode language_mode
= language_mode_auto
;
130 /* The language that the user expects to be typing in (the language
131 of main(), or the last language we notified them about, or C). */
133 const struct language_defn
*expected_language
;
135 /* The list of supported languages. The list itself is malloc'd. */
137 static const struct language_defn
**languages
;
138 static unsigned languages_size
;
139 static unsigned languages_allocsize
;
140 #define DEFAULT_ALLOCSIZE 4
142 /* The "set language/type/range" commands all put stuff in these
143 buffers. This is to make them work as set/show commands. The
144 user's string is copied here, then the set_* commands look at
145 them and update them to something that looks nice when it is
148 static char *language
;
152 /* Warning issued when current_language and the language of the current
153 frame do not match. */
154 char lang_frame_mismatch_warn
[] =
155 "Warning: the current language does not match this frame.";
158 /* This page contains the functions corresponding to GDB commands
159 and their helpers. */
161 /* Show command. Display a warning if the language set
162 does not match the frame. */
164 show_language_command (ignore
, from_tty
)
168 enum language flang
; /* The language of the current frame */
170 flang
= get_frame_language ();
171 if (flang
!= language_unknown
&&
172 language_mode
== language_mode_manual
&&
173 current_language
->la_language
!= flang
)
174 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
177 /* Set command. Change the current working language. */
179 set_language_command (ignore
, from_tty
)
187 if (!language
|| !language
[0])
189 printf_unfiltered ("The currently understood settings are:\n\n");
190 printf_unfiltered ("local or auto Automatic setting based on source file\n");
192 for (i
= 0; i
< languages_size
; ++i
)
194 /* Already dealt with these above. */
195 if (languages
[i
]->la_language
== language_unknown
196 || languages
[i
]->la_language
== language_auto
)
199 /* FIXME for now assume that the human-readable name is just
200 a capitalization of the internal name. */
201 printf_unfiltered ("%-16s Use the %c%s language\n",
202 languages
[i
]->la_name
,
203 /* Capitalize first letter of language
205 toupper (languages
[i
]->la_name
[0]),
206 languages
[i
]->la_name
+ 1);
208 /* Restore the silly string. */
209 set_language (current_language
->la_language
);
213 /* Search the list of languages for a match. */
214 for (i
= 0; i
< languages_size
; i
++)
216 if (STREQ (languages
[i
]->la_name
, language
))
218 /* Found it! Go into manual mode, and use this language. */
219 if (languages
[i
]->la_language
== language_auto
)
221 /* Enter auto mode. Set to the current frame's language, if known. */
222 language_mode
= language_mode_auto
;
223 flang
= get_frame_language ();
224 if (flang
!= language_unknown
)
225 set_language (flang
);
226 expected_language
= current_language
;
231 /* Enter manual mode. Set the specified language. */
232 language_mode
= language_mode_manual
;
233 current_language
= languages
[i
];
236 expected_language
= current_language
;
242 /* Reset the language (esp. the global string "language") to the
244 err_lang
= savestring (language
, strlen (language
));
245 make_cleanup (free
, err_lang
); /* Free it after error */
246 set_language (current_language
->la_language
);
247 error ("Unknown language `%s'.", err_lang
);
250 /* Show command. Display a warning if the type setting does
251 not match the current language. */
253 show_type_command (ignore
, from_tty
)
257 if (type_check
!= current_language
->la_type_check
)
259 "Warning: the current type check setting does not match the language.\n");
262 /* Set command. Change the setting for type checking. */
264 set_type_command (ignore
, from_tty
)
268 if (STREQ (type
, "on"))
270 type_check
= type_check_on
;
271 type_mode
= type_mode_manual
;
273 else if (STREQ (type
, "warn"))
275 type_check
= type_check_warn
;
276 type_mode
= type_mode_manual
;
278 else if (STREQ (type
, "off"))
280 type_check
= type_check_off
;
281 type_mode
= type_mode_manual
;
283 else if (STREQ (type
, "auto"))
285 type_mode
= type_mode_auto
;
287 /* Avoid hitting the set_type_str call below. We
288 did it in set_type_range. */
292 show_type_command ((char *) NULL
, from_tty
);
295 /* Show command. Display a warning if the range setting does
296 not match the current language. */
298 show_range_command (ignore
, from_tty
)
303 if (range_check
!= current_language
->la_range_check
)
305 "Warning: the current range check setting does not match the language.\n");
308 /* Set command. Change the setting for range checking. */
310 set_range_command (ignore
, from_tty
)
314 if (STREQ (range
, "on"))
316 range_check
= range_check_on
;
317 range_mode
= range_mode_manual
;
319 else if (STREQ (range
, "warn"))
321 range_check
= range_check_warn
;
322 range_mode
= range_mode_manual
;
324 else if (STREQ (range
, "off"))
326 range_check
= range_check_off
;
327 range_mode
= range_mode_manual
;
329 else if (STREQ (range
, "auto"))
331 range_mode
= range_mode_auto
;
333 /* Avoid hitting the set_range_str call below. We
334 did it in set_type_range. */
338 show_range_command ((char *) 0, from_tty
);
341 /* Set the status of range and type checking based on
342 the current modes and the current language.
343 If SHOW is non-zero, then print out the current language,
344 type and range checking status. */
349 if (range_mode
== range_mode_auto
)
350 range_check
= current_language
->la_range_check
;
352 if (type_mode
== type_mode_auto
)
353 type_check
= current_language
->la_type_check
;
359 /* Set current language to (enum language) LANG. Returns previous language. */
366 enum language prev_language
;
368 prev_language
= current_language
->la_language
;
370 for (i
= 0; i
< languages_size
; i
++)
372 if (languages
[i
]->la_language
== lang
)
374 current_language
= languages
[i
];
381 return prev_language
;
384 /* This page contains functions that update the global vars
385 language, type and range. */
392 if (language_mode
== language_mode_auto
)
393 prefix
= "auto; currently ";
395 language
= concat (prefix
, current_language
->la_name
, NULL
);
401 char *tmp
, *prefix
= "";
404 if (type_mode
== type_mode_auto
)
405 prefix
= "auto; currently ";
415 case type_check_warn
:
419 error ("Unrecognized type check setting.");
422 type
= concat (prefix
, tmp
, NULL
);
428 char *tmp
, *pref
= "";
431 if (range_mode
== range_mode_auto
)
432 pref
= "auto; currently ";
439 case range_check_off
:
442 case range_check_warn
:
446 error ("Unrecognized range check setting.");
449 range
= concat (pref
, tmp
, NULL
);
453 /* Print out the current language settings: language, range and
454 type checking. If QUIETLY, print only what has changed. */
457 language_info (quietly
)
460 if (quietly
&& expected_language
== current_language
)
463 expected_language
= current_language
;
464 printf_unfiltered ("Current language: %s\n", language
);
465 show_language_command ((char *) 0, 1);
469 printf_unfiltered ("Type checking: %s\n", type
);
470 show_type_command ((char *) 0, 1);
471 printf_unfiltered ("Range checking: %s\n", range
);
472 show_range_command ((char *) 0, 1);
476 /* Return the result of a binary operation. */
478 #if 0 /* Currently unused */
481 binop_result_type (v1
, v2
)
485 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
486 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
488 int l1
= TYPE_LENGTH (t1
);
489 int l2
= TYPE_LENGTH (t2
);
491 switch (current_language
->la_language
)
495 if (TYPE_CODE (t1
) == TYPE_CODE_FLT
)
496 return TYPE_CODE (t2
) == TYPE_CODE_FLT
&& l2
> l1
?
497 VALUE_TYPE (v2
) : VALUE_TYPE (v1
);
498 else if (TYPE_CODE (t2
) == TYPE_CODE_FLT
)
499 return TYPE_CODE (t1
) == TYPE_CODE_FLT
&& l1
> l2
?
500 VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
501 else if (TYPE_UNSIGNED (t1
) && l1
> l2
)
502 return VALUE_TYPE (v1
);
503 else if (TYPE_UNSIGNED (t2
) && l2
> l1
)
504 return VALUE_TYPE (v2
);
505 else /* Both are signed. Result is the longer type */
506 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
509 /* If we are doing type-checking, l1 should equal l2, so this is
511 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
514 error ("Missing Chill support in function binop_result_check."); /*FIXME */
517 return (struct type
*) 0; /* For lint */
523 /* This page contains functions that return format strings for
524 printf for printing out numbers in different formats */
526 /* Returns the appropriate printf format for hexadecimal
529 local_hex_format_custom (pre
)
532 static char form
[50];
534 strcpy (form
, local_hex_format_prefix ());
537 strcat (form
, local_hex_format_specifier ());
538 strcat (form
, local_hex_format_suffix ());
542 /* Converts a number to hexadecimal and stores it in a static
543 string. Returns a pointer to this string. */
545 local_hex_string (num
)
550 sprintf (res
, local_hex_format (), num
);
554 /* Converts a number to custom hexadecimal and stores it in a static
555 string. Returns a pointer to this string. */
557 local_hex_string_custom (num
, pre
)
563 sprintf (res
, local_hex_format_custom (pre
), num
);
567 /* Returns the appropriate printf format for octal
570 local_octal_format_custom (pre
)
573 static char form
[50];
575 strcpy (form
, local_octal_format_prefix ());
578 strcat (form
, local_octal_format_specifier ());
579 strcat (form
, local_octal_format_suffix ());
583 /* Returns the appropriate printf format for decimal numbers. */
585 local_decimal_format_custom (pre
)
588 static char form
[50];
590 strcpy (form
, local_decimal_format_prefix ());
593 strcat (form
, local_decimal_format_specifier ());
594 strcat (form
, local_decimal_format_suffix ());
599 /* This page contains functions that are used in type/range checking.
600 They all return zero if the type/range check fails.
602 It is hoped that these will make extending GDB to parse different
603 languages a little easier. These are primarily used in eval.c when
604 evaluating expressions and making sure that their types are correct.
605 Instead of having a mess of conjucted/disjuncted expressions in an "if",
606 the ideas of type can be wrapped up in the following functions.
608 Note that some of them are not currently dependent upon which language
609 is currently being parsed. For example, floats are the same in
610 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
611 TYPE_CODE_FLT), while booleans are different. */
613 /* Returns non-zero if its argument is a simple type. This is the same for
614 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
615 and thus will never cause the failure of the test. */
620 CHECK_TYPEDEF (type
);
621 switch (TYPE_CODE (type
))
627 case TYPE_CODE_RANGE
:
636 /* Returns non-zero if its argument is of an ordered type.
637 An ordered type is one in which the elements can be tested for the
638 properties of "greater than", "less than", etc, or for which the
639 operations "increment" or "decrement" make sense. */
644 CHECK_TYPEDEF (type
);
645 switch (TYPE_CODE (type
))
651 case TYPE_CODE_RANGE
:
659 /* Returns non-zero if the two types are the same */
661 same_type (arg1
, arg2
)
662 struct type
*arg1
, *arg2
;
664 CHECK_TYPEDEF (type
);
665 if (structured_type (arg1
) ? !structured_type (arg2
) : structured_type (arg2
))
666 /* One is structured and one isn't */
668 else if (structured_type (arg1
) && structured_type (arg2
))
670 else if (numeric_type (arg1
) && numeric_type (arg2
))
671 return (TYPE_CODE (arg2
) == TYPE_CODE (arg1
)) &&
672 (TYPE_UNSIGNED (arg1
) == TYPE_UNSIGNED (arg2
))
678 /* Returns non-zero if the type is integral */
683 CHECK_TYPEDEF (type
);
684 switch (current_language
->la_language
)
688 return (TYPE_CODE (type
) != TYPE_CODE_INT
) &&
689 (TYPE_CODE (type
) != TYPE_CODE_ENUM
) ? 0 : 1;
691 return TYPE_CODE (type
) != TYPE_CODE_INT
? 0 : 1;
693 error ("Missing Chill support in function integral_type."); /*FIXME */
695 error ("Language not supported.");
699 /* Returns non-zero if the value is numeric */
704 CHECK_TYPEDEF (type
);
705 switch (TYPE_CODE (type
))
716 /* Returns non-zero if the value is a character type */
718 character_type (type
)
721 CHECK_TYPEDEF (type
);
722 switch (current_language
->la_language
)
726 return TYPE_CODE (type
) != TYPE_CODE_CHAR
? 0 : 1;
730 return (TYPE_CODE (type
) == TYPE_CODE_INT
) &&
731 TYPE_LENGTH (type
) == sizeof (char)
738 /* Returns non-zero if the value is a string type */
743 CHECK_TYPEDEF (type
);
744 switch (current_language
->la_language
)
748 return TYPE_CODE (type
) != TYPE_CODE_STRING
? 0 : 1;
752 /* C does not have distinct string type. */
759 /* Returns non-zero if the value is a boolean type */
764 CHECK_TYPEDEF (type
);
765 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
767 switch (current_language
->la_language
)
771 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
772 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
773 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
781 /* Returns non-zero if the value is a floating-point type */
786 CHECK_TYPEDEF (type
);
787 return TYPE_CODE (type
) == TYPE_CODE_FLT
;
790 /* Returns non-zero if the value is a pointer type */
795 return TYPE_CODE (type
) == TYPE_CODE_PTR
||
796 TYPE_CODE (type
) == TYPE_CODE_REF
;
799 /* Returns non-zero if the value is a structured type */
801 structured_type (type
)
804 CHECK_TYPEDEF (type
);
805 switch (current_language
->la_language
)
809 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
810 (TYPE_CODE (type
) == TYPE_CODE_UNION
) ||
811 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
813 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
814 (TYPE_CODE (type
) == TYPE_CODE_SET
) ||
815 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
817 error ("Missing Chill support in function structured_type."); /*FIXME */
829 switch (current_language
->la_language
)
832 return builtin_type_chill_bool
;
833 case language_fortran
:
834 sym
= lookup_symbol ("logical", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
837 type
= SYMBOL_TYPE (sym
);
838 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
841 return builtin_type_f_logical_s2
;
843 sym
= lookup_symbol ("bool", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
846 type
= SYMBOL_TYPE (sym
);
847 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
850 return builtin_type_bool
;
852 return builtin_type_int
;
856 /* This page contains functions that return info about
857 (struct value) values used in GDB. */
859 /* Returns non-zero if the value VAL represents a true value. */
864 /* It is possible that we should have some sort of error if a non-boolean
865 value is used in this context. Possibly dependent on some kind of
866 "boolean-checking" option like range checking. But it should probably
867 not depend on the language except insofar as is necessary to identify
868 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
869 should be an error, probably). */
870 return !value_logical_not (val
);
873 /* Returns non-zero if the operator OP is defined on
874 the values ARG1 and ARG2. */
876 #if 0 /* Currently unused */
879 binop_type_check (arg1
, arg2
, op
)
880 value_ptr arg1
, arg2
;
883 struct type
*t1
, *t2
;
885 /* If we're not checking types, always return success. */
889 t1
= VALUE_TYPE (arg1
);
891 t2
= VALUE_TYPE (arg2
);
899 if ((numeric_type (t1
) && pointer_type (t2
)) ||
900 (pointer_type (t1
) && numeric_type (t2
)))
902 warning ("combining pointer and integer.\n");
908 if (!numeric_type (t1
) || !numeric_type (t2
))
909 type_op_error ("Arguments to %s must be numbers.", op
);
910 else if (!same_type (t1
, t2
))
911 type_op_error ("Arguments to %s must be of the same type.", op
);
914 case BINOP_LOGICAL_AND
:
915 case BINOP_LOGICAL_OR
:
916 if (!boolean_type (t1
) || !boolean_type (t2
))
917 type_op_error ("Arguments to %s must be of boolean type.", op
);
921 if ((pointer_type (t1
) && !(pointer_type (t2
) || integral_type (t2
))) ||
922 (pointer_type (t2
) && !(pointer_type (t1
) || integral_type (t1
))))
923 type_op_error ("A pointer can only be compared to an integer or pointer.", op
);
924 else if ((pointer_type (t1
) && integral_type (t2
)) ||
925 (integral_type (t1
) && pointer_type (t2
)))
927 warning ("combining integer and pointer.\n");
930 else if (!simple_type (t1
) || !simple_type (t2
))
931 type_op_error ("Arguments to %s must be of simple type.", op
);
932 else if (!same_type (t1
, t2
))
933 type_op_error ("Arguments to %s must be of the same type.", op
);
938 if (!integral_type (t1
) || !integral_type (t2
))
939 type_op_error ("Arguments to %s must be of integral type.", op
);
946 if (!ordered_type (t1
) || !ordered_type (t2
))
947 type_op_error ("Arguments to %s must be of ordered type.", op
);
948 else if (!same_type (t1
, t2
))
949 type_op_error ("Arguments to %s must be of the same type.", op
);
953 if (pointer_type (t1
) && !integral_type (t2
))
954 type_op_error ("A pointer can only be assigned an integer.", op
);
955 else if (pointer_type (t1
) && integral_type (t2
))
957 warning ("combining integer and pointer.");
960 else if (!simple_type (t1
) || !simple_type (t2
))
961 type_op_error ("Arguments to %s must be of simple type.", op
);
962 else if (!same_type (t1
, t2
))
963 type_op_error ("Arguments to %s must be of the same type.", op
);
967 /* FIXME: Needs to handle bitstrings as well. */
968 if (!(string_type (t1
) || character_type (t1
) || integral_type (t1
))
969 || !(string_type (t2
) || character_type (t2
) || integral_type (t2
)))
970 type_op_error ("Arguments to %s must be strings or characters.", op
);
973 /* Unary checks -- arg2 is null */
975 case UNOP_LOGICAL_NOT
:
976 if (!boolean_type (t1
))
977 type_op_error ("Argument to %s must be of boolean type.", op
);
982 if (!numeric_type (t1
))
983 type_op_error ("Argument to %s must be of numeric type.", op
);
987 if (integral_type (t1
))
989 warning ("combining pointer and integer.\n");
992 else if (!pointer_type (t1
))
993 type_op_error ("Argument to %s must be a pointer.", op
);
996 case UNOP_PREINCREMENT
:
997 case UNOP_POSTINCREMENT
:
998 case UNOP_PREDECREMENT
:
999 case UNOP_POSTDECREMENT
:
1000 if (!ordered_type (t1
))
1001 type_op_error ("Argument to %s must be of an ordered type.", op
);
1005 /* Ok. The following operators have different meanings in
1006 different languages. */
1007 switch (current_language
->la_language
)
1011 case language_cplus
:
1015 if (!numeric_type (t1
) || !numeric_type (t2
))
1016 type_op_error ("Arguments to %s must be numbers.", op
);
1027 if (!float_type (t1
) || !float_type (t2
))
1028 type_op_error ("Arguments to %s must be floating point numbers.", op
);
1031 if (!integral_type (t1
) || !integral_type (t2
))
1032 type_op_error ("Arguments to %s must be of integral type.", op
);
1038 case language_chill
:
1039 error ("Missing Chill support in function binop_type_check."); /*FIXME */
1049 /* This page contains functions for the printing out of
1050 error messages that occur during type- and range-
1053 /* Prints the format string FMT with the operator as a string
1054 corresponding to the opcode OP. If FATAL is non-zero, then
1055 this is an error and error () is called. Otherwise, it is
1056 a warning and printf() is called. */
1058 op_error (fmt
, op
, fatal
)
1064 error (fmt
, op_string (op
));
1067 warning (fmt
, op_string (op
));
1071 /* These are called when a language fails a type- or range-check.
1072 The first argument should be a printf()-style format string, and
1073 the rest of the arguments should be its arguments. If
1074 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1075 is called in the style of error (). Otherwise, the message is prefixed
1076 by the value of warning_pre_print and we do not return to the top level. */
1079 type_error (char *string
,...)
1082 va_start (args
, string
);
1084 if (type_check
== type_check_warn
)
1085 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1089 vfprintf_filtered (gdb_stderr
, string
, args
);
1090 fprintf_filtered (gdb_stderr
, "\n");
1092 if (type_check
== type_check_on
)
1093 return_to_top_level (RETURN_ERROR
);
1097 range_error (char *string
,...)
1100 va_start (args
, string
);
1102 if (range_check
== range_check_warn
)
1103 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1107 vfprintf_filtered (gdb_stderr
, string
, args
);
1108 fprintf_filtered (gdb_stderr
, "\n");
1110 if (range_check
== range_check_on
)
1111 return_to_top_level (RETURN_ERROR
);
1115 /* This page contains miscellaneous functions */
1117 /* Return the language enum for a given language string. */
1125 for (i
= 0; i
< languages_size
; i
++)
1126 if (STREQ (languages
[i
]->la_name
, str
))
1127 return languages
[i
]->la_language
;
1129 return language_unknown
;
1132 /* Return the language struct for a given language enum. */
1134 const struct language_defn
*
1140 for (i
= 0; i
< languages_size
; i
++)
1142 if (languages
[i
]->la_language
== lang
)
1144 return languages
[i
];
1150 /* Return the language as a string */
1157 for (i
= 0; i
< languages_size
; i
++)
1159 if (languages
[i
]->la_language
== lang
)
1161 return languages
[i
]->la_name
;
1168 set_check (ignore
, from_tty
)
1173 "\"set check\" must be followed by the name of a check subcommand.\n");
1174 help_list (setchecklist
, "set check ", -1, gdb_stdout
);
1178 show_check (ignore
, from_tty
)
1182 cmd_show_list (showchecklist
, from_tty
, "");
1185 /* Add a language to the set of known languages. */
1189 const struct language_defn
*lang
;
1191 if (lang
->la_magic
!= LANG_MAGIC
)
1193 fprintf_unfiltered (gdb_stderr
, "Magic number of %s language struct wrong\n",
1200 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1201 languages
= (const struct language_defn
**) xmalloc
1202 (languages_allocsize
* sizeof (*languages
));
1204 if (languages_size
>= languages_allocsize
)
1206 languages_allocsize
*= 2;
1207 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1208 languages_allocsize
* sizeof (*languages
));
1210 languages
[languages_size
++] = lang
;
1213 /* Define the language that is no language. */
1222 unk_lang_error (msg
)
1225 error ("Attempted to parse an expression with unknown language");
1229 unk_lang_emit_char (c
, stream
, quoter
)
1234 error ("internal error - unimplemented function unk_lang_emit_char called.");
1238 unk_lang_printchar (c
, stream
)
1242 error ("internal error - unimplemented function unk_lang_printchar called.");
1246 unk_lang_printstr (stream
, string
, length
, width
, force_ellipses
)
1249 unsigned int length
;
1253 error ("internal error - unimplemented function unk_lang_printstr called.");
1256 static struct type
*
1257 unk_lang_create_fundamental_type (objfile
, typeid)
1258 struct objfile
*objfile
;
1261 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1265 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1272 error ("internal error - unimplemented function unk_lang_print_type called.");
1276 unk_lang_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
, deref_ref
,
1280 int embedded_offset
;
1286 enum val_prettyprint pretty
;
1288 error ("internal error - unimplemented function unk_lang_val_print called.");
1292 unk_lang_value_print (val
, stream
, format
, pretty
)
1296 enum val_prettyprint pretty
;
1298 error ("internal error - unimplemented function unk_lang_value_print called.");
1301 static struct type
**CONST_PTR (unknown_builtin_types
[]) =
1305 static const struct op_print unk_op_print_tab
[] =
1307 {NULL
, OP_NULL
, PREC_NULL
, 0}
1310 const struct language_defn unknown_language_defn
=
1314 &unknown_builtin_types
[0],
1319 evaluate_subexp_standard
,
1320 unk_lang_printchar
, /* Print character constant */
1323 unk_lang_create_fundamental_type
,
1324 unk_lang_print_type
, /* Print a type using appropriate syntax */
1325 unk_lang_val_print
, /* Print a value using appropriate syntax */
1326 unk_lang_value_print
, /* Print a top-level value */
1327 {"", "", "", ""}, /* Binary format info */
1328 {"0%lo", "0", "o", ""}, /* Octal format info */
1329 {"%ld", "", "d", ""}, /* Decimal format info */
1330 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1331 unk_op_print_tab
, /* expression operators for printing */
1332 1, /* c-style arrays */
1333 0, /* String lower bound */
1334 &builtin_type_char
, /* Type of string elements */
1338 /* These two structs define fake entries for the "local" and "auto" options. */
1339 const struct language_defn auto_language_defn
=
1343 &unknown_builtin_types
[0],
1348 evaluate_subexp_standard
,
1349 unk_lang_printchar
, /* Print character constant */
1352 unk_lang_create_fundamental_type
,
1353 unk_lang_print_type
, /* Print a type using appropriate syntax */
1354 unk_lang_val_print
, /* Print a value using appropriate syntax */
1355 unk_lang_value_print
, /* Print a top-level value */
1356 {"", "", "", ""}, /* Binary format info */
1357 {"0%lo", "0", "o", ""}, /* Octal format info */
1358 {"%ld", "", "d", ""}, /* Decimal format info */
1359 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1360 unk_op_print_tab
, /* expression operators for printing */
1361 1, /* c-style arrays */
1362 0, /* String lower bound */
1363 &builtin_type_char
, /* Type of string elements */
1367 const struct language_defn local_language_defn
=
1371 &unknown_builtin_types
[0],
1376 evaluate_subexp_standard
,
1377 unk_lang_printchar
, /* Print character constant */
1380 unk_lang_create_fundamental_type
,
1381 unk_lang_print_type
, /* Print a type using appropriate syntax */
1382 unk_lang_val_print
, /* Print a value using appropriate syntax */
1383 unk_lang_value_print
, /* Print a top-level value */
1384 {"", "", "", ""}, /* Binary format info */
1385 {"0%lo", "0", "o", ""}, /* Octal format info */
1386 {"%ld", "", "d", ""}, /* Decimal format info */
1387 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1388 unk_op_print_tab
, /* expression operators for printing */
1389 1, /* c-style arrays */
1390 0, /* String lower bound */
1391 &builtin_type_char
, /* Type of string elements */
1395 /* Initialize the language routines */
1398 _initialize_language ()
1400 struct cmd_list_element
*set
, *show
;
1402 /* GDB commands for language specific stuff */
1404 set
= add_set_cmd ("language", class_support
, var_string_noescape
,
1406 "Set the current source language.",
1408 show
= add_show_from_set (set
, &showlist
);
1409 set
->function
.cfunc
= set_language_command
;
1410 show
->function
.cfunc
= show_language_command
;
1412 add_prefix_cmd ("check", no_class
, set_check
,
1413 "Set the status of the type/range checker",
1414 &setchecklist
, "set check ", 0, &setlist
);
1415 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1416 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1418 add_prefix_cmd ("check", no_class
, show_check
,
1419 "Show the status of the type/range checker",
1420 &showchecklist
, "show check ", 0, &showlist
);
1421 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1422 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1424 set
= add_set_cmd ("type", class_support
, var_string_noescape
,
1426 "Set type checking. (on/warn/off/auto)",
1428 show
= add_show_from_set (set
, &showchecklist
);
1429 set
->function
.cfunc
= set_type_command
;
1430 show
->function
.cfunc
= show_type_command
;
1432 set
= add_set_cmd ("range", class_support
, var_string_noescape
,
1434 "Set range checking. (on/warn/off/auto)",
1436 show
= add_show_from_set (set
, &showchecklist
);
1437 set
->function
.cfunc
= set_range_command
;
1438 show
->function
.cfunc
= show_range_command
;
1440 add_language (&unknown_language_defn
);
1441 add_language (&local_language_defn
);
1442 add_language (&auto_language_defn
);
1444 language
= savestring ("auto", strlen ("auto"));
1445 range
= savestring ("auto", strlen ("auto"));
1446 type
= savestring ("auto", strlen ("auto"));
1448 /* Have the above take effect */
1450 set_language_command (language
, 0);
1451 set_type_command (NULL
, 0);
1452 set_range_command (NULL
, 0);