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