Home | History | Annotate | Line # | Download | only in gdb
      1   1.1  christos /* Go language support routines for GDB, the GNU debugger.
      2   1.1  christos 
      3  1.11  christos    Copyright (C) 2012-2024 Free Software Foundation, Inc.
      4   1.1  christos 
      5   1.1  christos    This file is part of GDB.
      6   1.1  christos 
      7   1.1  christos    This program is free software; you can redistribute it and/or modify
      8   1.1  christos    it under the terms of the GNU General Public License as published by
      9   1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10   1.1  christos    (at your option) any later version.
     11   1.1  christos 
     12   1.1  christos    This program is distributed in the hope that it will be useful,
     13   1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15   1.1  christos    GNU General Public License for more details.
     16   1.1  christos 
     17   1.1  christos    You should have received a copy of the GNU General Public License
     18   1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19   1.1  christos 
     20   1.1  christos /* TODO:
     21   1.1  christos    - split stacks
     22   1.1  christos    - printing of native types
     23   1.1  christos    - goroutines
     24   1.1  christos    - lots more
     25   1.1  christos    - gccgo mangling needs redoing
     26   1.1  christos      It's too hard, for example, to know whether one is looking at a mangled
     27   1.1  christos      Go symbol or not, and their are ambiguities, e.g., the demangler may
     28   1.1  christos      get passed *any* symbol, including symbols from other languages
     29   1.1  christos      and including symbols that are already demangled.
     30   1.1  christos      One thought is to at least add an _G prefix.
     31   1.1  christos    - 6g mangling isn't supported yet
     32   1.1  christos */
     33   1.1  christos 
     34  1.10  christos #include "gdbsupport/gdb_obstack.h"
     35   1.1  christos #include "block.h"
     36   1.1  christos #include "symtab.h"
     37   1.1  christos #include "language.h"
     38   1.1  christos #include "varobj.h"
     39   1.1  christos #include "go-lang.h"
     40   1.1  christos #include "c-lang.h"
     41   1.1  christos #include "parser-defs.h"
     42   1.9  christos #include "gdbarch.h"
     43   1.1  christos 
     44   1.1  christos #include <ctype.h>
     45   1.1  christos 
     46   1.1  christos /* The main function in the main package.  */
     47   1.1  christos static const char GO_MAIN_MAIN[] = "main.main";
     48   1.1  christos 
     49   1.1  christos /* Function returning the special symbol name used by Go for the main
     50   1.1  christos    procedure in the main program if it is found in minimal symbol list.
     51   1.1  christos    This function tries to find minimal symbols so that it finds them even
     52   1.1  christos    if the program was compiled without debugging information.  */
     53   1.1  christos 
     54   1.1  christos const char *
     55   1.1  christos go_main_name (void)
     56   1.1  christos {
     57  1.12  christos   bound_minimal_symbol msym
     58  1.12  christos     = lookup_minimal_symbol (current_program_space, GO_MAIN_MAIN);
     59   1.3  christos   if (msym.minsym != NULL)
     60   1.1  christos     return GO_MAIN_MAIN;
     61   1.1  christos 
     62   1.1  christos   /* No known entry procedure found, the main program is probably not Go.  */
     63   1.1  christos   return NULL;
     64   1.1  christos }
     65   1.1  christos 
     66   1.1  christos /* Return non-zero if TYPE is a gccgo string.
     67   1.1  christos    We assume CHECK_TYPEDEF has already been done.  */
     68   1.1  christos 
     69   1.1  christos static int
     70   1.1  christos gccgo_string_p (struct type *type)
     71   1.1  christos {
     72   1.1  christos   /* gccgo strings don't necessarily have a name we can use.  */
     73   1.1  christos 
     74   1.9  christos   if (type->num_fields () == 2)
     75   1.1  christos     {
     76   1.9  christos       struct type *type0 = type->field (0).type ();
     77   1.9  christos       struct type *type1 = type->field (1).type ();
     78   1.1  christos 
     79   1.6  christos       type0 = check_typedef (type0);
     80   1.6  christos       type1 = check_typedef (type1);
     81   1.1  christos 
     82   1.9  christos       if (type0->code () == TYPE_CODE_PTR
     83  1.10  christos 	  && strcmp (type->field (0).name (), "__data") == 0
     84   1.9  christos 	  && type1->code () == TYPE_CODE_INT
     85  1.10  christos 	  && strcmp (type->field (1).name (), "__length") == 0)
     86   1.1  christos 	{
     87  1.10  christos 	  struct type *target_type = type0->target_type ();
     88   1.1  christos 
     89   1.6  christos 	  target_type = check_typedef (target_type);
     90   1.1  christos 
     91   1.9  christos 	  if (target_type->code () == TYPE_CODE_INT
     92  1.10  christos 	      && target_type->length () == 1
     93   1.9  christos 	      && strcmp (target_type->name (), "uint8") == 0)
     94   1.1  christos 	    return 1;
     95   1.1  christos 	}
     96   1.1  christos     }
     97   1.1  christos 
     98   1.1  christos   return 0;
     99   1.1  christos }
    100   1.1  christos 
    101   1.1  christos /* Return non-zero if TYPE is a 6g string.
    102   1.1  christos    We assume CHECK_TYPEDEF has already been done.  */
    103   1.1  christos 
    104   1.1  christos static int
    105   1.1  christos sixg_string_p (struct type *type)
    106   1.1  christos {
    107   1.9  christos   if (type->num_fields () == 2
    108   1.9  christos       && type->name () != NULL
    109   1.9  christos       && strcmp (type->name (), "string") == 0)
    110   1.1  christos     return 1;
    111   1.1  christos 
    112   1.1  christos   return 0;
    113   1.1  christos }
    114   1.1  christos 
    115   1.1  christos /* Classify the kind of Go object that TYPE is.
    116   1.1  christos    TYPE is a TYPE_CODE_STRUCT, used to represent a Go object.  */
    117   1.1  christos 
    118   1.1  christos enum go_type
    119   1.1  christos go_classify_struct_type (struct type *type)
    120   1.1  christos {
    121   1.6  christos   type = check_typedef (type);
    122   1.1  christos 
    123   1.1  christos   /* Recognize strings as they're useful to be able to print without
    124   1.1  christos      pretty-printers.  */
    125   1.1  christos   if (gccgo_string_p (type)
    126   1.1  christos       || sixg_string_p (type))
    127   1.1  christos     return GO_TYPE_STRING;
    128   1.1  christos 
    129   1.1  christos   return GO_TYPE_NONE;
    130   1.1  christos }
    131   1.1  christos 
    132   1.1  christos /* Subroutine of unpack_mangled_go_symbol to simplify it.
    133   1.1  christos    Given "[foo.]bar.baz", store "bar" in *PACKAGEP and "baz" in *OBJECTP.
    134   1.1  christos    We stomp on the last '.' to nul-terminate "bar".
    135   1.1  christos    The caller is responsible for memory management.  */
    136   1.1  christos 
    137   1.1  christos static void
    138   1.1  christos unpack_package_and_object (char *buf,
    139   1.1  christos 			   const char **packagep, const char **objectp)
    140   1.1  christos {
    141   1.1  christos   char *last_dot;
    142   1.1  christos 
    143   1.1  christos   last_dot = strrchr (buf, '.');
    144   1.1  christos   gdb_assert (last_dot != NULL);
    145   1.1  christos   *objectp = last_dot + 1;
    146   1.1  christos   *last_dot = '\0';
    147   1.1  christos   last_dot = strrchr (buf, '.');
    148   1.1  christos   if (last_dot != NULL)
    149   1.1  christos     *packagep = last_dot + 1;
    150   1.1  christos   else
    151   1.1  christos     *packagep = buf;
    152   1.1  christos }
    153   1.1  christos 
    154   1.1  christos /* Given a mangled Go symbol, find its package name, object name, and
    155   1.1  christos    method type (if present).
    156   1.1  christos    E.g., for "libgo_net.textproto.String.N33_libgo_net.textproto.ProtocolError"
    157   1.1  christos    *PACKAGEP = "textproto"
    158   1.1  christos    *OBJECTP = "String"
    159   1.1  christos    *METHOD_TYPE_PACKAGEP = "textproto"
    160   1.1  christos    *METHOD_TYPE_OBJECTP = "ProtocolError"
    161   1.1  christos 
    162   1.1  christos    Space for the resulting strings is malloc'd in one buffer.
    163   1.1  christos    PACKAGEP,OBJECTP,METHOD_TYPE* will (typically) point into this buffer.
    164   1.1  christos    A pointer to this buffer is returned, or NULL if symbol isn't a
    165   1.1  christos    mangled Go symbol.
    166   1.1  christos 
    167   1.1  christos    *METHOD_TYPE_IS_POINTERP is set to a boolean indicating if
    168   1.1  christos    the method type is a pointer.
    169   1.1  christos 
    170   1.1  christos    There may be value in returning the outer container,
    171   1.1  christos    i.e., "net" in the above example, but for now it's not needed.
    172   1.1  christos    Plus it's currently not straightforward to compute,
    173   1.1  christos    it comes from -fgo-prefix, and there's no algorithm to compute it.
    174   1.1  christos 
    175   1.1  christos    If we ever need to unpack the method type, this routine should work
    176   1.1  christos    for that too.  */
    177   1.1  christos 
    178  1.11  christos static gdb::unique_xmalloc_ptr<char>
    179   1.1  christos unpack_mangled_go_symbol (const char *mangled_name,
    180   1.1  christos 			  const char **packagep,
    181   1.1  christos 			  const char **objectp,
    182   1.1  christos 			  const char **method_type_packagep,
    183   1.1  christos 			  const char **method_type_objectp,
    184   1.1  christos 			  int *method_type_is_pointerp)
    185   1.1  christos {
    186   1.1  christos   char *buf;
    187   1.1  christos   char *p;
    188   1.1  christos   int len = strlen (mangled_name);
    189   1.1  christos   /* Pointer to last digit in "N<digit(s)>_".  */
    190   1.1  christos   char *saw_digit;
    191   1.1  christos   /* Pointer to "N" if valid "N<digit(s)>_" found.  */
    192   1.1  christos   char *method_type;
    193   1.1  christos   /* Pointer to the first '.'.  */
    194   1.6  christos   const char *first_dot;
    195   1.1  christos   /* Pointer to the last '.'.  */
    196   1.6  christos   const char *last_dot;
    197   1.1  christos   /* Non-zero if we saw a pointer indicator.  */
    198   1.1  christos   int saw_pointer;
    199   1.1  christos 
    200   1.1  christos   *packagep = *objectp = NULL;
    201   1.1  christos   *method_type_packagep = *method_type_objectp = NULL;
    202   1.1  christos   *method_type_is_pointerp = 0;
    203   1.1  christos 
    204   1.1  christos   /* main.init is mangled specially.  */
    205   1.1  christos   if (strcmp (mangled_name, "__go_init_main") == 0)
    206   1.1  christos     {
    207  1.11  christos       gdb::unique_xmalloc_ptr<char> package
    208  1.11  christos 	= make_unique_xstrdup ("main");
    209   1.1  christos 
    210  1.11  christos       *packagep = package.get ();
    211   1.1  christos       *objectp = "init";
    212   1.1  christos       return package;
    213   1.1  christos     }
    214   1.1  christos 
    215   1.1  christos   /* main.main is mangled specially (missing prefix).  */
    216   1.1  christos   if (strcmp (mangled_name, "main.main") == 0)
    217   1.1  christos     {
    218  1.11  christos       gdb::unique_xmalloc_ptr<char> package
    219  1.11  christos 	= make_unique_xstrdup ("main");
    220   1.1  christos 
    221  1.11  christos       *packagep = package.get ();
    222   1.1  christos       *objectp = "main";
    223   1.1  christos       return package;
    224   1.1  christos     }
    225   1.1  christos 
    226   1.1  christos   /* We may get passed, e.g., "main.T.Foo", which is *not* mangled.
    227   1.1  christos      Alas it looks exactly like "prefix.package.object."
    228   1.1  christos      To cope for now we only recognize the following prefixes:
    229   1.1  christos 
    230   1.1  christos      go: the default
    231   1.1  christos      libgo_.*: used by gccgo's runtime
    232   1.1  christos 
    233   1.1  christos      Thus we don't support -fgo-prefix (except as used by the runtime).  */
    234  1.11  christos   bool v3;
    235  1.11  christos   if (startswith (mangled_name, "go_0"))
    236  1.11  christos     /* V3 mangling detected, see
    237  1.11  christos        https://go-review.googlesource.com/c/gofrontend/+/271726 .  */
    238  1.11  christos     v3 = true;
    239  1.11  christos   else if (startswith (mangled_name, "go.")
    240  1.11  christos 	   || startswith (mangled_name, "libgo_"))
    241  1.11  christos     v3 = false;
    242  1.11  christos   else
    243   1.1  christos     return NULL;
    244   1.1  christos 
    245   1.1  christos   /* Quick check for whether a search may be fruitful.  */
    246   1.1  christos   /* Ignore anything with @plt, etc. in it.  */
    247   1.1  christos   if (strchr (mangled_name, '@') != NULL)
    248   1.1  christos     return NULL;
    249  1.11  christos 
    250   1.1  christos   /* It must have at least two dots.  */
    251  1.11  christos   if (v3)
    252  1.11  christos     first_dot = strchr (mangled_name, '0');
    253  1.11  christos   else
    254  1.11  christos     first_dot = strchr (mangled_name, '.');
    255  1.11  christos 
    256   1.1  christos   if (first_dot == NULL)
    257   1.1  christos     return NULL;
    258   1.1  christos   /* Treat "foo.bar" as unmangled.  It can collide with lots of other
    259   1.1  christos      languages and it's not clear what the consequences are.
    260   1.1  christos      And except for main.main, all gccgo symbols are at least
    261   1.1  christos      prefix.package.object.  */
    262   1.1  christos   last_dot = strrchr (mangled_name, '.');
    263   1.1  christos   if (last_dot == first_dot)
    264   1.1  christos     return NULL;
    265   1.1  christos 
    266   1.1  christos   /* More quick checks.  */
    267   1.1  christos   if (last_dot[1] == '\0' /* foo. */
    268   1.1  christos       || last_dot[-1] == '.') /* foo..bar */
    269   1.1  christos     return NULL;
    270   1.1  christos 
    271   1.1  christos   /* At this point we've decided we have a mangled Go symbol.  */
    272   1.1  christos 
    273  1.11  christos   gdb::unique_xmalloc_ptr<char> result = make_unique_xstrdup (mangled_name);
    274  1.11  christos   buf = result.get ();
    275  1.11  christos 
    276  1.11  christos   if (v3)
    277  1.11  christos     {
    278  1.11  christos       /* Replace "go_0" with "\0go.".  */
    279  1.11  christos       buf[0] = '\0';
    280  1.11  christos       buf[1] = 'g';
    281  1.11  christos       buf[2] = 'o';
    282  1.11  christos       buf[3] = '.';
    283  1.11  christos 
    284  1.11  christos       /* Skip the '\0'.  */
    285  1.11  christos       buf++;
    286  1.11  christos     }
    287   1.1  christos 
    288   1.1  christos   /* Search backwards looking for "N<digit(s)>".  */
    289   1.1  christos   p = buf + len;
    290   1.1  christos   saw_digit = method_type = NULL;
    291   1.1  christos   saw_pointer = 0;
    292   1.1  christos   while (p > buf)
    293   1.1  christos     {
    294   1.1  christos       int current = *(const unsigned char *) --p;
    295  1.11  christos       int current_is_digit = isdigit ((unsigned char)current);
    296   1.1  christos 
    297   1.1  christos       if (saw_digit)
    298   1.1  christos 	{
    299   1.1  christos 	  if (current_is_digit)
    300   1.1  christos 	    continue;
    301   1.1  christos 	  if (current == 'N'
    302   1.1  christos 	      && ((p > buf && p[-1] == '.')
    303   1.1  christos 		  || (p > buf + 1 && p[-1] == 'p' && p[-2] == '.')))
    304   1.1  christos 	    {
    305   1.1  christos 	      if (atoi (p + 1) == strlen (saw_digit + 2))
    306   1.1  christos 		{
    307   1.1  christos 		  if (p[-1] == '.')
    308   1.1  christos 		    method_type = p - 1;
    309   1.1  christos 		  else
    310   1.1  christos 		    {
    311   1.1  christos 		      gdb_assert (p[-1] == 'p');
    312   1.1  christos 		      saw_pointer = 1;
    313   1.1  christos 		      method_type = p - 2;
    314   1.1  christos 		    }
    315   1.1  christos 		  break;
    316   1.1  christos 		}
    317   1.1  christos 	    }
    318   1.1  christos 	  /* Not what we're looking for, reset and keep looking.  */
    319   1.1  christos 	  saw_digit = NULL;
    320   1.1  christos 	  saw_pointer = 0;
    321   1.1  christos 	  continue;
    322   1.1  christos 	}
    323   1.1  christos       if (current_is_digit && p[1] == '_')
    324   1.1  christos 	{
    325   1.1  christos 	  /* Possible start of method "this" [sic] type.  */
    326   1.1  christos 	  saw_digit = p;
    327   1.1  christos 	  continue;
    328   1.1  christos 	}
    329   1.1  christos     }
    330   1.1  christos 
    331   1.1  christos   if (method_type != NULL
    332   1.1  christos       /* Ensure not something like "..foo".  */
    333   1.1  christos       && (method_type > buf && method_type[-1] != '.'))
    334   1.1  christos     {
    335   1.1  christos       unpack_package_and_object (saw_digit + 2,
    336   1.1  christos 				 method_type_packagep, method_type_objectp);
    337   1.1  christos       *method_type = '\0';
    338   1.1  christos       *method_type_is_pointerp = saw_pointer;
    339   1.1  christos     }
    340   1.1  christos 
    341   1.1  christos   unpack_package_and_object (buf, packagep, objectp);
    342  1.11  christos   return result;
    343   1.1  christos }
    344   1.1  christos 
    345   1.1  christos /* Implements the la_demangle language_defn routine for language Go.
    346   1.1  christos 
    347   1.1  christos    N.B. This may get passed *any* symbol, including symbols from other
    348   1.1  christos    languages and including symbols that are already demangled.
    349   1.1  christos    Both of these situations are kinda unfortunate, but that's how things
    350   1.1  christos    are today.
    351   1.1  christos 
    352   1.1  christos    N.B. This currently only supports gccgo's mangling.
    353   1.1  christos 
    354   1.1  christos    N.B. gccgo's mangling needs, I think, changing.
    355   1.1  christos    This demangler can't work in all situations,
    356   1.1  christos    thus not too much effort is currently put into it.  */
    357   1.1  christos 
    358  1.10  christos gdb::unique_xmalloc_ptr<char>
    359  1.10  christos go_language::demangle_symbol (const char *mangled_name, int options) const
    360   1.1  christos {
    361   1.1  christos   const char *package_name;
    362   1.1  christos   const char *object_name;
    363   1.1  christos   const char *method_type_package_name;
    364   1.1  christos   const char *method_type_object_name;
    365   1.1  christos   int method_type_is_pointer;
    366   1.1  christos 
    367   1.1  christos   if (mangled_name == NULL)
    368   1.1  christos     return NULL;
    369   1.1  christos 
    370  1.10  christos   gdb::unique_xmalloc_ptr<char> name_buf
    371  1.10  christos     (unpack_mangled_go_symbol (mangled_name,
    372  1.10  christos 			       &package_name, &object_name,
    373  1.10  christos 			       &method_type_package_name,
    374  1.10  christos 			       &method_type_object_name,
    375  1.10  christos 			       &method_type_is_pointer));
    376   1.1  christos   if (name_buf == NULL)
    377   1.1  christos     return NULL;
    378   1.1  christos 
    379  1.10  christos   auto_obstack tempbuf;
    380   1.1  christos 
    381   1.1  christos   /* Print methods as they appear in "method expressions".  */
    382   1.1  christos   if (method_type_package_name != NULL)
    383   1.1  christos     {
    384   1.1  christos       /* FIXME: Seems like we should include package_name here somewhere.  */
    385   1.1  christos       if (method_type_is_pointer)
    386   1.1  christos 	  obstack_grow_str (&tempbuf, "(*");
    387   1.1  christos       obstack_grow_str (&tempbuf, method_type_package_name);
    388   1.1  christos       obstack_grow_str (&tempbuf, ".");
    389   1.1  christos       obstack_grow_str (&tempbuf, method_type_object_name);
    390   1.1  christos       if (method_type_is_pointer)
    391   1.1  christos 	obstack_grow_str (&tempbuf, ")");
    392   1.1  christos       obstack_grow_str (&tempbuf, ".");
    393   1.1  christos       obstack_grow_str (&tempbuf, object_name);
    394   1.1  christos     }
    395   1.1  christos   else
    396   1.1  christos     {
    397   1.1  christos       obstack_grow_str (&tempbuf, package_name);
    398   1.1  christos       obstack_grow_str (&tempbuf, ".");
    399   1.1  christos       obstack_grow_str (&tempbuf, object_name);
    400   1.1  christos     }
    401   1.1  christos   obstack_grow_str0 (&tempbuf, "");
    402   1.1  christos 
    403  1.10  christos   return make_unique_xstrdup ((const char *) obstack_finish (&tempbuf));
    404   1.1  christos }
    405   1.1  christos 
    406  1.11  christos /* See go-lang.h.  */
    407   1.1  christos 
    408  1.11  christos gdb::unique_xmalloc_ptr<char>
    409   1.1  christos go_symbol_package_name (const struct symbol *sym)
    410   1.1  christos {
    411   1.9  christos   const char *mangled_name = sym->linkage_name ();
    412   1.1  christos   const char *package_name;
    413   1.1  christos   const char *object_name;
    414   1.1  christos   const char *method_type_package_name;
    415   1.1  christos   const char *method_type_object_name;
    416   1.1  christos   int method_type_is_pointer;
    417  1.11  christos   gdb::unique_xmalloc_ptr<char> name_buf;
    418   1.1  christos 
    419  1.11  christos   if (sym->language () != language_go)
    420  1.11  christos     return nullptr;
    421   1.1  christos   name_buf = unpack_mangled_go_symbol (mangled_name,
    422   1.1  christos 				       &package_name, &object_name,
    423   1.1  christos 				       &method_type_package_name,
    424   1.1  christos 				       &method_type_object_name,
    425   1.1  christos 				       &method_type_is_pointer);
    426   1.1  christos   /* Some Go symbols don't have mangled form we interpret (yet).  */
    427   1.1  christos   if (name_buf == NULL)
    428   1.1  christos     return NULL;
    429  1.11  christos   return make_unique_xstrdup (package_name);
    430   1.1  christos }
    431   1.1  christos 
    432  1.11  christos /* See go-lang.h.  */
    433   1.1  christos 
    434  1.11  christos gdb::unique_xmalloc_ptr<char>
    435   1.1  christos go_block_package_name (const struct block *block)
    436   1.1  christos {
    437   1.1  christos   while (block != NULL)
    438   1.1  christos     {
    439  1.10  christos       struct symbol *function = block->function ();
    440   1.1  christos 
    441   1.1  christos       if (function != NULL)
    442   1.1  christos 	{
    443  1.11  christos 	  gdb::unique_xmalloc_ptr<char> package_name
    444  1.11  christos 	    = go_symbol_package_name (function);
    445   1.1  christos 
    446   1.1  christos 	  if (package_name != NULL)
    447   1.1  christos 	    return package_name;
    448   1.1  christos 
    449   1.1  christos 	  /* Stop looking if we find a function without a package name.
    450   1.1  christos 	     We're most likely outside of Go and thus the concept of the
    451   1.1  christos 	     "current" package is gone.  */
    452   1.1  christos 	  return NULL;
    453   1.1  christos 	}
    454   1.1  christos 
    455  1.10  christos       block = block->superblock ();
    456   1.1  christos     }
    457   1.1  christos 
    458   1.1  christos   return NULL;
    459   1.1  christos }
    460   1.1  christos 
    461  1.10  christos /* See language.h.  */
    462   1.9  christos 
    463  1.10  christos void
    464  1.10  christos go_language::language_arch_info (struct gdbarch *gdbarch,
    465  1.10  christos 				 struct language_arch_info *lai) const
    466  1.10  christos {
    467  1.10  christos   const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
    468   1.9  christos 
    469  1.10  christos   /* Helper function to allow shorter lines below.  */
    470  1.10  christos   auto add  = [&] (struct type * t) -> struct type *
    471   1.9  christos   {
    472  1.10  christos     lai->add_primitive_type (t);
    473  1.10  christos     return t;
    474  1.10  christos   };
    475  1.10  christos 
    476  1.10  christos   add (builtin->builtin_void);
    477  1.10  christos   add (builtin->builtin_char);
    478  1.10  christos   add (builtin->builtin_bool);
    479  1.10  christos   add (builtin->builtin_int);
    480  1.10  christos   add (builtin->builtin_uint);
    481  1.10  christos   add (builtin->builtin_uintptr);
    482  1.10  christos   add (builtin->builtin_int8);
    483  1.10  christos   add (builtin->builtin_int16);
    484  1.10  christos   add (builtin->builtin_int32);
    485  1.10  christos   add (builtin->builtin_int64);
    486  1.10  christos   add (builtin->builtin_uint8);
    487  1.10  christos   add (builtin->builtin_uint16);
    488  1.10  christos   add (builtin->builtin_uint32);
    489  1.10  christos   add (builtin->builtin_uint64);
    490  1.10  christos   add (builtin->builtin_float32);
    491  1.10  christos   add (builtin->builtin_float64);
    492  1.10  christos   add (builtin->builtin_complex64);
    493  1.10  christos   add (builtin->builtin_complex128);
    494   1.9  christos 
    495  1.10  christos   lai->set_string_char_type (builtin->builtin_char);
    496  1.10  christos   lai->set_bool_type (builtin->builtin_bool, "bool");
    497  1.10  christos }
    498   1.1  christos 
    499   1.9  christos /* Single instance of the Go language class.  */
    500   1.9  christos 
    501   1.9  christos static go_language go_language_defn;
    502   1.9  christos 
    503  1.10  christos static struct builtin_go_type *
    504   1.1  christos build_go_types (struct gdbarch *gdbarch)
    505   1.1  christos {
    506  1.10  christos   struct builtin_go_type *builtin_go_type = new struct builtin_go_type;
    507   1.1  christos 
    508  1.11  christos   type_allocator alloc (gdbarch);
    509  1.11  christos   builtin_go_type->builtin_void = builtin_type (gdbarch)->builtin_void;
    510   1.1  christos   builtin_go_type->builtin_char
    511  1.11  christos     = init_character_type (alloc, 8, 1, "char");
    512   1.1  christos   builtin_go_type->builtin_bool
    513  1.11  christos     = init_boolean_type (alloc, 8, 0, "bool");
    514   1.1  christos   builtin_go_type->builtin_int
    515  1.11  christos     = init_integer_type (alloc, gdbarch_int_bit (gdbarch), 0, "int");
    516   1.1  christos   builtin_go_type->builtin_uint
    517  1.11  christos     = init_integer_type (alloc, gdbarch_int_bit (gdbarch), 1, "uint");
    518   1.1  christos   builtin_go_type->builtin_uintptr
    519  1.11  christos     = init_integer_type (alloc, gdbarch_ptr_bit (gdbarch), 1, "uintptr");
    520   1.1  christos   builtin_go_type->builtin_int8
    521  1.11  christos     = init_integer_type (alloc, 8, 0, "int8");
    522   1.1  christos   builtin_go_type->builtin_int16
    523  1.11  christos     = init_integer_type (alloc, 16, 0, "int16");
    524   1.1  christos   builtin_go_type->builtin_int32
    525  1.11  christos     = init_integer_type (alloc, 32, 0, "int32");
    526   1.1  christos   builtin_go_type->builtin_int64
    527  1.11  christos     = init_integer_type (alloc, 64, 0, "int64");
    528   1.1  christos   builtin_go_type->builtin_uint8
    529  1.11  christos     = init_integer_type (alloc, 8, 1, "uint8");
    530   1.1  christos   builtin_go_type->builtin_uint16
    531  1.11  christos     = init_integer_type (alloc, 16, 1, "uint16");
    532   1.1  christos   builtin_go_type->builtin_uint32
    533  1.11  christos     = init_integer_type (alloc, 32, 1, "uint32");
    534   1.1  christos   builtin_go_type->builtin_uint64
    535  1.11  christos     = init_integer_type (alloc, 64, 1, "uint64");
    536   1.1  christos   builtin_go_type->builtin_float32
    537  1.11  christos     = init_float_type (alloc, 32, "float32", floatformats_ieee_single);
    538   1.1  christos   builtin_go_type->builtin_float64
    539  1.11  christos     = init_float_type (alloc, 64, "float64", floatformats_ieee_double);
    540   1.1  christos   builtin_go_type->builtin_complex64
    541   1.9  christos     = init_complex_type ("complex64", builtin_go_type->builtin_float32);
    542   1.1  christos   builtin_go_type->builtin_complex128
    543   1.9  christos     = init_complex_type ("complex128", builtin_go_type->builtin_float64);
    544   1.1  christos 
    545   1.1  christos   return builtin_go_type;
    546   1.1  christos }
    547   1.1  christos 
    548  1.10  christos static const registry<gdbarch>::key<struct builtin_go_type> go_type_data;
    549   1.1  christos 
    550   1.1  christos const struct builtin_go_type *
    551   1.1  christos builtin_go_type (struct gdbarch *gdbarch)
    552   1.1  christos {
    553  1.10  christos   struct builtin_go_type *result = go_type_data.get (gdbarch);
    554  1.10  christos   if (result == nullptr)
    555  1.10  christos     {
    556  1.10  christos       result = build_go_types (gdbarch);
    557  1.10  christos       go_type_data.set (gdbarch, result);
    558  1.10  christos     }
    559   1.1  christos 
    560  1.10  christos   return result;
    561   1.1  christos }
    562