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