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