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