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_printchar
PARAMS ((int, GDB_FILE
*));
90 unk_lang_printstr
PARAMS ((GDB_FILE
*, char *, unsigned int, int));
93 unk_lang_create_fundamental_type
PARAMS ((struct objfile
*, int));
96 unk_lang_print_type
PARAMS ((struct type
*, char *, GDB_FILE
*, int, int));
99 unk_lang_val_print
PARAMS ((struct type
*, char *, CORE_ADDR
, GDB_FILE
*,
100 int, int, int, enum val_prettyprint
));
103 unk_lang_value_print
PARAMS ((value_ptr
, GDB_FILE
*, int, enum val_prettyprint
));
105 /* Forward declaration */
106 extern const struct language_defn unknown_language_defn
;
107 extern char *warning_pre_print
;
109 /* The current (default at startup) state of type and range checking.
110 (If the modes are set to "auto", though, these are changed based
111 on the default language at startup, and then again based on the
112 language of the first source file. */
114 enum range_mode range_mode
= range_mode_auto
;
115 enum range_check range_check
= range_check_off
;
116 enum type_mode type_mode
= type_mode_auto
;
117 enum type_check type_check
= type_check_off
;
119 /* The current language and language_mode (see language.h) */
121 const struct language_defn
*current_language
= &unknown_language_defn
;
122 enum language_mode language_mode
= language_mode_auto
;
124 /* The language that the user expects to be typing in (the language
125 of main(), or the last language we notified them about, or C). */
127 const struct language_defn
*expected_language
;
129 /* The list of supported languages. The list itself is malloc'd. */
131 static const struct language_defn
**languages
;
132 static unsigned languages_size
;
133 static unsigned languages_allocsize
;
134 #define DEFAULT_ALLOCSIZE 4
136 /* The "set language/type/range" commands all put stuff in these
137 buffers. This is to make them work as set/show commands. The
138 user's string is copied here, then the set_* commands look at
139 them and update them to something that looks nice when it is
142 static char *language
;
146 /* Warning issued when current_language and the language of the current
147 frame do not match. */
148 char lang_frame_mismatch_warn
[] =
149 "Warning: the current language does not match this frame.";
152 /* This page contains the functions corresponding to GDB commands
153 and their helpers. */
155 /* Show command. Display a warning if the language set
156 does not match the frame. */
158 show_language_command (ignore
, from_tty
)
162 enum language flang
; /* The language of the current frame */
164 flang
= get_frame_language();
165 if (flang
!= language_unknown
&&
166 language_mode
== language_mode_manual
&&
167 current_language
->la_language
!= flang
)
168 printf_filtered("%s\n",lang_frame_mismatch_warn
);
171 /* Set command. Change the current working language. */
173 set_language_command (ignore
, from_tty
)
181 if (!language
|| !language
[0])
183 printf_unfiltered("The currently understood settings are:\n\n");
184 printf_unfiltered ("local or auto Automatic setting based on source file\n");
186 for (i
= 0; i
< languages_size
; ++i
)
188 /* Already dealt with these above. */
189 if (languages
[i
]->la_language
== language_unknown
190 || languages
[i
]->la_language
== language_auto
)
193 /* FIXME for now assume that the human-readable name is just
194 a capitalization of the internal name. */
195 printf_unfiltered ("%-16s Use the %c%s language\n",
196 languages
[i
]->la_name
,
197 /* Capitalize first letter of language
199 toupper (languages
[i
]->la_name
[0]),
200 languages
[i
]->la_name
+ 1);
202 /* Restore the silly string. */
203 set_language(current_language
->la_language
);
207 /* Search the list of languages for a match. */
208 for (i
= 0; i
< languages_size
; i
++) {
209 if (STREQ (languages
[i
]->la_name
, language
)) {
210 /* Found it! Go into manual mode, and use this language. */
211 if (languages
[i
]->la_language
== language_auto
) {
212 /* Enter auto mode. Set to the current frame's language, if known. */
213 language_mode
= language_mode_auto
;
214 flang
= get_frame_language();
215 if (flang
!=language_unknown
)
217 expected_language
= current_language
;
220 /* Enter manual mode. Set the specified language. */
221 language_mode
= language_mode_manual
;
222 current_language
= languages
[i
];
225 expected_language
= current_language
;
231 /* Reset the language (esp. the global string "language") to the
233 err_lang
=savestring(language
,strlen(language
));
234 make_cleanup (free
, err_lang
); /* Free it after error */
235 set_language(current_language
->la_language
);
236 error ("Unknown language `%s'.",err_lang
);
239 /* Show command. Display a warning if the type setting does
240 not match the current language. */
242 show_type_command(ignore
, from_tty
)
246 if (type_check
!= current_language
->la_type_check
)
248 "Warning: the current type check setting does not match the language.\n");
251 /* Set command. Change the setting for type checking. */
253 set_type_command(ignore
, from_tty
)
257 if (STREQ(type
,"on"))
259 type_check
= type_check_on
;
260 type_mode
= type_mode_manual
;
262 else if (STREQ(type
,"warn"))
264 type_check
= type_check_warn
;
265 type_mode
= type_mode_manual
;
267 else if (STREQ(type
,"off"))
269 type_check
= type_check_off
;
270 type_mode
= type_mode_manual
;
272 else if (STREQ(type
,"auto"))
274 type_mode
= type_mode_auto
;
276 /* Avoid hitting the set_type_str call below. We
277 did it in set_type_range. */
281 show_type_command((char *)NULL
, from_tty
);
284 /* Show command. Display a warning if the range setting does
285 not match the current language. */
287 show_range_command(ignore
, from_tty
)
292 if (range_check
!= current_language
->la_range_check
)
294 "Warning: the current range check setting does not match the language.\n");
297 /* Set command. Change the setting for range checking. */
299 set_range_command(ignore
, from_tty
)
303 if (STREQ(range
,"on"))
305 range_check
= range_check_on
;
306 range_mode
= range_mode_manual
;
308 else if (STREQ(range
,"warn"))
310 range_check
= range_check_warn
;
311 range_mode
= range_mode_manual
;
313 else if (STREQ(range
,"off"))
315 range_check
= range_check_off
;
316 range_mode
= range_mode_manual
;
318 else if (STREQ(range
,"auto"))
320 range_mode
= range_mode_auto
;
322 /* Avoid hitting the set_range_str call below. We
323 did it in set_type_range. */
327 show_range_command((char *)0, from_tty
);
330 /* Set the status of range and type checking based on
331 the current modes and the current language.
332 If SHOW is non-zero, then print out the current language,
333 type and range checking status. */
338 if (range_mode
== range_mode_auto
)
339 range_check
= current_language
->la_range_check
;
341 if (type_mode
== type_mode_auto
)
342 type_check
= current_language
->la_type_check
;
348 /* Set current language to (enum language) LANG. */
356 for (i
= 0; i
< languages_size
; i
++) {
357 if (languages
[i
]->la_language
== lang
) {
358 current_language
= languages
[i
];
366 /* This page contains functions that update the global vars
367 language, type and range. */
374 if (language_mode
== language_mode_auto
)
375 prefix
= "auto; currently ";
377 language
= concat(prefix
, current_language
->la_name
, NULL
);
383 char *tmp
, *prefix
= "";
386 if (type_mode
==type_mode_auto
)
387 prefix
= "auto; currently ";
397 case type_check_warn
:
401 error ("Unrecognized type check setting.");
404 type
= concat(prefix
,tmp
,NULL
);
410 char *tmp
, *pref
= "";
413 if (range_mode
==range_mode_auto
)
414 pref
= "auto; currently ";
421 case range_check_off
:
424 case range_check_warn
:
428 error ("Unrecognized range check setting.");
431 range
= concat(pref
,tmp
,NULL
);
435 /* Print out the current language settings: language, range and
436 type checking. If QUIETLY, print only what has changed. */
439 language_info (quietly
)
442 if (quietly
&& expected_language
== current_language
)
445 expected_language
= current_language
;
446 printf_unfiltered("Current language: %s\n",language
);
447 show_language_command((char *)0, 1);
451 printf_unfiltered("Type checking: %s\n",type
);
452 show_type_command((char *)0, 1);
453 printf_unfiltered("Range checking: %s\n",range
);
454 show_range_command((char *)0, 1);
458 /* Return the result of a binary operation. */
460 #if 0 /* Currently unused */
463 binop_result_type (v1
, v2
)
467 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
468 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
470 int l1
= TYPE_LENGTH (t1
);
471 int l2
= TYPE_LENGTH (t2
);
473 switch(current_language
->la_language
)
477 if (TYPE_CODE (t1
)==TYPE_CODE_FLT
)
478 return TYPE_CODE(t2
) == TYPE_CODE_FLT
&& l2
> l1
?
479 VALUE_TYPE(v2
) : VALUE_TYPE(v1
);
480 else if (TYPE_CODE(t2
)==TYPE_CODE_FLT
)
481 return TYPE_CODE(t1
)) == TYPE_CODE_FLT
&& l1
> l2
?
482 VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
483 else if (TYPE_UNSIGNED(t1
) && l1
> l2
)
484 return VALUE_TYPE(v1
);
485 else if (TYPE_UNSIGNED(t2
) && l2
> l1
)
486 return VALUE_TYPE(v2
);
487 else /* Both are signed. Result is the longer type */
488 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
491 /* If we are doing type-checking, l1 should equal l2, so this is
493 return l1
> l2
? VALUE_TYPE(v1
) : VALUE_TYPE(v2
);
496 error ("Missing Chill support in function binop_result_check.");/*FIXME*/
499 return (struct type
*)0; /* For lint */
505 /* This page contains functions that return format strings for
506 printf for printing out numbers in different formats */
508 /* Returns the appropriate printf format for hexadecimal
511 local_hex_format_custom(pre
)
514 static char form
[50];
516 strcpy (form
, local_hex_format_prefix ());
519 strcat (form
, local_hex_format_specifier ());
520 strcat (form
, local_hex_format_suffix ());
524 /* Converts a number to hexadecimal and stores it in a static
525 string. Returns a pointer to this string. */
527 local_hex_string (num
)
532 sprintf (res
, local_hex_format(), num
);
536 /* Converts a number to custom hexadecimal and stores it in a static
537 string. Returns a pointer to this string. */
539 local_hex_string_custom(num
,pre
)
545 sprintf (res
, local_hex_format_custom(pre
), num
);
549 /* Returns the appropriate printf format for octal
552 local_octal_format_custom(pre
)
555 static char form
[50];
557 strcpy (form
, local_octal_format_prefix ());
560 strcat (form
, local_octal_format_specifier ());
561 strcat (form
, local_octal_format_suffix ());
565 /* Returns the appropriate printf format for decimal numbers. */
567 local_decimal_format_custom(pre
)
570 static char form
[50];
572 strcpy (form
, local_decimal_format_prefix ());
575 strcat (form
, local_decimal_format_specifier ());
576 strcat (form
, local_decimal_format_suffix ());
581 /* This page contains functions that are used in type/range checking.
582 They all return zero if the type/range check fails.
584 It is hoped that these will make extending GDB to parse different
585 languages a little easier. These are primarily used in eval.c when
586 evaluating expressions and making sure that their types are correct.
587 Instead of having a mess of conjucted/disjuncted expressions in an "if",
588 the ideas of type can be wrapped up in the following functions.
590 Note that some of them are not currently dependent upon which language
591 is currently being parsed. For example, floats are the same in
592 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
593 TYPE_CODE_FLT), while booleans are different. */
595 /* Returns non-zero if its argument is a simple type. This is the same for
596 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
597 and thus will never cause the failure of the test. */
602 CHECK_TYPEDEF (type
);
603 switch (TYPE_CODE (type
)) {
608 case TYPE_CODE_RANGE
:
617 /* Returns non-zero if its argument is of an ordered type.
618 An ordered type is one in which the elements can be tested for the
619 properties of "greater than", "less than", etc, or for which the
620 operations "increment" or "decrement" make sense. */
625 CHECK_TYPEDEF (type
);
626 switch (TYPE_CODE (type
)) {
631 case TYPE_CODE_RANGE
:
639 /* Returns non-zero if the two types are the same */
641 same_type (arg1
, arg2
)
642 struct type
*arg1
, *arg2
;
644 CHECK_TYPEDEF (type
);
645 if (structured_type(arg1
) ? !structured_type(arg2
) : structured_type(arg2
))
646 /* One is structured and one isn't */
648 else if (structured_type(arg1
) && structured_type(arg2
))
650 else if (numeric_type(arg1
) && numeric_type(arg2
))
651 return (TYPE_CODE(arg2
) == TYPE_CODE(arg1
)) &&
652 (TYPE_UNSIGNED(arg1
) == TYPE_UNSIGNED(arg2
))
658 /* Returns non-zero if the type is integral */
663 CHECK_TYPEDEF (type
);
664 switch(current_language
->la_language
)
668 return (TYPE_CODE(type
) != TYPE_CODE_INT
) &&
669 (TYPE_CODE(type
) != TYPE_CODE_ENUM
) ? 0 : 1;
671 return TYPE_CODE(type
) != TYPE_CODE_INT
? 0 : 1;
673 error ("Missing Chill support in function integral_type."); /*FIXME*/
675 error ("Language not supported.");
679 /* Returns non-zero if the value is numeric */
684 CHECK_TYPEDEF (type
);
685 switch (TYPE_CODE (type
)) {
695 /* Returns non-zero if the value is a character type */
697 character_type (type
)
700 CHECK_TYPEDEF (type
);
701 switch(current_language
->la_language
)
705 return TYPE_CODE(type
) != TYPE_CODE_CHAR
? 0 : 1;
709 return (TYPE_CODE(type
) == TYPE_CODE_INT
) &&
710 TYPE_LENGTH(type
) == sizeof(char)
717 /* Returns non-zero if the value is a string type */
722 CHECK_TYPEDEF (type
);
723 switch(current_language
->la_language
)
727 return TYPE_CODE(type
) != TYPE_CODE_STRING
? 0 : 1;
731 /* C does not have distinct string type. */
738 /* Returns non-zero if the value is a boolean type */
743 CHECK_TYPEDEF (type
);
744 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
746 switch(current_language
->la_language
)
750 /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL
751 for CHILL and such languages, or a TYPE_CODE_INT_OR_BOOL for C. */
752 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
760 /* Returns non-zero if the value is a floating-point type */
765 CHECK_TYPEDEF (type
);
766 return TYPE_CODE(type
) == TYPE_CODE_FLT
;
769 /* Returns non-zero if the value is a pointer type */
774 return TYPE_CODE(type
) == TYPE_CODE_PTR
||
775 TYPE_CODE(type
) == TYPE_CODE_REF
;
778 /* Returns non-zero if the value is a structured type */
780 structured_type(type
)
783 CHECK_TYPEDEF (type
);
784 switch(current_language
->la_language
)
788 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
789 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
790 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
792 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
793 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
794 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
796 error ("Missing Chill support in function structured_type."); /*FIXME*/
808 switch(current_language
->la_language
)
811 return builtin_type_chill_bool
;
812 case language_fortran
:
813 sym
= lookup_symbol ("logical", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
816 type
= SYMBOL_TYPE (sym
);
817 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
820 return builtin_type_f_logical_s2
;
822 sym
= lookup_symbol ("bool", NULL
, VAR_NAMESPACE
, NULL
, NULL
);
825 type
= SYMBOL_TYPE (sym
);
826 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
829 /* ... else fall through ... */
831 return builtin_type_int
;
835 /* This page contains functions that return info about
836 (struct value) values used in GDB. */
838 /* Returns non-zero if the value VAL represents a true value. */
843 /* It is possible that we should have some sort of error if a non-boolean
844 value is used in this context. Possibly dependent on some kind of
845 "boolean-checking" option like range checking. But it should probably
846 not depend on the language except insofar as is necessary to identify
847 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
848 should be an error, probably). */
849 return !value_logical_not (val
);
852 /* Returns non-zero if the operator OP is defined on
853 the values ARG1 and ARG2. */
855 #if 0 /* Currently unused */
858 binop_type_check(arg1
,arg2
,op
)
862 struct type
*t1
, *t2
;
864 /* If we're not checking types, always return success. */
878 if ((numeric_type(t1
) && pointer_type(t2
)) ||
879 (pointer_type(t1
) && numeric_type(t2
)))
881 warning ("combining pointer and integer.\n");
887 if (!numeric_type(t1
) || !numeric_type(t2
))
888 type_op_error ("Arguments to %s must be numbers.",op
);
889 else if (!same_type(t1
,t2
))
890 type_op_error ("Arguments to %s must be of the same type.",op
);
893 case BINOP_LOGICAL_AND
:
894 case BINOP_LOGICAL_OR
:
895 if (!boolean_type(t1
) || !boolean_type(t2
))
896 type_op_error ("Arguments to %s must be of boolean type.",op
);
900 if ((pointer_type(t1
) && !(pointer_type(t2
) || integral_type(t2
))) ||
901 (pointer_type(t2
) && !(pointer_type(t1
) || integral_type(t1
))))
902 type_op_error ("A pointer can only be compared to an integer or pointer.",op
);
903 else if ((pointer_type(t1
) && integral_type(t2
)) ||
904 (integral_type(t1
) && pointer_type(t2
)))
906 warning ("combining integer and pointer.\n");
909 else if (!simple_type(t1
) || !simple_type(t2
))
910 type_op_error ("Arguments to %s must be of simple type.",op
);
911 else if (!same_type(t1
,t2
))
912 type_op_error ("Arguments to %s must be of the same type.",op
);
917 if (!integral_type(t1
) || !integral_type(t2
))
918 type_op_error ("Arguments to %s must be of integral type.",op
);
925 if (!ordered_type(t1
) || !ordered_type(t2
))
926 type_op_error ("Arguments to %s must be of ordered type.",op
);
927 else if (!same_type(t1
,t2
))
928 type_op_error ("Arguments to %s must be of the same type.",op
);
932 if (pointer_type(t1
) && !integral_type(t2
))
933 type_op_error ("A pointer can only be assigned an integer.",op
);
934 else if (pointer_type(t1
) && integral_type(t2
))
936 warning ("combining integer and pointer.");
939 else if (!simple_type(t1
) || !simple_type(t2
))
940 type_op_error ("Arguments to %s must be of simple type.",op
);
941 else if (!same_type(t1
,t2
))
942 type_op_error ("Arguments to %s must be of the same type.",op
);
946 /* FIXME: Needs to handle bitstrings as well. */
947 if (!(string_type(t1
) || character_type(t1
) || integral_type(t1
))
948 || !(string_type(t2
) || character_type(t2
) || integral_type(t2
)))
949 type_op_error ("Arguments to %s must be strings or characters.", op
);
952 /* Unary checks -- arg2 is null */
954 case UNOP_LOGICAL_NOT
:
955 if (!boolean_type(t1
))
956 type_op_error ("Argument to %s must be of boolean type.",op
);
961 if (!numeric_type(t1
))
962 type_op_error ("Argument to %s must be of numeric type.",op
);
966 if (integral_type(t1
))
968 warning ("combining pointer and integer.\n");
971 else if (!pointer_type(t1
))
972 type_op_error ("Argument to %s must be a pointer.",op
);
975 case UNOP_PREINCREMENT
:
976 case UNOP_POSTINCREMENT
:
977 case UNOP_PREDECREMENT
:
978 case UNOP_POSTDECREMENT
:
979 if (!ordered_type(t1
))
980 type_op_error ("Argument to %s must be of an ordered type.",op
);
984 /* Ok. The following operators have different meanings in
985 different languages. */
986 switch(current_language
->la_language
)
994 if (!numeric_type(t1
) || !numeric_type(t2
))
995 type_op_error ("Arguments to %s must be numbers.",op
);
1006 if (!float_type(t1
) || !float_type(t2
))
1007 type_op_error ("Arguments to %s must be floating point numbers.",op
);
1010 if (!integral_type(t1
) || !integral_type(t2
))
1011 type_op_error ("Arguments to %s must be of integral type.",op
);
1017 case language_chill
:
1018 error ("Missing Chill support in function binop_type_check.");/*FIXME*/
1028 /* This page contains functions for the printing out of
1029 error messages that occur during type- and range-
1032 /* Prints the format string FMT with the operator as a string
1033 corresponding to the opcode OP. If FATAL is non-zero, then
1034 this is an error and error () is called. Otherwise, it is
1035 a warning and printf() is called. */
1037 op_error (fmt
,op
,fatal
)
1043 error (fmt
,op_string(op
));
1046 warning (fmt
,op_string(op
));
1050 /* These are called when a language fails a type- or range-check.
1051 The first argument should be a printf()-style format string, and
1052 the rest of the arguments should be its arguments. If
1053 [type|range]_check is [type|range]_check_on, then return_to_top_level()
1054 is called in the style of error (). Otherwise, the message is prefixed
1055 by the value of warning_pre_print and we do not return to the top level. */
1058 #ifdef ANSI_PROTOTYPES
1059 type_error (char *string
, ...)
1061 type_error (va_alist
)
1066 #ifdef ANSI_PROTOTYPES
1067 va_start (args
, string
);
1071 string
= va_arg (args
, char *);
1074 if (type_check
== type_check_warn
)
1075 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1079 vfprintf_filtered (gdb_stderr
, string
, args
);
1080 fprintf_filtered (gdb_stderr
, "\n");
1082 if (type_check
== type_check_on
)
1083 return_to_top_level (RETURN_ERROR
);
1087 #ifdef ANSI_PROTOTYPES
1088 range_error (char *string
, ...)
1090 range_error (va_alist
)
1095 #ifdef ANSI_PROTOTYPES
1096 va_start (args
, string
);
1100 string
= va_arg (args
, char *);
1103 if (range_check
== range_check_warn
)
1104 fprintf_filtered (gdb_stderr
, warning_pre_print
);
1108 vfprintf_filtered (gdb_stderr
, string
, args
);
1109 fprintf_filtered (gdb_stderr
, "\n");
1111 if (range_check
== range_check_on
)
1112 return_to_top_level (RETURN_ERROR
);
1116 /* This page contains miscellaneous functions */
1118 /* Return the language struct for a given language enum. */
1120 const struct language_defn
*
1126 for (i
= 0; i
< languages_size
; i
++) {
1127 if (languages
[i
]->la_language
== lang
) {
1128 return languages
[i
];
1134 /* Return the language as a string */
1141 for (i
= 0; i
< languages_size
; i
++) {
1142 if (languages
[i
]->la_language
== lang
) {
1143 return languages
[i
]->la_name
;
1150 set_check (ignore
, from_tty
)
1155 "\"set check\" must be followed by the name of a check subcommand.\n");
1156 help_list(setchecklist
, "set check ", -1, gdb_stdout
);
1160 show_check (ignore
, from_tty
)
1164 cmd_show_list(showchecklist
, from_tty
, "");
1167 /* Add a language to the set of known languages. */
1171 const struct language_defn
*lang
;
1173 if (lang
->la_magic
!= LANG_MAGIC
)
1175 fprintf_unfiltered(gdb_stderr
, "Magic number of %s language struct wrong\n",
1182 languages_allocsize
= DEFAULT_ALLOCSIZE
;
1183 languages
= (const struct language_defn
**) xmalloc
1184 (languages_allocsize
* sizeof (*languages
));
1186 if (languages_size
>= languages_allocsize
)
1188 languages_allocsize
*= 2;
1189 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
1190 languages_allocsize
* sizeof (*languages
));
1192 languages
[languages_size
++] = lang
;
1195 /* Define the language that is no language. */
1204 unk_lang_error (msg
)
1207 error ("Attempted to parse an expression with unknown language");
1211 unk_lang_printchar (c
, stream
)
1215 error ("internal error - unimplemented function unk_lang_printchar called.");
1219 unk_lang_printstr (stream
, string
, length
, force_ellipses
)
1222 unsigned int length
;
1225 error ("internal error - unimplemented function unk_lang_printstr called.");
1228 static struct type
*
1229 unk_lang_create_fundamental_type (objfile
, typeid)
1230 struct objfile
*objfile
;
1233 error ("internal error - unimplemented function unk_lang_create_fundamental_type called.");
1237 unk_lang_print_type (type
, varstring
, stream
, show
, level
)
1244 error ("internal error - unimplemented function unk_lang_print_type called.");
1248 unk_lang_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
,
1257 enum val_prettyprint pretty
;
1259 error ("internal error - unimplemented function unk_lang_val_print called.");
1263 unk_lang_value_print (val
, stream
, format
, pretty
)
1267 enum val_prettyprint pretty
;
1269 error ("internal error - unimplemented function unk_lang_value_print called.");
1272 static struct type
** CONST_PTR (unknown_builtin_types
[]) = { 0 };
1273 static const struct op_print unk_op_print_tab
[] = {
1274 {NULL
, OP_NULL
, PREC_NULL
, 0}
1277 const struct language_defn unknown_language_defn
= {
1280 &unknown_builtin_types
[0],
1285 evaluate_subexp_standard
,
1286 unk_lang_printchar
, /* Print character constant */
1288 unk_lang_create_fundamental_type
,
1289 unk_lang_print_type
, /* Print a type using appropriate syntax */
1290 unk_lang_val_print
, /* Print a value using appropriate syntax */
1291 unk_lang_value_print
, /* Print a top-level value */
1292 {"", "", "", ""}, /* Binary format info */
1293 {"0%lo", "0", "o", ""}, /* Octal format info */
1294 {"%ld", "", "d", ""}, /* Decimal format info */
1295 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1296 unk_op_print_tab
, /* expression operators for printing */
1297 1, /* c-style arrays */
1298 0, /* String lower bound */
1299 &builtin_type_char
, /* Type of string elements */
1303 /* These two structs define fake entries for the "local" and "auto" options. */
1304 const struct language_defn auto_language_defn
= {
1307 &unknown_builtin_types
[0],
1312 evaluate_subexp_standard
,
1313 unk_lang_printchar
, /* Print character constant */
1315 unk_lang_create_fundamental_type
,
1316 unk_lang_print_type
, /* Print a type using appropriate syntax */
1317 unk_lang_val_print
, /* Print a value using appropriate syntax */
1318 unk_lang_value_print
, /* Print a top-level value */
1319 {"", "", "", ""}, /* Binary format info */
1320 {"0%lo", "0", "o", ""}, /* Octal format info */
1321 {"%ld", "", "d", ""}, /* Decimal format info */
1322 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1323 unk_op_print_tab
, /* expression operators for printing */
1324 1, /* c-style arrays */
1325 0, /* String lower bound */
1326 &builtin_type_char
, /* Type of string elements */
1330 const struct language_defn local_language_defn
= {
1333 &unknown_builtin_types
[0],
1338 evaluate_subexp_standard
,
1339 unk_lang_printchar
, /* Print character constant */
1341 unk_lang_create_fundamental_type
,
1342 unk_lang_print_type
, /* Print a type using appropriate syntax */
1343 unk_lang_val_print
, /* Print a value using appropriate syntax */
1344 unk_lang_value_print
, /* Print a top-level value */
1345 {"", "", "", ""}, /* Binary format info */
1346 {"0%lo", "0", "o", ""}, /* Octal format info */
1347 {"%ld", "", "d", ""}, /* Decimal format info */
1348 {"0x%lx", "0x", "x", ""}, /* Hex format info */
1349 unk_op_print_tab
, /* expression operators for printing */
1350 1, /* c-style arrays */
1351 0, /* String lower bound */
1352 &builtin_type_char
, /* Type of string elements */
1356 /* Initialize the language routines */
1359 _initialize_language()
1361 struct cmd_list_element
*set
, *show
;
1363 /* GDB commands for language specific stuff */
1365 set
= add_set_cmd ("language", class_support
, var_string_noescape
,
1367 "Set the current source language.",
1369 show
= add_show_from_set (set
, &showlist
);
1370 set
->function
.cfunc
= set_language_command
;
1371 show
->function
.cfunc
= show_language_command
;
1373 add_prefix_cmd ("check", no_class
, set_check
,
1374 "Set the status of the type/range checker",
1375 &setchecklist
, "set check ", 0, &setlist
);
1376 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1377 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1379 add_prefix_cmd ("check", no_class
, show_check
,
1380 "Show the status of the type/range checker",
1381 &showchecklist
, "show check ", 0, &showlist
);
1382 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1383 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1385 set
= add_set_cmd ("type", class_support
, var_string_noescape
,
1387 "Set type checking. (on/warn/off/auto)",
1389 show
= add_show_from_set (set
, &showchecklist
);
1390 set
->function
.cfunc
= set_type_command
;
1391 show
->function
.cfunc
= show_type_command
;
1393 set
= add_set_cmd ("range", class_support
, var_string_noescape
,
1395 "Set range checking. (on/warn/off/auto)",
1397 show
= add_show_from_set (set
, &showchecklist
);
1398 set
->function
.cfunc
= set_range_command
;
1399 show
->function
.cfunc
= show_range_command
;
1401 add_language (&unknown_language_defn
);
1402 add_language (&local_language_defn
);
1403 add_language (&auto_language_defn
);
1405 language
= savestring ("auto",strlen("auto"));
1406 range
= savestring ("auto",strlen("auto"));
1407 type
= savestring ("auto",strlen("auto"));
1409 /* Have the above take effect */
1411 set_language_command (language
, 0);
1412 set_type_command (NULL
, 0);
1413 set_range_command (NULL
, 0);