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, Boston, MA 02111-1307, USA. */
22 /* This file contains functions that return things that are specific
23 to languages. Each function should examine current_language if necessary,
24 and return the appropriate result. */
26 /* FIXME: Most of these would be better organized as macros which
27 return data out of a "language-specific" struct pointer that is set
28 whenever the working language changes. That would be a lot faster. */
32 #include "gdb_string.h"
39 #include "expression.h"
42 #include "parser-defs.h"
44 extern void _initialize_language
PARAMS ((void));
47 show_language_command
PARAMS ((char *, int));
50 set_language_command
PARAMS ((char *, int));
53 show_type_command
PARAMS ((char *, int));
56 set_type_command
PARAMS ((char *, int));
59 show_range_command
PARAMS ((char *, int));
62 set_range_command
PARAMS ((char *, int));
65 set_range_str
PARAMS ((void));
68 set_type_str
PARAMS ((void));
71 set_lang_str
PARAMS ((void));
74 unk_lang_error
PARAMS ((char *));
77 unk_lang_parser
PARAMS ((void));
80 show_check
PARAMS ((char *, int));
83 set_check
PARAMS ((char *, int));
86 set_type_range
PARAMS ((void));
89 unk_lang_emit_char
PARAMS ((int c
, GDB_FILE
*stream
, int quoter
));
92 unk_lang_printchar
PARAMS ((int c
, GDB_FILE
*stream
));
95 unk_lang_printstr
PARAMS ((GDB_FILE
*stream
, char *string
, unsigned int length
, int width
, int force_ellipses
));
98 unk_lang_create_fundamental_type
PARAMS ((struct objfile
*, int));
101 unk_lang_print_type
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int));
104 unk_lang_val_print
PARAMS ((struct type
*, char *, int, CORE_ADDR
, GDB_FILE
*,
105 int, int, int, enum val_prettyprint
));
108 unk_lang_value_print
PARAMS ((value_ptr
, GDB_FILE
*, int, enum val_prettyprint
));
110 /* Forward declaration */
111 extern const struct language_defn unknown_language_defn
;
112 extern char *warning_pre_print
;
114 /* The current (default at startup) state of type and range checking.
115 (If the modes are set to "auto", though, these are changed based
116 on the default language at startup, and then again based on the
117 language of the first source file. */
119 enum range_mode range_mode
= range_mode_auto
;
120 enum range_check range_check
= range_check_off
;
121 enum type_mode type_mode
= type_mode_auto
;
122 enum type_check type_check
= type_check_off
;
124 /* The current language and language_mode (see language.h) */
126 const struct language_defn
*current_language
= &unknown_language_defn
;
127 enum language_mode language_mode
= language_mode_auto
;
129 /* The language that the user expects to be typing in (the language
130 of main(), or the last language we notified them about, or C). */
132 const struct language_defn
*expected_language
;
134 /* The list of supported languages. The list itself is malloc'd. */
136 static const struct language_defn
**languages
;
137 static unsigned languages_size
;
138 static unsigned languages_allocsize
;
139 #define DEFAULT_ALLOCSIZE 4
141 /* The "set language/type/range" commands all put stuff in these
142 buffers. This is to make them work as set/show commands. The
143 user's string is copied here, then the set_* commands look at
144 them and update them to something that looks nice when it is
147 static char *language
;
151 /* Warning issued when current_language and the language of the current
152 frame do not match. */
153 char lang_frame_mismatch_warn
[] =
154 "Warning: the current language does not match this frame.";
157 /* This page contains the functions corresponding to GDB commands
158 and their helpers. */
160 /* Show command. Display a warning if the language set
161 does not match the frame. */
163 show_language_command (ignore
, from_tty
)
167 enum language flang
; /* The language of the current frame */
169 flang
= get_frame_language();
170 if (flang
!= language_unknown
&&
171 language_mode
== language_mode_manual
&&
172 current_language
->la_language
!= flang
)
173 printf_filtered("%s\n",lang_frame_mismatch_warn
);
176 /* Set command. Change the current working language. */
178 set_language_command (ignore
, from_tty
)
186 if (!language
|| !language
[0])
188 printf_unfiltered("The currently understood settings are:\n\n");
189 printf_unfiltered ("local or auto Automatic setting based on source file\n");
191 for (i
= 0; i
< languages_size
; ++i
)
193 /* Already dealt with these above. */
194 if (languages
[i
]->la_language
== language_unknown
195 || languages
[i
]->la_language
== language_auto
)
198 /* FIXME for now assume that the human-readable name is just
199 a capitalization of the internal name. */
200 printf_unfiltered ("%-16s Use the %c%s language\n",
201 languages
[i
]->la_name
,
202 /* Capitalize first letter of language
204 toupper (languages
[i
]->la_name
[0]),
205 languages
[i
]->la_name
+ 1);
207 /* Restore the silly string. */
208 set_language(current_language
->la_language
);
212 /* Search the list of languages for a match. */
213 for (i
= 0; i
< languages_size
; i
++) {
214 if (STREQ (languages
[i
]->la_name
, language
)) {
215 /* Found it! Go into manual mode, and use this language. */
216 if (languages
[i
]->la_language
== language_auto
) {
217 /* Enter auto mode. Set to the current frame's language, if known. */
218 language_mode
= language_mode_auto
;
219 flang
= get_frame_language();
220 if (flang
!=language_unknown
)
222 expected_language
= current_language
;
225 /* Enter manual mode. Set the specified language. */
226 language_mode
= language_mode_manual
;
227 current_language
= languages
[i
];
230 expected_language
= current_language
;
236 /* Reset the language (esp. the global string "language") to the
238 err_lang
=savestring(language
,strlen(language
));
239 make_cleanup (free
, err_lang
); /* Free it after error */
240 set_language(current_language
->la_language
);
241 error ("Unknown language `%s'.",err_lang
);
244 /* Show command. Display a warning if the type setting does
245 not match the current language. */
247 show_type_command(ignore
, from_tty
)
251 if (type_check
!= current_language
->la_type_check
)
253 "Warning: the current type check setting does not match the language.\n");
256 /* Set command. Change the setting for type checking. */
258 set_type_command(ignore
, from_tty
)
262 if (STREQ(type
,"on"))
264 type_check
= type_check_on
;
265 type_mode
= type_mode_manual
;
267 else if (STREQ(type
,"warn"))
269 type_check
= type_check_warn
;
270 type_mode
= type_mode_manual
;
272 else if (STREQ(type
,"off"))
274 type_check
= type_check_off
;
275 type_mode
= type_mode_manual
;
277 else if (STREQ(type
,"auto"))
279 type_mode
= type_mode_auto
;
281 /* Avoid hitting the set_type_str call below. We
282 did it in set_type_range. */
286 show_type_command((char *)NULL
, from_tty
);
289 /* Show command. Display a warning if the range setting does
290 not match the current language. */
292 show_range_command(ignore
, from_tty
)
297 if (range_check
!= current_language
->la_range_check
)
299 "Warning: the current range check setting does not match the language.\n");
302 /* Set command. Change the setting for range checking. */
304 set_range_command(ignore
, from_tty
)
308 if (STREQ(range
,"on"))
310 range_check
= range_check_on
;
311 range_mode
= range_mode_manual
;
313 else if (STREQ(range
,"warn"))
315 range_check
= range_check_warn
;
316 range_mode
= range_mode_manual
;
318 else if (STREQ(range
,"off"))
320 range_check
= range_check_off
;
321 range_mode
= range_mode_manual
;
323 else if (STREQ(range
,"auto"))
325 range_mode
= range_mode_auto
;
327 /* Avoid hitting the set_range_str call below. We
328 did it in set_type_range. */
332 show_range_command((char *)0, from_tty
);
335 /* Set the status of range and type checking based on
336 the current modes and the current language.
337 If SHOW is non-zero, then print out the current language,
338 type and range checking status. */
343 if (range_mode
== range_mode_auto
)
344 range_check
= current_language
->la_range_check
;
346 if (type_mode
== type_mode_auto
)
347 type_check
= current_language
->la_type_check
;
353 /* Set current language to (enum language) LANG. Returns previous language. */
360 enum language prev_language
;
362 prev_language
= current_language
->la_language
;
364 for (i
= 0; i
< languages_size
; i
++) {
365 if (languages
[i
]->la_language
== lang
) {
366 current_language
= languages
[i
];
373 return prev_language
;
376 /* This page contains functions that update the global vars
377 language, type and range. */
384 if (language_mode
== language_mode_auto
)
385 prefix
= "auto; currently ";
387 language
= concat(prefix
, current_language
->la_name
, NULL
);
393 char *tmp
, *prefix
= "";
396 if (type_mode
==type_mode_auto
)
397 prefix
= "auto; currently ";
407 case type_check_warn
:
411 error ("Unrecognized type check setting.");
414 type
= concat(prefix
,tmp
,NULL
);
420 char *tmp
, *pref
= "";
423 if (range_mode
==range_mode_auto
)
424 pref
= "auto; currently ";
431 case range_check_off
:
434 case range_check_warn
:
438 error ("Unrecognized range check setting.");
441 range
= concat(pref
,tmp
,NULL
);
445 /* Print out the current language settings: language, range and
446 type checking. If QUIETLY, print only what has changed. */
449 language_info (quietly
)
452 if (quietly
&& expected_language
== current_language
)
455 expected_language
= current_language
;
456 printf_unfiltered("Current language: %s\n",language
);
457 show_language_command((char *)0, 1);
461 printf_unfiltered("Type checking: %s\n",type
);
462 show_type_command((char *)0, 1);
463 printf_unfiltered("Range checking: %s\n",range
);
464 show_range_command((char *)0, 1);
468 /* Return the result of a binary operation. */
470 #if 0 /* Currently unused */
473 binop_result_type (v1
, v2
)
477 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
478 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
480 int l1
= TYPE_LENGTH (t1
);
481 int l2
= TYPE_LENGTH (t2
);
483 switch(current_language
->la_language
)
487 if (TYPE_CODE (t1
)==TYPE_CODE_FLT
)
488 return TYPE_CODE(t2
) == TYPE_CODE_FLT
&& l2
> l1
?
489 VALUE_TYPE(v2
) : VALUE_TYPE(v1
);
490 else if (TYPE_CODE(t2
)==TYPE_CODE_FLT
)
491 return TYPE_CODE(t1
)) == TYPE_CODE_FLT
&& l1
> l2
?
492 VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
493 else if (TYPE_UNSIGNED(t1
) && l1
> l2
)
494 return VALUE_TYPE(v1
);
495 else if (TYPE_UNSIGNED(t2
) && l2
> l1
)
496 return VALUE_TYPE(v2
);
497 else /* Both are signed. Result is the longer type */
498 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
501 /* If we are doing type-checking, l1 should equal l2, so this is
503 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
506 error ("Missing Chill support in function binop_result_check.");/*FIXME*/
509 return (struct type
*)0; /* For lint */
515 /* This page contains functions that return format strings for
516 printf for printing out numbers in different formats */
518 /* Returns the appropriate printf format for hexadecimal
521 local_hex_format_custom(pre
)
524 static char form
[50];
526 strcpy (form
, local_hex_format_prefix ());
529 strcat (form
, local_hex_format_specifier ());
530 strcat (form
, local_hex_format_suffix ());
534 /* Converts a number to hexadecimal and stores it in a static
535 string. Returns a pointer to this string. */
537 local_hex_string (num
)
542 sprintf (res
, local_hex_format(), num
);
546 /* Converts a number to custom hexadecimal and stores it in a static
547 string. Returns a pointer to this string. */
549 local_hex_string_custom(num
,pre
)
555 sprintf (res
, local_hex_format_custom(pre
), num
);
559 /* Returns the appropriate printf format for octal
562 local_octal_format_custom(pre
)
565 static char form
[50];
567 strcpy (form
, local_octal_format_prefix ());
570 strcat (form
, local_octal_format_specifier ());
571 strcat (form
, local_octal_format_suffix ());
575 /* Returns the appropriate printf format for decimal numbers. */
577 local_decimal_format_custom(pre
)
580 static char form
[50];
582 strcpy (form
, local_decimal_format_prefix ());
585 strcat (form
, local_decimal_format_specifier ());
586 strcat (form
, local_decimal_format_suffix ());
591 /* This page contains functions that are used in type/range checking.
592 They all return zero if the type/range check fails.
594 It is hoped that these will make extending GDB to parse different
595 languages a little easier. These are primarily used in eval.c when
596 evaluating expressions and making sure that their types are correct.
597 Instead of having a mess of conjucted/disjuncted expressions in an "if",
598 the ideas of type can be wrapped up in the following functions.
600 Note that some of them are not currently dependent upon which language
601 is currently being parsed. For example, floats are the same in
602 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
603 TYPE_CODE_FLT), while booleans are different. */
605 /* Returns non-zero if its argument is a simple type. This is the same for
606 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
607 and thus will never cause the failure of the test. */
612 CHECK_TYPEDEF (type
);
613 switch (TYPE_CODE (type
)) {
618 case TYPE_CODE_RANGE
:
627 /* Returns non-zero if its argument is of an ordered type.
628 An ordered type is one in which the elements can be tested for the
629 properties of "greater than", "less than", etc, or for which the
630 operations "increment" or "decrement" make sense. */
635 CHECK_TYPEDEF (type
);
636 switch (TYPE_CODE (type
)) {
641 case TYPE_CODE_RANGE
:
649 /* Returns non-zero if the two types are the same */
651 same_type (arg1
, arg2
)
652 struct type
*arg1
, *arg2
;
654 CHECK_TYPEDEF (type
);
655 if (structured_type(arg1
) ? !structured_type(arg2
) : structured_type(arg2
))
656 /* One is structured and one isn't */
658 else if (structured_type(arg1
) && structured_type(arg2
))
660 else if (numeric_type(arg1
) && numeric_type(arg2
))
661 return (TYPE_CODE(arg2
) == TYPE_CODE(arg1
)) &&
662 (TYPE_UNSIGNED(arg1
) == TYPE_UNSIGNED(arg2
))
668 /* Returns non-zero if the type is integral */
673 CHECK_TYPEDEF (type
);
674 switch(current_language
->la_language
)
678 return (TYPE_CODE(type
) != TYPE_CODE_INT
) &&
679 (TYPE_CODE(type
) != TYPE_CODE_ENUM
) ? 0 : 1;
681 return TYPE_CODE(type
) != TYPE_CODE_INT
? 0 : 1;
683 error ("Missing Chill support in function integral_type."); /*FIXME*/
685 error ("Language not supported.");
689 /* Returns non-zero if the value is numeric */
694 CHECK_TYPEDEF (type
);
695 switch (TYPE_CODE (type
)) {
705 /* Returns non-zero if the value is a character type */
707 character_type (type
)
710 CHECK_TYPEDEF (type
);
711 switch(current_language
->la_language
)
715 return TYPE_CODE(type
) != TYPE_CODE_CHAR
? 0 : 1;
719 return (TYPE_CODE(type
) == TYPE_CODE_INT
) &&
720 TYPE_LENGTH(type
) == sizeof(char)
727 /* Returns non-zero if the value is a string type */
732 CHECK_TYPEDEF (type
);
733 switch(current_language
->la_language
)
737 return TYPE_CODE(type
) != TYPE_CODE_STRING
? 0 : 1;
741 /* C does not have distinct string type. */
748 /* Returns non-zero if the value is a boolean type */
753 CHECK_TYPEDEF (type
);
754 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
756 switch(current_language
->la_language
)
760 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
761 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
762 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
770 /* Returns non-zero if the value is a floating-point type */
775 CHECK_TYPEDEF (type
);
776 return TYPE_CODE(type
) == TYPE_CODE_FLT
;
779 /* Returns non-zero if the value is a pointer type */
784 return TYPE_CODE(type
) == TYPE_CODE_PTR
||
785 TYPE_CODE(type
) == TYPE_CODE_REF
;
788 /* Returns non-zero if the value is a structured type */
790 structured_type(type
)
793 CHECK_TYPEDEF (type
);
794 switch(current_language
->la_language
)
798 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
799 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
800 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
802 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
803 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
804 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
806 error ("Missing Chill support in function structured_type."); /*FIXME*/
818 switch(current_language
->la_language
)
821 return builtin_type_chill_bool
;
822 case language_fortran
:
823 sym
= lookup_symbol ("logical", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
826 type
= SYMBOL_TYPE (sym
);
827 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
830 return builtin_type_f_logical_s2
;
832 sym
= lookup_symbol ("bool", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
835 type
= SYMBOL_TYPE (sym
);
836 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
839 return builtin_type_bool
;
841 return builtin_type_int
;
845 /* This page contains functions that return info about
846 (struct value) values used in GDB. */
848 /* Returns non-zero if the value VAL represents a true value. */
853 /* It is possible that we should have some sort of error if a non-boolean
854 value is used in this context. Possibly dependent on some kind of
855 "boolean-checking" option like range checking. But it should probably
856 not depend on the language except insofar as is necessary to identify
857 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
858 should be an error, probably). */
859 return !value_logical_not (val
);
862 /* Returns non-zero if the operator OP is defined on
863 the values ARG1 and ARG2. */
865 #if 0 /* Currently unused */
868 binop_type_check(arg1
,arg2
,op
)
872 struct type
*t1
, *t2
;
874 /* If we're not checking types, always return success. */
888 if ((numeric_type(t1
) && pointer_type(t2
)) ||
889 (pointer_type(t1
) && numeric_type(t2
)))
891 warning ("combining pointer and integer.\n");
897 if (!numeric_type(t1
) || !numeric_type(t2
))
898 type_op_error ("Arguments to %s must be numbers.",op
);
899 else if (!same_type(t1
,t2
))
900 type_op_error ("Arguments to %s must be of the same type.",op
);
903 case BINOP_LOGICAL_AND
:
904 case BINOP_LOGICAL_OR
:
905 if (!boolean_type(t1
) || !boolean_type(t2
))
906 type_op_error ("Arguments to %s must be of boolean type.",op
);
910 if ((pointer_type(t1
) && !(pointer_type(t2
) || integral_type(t2
))) ||
911 (pointer_type(t2
) && !(pointer_type(t1
) || integral_type(t1
))))
912 type_op_error ("A pointer can only be compared to an integer or pointer.",op
);
913 else if ((pointer_type(t1
) && integral_type(t2
)) ||
914 (integral_type(t1
) && pointer_type(t2
)))
916 warning ("combining integer and pointer.\n");
919 else if (!simple_type(t1
) || !simple_type(t2
))
920 type_op_error ("Arguments to %s must be of simple type.",op
);
921 else if (!same_type(t1
,t2
))
922 type_op_error ("Arguments to %s must be of the same type.",op
);
927 if (!integral_type(t1
) || !integral_type(t2
))
928 type_op_error ("Arguments to %s must be of integral type.",op
);
935 if (!ordered_type(t1
) || !ordered_type(t2
))
936 type_op_error ("Arguments to %s must be of ordered type.",op
);
937 else if (!same_type(t1
,t2
))
938 type_op_error ("Arguments to %s must be of the same type.",op
);
942 if (pointer_type(t1
) && !integral_type(t2
))
943 type_op_error ("A pointer can only be assigned an integer.",op
);
944 else if (pointer_type(t1
) && integral_type(t2
))
946 warning ("combining integer and pointer.");
949 else if (!simple_type(t1
) || !simple_type(t2
))
950 type_op_error ("Arguments to %s must be of simple type.",op
);
951 else if (!same_type(t1
,t2
))
952 type_op_error ("Arguments to %s must be of the same type.",op
);
956 /* FIXME: Needs to handle bitstrings as well. */
957 if (!(string_type(t1
) || character_type(t1
) || integral_type(t1
))
958 || !(string_type(t2
) || character_type(t2
) || integral_type(t2
)))
959 type_op_error ("Arguments to %s must be strings or characters.", op
);
962 /* Unary checks -- arg2 is null */
964 case UNOP_LOGICAL_NOT
:
965 if (!boolean_type(t1
))
966 type_op_error ("Argument to %s must be of boolean type.",op
);
971 if (!numeric_type(t1
))
972 type_op_error ("Argument to %s must be of numeric type.",op
);
976 if (integral_type(t1
))
978 warning ("combining pointer and integer.\n");
981 else if (!pointer_type(t1
))
982 type_op_error ("Argument to %s must be a pointer.",op
);
985 case UNOP_PREINCREMENT
:
986 case UNOP_POSTINCREMENT
:
987 case UNOP_PREDECREMENT
:
988 case UNOP_POSTDECREMENT
:
989 if (!ordered_type(t1
))
990 type_op_error ("Argument to %s must be of an ordered type.",op
);
994 /* Ok. The following operators have different meanings in
995 different languages. */
996 switch(current_language
->la_language
)
1000 case language_cplus
:
1004 if (!numeric_type(t1
) || !numeric_type(t2
))
1005 type_op_error ("Arguments to %s must be numbers.",op
);
1016 if (!float_type(t1
) || !float_type(t2
))
1017 type_op_error ("Arguments to %s must be floating point numbers.",op
);
1020 if (!integral_type(t1
) || !integral_type(t2
))
1021 type_op_error ("Arguments to %s must be of integral type.",op
);
1027 case language_chill
:
1028 error ("Missing Chill support in function binop_type_check.");/*FIXME*/
1038 /* This page contains functions for the printing out of
1039 error messages that occur during type- and range-
1042 /* Prints the format string FMT with the operator as a string
1043 corresponding to the opcode OP. If FATAL is non-zero, then
1044 this is an error and error () is called. Otherwise, it is
1045 a warning and printf() is called. */
1047 op_error (fmt
,op
,fatal
)
1053 error (fmt
,op_string(op
));
1056 warning (fmt
,op_string(op
));
1060 /* These are called when a language fails a type- or range-check.
1061 The first argument should be a printf()-style format string, and
1062 the rest of the arguments should be its arguments. If
1063 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1064 is called in the style of error (). Otherwise, the message is prefixed
1065 by the value of warning_pre_print and we do not return to the top level. */
1068 #ifdef ANSI_PROTOTYPES
1069 type_error (char *string
, ...)
1071 type_error (va_alist
)
1076 #ifdef ANSI_PROTOTYPES
1077 va_start (args
, string
);
1081 string
= va_arg (args
, char *);
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 #ifdef ANSI_PROTOTYPES
1098 range_error (char *string
, ...)
1100 range_error (va_alist
)
1105 #ifdef ANSI_PROTOTYPES
1106 va_start (args
, string
);
1110 string
= va_arg (args
, char *);
1113 if (range_check
== range_check_warn
)
1114 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1118 vfprintf_filtered (gdb_stderr
, string
, args
);
1119 fprintf_filtered (gdb_stderr
, "\n");
1121 if (range_check
== range_check_on
)
1122 return_to_top_level (RETURN_ERROR
);
1126 /* This page contains miscellaneous functions */
1128 /* Return the language enum for a given language string. */
1136 for (i
= 0; i
< languages_size
; i
++)
1137 if (STREQ (languages
[i
]->la_name
, str
))
1138 return languages
[i
]->la_language
;
1140 return language_unknown
;
1143 /* Return the language struct for a given language enum. */
1145 const struct language_defn
*
1151 for (i
= 0; i
< languages_size
; i
++) {
1152 if (languages
[i
]->la_language
== lang
) {
1153 return languages
[i
];
1159 /* Return the language as a string */
1166 for (i
= 0; i
< languages_size
; i
++) {
1167 if (languages
[i
]->la_language
== lang
) {
1168 return languages
[i
]->la_name
;
1175 set_check (ignore
, from_tty
)
1180 "\"set check\" must be followed by the name of a check subcommand.\n");
1181 help_list(setchecklist
, "set check ", -1, gdb_stdout
);
1185 show_check (ignore
, from_tty
)
1189 cmd_show_list(showchecklist
, from_tty
, "");
1192 /* Add a language to the set of known languages. */
1196 const struct language_defn
*lang
;
1198 if (lang
->la_magic
!= LANG_MAGIC
)
1200 fprintf_unfiltered(gdb_stderr
, "Magic number of %s language struct wrong\n",
1207 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1208 languages
= (const struct language_defn
**) xmalloc
1209 (languages_allocsize
* sizeof (*languages
));
1211 if (languages_size
>= languages_allocsize
)
1213 languages_allocsize
*= 2;
1214 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1215 languages_allocsize
* sizeof (*languages
));
1217 languages
[languages_size
++] = lang
;
1220 /* Define the language that is no language. */
1229 unk_lang_error (msg
)
1232 error ("Attempted to parse an expression with unknown language");
1236 unk_lang_emit_char (c
, stream
, quoter
)
1241 error ("internal error - unimplemented function unk_lang_emit_char called.");
1245 unk_lang_printchar (c
, stream
)
1249 error ("internal error - unimplemented function unk_lang_printchar called.");
1253 unk_lang_printstr (stream
, string
, length
, width
, force_ellipses
)
1256 unsigned int length
;
1260 error ("internal error - unimplemented function unk_lang_printstr called.");
1263 static struct type
*
1264 unk_lang_create_fundamental_type (objfile
, typeid)
1265 struct objfile
*objfile
;
1268 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1272 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1279 error ("internal error - unimplemented function unk_lang_print_type called.");
1283 unk_lang_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
, deref_ref
,
1287 int embedded_offset
;
1293 enum val_prettyprint pretty
;
1295 error ("internal error - unimplemented function unk_lang_val_print called.");
1299 unk_lang_value_print (val
, stream
, format
, pretty
)
1303 enum val_prettyprint pretty
;
1305 error ("internal error - unimplemented function unk_lang_value_print called.");
1308 static struct type
** CONST_PTR (unknown_builtin_types
[]) = { 0 };
1309 static const struct op_print unk_op_print_tab
[] = {
1310 {NULL
, OP_NULL
, PREC_NULL
, 0}
1313 const struct language_defn unknown_language_defn
= {
1316 &unknown_builtin_types
[0],
1321 evaluate_subexp_standard
,
1322 unk_lang_printchar
, /* Print character constant */
1325 unk_lang_create_fundamental_type
,
1326 unk_lang_print_type
, /* Print a type using appropriate syntax */
1327 unk_lang_val_print
, /* Print a value using appropriate syntax */
1328 unk_lang_value_print
, /* Print a top-level value */
1329 {"", "", "", ""}, /* Binary format info */
1330 {"0%lo", "0", "o", ""}, /* Octal format info */
1331 {"%ld", "", "d", ""}, /* Decimal format info */
1332 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1333 unk_op_print_tab
, /* expression operators for printing */
1334 1, /* c-style arrays */
1335 0, /* String lower bound */
1336 &builtin_type_char
, /* Type of string elements */
1340 /* These two structs define fake entries for the "local" and "auto" options. */
1341 const struct language_defn auto_language_defn
= {
1344 &unknown_builtin_types
[0],
1349 evaluate_subexp_standard
,
1350 unk_lang_printchar
, /* Print character constant */
1353 unk_lang_create_fundamental_type
,
1354 unk_lang_print_type
, /* Print a type using appropriate syntax */
1355 unk_lang_val_print
, /* Print a value using appropriate syntax */
1356 unk_lang_value_print
, /* Print a top-level value */
1357 {"", "", "", ""}, /* Binary format info */
1358 {"0%lo", "0", "o", ""}, /* Octal format info */
1359 {"%ld", "", "d", ""}, /* Decimal format info */
1360 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1361 unk_op_print_tab
, /* expression operators for printing */
1362 1, /* c-style arrays */
1363 0, /* String lower bound */
1364 &builtin_type_char
, /* Type of string elements */
1368 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);