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