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