gdb/d-lang.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* D language support routines for GDB, the GNU debugger.

  2.    Copyright (C) 2005-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "symtab.h"
  16. #include "language.h"
  17. #include "varobj.h"
  18. #include "d-lang.h"
  19. #include "c-lang.h"
  20. #include "demangle.h"
  21. #include "cp-support.h"

  22. /* The name of the symbol to use to get the name of the main subprogram.  */
  23. static const char D_MAIN[] = "D main";

  24. /* Function returning the special symbol name used by D for the main
  25.    procedure in the main program if it is found in minimal symbol list.
  26.    This function tries to find minimal symbols so that it finds them even
  27.    if the program was compiled without debugging information.  */

  28. const char *
  29. d_main_name (void)
  30. {
  31.   struct bound_minimal_symbol msym;

  32.   msym = lookup_minimal_symbol (D_MAIN, NULL, NULL);
  33.   if (msym.minsym != NULL)
  34.     return D_MAIN;

  35.   /* No known entry procedure found, the main program is probably not D.  */
  36.   return NULL;
  37. }

  38. /* Implements the la_demangle language_defn routine for language D.  */

  39. char *
  40. d_demangle (const char *symbol, int options)
  41. {
  42.   return gdb_demangle (symbol, options | DMGL_DLANG);
  43. }

  44. /* Table mapping opcodes into strings for printing operators
  45.    and precedences of the operators.  */
  46. static const struct op_print d_op_print_tab[] =
  47. {
  48.   {",", BINOP_COMMA, PREC_COMMA, 0},
  49.   {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
  50.   {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
  51.   {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
  52.   {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
  53.   {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
  54.   {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
  55.   {"==", BINOP_EQUAL, PREC_ORDER, 0},
  56.   {"!=", BINOP_NOTEQUAL, PREC_ORDER, 0},
  57.   {"<=", BINOP_LEQ, PREC_ORDER, 0},
  58.   {">=", BINOP_GEQ, PREC_ORDER, 0},
  59.   {">", BINOP_GTR, PREC_ORDER, 0},
  60.   {"<", BINOP_LESS, PREC_ORDER, 0},
  61.   {">>", BINOP_RSH, PREC_SHIFT, 0},
  62.   {"<<", BINOP_LSH, PREC_SHIFT, 0},
  63.   {"+", BINOP_ADD, PREC_ADD, 0},
  64.   {"-", BINOP_SUB, PREC_ADD, 0},
  65.   {"~", BINOP_CONCAT, PREC_ADD, 0},
  66.   {"*", BINOP_MUL, PREC_MUL, 0},
  67.   {"/", BINOP_DIV, PREC_MUL, 0},
  68.   {"%", BINOP_REM, PREC_MUL, 0},
  69.   {"^^", BINOP_EXP, PREC_REPEAT, 0},
  70.   {"@", BINOP_REPEAT, PREC_REPEAT, 0},
  71.   {"-", UNOP_NEG, PREC_PREFIX, 0},
  72.   {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
  73.   {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
  74.   {"*", UNOP_IND, PREC_PREFIX, 0},
  75.   {"&", UNOP_ADDR, PREC_PREFIX, 0},
  76.   {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
  77.   {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
  78.   {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
  79.   {NULL, 0, 0, 0}
  80. };

  81. /* Mapping of all D basic data types into the language vector.  */

  82. enum d_primitive_types {
  83.   d_primitive_type_void,
  84.   d_primitive_type_bool,
  85.   d_primitive_type_byte,
  86.   d_primitive_type_ubyte,
  87.   d_primitive_type_short,
  88.   d_primitive_type_ushort,
  89.   d_primitive_type_int,
  90.   d_primitive_type_uint,
  91.   d_primitive_type_long,
  92.   d_primitive_type_ulong,
  93.   d_primitive_type_cent,    /* Signed 128 bit integer.  */
  94.   d_primitive_type_ucent,   /* Unsigned 128 bit integer.  */
  95.   d_primitive_type_float,
  96.   d_primitive_type_double,
  97.   d_primitive_type_real,
  98.   d_primitive_type_ifloat,  /* Imaginary float types.  */
  99.   d_primitive_type_idouble,
  100.   d_primitive_type_ireal,
  101.   d_primitive_type_cfloat,  /* Complex number of two float values.  */
  102.   d_primitive_type_cdouble,
  103.   d_primitive_type_creal,
  104.   d_primitive_type_char,    /* Unsigned character types.  */
  105.   d_primitive_type_wchar,
  106.   d_primitive_type_dchar,
  107.   nr_d_primitive_types
  108. };

  109. /* Implements the la_language_arch_info language_defn routine
  110.    for language D.  */

  111. static void
  112. d_language_arch_info (struct gdbarch *gdbarch,
  113.                       struct language_arch_info *lai)
  114. {
  115.   const struct builtin_d_type *builtin = builtin_d_type (gdbarch);

  116.   lai->string_char_type = builtin->builtin_char;
  117.   lai->primitive_type_vector
  118.     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1,
  119.                               struct type *);

  120.   lai->primitive_type_vector [d_primitive_type_void]
  121.     = builtin->builtin_void;
  122.   lai->primitive_type_vector [d_primitive_type_bool]
  123.     = builtin->builtin_bool;
  124.   lai->primitive_type_vector [d_primitive_type_byte]
  125.     = builtin->builtin_byte;
  126.   lai->primitive_type_vector [d_primitive_type_ubyte]
  127.     = builtin->builtin_ubyte;
  128.   lai->primitive_type_vector [d_primitive_type_short]
  129.     = builtin->builtin_short;
  130.   lai->primitive_type_vector [d_primitive_type_ushort]
  131.     = builtin->builtin_ushort;
  132.   lai->primitive_type_vector [d_primitive_type_int]
  133.     = builtin->builtin_int;
  134.   lai->primitive_type_vector [d_primitive_type_uint]
  135.     = builtin->builtin_uint;
  136.   lai->primitive_type_vector [d_primitive_type_long]
  137.     = builtin->builtin_long;
  138.   lai->primitive_type_vector [d_primitive_type_ulong]
  139.     = builtin->builtin_ulong;
  140.   lai->primitive_type_vector [d_primitive_type_cent]
  141.     = builtin->builtin_cent;
  142.   lai->primitive_type_vector [d_primitive_type_ucent]
  143.     = builtin->builtin_ucent;
  144.   lai->primitive_type_vector [d_primitive_type_float]
  145.     = builtin->builtin_float;
  146.   lai->primitive_type_vector [d_primitive_type_double]
  147.     = builtin->builtin_double;
  148.   lai->primitive_type_vector [d_primitive_type_real]
  149.     = builtin->builtin_real;
  150.   lai->primitive_type_vector [d_primitive_type_ifloat]
  151.     = builtin->builtin_ifloat;
  152.   lai->primitive_type_vector [d_primitive_type_idouble]
  153.     = builtin->builtin_idouble;
  154.   lai->primitive_type_vector [d_primitive_type_ireal]
  155.     = builtin->builtin_ireal;
  156.   lai->primitive_type_vector [d_primitive_type_cfloat]
  157.     = builtin->builtin_cfloat;
  158.   lai->primitive_type_vector [d_primitive_type_cdouble]
  159.     = builtin->builtin_cdouble;
  160.   lai->primitive_type_vector [d_primitive_type_creal]
  161.     = builtin->builtin_creal;
  162.   lai->primitive_type_vector [d_primitive_type_char]
  163.     = builtin->builtin_char;
  164.   lai->primitive_type_vector [d_primitive_type_wchar]
  165.     = builtin->builtin_wchar;
  166.   lai->primitive_type_vector [d_primitive_type_dchar]
  167.     = builtin->builtin_dchar;

  168.   lai->bool_type_symbol = "bool";
  169.   lai->bool_type_default = builtin->builtin_bool;
  170. }

  171. static const struct language_defn d_language_defn =
  172. {
  173.   "d",
  174.   "D",
  175.   language_d,
  176.   range_check_off,
  177.   case_sensitive_on,
  178.   array_row_major,
  179.   macro_expansion_no,
  180.   &exp_descriptor_c,
  181.   d_parse,
  182.   d_error,
  183.   null_post_parser,
  184.   c_printchar,                        /* Print a character constant.  */
  185.   c_printstr,                        /* Function to print string constant.  */
  186.   c_emit_char,                        /* Print a single char.  */
  187.   c_print_type,                        /* Print a type using appropriate syntax.  */
  188.   c_print_typedef,                /* Print a typedef using appropriate
  189.                                    syntax.  */
  190.   d_val_print,                        /* Print a value using appropriate syntax.  */
  191.   c_value_print,                /* Print a top-level value.  */
  192.   default_read_var_value,        /* la_read_var_value */
  193.   NULL,                                /* Language specific skip_trampoline.  */
  194.   "this",
  195.   basic_lookup_symbol_nonlocal,
  196.   basic_lookup_transparent_type,
  197.   d_demangle,                        /* Language specific symbol demangler.  */
  198.   NULL,                                /* Language specific
  199.                                    class_name_from_physname.  */
  200.   d_op_print_tab,                /* Expression operators for printing.  */
  201.   1,                                /* C-style arrays.  */
  202.   0,                                /* String lower bound.  */
  203.   default_word_break_characters,
  204.   default_make_symbol_completion_list,
  205.   d_language_arch_info,
  206.   default_print_array_index,
  207.   default_pass_by_reference,
  208.   c_get_string,
  209.   NULL,                                /* la_get_symbol_name_cmp */
  210.   iterate_over_symbols,
  211.   &default_varobj_ops,
  212.   NULL,
  213.   NULL,
  214.   LANG_MAGIC
  215. };

  216. /* Build all D language types for the specified architecture.  */

  217. static void *
  218. build_d_types (struct gdbarch *gdbarch)
  219. {
  220.   struct builtin_d_type *builtin_d_type
  221.     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_d_type);

  222.   /* Basic types.  */
  223.   builtin_d_type->builtin_void
  224.     = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
  225.   builtin_d_type->builtin_bool
  226.     = arch_boolean_type (gdbarch, 8, 1, "bool");
  227.   builtin_d_type->builtin_byte
  228.     = arch_integer_type (gdbarch, 8, 0, "byte");
  229.   builtin_d_type->builtin_ubyte
  230.     = arch_integer_type (gdbarch, 8, 1, "ubyte");
  231.   builtin_d_type->builtin_short
  232.     = arch_integer_type (gdbarch, 16, 0, "short");
  233.   builtin_d_type->builtin_ushort
  234.     = arch_integer_type (gdbarch, 16, 1, "ushort");
  235.   builtin_d_type->builtin_int
  236.     = arch_integer_type (gdbarch, 32, 0, "int");
  237.   builtin_d_type->builtin_uint
  238.     = arch_integer_type (gdbarch, 32, 1, "uint");
  239.   builtin_d_type->builtin_long
  240.     = arch_integer_type (gdbarch, 64, 0, "long");
  241.   builtin_d_type->builtin_ulong
  242.     = arch_integer_type (gdbarch, 64, 1, "ulong");
  243.   builtin_d_type->builtin_cent
  244.     = arch_integer_type (gdbarch, 128, 0, "cent");
  245.   builtin_d_type->builtin_ucent
  246.     = arch_integer_type (gdbarch, 128, 1, "ucent");
  247.   builtin_d_type->builtin_float
  248.     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
  249.                        "float", NULL);
  250.   builtin_d_type->builtin_double
  251.     = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
  252.                        "double", NULL);
  253.   builtin_d_type->builtin_real
  254.     = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
  255.                        "real", NULL);

  256.   TYPE_INSTANCE_FLAGS (builtin_d_type->builtin_byte)
  257.     |= TYPE_INSTANCE_FLAG_NOTTEXT;
  258.   TYPE_INSTANCE_FLAGS (builtin_d_type->builtin_ubyte)
  259.     |= TYPE_INSTANCE_FLAG_NOTTEXT;

  260.   /* Imaginary and complex types.  */
  261.   builtin_d_type->builtin_ifloat
  262.     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
  263.                        "ifloat", NULL);
  264.   builtin_d_type->builtin_idouble
  265.     = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
  266.                        "idouble", NULL);
  267.   builtin_d_type->builtin_ireal
  268.     = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
  269.                        "ireal", NULL);
  270.   builtin_d_type->builtin_cfloat
  271.     = arch_complex_type (gdbarch, "cfloat",
  272.                          builtin_d_type->builtin_float);
  273.   builtin_d_type->builtin_cdouble
  274.     = arch_complex_type (gdbarch, "cdouble",
  275.                          builtin_d_type->builtin_double);
  276.   builtin_d_type->builtin_creal
  277.     = arch_complex_type (gdbarch, "creal",
  278.                          builtin_d_type->builtin_real);

  279.   /* Character types.  */
  280.   builtin_d_type->builtin_char
  281.     = arch_character_type (gdbarch, 8, 1, "char");
  282.   builtin_d_type->builtin_wchar
  283.     = arch_character_type (gdbarch, 16, 1, "wchar");
  284.   builtin_d_type->builtin_dchar
  285.     = arch_character_type (gdbarch, 32, 1, "dchar");

  286.   return builtin_d_type;
  287. }

  288. static struct gdbarch_data *d_type_data;

  289. /* Return the D type table for the specified architecture.  */

  290. const struct builtin_d_type *
  291. builtin_d_type (struct gdbarch *gdbarch)
  292. {
  293.   return gdbarch_data (gdbarch, d_type_data);
  294. }

  295. /* Provide a prototype to silence -Wmissing-prototypes.  */
  296. extern initialize_file_ftype _initialize_d_language;

  297. void
  298. _initialize_d_language (void)
  299. {
  300.   d_type_data = gdbarch_data_register_post_init (build_d_types);

  301.   add_language (&d_language_defn);
  302. }