* dwarf2read.c (read_str_index): Delete arg cu. All callers updated.
[deliverable/binutils-gdb.git] / gdb / language.c
CommitLineData
c906108c 1/* Multiple source language support for GDB.
1bac305b 2
ecd75fc8 3 Copyright (C) 1991-2014 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>
0e9f083f 33#include <string.h>
c906108c
SS
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. */
27cd387b 488const char *
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 522 /* For the "set language" command. */
27cd387b 523 static const char **language_names = NULL;
b84aa90a 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 794 "unknown",
6abde28f 795 "Unknown",
c906108c 796 language_unknown,
c906108c 797 range_check_off,
63872f9d 798 case_sensitive_on,
9a044a89
TT
799 array_row_major,
800 macro_expansion_no,
5f9769d1 801 &exp_descriptor_standard,
c906108c
SS
802 unk_lang_parser,
803 unk_lang_error,
e85c3284 804 null_post_parser,
c906108c
SS
805 unk_lang_printchar, /* Print character constant */
806 unk_lang_printstr,
807 unk_lang_emit_char,
c906108c 808 unk_lang_print_type, /* Print a type using appropriate syntax */
5c6ce71d 809 default_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
810 unk_lang_val_print, /* Print a value using appropriate syntax */
811 unk_lang_value_print, /* Print a top-level value */
a5ee536b 812 default_read_var_value, /* la_read_var_value */
f636b87d 813 unk_lang_trampoline, /* Language specific skip_trampoline */
2b2d9e11 814 "this", /* name_of_this */
5f9a71c3 815 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 816 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 817 unk_lang_demangle, /* Language specific symbol demangler */
3e43a32a
MS
818 unk_lang_class_name, /* Language specific
819 class_name_from_physname */
c906108c
SS
820 unk_op_print_tab, /* expression operators for printing */
821 1, /* c-style arrays */
822 0, /* String lower bound */
6084f43a 823 default_word_break_characters,
41d27058 824 default_make_symbol_completion_list,
f290d38e 825 unknown_language_arch_info, /* la_language_arch_info. */
e79af960 826 default_print_array_index,
41f1b697 827 default_pass_by_reference,
ae6a3a4c 828 default_get_string,
1a119f36 829 NULL, /* la_get_symbol_name_cmp */
f8eba3c6 830 iterate_over_symbols,
a53b64ea 831 &default_varobj_ops,
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,
c906108c
SS
877 LANG_MAGIC
878};
879
c5aa993b
JM
880const struct language_defn local_language_defn =
881{
c906108c 882 "local",
6abde28f 883 "Local",
c906108c 884 language_auto,
c906108c 885 range_check_off,
63872f9d 886 case_sensitive_on,
7ca2d3a3 887 array_row_major,
9a044a89 888 macro_expansion_no,
5f9769d1 889 &exp_descriptor_standard,
c906108c
SS
890 unk_lang_parser,
891 unk_lang_error,
e85c3284 892 null_post_parser,
c906108c
SS
893 unk_lang_printchar, /* Print character constant */
894 unk_lang_printstr,
895 unk_lang_emit_char,
c906108c 896 unk_lang_print_type, /* Print a type using appropriate syntax */
5c6ce71d 897 default_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
898 unk_lang_val_print, /* Print a value using appropriate syntax */
899 unk_lang_value_print, /* Print a top-level value */
a5ee536b 900 default_read_var_value, /* la_read_var_value */
f636b87d 901 unk_lang_trampoline, /* Language specific skip_trampoline */
2b2d9e11 902 "this", /* name_of_this */
5f9a71c3 903 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 904 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 905 unk_lang_demangle, /* Language specific symbol demangler */
3e43a32a
MS
906 unk_lang_class_name, /* Language specific
907 class_name_from_physname */
c906108c
SS
908 unk_op_print_tab, /* expression operators for printing */
909 1, /* c-style arrays */
910 0, /* String lower bound */
6084f43a 911 default_word_break_characters,
41d27058 912 default_make_symbol_completion_list,
f290d38e 913 unknown_language_arch_info, /* la_language_arch_info. */
e79af960 914 default_print_array_index,
41f1b697 915 default_pass_by_reference,
ae6a3a4c 916 default_get_string,
1a119f36 917 NULL, /* la_get_symbol_name_cmp */
f8eba3c6 918 iterate_over_symbols,
a53b64ea 919 &default_varobj_ops,
c906108c
SS
920 LANG_MAGIC
921};
922\f
f290d38e
AC
923/* Per-architecture language information. */
924
925static struct gdbarch_data *language_gdbarch_data;
926
927struct language_gdbarch
928{
929 /* A vector of per-language per-architecture info. Indexed by "enum
930 language". */
931 struct language_arch_info arch_info[nr_languages];
932};
933
934static void *
935language_gdbarch_post_init (struct gdbarch *gdbarch)
936{
937 struct language_gdbarch *l;
938 int i;
939
940 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
1285b746 941 for (i = 0; i < languages_size; i++)
f290d38e
AC
942 {
943 if (languages[i] != NULL
944 && languages[i]->la_language_arch_info != NULL)
945 languages[i]->la_language_arch_info
946 (gdbarch, l->arch_info + languages[i]->la_language);
947 }
948 return l;
949}
950
951struct type *
952language_string_char_type (const struct language_defn *la,
953 struct gdbarch *gdbarch)
954{
955 struct language_gdbarch *ld = gdbarch_data (gdbarch,
956 language_gdbarch_data);
e0881a8e 957
aba2dd37 958 return ld->arch_info[la->la_language].string_char_type;
f290d38e
AC
959}
960
fbb06eb1
UW
961struct type *
962language_bool_type (const struct language_defn *la,
963 struct gdbarch *gdbarch)
964{
965 struct language_gdbarch *ld = gdbarch_data (gdbarch,
966 language_gdbarch_data);
967
968 if (ld->arch_info[la->la_language].bool_type_symbol)
969 {
970 struct symbol *sym;
e0881a8e 971
fbb06eb1
UW
972 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
973 NULL, VAR_DOMAIN, NULL);
974 if (sym)
975 {
976 struct type *type = SYMBOL_TYPE (sym);
e0881a8e 977
fbb06eb1
UW
978 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
979 return type;
980 }
981 }
982
983 return ld->arch_info[la->la_language].bool_type_default;
984}
985
f290d38e 986struct type *
5a44ea29 987language_lookup_primitive_type_by_name (const struct language_defn *la,
f290d38e
AC
988 struct gdbarch *gdbarch,
989 const char *name)
990{
991 struct language_gdbarch *ld = gdbarch_data (gdbarch,
992 language_gdbarch_data);
aba2dd37 993 struct type *const *p;
e0881a8e 994
aba2dd37
UW
995 for (p = ld->arch_info[la->la_language].primitive_type_vector;
996 (*p) != NULL;
997 p++)
f290d38e 998 {
aba2dd37
UW
999 if (strcmp (TYPE_NAME (*p), name) == 0)
1000 return (*p);
f290d38e
AC
1001 }
1002 return (NULL);
1003}
1004
1777feb0 1005/* Initialize the language routines. */
c906108c
SS
1006
1007void
fba45db2 1008_initialize_language (void)
c906108c 1009{
40478521 1010 static const char *const type_or_range_names[]
b84aa90a
PA
1011 = { "on", "off", "warn", "auto", NULL };
1012
40478521 1013 static const char *const case_sensitive_names[]
b84aa90a 1014 = { "on", "off", "auto", NULL };
c5aa993b 1015
f290d38e
AC
1016 language_gdbarch_data
1017 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1018
1777feb0 1019 /* GDB commands for language specific stuff. */
c5aa993b 1020
c5aa993b 1021 add_prefix_cmd ("check", no_class, set_check,
1bedd215 1022 _("Set the status of the type/range checker."),
c5aa993b
JM
1023 &setchecklist, "set check ", 0, &setlist);
1024 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1025 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1026
1027 add_prefix_cmd ("check", no_class, show_check,
1bedd215 1028 _("Show the status of the type/range checker."),
c5aa993b
JM
1029 &showchecklist, "show check ", 0, &showlist);
1030 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1031 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1032
b84aa90a 1033 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
3e43a32a
MS
1034 &range,
1035 _("Set range checking. (on/warn/off/auto)"),
1036 _("Show range checking. (on/warn/off/auto)"),
1037 NULL, set_range_command,
b84aa90a
PA
1038 show_range_command,
1039 &setchecklist, &showchecklist);
1040
1041 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1042 &case_sensitive, _("\
4d28ad1e
AC
1043Set case sensitivity in name search. (on/off/auto)"), _("\
1044Show case sensitivity in name search. (on/off/auto)"), _("\
1045For Fortran the default is off; for other languages the default is on."),
b84aa90a
PA
1046 set_case_command,
1047 show_case_command,
1048 &setlist, &showlist);
63872f9d 1049
c5aa993b 1050 add_language (&auto_language_defn);
b84aa90a
PA
1051 add_language (&local_language_defn);
1052 add_language (&unknown_language_defn);
c5aa993b 1053
1b36a34b
JK
1054 language = xstrdup ("auto");
1055 type = xstrdup ("auto");
1056 range = xstrdup ("auto");
1057 case_sensitive = xstrdup ("auto");
63872f9d 1058
1777feb0 1059 /* Have the above take effect. */
63872f9d 1060 set_language (language_auto);
c906108c 1061}
This page took 1.901575 seconds and 4 git commands to generate.