1 /* Go language support definitions for GDB, the GNU debugger.
2 
3    Copyright (C) 2012-2021 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 #if !defined (GO_LANG_H)
21 #define GO_LANG_H 1
22 
23 struct type_print_options;
24 
25 #include "gdbtypes.h"
26 #include "symtab.h"
27 #include "value.h"
28 
29 struct parser_state;
30 
31 struct builtin_go_type
32 {
33   struct type *builtin_void;
34   struct type *builtin_char;
35   struct type *builtin_bool;
36   struct type *builtin_int;
37   struct type *builtin_uint;
38   struct type *builtin_uintptr;
39   struct type *builtin_int8;
40   struct type *builtin_int16;
41   struct type *builtin_int32;
42   struct type *builtin_int64;
43   struct type *builtin_uint8;
44   struct type *builtin_uint16;
45   struct type *builtin_uint32;
46   struct type *builtin_uint64;
47   struct type *builtin_float32;
48   struct type *builtin_float64;
49   struct type *builtin_complex64;
50   struct type *builtin_complex128;
51 };
52 
53 enum go_type
54 {
55   GO_TYPE_NONE, /* Not a Go object.  */
56   GO_TYPE_STRING
57 };
58 
59 /* Defined in go-lang.c.  */
60 
61 extern const char *go_main_name (void);
62 
63 extern enum go_type go_classify_struct_type (struct type *type);
64 
65 extern char *go_symbol_package_name (const struct symbol *sym);
66 
67 extern char *go_block_package_name (const struct block *block);
68 
69 extern const struct builtin_go_type *builtin_go_type (struct gdbarch *);
70 
71 /* Class representing the Go language.  */
72 
73 class go_language : public language_defn
74 {
75 public:
go_language()76   go_language ()
77     : language_defn (language_go)
78   { /* Nothing.  */ }
79 
80   /* See language.h.  */
81 
name()82   const char *name () const override
83   { return "go"; }
84 
85   /* See language.h.  */
86 
natural_name()87   const char *natural_name () const override
88   { return "Go"; }
89 
90   /* See language.h.  */
91 
92   void language_arch_info (struct gdbarch *gdbarch,
93 			   struct language_arch_info *lai) const override;
94 
95   /* See language.h.  */
96 
sniff_from_mangled_name(const char * mangled,char ** demangled)97   bool sniff_from_mangled_name (const char *mangled,
98 				char **demangled) const override
99   {
100     *demangled = demangle_symbol (mangled, 0);
101     return *demangled != NULL;
102   }
103 
104   /* See language.h.  */
105 
106   char *demangle_symbol (const char *mangled, int options) const override;
107 
108   /* See language.h.  */
109 
110   void print_type (struct type *type, const char *varstring,
111 		   struct ui_file *stream, int show, int level,
112 		   const struct type_print_options *flags) const override;
113 
114   /* See language.h.  */
115 
116   void value_print_inner
117 	(struct value *val, struct ui_file *stream, int recurse,
118 	 const struct value_print_options *options) const override;
119 
120   /* See language.h.  */
121 
122   int parser (struct parser_state *ps) const override;
123 
124   /* See language.h.  */
125 
is_string_type_p(struct type * type)126   bool is_string_type_p (struct type *type) const override
127   {
128     type = check_typedef (type);
129     return (type->code () == TYPE_CODE_STRUCT
130 	    && go_classify_struct_type (type) == GO_TYPE_STRING);
131   }
132 
133   /* See language.h.  */
134 
store_sym_names_in_linkage_form_p()135   bool store_sym_names_in_linkage_form_p () const override
136   { return true; }
137 };
138 
139 #endif /* !defined (GO_LANG_H) */
140