remove gdb_string.h
[deliverable/binutils-gdb.git] / gdb / language.c
1 /* Multiple source language support for GDB.
2
3 Copyright (C) 1991-2013 Free Software Foundation, Inc.
4
5 Contributed by the Department of Computer Science at the State University
6 of New York at Buffalo.
7
8 This file is part of GDB.
9
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
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
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.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23 /* This file contains functions that return things that are specific
24 to languages. Each function should examine current_language if necessary,
25 and return the appropriate result. */
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 <string.h>
34
35 #include "symtab.h"
36 #include "gdbtypes.h"
37 #include "value.h"
38 #include "gdbcmd.h"
39 #include "expression.h"
40 #include "language.h"
41 #include "varobj.h"
42 #include "target.h"
43 #include "parser-defs.h"
44 #include "jv-lang.h"
45 #include "demangle.h"
46 #include "symfile.h"
47 #include "cp-support.h"
48
49 extern void _initialize_language (void);
50
51 static void unk_lang_error (char *);
52
53 static int unk_lang_parser (void);
54
55 static void show_check (char *, int);
56
57 static void set_check (char *, int);
58
59 static void set_range_case (void);
60
61 static void unk_lang_emit_char (int c, struct type *type,
62 struct ui_file *stream, int quoter);
63
64 static void unk_lang_printchar (int c, struct type *type,
65 struct ui_file *stream);
66
67 static void unk_lang_value_print (struct value *, struct ui_file *,
68 const struct value_print_options *);
69
70 static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
71
72 /* Forward declaration */
73 extern const struct language_defn unknown_language_defn;
74
75 /* The current (default at startup) state of type and range checking.
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. */
79
80 enum range_mode range_mode = range_mode_auto;
81 enum range_check range_check = range_check_off;
82 enum case_mode case_mode = case_mode_auto;
83 enum case_sensitivity case_sensitivity = case_sensitive_on;
84
85 /* The current language and language_mode (see language.h). */
86
87 const struct language_defn *current_language = &unknown_language_defn;
88 enum 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
93 const struct language_defn *expected_language;
94
95 /* The list of supported languages. The list itself is malloc'd. */
96
97 static const struct language_defn **languages;
98 static unsigned languages_size;
99 static unsigned languages_allocsize;
100 #define DEFAULT_ALLOCSIZE 4
101
102 /* The current values of the "set language/type/range" enum
103 commands. */
104 static const char *language;
105 static const char *type;
106 static const char *range;
107 static const char *case_sensitive;
108
109 /* Warning issued when current_language and the language of the current
110 frame do not match. */
111 char lang_frame_mismatch_warn[] =
112 "Warning: the current language does not match this frame.";
113 \f
114 /* This page contains the functions corresponding to GDB commands
115 and their helpers. */
116
117 /* Show command. Display a warning if the language set
118 does not match the frame. */
119 static void
120 show_language_command (struct ui_file *file, int from_tty,
121 struct cmd_list_element *c, const char *value)
122 {
123 enum language flang; /* The language of the current frame. */
124
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
131 fprintf_filtered (gdb_stdout,
132 _("The current source language is \"%s\".\n"),
133 current_language->la_name);
134
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);
140 }
141
142 /* Set command. Change the current working language. */
143 static void
144 set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
145 {
146 int i;
147 enum language flang;
148
149 /* Search the list of languages for a match. */
150 for (i = 0; i < languages_size; i++)
151 {
152 if (strcmp (languages[i]->la_name, language) == 0)
153 {
154 /* Found it! Go into manual mode, and use this language. */
155 if (languages[i]->la_language == language_auto)
156 {
157 /* Enter auto mode. Set to the current frame's language, if
158 known, or fallback to the initial language. */
159 language_mode = language_mode_auto;
160 flang = get_frame_language ();
161 if (flang != language_unknown)
162 set_language (flang);
163 else
164 set_initial_language ();
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];
173 set_range_case ();
174 expected_language = current_language;
175 return;
176 }
177 }
178 }
179
180 internal_error (__FILE__, __LINE__,
181 "Couldn't find language `%s' in known languages list.",
182 language);
183 }
184
185 /* Show command. Display a warning if the range setting does
186 not match the current language. */
187 static void
188 show_range_command (struct ui_file *file, int from_tty,
189 struct cmd_list_element *c, const char *value)
190 {
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
219 if (range_check != current_language->la_range_check)
220 warning (_("the current range check setting "
221 "does not match the language.\n"));
222 }
223
224 /* Set command. Change the setting for range checking. */
225 static void
226 set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
227 {
228 if (strcmp (range, "on") == 0)
229 {
230 range_check = range_check_on;
231 range_mode = range_mode_manual;
232 }
233 else if (strcmp (range, "warn") == 0)
234 {
235 range_check = range_check_warn;
236 range_mode = range_mode_manual;
237 }
238 else if (strcmp (range, "off") == 0)
239 {
240 range_check = range_check_off;
241 range_mode = range_mode_manual;
242 }
243 else if (strcmp (range, "auto") == 0)
244 {
245 range_mode = range_mode_auto;
246 set_range_case ();
247 return;
248 }
249 else
250 {
251 internal_error (__FILE__, __LINE__,
252 _("Unrecognized range check setting: \"%s\""), range);
253 }
254 if (range_check != current_language->la_range_check)
255 warning (_("the current range check setting "
256 "does not match the language.\n"));
257 }
258
259 /* Show command. Display a warning if the case sensitivity setting does
260 not match the current language. */
261 static void
262 show_case_command (struct ui_file *file, int from_tty,
263 struct cmd_list_element *c, const char *value)
264 {
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
288 fprintf_filtered (gdb_stdout,
289 _("Case sensitivity in name search is \"%s\".\n"),
290 value);
291
292 if (case_sensitivity != current_language->la_case_sensitivity)
293 warning (_("the current case sensitivity setting does not match "
294 "the language.\n"));
295 }
296
297 /* Set command. Change the setting for case sensitivity. */
298
299 static void
300 set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
301 {
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;
315 set_range_case ();
316 return;
317 }
318 else
319 {
320 internal_error (__FILE__, __LINE__,
321 "Unrecognized case-sensitive setting: \"%s\"",
322 case_sensitive);
323 }
324
325 if (case_sensitivity != current_language->la_case_sensitivity)
326 warning (_("the current case sensitivity setting does not match "
327 "the language.\n"));
328 }
329
330 /* Set the status of range and type checking and case sensitivity based on
331 the current modes and the current language.
332 If SHOW is non-zero, then print out the current language,
333 type and range checking status. */
334 static void
335 set_range_case (void)
336 {
337 if (range_mode == range_mode_auto)
338 range_check = current_language->la_range_check;
339
340 if (case_mode == case_mode_auto)
341 case_sensitivity = current_language->la_case_sensitivity;
342 }
343
344 /* Set current language to (enum language) LANG. Returns previous
345 language. */
346
347 enum language
348 set_language (enum language lang)
349 {
350 int i;
351 enum language prev_language;
352
353 prev_language = current_language->la_language;
354
355 for (i = 0; i < languages_size; i++)
356 {
357 if (languages[i]->la_language == lang)
358 {
359 current_language = languages[i];
360 set_range_case ();
361 break;
362 }
363 }
364
365 return prev_language;
366 }
367 \f
368
369 /* Print out the current language settings: language, range and
370 type checking. If QUIETLY, print only what has changed. */
371
372 void
373 language_info (int quietly)
374 {
375 if (quietly && expected_language == current_language)
376 return;
377
378 expected_language = current_language;
379 printf_unfiltered (_("Current language: %s\n"), language);
380 show_language_command (NULL, 1, NULL, NULL);
381
382 if (!quietly)
383 {
384 printf_unfiltered (_("Range checking: %s\n"), range);
385 show_range_command (NULL, 1, NULL, NULL);
386 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
387 show_case_command (NULL, 1, NULL, NULL);
388 }
389 }
390 \f
391
392 /* Returns non-zero if the value is a pointer type. */
393 int
394 pointer_type (struct type *type)
395 {
396 return TYPE_CODE (type) == TYPE_CODE_PTR ||
397 TYPE_CODE (type) == TYPE_CODE_REF;
398 }
399
400 \f
401 /* This page contains functions that return info about
402 (struct value) values used in GDB. */
403
404 /* Returns non-zero if the value VAL represents a true value. */
405 int
406 value_true (struct value *val)
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
417 /* This page contains functions for the printing out of
418 error messages that occur during type- and range-
419 checking. */
420
421 /* This is called when a language fails a range-check. The
422 first argument should be a printf()-style format string, and the
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. */
426
427 void
428 range_error (const char *string,...)
429 {
430 va_list args;
431
432 va_start (args, string);
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:
448 internal_error (__FILE__, __LINE__, _("bad switch"));
449 }
450 va_end (args);
451 }
452 \f
453
454 /* This page contains miscellaneous functions. */
455
456 /* Return the language enum for a given language string. */
457
458 enum language
459 language_enum (char *str)
460 {
461 int i;
462
463 for (i = 0; i < languages_size; i++)
464 if (strcmp (languages[i]->la_name, str) == 0)
465 return languages[i]->la_language;
466
467 return language_unknown;
468 }
469
470 /* Return the language struct for a given language enum. */
471
472 const struct language_defn *
473 language_def (enum language lang)
474 {
475 int i;
476
477 for (i = 0; i < languages_size; i++)
478 {
479 if (languages[i]->la_language == lang)
480 {
481 return languages[i];
482 }
483 }
484 return NULL;
485 }
486
487 /* Return the language as a string. */
488 const char *
489 language_str (enum language lang)
490 {
491 int i;
492
493 for (i = 0; i < languages_size; i++)
494 {
495 if (languages[i]->la_language == lang)
496 {
497 return languages[i]->la_name;
498 }
499 }
500 return "Unknown";
501 }
502
503 static void
504 set_check (char *ignore, int from_tty)
505 {
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);
509 }
510
511 static void
512 show_check (char *ignore, int from_tty)
513 {
514 cmd_show_list (showchecklist, from_tty, "");
515 }
516 \f
517 /* Add a language to the set of known languages. */
518
519 void
520 add_language (const struct language_defn *lang)
521 {
522 /* For the "set language" command. */
523 static const char **language_names = NULL;
524 /* For the "help set language" command. */
525 char *language_set_doc = NULL;
526
527 int i;
528 struct ui_file *tmp_stream;
529
530 if (lang->la_magic != LANG_MAGIC)
531 {
532 fprintf_unfiltered (gdb_stderr,
533 "Magic number of %s language struct wrong\n",
534 lang->la_name);
535 internal_error (__FILE__, __LINE__,
536 _("failed internal consistency check"));
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,
549 languages_allocsize * sizeof (*languages));
550 }
551 languages[languages_size++] = lang;
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
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"));
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
586 language_set_doc = ui_file_xstrdup (tmp_stream, NULL);
587 ui_file_delete (tmp_stream);
588
589 add_setshow_enum_cmd ("language", class_support,
590 (const char **) language_names,
591 &language,
592 language_set_doc,
593 _("Show the current source language."),
594 NULL, set_language_command,
595 show_language_command,
596 &setlist, &showlist);
597
598 xfree (language_set_doc);
599 }
600
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'. */
605 CORE_ADDR
606 skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
607 {
608 int i;
609
610 for (i = 0; i < languages_size; i++)
611 {
612 if (languages[i]->skip_trampoline)
613 {
614 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
615
616 if (real_pc)
617 return real_pc;
618 }
619 }
620
621 return 0;
622 }
623
624 /* Return demangled language symbol, or NULL.
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
627 more flexible demangler for the languages that need it.
628 FIXME: Sometimes the demangler is invoked when we don't know the
629 language, so we can't use this everywhere. */
630 char *
631 language_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
639 /* Return class name from physname or NULL. */
640 char *
641 language_class_name_from_physname (const struct language_defn *lang,
642 const char *physname)
643 {
644 if (lang != NULL && lang->la_class_name_from_physname)
645 return lang->la_class_name_from_physname (physname);
646 return NULL;
647 }
648
649 /* Return non-zero if TYPE should be passed (and returned) by
650 reference at the language level. */
651 int
652 language_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. */
660 int
661 default_pass_by_reference (struct type *type)
662 {
663 return 0;
664 }
665
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
670 char *
671 default_word_break_characters (void)
672 {
673 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
674 }
675
676 /* Print the index of array elements using the C99 syntax. */
677
678 void
679 default_print_array_index (struct value *index_value, struct ui_file *stream,
680 const struct value_print_options *options)
681 {
682 fprintf_filtered (stream, "[");
683 LA_VALUE_PRINT (index_value, stream, options);
684 fprintf_filtered (stream, "] = ");
685 }
686
687 void
688 default_get_string (struct value *value, gdb_byte **buffer, int *length,
689 struct type **char_type, const char **charset)
690 {
691 error (_("Getting a string is unsupported in this language."));
692 }
693
694 /* Define the language that is no language. */
695
696 static int
697 unk_lang_parser (void)
698 {
699 return 1;
700 }
701
702 static void
703 unk_lang_error (char *msg)
704 {
705 error (_("Attempted to parse an expression with unknown language"));
706 }
707
708 static void
709 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
710 int quoter)
711 {
712 error (_("internal error - unimplemented "
713 "function unk_lang_emit_char called."));
714 }
715
716 static void
717 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
718 {
719 error (_("internal error - unimplemented "
720 "function unk_lang_printchar called."));
721 }
722
723 static void
724 unk_lang_printstr (struct ui_file *stream, struct type *type,
725 const gdb_byte *string, unsigned int length,
726 const char *encoding, int force_ellipses,
727 const struct value_print_options *options)
728 {
729 error (_("internal error - unimplemented "
730 "function unk_lang_printstr called."));
731 }
732
733 static void
734 unk_lang_print_type (struct type *type, const char *varstring,
735 struct ui_file *stream, int show, int level,
736 const struct type_print_options *flags)
737 {
738 error (_("internal error - unimplemented "
739 "function unk_lang_print_type called."));
740 }
741
742 static void
743 unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
744 int embedded_offset, CORE_ADDR address,
745 struct ui_file *stream, int recurse,
746 const struct value *val,
747 const struct value_print_options *options)
748 {
749 error (_("internal error - unimplemented "
750 "function unk_lang_val_print called."));
751 }
752
753 static void
754 unk_lang_value_print (struct value *val, struct ui_file *stream,
755 const struct value_print_options *options)
756 {
757 error (_("internal error - unimplemented "
758 "function unk_lang_value_print called."));
759 }
760
761 static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
762 {
763 return 0;
764 }
765
766 /* Unknown languages just use the cplus demangler. */
767 static char *unk_lang_demangle (const char *mangled, int options)
768 {
769 return gdb_demangle (mangled, options);
770 }
771
772 static char *unk_lang_class_name (const char *mangled)
773 {
774 return NULL;
775 }
776
777 static const struct op_print unk_op_print_tab[] =
778 {
779 {NULL, OP_NULL, PREC_NULL, 0}
780 };
781
782 static void
783 unknown_language_arch_info (struct gdbarch *gdbarch,
784 struct language_arch_info *lai)
785 {
786 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
787 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
788 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
789 struct type *);
790 }
791
792 const struct language_defn unknown_language_defn =
793 {
794 "unknown",
795 "Unknown",
796 language_unknown,
797 range_check_off,
798 case_sensitive_on,
799 array_row_major,
800 macro_expansion_no,
801 &exp_descriptor_standard,
802 unk_lang_parser,
803 unk_lang_error,
804 null_post_parser,
805 unk_lang_printchar, /* Print character constant */
806 unk_lang_printstr,
807 unk_lang_emit_char,
808 unk_lang_print_type, /* Print a type using appropriate syntax */
809 default_print_typedef, /* Print a typedef using appropriate syntax */
810 unk_lang_val_print, /* Print a value using appropriate syntax */
811 unk_lang_value_print, /* Print a top-level value */
812 default_read_var_value, /* la_read_var_value */
813 unk_lang_trampoline, /* Language specific skip_trampoline */
814 "this", /* name_of_this */
815 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
816 basic_lookup_transparent_type,/* lookup_transparent_type */
817 unk_lang_demangle, /* Language specific symbol demangler */
818 unk_lang_class_name, /* Language specific
819 class_name_from_physname */
820 unk_op_print_tab, /* expression operators for printing */
821 1, /* c-style arrays */
822 0, /* String lower bound */
823 default_word_break_characters,
824 default_make_symbol_completion_list,
825 unknown_language_arch_info, /* la_language_arch_info. */
826 default_print_array_index,
827 default_pass_by_reference,
828 default_get_string,
829 NULL, /* la_get_symbol_name_cmp */
830 iterate_over_symbols,
831 &default_varobj_ops,
832 LANG_MAGIC
833 };
834
835 /* These two structs define fake entries for the "local" and "auto"
836 options. */
837 const struct language_defn auto_language_defn =
838 {
839 "auto",
840 "Auto",
841 language_auto,
842 range_check_off,
843 case_sensitive_on,
844 array_row_major,
845 macro_expansion_no,
846 &exp_descriptor_standard,
847 unk_lang_parser,
848 unk_lang_error,
849 null_post_parser,
850 unk_lang_printchar, /* Print character constant */
851 unk_lang_printstr,
852 unk_lang_emit_char,
853 unk_lang_print_type, /* Print a type using appropriate syntax */
854 default_print_typedef, /* Print a typedef using appropriate syntax */
855 unk_lang_val_print, /* Print a value using appropriate syntax */
856 unk_lang_value_print, /* Print a top-level value */
857 default_read_var_value, /* la_read_var_value */
858 unk_lang_trampoline, /* Language specific skip_trampoline */
859 "this", /* name_of_this */
860 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
861 basic_lookup_transparent_type,/* lookup_transparent_type */
862 unk_lang_demangle, /* Language specific symbol demangler */
863 unk_lang_class_name, /* Language specific
864 class_name_from_physname */
865 unk_op_print_tab, /* expression operators for printing */
866 1, /* c-style arrays */
867 0, /* String lower bound */
868 default_word_break_characters,
869 default_make_symbol_completion_list,
870 unknown_language_arch_info, /* la_language_arch_info. */
871 default_print_array_index,
872 default_pass_by_reference,
873 default_get_string,
874 NULL, /* la_get_symbol_name_cmp */
875 iterate_over_symbols,
876 &default_varobj_ops,
877 LANG_MAGIC
878 };
879
880 const struct language_defn local_language_defn =
881 {
882 "local",
883 "Local",
884 language_auto,
885 range_check_off,
886 case_sensitive_on,
887 array_row_major,
888 macro_expansion_no,
889 &exp_descriptor_standard,
890 unk_lang_parser,
891 unk_lang_error,
892 null_post_parser,
893 unk_lang_printchar, /* Print character constant */
894 unk_lang_printstr,
895 unk_lang_emit_char,
896 unk_lang_print_type, /* Print a type using appropriate syntax */
897 default_print_typedef, /* Print a typedef using appropriate syntax */
898 unk_lang_val_print, /* Print a value using appropriate syntax */
899 unk_lang_value_print, /* Print a top-level value */
900 default_read_var_value, /* la_read_var_value */
901 unk_lang_trampoline, /* Language specific skip_trampoline */
902 "this", /* name_of_this */
903 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
904 basic_lookup_transparent_type,/* lookup_transparent_type */
905 unk_lang_demangle, /* Language specific symbol demangler */
906 unk_lang_class_name, /* Language specific
907 class_name_from_physname */
908 unk_op_print_tab, /* expression operators for printing */
909 1, /* c-style arrays */
910 0, /* String lower bound */
911 default_word_break_characters,
912 default_make_symbol_completion_list,
913 unknown_language_arch_info, /* la_language_arch_info. */
914 default_print_array_index,
915 default_pass_by_reference,
916 default_get_string,
917 NULL, /* la_get_symbol_name_cmp */
918 iterate_over_symbols,
919 &default_varobj_ops,
920 LANG_MAGIC
921 };
922 \f
923 /* Per-architecture language information. */
924
925 static struct gdbarch_data *language_gdbarch_data;
926
927 struct 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
934 static void *
935 language_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);
941 for (i = 0; i < languages_size; i++)
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
951 struct type *
952 language_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);
957
958 return ld->arch_info[la->la_language].string_char_type;
959 }
960
961 struct type *
962 language_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;
971
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);
977
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
986 struct type *
987 language_lookup_primitive_type_by_name (const struct language_defn *la,
988 struct gdbarch *gdbarch,
989 const char *name)
990 {
991 struct language_gdbarch *ld = gdbarch_data (gdbarch,
992 language_gdbarch_data);
993 struct type *const *p;
994
995 for (p = ld->arch_info[la->la_language].primitive_type_vector;
996 (*p) != NULL;
997 p++)
998 {
999 if (strcmp (TYPE_NAME (*p), name) == 0)
1000 return (*p);
1001 }
1002 return (NULL);
1003 }
1004
1005 /* Initialize the language routines. */
1006
1007 void
1008 _initialize_language (void)
1009 {
1010 static const char *const type_or_range_names[]
1011 = { "on", "off", "warn", "auto", NULL };
1012
1013 static const char *const case_sensitive_names[]
1014 = { "on", "off", "auto", NULL };
1015
1016 language_gdbarch_data
1017 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1018
1019 /* GDB commands for language specific stuff. */
1020
1021 add_prefix_cmd ("check", no_class, set_check,
1022 _("Set the status of the type/range checker."),
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,
1028 _("Show the status of the type/range checker."),
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
1033 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
1034 &range,
1035 _("Set range checking. (on/warn/off/auto)"),
1036 _("Show range checking. (on/warn/off/auto)"),
1037 NULL, set_range_command,
1038 show_range_command,
1039 &setchecklist, &showchecklist);
1040
1041 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1042 &case_sensitive, _("\
1043 Set case sensitivity in name search. (on/off/auto)"), _("\
1044 Show case sensitivity in name search. (on/off/auto)"), _("\
1045 For Fortran the default is off; for other languages the default is on."),
1046 set_case_command,
1047 show_case_command,
1048 &setlist, &showlist);
1049
1050 add_language (&auto_language_defn);
1051 add_language (&local_language_defn);
1052 add_language (&unknown_language_defn);
1053
1054 language = xstrdup ("auto");
1055 type = xstrdup ("auto");
1056 range = xstrdup ("auto");
1057 case_sensitive = xstrdup ("auto");
1058
1059 /* Have the above take effect. */
1060 set_language (language_auto);
1061 }
This page took 0.144789 seconds and 5 git commands to generate.