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