Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Multiple source language support for GDB. |
1bac305b | 2 | |
b811d2c2 | 3 | Copyright (C) 1991-2020 Free Software Foundation, Inc. |
1bac305b | 4 | |
c906108c SS |
5 | Contributed by the Department of Computer Science at the State University |
6 | of New York at Buffalo. | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 13 | (at your option) any later version. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
22 | |
23 | /* This file contains functions that return things that are specific | |
24 | to languages. Each function should examine current_language if necessary, | |
1777feb0 | 25 | and return the appropriate result. */ |
c906108c SS |
26 | |
27 | /* FIXME: Most of these would be better organized as macros which | |
28 | return data out of a "language-specific" struct pointer that is set | |
29 | whenever the working language changes. That would be a lot faster. */ | |
30 | ||
31 | #include "defs.h" | |
32 | #include <ctype.h> | |
c906108c SS |
33 | #include "symtab.h" |
34 | #include "gdbtypes.h" | |
35 | #include "value.h" | |
36 | #include "gdbcmd.h" | |
c906108c SS |
37 | #include "expression.h" |
38 | #include "language.h" | |
a53b64ea | 39 | #include "varobj.h" |
c906108c SS |
40 | #include "target.h" |
41 | #include "parser-defs.h" | |
9a3d7dfd | 42 | #include "demangle.h" |
8b60591b | 43 | #include "symfile.h" |
8de20a37 | 44 | #include "cp-support.h" |
06096720 | 45 | #include "frame.h" |
43cc5389 | 46 | #include "c-lang.h" |
47e77640 | 47 | #include <algorithm> |
0d12e84c | 48 | #include "gdbarch.h" |
c906108c | 49 | |
410a0ff2 | 50 | static int unk_lang_parser (struct parser_state *); |
c906108c | 51 | |
a451cb65 | 52 | static void set_range_case (void); |
c906108c | 53 | |
6c7a06a3 TT |
54 | static void unk_lang_emit_char (int c, struct type *type, |
55 | struct ui_file *stream, int quoter); | |
c906108c | 56 | |
6c7a06a3 TT |
57 | static void unk_lang_printchar (int c, struct type *type, |
58 | struct ui_file *stream); | |
c906108c | 59 | |
8e069a98 TT |
60 | static void unk_lang_value_print (struct value *, struct ui_file *, |
61 | const struct value_print_options *); | |
c906108c | 62 | |
52f729a7 | 63 | static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); |
f636b87d | 64 | |
c906108c | 65 | /* The current (default at startup) state of type and range checking. |
c5aa993b JM |
66 | (If the modes are set to "auto", though, these are changed based |
67 | on the default language at startup, and then again based on the | |
68 | language of the first source file. */ | |
c906108c SS |
69 | |
70 | enum range_mode range_mode = range_mode_auto; | |
71 | enum range_check range_check = range_check_off; | |
63872f9d JG |
72 | enum case_mode case_mode = case_mode_auto; |
73 | enum case_sensitivity case_sensitivity = case_sensitive_on; | |
c906108c | 74 | |
1777feb0 | 75 | /* The current language and language_mode (see language.h). */ |
c906108c | 76 | |
0874fd07 | 77 | const struct language_defn *current_language = nullptr; |
c906108c SS |
78 | enum language_mode language_mode = language_mode_auto; |
79 | ||
80 | /* The language that the user expects to be typing in (the language | |
81 | of main(), or the last language we notified them about, or C). */ | |
82 | ||
83 | const struct language_defn *expected_language; | |
84 | ||
0874fd07 AB |
85 | /* Define the array containing all languages. */ |
86 | ||
87 | const struct language_defn *language_defn::languages[nr_languages]; | |
c906108c | 88 | |
814fa4f6 | 89 | /* The current values of the "set language/range/case-sensitive" enum |
b84aa90a PA |
90 | commands. */ |
91 | static const char *language; | |
b84aa90a PA |
92 | static const char *range; |
93 | static const char *case_sensitive; | |
c906108c | 94 | |
34916edc CB |
95 | /* See language.h. */ |
96 | const char lang_frame_mismatch_warn[] = | |
97 | N_("Warning: the current language does not match this frame."); | |
c906108c SS |
98 | \f |
99 | /* This page contains the functions corresponding to GDB commands | |
1777feb0 | 100 | and their helpers. */ |
c906108c SS |
101 | |
102 | /* Show command. Display a warning if the language set | |
1777feb0 | 103 | does not match the frame. */ |
c906108c | 104 | static void |
4d28ad1e AC |
105 | show_language_command (struct ui_file *file, int from_tty, |
106 | struct cmd_list_element *c, const char *value) | |
c906108c | 107 | { |
7ff38b1c | 108 | enum language flang; /* The language of the frame. */ |
c906108c | 109 | |
b84aa90a PA |
110 | if (language_mode == language_mode_auto) |
111 | fprintf_filtered (gdb_stdout, | |
112 | _("The current source language is " | |
113 | "\"auto; currently %s\".\n"), | |
114 | current_language->la_name); | |
115 | else | |
3e43a32a MS |
116 | fprintf_filtered (gdb_stdout, |
117 | _("The current source language is \"%s\".\n"), | |
b84aa90a PA |
118 | current_language->la_name); |
119 | ||
7ff38b1c AB |
120 | if (has_stack_frames ()) |
121 | { | |
122 | struct frame_info *frame; | |
123 | ||
124 | frame = get_selected_frame (NULL); | |
125 | flang = get_frame_language (frame); | |
126 | if (flang != language_unknown | |
127 | && language_mode == language_mode_manual | |
128 | && current_language->la_language != flang) | |
34916edc | 129 | printf_filtered ("%s\n", _(lang_frame_mismatch_warn)); |
7ff38b1c | 130 | } |
c906108c SS |
131 | } |
132 | ||
1777feb0 | 133 | /* Set command. Change the current working language. */ |
c906108c | 134 | static void |
eb4c3f4a TT |
135 | set_language_command (const char *ignore, |
136 | int from_tty, struct cmd_list_element *c) | |
c906108c | 137 | { |
7ff38b1c | 138 | enum language flang = language_unknown; |
c906108c | 139 | |
47e77640 PA |
140 | /* "local" is a synonym of "auto". */ |
141 | if (strcmp (language, "local") == 0) | |
142 | language = "auto"; | |
143 | ||
c906108c | 144 | /* Search the list of languages for a match. */ |
0874fd07 | 145 | for (const auto &lang : language_defn::languages) |
c5aa993b | 146 | { |
47e77640 | 147 | if (strcmp (lang->la_name, language) == 0) |
c5aa993b JM |
148 | { |
149 | /* Found it! Go into manual mode, and use this language. */ | |
47e77640 | 150 | if (lang->la_language == language_auto) |
c5aa993b | 151 | { |
8b60591b JB |
152 | /* Enter auto mode. Set to the current frame's language, if |
153 | known, or fallback to the initial language. */ | |
c5aa993b | 154 | language_mode = language_mode_auto; |
a70b8144 | 155 | try |
7ff38b1c AB |
156 | { |
157 | struct frame_info *frame; | |
158 | ||
159 | frame = get_selected_frame (NULL); | |
160 | flang = get_frame_language (frame); | |
161 | } | |
230d2906 | 162 | catch (const gdb_exception_error &ex) |
7ff38b1c AB |
163 | { |
164 | flang = language_unknown; | |
165 | } | |
7ff38b1c | 166 | |
c5aa993b JM |
167 | if (flang != language_unknown) |
168 | set_language (flang); | |
8b60591b JB |
169 | else |
170 | set_initial_language (); | |
c5aa993b JM |
171 | expected_language = current_language; |
172 | return; | |
173 | } | |
174 | else | |
175 | { | |
176 | /* Enter manual mode. Set the specified language. */ | |
177 | language_mode = language_mode_manual; | |
47e77640 | 178 | current_language = lang; |
a451cb65 | 179 | set_range_case (); |
c5aa993b JM |
180 | expected_language = current_language; |
181 | return; | |
182 | } | |
183 | } | |
c906108c | 184 | } |
c906108c | 185 | |
b84aa90a PA |
186 | internal_error (__FILE__, __LINE__, |
187 | "Couldn't find language `%s' in known languages list.", | |
188 | language); | |
c906108c SS |
189 | } |
190 | ||
c906108c | 191 | /* Show command. Display a warning if the range setting does |
1777feb0 | 192 | not match the current language. */ |
c906108c | 193 | static void |
4d28ad1e AC |
194 | show_range_command (struct ui_file *file, int from_tty, |
195 | struct cmd_list_element *c, const char *value) | |
c906108c | 196 | { |
b84aa90a PA |
197 | if (range_mode == range_mode_auto) |
198 | { | |
a121b7c1 | 199 | const char *tmp; |
b84aa90a PA |
200 | |
201 | switch (range_check) | |
202 | { | |
203 | case range_check_on: | |
204 | tmp = "on"; | |
205 | break; | |
206 | case range_check_off: | |
207 | tmp = "off"; | |
208 | break; | |
209 | case range_check_warn: | |
210 | tmp = "warn"; | |
211 | break; | |
212 | default: | |
213 | internal_error (__FILE__, __LINE__, | |
214 | "Unrecognized range check setting."); | |
215 | } | |
216 | ||
217 | fprintf_filtered (gdb_stdout, | |
218 | _("Range checking is \"auto; currently %s\".\n"), | |
219 | tmp); | |
220 | } | |
221 | else | |
222 | fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"), | |
223 | value); | |
224 | ||
c5aa993b | 225 | if (range_check != current_language->la_range_check) |
b84aa90a PA |
226 | warning (_("the current range check setting " |
227 | "does not match the language.\n")); | |
c906108c SS |
228 | } |
229 | ||
1777feb0 | 230 | /* Set command. Change the setting for range checking. */ |
c906108c | 231 | static void |
eb4c3f4a TT |
232 | set_range_command (const char *ignore, |
233 | int from_tty, struct cmd_list_element *c) | |
c906108c | 234 | { |
6314a349 | 235 | if (strcmp (range, "on") == 0) |
c5aa993b | 236 | { |
c906108c SS |
237 | range_check = range_check_on; |
238 | range_mode = range_mode_manual; | |
c5aa993b | 239 | } |
6314a349 | 240 | else if (strcmp (range, "warn") == 0) |
c5aa993b | 241 | { |
c906108c SS |
242 | range_check = range_check_warn; |
243 | range_mode = range_mode_manual; | |
c5aa993b | 244 | } |
6314a349 | 245 | else if (strcmp (range, "off") == 0) |
c5aa993b | 246 | { |
c906108c SS |
247 | range_check = range_check_off; |
248 | range_mode = range_mode_manual; | |
c5aa993b | 249 | } |
6314a349 | 250 | else if (strcmp (range, "auto") == 0) |
c5aa993b | 251 | { |
c906108c | 252 | range_mode = range_mode_auto; |
a451cb65 | 253 | set_range_case (); |
c906108c | 254 | return; |
c5aa993b | 255 | } |
c4093a6a JM |
256 | else |
257 | { | |
b84aa90a PA |
258 | internal_error (__FILE__, __LINE__, |
259 | _("Unrecognized range check setting: \"%s\""), range); | |
c4093a6a | 260 | } |
b84aa90a PA |
261 | if (range_check != current_language->la_range_check) |
262 | warning (_("the current range check setting " | |
263 | "does not match the language.\n")); | |
c906108c SS |
264 | } |
265 | ||
63872f9d | 266 | /* Show command. Display a warning if the case sensitivity setting does |
1777feb0 | 267 | not match the current language. */ |
63872f9d | 268 | static void |
4d28ad1e AC |
269 | show_case_command (struct ui_file *file, int from_tty, |
270 | struct cmd_list_element *c, const char *value) | |
63872f9d | 271 | { |
b84aa90a PA |
272 | if (case_mode == case_mode_auto) |
273 | { | |
a121b7c1 | 274 | const char *tmp = NULL; |
b84aa90a PA |
275 | |
276 | switch (case_sensitivity) | |
277 | { | |
278 | case case_sensitive_on: | |
279 | tmp = "on"; | |
280 | break; | |
281 | case case_sensitive_off: | |
282 | tmp = "off"; | |
283 | break; | |
284 | default: | |
285 | internal_error (__FILE__, __LINE__, | |
286 | "Unrecognized case-sensitive setting."); | |
287 | } | |
288 | ||
289 | fprintf_filtered (gdb_stdout, | |
290 | _("Case sensitivity in " | |
291 | "name search is \"auto; currently %s\".\n"), | |
292 | tmp); | |
293 | } | |
294 | else | |
3e43a32a MS |
295 | fprintf_filtered (gdb_stdout, |
296 | _("Case sensitivity in name search is \"%s\".\n"), | |
b84aa90a PA |
297 | value); |
298 | ||
4d28ad1e | 299 | if (case_sensitivity != current_language->la_case_sensitivity) |
b84aa90a PA |
300 | warning (_("the current case sensitivity setting does not match " |
301 | "the language.\n")); | |
63872f9d JG |
302 | } |
303 | ||
591e78ff MK |
304 | /* Set command. Change the setting for case sensitivity. */ |
305 | ||
63872f9d | 306 | static void |
eb4c3f4a | 307 | set_case_command (const char *ignore, int from_tty, struct cmd_list_element *c) |
63872f9d | 308 | { |
591e78ff MK |
309 | if (strcmp (case_sensitive, "on") == 0) |
310 | { | |
311 | case_sensitivity = case_sensitive_on; | |
312 | case_mode = case_mode_manual; | |
313 | } | |
314 | else if (strcmp (case_sensitive, "off") == 0) | |
315 | { | |
316 | case_sensitivity = case_sensitive_off; | |
317 | case_mode = case_mode_manual; | |
318 | } | |
319 | else if (strcmp (case_sensitive, "auto") == 0) | |
320 | { | |
321 | case_mode = case_mode_auto; | |
a451cb65 | 322 | set_range_case (); |
591e78ff MK |
323 | return; |
324 | } | |
63872f9d | 325 | else |
591e78ff | 326 | { |
b84aa90a PA |
327 | internal_error (__FILE__, __LINE__, |
328 | "Unrecognized case-sensitive setting: \"%s\"", | |
329 | case_sensitive); | |
591e78ff | 330 | } |
b84aa90a PA |
331 | |
332 | if (case_sensitivity != current_language->la_case_sensitivity) | |
333 | warning (_("the current case sensitivity setting does not match " | |
334 | "the language.\n")); | |
63872f9d JG |
335 | } |
336 | ||
337 | /* Set the status of range and type checking and case sensitivity based on | |
c906108c SS |
338 | the current modes and the current language. |
339 | If SHOW is non-zero, then print out the current language, | |
1777feb0 | 340 | type and range checking status. */ |
c906108c | 341 | static void |
a451cb65 | 342 | set_range_case (void) |
c906108c | 343 | { |
c906108c SS |
344 | if (range_mode == range_mode_auto) |
345 | range_check = current_language->la_range_check; | |
346 | ||
63872f9d JG |
347 | if (case_mode == case_mode_auto) |
348 | case_sensitivity = current_language->la_case_sensitivity; | |
c906108c SS |
349 | } |
350 | ||
1777feb0 MS |
351 | /* Set current language to (enum language) LANG. Returns previous |
352 | language. */ | |
c906108c SS |
353 | |
354 | enum language | |
fba45db2 | 355 | set_language (enum language lang) |
c906108c | 356 | { |
c906108c SS |
357 | enum language prev_language; |
358 | ||
359 | prev_language = current_language->la_language; | |
0874fd07 | 360 | current_language = language_def (lang); |
47e77640 | 361 | set_range_case (); |
c906108c SS |
362 | return prev_language; |
363 | } | |
364 | \f | |
c906108c SS |
365 | |
366 | /* Print out the current language settings: language, range and | |
367 | type checking. If QUIETLY, print only what has changed. */ | |
368 | ||
369 | void | |
fba45db2 | 370 | language_info (int quietly) |
c906108c SS |
371 | { |
372 | if (quietly && expected_language == current_language) | |
373 | return; | |
374 | ||
375 | expected_language = current_language; | |
a3f17187 | 376 | printf_unfiltered (_("Current language: %s\n"), language); |
4d28ad1e | 377 | show_language_command (NULL, 1, NULL, NULL); |
c906108c SS |
378 | |
379 | if (!quietly) | |
380 | { | |
a3f17187 | 381 | printf_unfiltered (_("Range checking: %s\n"), range); |
4d28ad1e | 382 | show_range_command (NULL, 1, NULL, NULL); |
a3f17187 | 383 | printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); |
4d28ad1e | 384 | show_case_command (NULL, 1, NULL, NULL); |
c906108c SS |
385 | } |
386 | } | |
387 | \f | |
c906108c | 388 | |
1777feb0 | 389 | /* Returns non-zero if the value is a pointer type. */ |
c906108c | 390 | int |
fba45db2 | 391 | pointer_type (struct type *type) |
c906108c | 392 | { |
78134374 | 393 | return type->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type); |
c906108c SS |
394 | } |
395 | ||
c906108c | 396 | \f |
c906108c | 397 | /* This page contains functions that return info about |
1777feb0 | 398 | (struct value) values used in GDB. */ |
c906108c | 399 | |
1777feb0 | 400 | /* Returns non-zero if the value VAL represents a true value. */ |
c906108c | 401 | int |
3d6d86c6 | 402 | value_true (struct value *val) |
c906108c SS |
403 | { |
404 | /* It is possible that we should have some sort of error if a non-boolean | |
405 | value is used in this context. Possibly dependent on some kind of | |
406 | "boolean-checking" option like range checking. But it should probably | |
407 | not depend on the language except insofar as is necessary to identify | |
408 | a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean | |
409 | should be an error, probably). */ | |
410 | return !value_logical_not (val); | |
411 | } | |
412 | \f | |
c906108c SS |
413 | /* This page contains functions for the printing out of |
414 | error messages that occur during type- and range- | |
1777feb0 | 415 | checking. */ |
c906108c | 416 | |
a451cb65 | 417 | /* This is called when a language fails a range-check. The |
ddfe3c15 | 418 | first argument should be a printf()-style format string, and the |
a451cb65 KS |
419 | rest of the arguments should be its arguments. If range_check is |
420 | range_check_on, an error is printed; if range_check_warn, a warning; | |
421 | otherwise just the message. */ | |
c906108c SS |
422 | |
423 | void | |
ddfe3c15 | 424 | range_error (const char *string,...) |
c906108c | 425 | { |
c5aa993b | 426 | va_list args; |
c906108c | 427 | |
e0881a8e | 428 | va_start (args, string); |
ddfe3c15 AC |
429 | switch (range_check) |
430 | { | |
431 | case range_check_warn: | |
432 | vwarning (string, args); | |
433 | break; | |
434 | case range_check_on: | |
435 | verror (string, args); | |
436 | break; | |
437 | case range_check_off: | |
438 | /* FIXME: cagney/2002-01-30: Should this function print anything | |
439 | when range error is off? */ | |
440 | vfprintf_filtered (gdb_stderr, string, args); | |
441 | fprintf_filtered (gdb_stderr, "\n"); | |
442 | break; | |
443 | default: | |
e2e0b3e5 | 444 | internal_error (__FILE__, __LINE__, _("bad switch")); |
ddfe3c15 | 445 | } |
c5aa993b | 446 | va_end (args); |
c906108c | 447 | } |
c906108c | 448 | \f |
c5aa993b | 449 | |
1777feb0 | 450 | /* This page contains miscellaneous functions. */ |
c906108c | 451 | |
1777feb0 | 452 | /* Return the language enum for a given language string. */ |
c906108c SS |
453 | |
454 | enum language | |
2039bd9f | 455 | language_enum (const char *str) |
c906108c | 456 | { |
0874fd07 | 457 | for (const auto &lang : language_defn::languages) |
47e77640 PA |
458 | if (strcmp (lang->la_name, str) == 0) |
459 | return lang->la_language; | |
c906108c | 460 | |
47e77640 PA |
461 | if (strcmp (str, "local") == 0) |
462 | return language_auto; | |
c906108c SS |
463 | |
464 | return language_unknown; | |
465 | } | |
466 | ||
1777feb0 | 467 | /* Return the language struct for a given language enum. */ |
c906108c SS |
468 | |
469 | const struct language_defn * | |
fba45db2 | 470 | language_def (enum language lang) |
c906108c | 471 | { |
0874fd07 AB |
472 | const struct language_defn *l = language_defn::languages[lang]; |
473 | gdb_assert (l != nullptr); | |
474 | return l; | |
c906108c SS |
475 | } |
476 | ||
1777feb0 | 477 | /* Return the language as a string. */ |
47e77640 | 478 | |
27cd387b | 479 | const char * |
fba45db2 | 480 | language_str (enum language lang) |
c906108c | 481 | { |
0874fd07 | 482 | return language_def (lang)->la_name; |
c906108c SS |
483 | } |
484 | ||
c906108c | 485 | \f |
c906108c | 486 | |
47e77640 | 487 | /* Build and install the "set language LANG" command. */ |
b84aa90a | 488 | |
47e77640 PA |
489 | static void |
490 | add_set_language_command () | |
491 | { | |
492 | static const char **language_names; | |
c906108c | 493 | |
47e77640 PA |
494 | /* Build the language names array, to be used as enumeration in the |
495 | "set language" enum command. +1 for "local" and +1 for NULL | |
496 | termination. */ | |
0874fd07 | 497 | language_names = new const char *[ARRAY_SIZE (language_defn::languages) + 2]; |
47e77640 PA |
498 | |
499 | /* Display "auto", "local" and "unknown" first, and then the rest, | |
500 | alpha sorted. */ | |
501 | const char **language_names_p = language_names; | |
0874fd07 | 502 | *language_names_p++ = language_def (language_auto)->la_name; |
47e77640 | 503 | *language_names_p++ = "local"; |
0874fd07 | 504 | *language_names_p++ = language_def (language_unknown)->la_name; |
47e77640 | 505 | const char **sort_begin = language_names_p; |
0874fd07 | 506 | for (const auto &lang : language_defn::languages) |
c906108c | 507 | { |
47e77640 PA |
508 | /* Already handled above. */ |
509 | if (lang->la_language == language_auto | |
510 | || lang->la_language == language_unknown) | |
511 | continue; | |
512 | *language_names_p++ = lang->la_name; | |
c906108c | 513 | } |
47e77640 PA |
514 | *language_names_p = NULL; |
515 | std::sort (sort_begin, language_names_p, compare_cstrings); | |
b84aa90a | 516 | |
56618e20 | 517 | /* Add the filename extensions. */ |
0874fd07 | 518 | for (const auto &lang : language_defn::languages) |
47e77640 PA |
519 | if (lang->la_filename_extensions != NULL) |
520 | { | |
521 | for (size_t i = 0; lang->la_filename_extensions[i] != NULL; ++i) | |
522 | add_filename_language (lang->la_filename_extensions[i], | |
523 | lang->la_language); | |
524 | } | |
56618e20 | 525 | |
b84aa90a | 526 | /* Build the "help set language" docs. */ |
d7e74731 | 527 | string_file doc; |
b84aa90a | 528 | |
d7e74731 PA |
529 | doc.printf (_("Set the current source language.\n" |
530 | "The currently understood settings are:\n\nlocal or " | |
89549d7f | 531 | "auto Automatic setting based on source file")); |
b84aa90a | 532 | |
0874fd07 | 533 | for (const auto &lang : language_defn::languages) |
b84aa90a PA |
534 | { |
535 | /* Already dealt with these above. */ | |
47e77640 PA |
536 | if (lang->la_language == language_unknown |
537 | || lang->la_language == language_auto) | |
b84aa90a PA |
538 | continue; |
539 | ||
d7e74731 PA |
540 | /* FIXME: i18n: for now assume that the human-readable name is |
541 | just a capitalization of the internal name. */ | |
89549d7f TT |
542 | /* Note that we add the newline at the front, so we don't wind |
543 | up with a trailing newline. */ | |
544 | doc.printf ("\n%-16s Use the %c%s language", | |
47e77640 | 545 | lang->la_name, |
d7e74731 | 546 | /* Capitalize first letter of language name. */ |
47e77640 PA |
547 | toupper (lang->la_name[0]), |
548 | lang->la_name + 1); | |
b84aa90a PA |
549 | } |
550 | ||
b84aa90a | 551 | add_setshow_enum_cmd ("language", class_support, |
47e77640 | 552 | language_names, |
b84aa90a | 553 | &language, |
d7e74731 | 554 | doc.c_str (), |
3e43a32a MS |
555 | _("Show the current source language."), |
556 | NULL, set_language_command, | |
b84aa90a PA |
557 | show_language_command, |
558 | &setlist, &showlist); | |
c906108c SS |
559 | } |
560 | ||
f636b87d AF |
561 | /* Iterate through all registered languages looking for and calling |
562 | any non-NULL struct language_defn.skip_trampoline() functions. | |
563 | Return the result from the first that returns non-zero, or 0 if all | |
564 | `fail'. */ | |
565 | CORE_ADDR | |
52f729a7 | 566 | skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) |
f636b87d | 567 | { |
0874fd07 | 568 | for (const auto &lang : language_defn::languages) |
f636b87d | 569 | { |
47e77640 | 570 | if (lang->skip_trampoline != NULL) |
f636b87d | 571 | { |
47e77640 | 572 | CORE_ADDR real_pc = lang->skip_trampoline (frame, pc); |
e0881a8e | 573 | |
f636b87d AF |
574 | if (real_pc) |
575 | return real_pc; | |
576 | } | |
577 | } | |
578 | ||
579 | return 0; | |
580 | } | |
581 | ||
1777feb0 | 582 | /* Return demangled language symbol, or NULL. |
9a3d7dfd AF |
583 | FIXME: Options are only useful for certain languages and ignored |
584 | by others, so it would be better to remove them here and have a | |
1777feb0 | 585 | more flexible demangler for the languages that need it. |
9a3d7dfd AF |
586 | FIXME: Sometimes the demangler is invoked when we don't know the |
587 | language, so we can't use this everywhere. */ | |
588 | char * | |
589 | language_demangle (const struct language_defn *current_language, | |
590 | const char *mangled, int options) | |
591 | { | |
592 | if (current_language != NULL && current_language->la_demangle) | |
593 | return current_language->la_demangle (mangled, options); | |
594 | return NULL; | |
595 | } | |
596 | ||
66b8bb74 | 597 | /* See language.h. */ |
8b302db8 TT |
598 | |
599 | int | |
600 | language_sniff_from_mangled_name (const struct language_defn *lang, | |
601 | const char *mangled, char **demangled) | |
602 | { | |
603 | gdb_assert (lang != NULL); | |
604 | ||
605 | if (lang->la_sniff_from_mangled_name == NULL) | |
606 | { | |
607 | *demangled = NULL; | |
608 | return 0; | |
609 | } | |
610 | ||
611 | return lang->la_sniff_from_mangled_name (mangled, demangled); | |
612 | } | |
613 | ||
31c27f77 JJ |
614 | /* Return class name from physname or NULL. */ |
615 | char * | |
79b97fa8 | 616 | language_class_name_from_physname (const struct language_defn *lang, |
31c27f77 JJ |
617 | const char *physname) |
618 | { | |
79b97fa8 TT |
619 | if (lang != NULL && lang->la_class_name_from_physname) |
620 | return lang->la_class_name_from_physname (physname); | |
31c27f77 JJ |
621 | return NULL; |
622 | } | |
623 | ||
9d084466 TBA |
624 | /* Return information about whether TYPE should be passed |
625 | (and returned) by reference at the language level. */ | |
626 | ||
627 | struct language_pass_by_ref_info | |
41f1b697 DJ |
628 | language_pass_by_reference (struct type *type) |
629 | { | |
48448202 | 630 | return current_language->pass_by_reference_info (type); |
41f1b697 DJ |
631 | } |
632 | ||
9f0a5303 JB |
633 | /* Return the default string containing the list of characters |
634 | delimiting words. This is a reasonable default value that | |
635 | most languages should be able to use. */ | |
636 | ||
67cb5b2d | 637 | const char * |
9f0a5303 JB |
638 | default_word_break_characters (void) |
639 | { | |
640 | return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; | |
641 | } | |
f636b87d | 642 | |
5bd40f2a | 643 | /* See language.h. */ |
e79af960 JB |
644 | |
645 | void | |
5bd40f2a AB |
646 | language_defn::print_array_index (struct type *index_type, LONGEST index, |
647 | struct ui_file *stream, | |
648 | const value_print_options *options) const | |
e79af960 | 649 | { |
53a47a3e TT |
650 | struct value *index_value = value_from_longest (index_type, index); |
651 | ||
e79af960 | 652 | fprintf_filtered (stream, "["); |
79a45b7d | 653 | LA_VALUE_PRINT (index_value, stream, options); |
e79af960 JB |
654 | fprintf_filtered (stream, "] = "); |
655 | } | |
656 | ||
b5ec771e PA |
657 | /* See language.h. */ |
658 | ||
659 | bool | |
660 | default_symbol_name_matcher (const char *symbol_search_name, | |
661 | const lookup_name_info &lookup_name, | |
a207cff2 | 662 | completion_match_result *comp_match_res) |
b5ec771e | 663 | { |
e0802d59 | 664 | gdb::string_view name = lookup_name.name (); |
bd69330d PA |
665 | completion_match_for_lcd *match_for_lcd |
666 | = (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL); | |
b5ec771e PA |
667 | strncmp_iw_mode mode = (lookup_name.completion_mode () |
668 | ? strncmp_iw_mode::NORMAL | |
669 | : strncmp_iw_mode::MATCH_PARAMS); | |
670 | ||
e0802d59 | 671 | if (strncmp_iw_with_mode (symbol_search_name, name.data (), name.size (), |
bd69330d | 672 | mode, language_minimal, match_for_lcd) == 0) |
b5ec771e | 673 | { |
a207cff2 PA |
674 | if (comp_match_res != NULL) |
675 | comp_match_res->set_match (symbol_search_name); | |
b5ec771e PA |
676 | return true; |
677 | } | |
678 | else | |
679 | return false; | |
680 | } | |
681 | ||
682 | /* See language.h. */ | |
683 | ||
4be290b2 AB |
684 | bool |
685 | default_is_string_type_p (struct type *type) | |
686 | { | |
687 | type = check_typedef (type); | |
78134374 | 688 | while (type->code () == TYPE_CODE_REF) |
4be290b2 AB |
689 | { |
690 | type = TYPE_TARGET_TYPE (type); | |
691 | type = check_typedef (type); | |
692 | } | |
78134374 | 693 | return (type->code () == TYPE_CODE_STRING); |
4be290b2 AB |
694 | } |
695 | ||
696 | /* See language.h. */ | |
697 | ||
b5ec771e | 698 | symbol_name_matcher_ftype * |
618daa93 PA |
699 | get_symbol_name_matcher (const language_defn *lang, |
700 | const lookup_name_info &lookup_name) | |
b5ec771e | 701 | { |
c63d3e8d PA |
702 | /* If currently in Ada mode, and the lookup name is wrapped in |
703 | '<...>', hijack all symbol name comparisons using the Ada | |
704 | matcher, which handles the verbatim matching. */ | |
705 | if (current_language->la_language == language_ada | |
706 | && lookup_name.ada ().verbatim_p ()) | |
707 | return current_language->la_get_symbol_name_matcher (lookup_name); | |
708 | ||
b5ec771e PA |
709 | if (lang->la_get_symbol_name_matcher != nullptr) |
710 | return lang->la_get_symbol_name_matcher (lookup_name); | |
711 | return default_symbol_name_matcher; | |
712 | } | |
713 | ||
c906108c SS |
714 | /* Define the language that is no language. */ |
715 | ||
716 | static int | |
410a0ff2 | 717 | unk_lang_parser (struct parser_state *ps) |
c906108c SS |
718 | { |
719 | return 1; | |
720 | } | |
721 | ||
c906108c | 722 | static void |
6c7a06a3 TT |
723 | unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, |
724 | int quoter) | |
c906108c | 725 | { |
3e43a32a MS |
726 | error (_("internal error - unimplemented " |
727 | "function unk_lang_emit_char called.")); | |
c906108c SS |
728 | } |
729 | ||
730 | static void | |
6c7a06a3 | 731 | unk_lang_printchar (int c, struct type *type, struct ui_file *stream) |
c906108c | 732 | { |
3e43a32a MS |
733 | error (_("internal error - unimplemented " |
734 | "function unk_lang_printchar called.")); | |
c906108c SS |
735 | } |
736 | ||
737 | static void | |
6c7a06a3 TT |
738 | unk_lang_printstr (struct ui_file *stream, struct type *type, |
739 | const gdb_byte *string, unsigned int length, | |
be759fcf | 740 | const char *encoding, int force_ellipses, |
79a45b7d | 741 | const struct value_print_options *options) |
c906108c | 742 | { |
3e43a32a MS |
743 | error (_("internal error - unimplemented " |
744 | "function unk_lang_printstr called.")); | |
c906108c SS |
745 | } |
746 | ||
c906108c | 747 | static void |
25b524e8 | 748 | unk_lang_print_type (struct type *type, const char *varstring, |
79d43c61 TT |
749 | struct ui_file *stream, int show, int level, |
750 | const struct type_print_options *flags) | |
c906108c | 751 | { |
3e43a32a MS |
752 | error (_("internal error - unimplemented " |
753 | "function unk_lang_print_type called.")); | |
c906108c SS |
754 | } |
755 | ||
d3eab38a | 756 | static void |
426a9c18 TT |
757 | unk_lang_value_print_inner (struct value *val, |
758 | struct ui_file *stream, int recurse, | |
759 | const struct value_print_options *options) | |
c906108c | 760 | { |
3e43a32a | 761 | error (_("internal error - unimplemented " |
426a9c18 | 762 | "function unk_lang_value_print_inner called.")); |
c906108c SS |
763 | } |
764 | ||
8e069a98 | 765 | static void |
79a45b7d TT |
766 | unk_lang_value_print (struct value *val, struct ui_file *stream, |
767 | const struct value_print_options *options) | |
c906108c | 768 | { |
3e43a32a MS |
769 | error (_("internal error - unimplemented " |
770 | "function unk_lang_value_print called.")); | |
c906108c SS |
771 | } |
772 | ||
52f729a7 | 773 | static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) |
f636b87d AF |
774 | { |
775 | return 0; | |
776 | } | |
777 | ||
9a3d7dfd AF |
778 | /* Unknown languages just use the cplus demangler. */ |
779 | static char *unk_lang_demangle (const char *mangled, int options) | |
780 | { | |
8de20a37 | 781 | return gdb_demangle (mangled, options); |
9a3d7dfd AF |
782 | } |
783 | ||
31c27f77 JJ |
784 | static char *unk_lang_class_name (const char *mangled) |
785 | { | |
786 | return NULL; | |
787 | } | |
9a3d7dfd | 788 | |
c5aa993b JM |
789 | static const struct op_print unk_op_print_tab[] = |
790 | { | |
791 | {NULL, OP_NULL, PREC_NULL, 0} | |
c906108c SS |
792 | }; |
793 | ||
f290d38e AC |
794 | static void |
795 | unknown_language_arch_info (struct gdbarch *gdbarch, | |
796 | struct language_arch_info *lai) | |
797 | { | |
798 | lai->string_char_type = builtin_type (gdbarch)->builtin_char; | |
fbb06eb1 | 799 | lai->bool_type_default = builtin_type (gdbarch)->builtin_int; |
5a44ea29 | 800 | lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, |
f290d38e AC |
801 | struct type *); |
802 | } | |
803 | ||
0874fd07 AB |
804 | /* Constant data that describes the unknown language. */ |
805 | ||
806 | extern const struct language_data unknown_language_data = | |
c5aa993b | 807 | { |
c906108c | 808 | "unknown", |
6abde28f | 809 | "Unknown", |
c906108c | 810 | language_unknown, |
c906108c | 811 | range_check_off, |
63872f9d | 812 | case_sensitive_on, |
9a044a89 TT |
813 | array_row_major, |
814 | macro_expansion_no, | |
56618e20 | 815 | NULL, |
5f9769d1 | 816 | &exp_descriptor_standard, |
c906108c | 817 | unk_lang_parser, |
e85c3284 | 818 | null_post_parser, |
c906108c SS |
819 | unk_lang_printchar, /* Print character constant */ |
820 | unk_lang_printstr, | |
821 | unk_lang_emit_char, | |
c906108c | 822 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 823 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
426a9c18 | 824 | unk_lang_value_print_inner, /* la_value_print_inner */ |
c906108c | 825 | unk_lang_value_print, /* Print a top-level value */ |
f636b87d | 826 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 827 | "this", /* name_of_this */ |
59cc4834 | 828 | true, /* store_sym_names_in_linkage_form_p */ |
5f9a71c3 | 829 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
9a3d7dfd | 830 | unk_lang_demangle, /* Language specific symbol demangler */ |
8b302db8 | 831 | NULL, |
3e43a32a MS |
832 | unk_lang_class_name, /* Language specific |
833 | class_name_from_physname */ | |
c906108c SS |
834 | unk_op_print_tab, /* expression operators for printing */ |
835 | 1, /* c-style arrays */ | |
836 | 0, /* String lower bound */ | |
6084f43a | 837 | default_word_break_characters, |
eb3ff9a5 | 838 | default_collect_symbol_completion_matches, |
43cc5389 | 839 | c_watch_location_expression, |
b5ec771e | 840 | NULL, /* la_get_symbol_name_matcher */ |
a53b64ea | 841 | &default_varobj_ops, |
bb2ec1b3 | 842 | NULL, |
4be290b2 | 843 | default_is_string_type_p, |
721b08c6 | 844 | "{...}" /* la_struct_too_deep_ellipsis */ |
c906108c SS |
845 | }; |
846 | ||
0874fd07 AB |
847 | /* Class representing the unknown language. */ |
848 | ||
849 | class unknown_language : public language_defn | |
850 | { | |
851 | public: | |
852 | unknown_language () | |
853 | : language_defn (language_unknown, unknown_language_data) | |
854 | { /* Nothing. */ } | |
1fb314aa AB |
855 | |
856 | /* See language.h. */ | |
857 | void language_arch_info (struct gdbarch *gdbarch, | |
858 | struct language_arch_info *lai) const override | |
859 | { | |
860 | unknown_language_arch_info (gdbarch, lai); | |
861 | } | |
0874fd07 AB |
862 | }; |
863 | ||
864 | /* Single instance of the unknown language class. */ | |
865 | ||
866 | static unknown_language unknown_language_defn; | |
867 | ||
868 | /* Constant data for the fake "auto" language. */ | |
869 | ||
870 | extern const struct language_data auto_language_data = | |
c5aa993b | 871 | { |
c906108c | 872 | "auto", |
6abde28f | 873 | "Auto", |
c906108c | 874 | language_auto, |
c906108c | 875 | range_check_off, |
63872f9d | 876 | case_sensitive_on, |
9a044a89 TT |
877 | array_row_major, |
878 | macro_expansion_no, | |
56618e20 | 879 | NULL, |
5f9769d1 | 880 | &exp_descriptor_standard, |
c906108c | 881 | unk_lang_parser, |
e85c3284 | 882 | null_post_parser, |
c906108c SS |
883 | unk_lang_printchar, /* Print character constant */ |
884 | unk_lang_printstr, | |
885 | unk_lang_emit_char, | |
c906108c | 886 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 887 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
426a9c18 | 888 | unk_lang_value_print_inner, /* la_value_print_inner */ |
c906108c | 889 | unk_lang_value_print, /* Print a top-level value */ |
f636b87d | 890 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 891 | "this", /* name_of_this */ |
59cc4834 | 892 | false, /* store_sym_names_in_linkage_form_p */ |
5f9a71c3 | 893 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
9a3d7dfd | 894 | unk_lang_demangle, /* Language specific symbol demangler */ |
8b302db8 | 895 | NULL, |
3e43a32a MS |
896 | unk_lang_class_name, /* Language specific |
897 | class_name_from_physname */ | |
c906108c SS |
898 | unk_op_print_tab, /* expression operators for printing */ |
899 | 1, /* c-style arrays */ | |
900 | 0, /* String lower bound */ | |
6084f43a | 901 | default_word_break_characters, |
eb3ff9a5 | 902 | default_collect_symbol_completion_matches, |
43cc5389 | 903 | c_watch_location_expression, |
b5ec771e | 904 | NULL, /* la_get_symbol_name_matcher */ |
a53b64ea | 905 | &default_varobj_ops, |
bb2ec1b3 | 906 | NULL, |
4be290b2 | 907 | default_is_string_type_p, |
721b08c6 | 908 | "{...}" /* la_struct_too_deep_ellipsis */ |
c906108c SS |
909 | }; |
910 | ||
0874fd07 AB |
911 | /* Class representing the fake "auto" language. */ |
912 | ||
913 | class auto_language : public language_defn | |
914 | { | |
915 | public: | |
916 | auto_language () | |
917 | : language_defn (language_auto, auto_language_data) | |
918 | { /* Nothing. */ } | |
1fb314aa AB |
919 | |
920 | /* See language.h. */ | |
921 | void language_arch_info (struct gdbarch *gdbarch, | |
922 | struct language_arch_info *lai) const override | |
923 | { | |
924 | unknown_language_arch_info (gdbarch, lai); | |
925 | } | |
0874fd07 AB |
926 | }; |
927 | ||
928 | /* Single instance of the fake "auto" language. */ | |
929 | ||
930 | static auto_language auto_language_defn; | |
931 | ||
c906108c | 932 | \f |
f290d38e AC |
933 | /* Per-architecture language information. */ |
934 | ||
935 | static struct gdbarch_data *language_gdbarch_data; | |
936 | ||
937 | struct language_gdbarch | |
938 | { | |
939 | /* A vector of per-language per-architecture info. Indexed by "enum | |
940 | language". */ | |
941 | struct language_arch_info arch_info[nr_languages]; | |
942 | }; | |
943 | ||
944 | static void * | |
945 | language_gdbarch_post_init (struct gdbarch *gdbarch) | |
946 | { | |
947 | struct language_gdbarch *l; | |
f290d38e AC |
948 | |
949 | l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); | |
0874fd07 | 950 | for (const auto &lang : language_defn::languages) |
1fb314aa AB |
951 | { |
952 | gdb_assert (lang != nullptr); | |
953 | lang->language_arch_info (gdbarch, | |
954 | l->arch_info + lang->la_language); | |
955 | } | |
47e77640 | 956 | |
f290d38e AC |
957 | return l; |
958 | } | |
959 | ||
960 | struct type * | |
961 | language_string_char_type (const struct language_defn *la, | |
962 | struct gdbarch *gdbarch) | |
963 | { | |
9a3c8263 SM |
964 | struct language_gdbarch *ld |
965 | = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); | |
e0881a8e | 966 | |
aba2dd37 | 967 | return ld->arch_info[la->la_language].string_char_type; |
f290d38e AC |
968 | } |
969 | ||
fbb06eb1 UW |
970 | struct type * |
971 | language_bool_type (const struct language_defn *la, | |
972 | struct gdbarch *gdbarch) | |
973 | { | |
9a3c8263 SM |
974 | struct language_gdbarch *ld |
975 | = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); | |
fbb06eb1 UW |
976 | |
977 | if (ld->arch_info[la->la_language].bool_type_symbol) | |
978 | { | |
979 | struct symbol *sym; | |
e0881a8e | 980 | |
fbb06eb1 | 981 | sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, |
d12307c1 | 982 | NULL, VAR_DOMAIN, NULL).symbol; |
fbb06eb1 UW |
983 | if (sym) |
984 | { | |
985 | struct type *type = SYMBOL_TYPE (sym); | |
e0881a8e | 986 | |
78134374 | 987 | if (type && type->code () == TYPE_CODE_BOOL) |
fbb06eb1 UW |
988 | return type; |
989 | } | |
990 | } | |
991 | ||
992 | return ld->arch_info[la->la_language].bool_type_default; | |
993 | } | |
994 | ||
1994afbf DE |
995 | /* Helper function for primitive type lookup. */ |
996 | ||
997 | static struct type ** | |
998 | language_lookup_primitive_type_1 (const struct language_arch_info *lai, | |
999 | const char *name) | |
1000 | { | |
1001 | struct type **p; | |
1002 | ||
1003 | for (p = lai->primitive_type_vector; (*p) != NULL; p++) | |
1004 | { | |
7d93a1e0 | 1005 | if (strcmp ((*p)->name (), name) == 0) |
1994afbf DE |
1006 | return p; |
1007 | } | |
1008 | return NULL; | |
1009 | } | |
1010 | ||
1011 | /* See language.h. */ | |
1012 | ||
f290d38e | 1013 | struct type * |
46b0da17 DE |
1014 | language_lookup_primitive_type (const struct language_defn *la, |
1015 | struct gdbarch *gdbarch, | |
1016 | const char *name) | |
f290d38e | 1017 | { |
9a3c8263 SM |
1018 | struct language_gdbarch *ld = |
1019 | (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); | |
1994afbf DE |
1020 | struct type **typep; |
1021 | ||
1022 | typep = language_lookup_primitive_type_1 (&ld->arch_info[la->la_language], | |
1023 | name); | |
1024 | if (typep == NULL) | |
1025 | return NULL; | |
1026 | return *typep; | |
1027 | } | |
1028 | ||
1029 | /* Helper function for type lookup as a symbol. | |
1030 | Create the symbol corresponding to type TYPE in language LANG. */ | |
1031 | ||
1032 | static struct symbol * | |
1033 | language_alloc_type_symbol (enum language lang, struct type *type) | |
1034 | { | |
1035 | struct symbol *symbol; | |
1036 | struct gdbarch *gdbarch; | |
1037 | ||
1038 | gdb_assert (!TYPE_OBJFILE_OWNED (type)); | |
1039 | ||
1040 | gdbarch = TYPE_OWNER (type).gdbarch; | |
468c0cbb | 1041 | symbol = new (gdbarch_obstack (gdbarch)) struct symbol (); |
1994afbf | 1042 | |
7d93a1e0 | 1043 | symbol->m_name = type->name (); |
d3ecddab | 1044 | symbol->set_language (lang, nullptr); |
1994afbf DE |
1045 | symbol->owner.arch = gdbarch; |
1046 | SYMBOL_OBJFILE_OWNED (symbol) = 0; | |
8c14c3a3 | 1047 | SYMBOL_SECTION (symbol) = 0; |
1994afbf DE |
1048 | SYMBOL_TYPE (symbol) = type; |
1049 | SYMBOL_DOMAIN (symbol) = VAR_DOMAIN; | |
1050 | SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF; | |
1051 | ||
1052 | return symbol; | |
1053 | } | |
1054 | ||
1055 | /* Initialize the primitive type symbols of language LD. | |
1056 | The primitive type vector must have already been initialized. */ | |
1057 | ||
1058 | static void | |
1059 | language_init_primitive_type_symbols (struct language_arch_info *lai, | |
1060 | const struct language_defn *la, | |
1061 | struct gdbarch *gdbarch) | |
1062 | { | |
1063 | int n; | |
1994afbf DE |
1064 | |
1065 | gdb_assert (lai->primitive_type_vector != NULL); | |
1066 | ||
1067 | for (n = 0; lai->primitive_type_vector[n] != NULL; ++n) | |
1068 | continue; | |
1069 | ||
1070 | lai->primitive_type_symbols | |
1071 | = GDBARCH_OBSTACK_CALLOC (gdbarch, n + 1, struct symbol *); | |
1072 | ||
1073 | for (n = 0; lai->primitive_type_vector[n] != NULL; ++n) | |
1074 | { | |
1075 | lai->primitive_type_symbols[n] | |
1076 | = language_alloc_type_symbol (la->la_language, | |
1077 | lai->primitive_type_vector[n]); | |
1078 | } | |
1079 | ||
1080 | /* Note: The result of symbol lookup is normally a symbol *and* the block | |
d12307c1 PMR |
1081 | it was found in. Builtin types don't live in blocks. We *could* give |
1082 | them one, but there is no current need so to keep things simple symbol | |
1083 | lookup is extended to allow for BLOCK_FOUND to be NULL. */ | |
1994afbf DE |
1084 | } |
1085 | ||
1086 | /* See language.h. */ | |
1087 | ||
1088 | struct symbol * | |
1089 | language_lookup_primitive_type_as_symbol (const struct language_defn *la, | |
1090 | struct gdbarch *gdbarch, | |
1091 | const char *name) | |
1092 | { | |
9a3c8263 SM |
1093 | struct language_gdbarch *ld |
1094 | = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); | |
1994afbf DE |
1095 | struct language_arch_info *lai = &ld->arch_info[la->la_language]; |
1096 | struct type **typep; | |
1097 | struct symbol *sym; | |
e0881a8e | 1098 | |
cc485e62 DE |
1099 | if (symbol_lookup_debug) |
1100 | { | |
1101 | fprintf_unfiltered (gdb_stdlog, | |
1994afbf DE |
1102 | "language_lookup_primitive_type_as_symbol" |
1103 | " (%s, %s, %s)", | |
cc485e62 DE |
1104 | la->la_name, host_address_to_string (gdbarch), name); |
1105 | } | |
1106 | ||
1994afbf DE |
1107 | typep = language_lookup_primitive_type_1 (lai, name); |
1108 | if (typep == NULL) | |
f290d38e | 1109 | { |
1994afbf DE |
1110 | if (symbol_lookup_debug) |
1111 | fprintf_unfiltered (gdb_stdlog, " = NULL\n"); | |
1112 | return NULL; | |
f290d38e | 1113 | } |
cc485e62 | 1114 | |
1994afbf DE |
1115 | /* The set of symbols is lazily initialized. */ |
1116 | if (lai->primitive_type_symbols == NULL) | |
1117 | language_init_primitive_type_symbols (lai, la, gdbarch); | |
1118 | ||
1119 | sym = lai->primitive_type_symbols[typep - lai->primitive_type_vector]; | |
1120 | ||
cc485e62 | 1121 | if (symbol_lookup_debug) |
1994afbf DE |
1122 | fprintf_unfiltered (gdb_stdlog, " = %s\n", host_address_to_string (sym)); |
1123 | return sym; | |
f290d38e AC |
1124 | } |
1125 | ||
1777feb0 | 1126 | /* Initialize the language routines. */ |
c906108c | 1127 | |
6c265988 | 1128 | void _initialize_language (); |
c906108c | 1129 | void |
6c265988 | 1130 | _initialize_language () |
c906108c | 1131 | { |
40478521 | 1132 | static const char *const type_or_range_names[] |
b84aa90a PA |
1133 | = { "on", "off", "warn", "auto", NULL }; |
1134 | ||
40478521 | 1135 | static const char *const case_sensitive_names[] |
b84aa90a | 1136 | = { "on", "off", "auto", NULL }; |
c5aa993b | 1137 | |
f290d38e AC |
1138 | language_gdbarch_data |
1139 | = gdbarch_data_register_post_init (language_gdbarch_post_init); | |
1140 | ||
1777feb0 | 1141 | /* GDB commands for language specific stuff. */ |
c5aa993b | 1142 | |
0743fc83 TT |
1143 | add_basic_prefix_cmd ("check", no_class, |
1144 | _("Set the status of the type/range checker."), | |
1145 | &setchecklist, "set check ", 0, &setlist); | |
c5aa993b JM |
1146 | add_alias_cmd ("c", "check", no_class, 1, &setlist); |
1147 | add_alias_cmd ("ch", "check", no_class, 1, &setlist); | |
1148 | ||
0743fc83 TT |
1149 | add_show_prefix_cmd ("check", no_class, |
1150 | _("Show the status of the type/range checker."), | |
1151 | &showchecklist, "show check ", 0, &showlist); | |
c5aa993b JM |
1152 | add_alias_cmd ("c", "check", no_class, 1, &showlist); |
1153 | add_alias_cmd ("ch", "check", no_class, 1, &showlist); | |
1154 | ||
b84aa90a | 1155 | add_setshow_enum_cmd ("range", class_support, type_or_range_names, |
3e43a32a | 1156 | &range, |
590042fc PW |
1157 | _("Set range checking (on/warn/off/auto)."), |
1158 | _("Show range checking (on/warn/off/auto)."), | |
3e43a32a | 1159 | NULL, set_range_command, |
b84aa90a PA |
1160 | show_range_command, |
1161 | &setchecklist, &showchecklist); | |
1162 | ||
1163 | add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names, | |
1164 | &case_sensitive, _("\ | |
590042fc PW |
1165 | Set case sensitivity in name search (on/off/auto)."), _("\ |
1166 | Show case sensitivity in name search (on/off/auto)."), _("\ | |
4d28ad1e | 1167 | For Fortran the default is off; for other languages the default is on."), |
b84aa90a PA |
1168 | set_case_command, |
1169 | show_case_command, | |
1170 | &setlist, &showlist); | |
63872f9d | 1171 | |
0874fd07 AB |
1172 | /* In order to call SET_LANGUAGE (below) we need to make sure that |
1173 | CURRENT_LANGUAGE is not NULL. So first set the language to unknown, | |
1174 | then we can change the language to 'auto'. */ | |
1175 | current_language = language_def (language_unknown); | |
1176 | ||
47e77640 | 1177 | add_set_language_command (); |
c5aa993b | 1178 | |
4a811000 PW |
1179 | language = "auto"; |
1180 | range = "auto"; | |
1181 | case_sensitive = "auto"; | |
63872f9d | 1182 | |
1777feb0 | 1183 | /* Have the above take effect. */ |
63872f9d | 1184 | set_language (language_auto); |
c906108c | 1185 | } |