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