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