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