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