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