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 Free Software Foundation, Inc.
6 Contributed by the Department of Computer Science at the State University
7 of New York at Buffalo.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 /* This file contains functions that return things that are specific
25 to languages. Each function should examine current_language if necessary,
26 and return the appropriate result. */
28 /* FIXME: Most of these would be better organized as macros which
29 return data out of a "language-specific" struct pointer that is set
30 whenever the working language changes. That would be a lot faster. */
34 #include "gdb_string.h"
40 #include "expression.h"
43 #include "parser-defs.h"
48 extern void _initialize_language (void);
50 static void unk_lang_error (char *);
52 static int unk_lang_parser (void);
54 static void show_check (char *, int);
56 static void set_check (char *, int);
58 static void set_type_range_case (void);
60 static void unk_lang_emit_char (int c
, struct type
*type
,
61 struct ui_file
*stream
, int quoter
);
63 static void unk_lang_printchar (int c
, struct type
*type
,
64 struct ui_file
*stream
);
66 static void unk_lang_print_type (struct type
*, char *, struct ui_file
*,
69 static int unk_lang_value_print (struct value
*, struct ui_file
*,
70 const struct value_print_options
*);
72 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*, CORE_ADDR pc
);
74 /* Forward declaration */
75 extern const struct language_defn unknown_language_defn
;
77 /* The current (default at startup) state of type and range checking.
78 (If the modes are set to "auto", though, these are changed based
79 on the default language at startup, and then again based on the
80 language of the first source file. */
82 enum range_mode range_mode
= range_mode_auto
;
83 enum range_check range_check
= range_check_off
;
84 enum type_mode type_mode
= type_mode_auto
;
85 enum type_check type_check
= type_check_off
;
86 enum case_mode case_mode
= case_mode_auto
;
87 enum case_sensitivity case_sensitivity
= case_sensitive_on
;
89 /* The current language and language_mode (see language.h) */
91 const struct language_defn
*current_language
= &unknown_language_defn
;
92 enum language_mode language_mode
= language_mode_auto
;
94 /* The language that the user expects to be typing in (the language
95 of main(), or the last language we notified them about, or C). */
97 const struct language_defn
*expected_language
;
99 /* The list of supported languages. The list itself is malloc'd. */
101 static const struct language_defn
**languages
;
102 static unsigned languages_size
;
103 static unsigned languages_allocsize
;
104 #define DEFAULT_ALLOCSIZE 4
106 /* The current values of the "set language/type/range" enum
108 static const char *language
;
109 static const char *type
;
110 static const char *range
;
111 static const char *case_sensitive
;
113 /* Warning issued when current_language and the language of the current
114 frame do not match. */
115 char lang_frame_mismatch_warn
[] =
116 "Warning: the current language does not match this frame.";
118 /* This page contains the functions corresponding to GDB commands
119 and their helpers. */
121 /* Show command. Display a warning if the language set
122 does not match the frame. */
124 show_language_command (struct ui_file
*file
, int from_tty
,
125 struct cmd_list_element
*c
, const char *value
)
127 enum language flang
; /* The language of the current frame */
129 if (language_mode
== language_mode_auto
)
130 fprintf_filtered (gdb_stdout
,
131 _("The current source language is "
132 "\"auto; currently %s\".\n"),
133 current_language
->la_name
);
135 fprintf_filtered (gdb_stdout
, _("The current source language is \"%s\".\n"),
136 current_language
->la_name
);
138 flang
= get_frame_language ();
139 if (flang
!= language_unknown
&&
140 language_mode
== language_mode_manual
&&
141 current_language
->la_language
!= flang
)
142 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
145 /* Set command. Change the current working language. */
147 set_language_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
152 /* Search the list of languages for a match. */
153 for (i
= 0; i
< languages_size
; i
++)
155 if (strcmp (languages
[i
]->la_name
, language
) == 0)
157 /* Found it! Go into manual mode, and use this language. */
158 if (languages
[i
]->la_language
== language_auto
)
160 /* Enter auto mode. Set to the current frame's language, if
161 known, or fallback to the initial language. */
162 language_mode
= language_mode_auto
;
163 flang
= get_frame_language ();
164 if (flang
!= language_unknown
)
165 set_language (flang
);
167 set_initial_language ();
168 expected_language
= current_language
;
173 /* Enter manual mode. Set the specified language. */
174 language_mode
= language_mode_manual
;
175 current_language
= languages
[i
];
176 set_type_range_case ();
177 expected_language
= current_language
;
183 internal_error (__FILE__
, __LINE__
,
184 "Couldn't find language `%s' in known languages list.",
188 /* Show command. Display a warning if the type setting does
189 not match the current language. */
191 show_type_command (struct ui_file
*file
, int from_tty
,
192 struct cmd_list_element
*c
, const char *value
)
194 if (type_mode
== type_mode_auto
)
206 case type_check_warn
:
210 internal_error (__FILE__
, __LINE__
,
211 "Unrecognized type check setting.");
214 fprintf_filtered (gdb_stdout
,
215 _("Type checking is \"auto; currently %s\".\n"),
219 fprintf_filtered (gdb_stdout
, _("Type checking is \"%s\".\n"),
222 if (type_check
!= current_language
->la_type_check
)
223 warning (_("the current type check setting"
224 " does not match the language.\n"));
227 /* Set command. Change the setting for type checking. */
229 set_type_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
231 if (strcmp (type
, "on") == 0)
233 type_check
= type_check_on
;
234 type_mode
= type_mode_manual
;
236 else if (strcmp (type
, "warn") == 0)
238 type_check
= type_check_warn
;
239 type_mode
= type_mode_manual
;
241 else if (strcmp (type
, "off") == 0)
243 type_check
= type_check_off
;
244 type_mode
= type_mode_manual
;
246 else if (strcmp (type
, "auto") == 0)
248 type_mode
= type_mode_auto
;
249 set_type_range_case ();
253 internal_error (__FILE__
, __LINE__
,
254 _("Unrecognized type check setting: \"%s\""), type
);
256 if (type_check
!= current_language
->la_type_check
)
257 warning (_("the current type check setting"
258 " does not match the language.\n"));
261 /* Show command. Display a warning if the range setting does
262 not match the current language. */
264 show_range_command (struct ui_file
*file
, int from_tty
,
265 struct cmd_list_element
*c
, const char *value
)
267 if (range_mode
== range_mode_auto
)
276 case range_check_off
:
279 case range_check_warn
:
283 internal_error (__FILE__
, __LINE__
,
284 "Unrecognized range check setting.");
287 fprintf_filtered (gdb_stdout
,
288 _("Range checking is \"auto; currently %s\".\n"),
292 fprintf_filtered (gdb_stdout
, _("Range checking is \"%s\".\n"),
295 if (range_check
!= current_language
->la_range_check
)
296 warning (_("the current range check setting "
297 "does not match the language.\n"));
300 /* Set command. Change the setting for range checking. */
302 set_range_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
304 if (strcmp (range
, "on") == 0)
306 range_check
= range_check_on
;
307 range_mode
= range_mode_manual
;
309 else if (strcmp (range
, "warn") == 0)
311 range_check
= range_check_warn
;
312 range_mode
= range_mode_manual
;
314 else if (strcmp (range
, "off") == 0)
316 range_check
= range_check_off
;
317 range_mode
= range_mode_manual
;
319 else if (strcmp (range
, "auto") == 0)
321 range_mode
= range_mode_auto
;
322 set_type_range_case ();
327 internal_error (__FILE__
, __LINE__
,
328 _("Unrecognized range check setting: \"%s\""), range
);
330 if (range_check
!= current_language
->la_range_check
)
331 warning (_("the current range check setting "
332 "does not match the language.\n"));
335 /* Show command. Display a warning if the case sensitivity setting does
336 not match the current language. */
338 show_case_command (struct ui_file
*file
, int from_tty
,
339 struct cmd_list_element
*c
, const char *value
)
341 if (case_mode
== case_mode_auto
)
345 switch (case_sensitivity
)
347 case case_sensitive_on
:
350 case case_sensitive_off
:
354 internal_error (__FILE__
, __LINE__
,
355 "Unrecognized case-sensitive setting.");
358 fprintf_filtered (gdb_stdout
,
359 _("Case sensitivity in "
360 "name search is \"auto; currently %s\".\n"),
364 fprintf_filtered (gdb_stdout
, _("Case sensitivity in name search is \"%s\".\n"),
367 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
368 warning (_("the current case sensitivity setting does not match "
372 /* Set command. Change the setting for case sensitivity. */
375 set_case_command (char *ignore
, int from_tty
, struct cmd_list_element
*c
)
377 if (strcmp (case_sensitive
, "on") == 0)
379 case_sensitivity
= case_sensitive_on
;
380 case_mode
= case_mode_manual
;
382 else if (strcmp (case_sensitive
, "off") == 0)
384 case_sensitivity
= case_sensitive_off
;
385 case_mode
= case_mode_manual
;
387 else if (strcmp (case_sensitive
, "auto") == 0)
389 case_mode
= case_mode_auto
;
390 set_type_range_case ();
395 internal_error (__FILE__
, __LINE__
,
396 "Unrecognized case-sensitive setting: \"%s\"",
400 if (case_sensitivity
!= current_language
->la_case_sensitivity
)
401 warning (_("the current case sensitivity setting does not match "
405 /* Set the status of range and type checking and case sensitivity based on
406 the current modes and the current language.
407 If SHOW is non-zero, then print out the current language,
408 type and range checking status. */
410 set_type_range_case (void)
412 if (range_mode
== range_mode_auto
)
413 range_check
= current_language
->la_range_check
;
415 if (type_mode
== type_mode_auto
)
416 type_check
= current_language
->la_type_check
;
418 if (case_mode
== case_mode_auto
)
419 case_sensitivity
= current_language
->la_case_sensitivity
;
422 /* Set current language to (enum language) LANG. Returns previous language. */
425 set_language (enum language lang
)
428 enum language prev_language
;
430 prev_language
= current_language
->la_language
;
432 for (i
= 0; i
< languages_size
; i
++)
434 if (languages
[i
]->la_language
== lang
)
436 current_language
= languages
[i
];
437 set_type_range_case ();
442 return prev_language
;
446 /* Print out the current language settings: language, range and
447 type checking. If QUIETLY, print only what has changed. */
450 language_info (int quietly
)
452 if (quietly
&& expected_language
== current_language
)
455 expected_language
= current_language
;
456 printf_unfiltered (_("Current language: %s\n"), language
);
457 show_language_command (NULL
, 1, NULL
, NULL
);
461 printf_unfiltered (_("Type checking: %s\n"), type
);
462 show_type_command (NULL
, 1, NULL
, NULL
);
463 printf_unfiltered (_("Range checking: %s\n"), range
);
464 show_range_command (NULL
, 1, NULL
, NULL
);
465 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive
);
466 show_case_command (NULL
, 1, NULL
, NULL
);
470 /* Return the result of a binary operation. */
472 #if 0 /* Currently unused */
475 binop_result_type (struct value
*v1
, struct value
*v2
)
478 struct type
*t1
= check_typedef (VALUE_TYPE (v1
));
479 struct type
*t2
= check_typedef (VALUE_TYPE (v2
));
481 int l1
= TYPE_LENGTH (t1
);
482 int l2
= TYPE_LENGTH (t2
);
484 switch (current_language
->la_language
)
489 if (TYPE_CODE (t1
) == TYPE_CODE_FLT
)
490 return TYPE_CODE (t2
) == TYPE_CODE_FLT
&& l2
> l1
?
491 VALUE_TYPE (v2
) : VALUE_TYPE (v1
);
492 else if (TYPE_CODE (t2
) == TYPE_CODE_FLT
)
493 return TYPE_CODE (t1
) == TYPE_CODE_FLT
&& l1
> l2
?
494 VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
495 else if (TYPE_UNSIGNED (t1
) && l1
> l2
)
496 return VALUE_TYPE (v1
);
497 else if (TYPE_UNSIGNED (t2
) && l2
> l1
)
498 return VALUE_TYPE (v2
);
499 else /* Both are signed. Result is the longer type */
500 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
503 /* If we are doing type-checking, l1 should equal l2, so this is
505 return l1
> l2
? VALUE_TYPE (v1
) : VALUE_TYPE (v2
);
508 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
509 return (struct type
*) 0; /* For lint */
514 /* This page contains functions that are used in type/range checking.
515 They all return zero if the type/range check fails.
517 It is hoped that these will make extending GDB to parse different
518 languages a little easier. These are primarily used in eval.c when
519 evaluating expressions and making sure that their types are correct.
520 Instead of having a mess of conjucted/disjuncted expressions in an "if",
521 the ideas of type can be wrapped up in the following functions.
523 Note that some of them are not currently dependent upon which language
524 is currently being parsed. For example, floats are the same in
525 C and Modula-2 (ie. the only floating point type has TYPE_CODE of
526 TYPE_CODE_FLT), while booleans are different. */
528 /* Returns non-zero if its argument is a simple type. This is the same for
529 both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur,
530 and thus will never cause the failure of the test. */
532 simple_type (struct type
*type
)
534 CHECK_TYPEDEF (type
);
535 switch (TYPE_CODE (type
))
541 case TYPE_CODE_RANGE
:
550 /* Returns non-zero if its argument is of an ordered type.
551 An ordered type is one in which the elements can be tested for the
552 properties of "greater than", "less than", etc, or for which the
553 operations "increment" or "decrement" make sense. */
555 ordered_type (struct type
*type
)
557 CHECK_TYPEDEF (type
);
558 switch (TYPE_CODE (type
))
564 case TYPE_CODE_RANGE
:
572 /* Returns non-zero if the two types are the same */
574 same_type (struct type
*arg1
, struct type
*arg2
)
576 CHECK_TYPEDEF (type
);
577 if (structured_type (arg1
) ? !structured_type (arg2
) : structured_type (arg2
))
578 /* One is structured and one isn't */
580 else if (structured_type (arg1
) && structured_type (arg2
))
582 else if (numeric_type (arg1
) && numeric_type (arg2
))
583 return (TYPE_CODE (arg2
) == TYPE_CODE (arg1
)) &&
584 (TYPE_UNSIGNED (arg1
) == TYPE_UNSIGNED (arg2
))
590 /* Returns non-zero if the type is integral */
592 integral_type (struct type
*type
)
594 CHECK_TYPEDEF (type
);
595 switch (current_language
->la_language
)
600 return (TYPE_CODE (type
) != TYPE_CODE_INT
) &&
601 (TYPE_CODE (type
) != TYPE_CODE_ENUM
) ? 0 : 1;
603 case language_pascal
:
604 return TYPE_CODE (type
) != TYPE_CODE_INT
? 0 : 1;
606 error (_("Language not supported."));
610 /* Returns non-zero if the value is numeric */
612 numeric_type (struct type
*type
)
614 CHECK_TYPEDEF (type
);
615 switch (TYPE_CODE (type
))
626 /* Returns non-zero if the value is a character type */
628 character_type (struct type
*type
)
630 CHECK_TYPEDEF (type
);
631 switch (current_language
->la_language
)
634 case language_pascal
:
635 return TYPE_CODE (type
) != TYPE_CODE_CHAR
? 0 : 1;
640 return (TYPE_CODE (type
) == TYPE_CODE_INT
) &&
641 TYPE_LENGTH (type
) == sizeof (char)
648 /* Returns non-zero if the value is a string type */
650 string_type (struct type
*type
)
652 CHECK_TYPEDEF (type
);
653 switch (current_language
->la_language
)
656 case language_pascal
:
657 return TYPE_CODE (type
) != TYPE_CODE_STRING
? 0 : 1;
662 /* C does not have distinct string type. */
669 /* Returns non-zero if the value is a boolean type */
671 boolean_type (struct type
*type
)
673 CHECK_TYPEDEF (type
);
674 if (TYPE_CODE (type
) == TYPE_CODE_BOOL
)
676 switch (current_language
->la_language
)
681 /* Might be more cleanly handled by having a
682 TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
683 languages, or a TYPE_CODE_INT_OR_BOOL for C. */
684 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
692 /* Returns non-zero if the value is a floating-point type */
694 float_type (struct type
*type
)
696 CHECK_TYPEDEF (type
);
697 return TYPE_CODE (type
) == TYPE_CODE_FLT
;
701 /* Returns non-zero if the value is a pointer type */
703 pointer_type (struct type
*type
)
705 return TYPE_CODE (type
) == TYPE_CODE_PTR
||
706 TYPE_CODE (type
) == TYPE_CODE_REF
;
710 /* Returns non-zero if the value is a structured type */
712 structured_type (struct type
*type
)
714 CHECK_TYPEDEF (type
);
715 switch (current_language
->la_language
)
720 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
721 (TYPE_CODE (type
) == TYPE_CODE_UNION
) ||
722 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
723 case language_pascal
:
724 return (TYPE_CODE(type
) == TYPE_CODE_STRUCT
) ||
725 (TYPE_CODE(type
) == TYPE_CODE_UNION
) ||
726 (TYPE_CODE(type
) == TYPE_CODE_SET
) ||
727 (TYPE_CODE(type
) == TYPE_CODE_ARRAY
);
729 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
) ||
730 (TYPE_CODE (type
) == TYPE_CODE_SET
) ||
731 (TYPE_CODE (type
) == TYPE_CODE_ARRAY
);
738 /* This page contains functions that return info about
739 (struct value) values used in GDB. */
741 /* Returns non-zero if the value VAL represents a true value. */
743 value_true (struct value
*val
)
745 /* It is possible that we should have some sort of error if a non-boolean
746 value is used in this context. Possibly dependent on some kind of
747 "boolean-checking" option like range checking. But it should probably
748 not depend on the language except insofar as is necessary to identify
749 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
750 should be an error, probably). */
751 return !value_logical_not (val
);
754 /* This page contains functions for the printing out of
755 error messages that occur during type- and range-
758 /* These are called when a language fails a type- or range-check. The
759 first argument should be a printf()-style format string, and the
760 rest of the arguments should be its arguments. If
761 [type|range]_check is [type|range]_check_on, an error is printed;
762 if [type|range]_check_warn, a warning; otherwise just the
766 type_error (const char *string
,...)
769 va_start (args
, string
);
773 case type_check_warn
:
774 vwarning (string
, args
);
777 verror (string
, args
);
780 /* FIXME: cagney/2002-01-30: Should this function print anything
781 when type error is off? */
782 vfprintf_filtered (gdb_stderr
, string
, args
);
783 fprintf_filtered (gdb_stderr
, "\n");
786 internal_error (__FILE__
, __LINE__
, _("bad switch"));
792 range_error (const char *string
,...)
795 va_start (args
, string
);
799 case range_check_warn
:
800 vwarning (string
, args
);
803 verror (string
, args
);
805 case range_check_off
:
806 /* FIXME: cagney/2002-01-30: Should this function print anything
807 when range error is off? */
808 vfprintf_filtered (gdb_stderr
, string
, args
);
809 fprintf_filtered (gdb_stderr
, "\n");
812 internal_error (__FILE__
, __LINE__
, _("bad switch"));
818 /* This page contains miscellaneous functions */
820 /* Return the language enum for a given language string. */
823 language_enum (char *str
)
827 for (i
= 0; i
< languages_size
; i
++)
828 if (strcmp (languages
[i
]->la_name
, str
) == 0)
829 return languages
[i
]->la_language
;
831 return language_unknown
;
834 /* Return the language struct for a given language enum. */
836 const struct language_defn
*
837 language_def (enum language lang
)
841 for (i
= 0; i
< languages_size
; i
++)
843 if (languages
[i
]->la_language
== lang
)
851 /* Return the language as a string */
853 language_str (enum language lang
)
857 for (i
= 0; i
< languages_size
; i
++)
859 if (languages
[i
]->la_language
== lang
)
861 return languages
[i
]->la_name
;
868 set_check (char *ignore
, int from_tty
)
871 "\"set check\" must be followed by the name of a check subcommand.\n");
872 help_list (setchecklist
, "set check ", -1, gdb_stdout
);
876 show_check (char *ignore
, int from_tty
)
878 cmd_show_list (showchecklist
, from_tty
, "");
881 /* Add a language to the set of known languages. */
884 add_language (const struct language_defn
*lang
)
886 /* For the "set language" command. */
887 static char **language_names
= NULL
;
888 /* For the "help set language" command. */
889 char *language_set_doc
= NULL
;
892 struct ui_file
*tmp_stream
;
894 if (lang
->la_magic
!= LANG_MAGIC
)
896 fprintf_unfiltered (gdb_stderr
, "Magic number of %s language struct wrong\n",
898 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
903 languages_allocsize
= DEFAULT_ALLOCSIZE
;
904 languages
= (const struct language_defn
**) xmalloc
905 (languages_allocsize
* sizeof (*languages
));
907 if (languages_size
>= languages_allocsize
)
909 languages_allocsize
*= 2;
910 languages
= (const struct language_defn
**) xrealloc ((char *) languages
,
911 languages_allocsize
* sizeof (*languages
));
913 languages
[languages_size
++] = lang
;
915 /* Build the language names array, to be used as enumeration in the
916 set language" enum command. */
917 language_names
= xrealloc (language_names
,
918 (languages_size
+ 1) * sizeof (const char *));
919 for (i
= 0; i
< languages_size
; ++i
)
920 language_names
[i
] = languages
[i
]->la_name
;
921 language_names
[i
] = NULL
;
923 /* Build the "help set language" docs. */
924 tmp_stream
= mem_fileopen ();
926 fprintf_unfiltered (tmp_stream
, _("\
927 Set the current source language.\n\
928 The currently understood settings are:\n\n\
929 local or auto Automatic setting based on source file\n"));
931 for (i
= 0; i
< languages_size
; ++i
)
933 /* Already dealt with these above. */
934 if (languages
[i
]->la_language
== language_unknown
935 || languages
[i
]->la_language
== language_auto
)
938 /* FIXME: i18n: for now assume that the human-readable name
939 is just a capitalization of the internal name. */
940 fprintf_unfiltered (tmp_stream
, "%-16s Use the %c%s language\n",
941 languages
[i
]->la_name
,
942 /* Capitalize first letter of language
944 toupper (languages
[i
]->la_name
[0]),
945 languages
[i
]->la_name
+ 1);
948 language_set_doc
= ui_file_xstrdup (tmp_stream
, NULL
);
949 ui_file_delete (tmp_stream
);
951 add_setshow_enum_cmd ("language", class_support
,
952 (const char **) language_names
,
954 language_set_doc
, _("\
955 Show the current source language."), NULL
,
956 set_language_command
,
957 show_language_command
,
958 &setlist
, &showlist
);
960 xfree (language_set_doc
);
963 /* Iterate through all registered languages looking for and calling
964 any non-NULL struct language_defn.skip_trampoline() functions.
965 Return the result from the first that returns non-zero, or 0 if all
968 skip_language_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
972 for (i
= 0; i
< languages_size
; i
++)
974 if (languages
[i
]->skip_trampoline
)
976 CORE_ADDR real_pc
= (languages
[i
]->skip_trampoline
) (frame
, pc
);
985 /* Return demangled language symbol, or NULL.
986 FIXME: Options are only useful for certain languages and ignored
987 by others, so it would be better to remove them here and have a
988 more flexible demangler for the languages that need it.
989 FIXME: Sometimes the demangler is invoked when we don't know the
990 language, so we can't use this everywhere. */
992 language_demangle (const struct language_defn
*current_language
,
993 const char *mangled
, int options
)
995 if (current_language
!= NULL
&& current_language
->la_demangle
)
996 return current_language
->la_demangle (mangled
, options
);
1000 /* Return class name from physname or NULL. */
1002 language_class_name_from_physname (const struct language_defn
*current_language
,
1003 const char *physname
)
1005 if (current_language
!= NULL
&& current_language
->la_class_name_from_physname
)
1006 return current_language
->la_class_name_from_physname (physname
);
1010 /* Return non-zero if TYPE should be passed (and returned) by
1011 reference at the language level. */
1013 language_pass_by_reference (struct type
*type
)
1015 return current_language
->la_pass_by_reference (type
);
1018 /* Return zero; by default, types are passed by value at the language
1019 level. The target ABI may pass or return some structs by reference
1020 independent of this. */
1022 default_pass_by_reference (struct type
*type
)
1027 /* Return the default string containing the list of characters
1028 delimiting words. This is a reasonable default value that
1029 most languages should be able to use. */
1032 default_word_break_characters (void)
1034 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1037 /* Print the index of array elements using the C99 syntax. */
1040 default_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
1041 const struct value_print_options
*options
)
1043 fprintf_filtered (stream
, "[");
1044 LA_VALUE_PRINT (index_value
, stream
, options
);
1045 fprintf_filtered (stream
, "] = ");
1049 default_get_string (struct value
*value
, gdb_byte
**buffer
, int *length
,
1050 struct type
**char_type
, const char **charset
)
1052 error (_("Getting a string is unsupported in this language."));
1055 /* Define the language that is no language. */
1058 unk_lang_parser (void)
1064 unk_lang_error (char *msg
)
1066 error (_("Attempted to parse an expression with unknown language"));
1070 unk_lang_emit_char (int c
, struct type
*type
, struct ui_file
*stream
,
1073 error (_("internal error - unimplemented function unk_lang_emit_char called."));
1077 unk_lang_printchar (int c
, struct type
*type
, struct ui_file
*stream
)
1079 error (_("internal error - unimplemented function unk_lang_printchar called."));
1083 unk_lang_printstr (struct ui_file
*stream
, struct type
*type
,
1084 const gdb_byte
*string
, unsigned int length
,
1086 const struct value_print_options
*options
)
1088 error (_("internal error - unimplemented function unk_lang_printstr called."));
1092 unk_lang_print_type (struct type
*type
, char *varstring
, struct ui_file
*stream
,
1093 int show
, int level
)
1095 error (_("internal error - unimplemented function unk_lang_print_type called."));
1099 unk_lang_val_print (struct type
*type
, const gdb_byte
*valaddr
,
1100 int embedded_offset
, CORE_ADDR address
,
1101 struct ui_file
*stream
, int recurse
,
1102 const struct value_print_options
*options
)
1104 error (_("internal error - unimplemented function unk_lang_val_print called."));
1108 unk_lang_value_print (struct value
*val
, struct ui_file
*stream
,
1109 const struct value_print_options
*options
)
1111 error (_("internal error - unimplemented function unk_lang_value_print called."));
1114 static CORE_ADDR
unk_lang_trampoline (struct frame_info
*frame
, CORE_ADDR pc
)
1119 /* Unknown languages just use the cplus demangler. */
1120 static char *unk_lang_demangle (const char *mangled
, int options
)
1122 return cplus_demangle (mangled
, options
);
1125 static char *unk_lang_class_name (const char *mangled
)
1130 static const struct op_print unk_op_print_tab
[] =
1132 {NULL
, OP_NULL
, PREC_NULL
, 0}
1136 unknown_language_arch_info (struct gdbarch
*gdbarch
,
1137 struct language_arch_info
*lai
)
1139 lai
->string_char_type
= builtin_type (gdbarch
)->builtin_char
;
1140 lai
->bool_type_default
= builtin_type (gdbarch
)->builtin_int
;
1141 lai
->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch
, 1,
1145 const struct language_defn unknown_language_defn
=
1154 &exp_descriptor_standard
,
1158 unk_lang_printchar
, /* Print character constant */
1161 unk_lang_print_type
, /* Print a type using appropriate syntax */
1162 default_print_typedef
, /* Print a typedef using appropriate syntax */
1163 unk_lang_val_print
, /* Print a value using appropriate syntax */
1164 unk_lang_value_print
, /* Print a top-level value */
1165 unk_lang_trampoline
, /* Language specific skip_trampoline */
1166 "this", /* name_of_this */
1167 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1168 basic_lookup_transparent_type
,/* lookup_transparent_type */
1169 unk_lang_demangle
, /* Language specific symbol demangler */
1170 unk_lang_class_name
, /* Language specific class_name_from_physname */
1171 unk_op_print_tab
, /* expression operators for printing */
1172 1, /* c-style arrays */
1173 0, /* String lower bound */
1174 default_word_break_characters
,
1175 default_make_symbol_completion_list
,
1176 unknown_language_arch_info
, /* la_language_arch_info. */
1177 default_print_array_index
,
1178 default_pass_by_reference
,
1183 /* These two structs define fake entries for the "local" and "auto" options. */
1184 const struct language_defn auto_language_defn
=
1193 &exp_descriptor_standard
,
1197 unk_lang_printchar
, /* Print character constant */
1200 unk_lang_print_type
, /* Print a type using appropriate syntax */
1201 default_print_typedef
, /* Print a typedef using appropriate syntax */
1202 unk_lang_val_print
, /* Print a value using appropriate syntax */
1203 unk_lang_value_print
, /* Print a top-level value */
1204 unk_lang_trampoline
, /* Language specific skip_trampoline */
1205 "this", /* name_of_this */
1206 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1207 basic_lookup_transparent_type
,/* lookup_transparent_type */
1208 unk_lang_demangle
, /* Language specific symbol demangler */
1209 unk_lang_class_name
, /* Language specific class_name_from_physname */
1210 unk_op_print_tab
, /* expression operators for printing */
1211 1, /* c-style arrays */
1212 0, /* String lower bound */
1213 default_word_break_characters
,
1214 default_make_symbol_completion_list
,
1215 unknown_language_arch_info
, /* la_language_arch_info. */
1216 default_print_array_index
,
1217 default_pass_by_reference
,
1222 const struct language_defn local_language_defn
=
1231 &exp_descriptor_standard
,
1235 unk_lang_printchar
, /* Print character constant */
1238 unk_lang_print_type
, /* Print a type using appropriate syntax */
1239 default_print_typedef
, /* Print a typedef using appropriate syntax */
1240 unk_lang_val_print
, /* Print a value using appropriate syntax */
1241 unk_lang_value_print
, /* Print a top-level value */
1242 unk_lang_trampoline
, /* Language specific skip_trampoline */
1243 "this", /* name_of_this */
1244 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
1245 basic_lookup_transparent_type
,/* lookup_transparent_type */
1246 unk_lang_demangle
, /* Language specific symbol demangler */
1247 unk_lang_class_name
, /* Language specific class_name_from_physname */
1248 unk_op_print_tab
, /* expression operators for printing */
1249 1, /* c-style arrays */
1250 0, /* String lower bound */
1251 default_word_break_characters
,
1252 default_make_symbol_completion_list
,
1253 unknown_language_arch_info
, /* la_language_arch_info. */
1254 default_print_array_index
,
1255 default_pass_by_reference
,
1260 /* Per-architecture language information. */
1262 static struct gdbarch_data
*language_gdbarch_data
;
1264 struct language_gdbarch
1266 /* A vector of per-language per-architecture info. Indexed by "enum
1268 struct language_arch_info arch_info
[nr_languages
];
1272 language_gdbarch_post_init (struct gdbarch
*gdbarch
)
1274 struct language_gdbarch
*l
;
1277 l
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct language_gdbarch
);
1278 for (i
= 0; i
< languages_size
; i
++)
1280 if (languages
[i
] != NULL
1281 && languages
[i
]->la_language_arch_info
!= NULL
)
1282 languages
[i
]->la_language_arch_info
1283 (gdbarch
, l
->arch_info
+ languages
[i
]->la_language
);
1289 language_string_char_type (const struct language_defn
*la
,
1290 struct gdbarch
*gdbarch
)
1292 struct language_gdbarch
*ld
= gdbarch_data (gdbarch
,
1293 language_gdbarch_data
);
1294 return ld
->arch_info
[la
->la_language
].string_char_type
;
1298 language_bool_type (const struct language_defn
*la
,
1299 struct gdbarch
*gdbarch
)
1301 struct language_gdbarch
*ld
= gdbarch_data (gdbarch
,
1302 language_gdbarch_data
);
1304 if (ld
->arch_info
[la
->la_language
].bool_type_symbol
)
1307 sym
= lookup_symbol (ld
->arch_info
[la
->la_language
].bool_type_symbol
,
1308 NULL
, VAR_DOMAIN
, NULL
);
1311 struct type
*type
= SYMBOL_TYPE (sym
);
1312 if (type
&& TYPE_CODE (type
) == TYPE_CODE_BOOL
)
1317 return ld
->arch_info
[la
->la_language
].bool_type_default
;
1321 language_lookup_primitive_type_by_name (const struct language_defn
*la
,
1322 struct gdbarch
*gdbarch
,
1325 struct language_gdbarch
*ld
= gdbarch_data (gdbarch
,
1326 language_gdbarch_data
);
1327 struct type
*const *p
;
1328 for (p
= ld
->arch_info
[la
->la_language
].primitive_type_vector
;
1332 if (strcmp (TYPE_NAME (*p
), name
) == 0)
1338 /* Initialize the language routines */
1341 _initialize_language (void)
1343 static const char *type_or_range_names
[]
1344 = { "on", "off", "warn", "auto", NULL
};
1346 static const char *case_sensitive_names
[]
1347 = { "on", "off", "auto", NULL
};
1349 language_gdbarch_data
1350 = gdbarch_data_register_post_init (language_gdbarch_post_init
);
1352 /* GDB commands for language specific stuff */
1354 add_prefix_cmd ("check", no_class
, set_check
,
1355 _("Set the status of the type/range checker."),
1356 &setchecklist
, "set check ", 0, &setlist
);
1357 add_alias_cmd ("c", "check", no_class
, 1, &setlist
);
1358 add_alias_cmd ("ch", "check", no_class
, 1, &setlist
);
1360 add_prefix_cmd ("check", no_class
, show_check
,
1361 _("Show the status of the type/range checker."),
1362 &showchecklist
, "show check ", 0, &showlist
);
1363 add_alias_cmd ("c", "check", no_class
, 1, &showlist
);
1364 add_alias_cmd ("ch", "check", no_class
, 1, &showlist
);
1366 add_setshow_enum_cmd ("type", class_support
, type_or_range_names
, &type
, _("\
1367 Set type checking. (on/warn/off/auto)"), _("\
1368 Show type checking. (on/warn/off/auto)"), NULL
,
1371 &setchecklist
, &showchecklist
);
1373 add_setshow_enum_cmd ("range", class_support
, type_or_range_names
,
1375 Set range checking. (on/warn/off/auto)"), _("\
1376 Show range checking. (on/warn/off/auto)"), NULL
,
1379 &setchecklist
, &showchecklist
);
1381 add_setshow_enum_cmd ("case-sensitive", class_support
, case_sensitive_names
,
1382 &case_sensitive
, _("\
1383 Set case sensitivity in name search. (on/off/auto)"), _("\
1384 Show case sensitivity in name search. (on/off/auto)"), _("\
1385 For Fortran the default is off; for other languages the default is on."),
1388 &setlist
, &showlist
);
1390 add_language (&auto_language_defn
);
1391 add_language (&local_language_defn
);
1392 add_language (&unknown_language_defn
);
1394 language
= xstrdup ("auto");
1395 type
= xstrdup ("auto");
1396 range
= xstrdup ("auto");
1397 case_sensitive
= xstrdup ("auto");
1399 /* Have the above take effect */
1400 set_language (language_auto
);