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