1 /* Multiple source language support for GDB.
3 Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Contributed by the Department of Computer Science at the State University
8 of New York at Buffalo.
10 This file is part of GDB.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 /* This file contains functions that return things that are specific
26 to languages. Each function should examine current_language if necessary,
27 and return the appropriate result. */
29 /* FIXME: Most of these would be better organized as macros which
30 return data out of a "language-specific" struct pointer that is set
31 whenever the working language changes. That would be a lot faster. */
35 #include "gdb_string.h"
41 #include "expression.h"
44 #include "parser-defs.h"
49 extern void _initialize_language (void);
51 static void unk_lang_error (char *);
53 static int unk_lang_parser (void);
55 static void show_check (char *, int);
57 static void set_check (char *, int);
59 static void set_type_range_case (void);
61 static void unk_lang_emit_char (int c
, struct type
*type
,
62 struct ui_file
*stream
, int quoter
);
64 static void unk_lang_printchar (int c
, struct type
*type
,
65 struct ui_file
*stream
);
67 static void unk_lang_print_type (struct type
*, char *, struct ui_file
*,
70 static int unk_lang_value_print (struct value
*, struct ui_file
*,
71 const struct value_print_options
*);
73 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
75 /* Forward declaration */
76 extern const struct language_defn unknown_language_defn
;
78 /* The current (default at startup) state of type and range checking.
79 (If the modes are set to "auto", though, these are changed based
80 on the default language at startup, and then again based on the
81 language of the first source file. */
83 enum range_mode range_mode
= range_mode_auto
;
84 enum range_check range_check
= range_check_off
;
85 enum type_mode type_mode
= type_mode_auto
;
86 enum type_check type_check
= type_check_off
;
87 enum case_mode case_mode
= case_mode_auto
;
88 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
90 /* The current language and language_mode (see language.h) */
92 const struct language_defn
*current_language
= &unknown_language_defn
;
93 enum language_mode language_mode
= language_mode_auto
;
95 /* The language that the user expects to be typing in (the language
96 of main(), or the last language we notified them about, or C). */
98 const struct language_defn
*expected_language
;
100 /* The list of supported languages. The list itself is malloc'd. */
102 static const struct language_defn
**languages
;
103 static unsigned languages_size
;
104 static unsigned languages_allocsize
;
105 #define DEFAULT_ALLOCSIZE 4
107 /* The current values of the "set language/type/range" enum
109 static const char *language
;
110 static const char *type
;
111 static const char *range
;
112 static const char *case_sensitive
;
114 /* Warning issued when current_language and the language of the current
115 frame do not match. */
116 char lang_frame_mismatch_warn
[] =
117 "Warning: the current language does not match this frame.";
119 /* This page contains the functions corresponding to GDB commands
120 and their helpers. */
122 /* Show command. Display a warning if the language set
123 does not match the frame. */
125 show_language_command (struct ui_file
*file
, int from_tty
,
126 struct cmd_list_element
*c
, const char *value
)
128 enum language flang
; /* The language of the current frame */
130 if (language_mode
== language_mode_auto
)
131 fprintf_filtered (gdb_stdout
,
132 _("The current source language is "
133 "\"auto; currently %s\".\n"),
134 current_language
->la_name
);
136 fprintf_filtered (gdb_stdout
, _("The current source language is \"%s\".\n"),
137 current_language
->la_name
);
139 flang
= get_frame_language ();
140 if (flang
!= language_unknown
&&
141 language_mode
== language_mode_manual
&&
142 current_language
->la_language
!= flang
)
143 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
146 /* Set command. Change the current working language. */
148 set_language_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
153 /* Search the list of languages for a match. */
154 for (i
= 0; i
< languages_size
; i
++)
156 if (strcmp (languages
[i
]->la_name
, language
) == 0)
158 /* Found it! Go into manual mode, and use this language. */
159 if (languages
[i
]->la_language
== language_auto
)
161 /* Enter auto mode. Set to the current frame's language, if
162 known, or fallback to the initial language. */
163 language_mode
= language_mode_auto
;
164 flang
= get_frame_language ();
165 if (flang
!= language_unknown
)
166 set_language (flang
);
168 set_initial_language ();
169 expected_language
= current_language
;
174 /* Enter manual mode. Set the specified language. */
175 language_mode
= language_mode_manual
;
176 current_language
= languages
[i
];
177 set_type_range_case ();
178 expected_language
= current_language
;
184 internal_error (__FILE__
, __LINE__
,
185 "Couldn't find language `%s' in known languages list.",
189 /* Show command. Display a warning if the type setting does
190 not match the current language. */
192 show_type_command (struct ui_file
*file
, int from_tty
,
193 struct cmd_list_element
*c
, const char *value
)
195 if (type_mode
== type_mode_auto
)
207 case type_check_warn
:
211 internal_error (__FILE__
, __LINE__
,
212 "Unrecognized type check setting.");
215 fprintf_filtered (gdb_stdout
,
216 _("Type checking is \"auto; currently %s\".\n"),
220 fprintf_filtered (gdb_stdout
, _("Type checking is \"%s\".\n"),
223 if (type_check
!= current_language
->la_type_check
)
224 warning (_("the current type check setting"
225 " does not match the language.\n"));
228 /* Set command. Change the setting for type checking. */
230 set_type_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
232 if (strcmp (type
, "on") == 0)
234 type_check
= type_check_on
;
235 type_mode
= type_mode_manual
;
237 else if (strcmp (type
, "warn") == 0)
239 type_check
= type_check_warn
;
240 type_mode
= type_mode_manual
;
242 else if (strcmp (type
, "off") == 0)
244 type_check
= type_check_off
;
245 type_mode
= type_mode_manual
;
247 else if (strcmp (type
, "auto") == 0)
249 type_mode
= type_mode_auto
;
250 set_type_range_case ();
254 internal_error (__FILE__
, __LINE__
,
255 _("Unrecognized type check setting: \"%s\""), type
);
257 if (type_check
!= current_language
->la_type_check
)
258 warning (_("the current type check setting"
259 " does not match the language.\n"));
262 /* Show command. Display a warning if the range setting does
263 not match the current language. */
265 show_range_command (struct ui_file
*file
, int from_tty
,
266 struct cmd_list_element
*c
, const char *value
)
268 if (range_mode
== range_mode_auto
)
277 case range_check_off
:
280 case range_check_warn
:
284 internal_error (__FILE__
, __LINE__
,
285 "Unrecognized range check setting.");
288 fprintf_filtered (gdb_stdout
,
289 _("Range checking is \"auto; currently %s\".\n"),
293 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
296 if (range_check
!= current_language
->la_range_check
)
297 warning (_("the current range check setting "
298 "does not match the language.\n"));
301 /* Set command. Change the setting for range checking. */
303 set_range_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
305 if (strcmp (range
, "on") == 0)
307 range_check
= range_check_on
;
308 range_mode
= range_mode_manual
;
310 else if (strcmp (range
, "warn") == 0)
312 range_check
= range_check_warn
;
313 range_mode
= range_mode_manual
;
315 else if (strcmp (range
, "off") == 0)
317 range_check
= range_check_off
;
318 range_mode
= range_mode_manual
;
320 else if (strcmp (range
, "auto") == 0)
322 range_mode
= range_mode_auto
;
323 set_type_range_case ();
328 internal_error (__FILE__
, __LINE__
,
329 _("Unrecognized range check setting: \"%s\""), range
);
331 if (range_check
!= current_language
->la_range_check
)
332 warning (_("the current range check setting "
333 "does not match the language.\n"));
336 /* Show command. Display a warning if the case sensitivity setting does
337 not match the current language. */
339 show_case_command (struct ui_file
*file
, int from_tty
,
340 struct cmd_list_element
*c
, const char *value
)
342 if (case_mode
== case_mode_auto
)
346 switch (case_sensitivity
)
348 case case_sensitive_on
:
351 case case_sensitive_off
:
355 internal_error (__FILE__
, __LINE__
,
356 "Unrecognized case-sensitive setting.");
359 fprintf_filtered (gdb_stdout
,
360 _("Case sensitivity in "
361 "name search is \"auto; currently %s\".\n"),
365 fprintf_filtered (gdb_stdout
, _("Case sensitivity in name search is \"%s\".\n"),
368 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
369 warning (_("the current case sensitivity setting does not match "
373 /* Set command. Change the setting for case sensitivity. */
376 set_case_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
378 if (strcmp (case_sensitive
, "on") == 0)
380 case_sensitivity
= case_sensitive_on
;
381 case_mode
= case_mode_manual
;
383 else if (strcmp (case_sensitive
, "off") == 0)
385 case_sensitivity
= case_sensitive_off
;
386 case_mode
= case_mode_manual
;
388 else if (strcmp (case_sensitive
, "auto") == 0)
390 case_mode
= case_mode_auto
;
391 set_type_range_case ();
396 internal_error (__FILE__
, __LINE__
,
397 "Unrecognized case-sensitive setting: \"%s\"",
401 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
402 warning (_("the current case sensitivity setting does not match "
406 /* Set the status of range and type checking and case sensitivity based on
407 the current modes and the current language.
408 If SHOW is non-zero, then print out the current language,
409 type and range checking status. */
411 set_type_range_case (void)
413 if (range_mode
== range_mode_auto
)
414 range_check
= current_language
->la_range_check
;
416 if (type_mode
== type_mode_auto
)
417 type_check
= current_language
->la_type_check
;
419 if (case_mode
== case_mode_auto
)
420 case_sensitivity
= current_language
->la_case_sensitivity
;
423 /* Set current language to (enum language) LANG. Returns previous language. */
426 set_language (enum language lang
)
429 enum language prev_language
;
431 prev_language
= current_language
->la_language
;
433 for (i
= 0; i
< languages_size
; i
++)
435 if (languages
[i
]->la_language
== lang
)
437 current_language
= languages
[i
];
438 set_type_range_case ();
443 return prev_language
;
447 /* Print out the current language settings: language, range and
448 type checking. If QUIETLY, print only what has changed. */
451 language_info (int quietly
)
453 if (quietly
&& expected_language
== current_language
)
456 expected_language
= current_language
;
457 printf_unfiltered (_("Current language: %s\n"), language
);
458 show_language_command (NULL
, 1, NULL
, NULL
);
462 printf_unfiltered (_("Type checking: %s\n"), type
);
463 show_type_command (NULL
, 1, NULL
, NULL
);
464 printf_unfiltered (_("Range checking: %s\n"), range
);
465 show_range_command (NULL
, 1, NULL
, NULL
);
466 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
467 show_case_command (NULL
, 1, NULL
, NULL
);
471 /* Return the result of a binary operation. */
473 #if 0 /* Currently unused */
476 binop_result_type (struct value
*v1
, struct value
*v2
)
479 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
480 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
482 int l1
= TYPE_LENGTH (t1
);
483 int l2
= TYPE_LENGTH (t2
);
485 switch (current_language
->la_language
)
490 if (TYPE_CODE (t1
) == TYPE_CODE_FLT
)
491 return TYPE_CODE (t2
) == TYPE_CODE_FLT
&& l2
> l1
?
492 VALUE_TYPE (v2
) : VALUE_TYPE (v1
);
493 else if (TYPE_CODE (t2
) == TYPE_CODE_FLT
)
494 return TYPE_CODE (t1
) == TYPE_CODE_FLT
&& l1
> l2
?
495 VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
496 else if (TYPE_UNSIGNED (t1
) && l1
> l2
)
497 return VALUE_TYPE (v1
);
498 else if (TYPE_UNSIGNED (t2
) && l2
> l1
)
499 return VALUE_TYPE (v2
);
500 else /* Both are signed. Result is the longer type */
501 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
504 /* If we are doing type-checking, l1 should equal l2, so this is
506 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
509 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
510 return (struct type
*) 0; /* For lint */
515 /* This page contains functions that are used in type/range checking.
516 They all return zero if the type/range check fails.
518 It is hoped that these will make extending GDB to parse different
519 languages a little easier. These are primarily used in eval.c when
520 evaluating expressions and making sure that their types are correct.
521 Instead of having a mess of conjucted/disjuncted expressions in an "if",
522 the ideas of type can be wrapped up in the following functions.
524 Note that some of them are not currently dependent upon which language
525 is currently being parsed. For example, floats are the same in
526 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
527 TYPE_CODE_FLT), while booleans are different. */
529 /* Returns non-zero if its argument is a simple type. This is the same for
530 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
531 and thus will never cause the failure of the test. */
533 simple_type (struct type
*type
)
535 CHECK_TYPEDEF (type
);
536 switch (TYPE_CODE (type
))
542 case TYPE_CODE_RANGE
:
551 /* Returns non-zero if its argument is of an ordered type.
552 An ordered type is one in which the elements can be tested for the
553 properties of "greater than", "less than", etc, or for which the
554 operations "increment" or "decrement" make sense. */
556 ordered_type (struct type
*type
)
558 CHECK_TYPEDEF (type
);
559 switch (TYPE_CODE (type
))
565 case TYPE_CODE_RANGE
:
573 /* Returns non-zero if the two types are the same */
575 same_type (struct type
*arg1
, struct type
*arg2
)
577 CHECK_TYPEDEF (type
);
578 if (structured_type (arg1
) ? !structured_type (arg2
) : structured_type (arg2
))
579 /* One is structured and one isn't */
581 else if (structured_type (arg1
) && structured_type (arg2
))
583 else if (numeric_type (arg1
) && numeric_type (arg2
))
584 return (TYPE_CODE (arg2
) == TYPE_CODE (arg1
)) &&
585 (TYPE_UNSIGNED (arg1
) == TYPE_UNSIGNED (arg2
))
591 /* Returns non-zero if the type is integral */
593 integral_type (struct type
*type
)
595 CHECK_TYPEDEF (type
);
596 switch (current_language
->la_language
)
601 return (TYPE_CODE (type
) != TYPE_CODE_INT
) &&
602 (TYPE_CODE (type
) != TYPE_CODE_ENUM
) ? 0 : 1;
604 case language_pascal
:
605 return TYPE_CODE (type
) != TYPE_CODE_INT
? 0 : 1;
607 error (_("Language not supported."));
611 /* Returns non-zero if the value is numeric */
613 numeric_type (struct type
*type
)
615 CHECK_TYPEDEF (type
);
616 switch (TYPE_CODE (type
))
627 /* Returns non-zero if the value is a character type */
629 character_type (struct type
*type
)
631 CHECK_TYPEDEF (type
);
632 switch (current_language
->la_language
)
635 case language_pascal
:
636 return TYPE_CODE (type
) != TYPE_CODE_CHAR
? 0 : 1;
641 return (TYPE_CODE (type
) == TYPE_CODE_INT
) &&
642 TYPE_LENGTH (type
) == sizeof (char)
649 /* Returns non-zero if the value is a string type */
651 string_type (struct type
*type
)
653 CHECK_TYPEDEF (type
);
654 switch (current_language
->la_language
)
657 case language_pascal
:
658 return TYPE_CODE (type
) != TYPE_CODE_STRING
? 0 : 1;
663 /* C does not have distinct string type. */
670 /* Returns non-zero if the value is a boolean type */
672 boolean_type (struct type
*type
)
674 CHECK_TYPEDEF (type
);
675 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
677 switch (current_language
->la_language
)
682 /* Might be more cleanly handled by having a
683 TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
684 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
685 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
693 /* Returns non-zero if the value is a floating-point type */
695 float_type (struct type
*type
)
697 CHECK_TYPEDEF (type
);
698 return TYPE_CODE (type
) == TYPE_CODE_FLT
;
702 /* Returns non-zero if the value is a pointer type */
704 pointer_type (struct type
*type
)
706 return TYPE_CODE (type
) == TYPE_CODE_PTR
||
707 TYPE_CODE (type
) == TYPE_CODE_REF
;
711 /* Returns non-zero if the value is a structured type */
713 structured_type (struct type
*type
)
715 CHECK_TYPEDEF (type
);
716 switch (current_language
->la_language
)
721 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
722 (TYPE_CODE (type
) == TYPE_CODE_UNION
) ||
723 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
724 case language_pascal
:
725 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
726 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
727 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
728 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
730 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
731 (TYPE_CODE (type
) == TYPE_CODE_SET
) ||
732 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
739 /* This page contains functions that return info about
740 (struct value) values used in GDB. */
742 /* Returns non-zero if the value VAL represents a true value. */
744 value_true (struct value
*val
)
746 /* It is possible that we should have some sort of error if a non-boolean
747 value is used in this context. Possibly dependent on some kind of
748 "boolean-checking" option like range checking. But it should probably
749 not depend on the language except insofar as is necessary to identify
750 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
751 should be an error, probably). */
752 return !value_logical_not (val
);
755 /* This page contains functions for the printing out of
756 error messages that occur during type- and range-
759 /* These are called when a language fails a type- or range-check. The
760 first argument should be a printf()-style format string, and the
761 rest of the arguments should be its arguments. If
762 [type|range]_check is [type|range]_check_on, an error is printed;
763 if [type|range]_check_warn, a warning; otherwise just the
767 type_error (const char *string
,...)
770 va_start (args
, string
);
774 case type_check_warn
:
775 vwarning (string
, args
);
778 verror (string
, args
);
781 /* FIXME: cagney/2002-01-30: Should this function print anything
782 when type error is off? */
783 vfprintf_filtered (gdb_stderr
, string
, args
);
784 fprintf_filtered (gdb_stderr
, "\n");
787 internal_error (__FILE__
, __LINE__
, _("bad switch"));
793 range_error (const char *string
,...)
796 va_start (args
, string
);
800 case range_check_warn
:
801 vwarning (string
, args
);
804 verror (string
, args
);
806 case range_check_off
:
807 /* FIXME: cagney/2002-01-30: Should this function print anything
808 when range error is off? */
809 vfprintf_filtered (gdb_stderr
, string
, args
);
810 fprintf_filtered (gdb_stderr
, "\n");
813 internal_error (__FILE__
, __LINE__
, _("bad switch"));
819 /* This page contains miscellaneous functions */
821 /* Return the language enum for a given language string. */
824 language_enum (char *str
)
828 for (i
= 0; i
< languages_size
; i
++)
829 if (strcmp (languages
[i
]->la_name
, str
) == 0)
830 return languages
[i
]->la_language
;
832 return language_unknown
;
835 /* Return the language struct for a given language enum. */
837 const struct language_defn
*
838 language_def (enum language lang
)
842 for (i
= 0; i
< languages_size
; i
++)
844 if (languages
[i
]->la_language
== lang
)
852 /* Return the language as a string */
854 language_str (enum language lang
)
858 for (i
= 0; i
< languages_size
; i
++)
860 if (languages
[i
]->la_language
== lang
)
862 return languages
[i
]->la_name
;
869 set_check (char *ignore
, int from_tty
)
872 "\"set check\" must be followed by the name of a check subcommand.\n");
873 help_list (setchecklist
, "set check ", -1, gdb_stdout
);
877 show_check (char *ignore
, int from_tty
)
879 cmd_show_list (showchecklist
, from_tty
, "");
882 /* Add a language to the set of known languages. */
885 add_language (const struct language_defn
*lang
)
887 /* For the "set language" command. */
888 static char **language_names
= NULL
;
889 /* For the "help set language" command. */
890 char *language_set_doc
= NULL
;
893 struct ui_file
*tmp_stream
;
895 if (lang
->la_magic
!= LANG_MAGIC
)
897 fprintf_unfiltered (gdb_stderr
, "Magic number of %s language struct wrong\n",
899 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
904 languages_allocsize
= DEFAULT_ALLOCSIZE
;
905 languages
= (const struct language_defn
**) xmalloc
906 (languages_allocsize
* sizeof (*languages
));
908 if (languages_size
>= languages_allocsize
)
910 languages_allocsize
*= 2;
911 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
912 languages_allocsize
* sizeof (*languages
));
914 languages
[languages_size
++] = lang
;
916 /* Build the language names array, to be used as enumeration in the
917 set language" enum command. */
918 language_names
= xrealloc (language_names
,
919 (languages_size
+ 1) * sizeof (const char *));
920 for (i
= 0; i
< languages_size
; ++i
)
921 language_names
[i
] = languages
[i
]->la_name
;
922 language_names
[i
] = NULL
;
924 /* Build the "help set language" docs. */
925 tmp_stream
= mem_fileopen ();
927 fprintf_unfiltered (tmp_stream
, _("\
928 Set the current source language.\n\
929 The currently understood settings are:\n\n\
930 local or auto Automatic setting based on source file\n"));
932 for (i
= 0; i
< languages_size
; ++i
)
934 /* Already dealt with these above. */
935 if (languages
[i
]->la_language
== language_unknown
936 || languages
[i
]->la_language
== language_auto
)
939 /* FIXME: i18n: for now assume that the human-readable name
940 is just a capitalization of the internal name. */
941 fprintf_unfiltered (tmp_stream
, "%-16s Use the %c%s language\n",
942 languages
[i
]->la_name
,
943 /* Capitalize first letter of language
945 toupper (languages
[i
]->la_name
[0]),
946 languages
[i
]->la_name
+ 1);
949 language_set_doc
= ui_file_xstrdup (tmp_stream
, NULL
);
950 ui_file_delete (tmp_stream
);
952 add_setshow_enum_cmd ("language", class_support
,
953 (const char **) language_names
,
955 language_set_doc
, _("\
956 Show the current source language."), NULL
,
957 set_language_command
,
958 show_language_command
,
959 &setlist
, &showlist
);
961 xfree (language_set_doc
);
964 /* Iterate through all registered languages looking for and calling
965 any non-NULL struct language_defn.skip_trampoline() functions.
966 Return the result from the first that returns non-zero, or 0 if all
969 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
973 for (i
= 0; i
< languages_size
; i
++)
975 if (languages
[i
]->skip_trampoline
)
977 CORE_ADDR real_pc
= (languages
[i
]->skip_trampoline
) (frame
, pc
);
986 /* Return demangled language symbol, or NULL.
987 FIXME: Options are only useful for certain languages and ignored
988 by others, so it would be better to remove them here and have a
989 more flexible demangler for the languages that need it.
990 FIXME: Sometimes the demangler is invoked when we don't know the
991 language, so we can't use this everywhere. */
993 language_demangle (const struct language_defn
*current_language
,
994 const char *mangled
, int options
)
996 if (current_language
!= NULL
&& current_language
->la_demangle
)
997 return current_language
->la_demangle (mangled
, options
);
1001 /* Return class name from physname or NULL. */
1003 language_class_name_from_physname (const struct language_defn
*current_language
,
1004 const char *physname
)
1006 if (current_language
!= NULL
&& current_language
->la_class_name_from_physname
)
1007 return current_language
->la_class_name_from_physname (physname
);
1011 /* Return non-zero if TYPE should be passed (and returned) by
1012 reference at the language level. */
1014 language_pass_by_reference (struct type
*type
)
1016 return current_language
->la_pass_by_reference (type
);
1019 /* Return zero; by default, types are passed by value at the language
1020 level. The target ABI may pass or return some structs by reference
1021 independent of this. */
1023 default_pass_by_reference (struct type
*type
)
1028 /* Return the default string containing the list of characters
1029 delimiting words. This is a reasonable default value that
1030 most languages should be able to use. */
1033 default_word_break_characters (void)
1035 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1038 /* Print the index of array elements using the C99 syntax. */
1041 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
1042 const struct value_print_options
*options
)
1044 fprintf_filtered (stream
, "[");
1045 LA_VALUE_PRINT (index_value
, stream
, options
);
1046 fprintf_filtered (stream
, "] = ");
1050 default_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
1051 struct type
**char_type
, const char **charset
)
1053 error (_("Getting a string is unsupported in this language."));
1056 /* Define the language that is no language. */
1059 unk_lang_parser (void)
1065 unk_lang_error (char *msg
)
1067 error (_("Attempted to parse an expression with unknown language"));
1071 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
1074 error (_("internal error - unimplemented function unk_lang_emit_char called."));
1078 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
1080 error (_("internal error - unimplemented function unk_lang_printchar called."));
1084 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
1085 const gdb_byte
*string
, unsigned int length
,
1086 const char *encoding
, int force_ellipses
,
1087 const struct value_print_options
*options
)
1089 error (_("internal error - unimplemented function unk_lang_printstr called."));
1093 unk_lang_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
1094 int show
, int level
)
1096 error (_("internal error - unimplemented function unk_lang_print_type called."));
1100 unk_lang_val_print (struct type
*type
, const gdb_byte
*valaddr
,
1101 int embedded_offset
, CORE_ADDR address
,
1102 struct ui_file
*stream
, int recurse
,
1103 const struct value_print_options
*options
)
1105 error (_("internal error - unimplemented function unk_lang_val_print called."));
1109 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
1110 const struct value_print_options
*options
)
1112 error (_("internal error - unimplemented function unk_lang_value_print called."));
1115 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
1120 /* Unknown languages just use the cplus demangler. */
1121 static char *unk_lang_demangle (const char *mangled
, int options
)
1123 return cplus_demangle (mangled
, options
);
1126 static char *unk_lang_class_name (const char *mangled
)
1131 static const struct op_print unk_op_print_tab
[] =
1133 {NULL
, OP_NULL
, PREC_NULL
, 0}
1137 unknown_language_arch_info (struct gdbarch
*gdbarch
,
1138 struct language_arch_info
*lai
)
1140 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
1141 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
1142 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
1146 const struct language_defn unknown_language_defn
=
1155 &exp_descriptor_standard
,
1159 unk_lang_printchar
, /* Print character constant */
1162 unk_lang_print_type
, /* Print a type using appropriate syntax */
1163 default_print_typedef
, /* Print a typedef using appropriate syntax */
1164 unk_lang_val_print
, /* Print a value using appropriate syntax */
1165 unk_lang_value_print
, /* Print a top-level value */
1166 unk_lang_trampoline
, /* Language specific skip_trampoline */
1167 "this", /* name_of_this */
1168 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1169 basic_lookup_transparent_type
,/* lookup_transparent_type */
1170 unk_lang_demangle
, /* Language specific symbol demangler */
1171 unk_lang_class_name
, /* Language specific class_name_from_physname */
1172 unk_op_print_tab
, /* expression operators for printing */
1173 1, /* c-style arrays */
1174 0, /* String lower bound */
1175 default_word_break_characters
,
1176 default_make_symbol_completion_list
,
1177 unknown_language_arch_info
, /* la_language_arch_info. */
1178 default_print_array_index
,
1179 default_pass_by_reference
,
1184 /* These two structs define fake entries for the "local" and "auto" options. */
1185 const struct language_defn auto_language_defn
=
1194 &exp_descriptor_standard
,
1198 unk_lang_printchar
, /* Print character constant */
1201 unk_lang_print_type
, /* Print a type using appropriate syntax */
1202 default_print_typedef
, /* Print a typedef using appropriate syntax */
1203 unk_lang_val_print
, /* Print a value using appropriate syntax */
1204 unk_lang_value_print
, /* Print a top-level value */
1205 unk_lang_trampoline
, /* Language specific skip_trampoline */
1206 "this", /* name_of_this */
1207 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1208 basic_lookup_transparent_type
,/* lookup_transparent_type */
1209 unk_lang_demangle
, /* Language specific symbol demangler */
1210 unk_lang_class_name
, /* Language specific class_name_from_physname */
1211 unk_op_print_tab
, /* expression operators for printing */
1212 1, /* c-style arrays */
1213 0, /* String lower bound */
1214 default_word_break_characters
,
1215 default_make_symbol_completion_list
,
1216 unknown_language_arch_info
, /* la_language_arch_info. */
1217 default_print_array_index
,
1218 default_pass_by_reference
,
1223 const struct language_defn local_language_defn
=
1232 &exp_descriptor_standard
,
1236 unk_lang_printchar
, /* Print character constant */
1239 unk_lang_print_type
, /* Print a type using appropriate syntax */
1240 default_print_typedef
, /* Print a typedef using appropriate syntax */
1241 unk_lang_val_print
, /* Print a value using appropriate syntax */
1242 unk_lang_value_print
, /* Print a top-level value */
1243 unk_lang_trampoline
, /* Language specific skip_trampoline */
1244 "this", /* name_of_this */
1245 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1246 basic_lookup_transparent_type
,/* lookup_transparent_type */
1247 unk_lang_demangle
, /* Language specific symbol demangler */
1248 unk_lang_class_name
, /* Language specific class_name_from_physname */
1249 unk_op_print_tab
, /* expression operators for printing */
1250 1, /* c-style arrays */
1251 0, /* String lower bound */
1252 default_word_break_characters
,
1253 default_make_symbol_completion_list
,
1254 unknown_language_arch_info
, /* la_language_arch_info. */
1255 default_print_array_index
,
1256 default_pass_by_reference
,
1261 /* Per-architecture language information. */
1263 static struct gdbarch_data
*language_gdbarch_data
;
1265 struct language_gdbarch
1267 /* A vector of per-language per-architecture info. Indexed by "enum
1269 struct language_arch_info arch_info
[nr_languages
];
1273 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
1275 struct language_gdbarch
*l
;
1278 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
1279 for (i
= 0; i
< languages_size
; i
++)
1281 if (languages
[i
] != NULL
1282 && languages
[i
]->la_language_arch_info
!= NULL
)
1283 languages
[i
]->la_language_arch_info
1284 (gdbarch
, l
->arch_info
+ languages
[i
]->la_language
);
1290 language_string_char_type (const struct language_defn
*la
,
1291 struct gdbarch
*gdbarch
)
1293 struct language_gdbarch
*ld
= gdbarch_data (gdbarch
,
1294 language_gdbarch_data
);
1295 return ld
->arch_info
[la
->la_language
].string_char_type
;
1299 language_bool_type (const struct language_defn
*la
,
1300 struct gdbarch
*gdbarch
)
1302 struct language_gdbarch
*ld
= gdbarch_data (gdbarch
,
1303 language_gdbarch_data
);
1305 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
1308 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
1309 NULL
, VAR_DOMAIN
, NULL
);
1312 struct type
*type
= SYMBOL_TYPE (sym
);
1313 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
1318 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1322 language_lookup_primitive_type_by_name (const struct language_defn
*la
,
1323 struct gdbarch
*gdbarch
,
1326 struct language_gdbarch
*ld
= gdbarch_data (gdbarch
,
1327 language_gdbarch_data
);
1328 struct type
*const *p
;
1329 for (p
= ld
->arch_info
[la
->la_language
].primitive_type_vector
;
1333 if (strcmp (TYPE_NAME (*p
), name
) == 0)
1339 /* Initialize the language routines */
1342 _initialize_language (void)
1344 static const char *type_or_range_names
[]
1345 = { "on", "off", "warn", "auto", NULL
};
1347 static const char *case_sensitive_names
[]
1348 = { "on", "off", "auto", NULL
};
1350 language_gdbarch_data
1351 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1353 /* GDB commands for language specific stuff */
1355 add_prefix_cmd ("check", no_class
, set_check
,
1356 _("Set the status of the type/range checker."),
1357 &setchecklist
, "set check ", 0, &setlist
);
1358 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1359 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1361 add_prefix_cmd ("check", no_class
, show_check
,
1362 _("Show the status of the type/range checker."),
1363 &showchecklist
, "show check ", 0, &showlist
);
1364 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1365 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1367 add_setshow_enum_cmd ("type", class_support
, type_or_range_names
, &type
, _("\
1368 Set type checking. (on/warn/off/auto)"), _("\
1369 Show type checking. (on/warn/off/auto)"), NULL
,
1372 &setchecklist
, &showchecklist
);
1374 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1376 Set range checking. (on/warn/off/auto)"), _("\
1377 Show range checking. (on/warn/off/auto)"), NULL
,
1380 &setchecklist
, &showchecklist
);
1382 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1383 &case_sensitive
, _("\
1384 Set case sensitivity in name search. (on/off/auto)"), _("\
1385 Show case sensitivity in name search. (on/off/auto)"), _("\
1386 For Fortran the default is off; for other languages the default is on."),
1389 &setlist
, &showlist
);
1391 add_language (&auto_language_defn
);
1392 add_language (&local_language_defn
);
1393 add_language (&unknown_language_defn
);
1395 language
= xstrdup ("auto");
1396 type
= xstrdup ("auto");
1397 range
= xstrdup ("auto");
1398 case_sensitive
= xstrdup ("auto");
1400 /* Have the above take effect */
1401 set_language (language_auto
);