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