Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Multiple source language support for GDB. |
1bac305b | 2 | |
0b302171 JB |
3 | Copyright (C) 1991-1996, 1998-2005, 2007-2012 Free Software |
4 | Foundation, Inc. | |
1bac305b | 5 | |
c906108c SS |
6 | Contributed by the Department of Computer Science at the State University |
7 | of New York at Buffalo. | |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
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 | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 14 | (at your option) any later version. |
c906108c | 15 | |
c5aa993b JM |
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. | |
c906108c | 20 | |
c5aa993b | 21 | You should have received a copy of the GNU General Public License |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
23 | |
24 | /* This file contains functions that return things that are specific | |
25 | to languages. Each function should examine current_language if necessary, | |
1777feb0 | 26 | and return the appropriate result. */ |
c906108c SS |
27 | |
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. */ | |
31 | ||
32 | #include "defs.h" | |
33 | #include <ctype.h> | |
34 | #include "gdb_string.h" | |
35 | ||
36 | #include "symtab.h" | |
37 | #include "gdbtypes.h" | |
38 | #include "value.h" | |
39 | #include "gdbcmd.h" | |
c906108c SS |
40 | #include "expression.h" |
41 | #include "language.h" | |
42 | #include "target.h" | |
43 | #include "parser-defs.h" | |
8caabe69 | 44 | #include "jv-lang.h" |
9a3d7dfd | 45 | #include "demangle.h" |
8b60591b | 46 | #include "symfile.h" |
c906108c | 47 | |
a14ed312 | 48 | extern void _initialize_language (void); |
392a587b | 49 | |
a14ed312 | 50 | static void unk_lang_error (char *); |
c906108c | 51 | |
a14ed312 | 52 | static int unk_lang_parser (void); |
c906108c | 53 | |
a14ed312 | 54 | static void show_check (char *, int); |
c906108c | 55 | |
a14ed312 | 56 | static void set_check (char *, int); |
c906108c | 57 | |
63872f9d | 58 | static void set_type_range_case (void); |
c906108c | 59 | |
6c7a06a3 TT |
60 | static void unk_lang_emit_char (int c, struct type *type, |
61 | struct ui_file *stream, int quoter); | |
c906108c | 62 | |
6c7a06a3 TT |
63 | static void unk_lang_printchar (int c, struct type *type, |
64 | struct ui_file *stream); | |
c906108c | 65 | |
25b524e8 | 66 | static void unk_lang_print_type (struct type *, const char *, struct ui_file *, |
d9fcf2fb | 67 | int, int); |
c906108c | 68 | |
79a45b7d TT |
69 | static int unk_lang_value_print (struct value *, struct ui_file *, |
70 | const struct value_print_options *); | |
c906108c | 71 | |
52f729a7 | 72 | static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); |
f636b87d | 73 | |
c906108c SS |
74 | /* Forward declaration */ |
75 | extern const struct language_defn unknown_language_defn; | |
c5aa993b | 76 | |
c906108c | 77 | /* The current (default at startup) state of type and range checking. |
c5aa993b JM |
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. */ | |
c906108c SS |
81 | |
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; | |
63872f9d JG |
86 | enum case_mode case_mode = case_mode_auto; |
87 | enum case_sensitivity case_sensitivity = case_sensitive_on; | |
c906108c | 88 | |
1777feb0 | 89 | /* The current language and language_mode (see language.h). */ |
c906108c SS |
90 | |
91 | const struct language_defn *current_language = &unknown_language_defn; | |
92 | enum language_mode language_mode = language_mode_auto; | |
93 | ||
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). */ | |
96 | ||
97 | const struct language_defn *expected_language; | |
98 | ||
99 | /* The list of supported languages. The list itself is malloc'd. */ | |
100 | ||
101 | static const struct language_defn **languages; | |
102 | static unsigned languages_size; | |
103 | static unsigned languages_allocsize; | |
104 | #define DEFAULT_ALLOCSIZE 4 | |
105 | ||
b84aa90a PA |
106 | /* The current values of the "set language/type/range" enum |
107 | commands. */ | |
108 | static const char *language; | |
109 | static const char *type; | |
110 | static const char *range; | |
111 | static const char *case_sensitive; | |
c906108c SS |
112 | |
113 | /* Warning issued when current_language and the language of the current | |
1777feb0 | 114 | frame do not match. */ |
c906108c | 115 | char lang_frame_mismatch_warn[] = |
c5aa993b | 116 | "Warning: the current language does not match this frame."; |
c906108c SS |
117 | \f |
118 | /* This page contains the functions corresponding to GDB commands | |
1777feb0 | 119 | and their helpers. */ |
c906108c SS |
120 | |
121 | /* Show command. Display a warning if the language set | |
1777feb0 | 122 | does not match the frame. */ |
c906108c | 123 | static void |
4d28ad1e AC |
124 | show_language_command (struct ui_file *file, int from_tty, |
125 | struct cmd_list_element *c, const char *value) | |
c906108c | 126 | { |
1777feb0 | 127 | enum language flang; /* The language of the current frame. */ |
c906108c | 128 | |
b84aa90a PA |
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); | |
134 | else | |
3e43a32a MS |
135 | fprintf_filtered (gdb_stdout, |
136 | _("The current source language is \"%s\".\n"), | |
b84aa90a PA |
137 | current_language->la_name); |
138 | ||
c5aa993b JM |
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); | |
c906108c SS |
144 | } |
145 | ||
1777feb0 | 146 | /* Set command. Change the current working language. */ |
c906108c | 147 | static void |
4d28ad1e | 148 | set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) |
c906108c | 149 | { |
5efd5804 | 150 | int i; |
c906108c | 151 | enum language flang; |
c906108c SS |
152 | |
153 | /* Search the list of languages for a match. */ | |
c5aa993b JM |
154 | for (i = 0; i < languages_size; i++) |
155 | { | |
6314a349 | 156 | if (strcmp (languages[i]->la_name, language) == 0) |
c5aa993b JM |
157 | { |
158 | /* Found it! Go into manual mode, and use this language. */ | |
159 | if (languages[i]->la_language == language_auto) | |
160 | { | |
8b60591b JB |
161 | /* Enter auto mode. Set to the current frame's language, if |
162 | known, or fallback to the initial language. */ | |
c5aa993b JM |
163 | language_mode = language_mode_auto; |
164 | flang = get_frame_language (); | |
165 | if (flang != language_unknown) | |
166 | set_language (flang); | |
8b60591b JB |
167 | else |
168 | set_initial_language (); | |
c5aa993b JM |
169 | expected_language = current_language; |
170 | return; | |
171 | } | |
172 | else | |
173 | { | |
174 | /* Enter manual mode. Set the specified language. */ | |
175 | language_mode = language_mode_manual; | |
176 | current_language = languages[i]; | |
63872f9d | 177 | set_type_range_case (); |
c5aa993b JM |
178 | expected_language = current_language; |
179 | return; | |
180 | } | |
181 | } | |
c906108c | 182 | } |
c906108c | 183 | |
b84aa90a PA |
184 | internal_error (__FILE__, __LINE__, |
185 | "Couldn't find language `%s' in known languages list.", | |
186 | language); | |
c906108c SS |
187 | } |
188 | ||
189 | /* Show command. Display a warning if the type setting does | |
1777feb0 | 190 | not match the current language. */ |
c906108c | 191 | static void |
4d28ad1e AC |
192 | show_type_command (struct ui_file *file, int from_tty, |
193 | struct cmd_list_element *c, const char *value) | |
c906108c | 194 | { |
b84aa90a PA |
195 | if (type_mode == type_mode_auto) |
196 | { | |
197 | char *tmp = NULL; | |
198 | ||
199 | switch (type_check) | |
200 | { | |
201 | case type_check_on: | |
202 | tmp = "on"; | |
203 | break; | |
204 | case type_check_off: | |
205 | tmp = "off"; | |
206 | break; | |
207 | case type_check_warn: | |
208 | tmp = "warn"; | |
209 | break; | |
210 | default: | |
211 | internal_error (__FILE__, __LINE__, | |
212 | "Unrecognized type check setting."); | |
213 | } | |
214 | ||
215 | fprintf_filtered (gdb_stdout, | |
216 | _("Type checking is \"auto; currently %s\".\n"), | |
217 | tmp); | |
218 | } | |
219 | else | |
220 | fprintf_filtered (gdb_stdout, _("Type checking is \"%s\".\n"), | |
221 | value); | |
222 | ||
223 | if (type_check != current_language->la_type_check) | |
224 | warning (_("the current type check setting" | |
225 | " does not match the language.\n")); | |
c906108c SS |
226 | } |
227 | ||
1777feb0 | 228 | /* Set command. Change the setting for type checking. */ |
c906108c | 229 | static void |
4d28ad1e | 230 | set_type_command (char *ignore, int from_tty, struct cmd_list_element *c) |
c906108c | 231 | { |
6314a349 | 232 | if (strcmp (type, "on") == 0) |
c5aa993b | 233 | { |
c906108c SS |
234 | type_check = type_check_on; |
235 | type_mode = type_mode_manual; | |
c5aa993b | 236 | } |
6314a349 | 237 | else if (strcmp (type, "warn") == 0) |
c5aa993b | 238 | { |
c906108c SS |
239 | type_check = type_check_warn; |
240 | type_mode = type_mode_manual; | |
c5aa993b | 241 | } |
6314a349 | 242 | else if (strcmp (type, "off") == 0) |
c5aa993b | 243 | { |
c906108c SS |
244 | type_check = type_check_off; |
245 | type_mode = type_mode_manual; | |
c5aa993b | 246 | } |
6314a349 | 247 | else if (strcmp (type, "auto") == 0) |
c5aa993b | 248 | { |
c906108c | 249 | type_mode = type_mode_auto; |
63872f9d | 250 | set_type_range_case (); |
c906108c | 251 | return; |
c5aa993b | 252 | } |
c4093a6a | 253 | else |
b84aa90a PA |
254 | internal_error (__FILE__, __LINE__, |
255 | _("Unrecognized type check setting: \"%s\""), type); | |
256 | ||
257 | if (type_check != current_language->la_type_check) | |
258 | warning (_("the current type check setting" | |
259 | " does not match the language.\n")); | |
c906108c SS |
260 | } |
261 | ||
262 | /* Show command. Display a warning if the range setting does | |
1777feb0 | 263 | not match the current language. */ |
c906108c | 264 | static void |
4d28ad1e AC |
265 | show_range_command (struct ui_file *file, int from_tty, |
266 | struct cmd_list_element *c, const char *value) | |
c906108c | 267 | { |
b84aa90a PA |
268 | if (range_mode == range_mode_auto) |
269 | { | |
270 | char *tmp; | |
271 | ||
272 | switch (range_check) | |
273 | { | |
274 | case range_check_on: | |
275 | tmp = "on"; | |
276 | break; | |
277 | case range_check_off: | |
278 | tmp = "off"; | |
279 | break; | |
280 | case range_check_warn: | |
281 | tmp = "warn"; | |
282 | break; | |
283 | default: | |
284 | internal_error (__FILE__, __LINE__, | |
285 | "Unrecognized range check setting."); | |
286 | } | |
287 | ||
288 | fprintf_filtered (gdb_stdout, | |
289 | _("Range checking is \"auto; currently %s\".\n"), | |
290 | tmp); | |
291 | } | |
292 | else | |
293 | fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"), | |
294 | value); | |
295 | ||
c5aa993b | 296 | if (range_check != current_language->la_range_check) |
b84aa90a PA |
297 | warning (_("the current range check setting " |
298 | "does not match the language.\n")); | |
c906108c SS |
299 | } |
300 | ||
1777feb0 | 301 | /* Set command. Change the setting for range checking. */ |
c906108c | 302 | static void |
4d28ad1e | 303 | set_range_command (char *ignore, int from_tty, struct cmd_list_element *c) |
c906108c | 304 | { |
6314a349 | 305 | if (strcmp (range, "on") == 0) |
c5aa993b | 306 | { |
c906108c SS |
307 | range_check = range_check_on; |
308 | range_mode = range_mode_manual; | |
c5aa993b | 309 | } |
6314a349 | 310 | else if (strcmp (range, "warn") == 0) |
c5aa993b | 311 | { |
c906108c SS |
312 | range_check = range_check_warn; |
313 | range_mode = range_mode_manual; | |
c5aa993b | 314 | } |
6314a349 | 315 | else if (strcmp (range, "off") == 0) |
c5aa993b | 316 | { |
c906108c SS |
317 | range_check = range_check_off; |
318 | range_mode = range_mode_manual; | |
c5aa993b | 319 | } |
6314a349 | 320 | else if (strcmp (range, "auto") == 0) |
c5aa993b | 321 | { |
c906108c | 322 | range_mode = range_mode_auto; |
63872f9d | 323 | set_type_range_case (); |
c906108c | 324 | return; |
c5aa993b | 325 | } |
c4093a6a JM |
326 | else |
327 | { | |
b84aa90a PA |
328 | internal_error (__FILE__, __LINE__, |
329 | _("Unrecognized range check setting: \"%s\""), range); | |
c4093a6a | 330 | } |
b84aa90a PA |
331 | if (range_check != current_language->la_range_check) |
332 | warning (_("the current range check setting " | |
333 | "does not match the language.\n")); | |
c906108c SS |
334 | } |
335 | ||
63872f9d | 336 | /* Show command. Display a warning if the case sensitivity setting does |
1777feb0 | 337 | not match the current language. */ |
63872f9d | 338 | static void |
4d28ad1e AC |
339 | show_case_command (struct ui_file *file, int from_tty, |
340 | struct cmd_list_element *c, const char *value) | |
63872f9d | 341 | { |
b84aa90a PA |
342 | if (case_mode == case_mode_auto) |
343 | { | |
344 | char *tmp = NULL; | |
345 | ||
346 | switch (case_sensitivity) | |
347 | { | |
348 | case case_sensitive_on: | |
349 | tmp = "on"; | |
350 | break; | |
351 | case case_sensitive_off: | |
352 | tmp = "off"; | |
353 | break; | |
354 | default: | |
355 | internal_error (__FILE__, __LINE__, | |
356 | "Unrecognized case-sensitive setting."); | |
357 | } | |
358 | ||
359 | fprintf_filtered (gdb_stdout, | |
360 | _("Case sensitivity in " | |
361 | "name search is \"auto; currently %s\".\n"), | |
362 | tmp); | |
363 | } | |
364 | else | |
3e43a32a MS |
365 | fprintf_filtered (gdb_stdout, |
366 | _("Case sensitivity in name search is \"%s\".\n"), | |
b84aa90a PA |
367 | value); |
368 | ||
4d28ad1e | 369 | if (case_sensitivity != current_language->la_case_sensitivity) |
b84aa90a PA |
370 | warning (_("the current case sensitivity setting does not match " |
371 | "the language.\n")); | |
63872f9d JG |
372 | } |
373 | ||
591e78ff MK |
374 | /* Set command. Change the setting for case sensitivity. */ |
375 | ||
63872f9d | 376 | static void |
4d28ad1e | 377 | set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) |
63872f9d | 378 | { |
591e78ff MK |
379 | if (strcmp (case_sensitive, "on") == 0) |
380 | { | |
381 | case_sensitivity = case_sensitive_on; | |
382 | case_mode = case_mode_manual; | |
383 | } | |
384 | else if (strcmp (case_sensitive, "off") == 0) | |
385 | { | |
386 | case_sensitivity = case_sensitive_off; | |
387 | case_mode = case_mode_manual; | |
388 | } | |
389 | else if (strcmp (case_sensitive, "auto") == 0) | |
390 | { | |
391 | case_mode = case_mode_auto; | |
392 | set_type_range_case (); | |
591e78ff MK |
393 | return; |
394 | } | |
63872f9d | 395 | else |
591e78ff | 396 | { |
b84aa90a PA |
397 | internal_error (__FILE__, __LINE__, |
398 | "Unrecognized case-sensitive setting: \"%s\"", | |
399 | case_sensitive); | |
591e78ff | 400 | } |
b84aa90a PA |
401 | |
402 | if (case_sensitivity != current_language->la_case_sensitivity) | |
403 | warning (_("the current case sensitivity setting does not match " | |
404 | "the language.\n")); | |
63872f9d JG |
405 | } |
406 | ||
407 | /* Set the status of range and type checking and case sensitivity based on | |
c906108c SS |
408 | the current modes and the current language. |
409 | If SHOW is non-zero, then print out the current language, | |
1777feb0 | 410 | type and range checking status. */ |
c906108c | 411 | static void |
63872f9d | 412 | set_type_range_case (void) |
c906108c | 413 | { |
c906108c SS |
414 | if (range_mode == range_mode_auto) |
415 | range_check = current_language->la_range_check; | |
416 | ||
417 | if (type_mode == type_mode_auto) | |
418 | type_check = current_language->la_type_check; | |
419 | ||
63872f9d JG |
420 | if (case_mode == case_mode_auto) |
421 | case_sensitivity = current_language->la_case_sensitivity; | |
c906108c SS |
422 | } |
423 | ||
1777feb0 MS |
424 | /* Set current language to (enum language) LANG. Returns previous |
425 | language. */ | |
c906108c SS |
426 | |
427 | enum language | |
fba45db2 | 428 | set_language (enum language lang) |
c906108c SS |
429 | { |
430 | int i; | |
431 | enum language prev_language; | |
432 | ||
433 | prev_language = current_language->la_language; | |
434 | ||
c5aa993b JM |
435 | for (i = 0; i < languages_size; i++) |
436 | { | |
437 | if (languages[i]->la_language == lang) | |
438 | { | |
439 | current_language = languages[i]; | |
63872f9d | 440 | set_type_range_case (); |
c5aa993b JM |
441 | break; |
442 | } | |
c906108c | 443 | } |
c906108c SS |
444 | |
445 | return prev_language; | |
446 | } | |
447 | \f | |
c906108c SS |
448 | |
449 | /* Print out the current language settings: language, range and | |
450 | type checking. If QUIETLY, print only what has changed. */ | |
451 | ||
452 | void | |
fba45db2 | 453 | language_info (int quietly) |
c906108c SS |
454 | { |
455 | if (quietly && expected_language == current_language) | |
456 | return; | |
457 | ||
458 | expected_language = current_language; | |
a3f17187 | 459 | printf_unfiltered (_("Current language: %s\n"), language); |
4d28ad1e | 460 | show_language_command (NULL, 1, NULL, NULL); |
c906108c SS |
461 | |
462 | if (!quietly) | |
463 | { | |
a3f17187 | 464 | printf_unfiltered (_("Type checking: %s\n"), type); |
4d28ad1e | 465 | show_type_command (NULL, 1, NULL, NULL); |
a3f17187 | 466 | printf_unfiltered (_("Range checking: %s\n"), range); |
4d28ad1e | 467 | show_range_command (NULL, 1, NULL, NULL); |
a3f17187 | 468 | printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); |
4d28ad1e | 469 | show_case_command (NULL, 1, NULL, NULL); |
c906108c SS |
470 | } |
471 | } | |
472 | \f | |
c906108c | 473 | |
1777feb0 | 474 | /* Returns non-zero if the value is a pointer type. */ |
c906108c | 475 | int |
fba45db2 | 476 | pointer_type (struct type *type) |
c906108c | 477 | { |
c5aa993b JM |
478 | return TYPE_CODE (type) == TYPE_CODE_PTR || |
479 | TYPE_CODE (type) == TYPE_CODE_REF; | |
c906108c SS |
480 | } |
481 | ||
c906108c | 482 | \f |
c906108c | 483 | /* This page contains functions that return info about |
1777feb0 | 484 | (struct value) values used in GDB. */ |
c906108c | 485 | |
1777feb0 | 486 | /* Returns non-zero if the value VAL represents a true value. */ |
c906108c | 487 | int |
3d6d86c6 | 488 | value_true (struct value *val) |
c906108c SS |
489 | { |
490 | /* It is possible that we should have some sort of error if a non-boolean | |
491 | value is used in this context. Possibly dependent on some kind of | |
492 | "boolean-checking" option like range checking. But it should probably | |
493 | not depend on the language except insofar as is necessary to identify | |
494 | a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean | |
495 | should be an error, probably). */ | |
496 | return !value_logical_not (val); | |
497 | } | |
498 | \f | |
c906108c SS |
499 | /* This page contains functions for the printing out of |
500 | error messages that occur during type- and range- | |
1777feb0 | 501 | checking. */ |
c906108c | 502 | |
ddfe3c15 AC |
503 | /* These are called when a language fails a type- or range-check. The |
504 | first argument should be a printf()-style format string, and the | |
505 | rest of the arguments should be its arguments. If | |
506 | [type|range]_check is [type|range]_check_on, an error is printed; | |
507 | if [type|range]_check_warn, a warning; otherwise just the | |
1777feb0 | 508 | message. */ |
c906108c SS |
509 | |
510 | void | |
ddfe3c15 | 511 | type_error (const char *string,...) |
c906108c | 512 | { |
c5aa993b | 513 | va_list args; |
c906108c | 514 | |
e0881a8e | 515 | va_start (args, string); |
ddfe3c15 AC |
516 | switch (type_check) |
517 | { | |
518 | case type_check_warn: | |
519 | vwarning (string, args); | |
520 | break; | |
521 | case type_check_on: | |
522 | verror (string, args); | |
523 | break; | |
524 | case type_check_off: | |
525 | /* FIXME: cagney/2002-01-30: Should this function print anything | |
526 | when type error is off? */ | |
527 | vfprintf_filtered (gdb_stderr, string, args); | |
528 | fprintf_filtered (gdb_stderr, "\n"); | |
529 | break; | |
530 | default: | |
e2e0b3e5 | 531 | internal_error (__FILE__, __LINE__, _("bad switch")); |
ddfe3c15 | 532 | } |
c5aa993b | 533 | va_end (args); |
c906108c SS |
534 | } |
535 | ||
536 | void | |
ddfe3c15 | 537 | range_error (const char *string,...) |
c906108c | 538 | { |
c5aa993b | 539 | va_list args; |
c906108c | 540 | |
e0881a8e | 541 | va_start (args, string); |
ddfe3c15 AC |
542 | switch (range_check) |
543 | { | |
544 | case range_check_warn: | |
545 | vwarning (string, args); | |
546 | break; | |
547 | case range_check_on: | |
548 | verror (string, args); | |
549 | break; | |
550 | case range_check_off: | |
551 | /* FIXME: cagney/2002-01-30: Should this function print anything | |
552 | when range error is off? */ | |
553 | vfprintf_filtered (gdb_stderr, string, args); | |
554 | fprintf_filtered (gdb_stderr, "\n"); | |
555 | break; | |
556 | default: | |
e2e0b3e5 | 557 | internal_error (__FILE__, __LINE__, _("bad switch")); |
ddfe3c15 | 558 | } |
c5aa993b | 559 | va_end (args); |
c906108c | 560 | } |
c906108c | 561 | \f |
c5aa993b | 562 | |
1777feb0 | 563 | /* This page contains miscellaneous functions. */ |
c906108c | 564 | |
1777feb0 | 565 | /* Return the language enum for a given language string. */ |
c906108c SS |
566 | |
567 | enum language | |
fba45db2 | 568 | language_enum (char *str) |
c906108c SS |
569 | { |
570 | int i; | |
571 | ||
c5aa993b | 572 | for (i = 0; i < languages_size; i++) |
591e78ff | 573 | if (strcmp (languages[i]->la_name, str) == 0) |
c906108c SS |
574 | return languages[i]->la_language; |
575 | ||
576 | return language_unknown; | |
577 | } | |
578 | ||
1777feb0 | 579 | /* Return the language struct for a given language enum. */ |
c906108c SS |
580 | |
581 | const struct language_defn * | |
fba45db2 | 582 | language_def (enum language lang) |
c906108c SS |
583 | { |
584 | int i; | |
585 | ||
c5aa993b JM |
586 | for (i = 0; i < languages_size; i++) |
587 | { | |
588 | if (languages[i]->la_language == lang) | |
589 | { | |
590 | return languages[i]; | |
591 | } | |
c906108c | 592 | } |
c906108c SS |
593 | return NULL; |
594 | } | |
595 | ||
1777feb0 | 596 | /* Return the language as a string. */ |
c906108c | 597 | char * |
fba45db2 | 598 | language_str (enum language lang) |
c906108c SS |
599 | { |
600 | int i; | |
601 | ||
c5aa993b JM |
602 | for (i = 0; i < languages_size; i++) |
603 | { | |
604 | if (languages[i]->la_language == lang) | |
605 | { | |
606 | return languages[i]->la_name; | |
607 | } | |
c906108c | 608 | } |
c906108c SS |
609 | return "Unknown"; |
610 | } | |
611 | ||
612 | static void | |
fba45db2 | 613 | set_check (char *ignore, int from_tty) |
c906108c | 614 | { |
c5aa993b JM |
615 | printf_unfiltered ( |
616 | "\"set check\" must be followed by the name of a check subcommand.\n"); | |
617 | help_list (setchecklist, "set check ", -1, gdb_stdout); | |
c906108c SS |
618 | } |
619 | ||
620 | static void | |
fba45db2 | 621 | show_check (char *ignore, int from_tty) |
c906108c | 622 | { |
c5aa993b | 623 | cmd_show_list (showchecklist, from_tty, ""); |
c906108c SS |
624 | } |
625 | \f | |
626 | /* Add a language to the set of known languages. */ | |
627 | ||
628 | void | |
fba45db2 | 629 | add_language (const struct language_defn *lang) |
c906108c | 630 | { |
b84aa90a PA |
631 | /* For the "set language" command. */ |
632 | static char **language_names = NULL; | |
633 | /* For the "help set language" command. */ | |
1eefb858 | 634 | char *language_set_doc = NULL; |
b84aa90a PA |
635 | |
636 | int i; | |
637 | struct ui_file *tmp_stream; | |
b84aa90a | 638 | |
c906108c SS |
639 | if (lang->la_magic != LANG_MAGIC) |
640 | { | |
3e43a32a MS |
641 | fprintf_unfiltered (gdb_stderr, |
642 | "Magic number of %s language struct wrong\n", | |
c5aa993b | 643 | lang->la_name); |
3e43a32a MS |
644 | internal_error (__FILE__, __LINE__, |
645 | _("failed internal consistency check")); | |
c906108c SS |
646 | } |
647 | ||
648 | if (!languages) | |
649 | { | |
650 | languages_allocsize = DEFAULT_ALLOCSIZE; | |
651 | languages = (const struct language_defn **) xmalloc | |
652 | (languages_allocsize * sizeof (*languages)); | |
653 | } | |
654 | if (languages_size >= languages_allocsize) | |
655 | { | |
656 | languages_allocsize *= 2; | |
657 | languages = (const struct language_defn **) xrealloc ((char *) languages, | |
c5aa993b | 658 | languages_allocsize * sizeof (*languages)); |
c906108c SS |
659 | } |
660 | languages[languages_size++] = lang; | |
b84aa90a PA |
661 | |
662 | /* Build the language names array, to be used as enumeration in the | |
663 | set language" enum command. */ | |
664 | language_names = xrealloc (language_names, | |
665 | (languages_size + 1) * sizeof (const char *)); | |
666 | for (i = 0; i < languages_size; ++i) | |
667 | language_names[i] = languages[i]->la_name; | |
668 | language_names[i] = NULL; | |
669 | ||
670 | /* Build the "help set language" docs. */ | |
671 | tmp_stream = mem_fileopen (); | |
672 | ||
3e43a32a MS |
673 | fprintf_unfiltered (tmp_stream, |
674 | _("Set the current source language.\n" | |
675 | "The currently understood settings are:\n\nlocal or " | |
676 | "auto Automatic setting based on source file\n")); | |
b84aa90a PA |
677 | |
678 | for (i = 0; i < languages_size; ++i) | |
679 | { | |
680 | /* Already dealt with these above. */ | |
681 | if (languages[i]->la_language == language_unknown | |
682 | || languages[i]->la_language == language_auto) | |
683 | continue; | |
684 | ||
685 | /* FIXME: i18n: for now assume that the human-readable name | |
686 | is just a capitalization of the internal name. */ | |
687 | fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n", | |
688 | languages[i]->la_name, | |
689 | /* Capitalize first letter of language | |
690 | name. */ | |
691 | toupper (languages[i]->la_name[0]), | |
692 | languages[i]->la_name + 1); | |
693 | } | |
694 | ||
759ef836 | 695 | language_set_doc = ui_file_xstrdup (tmp_stream, NULL); |
b84aa90a PA |
696 | ui_file_delete (tmp_stream); |
697 | ||
698 | add_setshow_enum_cmd ("language", class_support, | |
699 | (const char **) language_names, | |
700 | &language, | |
3e43a32a MS |
701 | language_set_doc, |
702 | _("Show the current source language."), | |
703 | NULL, set_language_command, | |
b84aa90a PA |
704 | show_language_command, |
705 | &setlist, &showlist); | |
1eefb858 TT |
706 | |
707 | xfree (language_set_doc); | |
c906108c SS |
708 | } |
709 | ||
f636b87d AF |
710 | /* Iterate through all registered languages looking for and calling |
711 | any non-NULL struct language_defn.skip_trampoline() functions. | |
712 | Return the result from the first that returns non-zero, or 0 if all | |
713 | `fail'. */ | |
714 | CORE_ADDR | |
52f729a7 | 715 | skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) |
f636b87d AF |
716 | { |
717 | int i; | |
718 | ||
719 | for (i = 0; i < languages_size; i++) | |
720 | { | |
721 | if (languages[i]->skip_trampoline) | |
722 | { | |
52f729a7 | 723 | CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); |
e0881a8e | 724 | |
f636b87d AF |
725 | if (real_pc) |
726 | return real_pc; | |
727 | } | |
728 | } | |
729 | ||
730 | return 0; | |
731 | } | |
732 | ||
1777feb0 | 733 | /* Return demangled language symbol, or NULL. |
9a3d7dfd AF |
734 | FIXME: Options are only useful for certain languages and ignored |
735 | by others, so it would be better to remove them here and have a | |
1777feb0 | 736 | more flexible demangler for the languages that need it. |
9a3d7dfd AF |
737 | FIXME: Sometimes the demangler is invoked when we don't know the |
738 | language, so we can't use this everywhere. */ | |
739 | char * | |
740 | language_demangle (const struct language_defn *current_language, | |
741 | const char *mangled, int options) | |
742 | { | |
743 | if (current_language != NULL && current_language->la_demangle) | |
744 | return current_language->la_demangle (mangled, options); | |
745 | return NULL; | |
746 | } | |
747 | ||
31c27f77 JJ |
748 | /* Return class name from physname or NULL. */ |
749 | char * | |
79b97fa8 | 750 | language_class_name_from_physname (const struct language_defn *lang, |
31c27f77 JJ |
751 | const char *physname) |
752 | { | |
79b97fa8 TT |
753 | if (lang != NULL && lang->la_class_name_from_physname) |
754 | return lang->la_class_name_from_physname (physname); | |
31c27f77 JJ |
755 | return NULL; |
756 | } | |
757 | ||
41f1b697 DJ |
758 | /* Return non-zero if TYPE should be passed (and returned) by |
759 | reference at the language level. */ | |
760 | int | |
761 | language_pass_by_reference (struct type *type) | |
762 | { | |
763 | return current_language->la_pass_by_reference (type); | |
764 | } | |
765 | ||
766 | /* Return zero; by default, types are passed by value at the language | |
767 | level. The target ABI may pass or return some structs by reference | |
768 | independent of this. */ | |
769 | int | |
770 | default_pass_by_reference (struct type *type) | |
771 | { | |
772 | return 0; | |
773 | } | |
774 | ||
9f0a5303 JB |
775 | /* Return the default string containing the list of characters |
776 | delimiting words. This is a reasonable default value that | |
777 | most languages should be able to use. */ | |
778 | ||
779 | char * | |
780 | default_word_break_characters (void) | |
781 | { | |
782 | return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; | |
783 | } | |
f636b87d | 784 | |
e79af960 JB |
785 | /* Print the index of array elements using the C99 syntax. */ |
786 | ||
787 | void | |
788 | default_print_array_index (struct value *index_value, struct ui_file *stream, | |
79a45b7d | 789 | const struct value_print_options *options) |
e79af960 JB |
790 | { |
791 | fprintf_filtered (stream, "["); | |
79a45b7d | 792 | LA_VALUE_PRINT (index_value, stream, options); |
e79af960 JB |
793 | fprintf_filtered (stream, "] = "); |
794 | } | |
795 | ||
ae6a3a4c TJB |
796 | void |
797 | default_get_string (struct value *value, gdb_byte **buffer, int *length, | |
96c07c5b | 798 | struct type **char_type, const char **charset) |
ae6a3a4c TJB |
799 | { |
800 | error (_("Getting a string is unsupported in this language.")); | |
801 | } | |
802 | ||
c906108c SS |
803 | /* Define the language that is no language. */ |
804 | ||
805 | static int | |
fba45db2 | 806 | unk_lang_parser (void) |
c906108c SS |
807 | { |
808 | return 1; | |
809 | } | |
810 | ||
811 | static void | |
fba45db2 | 812 | unk_lang_error (char *msg) |
c906108c | 813 | { |
8a3fe4f8 | 814 | error (_("Attempted to parse an expression with unknown language")); |
c906108c SS |
815 | } |
816 | ||
817 | static void | |
6c7a06a3 TT |
818 | unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, |
819 | int quoter) | |
c906108c | 820 | { |
3e43a32a MS |
821 | error (_("internal error - unimplemented " |
822 | "function unk_lang_emit_char called.")); | |
c906108c SS |
823 | } |
824 | ||
825 | static void | |
6c7a06a3 | 826 | unk_lang_printchar (int c, struct type *type, struct ui_file *stream) |
c906108c | 827 | { |
3e43a32a MS |
828 | error (_("internal error - unimplemented " |
829 | "function unk_lang_printchar called.")); | |
c906108c SS |
830 | } |
831 | ||
832 | static void | |
6c7a06a3 TT |
833 | unk_lang_printstr (struct ui_file *stream, struct type *type, |
834 | const gdb_byte *string, unsigned int length, | |
be759fcf | 835 | const char *encoding, int force_ellipses, |
79a45b7d | 836 | const struct value_print_options *options) |
c906108c | 837 | { |
3e43a32a MS |
838 | error (_("internal error - unimplemented " |
839 | "function unk_lang_printstr called.")); | |
c906108c SS |
840 | } |
841 | ||
c906108c | 842 | static void |
25b524e8 JK |
843 | unk_lang_print_type (struct type *type, const char *varstring, |
844 | struct ui_file *stream, int show, int level) | |
c906108c | 845 | { |
3e43a32a MS |
846 | error (_("internal error - unimplemented " |
847 | "function unk_lang_print_type called.")); | |
c906108c SS |
848 | } |
849 | ||
850 | static int | |
fc1a4b47 | 851 | unk_lang_val_print (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd | 852 | int embedded_offset, CORE_ADDR address, |
79a45b7d | 853 | struct ui_file *stream, int recurse, |
0e03807e | 854 | const struct value *val, |
79a45b7d | 855 | const struct value_print_options *options) |
c906108c | 856 | { |
3e43a32a MS |
857 | error (_("internal error - unimplemented " |
858 | "function unk_lang_val_print called.")); | |
c906108c SS |
859 | } |
860 | ||
861 | static int | |
79a45b7d TT |
862 | unk_lang_value_print (struct value *val, struct ui_file *stream, |
863 | const struct value_print_options *options) | |
c906108c | 864 | { |
3e43a32a MS |
865 | error (_("internal error - unimplemented " |
866 | "function unk_lang_value_print called.")); | |
c906108c SS |
867 | } |
868 | ||
52f729a7 | 869 | static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) |
f636b87d AF |
870 | { |
871 | return 0; | |
872 | } | |
873 | ||
9a3d7dfd AF |
874 | /* Unknown languages just use the cplus demangler. */ |
875 | static char *unk_lang_demangle (const char *mangled, int options) | |
876 | { | |
877 | return cplus_demangle (mangled, options); | |
878 | } | |
879 | ||
31c27f77 JJ |
880 | static char *unk_lang_class_name (const char *mangled) |
881 | { | |
882 | return NULL; | |
883 | } | |
9a3d7dfd | 884 | |
c5aa993b JM |
885 | static const struct op_print unk_op_print_tab[] = |
886 | { | |
887 | {NULL, OP_NULL, PREC_NULL, 0} | |
c906108c SS |
888 | }; |
889 | ||
f290d38e AC |
890 | static void |
891 | unknown_language_arch_info (struct gdbarch *gdbarch, | |
892 | struct language_arch_info *lai) | |
893 | { | |
894 | lai->string_char_type = builtin_type (gdbarch)->builtin_char; | |
fbb06eb1 | 895 | lai->bool_type_default = builtin_type (gdbarch)->builtin_int; |
5a44ea29 | 896 | lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, |
f290d38e AC |
897 | struct type *); |
898 | } | |
899 | ||
c5aa993b JM |
900 | const struct language_defn unknown_language_defn = |
901 | { | |
c906108c SS |
902 | "unknown", |
903 | language_unknown, | |
c906108c SS |
904 | range_check_off, |
905 | type_check_off, | |
63872f9d | 906 | case_sensitive_on, |
9a044a89 TT |
907 | array_row_major, |
908 | macro_expansion_no, | |
5f9769d1 | 909 | &exp_descriptor_standard, |
c906108c SS |
910 | unk_lang_parser, |
911 | unk_lang_error, | |
e85c3284 | 912 | null_post_parser, |
c906108c SS |
913 | unk_lang_printchar, /* Print character constant */ |
914 | unk_lang_printstr, | |
915 | unk_lang_emit_char, | |
c906108c | 916 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 917 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
c906108c SS |
918 | unk_lang_val_print, /* Print a value using appropriate syntax */ |
919 | unk_lang_value_print, /* Print a top-level value */ | |
f636b87d | 920 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 921 | "this", /* name_of_this */ |
5f9a71c3 | 922 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
b368761e | 923 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
9a3d7dfd | 924 | unk_lang_demangle, /* Language specific symbol demangler */ |
3e43a32a MS |
925 | unk_lang_class_name, /* Language specific |
926 | class_name_from_physname */ | |
c906108c SS |
927 | unk_op_print_tab, /* expression operators for printing */ |
928 | 1, /* c-style arrays */ | |
929 | 0, /* String lower bound */ | |
6084f43a | 930 | default_word_break_characters, |
41d27058 | 931 | default_make_symbol_completion_list, |
f290d38e | 932 | unknown_language_arch_info, /* la_language_arch_info. */ |
e79af960 | 933 | default_print_array_index, |
41f1b697 | 934 | default_pass_by_reference, |
ae6a3a4c | 935 | default_get_string, |
f8eba3c6 TT |
936 | strcmp_iw_ordered, |
937 | iterate_over_symbols, | |
c906108c SS |
938 | LANG_MAGIC |
939 | }; | |
940 | ||
1777feb0 MS |
941 | /* These two structs define fake entries for the "local" and "auto" |
942 | options. */ | |
c5aa993b JM |
943 | const struct language_defn auto_language_defn = |
944 | { | |
c906108c SS |
945 | "auto", |
946 | language_auto, | |
c906108c SS |
947 | range_check_off, |
948 | type_check_off, | |
63872f9d | 949 | case_sensitive_on, |
9a044a89 TT |
950 | array_row_major, |
951 | macro_expansion_no, | |
5f9769d1 | 952 | &exp_descriptor_standard, |
c906108c SS |
953 | unk_lang_parser, |
954 | unk_lang_error, | |
e85c3284 | 955 | null_post_parser, |
c906108c SS |
956 | unk_lang_printchar, /* Print character constant */ |
957 | unk_lang_printstr, | |
958 | unk_lang_emit_char, | |
c906108c | 959 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 960 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
c906108c SS |
961 | unk_lang_val_print, /* Print a value using appropriate syntax */ |
962 | unk_lang_value_print, /* Print a top-level value */ | |
f636b87d | 963 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 964 | "this", /* name_of_this */ |
5f9a71c3 | 965 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
b368761e | 966 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
9a3d7dfd | 967 | unk_lang_demangle, /* Language specific symbol demangler */ |
3e43a32a MS |
968 | unk_lang_class_name, /* Language specific |
969 | class_name_from_physname */ | |
c906108c SS |
970 | unk_op_print_tab, /* expression operators for printing */ |
971 | 1, /* c-style arrays */ | |
972 | 0, /* String lower bound */ | |
6084f43a | 973 | default_word_break_characters, |
41d27058 | 974 | default_make_symbol_completion_list, |
f290d38e | 975 | unknown_language_arch_info, /* la_language_arch_info. */ |
e79af960 | 976 | default_print_array_index, |
41f1b697 | 977 | default_pass_by_reference, |
ae6a3a4c | 978 | default_get_string, |
f8eba3c6 TT |
979 | strcmp_iw_ordered, |
980 | iterate_over_symbols, | |
c906108c SS |
981 | LANG_MAGIC |
982 | }; | |
983 | ||
c5aa993b JM |
984 | const struct language_defn local_language_defn = |
985 | { | |
c906108c SS |
986 | "local", |
987 | language_auto, | |
c906108c SS |
988 | range_check_off, |
989 | type_check_off, | |
63872f9d | 990 | case_sensitive_on, |
7ca2d3a3 | 991 | array_row_major, |
9a044a89 | 992 | macro_expansion_no, |
5f9769d1 | 993 | &exp_descriptor_standard, |
c906108c SS |
994 | unk_lang_parser, |
995 | unk_lang_error, | |
e85c3284 | 996 | null_post_parser, |
c906108c SS |
997 | unk_lang_printchar, /* Print character constant */ |
998 | unk_lang_printstr, | |
999 | unk_lang_emit_char, | |
c906108c | 1000 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 1001 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
c906108c SS |
1002 | unk_lang_val_print, /* Print a value using appropriate syntax */ |
1003 | unk_lang_value_print, /* Print a top-level value */ | |
f636b87d | 1004 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 1005 | "this", /* name_of_this */ |
5f9a71c3 | 1006 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
b368761e | 1007 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
9a3d7dfd | 1008 | unk_lang_demangle, /* Language specific symbol demangler */ |
3e43a32a MS |
1009 | unk_lang_class_name, /* Language specific |
1010 | class_name_from_physname */ | |
c906108c SS |
1011 | unk_op_print_tab, /* expression operators for printing */ |
1012 | 1, /* c-style arrays */ | |
1013 | 0, /* String lower bound */ | |
6084f43a | 1014 | default_word_break_characters, |
41d27058 | 1015 | default_make_symbol_completion_list, |
f290d38e | 1016 | unknown_language_arch_info, /* la_language_arch_info. */ |
e79af960 | 1017 | default_print_array_index, |
41f1b697 | 1018 | default_pass_by_reference, |
ae6a3a4c | 1019 | default_get_string, |
f8eba3c6 TT |
1020 | strcmp_iw_ordered, |
1021 | iterate_over_symbols, | |
c906108c SS |
1022 | LANG_MAGIC |
1023 | }; | |
1024 | \f | |
f290d38e AC |
1025 | /* Per-architecture language information. */ |
1026 | ||
1027 | static struct gdbarch_data *language_gdbarch_data; | |
1028 | ||
1029 | struct language_gdbarch | |
1030 | { | |
1031 | /* A vector of per-language per-architecture info. Indexed by "enum | |
1032 | language". */ | |
1033 | struct language_arch_info arch_info[nr_languages]; | |
1034 | }; | |
1035 | ||
1036 | static void * | |
1037 | language_gdbarch_post_init (struct gdbarch *gdbarch) | |
1038 | { | |
1039 | struct language_gdbarch *l; | |
1040 | int i; | |
1041 | ||
1042 | l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); | |
1285b746 | 1043 | for (i = 0; i < languages_size; i++) |
f290d38e AC |
1044 | { |
1045 | if (languages[i] != NULL | |
1046 | && languages[i]->la_language_arch_info != NULL) | |
1047 | languages[i]->la_language_arch_info | |
1048 | (gdbarch, l->arch_info + languages[i]->la_language); | |
1049 | } | |
1050 | return l; | |
1051 | } | |
1052 | ||
1053 | struct type * | |
1054 | language_string_char_type (const struct language_defn *la, | |
1055 | struct gdbarch *gdbarch) | |
1056 | { | |
1057 | struct language_gdbarch *ld = gdbarch_data (gdbarch, | |
1058 | language_gdbarch_data); | |
e0881a8e | 1059 | |
aba2dd37 | 1060 | return ld->arch_info[la->la_language].string_char_type; |
f290d38e AC |
1061 | } |
1062 | ||
fbb06eb1 UW |
1063 | struct type * |
1064 | language_bool_type (const struct language_defn *la, | |
1065 | struct gdbarch *gdbarch) | |
1066 | { | |
1067 | struct language_gdbarch *ld = gdbarch_data (gdbarch, | |
1068 | language_gdbarch_data); | |
1069 | ||
1070 | if (ld->arch_info[la->la_language].bool_type_symbol) | |
1071 | { | |
1072 | struct symbol *sym; | |
e0881a8e | 1073 | |
fbb06eb1 UW |
1074 | sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, |
1075 | NULL, VAR_DOMAIN, NULL); | |
1076 | if (sym) | |
1077 | { | |
1078 | struct type *type = SYMBOL_TYPE (sym); | |
e0881a8e | 1079 | |
fbb06eb1 UW |
1080 | if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) |
1081 | return type; | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | return ld->arch_info[la->la_language].bool_type_default; | |
1086 | } | |
1087 | ||
f290d38e | 1088 | struct type * |
5a44ea29 | 1089 | language_lookup_primitive_type_by_name (const struct language_defn *la, |
f290d38e AC |
1090 | struct gdbarch *gdbarch, |
1091 | const char *name) | |
1092 | { | |
1093 | struct language_gdbarch *ld = gdbarch_data (gdbarch, | |
1094 | language_gdbarch_data); | |
aba2dd37 | 1095 | struct type *const *p; |
e0881a8e | 1096 | |
aba2dd37 UW |
1097 | for (p = ld->arch_info[la->la_language].primitive_type_vector; |
1098 | (*p) != NULL; | |
1099 | p++) | |
f290d38e | 1100 | { |
aba2dd37 UW |
1101 | if (strcmp (TYPE_NAME (*p), name) == 0) |
1102 | return (*p); | |
f290d38e AC |
1103 | } |
1104 | return (NULL); | |
1105 | } | |
1106 | ||
1777feb0 | 1107 | /* Initialize the language routines. */ |
c906108c SS |
1108 | |
1109 | void | |
fba45db2 | 1110 | _initialize_language (void) |
c906108c | 1111 | { |
b84aa90a PA |
1112 | static const char *type_or_range_names[] |
1113 | = { "on", "off", "warn", "auto", NULL }; | |
1114 | ||
1115 | static const char *case_sensitive_names[] | |
1116 | = { "on", "off", "auto", NULL }; | |
c5aa993b | 1117 | |
f290d38e AC |
1118 | language_gdbarch_data |
1119 | = gdbarch_data_register_post_init (language_gdbarch_post_init); | |
1120 | ||
1777feb0 | 1121 | /* GDB commands for language specific stuff. */ |
c5aa993b | 1122 | |
c5aa993b | 1123 | add_prefix_cmd ("check", no_class, set_check, |
1bedd215 | 1124 | _("Set the status of the type/range checker."), |
c5aa993b JM |
1125 | &setchecklist, "set check ", 0, &setlist); |
1126 | add_alias_cmd ("c", "check", no_class, 1, &setlist); | |
1127 | add_alias_cmd ("ch", "check", no_class, 1, &setlist); | |
1128 | ||
1129 | add_prefix_cmd ("check", no_class, show_check, | |
1bedd215 | 1130 | _("Show the status of the type/range checker."), |
c5aa993b JM |
1131 | &showchecklist, "show check ", 0, &showlist); |
1132 | add_alias_cmd ("c", "check", no_class, 1, &showlist); | |
1133 | add_alias_cmd ("ch", "check", no_class, 1, &showlist); | |
1134 | ||
3e43a32a MS |
1135 | add_setshow_enum_cmd ("type", class_support, type_or_range_names, &type, |
1136 | _("Set type checking. (on/warn/off/auto)"), | |
1137 | _("Show type checking. (on/warn/off/auto)"), | |
1138 | NULL, set_type_command, | |
b84aa90a PA |
1139 | show_type_command, |
1140 | &setchecklist, &showchecklist); | |
5efd5804 | 1141 | |
b84aa90a | 1142 | add_setshow_enum_cmd ("range", class_support, type_or_range_names, |
3e43a32a MS |
1143 | &range, |
1144 | _("Set range checking. (on/warn/off/auto)"), | |
1145 | _("Show range checking. (on/warn/off/auto)"), | |
1146 | NULL, set_range_command, | |
b84aa90a PA |
1147 | show_range_command, |
1148 | &setchecklist, &showchecklist); | |
1149 | ||
1150 | add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, | |
1151 | &case_sensitive, _("\ | |
4d28ad1e AC |
1152 | Set case sensitivity in name search. (on/off/auto)"), _("\ |
1153 | Show case sensitivity in name search. (on/off/auto)"), _("\ | |
1154 | For Fortran the default is off; for other languages the default is on."), | |
b84aa90a PA |
1155 | set_case_command, |
1156 | show_case_command, | |
1157 | &setlist, &showlist); | |
63872f9d | 1158 | |
c5aa993b | 1159 | add_language (&auto_language_defn); |
b84aa90a PA |
1160 | add_language (&local_language_defn); |
1161 | add_language (&unknown_language_defn); | |
c5aa993b | 1162 | |
1b36a34b JK |
1163 | language = xstrdup ("auto"); |
1164 | type = xstrdup ("auto"); | |
1165 | range = xstrdup ("auto"); | |
1166 | case_sensitive = xstrdup ("auto"); | |
63872f9d | 1167 | |
1777feb0 | 1168 | /* Have the above take effect. */ |
63872f9d | 1169 | set_language (language_auto); |
c906108c | 1170 | } |