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