Home | History | Annotate | Line # | Download | only in gdb
go-lang.c revision 1.1
      1  1.1  christos /* Go language support routines for GDB, the GNU debugger.
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 2012-2014 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.1  christos #include "defs.h"
     35  1.1  christos #include "gdb_assert.h"
     36  1.1  christos #include "gdb_obstack.h"
     37  1.1  christos #include <string.h>
     38  1.1  christos #include "block.h"
     39  1.1  christos #include "symtab.h"
     40  1.1  christos #include "language.h"
     41  1.1  christos #include "varobj.h"
     42  1.1  christos #include "go-lang.h"
     43  1.1  christos #include "c-lang.h"
     44  1.1  christos #include "parser-defs.h"
     45  1.1  christos 
     46  1.1  christos #include <ctype.h>
     47  1.1  christos 
     48  1.1  christos /* The main function in the main package.  */
     49  1.1  christos static const char GO_MAIN_MAIN[] = "main.main";
     50  1.1  christos 
     51  1.1  christos /* Function returning the special symbol name used by Go for the main
     52  1.1  christos    procedure in the main program if it is found in minimal symbol list.
     53  1.1  christos    This function tries to find minimal symbols so that it finds them even
     54  1.1  christos    if the program was compiled without debugging information.  */
     55  1.1  christos 
     56  1.1  christos const char *
     57  1.1  christos go_main_name (void)
     58  1.1  christos {
     59  1.1  christos   struct minimal_symbol *msym;
     60  1.1  christos 
     61  1.1  christos   msym = lookup_minimal_symbol (GO_MAIN_MAIN, NULL, NULL);
     62  1.1  christos   if (msym != NULL)
     63  1.1  christos     return GO_MAIN_MAIN;
     64  1.1  christos 
     65  1.1  christos   /* No known entry procedure found, the main program is probably not Go.  */
     66  1.1  christos   return NULL;
     67  1.1  christos }
     68  1.1  christos 
     69  1.1  christos /* Return non-zero if TYPE is a gccgo string.
     70  1.1  christos    We assume CHECK_TYPEDEF has already been done.  */
     71  1.1  christos 
     72  1.1  christos static int
     73  1.1  christos gccgo_string_p (struct type *type)
     74  1.1  christos {
     75  1.1  christos   /* gccgo strings don't necessarily have a name we can use.  */
     76  1.1  christos 
     77  1.1  christos   if (TYPE_NFIELDS (type) == 2)
     78  1.1  christos     {
     79  1.1  christos       struct type *type0 = TYPE_FIELD_TYPE (type, 0);
     80  1.1  christos       struct type *type1 = TYPE_FIELD_TYPE (type, 1);
     81  1.1  christos 
     82  1.1  christos       CHECK_TYPEDEF (type0);
     83  1.1  christos       CHECK_TYPEDEF (type1);
     84  1.1  christos 
     85  1.1  christos       if (TYPE_CODE (type0) == TYPE_CODE_PTR
     86  1.1  christos 	  && strcmp (TYPE_FIELD_NAME (type, 0), "__data") == 0
     87  1.1  christos 	  && TYPE_CODE (type1) == TYPE_CODE_INT
     88  1.1  christos 	  && strcmp (TYPE_FIELD_NAME (type, 1), "__length") == 0)
     89  1.1  christos 	{
     90  1.1  christos 	  struct type *target_type = TYPE_TARGET_TYPE (type0);
     91  1.1  christos 
     92  1.1  christos 	  CHECK_TYPEDEF (target_type);
     93  1.1  christos 
     94  1.1  christos 	  if (TYPE_CODE (target_type) == TYPE_CODE_INT
     95  1.1  christos 	      && TYPE_LENGTH (target_type) == 1
     96  1.1  christos 	      && strcmp (TYPE_NAME (target_type), "uint8") == 0)
     97  1.1  christos 	    return 1;
     98  1.1  christos 	}
     99  1.1  christos     }
    100  1.1  christos 
    101  1.1  christos   return 0;
    102  1.1  christos }
    103  1.1  christos 
    104  1.1  christos /* Return non-zero if TYPE is a 6g string.
    105  1.1  christos    We assume CHECK_TYPEDEF has already been done.  */
    106  1.1  christos 
    107  1.1  christos static int
    108  1.1  christos sixg_string_p (struct type *type)
    109  1.1  christos {
    110  1.1  christos   if (TYPE_NFIELDS (type) == 2
    111  1.1  christos       && TYPE_TAG_NAME (type) != NULL
    112  1.1  christos       && strcmp (TYPE_TAG_NAME (type), "string") == 0)
    113  1.1  christos     return 1;
    114  1.1  christos 
    115  1.1  christos   return 0;
    116  1.1  christos }
    117  1.1  christos 
    118  1.1  christos /* Classify the kind of Go object that TYPE is.
    119  1.1  christos    TYPE is a TYPE_CODE_STRUCT, used to represent a Go object.  */
    120  1.1  christos 
    121  1.1  christos enum go_type
    122  1.1  christos go_classify_struct_type (struct type *type)
    123  1.1  christos {
    124  1.1  christos   CHECK_TYPEDEF (type);
    125  1.1  christos 
    126  1.1  christos   /* Recognize strings as they're useful to be able to print without
    127  1.1  christos      pretty-printers.  */
    128  1.1  christos   if (gccgo_string_p (type)
    129  1.1  christos       || sixg_string_p (type))
    130  1.1  christos     return GO_TYPE_STRING;
    131  1.1  christos 
    132  1.1  christos   return GO_TYPE_NONE;
    133  1.1  christos }
    134  1.1  christos 
    135  1.1  christos /* Subroutine of unpack_mangled_go_symbol to simplify it.
    136  1.1  christos    Given "[foo.]bar.baz", store "bar" in *PACKAGEP and "baz" in *OBJECTP.
    137  1.1  christos    We stomp on the last '.' to nul-terminate "bar".
    138  1.1  christos    The caller is responsible for memory management.  */
    139  1.1  christos 
    140  1.1  christos static void
    141  1.1  christos unpack_package_and_object (char *buf,
    142  1.1  christos 			   const char **packagep, const char **objectp)
    143  1.1  christos {
    144  1.1  christos   char *last_dot;
    145  1.1  christos 
    146  1.1  christos   last_dot = strrchr (buf, '.');
    147  1.1  christos   gdb_assert (last_dot != NULL);
    148  1.1  christos   *objectp = last_dot + 1;
    149  1.1  christos   *last_dot = '\0';
    150  1.1  christos   last_dot = strrchr (buf, '.');
    151  1.1  christos   if (last_dot != NULL)
    152  1.1  christos     *packagep = last_dot + 1;
    153  1.1  christos   else
    154  1.1  christos     *packagep = buf;
    155  1.1  christos }
    156  1.1  christos 
    157  1.1  christos /* Given a mangled Go symbol, find its package name, object name, and
    158  1.1  christos    method type (if present).
    159  1.1  christos    E.g., for "libgo_net.textproto.String.N33_libgo_net.textproto.ProtocolError"
    160  1.1  christos    *PACKAGEP = "textproto"
    161  1.1  christos    *OBJECTP = "String"
    162  1.1  christos    *METHOD_TYPE_PACKAGEP = "textproto"
    163  1.1  christos    *METHOD_TYPE_OBJECTP = "ProtocolError"
    164  1.1  christos 
    165  1.1  christos    Space for the resulting strings is malloc'd in one buffer.
    166  1.1  christos    PACKAGEP,OBJECTP,METHOD_TYPE* will (typically) point into this buffer.
    167  1.1  christos    [There are a few exceptions, but the caller is still responsible for
    168  1.1  christos    freeing the resulting pointer.]
    169  1.1  christos    A pointer to this buffer is returned, or NULL if symbol isn't a
    170  1.1  christos    mangled Go symbol.
    171  1.1  christos    The caller is responsible for freeing the result.
    172  1.1  christos 
    173  1.1  christos    *METHOD_TYPE_IS_POINTERP is set to a boolean indicating if
    174  1.1  christos    the method type is a pointer.
    175  1.1  christos 
    176  1.1  christos    There may be value in returning the outer container,
    177  1.1  christos    i.e., "net" in the above example, but for now it's not needed.
    178  1.1  christos    Plus it's currently not straightforward to compute,
    179  1.1  christos    it comes from -fgo-prefix, and there's no algorithm to compute it.
    180  1.1  christos 
    181  1.1  christos    If we ever need to unpack the method type, this routine should work
    182  1.1  christos    for that too.  */
    183  1.1  christos 
    184  1.1  christos static char *
    185  1.1  christos unpack_mangled_go_symbol (const char *mangled_name,
    186  1.1  christos 			  const char **packagep,
    187  1.1  christos 			  const char **objectp,
    188  1.1  christos 			  const char **method_type_packagep,
    189  1.1  christos 			  const char **method_type_objectp,
    190  1.1  christos 			  int *method_type_is_pointerp)
    191  1.1  christos {
    192  1.1  christos   char *buf;
    193  1.1  christos   char *p;
    194  1.1  christos   int len = strlen (mangled_name);
    195  1.1  christos   /* Pointer to last digit in "N<digit(s)>_".  */
    196  1.1  christos   char *saw_digit;
    197  1.1  christos   /* Pointer to "N" if valid "N<digit(s)>_" found.  */
    198  1.1  christos   char *method_type;
    199  1.1  christos   /* Pointer to the first '.'.  */
    200  1.1  christos   char *first_dot;
    201  1.1  christos   /* Pointer to the last '.'.  */
    202  1.1  christos   char *last_dot;
    203  1.1  christos   /* Non-zero if we saw a pointer indicator.  */
    204  1.1  christos   int saw_pointer;
    205  1.1  christos 
    206  1.1  christos   *packagep = *objectp = NULL;
    207  1.1  christos   *method_type_packagep = *method_type_objectp = NULL;
    208  1.1  christos   *method_type_is_pointerp = 0;
    209  1.1  christos 
    210  1.1  christos   /* main.init is mangled specially.  */
    211  1.1  christos   if (strcmp (mangled_name, "__go_init_main") == 0)
    212  1.1  christos     {
    213  1.1  christos       char *package = xstrdup ("main");
    214  1.1  christos 
    215  1.1  christos       *packagep = package;
    216  1.1  christos       *objectp = "init";
    217  1.1  christos       return package;
    218  1.1  christos     }
    219  1.1  christos 
    220  1.1  christos   /* main.main is mangled specially (missing prefix).  */
    221  1.1  christos   if (strcmp (mangled_name, "main.main") == 0)
    222  1.1  christos     {
    223  1.1  christos       char *package = xstrdup ("main");
    224  1.1  christos 
    225  1.1  christos       *packagep = package;
    226  1.1  christos       *objectp = "main";
    227  1.1  christos       return package;
    228  1.1  christos     }
    229  1.1  christos 
    230  1.1  christos   /* We may get passed, e.g., "main.T.Foo", which is *not* mangled.
    231  1.1  christos      Alas it looks exactly like "prefix.package.object."
    232  1.1  christos      To cope for now we only recognize the following prefixes:
    233  1.1  christos 
    234  1.1  christos      go: the default
    235  1.1  christos      libgo_.*: used by gccgo's runtime
    236  1.1  christos 
    237  1.1  christos      Thus we don't support -fgo-prefix (except as used by the runtime).  */
    238  1.1  christos   if (strncmp (mangled_name, "go.", 3) != 0
    239  1.1  christos       && strncmp (mangled_name, "libgo_", 6) != 0)
    240  1.1  christos     return NULL;
    241  1.1  christos 
    242  1.1  christos   /* Quick check for whether a search may be fruitful.  */
    243  1.1  christos   /* Ignore anything with @plt, etc. in it.  */
    244  1.1  christos   if (strchr (mangled_name, '@') != NULL)
    245  1.1  christos     return NULL;
    246  1.1  christos   /* It must have at least two dots.  */
    247  1.1  christos   first_dot = strchr (mangled_name, '.');
    248  1.1  christos   if (first_dot == NULL)
    249  1.1  christos     return NULL;
    250  1.1  christos   /* Treat "foo.bar" as unmangled.  It can collide with lots of other
    251  1.1  christos      languages and it's not clear what the consequences are.
    252  1.1  christos      And except for main.main, all gccgo symbols are at least
    253  1.1  christos      prefix.package.object.  */
    254  1.1  christos   last_dot = strrchr (mangled_name, '.');
    255  1.1  christos   if (last_dot == first_dot)
    256  1.1  christos     return NULL;
    257  1.1  christos 
    258  1.1  christos   /* More quick checks.  */
    259  1.1  christos   if (last_dot[1] == '\0' /* foo. */
    260  1.1  christos       || last_dot[-1] == '.') /* foo..bar */
    261  1.1  christos     return NULL;
    262  1.1  christos 
    263  1.1  christos   /* At this point we've decided we have a mangled Go symbol.  */
    264  1.1  christos 
    265  1.1  christos   buf = xstrdup (mangled_name);
    266  1.1  christos 
    267  1.1  christos   /* Search backwards looking for "N<digit(s)>".  */
    268  1.1  christos   p = buf + len;
    269  1.1  christos   saw_digit = method_type = NULL;
    270  1.1  christos   saw_pointer = 0;
    271  1.1  christos   while (p > buf)
    272  1.1  christos     {
    273  1.1  christos       int current = *(const unsigned char *) --p;
    274  1.1  christos       int current_is_digit = isdigit (current);
    275  1.1  christos 
    276  1.1  christos       if (saw_digit)
    277  1.1  christos 	{
    278  1.1  christos 	  if (current_is_digit)
    279  1.1  christos 	    continue;
    280  1.1  christos 	  if (current == 'N'
    281  1.1  christos 	      && ((p > buf && p[-1] == '.')
    282  1.1  christos 		  || (p > buf + 1 && p[-1] == 'p' && p[-2] == '.')))
    283  1.1  christos 	    {
    284  1.1  christos 	      if (atoi (p + 1) == strlen (saw_digit + 2))
    285  1.1  christos 		{
    286  1.1  christos 		  if (p[-1] == '.')
    287  1.1  christos 		    method_type = p - 1;
    288  1.1  christos 		  else
    289  1.1  christos 		    {
    290  1.1  christos 		      gdb_assert (p[-1] == 'p');
    291  1.1  christos 		      saw_pointer = 1;
    292  1.1  christos 		      method_type = p - 2;
    293  1.1  christos 		    }
    294  1.1  christos 		  break;
    295  1.1  christos 		}
    296  1.1  christos 	    }
    297  1.1  christos 	  /* Not what we're looking for, reset and keep looking.  */
    298  1.1  christos 	  saw_digit = NULL;
    299  1.1  christos 	  saw_pointer = 0;
    300  1.1  christos 	  continue;
    301  1.1  christos 	}
    302  1.1  christos       if (current_is_digit && p[1] == '_')
    303  1.1  christos 	{
    304  1.1  christos 	  /* Possible start of method "this" [sic] type.  */
    305  1.1  christos 	  saw_digit = p;
    306  1.1  christos 	  continue;
    307  1.1  christos 	}
    308  1.1  christos     }
    309  1.1  christos 
    310  1.1  christos   if (method_type != NULL
    311  1.1  christos       /* Ensure not something like "..foo".  */
    312  1.1  christos       && (method_type > buf && method_type[-1] != '.'))
    313  1.1  christos     {
    314  1.1  christos       unpack_package_and_object (saw_digit + 2,
    315  1.1  christos 				 method_type_packagep, method_type_objectp);
    316  1.1  christos       *method_type = '\0';
    317  1.1  christos       *method_type_is_pointerp = saw_pointer;
    318  1.1  christos     }
    319  1.1  christos 
    320  1.1  christos   unpack_package_and_object (buf, packagep, objectp);
    321  1.1  christos   return buf;
    322  1.1  christos }
    323  1.1  christos 
    324  1.1  christos /* Implements the la_demangle language_defn routine for language Go.
    325  1.1  christos 
    326  1.1  christos    N.B. This may get passed *any* symbol, including symbols from other
    327  1.1  christos    languages and including symbols that are already demangled.
    328  1.1  christos    Both of these situations are kinda unfortunate, but that's how things
    329  1.1  christos    are today.
    330  1.1  christos 
    331  1.1  christos    N.B. This currently only supports gccgo's mangling.
    332  1.1  christos 
    333  1.1  christos    N.B. gccgo's mangling needs, I think, changing.
    334  1.1  christos    This demangler can't work in all situations,
    335  1.1  christos    thus not too much effort is currently put into it.  */
    336  1.1  christos 
    337  1.1  christos char *
    338  1.1  christos go_demangle (const char *mangled_name, int options)
    339  1.1  christos {
    340  1.1  christos   struct obstack tempbuf;
    341  1.1  christos   char *result;
    342  1.1  christos   char *name_buf;
    343  1.1  christos   const char *package_name;
    344  1.1  christos   const char *object_name;
    345  1.1  christos   const char *method_type_package_name;
    346  1.1  christos   const char *method_type_object_name;
    347  1.1  christos   int method_type_is_pointer;
    348  1.1  christos 
    349  1.1  christos   if (mangled_name == NULL)
    350  1.1  christos     return NULL;
    351  1.1  christos 
    352  1.1  christos   name_buf = unpack_mangled_go_symbol (mangled_name,
    353  1.1  christos 				       &package_name, &object_name,
    354  1.1  christos 				       &method_type_package_name,
    355  1.1  christos 				       &method_type_object_name,
    356  1.1  christos 				       &method_type_is_pointer);
    357  1.1  christos   if (name_buf == NULL)
    358  1.1  christos     return NULL;
    359  1.1  christos 
    360  1.1  christos   obstack_init (&tempbuf);
    361  1.1  christos 
    362  1.1  christos   /* Print methods as they appear in "method expressions".  */
    363  1.1  christos   if (method_type_package_name != NULL)
    364  1.1  christos     {
    365  1.1  christos       /* FIXME: Seems like we should include package_name here somewhere.  */
    366  1.1  christos       if (method_type_is_pointer)
    367  1.1  christos 	  obstack_grow_str (&tempbuf, "(*");
    368  1.1  christos       obstack_grow_str (&tempbuf, method_type_package_name);
    369  1.1  christos       obstack_grow_str (&tempbuf, ".");
    370  1.1  christos       obstack_grow_str (&tempbuf, method_type_object_name);
    371  1.1  christos       if (method_type_is_pointer)
    372  1.1  christos 	obstack_grow_str (&tempbuf, ")");
    373  1.1  christos       obstack_grow_str (&tempbuf, ".");
    374  1.1  christos       obstack_grow_str (&tempbuf, object_name);
    375  1.1  christos     }
    376  1.1  christos   else
    377  1.1  christos     {
    378  1.1  christos       obstack_grow_str (&tempbuf, package_name);
    379  1.1  christos       obstack_grow_str (&tempbuf, ".");
    380  1.1  christos       obstack_grow_str (&tempbuf, object_name);
    381  1.1  christos     }
    382  1.1  christos   obstack_grow_str0 (&tempbuf, "");
    383  1.1  christos 
    384  1.1  christos   result = xstrdup (obstack_finish (&tempbuf));
    385  1.1  christos   obstack_free (&tempbuf, NULL);
    386  1.1  christos   xfree (name_buf);
    387  1.1  christos   return result;
    388  1.1  christos }
    389  1.1  christos 
    390  1.1  christos /* Given a Go symbol, return its package or NULL if unknown.
    391  1.1  christos    Space for the result is malloc'd, caller must free.  */
    392  1.1  christos 
    393  1.1  christos char *
    394  1.1  christos go_symbol_package_name (const struct symbol *sym)
    395  1.1  christos {
    396  1.1  christos   const char *mangled_name = SYMBOL_LINKAGE_NAME (sym);
    397  1.1  christos   const char *package_name;
    398  1.1  christos   const char *object_name;
    399  1.1  christos   const char *method_type_package_name;
    400  1.1  christos   const char *method_type_object_name;
    401  1.1  christos   int method_type_is_pointer;
    402  1.1  christos   char *name_buf;
    403  1.1  christos   char *result;
    404  1.1  christos 
    405  1.1  christos   gdb_assert (SYMBOL_LANGUAGE (sym) == language_go);
    406  1.1  christos   name_buf = unpack_mangled_go_symbol (mangled_name,
    407  1.1  christos 				       &package_name, &object_name,
    408  1.1  christos 				       &method_type_package_name,
    409  1.1  christos 				       &method_type_object_name,
    410  1.1  christos 				       &method_type_is_pointer);
    411  1.1  christos   /* Some Go symbols don't have mangled form we interpret (yet).  */
    412  1.1  christos   if (name_buf == NULL)
    413  1.1  christos     return NULL;
    414  1.1  christos   result = xstrdup (package_name);
    415  1.1  christos   xfree (name_buf);
    416  1.1  christos   return result;
    417  1.1  christos }
    418  1.1  christos 
    419  1.1  christos /* Return the package that BLOCK is in, or NULL if there isn't one.
    420  1.1  christos    Space for the result is malloc'd, caller must free.  */
    421  1.1  christos 
    422  1.1  christos char *
    423  1.1  christos go_block_package_name (const struct block *block)
    424  1.1  christos {
    425  1.1  christos   while (block != NULL)
    426  1.1  christos     {
    427  1.1  christos       struct symbol *function = BLOCK_FUNCTION (block);
    428  1.1  christos 
    429  1.1  christos       if (function != NULL)
    430  1.1  christos 	{
    431  1.1  christos 	  char *package_name = go_symbol_package_name (function);
    432  1.1  christos 
    433  1.1  christos 	  if (package_name != NULL)
    434  1.1  christos 	    return package_name;
    435  1.1  christos 
    436  1.1  christos 	  /* Stop looking if we find a function without a package name.
    437  1.1  christos 	     We're most likely outside of Go and thus the concept of the
    438  1.1  christos 	     "current" package is gone.  */
    439  1.1  christos 	  return NULL;
    440  1.1  christos 	}
    441  1.1  christos 
    442  1.1  christos       block = BLOCK_SUPERBLOCK (block);
    443  1.1  christos     }
    444  1.1  christos 
    445  1.1  christos   return NULL;
    446  1.1  christos }
    447  1.1  christos 
    448  1.1  christos /* Table mapping opcodes into strings for printing operators
    449  1.1  christos    and precedences of the operators.
    450  1.1  christos    TODO(dje): &^ ?  */
    451  1.1  christos 
    452  1.1  christos static const struct op_print go_op_print_tab[] =
    453  1.1  christos {
    454  1.1  christos   {",", BINOP_COMMA, PREC_COMMA, 0},
    455  1.1  christos   {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
    456  1.1  christos   {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
    457  1.1  christos   {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
    458  1.1  christos   {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
    459  1.1  christos   {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
    460  1.1  christos   {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
    461  1.1  christos   {"==", BINOP_EQUAL, PREC_EQUAL, 0},
    462  1.1  christos   {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
    463  1.1  christos   {"<=", BINOP_LEQ, PREC_ORDER, 0},
    464  1.1  christos   {">=", BINOP_GEQ, PREC_ORDER, 0},
    465  1.1  christos   {">", BINOP_GTR, PREC_ORDER, 0},
    466  1.1  christos   {"<", BINOP_LESS, PREC_ORDER, 0},
    467  1.1  christos   {">>", BINOP_RSH, PREC_SHIFT, 0},
    468  1.1  christos   {"<<", BINOP_LSH, PREC_SHIFT, 0},
    469  1.1  christos   {"+", BINOP_ADD, PREC_ADD, 0},
    470  1.1  christos   {"-", BINOP_SUB, PREC_ADD, 0},
    471  1.1  christos   {"*", BINOP_MUL, PREC_MUL, 0},
    472  1.1  christos   {"/", BINOP_DIV, PREC_MUL, 0},
    473  1.1  christos   {"%", BINOP_REM, PREC_MUL, 0},
    474  1.1  christos   {"@", BINOP_REPEAT, PREC_REPEAT, 0},
    475  1.1  christos   {"-", UNOP_NEG, PREC_PREFIX, 0},
    476  1.1  christos   {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
    477  1.1  christos   {"^", UNOP_COMPLEMENT, PREC_PREFIX, 0},
    478  1.1  christos   {"*", UNOP_IND, PREC_PREFIX, 0},
    479  1.1  christos   {"&", UNOP_ADDR, PREC_PREFIX, 0},
    480  1.1  christos   {"unsafe.Sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0},
    481  1.1  christos   {"++", UNOP_POSTINCREMENT, PREC_SUFFIX, 0},
    482  1.1  christos   {"--", UNOP_POSTDECREMENT, PREC_SUFFIX, 0},
    483  1.1  christos   {NULL, 0, 0, 0}
    484  1.1  christos };
    485  1.1  christos 
    486  1.1  christos enum go_primitive_types {
    487  1.1  christos   go_primitive_type_void,
    488  1.1  christos   go_primitive_type_char,
    489  1.1  christos   go_primitive_type_bool,
    490  1.1  christos   go_primitive_type_int,
    491  1.1  christos   go_primitive_type_uint,
    492  1.1  christos   go_primitive_type_uintptr,
    493  1.1  christos   go_primitive_type_int8,
    494  1.1  christos   go_primitive_type_int16,
    495  1.1  christos   go_primitive_type_int32,
    496  1.1  christos   go_primitive_type_int64,
    497  1.1  christos   go_primitive_type_uint8,
    498  1.1  christos   go_primitive_type_uint16,
    499  1.1  christos   go_primitive_type_uint32,
    500  1.1  christos   go_primitive_type_uint64,
    501  1.1  christos   go_primitive_type_float32,
    502  1.1  christos   go_primitive_type_float64,
    503  1.1  christos   go_primitive_type_complex64,
    504  1.1  christos   go_primitive_type_complex128,
    505  1.1  christos   nr_go_primitive_types
    506  1.1  christos };
    507  1.1  christos 
    508  1.1  christos static void
    509  1.1  christos go_language_arch_info (struct gdbarch *gdbarch,
    510  1.1  christos 		       struct language_arch_info *lai)
    511  1.1  christos {
    512  1.1  christos   const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
    513  1.1  christos 
    514  1.1  christos   lai->string_char_type = builtin->builtin_char;
    515  1.1  christos 
    516  1.1  christos   lai->primitive_type_vector
    517  1.1  christos     = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_go_primitive_types + 1,
    518  1.1  christos 			      struct type *);
    519  1.1  christos 
    520  1.1  christos   lai->primitive_type_vector [go_primitive_type_void]
    521  1.1  christos     = builtin->builtin_void;
    522  1.1  christos   lai->primitive_type_vector [go_primitive_type_char]
    523  1.1  christos     = builtin->builtin_char;
    524  1.1  christos   lai->primitive_type_vector [go_primitive_type_bool]
    525  1.1  christos     = builtin->builtin_bool;
    526  1.1  christos   lai->primitive_type_vector [go_primitive_type_int]
    527  1.1  christos     = builtin->builtin_int;
    528  1.1  christos   lai->primitive_type_vector [go_primitive_type_uint]
    529  1.1  christos     = builtin->builtin_uint;
    530  1.1  christos   lai->primitive_type_vector [go_primitive_type_uintptr]
    531  1.1  christos     = builtin->builtin_uintptr;
    532  1.1  christos   lai->primitive_type_vector [go_primitive_type_int8]
    533  1.1  christos     = builtin->builtin_int8;
    534  1.1  christos   lai->primitive_type_vector [go_primitive_type_int16]
    535  1.1  christos     = builtin->builtin_int16;
    536  1.1  christos   lai->primitive_type_vector [go_primitive_type_int32]
    537  1.1  christos     = builtin->builtin_int32;
    538  1.1  christos   lai->primitive_type_vector [go_primitive_type_int64]
    539  1.1  christos     = builtin->builtin_int64;
    540  1.1  christos   lai->primitive_type_vector [go_primitive_type_uint8]
    541  1.1  christos     = builtin->builtin_uint8;
    542  1.1  christos   lai->primitive_type_vector [go_primitive_type_uint16]
    543  1.1  christos     = builtin->builtin_uint16;
    544  1.1  christos   lai->primitive_type_vector [go_primitive_type_uint32]
    545  1.1  christos     = builtin->builtin_uint32;
    546  1.1  christos   lai->primitive_type_vector [go_primitive_type_uint64]
    547  1.1  christos     = builtin->builtin_uint64;
    548  1.1  christos   lai->primitive_type_vector [go_primitive_type_float32]
    549  1.1  christos     = builtin->builtin_float32;
    550  1.1  christos   lai->primitive_type_vector [go_primitive_type_float64]
    551  1.1  christos     = builtin->builtin_float64;
    552  1.1  christos   lai->primitive_type_vector [go_primitive_type_complex64]
    553  1.1  christos     = builtin->builtin_complex64;
    554  1.1  christos   lai->primitive_type_vector [go_primitive_type_complex128]
    555  1.1  christos     = builtin->builtin_complex128;
    556  1.1  christos 
    557  1.1  christos   lai->bool_type_symbol = "bool";
    558  1.1  christos   lai->bool_type_default = builtin->builtin_bool;
    559  1.1  christos }
    560  1.1  christos 
    561  1.1  christos static const struct language_defn go_language_defn =
    562  1.1  christos {
    563  1.1  christos   "go",
    564  1.1  christos   "Go",
    565  1.1  christos   language_go,
    566  1.1  christos   range_check_off,
    567  1.1  christos   case_sensitive_on,
    568  1.1  christos   array_row_major,
    569  1.1  christos   macro_expansion_no,
    570  1.1  christos   &exp_descriptor_c,
    571  1.1  christos   go_parse,
    572  1.1  christos   go_error,
    573  1.1  christos   null_post_parser,
    574  1.1  christos   c_printchar,			/* Print a character constant.  */
    575  1.1  christos   c_printstr,			/* Function to print string constant.  */
    576  1.1  christos   c_emit_char,			/* Print a single char.  */
    577  1.1  christos   go_print_type,		/* Print a type using appropriate syntax.  */
    578  1.1  christos   c_print_typedef,		/* Print a typedef using appropriate
    579  1.1  christos 				   syntax.  */
    580  1.1  christos   go_val_print,			/* Print a value using appropriate syntax.  */
    581  1.1  christos   c_value_print,		/* Print a top-level value.  */
    582  1.1  christos   default_read_var_value,	/* la_read_var_value */
    583  1.1  christos   NULL,				/* Language specific skip_trampoline.  */
    584  1.1  christos   NULL,				/* name_of_this */
    585  1.1  christos   basic_lookup_symbol_nonlocal,
    586  1.1  christos   basic_lookup_transparent_type,
    587  1.1  christos   go_demangle,			/* Language specific symbol demangler.  */
    588  1.1  christos   NULL,				/* Language specific
    589  1.1  christos 				   class_name_from_physname.  */
    590  1.1  christos   go_op_print_tab,		/* Expression operators for printing.  */
    591  1.1  christos   1,				/* C-style arrays.  */
    592  1.1  christos   0,				/* String lower bound.  */
    593  1.1  christos   default_word_break_characters,
    594  1.1  christos   default_make_symbol_completion_list,
    595  1.1  christos   go_language_arch_info,
    596  1.1  christos   default_print_array_index,
    597  1.1  christos   default_pass_by_reference,
    598  1.1  christos   c_get_string,
    599  1.1  christos   NULL,
    600  1.1  christos   iterate_over_symbols,
    601  1.1  christos   &default_varobj_ops,
    602  1.1  christos   LANG_MAGIC
    603  1.1  christos };
    604  1.1  christos 
    605  1.1  christos static void *
    606  1.1  christos build_go_types (struct gdbarch *gdbarch)
    607  1.1  christos {
    608  1.1  christos   struct builtin_go_type *builtin_go_type
    609  1.1  christos     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_go_type);
    610  1.1  christos 
    611  1.1  christos   builtin_go_type->builtin_void
    612  1.1  christos     = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
    613  1.1  christos   builtin_go_type->builtin_char
    614  1.1  christos     = arch_character_type (gdbarch, 8, 1, "char");
    615  1.1  christos   builtin_go_type->builtin_bool
    616  1.1  christos     = arch_boolean_type (gdbarch, 8, 0, "bool");
    617  1.1  christos   builtin_go_type->builtin_int
    618  1.1  christos     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "int");
    619  1.1  christos   builtin_go_type->builtin_uint
    620  1.1  christos     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "uint");
    621  1.1  christos   builtin_go_type->builtin_uintptr
    622  1.1  christos     = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr");
    623  1.1  christos   builtin_go_type->builtin_int8
    624  1.1  christos     = arch_integer_type (gdbarch, 8, 0, "int8");
    625  1.1  christos   builtin_go_type->builtin_int16
    626  1.1  christos     = arch_integer_type (gdbarch, 16, 0, "int16");
    627  1.1  christos   builtin_go_type->builtin_int32
    628  1.1  christos     = arch_integer_type (gdbarch, 32, 0, "int32");
    629  1.1  christos   builtin_go_type->builtin_int64
    630  1.1  christos     = arch_integer_type (gdbarch, 64, 0, "int64");
    631  1.1  christos   builtin_go_type->builtin_uint8
    632  1.1  christos     = arch_integer_type (gdbarch, 8, 1, "uint8");
    633  1.1  christos   builtin_go_type->builtin_uint16
    634  1.1  christos     = arch_integer_type (gdbarch, 16, 1, "uint16");
    635  1.1  christos   builtin_go_type->builtin_uint32
    636  1.1  christos     = arch_integer_type (gdbarch, 32, 1, "uint32");
    637  1.1  christos   builtin_go_type->builtin_uint64
    638  1.1  christos     = arch_integer_type (gdbarch, 64, 1, "uint64");
    639  1.1  christos   builtin_go_type->builtin_float32
    640  1.1  christos     = arch_float_type (gdbarch, 32, "float32", NULL);
    641  1.1  christos   builtin_go_type->builtin_float64
    642  1.1  christos     = arch_float_type (gdbarch, 64, "float64", NULL);
    643  1.1  christos   builtin_go_type->builtin_complex64
    644  1.1  christos     = arch_complex_type (gdbarch, "complex64",
    645  1.1  christos 			 builtin_go_type->builtin_float32);
    646  1.1  christos   builtin_go_type->builtin_complex128
    647  1.1  christos     = arch_complex_type (gdbarch, "complex128",
    648  1.1  christos 			 builtin_go_type->builtin_float64);
    649  1.1  christos 
    650  1.1  christos   return builtin_go_type;
    651  1.1  christos }
    652  1.1  christos 
    653  1.1  christos static struct gdbarch_data *go_type_data;
    654  1.1  christos 
    655  1.1  christos const struct builtin_go_type *
    656  1.1  christos builtin_go_type (struct gdbarch *gdbarch)
    657  1.1  christos {
    658  1.1  christos   return gdbarch_data (gdbarch, go_type_data);
    659  1.1  christos }
    660  1.1  christos 
    661  1.1  christos extern initialize_file_ftype _initialize_go_language;
    662  1.1  christos 
    663  1.1  christos void
    664  1.1  christos _initialize_go_language (void)
    665  1.1  christos {
    666  1.1  christos   go_type_data = gdbarch_data_register_post_init (build_go_types);
    667  1.1  christos 
    668  1.1  christos   add_language (&go_language_defn);
    669  1.1  christos }
    670