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"
45 show_language_command
PARAMS ((char *, int));
48 set_language_command
PARAMS ((char *, int));
51 show_type_command
PARAMS ((char *, int));
54 set_type_command
PARAMS ((char *, int));
57 show_range_command
PARAMS ((char *, int));
60 set_range_command
PARAMS ((char *, int));
63 set_range_str
PARAMS ((void));
66 set_type_str
PARAMS ((void));
69 set_lang_str
PARAMS ((void));
72 unk_lang_error
PARAMS ((char *));
75 unk_lang_parser
PARAMS ((void));
78 show_check
PARAMS ((char *, int));
81 set_check
PARAMS ((char *, int));
84 set_type_range
PARAMS ((void));
87 unk_lang_emit_char
PARAMS ((int c
, GDB_FILE
*stream
, int quoter
));
90 unk_lang_printchar
PARAMS ((int c
, GDB_FILE
*stream
));
93 unk_lang_printstr
PARAMS ((GDB_FILE
*stream
, char *string
, unsigned int length
, int width
, int force_ellipses
));
96 unk_lang_create_fundamental_type
PARAMS ((struct objfile
*, int));
99 unk_lang_print_type
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int));
102 unk_lang_val_print
PARAMS ((struct type
*, char *, int, CORE_ADDR
, GDB_FILE
*,
103 int, int, int, enum val_prettyprint
));
106 unk_lang_value_print
PARAMS ((value_ptr
, GDB_FILE
*, int, enum val_prettyprint
));
108 /* Forward declaration */
109 extern const struct language_defn unknown_language_defn
;
110 extern char *warning_pre_print
;
112 /* The current (default at startup) state of type and range checking.
113 (If the modes are set to "auto", though, these are changed based
114 on the default language at startup, and then again based on the
115 language of the first source file. */
117 enum range_mode range_mode
= range_mode_auto
;
118 enum range_check range_check
= range_check_off
;
119 enum type_mode type_mode
= type_mode_auto
;
120 enum type_check type_check
= type_check_off
;
122 /* The current language and language_mode (see language.h) */
124 const struct language_defn
*current_language
= &unknown_language_defn
;
125 enum language_mode language_mode
= language_mode_auto
;
127 /* The language that the user expects to be typing in (the language
128 of main(), or the last language we notified them about, or C). */
130 const struct language_defn
*expected_language
;
132 /* The list of supported languages. The list itself is malloc'd. */
134 static const struct language_defn
**languages
;
135 static unsigned languages_size
;
136 static unsigned languages_allocsize
;
137 #define DEFAULT_ALLOCSIZE 4
139 /* The "set language/type/range" commands all put stuff in these
140 buffers. This is to make them work as set/show commands. The
141 user's string is copied here, then the set_* commands look at
142 them and update them to something that looks nice when it is
145 static char *language
;
149 /* Warning issued when current_language and the language of the current
150 frame do not match. */
151 char lang_frame_mismatch_warn
[] =
152 "Warning: the current language does not match this frame.";
155 /* This page contains the functions corresponding to GDB commands
156 and their helpers. */
158 /* Show command. Display a warning if the language set
159 does not match the frame. */
161 show_language_command (ignore
, from_tty
)
165 enum language flang
; /* The language of the current frame */
167 flang
= get_frame_language();
168 if (flang
!= language_unknown
&&
169 language_mode
== language_mode_manual
&&
170 current_language
->la_language
!= flang
)
171 printf_filtered("%s\n",lang_frame_mismatch_warn
);
174 /* Set command. Change the current working language. */
176 set_language_command (ignore
, from_tty
)
184 if (!language
|| !language
[0])
186 printf_unfiltered("The currently understood settings are:\n\n");
187 printf_unfiltered ("local or auto Automatic setting based on source file\n");
189 for (i
= 0; i
< languages_size
; ++i
)
191 /* Already dealt with these above. */
192 if (languages
[i
]->la_language
== language_unknown
193 || languages
[i
]->la_language
== language_auto
)
196 /* FIXME for now assume that the human-readable name is just
197 a capitalization of the internal name. */
198 printf_unfiltered ("%-16s Use the %c%s language\n",
199 languages
[i
]->la_name
,
200 /* Capitalize first letter of language
202 toupper (languages
[i
]->la_name
[0]),
203 languages
[i
]->la_name
+ 1);
205 /* Restore the silly string. */
206 set_language(current_language
->la_language
);
210 /* Search the list of languages for a match. */
211 for (i
= 0; i
< languages_size
; i
++) {
212 if (STREQ (languages
[i
]->la_name
, language
)) {
213 /* Found it! Go into manual mode, and use this language. */
214 if (languages
[i
]->la_language
== language_auto
) {
215 /* Enter auto mode. Set to the current frame's language, if known. */
216 language_mode
= language_mode_auto
;
217 flang
= get_frame_language();
218 if (flang
!=language_unknown
)
220 expected_language
= current_language
;
223 /* Enter manual mode. Set the specified language. */
224 language_mode
= language_mode_manual
;
225 current_language
= languages
[i
];
228 expected_language
= current_language
;
234 /* Reset the language (esp. the global string "language") to the
236 err_lang
=savestring(language
,strlen(language
));
237 make_cleanup (free
, err_lang
); /* Free it after error */
238 set_language(current_language
->la_language
);
239 error ("Unknown language `%s'.",err_lang
);
242 /* Show command. Display a warning if the type setting does
243 not match the current language. */
245 show_type_command(ignore
, from_tty
)
249 if (type_check
!= current_language
->la_type_check
)
251 "Warning: the current type check setting does not match the language.\n");
254 /* Set command. Change the setting for type checking. */
256 set_type_command(ignore
, from_tty
)
260 if (STREQ(type
,"on"))
262 type_check
= type_check_on
;
263 type_mode
= type_mode_manual
;
265 else if (STREQ(type
,"warn"))
267 type_check
= type_check_warn
;
268 type_mode
= type_mode_manual
;
270 else if (STREQ(type
,"off"))
272 type_check
= type_check_off
;
273 type_mode
= type_mode_manual
;
275 else if (STREQ(type
,"auto"))
277 type_mode
= type_mode_auto
;
279 /* Avoid hitting the set_type_str call below. We
280 did it in set_type_range. */
284 show_type_command((char *)NULL
, from_tty
);
287 /* Show command. Display a warning if the range setting does
288 not match the current language. */
290 show_range_command(ignore
, from_tty
)
295 if (range_check
!= current_language
->la_range_check
)
297 "Warning: the current range check setting does not match the language.\n");
300 /* Set command. Change the setting for range checking. */
302 set_range_command(ignore
, from_tty
)
306 if (STREQ(range
,"on"))
308 range_check
= range_check_on
;
309 range_mode
= range_mode_manual
;
311 else if (STREQ(range
,"warn"))
313 range_check
= range_check_warn
;
314 range_mode
= range_mode_manual
;
316 else if (STREQ(range
,"off"))
318 range_check
= range_check_off
;
319 range_mode
= range_mode_manual
;
321 else if (STREQ(range
,"auto"))
323 range_mode
= range_mode_auto
;
325 /* Avoid hitting the set_range_str call below. We
326 did it in set_type_range. */
330 show_range_command((char *)0, from_tty
);
333 /* Set the status of range and type checking based on
334 the current modes and the current language.
335 If SHOW is non-zero, then print out the current language,
336 type and range checking status. */
341 if (range_mode
== range_mode_auto
)
342 range_check
= current_language
->la_range_check
;
344 if (type_mode
== type_mode_auto
)
345 type_check
= current_language
->la_type_check
;
351 /* Set current language to (enum language) LANG. Returns previous language. */
358 enum language prev_language
;
360 prev_language
= current_language
->la_language
;
362 for (i
= 0; i
< languages_size
; i
++) {
363 if (languages
[i
]->la_language
== lang
) {
364 current_language
= languages
[i
];
371 return prev_language
;
374 /* This page contains functions that update the global vars
375 language, type and range. */
382 if (language_mode
== language_mode_auto
)
383 prefix
= "auto; currently ";
385 language
= concat(prefix
, current_language
->la_name
, NULL
);
391 char *tmp
, *prefix
= "";
394 if (type_mode
==type_mode_auto
)
395 prefix
= "auto; currently ";
405 case type_check_warn
:
409 error ("Unrecognized type check setting.");
412 type
= concat(prefix
,tmp
,NULL
);
418 char *tmp
, *pref
= "";
421 if (range_mode
==range_mode_auto
)
422 pref
= "auto; currently ";
429 case range_check_off
:
432 case range_check_warn
:
436 error ("Unrecognized range check setting.");
439 range
= concat(pref
,tmp
,NULL
);
443 /* Print out the current language settings: language, range and
444 type checking. If QUIETLY, print only what has changed. */
447 language_info (quietly
)
450 if (quietly
&& expected_language
== current_language
)
453 expected_language
= current_language
;
454 printf_unfiltered("Current language: %s\n",language
);
455 show_language_command((char *)0, 1);
459 printf_unfiltered("Type checking: %s\n",type
);
460 show_type_command((char *)0, 1);
461 printf_unfiltered("Range checking: %s\n",range
);
462 show_range_command((char *)0, 1);
466 /* Return the result of a binary operation. */
468 #if 0 /* Currently unused */
471 binop_result_type (v1
, v2
)
475 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
476 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
478 int l1
= TYPE_LENGTH (t1
);
479 int l2
= TYPE_LENGTH (t2
);
481 switch(current_language
->la_language
)
485 if (TYPE_CODE (t1
)==TYPE_CODE_FLT
)
486 return TYPE_CODE(t2
) == TYPE_CODE_FLT
&& l2
> l1
?
487 VALUE_TYPE(v2
) : VALUE_TYPE(v1
);
488 else if (TYPE_CODE(t2
)==TYPE_CODE_FLT
)
489 return TYPE_CODE(t1
)) == TYPE_CODE_FLT
&& l1
> l2
?
490 VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
491 else if (TYPE_UNSIGNED(t1
) && l1
> l2
)
492 return VALUE_TYPE(v1
);
493 else if (TYPE_UNSIGNED(t2
) && l2
> l1
)
494 return VALUE_TYPE(v2
);
495 else /* Both are signed. Result is the longer type */
496 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
499 /* If we are doing type-checking, l1 should equal l2, so this is
501 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
504 error ("Missing Chill support in function binop_result_check.");/*FIXME*/
507 return (struct type
*)0; /* For lint */
513 /* This page contains functions that return format strings for
514 printf for printing out numbers in different formats */
516 /* Returns the appropriate printf format for hexadecimal
519 local_hex_format_custom(pre
)
522 static char form
[50];
524 strcpy (form
, local_hex_format_prefix ());
527 strcat (form
, local_hex_format_specifier ());
528 strcat (form
, local_hex_format_suffix ());
532 /* Converts a number to hexadecimal and stores it in a static
533 string. Returns a pointer to this string. */
535 local_hex_string (num
)
540 sprintf (res
, local_hex_format(), num
);
544 /* Converts a number to custom hexadecimal and stores it in a static
545 string. Returns a pointer to this string. */
547 local_hex_string_custom(num
,pre
)
553 sprintf (res
, local_hex_format_custom(pre
), num
);
557 /* Returns the appropriate printf format for octal
560 local_octal_format_custom(pre
)
563 static char form
[50];
565 strcpy (form
, local_octal_format_prefix ());
568 strcat (form
, local_octal_format_specifier ());
569 strcat (form
, local_octal_format_suffix ());
573 /* Returns the appropriate printf format for decimal numbers. */
575 local_decimal_format_custom(pre
)
578 static char form
[50];
580 strcpy (form
, local_decimal_format_prefix ());
583 strcat (form
, local_decimal_format_specifier ());
584 strcat (form
, local_decimal_format_suffix ());
589 /* This page contains functions that are used in type/range checking.
590 They all return zero if the type/range check fails.
592 It is hoped that these will make extending GDB to parse different
593 languages a little easier. These are primarily used in eval.c when
594 evaluating expressions and making sure that their types are correct.
595 Instead of having a mess of conjucted/disjuncted expressions in an "if",
596 the ideas of type can be wrapped up in the following functions.
598 Note that some of them are not currently dependent upon which language
599 is currently being parsed. For example, floats are the same in
600 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
601 TYPE_CODE_FLT), while booleans are different. */
603 /* Returns non-zero if its argument is a simple type. This is the same for
604 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
605 and thus will never cause the failure of the test. */
610 CHECK_TYPEDEF (type
);
611 switch (TYPE_CODE (type
)) {
616 case TYPE_CODE_RANGE
:
625 /* Returns non-zero if its argument is of an ordered type.
626 An ordered type is one in which the elements can be tested for the
627 properties of "greater than", "less than", etc, or for which the
628 operations "increment" or "decrement" make sense. */
633 CHECK_TYPEDEF (type
);
634 switch (TYPE_CODE (type
)) {
639 case TYPE_CODE_RANGE
:
647 /* Returns non-zero if the two types are the same */
649 same_type (arg1
, arg2
)
650 struct type
*arg1
, *arg2
;
652 CHECK_TYPEDEF (type
);
653 if (structured_type(arg1
) ? !structured_type(arg2
) : structured_type(arg2
))
654 /* One is structured and one isn't */
656 else if (structured_type(arg1
) && structured_type(arg2
))
658 else if (numeric_type(arg1
) && numeric_type(arg2
))
659 return (TYPE_CODE(arg2
) == TYPE_CODE(arg1
)) &&
660 (TYPE_UNSIGNED(arg1
) == TYPE_UNSIGNED(arg2
))
666 /* Returns non-zero if the type is integral */
671 CHECK_TYPEDEF (type
);
672 switch(current_language
->la_language
)
676 return (TYPE_CODE(type
) != TYPE_CODE_INT
) &&
677 (TYPE_CODE(type
) != TYPE_CODE_ENUM
) ? 0 : 1;
679 return TYPE_CODE(type
) != TYPE_CODE_INT
? 0 : 1;
681 error ("Missing Chill support in function integral_type."); /*FIXME*/
683 error ("Language not supported.");
687 /* Returns non-zero if the value is numeric */
692 CHECK_TYPEDEF (type
);
693 switch (TYPE_CODE (type
)) {
703 /* Returns non-zero if the value is a character type */
705 character_type (type
)
708 CHECK_TYPEDEF (type
);
709 switch(current_language
->la_language
)
713 return TYPE_CODE(type
) != TYPE_CODE_CHAR
? 0 : 1;
717 return (TYPE_CODE(type
) == TYPE_CODE_INT
) &&
718 TYPE_LENGTH(type
) == sizeof(char)
725 /* Returns non-zero if the value is a string type */
730 CHECK_TYPEDEF (type
);
731 switch(current_language
->la_language
)
735 return TYPE_CODE(type
) != TYPE_CODE_STRING
? 0 : 1;
739 /* C does not have distinct string type. */
746 /* Returns non-zero if the value is a boolean type */
751 CHECK_TYPEDEF (type
);
752 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
754 switch(current_language
->la_language
)
758 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
759 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
760 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
768 /* Returns non-zero if the value is a floating-point type */
773 CHECK_TYPEDEF (type
);
774 return TYPE_CODE(type
) == TYPE_CODE_FLT
;
777 /* Returns non-zero if the value is a pointer type */
782 return TYPE_CODE(type
) == TYPE_CODE_PTR
||
783 TYPE_CODE(type
) == TYPE_CODE_REF
;
786 /* Returns non-zero if the value is a structured type */
788 structured_type(type
)
791 CHECK_TYPEDEF (type
);
792 switch(current_language
->la_language
)
796 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
797 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
798 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
800 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
801 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
802 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
804 error ("Missing Chill support in function structured_type."); /*FIXME*/
816 switch(current_language
->la_language
)
819 return builtin_type_chill_bool
;
820 case language_fortran
:
821 sym
= lookup_symbol ("logical", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
824 type
= SYMBOL_TYPE (sym
);
825 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
828 return builtin_type_f_logical_s2
;
830 sym
= lookup_symbol ("bool", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
833 type
= SYMBOL_TYPE (sym
);
834 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
837 return builtin_type_bool
;
839 return builtin_type_int
;
843 /* This page contains functions that return info about
844 (struct value) values used in GDB. */
846 /* Returns non-zero if the value VAL represents a true value. */
851 /* It is possible that we should have some sort of error if a non-boolean
852 value is used in this context. Possibly dependent on some kind of
853 "boolean-checking" option like range checking. But it should probably
854 not depend on the language except insofar as is necessary to identify
855 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
856 should be an error, probably). */
857 return !value_logical_not (val
);
860 /* Returns non-zero if the operator OP is defined on
861 the values ARG1 and ARG2. */
863 #if 0 /* Currently unused */
866 binop_type_check(arg1
,arg2
,op
)
870 struct type
*t1
, *t2
;
872 /* If we're not checking types, always return success. */
886 if ((numeric_type(t1
) && pointer_type(t2
)) ||
887 (pointer_type(t1
) && numeric_type(t2
)))
889 warning ("combining pointer and integer.\n");
895 if (!numeric_type(t1
) || !numeric_type(t2
))
896 type_op_error ("Arguments to %s must be numbers.",op
);
897 else if (!same_type(t1
,t2
))
898 type_op_error ("Arguments to %s must be of the same type.",op
);
901 case BINOP_LOGICAL_AND
:
902 case BINOP_LOGICAL_OR
:
903 if (!boolean_type(t1
) || !boolean_type(t2
))
904 type_op_error ("Arguments to %s must be of boolean type.",op
);
908 if ((pointer_type(t1
) && !(pointer_type(t2
) || integral_type(t2
))) ||
909 (pointer_type(t2
) && !(pointer_type(t1
) || integral_type(t1
))))
910 type_op_error ("A pointer can only be compared to an integer or pointer.",op
);
911 else if ((pointer_type(t1
) && integral_type(t2
)) ||
912 (integral_type(t1
) && pointer_type(t2
)))
914 warning ("combining integer and pointer.\n");
917 else if (!simple_type(t1
) || !simple_type(t2
))
918 type_op_error ("Arguments to %s must be of simple type.",op
);
919 else if (!same_type(t1
,t2
))
920 type_op_error ("Arguments to %s must be of the same type.",op
);
925 if (!integral_type(t1
) || !integral_type(t2
))
926 type_op_error ("Arguments to %s must be of integral type.",op
);
933 if (!ordered_type(t1
) || !ordered_type(t2
))
934 type_op_error ("Arguments to %s must be of ordered type.",op
);
935 else if (!same_type(t1
,t2
))
936 type_op_error ("Arguments to %s must be of the same type.",op
);
940 if (pointer_type(t1
) && !integral_type(t2
))
941 type_op_error ("A pointer can only be assigned an integer.",op
);
942 else if (pointer_type(t1
) && integral_type(t2
))
944 warning ("combining integer and pointer.");
947 else if (!simple_type(t1
) || !simple_type(t2
))
948 type_op_error ("Arguments to %s must be of simple type.",op
);
949 else if (!same_type(t1
,t2
))
950 type_op_error ("Arguments to %s must be of the same type.",op
);
954 /* FIXME: Needs to handle bitstrings as well. */
955 if (!(string_type(t1
) || character_type(t1
) || integral_type(t1
))
956 || !(string_type(t2
) || character_type(t2
) || integral_type(t2
)))
957 type_op_error ("Arguments to %s must be strings or characters.", op
);
960 /* Unary checks -- arg2 is null */
962 case UNOP_LOGICAL_NOT
:
963 if (!boolean_type(t1
))
964 type_op_error ("Argument to %s must be of boolean type.",op
);
969 if (!numeric_type(t1
))
970 type_op_error ("Argument to %s must be of numeric type.",op
);
974 if (integral_type(t1
))
976 warning ("combining pointer and integer.\n");
979 else if (!pointer_type(t1
))
980 type_op_error ("Argument to %s must be a pointer.",op
);
983 case UNOP_PREINCREMENT
:
984 case UNOP_POSTINCREMENT
:
985 case UNOP_PREDECREMENT
:
986 case UNOP_POSTDECREMENT
:
987 if (!ordered_type(t1
))
988 type_op_error ("Argument to %s must be of an ordered type.",op
);
992 /* Ok. The following operators have different meanings in
993 different languages. */
994 switch(current_language
->la_language
)
1002 if (!numeric_type(t1
) || !numeric_type(t2
))
1003 type_op_error ("Arguments to %s must be numbers.",op
);
1014 if (!float_type(t1
) || !float_type(t2
))
1015 type_op_error ("Arguments to %s must be floating point numbers.",op
);
1018 if (!integral_type(t1
) || !integral_type(t2
))
1019 type_op_error ("Arguments to %s must be of integral type.",op
);
1025 case language_chill
:
1026 error ("Missing Chill support in function binop_type_check.");/*FIXME*/
1036 /* This page contains functions for the printing out of
1037 error messages that occur during type- and range-
1040 /* Prints the format string FMT with the operator as a string
1041 corresponding to the opcode OP. If FATAL is non-zero, then
1042 this is an error and error () is called. Otherwise, it is
1043 a warning and printf() is called. */
1045 op_error (fmt
,op
,fatal
)
1051 error (fmt
,op_string(op
));
1054 warning (fmt
,op_string(op
));
1058 /* These are called when a language fails a type- or range-check.
1059 The first argument should be a printf()-style format string, and
1060 the rest of the arguments should be its arguments. If
1061 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1062 is called in the style of error (). Otherwise, the message is prefixed
1063 by the value of warning_pre_print and we do not return to the top level. */
1066 #ifdef ANSI_PROTOTYPES
1067 type_error (char *string
, ...)
1069 type_error (va_alist
)
1074 #ifdef ANSI_PROTOTYPES
1075 va_start (args
, string
);
1079 string
= va_arg (args
, char *);
1082 if (type_check
== type_check_warn
)
1083 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1087 vfprintf_filtered (gdb_stderr
, string
, args
);
1088 fprintf_filtered (gdb_stderr
, "\n");
1090 if (type_check
== type_check_on
)
1091 return_to_top_level (RETURN_ERROR
);
1095 #ifdef ANSI_PROTOTYPES
1096 range_error (char *string
, ...)
1098 range_error (va_alist
)
1103 #ifdef ANSI_PROTOTYPES
1104 va_start (args
, string
);
1108 string
= va_arg (args
, char *);
1111 if (range_check
== range_check_warn
)
1112 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1116 vfprintf_filtered (gdb_stderr
, string
, args
);
1117 fprintf_filtered (gdb_stderr
, "\n");
1119 if (range_check
== range_check_on
)
1120 return_to_top_level (RETURN_ERROR
);
1124 /* This page contains miscellaneous functions */
1126 /* Return the language enum for a given language string. */
1134 for (i
= 0; i
< languages_size
; i
++)
1135 if (STREQ (languages
[i
]->la_name
, str
))
1136 return languages
[i
]->la_language
;
1138 return language_unknown
;
1141 /* Return the language struct for a given language enum. */
1143 const struct language_defn
*
1149 for (i
= 0; i
< languages_size
; i
++) {
1150 if (languages
[i
]->la_language
== lang
) {
1151 return languages
[i
];
1157 /* Return the language as a string */
1164 for (i
= 0; i
< languages_size
; i
++) {
1165 if (languages
[i
]->la_language
== lang
) {
1166 return languages
[i
]->la_name
;
1173 set_check (ignore
, from_tty
)
1178 "\"set check\" must be followed by the name of a check subcommand.\n");
1179 help_list(setchecklist
, "set check ", -1, gdb_stdout
);
1183 show_check (ignore
, from_tty
)
1187 cmd_show_list(showchecklist
, from_tty
, "");
1190 /* Add a language to the set of known languages. */
1194 const struct language_defn
*lang
;
1196 if (lang
->la_magic
!= LANG_MAGIC
)
1198 fprintf_unfiltered(gdb_stderr
, "Magic number of %s language struct wrong\n",
1205 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1206 languages
= (const struct language_defn
**) xmalloc
1207 (languages_allocsize
* sizeof (*languages
));
1209 if (languages_size
>= languages_allocsize
)
1211 languages_allocsize
*= 2;
1212 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1213 languages_allocsize
* sizeof (*languages
));
1215 languages
[languages_size
++] = lang
;
1218 /* Define the language that is no language. */
1227 unk_lang_error (msg
)
1230 error ("Attempted to parse an expression with unknown language");
1234 unk_lang_emit_char (c
, stream
, quoter
)
1239 error ("internal error - unimplemented function unk_lang_emit_char called.");
1243 unk_lang_printchar (c
, stream
)
1247 error ("internal error - unimplemented function unk_lang_printchar called.");
1251 unk_lang_printstr (stream
, string
, length
, width
, force_ellipses
)
1254 unsigned int length
;
1258 error ("internal error - unimplemented function unk_lang_printstr called.");
1261 static struct type
*
1262 unk_lang_create_fundamental_type (objfile
, typeid)
1263 struct objfile
*objfile
;
1266 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1270 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1277 error ("internal error - unimplemented function unk_lang_print_type called.");
1281 unk_lang_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
, deref_ref
,
1285 int embedded_offset
;
1291 enum val_prettyprint pretty
;
1293 error ("internal error - unimplemented function unk_lang_val_print called.");
1297 unk_lang_value_print (val
, stream
, format
, pretty
)
1301 enum val_prettyprint pretty
;
1303 error ("internal error - unimplemented function unk_lang_value_print called.");
1306 static struct type
** CONST_PTR (unknown_builtin_types
[]) = { 0 };
1307 static const struct op_print unk_op_print_tab
[] = {
1308 {NULL
, OP_NULL
, PREC_NULL
, 0}
1311 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
= {
1342 &unknown_builtin_types
[0],
1347 evaluate_subexp_standard
,
1348 unk_lang_printchar
, /* Print character constant */
1351 unk_lang_create_fundamental_type
,
1352 unk_lang_print_type
, /* Print a type using appropriate syntax */
1353 unk_lang_val_print
, /* Print a value using appropriate syntax */
1354 unk_lang_value_print
, /* Print a top-level value */
1355 {"", "", "", ""}, /* Binary format info */
1356 {"0%lo", "0", "o", ""}, /* Octal format info */
1357 {"%ld", "", "d", ""}, /* Decimal format info */
1358 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1359 unk_op_print_tab
, /* expression operators for printing */
1360 1, /* c-style arrays */
1361 0, /* String lower bound */
1362 &builtin_type_char
, /* Type of string elements */
1366 const struct language_defn local_language_defn
= {
1369 &unknown_builtin_types
[0],
1374 evaluate_subexp_standard
,
1375 unk_lang_printchar
, /* Print character constant */
1378 unk_lang_create_fundamental_type
,
1379 unk_lang_print_type
, /* Print a type using appropriate syntax */
1380 unk_lang_val_print
, /* Print a value using appropriate syntax */
1381 unk_lang_value_print
, /* Print a top-level value */
1382 {"", "", "", ""}, /* Binary format info */
1383 {"0%lo", "0", "o", ""}, /* Octal format info */
1384 {"%ld", "", "d", ""}, /* Decimal format info */
1385 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1386 unk_op_print_tab
, /* expression operators for printing */
1387 1, /* c-style arrays */
1388 0, /* String lower bound */
1389 &builtin_type_char
, /* Type of string elements */
1393 /* Initialize the language routines */
1396 _initialize_language()
1398 struct cmd_list_element
*set
, *show
;
1400 /* GDB commands for language specific stuff */
1402 set
= add_set_cmd ("language", class_support
, var_string_noescape
,
1404 "Set the current source language.",
1406 show
= add_show_from_set (set
, &showlist
);
1407 set
->function
.cfunc
= set_language_command
;
1408 show
->function
.cfunc
= show_language_command
;
1410 add_prefix_cmd ("check", no_class
, set_check
,
1411 "Set the status of the type/range checker",
1412 &setchecklist
, "set check ", 0, &setlist
);
1413 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1414 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1416 add_prefix_cmd ("check", no_class
, show_check
,
1417 "Show the status of the type/range checker",
1418 &showchecklist
, "show check ", 0, &showlist
);
1419 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1420 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1422 set
= add_set_cmd ("type", class_support
, var_string_noescape
,
1424 "Set type checking. (on/warn/off/auto)",
1426 show
= add_show_from_set (set
, &showchecklist
);
1427 set
->function
.cfunc
= set_type_command
;
1428 show
->function
.cfunc
= show_type_command
;
1430 set
= add_set_cmd ("range", class_support
, var_string_noescape
,
1432 "Set range checking. (on/warn/off/auto)",
1434 show
= add_show_from_set (set
, &showchecklist
);
1435 set
->function
.cfunc
= set_range_command
;
1436 show
->function
.cfunc
= show_range_command
;
1438 add_language (&unknown_language_defn
);
1439 add_language (&local_language_defn
);
1440 add_language (&auto_language_defn
);
1442 language
= savestring ("auto",strlen("auto"));
1443 range
= savestring ("auto",strlen("auto"));
1444 type
= savestring ("auto",strlen("auto"));
1446 /* Have the above take effect */
1448 set_language_command (language
, 0);
1449 set_type_command (NULL
, 0);
1450 set_range_command (NULL
, 0);