2012-04-25 22:07:23 +08:00
|
|
|
/* Go language support routines for GDB, the GNU debugger.
|
|
|
|
|
2024-01-12 23:30:44 +08:00
|
|
|
Copyright (C) 2012-2024 Free Software Foundation, Inc.
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
- split stacks
|
|
|
|
- printing of native types
|
|
|
|
- goroutines
|
|
|
|
- lots more
|
|
|
|
- gccgo mangling needs redoing
|
|
|
|
It's too hard, for example, to know whether one is looking at a mangled
|
|
|
|
Go symbol or not, and their are ambiguities, e.g., the demangler may
|
|
|
|
get passed *any* symbol, including symbols from other languages
|
|
|
|
and including symbols that are already demangled.
|
|
|
|
One thought is to at least add an _G prefix.
|
|
|
|
- 6g mangling isn't supported yet
|
|
|
|
*/
|
|
|
|
|
2021-12-22 07:38:32 +08:00
|
|
|
#include "gdbsupport/gdb_obstack.h"
|
2012-04-25 22:07:23 +08:00
|
|
|
#include "block.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "language.h"
|
2013-10-17 21:15:21 +08:00
|
|
|
#include "varobj.h"
|
2012-04-25 22:07:23 +08:00
|
|
|
#include "go-lang.h"
|
|
|
|
#include "c-lang.h"
|
|
|
|
#include "parser-defs.h"
|
Don't include gdbarch.h from defs.h
I touched symtab.h and was surprised to see how many files were
rebuilt. I looked into it a bit, and found that defs.h includes
gdbarch.h, which in turn includes many things.
gdbarch.h is only needed by a minority ofthe files in gdb, so this
patch removes the include from defs.h and updates the fallout.
I did "wc -l" on the files in build/gdb/.deps; this patch reduces the
line count from 139935 to 137030; so there are definitely future
build-time savings here.
Note that while I configured with --enable-targets=all, it's possible
that some *-nat.c file needs an update. I could not test all of
these. The buildbot caught a few problems along these lines.
gdb/ChangeLog
2019-07-10 Tom Tromey <tom@tromey.com>
* defs.h: Don't include gdbarch.h.
* aarch64-ravenscar-thread.c, aarch64-tdep.c, alpha-bsd-tdep.h,
alpha-linux-tdep.c, alpha-mdebug-tdep.c, arch-utils.h, arm-tdep.h,
ax-general.c, btrace.c, buildsym-legacy.c, buildsym.h, c-lang.c,
cli/cli-decode.h, cli/cli-dump.c, cli/cli-script.h,
cli/cli-style.h, coff-pe-read.h, compile/compile-c-support.c,
compile/compile-cplus.h, compile/compile-loc2c.c, corefile.c,
cp-valprint.c, cris-linux-tdep.c, ctf.c, d-lang.c, d-namespace.c,
dcache.c, dicos-tdep.c, dictionary.c, disasm-selftests.c,
dummy-frame.c, dummy-frame.h, dwarf2-frame-tailcall.c,
dwarf2expr.c, expression.h, f-lang.c, frame-base.c,
frame-unwind.c, frv-linux-tdep.c, gdbarch-selftests.c, gdbtypes.h,
go-lang.c, hppa-nbsd-tdep.c, hppa-obsd-tdep.c, i386-dicos-tdep.c,
i386-tdep.h, ia64-vms-tdep.c, interps.h, language.c,
linux-record.c, location.h, m2-lang.c, m32r-linux-tdep.c,
mem-break.c, memattr.c, mn10300-linux-tdep.c, nios2-linux-tdep.c,
objfiles.h, opencl-lang.c, or1k-linux-tdep.c, p-lang.c,
parser-defs.h, ppc-tdep.h, probe.h, python/py-record-btrace.c,
record-btrace.c, record.h, regcache-dump.c, regcache.h,
riscv-fbsd-tdep.c, riscv-linux-tdep.c, rust-exp.y,
sh-linux-tdep.c, sh-nbsd-tdep.c, source-cache.c,
sparc-nbsd-tdep.c, sparc-obsd-tdep.c, sparc-ravenscar-thread.c,
sparc64-fbsd-tdep.c, std-regs.c, target-descriptions.h,
target-float.c, tic6x-linux-tdep.c, tilegx-linux-tdep.c, top.c,
tracefile.c, trad-frame.c, type-stack.h, ui-style.c, utils.c,
utils.h, valarith.c, valprint.c, varobj.c, x86-tdep.c,
xml-support.h, xtensa-linux-tdep.c, cli/cli-cmds.h: Update.
* s390-linux-nat.c, procfs.c, inf-ptrace.c: Likewise.
2019-06-10 05:21:02 +08:00
|
|
|
#include "gdbarch.h"
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
/* The main function in the main package. */
|
|
|
|
static const char GO_MAIN_MAIN[] = "main.main";
|
|
|
|
|
|
|
|
/* Function returning the special symbol name used by Go for the main
|
|
|
|
procedure in the main program if it is found in minimal symbol list.
|
|
|
|
This function tries to find minimal symbols so that it finds them even
|
|
|
|
if the program was compiled without debugging information. */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
go_main_name (void)
|
|
|
|
{
|
use bound_minsym as result for lookup_minimal_symbol et al
This patch changes a few minimal symbol lookup functions to return a
bound_minimal_symbol rather than a pointer to the minsym. This change
helps prepare gdb for computing a minimal symbol's address at the
point of use.
Note that this changes even those functions that ostensibly search a
single objfile. That was necessary because, in fact, those functions
can search an objfile and its separate debug objfiles; and it is
important for the caller to know in which objfile the minimal symbol
was actually found.
The bulk of this patch is mechanical.
2014-02-26 Tom Tromey <tromey@redhat.com>
* ada-lang.c (ada_update_initial_language): Update.
(ada_main_name, ada_has_this_exception_support): Update.
* ada-tasks.c (ada_tasks_inferior_data_sniffer): Update.
* aix-thread.c (pdc_symbol_addrs, pd_enable): Update.
* arm-tdep.c (arm_skip_stub): Update.
* auxv.c (ld_so_xfer_auxv): Update.
* avr-tdep.c (avr_scan_prologue): Update.
* ax-gdb.c (gen_var_ref): Update.
* breakpoint.c (struct breakpoint_objfile_data)
<overlay_msym, longjmp_msym, terminate_msym, exception_msym>: Change
type to bound_minimal_symbol.
(create_overlay_event_breakpoint)
(create_longjmp_master_breakpoint)
(create_std_terminate_master_breakpoint)
(create_exception_master_breakpoint): Update.
* bsd-uthread.c (bsd_uthread_lookup_address): Update.
* c-exp.y (classify_name): Update.
* coffread.c (coff_symfile_read): Update.
* common/agent.c (agent_look_up_symbols): Update.
* d-lang.c (d_main_name): Update.
* dbxread.c (find_stab_function_addr, end_psymtab): Update.
* dec-thread.c (enable_dec_thread): Update.
* dwarf2loc.c (call_site_to_target_addr): Update.
* elfread.c (elf_gnu_ifunc_resolve_by_got): Update.
* eval.c (evaluate_subexp_standard): Update.
* findvar.c (struct minsym_lookup_data) <result>: Change type
to bound_minimal_symbol.
<objfile>: Remove.
(minsym_lookup_iterator_cb, default_read_var_value): Update.
* frame.c (inside_main_func): Update.
* frv-tdep.c (frv_frame_this_id): Update.
* gcore.c (call_target_sbrk): Update.
* glibc-tdep.c (glibc_skip_solib_resolver): Update.
* gnu-v3-abi.c (gnuv3_get_typeid, gnuv3_skip_trampoline):
Update.
* go-lang.c (go_main_name): Update.
* hppa-hpux-tdep.c (hppa_hpux_skip_trampoline_code)
(hppa_hpux_find_import_stub_for_addr): Update.
* hppa-tdep.c (hppa_extract_17, hppa_lookup_stub_minimal_symbol):
Update. Change return type.
* hppa-tdep.h (hppa_lookup_stub_minimal_symbol): Change return
type.
* jit.c (jit_breakpoint_re_set_internal): Update.
* linux-fork.c (inferior_call_waitpid, checkpoint_command):
Update.
* linux-nat.c (get_signo): Update.
* linux-thread-db.c (inferior_has_bug): Update
* m32c-tdep.c (m32c_return_value)
(m32c_m16c_address_to_pointer): Update.
* m32r-tdep.c (m32r_frame_this_id): Update.
* m68hc11-tdep.c (m68hc11_get_register_info): Update.
* machoread.c (macho_resolve_oso_sym_with_minsym): Update.
* minsyms.c (lookup_minimal_symbol_internal): Rename to
lookup_minimal_symbol. Change return type.
(lookup_minimal_symbol): Remove.
(lookup_bound_minimal_symbol): Update.
(lookup_minimal_symbol_text): Change return type.
(lookup_minimal_symbol_solib_trampoline): Change return type.
* minsyms.h (lookup_minimal_symbol, lookup_minimal_symbol_text)
(lookup_minimal_symbol_solib_trampoline): Change return type.
* mips-linux-tdep.c (mips_linux_skip_resolver): Update.
* objc-lang.c (lookup_objc_class, lookup_child_selector)
(value_nsstring, find_imps): Update.
* obsd-tdep.c (obsd_skip_solib_resolver): Update.
* p-lang.c (pascal_main_name): Update.
* ppc-linux-tdep.c (ppc_linux_spe_context_lookup): Update.
* ppc-sysv-tdep.c (convert_code_addr_to_desc_addr): Update.
* proc-service.c (ps_pglobal_lookup): Update.
* ravenscar-thread.c (get_running_thread_msymbol): Change
return type.
(has_ravenscar_runtime, get_running_thread_id): Update.
* remote.c (remote_check_symbols): Update.
* sol-thread.c (ps_pglobal_lookup): Update.
* sol2-tdep.c (sol2_skip_solib_resolver): Update.
* solib-dsbt.c (lm_base): Update.
* solib-frv.c (lm_base, frv_relocate_section_addresses):
Update.
* solib-irix.c (locate_base): Update.
* solib-som.c (som_solib_create_inferior_hook)
(som_solib_desire_dynamic_linker_symbols, link_map_start):
Update.
* solib-spu.c (spu_enable_break): Update.
* solib-svr4.c (elf_locate_base, enable_break): Update.
* spu-tdep.c (spu_get_overlay_table, spu_catch_start)
(flush_ea_cache): Update.
* stabsread.c (define_symbol): Update.
* symfile.c (simple_read_overlay_table): Update.
* symtab.c (find_pc_sect_line): Update.
* tracepoint.c (scope_info): Update.
* tui-disasm.c (tui_get_begin_asm_address): Update.
* value.c (value_static_field): Update.
2013-10-15 09:53:29 +08:00
|
|
|
struct bound_minimal_symbol msym;
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
msym = lookup_minimal_symbol (GO_MAIN_MAIN, NULL, NULL);
|
use bound_minsym as result for lookup_minimal_symbol et al
This patch changes a few minimal symbol lookup functions to return a
bound_minimal_symbol rather than a pointer to the minsym. This change
helps prepare gdb for computing a minimal symbol's address at the
point of use.
Note that this changes even those functions that ostensibly search a
single objfile. That was necessary because, in fact, those functions
can search an objfile and its separate debug objfiles; and it is
important for the caller to know in which objfile the minimal symbol
was actually found.
The bulk of this patch is mechanical.
2014-02-26 Tom Tromey <tromey@redhat.com>
* ada-lang.c (ada_update_initial_language): Update.
(ada_main_name, ada_has_this_exception_support): Update.
* ada-tasks.c (ada_tasks_inferior_data_sniffer): Update.
* aix-thread.c (pdc_symbol_addrs, pd_enable): Update.
* arm-tdep.c (arm_skip_stub): Update.
* auxv.c (ld_so_xfer_auxv): Update.
* avr-tdep.c (avr_scan_prologue): Update.
* ax-gdb.c (gen_var_ref): Update.
* breakpoint.c (struct breakpoint_objfile_data)
<overlay_msym, longjmp_msym, terminate_msym, exception_msym>: Change
type to bound_minimal_symbol.
(create_overlay_event_breakpoint)
(create_longjmp_master_breakpoint)
(create_std_terminate_master_breakpoint)
(create_exception_master_breakpoint): Update.
* bsd-uthread.c (bsd_uthread_lookup_address): Update.
* c-exp.y (classify_name): Update.
* coffread.c (coff_symfile_read): Update.
* common/agent.c (agent_look_up_symbols): Update.
* d-lang.c (d_main_name): Update.
* dbxread.c (find_stab_function_addr, end_psymtab): Update.
* dec-thread.c (enable_dec_thread): Update.
* dwarf2loc.c (call_site_to_target_addr): Update.
* elfread.c (elf_gnu_ifunc_resolve_by_got): Update.
* eval.c (evaluate_subexp_standard): Update.
* findvar.c (struct minsym_lookup_data) <result>: Change type
to bound_minimal_symbol.
<objfile>: Remove.
(minsym_lookup_iterator_cb, default_read_var_value): Update.
* frame.c (inside_main_func): Update.
* frv-tdep.c (frv_frame_this_id): Update.
* gcore.c (call_target_sbrk): Update.
* glibc-tdep.c (glibc_skip_solib_resolver): Update.
* gnu-v3-abi.c (gnuv3_get_typeid, gnuv3_skip_trampoline):
Update.
* go-lang.c (go_main_name): Update.
* hppa-hpux-tdep.c (hppa_hpux_skip_trampoline_code)
(hppa_hpux_find_import_stub_for_addr): Update.
* hppa-tdep.c (hppa_extract_17, hppa_lookup_stub_minimal_symbol):
Update. Change return type.
* hppa-tdep.h (hppa_lookup_stub_minimal_symbol): Change return
type.
* jit.c (jit_breakpoint_re_set_internal): Update.
* linux-fork.c (inferior_call_waitpid, checkpoint_command):
Update.
* linux-nat.c (get_signo): Update.
* linux-thread-db.c (inferior_has_bug): Update
* m32c-tdep.c (m32c_return_value)
(m32c_m16c_address_to_pointer): Update.
* m32r-tdep.c (m32r_frame_this_id): Update.
* m68hc11-tdep.c (m68hc11_get_register_info): Update.
* machoread.c (macho_resolve_oso_sym_with_minsym): Update.
* minsyms.c (lookup_minimal_symbol_internal): Rename to
lookup_minimal_symbol. Change return type.
(lookup_minimal_symbol): Remove.
(lookup_bound_minimal_symbol): Update.
(lookup_minimal_symbol_text): Change return type.
(lookup_minimal_symbol_solib_trampoline): Change return type.
* minsyms.h (lookup_minimal_symbol, lookup_minimal_symbol_text)
(lookup_minimal_symbol_solib_trampoline): Change return type.
* mips-linux-tdep.c (mips_linux_skip_resolver): Update.
* objc-lang.c (lookup_objc_class, lookup_child_selector)
(value_nsstring, find_imps): Update.
* obsd-tdep.c (obsd_skip_solib_resolver): Update.
* p-lang.c (pascal_main_name): Update.
* ppc-linux-tdep.c (ppc_linux_spe_context_lookup): Update.
* ppc-sysv-tdep.c (convert_code_addr_to_desc_addr): Update.
* proc-service.c (ps_pglobal_lookup): Update.
* ravenscar-thread.c (get_running_thread_msymbol): Change
return type.
(has_ravenscar_runtime, get_running_thread_id): Update.
* remote.c (remote_check_symbols): Update.
* sol-thread.c (ps_pglobal_lookup): Update.
* sol2-tdep.c (sol2_skip_solib_resolver): Update.
* solib-dsbt.c (lm_base): Update.
* solib-frv.c (lm_base, frv_relocate_section_addresses):
Update.
* solib-irix.c (locate_base): Update.
* solib-som.c (som_solib_create_inferior_hook)
(som_solib_desire_dynamic_linker_symbols, link_map_start):
Update.
* solib-spu.c (spu_enable_break): Update.
* solib-svr4.c (elf_locate_base, enable_break): Update.
* spu-tdep.c (spu_get_overlay_table, spu_catch_start)
(flush_ea_cache): Update.
* stabsread.c (define_symbol): Update.
* symfile.c (simple_read_overlay_table): Update.
* symtab.c (find_pc_sect_line): Update.
* tracepoint.c (scope_info): Update.
* tui-disasm.c (tui_get_begin_asm_address): Update.
* value.c (value_static_field): Update.
2013-10-15 09:53:29 +08:00
|
|
|
if (msym.minsym != NULL)
|
2012-04-25 22:07:23 +08:00
|
|
|
return GO_MAIN_MAIN;
|
|
|
|
|
|
|
|
/* No known entry procedure found, the main program is probably not Go. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return non-zero if TYPE is a gccgo string.
|
|
|
|
We assume CHECK_TYPEDEF has already been done. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
gccgo_string_p (struct type *type)
|
|
|
|
{
|
|
|
|
/* gccgo strings don't necessarily have a name we can use. */
|
|
|
|
|
2020-05-23 04:55:15 +08:00
|
|
|
if (type->num_fields () == 2)
|
2012-04-25 22:07:23 +08:00
|
|
|
{
|
2020-06-09 03:26:20 +08:00
|
|
|
struct type *type0 = type->field (0).type ();
|
|
|
|
struct type *type1 = type->field (1).type ();
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2015-07-07 04:05:06 +08:00
|
|
|
type0 = check_typedef (type0);
|
|
|
|
type1 = check_typedef (type1);
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2020-05-15 01:46:38 +08:00
|
|
|
if (type0->code () == TYPE_CODE_PTR
|
2021-08-30 23:49:49 +08:00
|
|
|
&& strcmp (type->field (0).name (), "__data") == 0
|
2020-05-15 01:46:38 +08:00
|
|
|
&& type1->code () == TYPE_CODE_INT
|
2021-08-30 23:49:49 +08:00
|
|
|
&& strcmp (type->field (1).name (), "__length") == 0)
|
2012-04-25 22:07:23 +08:00
|
|
|
{
|
2022-07-31 10:43:54 +08:00
|
|
|
struct type *target_type = type0->target_type ();
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2015-07-07 04:05:06 +08:00
|
|
|
target_type = check_typedef (target_type);
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2020-05-15 01:46:38 +08:00
|
|
|
if (target_type->code () == TYPE_CODE_INT
|
2022-09-21 23:05:21 +08:00
|
|
|
&& target_type->length () == 1
|
2020-05-17 00:16:06 +08:00
|
|
|
&& strcmp (target_type->name (), "uint8") == 0)
|
2012-04-25 22:07:23 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return non-zero if TYPE is a 6g string.
|
|
|
|
We assume CHECK_TYPEDEF has already been done. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
sixg_string_p (struct type *type)
|
|
|
|
{
|
2020-05-23 04:55:15 +08:00
|
|
|
if (type->num_fields () == 2
|
2020-05-17 00:16:06 +08:00
|
|
|
&& type->name () != NULL
|
|
|
|
&& strcmp (type->name (), "string") == 0)
|
2012-04-25 22:07:23 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Classify the kind of Go object that TYPE is.
|
|
|
|
TYPE is a TYPE_CODE_STRUCT, used to represent a Go object. */
|
|
|
|
|
|
|
|
enum go_type
|
|
|
|
go_classify_struct_type (struct type *type)
|
|
|
|
{
|
2015-07-07 04:05:06 +08:00
|
|
|
type = check_typedef (type);
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
/* Recognize strings as they're useful to be able to print without
|
|
|
|
pretty-printers. */
|
|
|
|
if (gccgo_string_p (type)
|
|
|
|
|| sixg_string_p (type))
|
|
|
|
return GO_TYPE_STRING;
|
|
|
|
|
|
|
|
return GO_TYPE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Subroutine of unpack_mangled_go_symbol to simplify it.
|
|
|
|
Given "[foo.]bar.baz", store "bar" in *PACKAGEP and "baz" in *OBJECTP.
|
|
|
|
We stomp on the last '.' to nul-terminate "bar".
|
|
|
|
The caller is responsible for memory management. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
unpack_package_and_object (char *buf,
|
|
|
|
const char **packagep, const char **objectp)
|
|
|
|
{
|
|
|
|
char *last_dot;
|
|
|
|
|
|
|
|
last_dot = strrchr (buf, '.');
|
|
|
|
gdb_assert (last_dot != NULL);
|
|
|
|
*objectp = last_dot + 1;
|
|
|
|
*last_dot = '\0';
|
|
|
|
last_dot = strrchr (buf, '.');
|
|
|
|
if (last_dot != NULL)
|
|
|
|
*packagep = last_dot + 1;
|
|
|
|
else
|
|
|
|
*packagep = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a mangled Go symbol, find its package name, object name, and
|
|
|
|
method type (if present).
|
|
|
|
E.g., for "libgo_net.textproto.String.N33_libgo_net.textproto.ProtocolError"
|
|
|
|
*PACKAGEP = "textproto"
|
|
|
|
*OBJECTP = "String"
|
|
|
|
*METHOD_TYPE_PACKAGEP = "textproto"
|
|
|
|
*METHOD_TYPE_OBJECTP = "ProtocolError"
|
|
|
|
|
|
|
|
Space for the resulting strings is malloc'd in one buffer.
|
|
|
|
PACKAGEP,OBJECTP,METHOD_TYPE* will (typically) point into this buffer.
|
|
|
|
A pointer to this buffer is returned, or NULL if symbol isn't a
|
|
|
|
mangled Go symbol.
|
|
|
|
|
|
|
|
*METHOD_TYPE_IS_POINTERP is set to a boolean indicating if
|
|
|
|
the method type is a pointer.
|
|
|
|
|
|
|
|
There may be value in returning the outer container,
|
|
|
|
i.e., "net" in the above example, but for now it's not needed.
|
|
|
|
Plus it's currently not straightforward to compute,
|
|
|
|
it comes from -fgo-prefix, and there's no algorithm to compute it.
|
|
|
|
|
|
|
|
If we ever need to unpack the method type, this routine should work
|
|
|
|
for that too. */
|
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
static gdb::unique_xmalloc_ptr<char>
|
2012-04-25 22:07:23 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
char *p;
|
|
|
|
int len = strlen (mangled_name);
|
|
|
|
/* Pointer to last digit in "N<digit(s)>_". */
|
|
|
|
char *saw_digit;
|
|
|
|
/* Pointer to "N" if valid "N<digit(s)>_" found. */
|
|
|
|
char *method_type;
|
|
|
|
/* Pointer to the first '.'. */
|
2015-10-14 02:40:50 +08:00
|
|
|
const char *first_dot;
|
2012-04-25 22:07:23 +08:00
|
|
|
/* Pointer to the last '.'. */
|
2015-10-14 02:40:50 +08:00
|
|
|
const char *last_dot;
|
2012-04-25 22:07:23 +08:00
|
|
|
/* Non-zero if we saw a pointer indicator. */
|
|
|
|
int saw_pointer;
|
|
|
|
|
|
|
|
*packagep = *objectp = NULL;
|
|
|
|
*method_type_packagep = *method_type_objectp = NULL;
|
|
|
|
*method_type_is_pointerp = 0;
|
|
|
|
|
|
|
|
/* main.init is mangled specially. */
|
|
|
|
if (strcmp (mangled_name, "__go_init_main") == 0)
|
|
|
|
{
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> package
|
|
|
|
= make_unique_xstrdup ("main");
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
*packagep = package.get ();
|
2012-04-25 22:07:23 +08:00
|
|
|
*objectp = "init";
|
|
|
|
return package;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main.main is mangled specially (missing prefix). */
|
|
|
|
if (strcmp (mangled_name, "main.main") == 0)
|
|
|
|
{
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> package
|
|
|
|
= make_unique_xstrdup ("main");
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
*packagep = package.get ();
|
2012-04-25 22:07:23 +08:00
|
|
|
*objectp = "main";
|
|
|
|
return package;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We may get passed, e.g., "main.T.Foo", which is *not* mangled.
|
|
|
|
Alas it looks exactly like "prefix.package.object."
|
|
|
|
To cope for now we only recognize the following prefixes:
|
|
|
|
|
|
|
|
go: the default
|
|
|
|
libgo_.*: used by gccgo's runtime
|
|
|
|
|
|
|
|
Thus we don't support -fgo-prefix (except as used by the runtime). */
|
[gdb/go] Handle v3 go_0 mangled prefix
With gcc-10 we have:
...
(gdb) break package2.Foo^M
Breakpoint 2 at 0x402563: file package2.go, line 5.^M
(gdb) PASS: gdb.go/package.exp: setting breakpoint 1
...
but with gcc-11:
...
gdb) break package2.Foo^M
Function "package2.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/package.exp: gdb_breakpoint: set breakpoint at package2.Foo
...
In the gcc-10 case, though the exec contains dwarf, it's not used to set the
breakpoint (which is an independent problem, filed as PR go/30941), instead
the minimal symbol information is used.
The minimal symbol information changed between gcc-10 and gcc-11:
...
$ nm a.out.10 | grep Foo
000000000040370d T go.package2.Foo
0000000000404e50 R go.package2.Foo..f
$ nm a.out.11 | grep Foo
0000000000403857 T go_0package2.Foo
0000000000405030 R go_0package2.Foo..f
...
A new v3 mangling scheme was used. The mangling schemes define a separator
character and mangling character:
- for v2, dot is used both as separator character and mangling character, and
- for v3, dot is used as separator character and underscore as mangling
character.
For more details, see [1] and [2].
In v3, "_0" demangles to ".". [ See gcc commit a01dda3c23b ("compiler, libgo:
change mangling scheme"), function Special_char_code::Special_char_code. ]
Handle the new go_0 prefix in unpack_mangled_go_symbol, which fixes the
test-case.
Note that this doesn't fix this regression:
...
$ gccgo-10 package2.go -c -g0
$ gccgo-10 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Breakpoint 1 at 0x40370d
$ gccgo-11 package2.go -c -g0
$ gccgo-11 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Function "go.package2.Foo" not defined.
...
With gcc-10, we set a breakpoint on the mangled minimal symbol. That
one has simply changed for gcc-11, so it's equivalent to using:
...
$ gdb -q -batch a.out -ex "break go_0package2.Foo"
Breakpoint 1 at 0x403857
...
which does work.
Tested on x86_64-linux:
- openSUSE Leap 15.4, using gccgo-7,
- openSUSE Tumbleweed, using gccgo-13.
PR go/27238
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27238
[1] https://go-review.googlesource.com/c/gofrontend/+/271726
[2] https://github.com/golang/go/issues/41862#issuecomment-707244103
2023-10-06 05:22:11 +08:00
|
|
|
bool v3;
|
|
|
|
if (startswith (mangled_name, "go_0"))
|
|
|
|
/* V3 mangling detected, see
|
|
|
|
https://go-review.googlesource.com/c/gofrontend/+/271726 . */
|
|
|
|
v3 = true;
|
|
|
|
else if (startswith (mangled_name, "go.")
|
|
|
|
|| startswith (mangled_name, "libgo_"))
|
|
|
|
v3 = false;
|
|
|
|
else
|
2012-04-25 22:07:23 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Quick check for whether a search may be fruitful. */
|
|
|
|
/* Ignore anything with @plt, etc. in it. */
|
|
|
|
if (strchr (mangled_name, '@') != NULL)
|
|
|
|
return NULL;
|
[gdb/go] Handle v3 go_0 mangled prefix
With gcc-10 we have:
...
(gdb) break package2.Foo^M
Breakpoint 2 at 0x402563: file package2.go, line 5.^M
(gdb) PASS: gdb.go/package.exp: setting breakpoint 1
...
but with gcc-11:
...
gdb) break package2.Foo^M
Function "package2.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/package.exp: gdb_breakpoint: set breakpoint at package2.Foo
...
In the gcc-10 case, though the exec contains dwarf, it's not used to set the
breakpoint (which is an independent problem, filed as PR go/30941), instead
the minimal symbol information is used.
The minimal symbol information changed between gcc-10 and gcc-11:
...
$ nm a.out.10 | grep Foo
000000000040370d T go.package2.Foo
0000000000404e50 R go.package2.Foo..f
$ nm a.out.11 | grep Foo
0000000000403857 T go_0package2.Foo
0000000000405030 R go_0package2.Foo..f
...
A new v3 mangling scheme was used. The mangling schemes define a separator
character and mangling character:
- for v2, dot is used both as separator character and mangling character, and
- for v3, dot is used as separator character and underscore as mangling
character.
For more details, see [1] and [2].
In v3, "_0" demangles to ".". [ See gcc commit a01dda3c23b ("compiler, libgo:
change mangling scheme"), function Special_char_code::Special_char_code. ]
Handle the new go_0 prefix in unpack_mangled_go_symbol, which fixes the
test-case.
Note that this doesn't fix this regression:
...
$ gccgo-10 package2.go -c -g0
$ gccgo-10 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Breakpoint 1 at 0x40370d
$ gccgo-11 package2.go -c -g0
$ gccgo-11 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Function "go.package2.Foo" not defined.
...
With gcc-10, we set a breakpoint on the mangled minimal symbol. That
one has simply changed for gcc-11, so it's equivalent to using:
...
$ gdb -q -batch a.out -ex "break go_0package2.Foo"
Breakpoint 1 at 0x403857
...
which does work.
Tested on x86_64-linux:
- openSUSE Leap 15.4, using gccgo-7,
- openSUSE Tumbleweed, using gccgo-13.
PR go/27238
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27238
[1] https://go-review.googlesource.com/c/gofrontend/+/271726
[2] https://github.com/golang/go/issues/41862#issuecomment-707244103
2023-10-06 05:22:11 +08:00
|
|
|
|
2012-04-25 22:07:23 +08:00
|
|
|
/* It must have at least two dots. */
|
[gdb/go] Handle v3 go_0 mangled prefix
With gcc-10 we have:
...
(gdb) break package2.Foo^M
Breakpoint 2 at 0x402563: file package2.go, line 5.^M
(gdb) PASS: gdb.go/package.exp: setting breakpoint 1
...
but with gcc-11:
...
gdb) break package2.Foo^M
Function "package2.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/package.exp: gdb_breakpoint: set breakpoint at package2.Foo
...
In the gcc-10 case, though the exec contains dwarf, it's not used to set the
breakpoint (which is an independent problem, filed as PR go/30941), instead
the minimal symbol information is used.
The minimal symbol information changed between gcc-10 and gcc-11:
...
$ nm a.out.10 | grep Foo
000000000040370d T go.package2.Foo
0000000000404e50 R go.package2.Foo..f
$ nm a.out.11 | grep Foo
0000000000403857 T go_0package2.Foo
0000000000405030 R go_0package2.Foo..f
...
A new v3 mangling scheme was used. The mangling schemes define a separator
character and mangling character:
- for v2, dot is used both as separator character and mangling character, and
- for v3, dot is used as separator character and underscore as mangling
character.
For more details, see [1] and [2].
In v3, "_0" demangles to ".". [ See gcc commit a01dda3c23b ("compiler, libgo:
change mangling scheme"), function Special_char_code::Special_char_code. ]
Handle the new go_0 prefix in unpack_mangled_go_symbol, which fixes the
test-case.
Note that this doesn't fix this regression:
...
$ gccgo-10 package2.go -c -g0
$ gccgo-10 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Breakpoint 1 at 0x40370d
$ gccgo-11 package2.go -c -g0
$ gccgo-11 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Function "go.package2.Foo" not defined.
...
With gcc-10, we set a breakpoint on the mangled minimal symbol. That
one has simply changed for gcc-11, so it's equivalent to using:
...
$ gdb -q -batch a.out -ex "break go_0package2.Foo"
Breakpoint 1 at 0x403857
...
which does work.
Tested on x86_64-linux:
- openSUSE Leap 15.4, using gccgo-7,
- openSUSE Tumbleweed, using gccgo-13.
PR go/27238
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27238
[1] https://go-review.googlesource.com/c/gofrontend/+/271726
[2] https://github.com/golang/go/issues/41862#issuecomment-707244103
2023-10-06 05:22:11 +08:00
|
|
|
if (v3)
|
|
|
|
first_dot = strchr (mangled_name, '0');
|
|
|
|
else
|
|
|
|
first_dot = strchr (mangled_name, '.');
|
|
|
|
|
2012-04-25 22:07:23 +08:00
|
|
|
if (first_dot == NULL)
|
|
|
|
return NULL;
|
|
|
|
/* Treat "foo.bar" as unmangled. It can collide with lots of other
|
|
|
|
languages and it's not clear what the consequences are.
|
|
|
|
And except for main.main, all gccgo symbols are at least
|
|
|
|
prefix.package.object. */
|
|
|
|
last_dot = strrchr (mangled_name, '.');
|
|
|
|
if (last_dot == first_dot)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* More quick checks. */
|
|
|
|
if (last_dot[1] == '\0' /* foo. */
|
|
|
|
|| last_dot[-1] == '.') /* foo..bar */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* At this point we've decided we have a mangled Go symbol. */
|
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> result = make_unique_xstrdup (mangled_name);
|
|
|
|
buf = result.get ();
|
2012-04-25 22:07:23 +08:00
|
|
|
|
[gdb/go] Handle v3 go_0 mangled prefix
With gcc-10 we have:
...
(gdb) break package2.Foo^M
Breakpoint 2 at 0x402563: file package2.go, line 5.^M
(gdb) PASS: gdb.go/package.exp: setting breakpoint 1
...
but with gcc-11:
...
gdb) break package2.Foo^M
Function "package2.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/package.exp: gdb_breakpoint: set breakpoint at package2.Foo
...
In the gcc-10 case, though the exec contains dwarf, it's not used to set the
breakpoint (which is an independent problem, filed as PR go/30941), instead
the minimal symbol information is used.
The minimal symbol information changed between gcc-10 and gcc-11:
...
$ nm a.out.10 | grep Foo
000000000040370d T go.package2.Foo
0000000000404e50 R go.package2.Foo..f
$ nm a.out.11 | grep Foo
0000000000403857 T go_0package2.Foo
0000000000405030 R go_0package2.Foo..f
...
A new v3 mangling scheme was used. The mangling schemes define a separator
character and mangling character:
- for v2, dot is used both as separator character and mangling character, and
- for v3, dot is used as separator character and underscore as mangling
character.
For more details, see [1] and [2].
In v3, "_0" demangles to ".". [ See gcc commit a01dda3c23b ("compiler, libgo:
change mangling scheme"), function Special_char_code::Special_char_code. ]
Handle the new go_0 prefix in unpack_mangled_go_symbol, which fixes the
test-case.
Note that this doesn't fix this regression:
...
$ gccgo-10 package2.go -c -g0
$ gccgo-10 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Breakpoint 1 at 0x40370d
$ gccgo-11 package2.go -c -g0
$ gccgo-11 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Function "go.package2.Foo" not defined.
...
With gcc-10, we set a breakpoint on the mangled minimal symbol. That
one has simply changed for gcc-11, so it's equivalent to using:
...
$ gdb -q -batch a.out -ex "break go_0package2.Foo"
Breakpoint 1 at 0x403857
...
which does work.
Tested on x86_64-linux:
- openSUSE Leap 15.4, using gccgo-7,
- openSUSE Tumbleweed, using gccgo-13.
PR go/27238
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27238
[1] https://go-review.googlesource.com/c/gofrontend/+/271726
[2] https://github.com/golang/go/issues/41862#issuecomment-707244103
2023-10-06 05:22:11 +08:00
|
|
|
if (v3)
|
|
|
|
{
|
|
|
|
/* Replace "go_0" with "\0go.". */
|
|
|
|
buf[0] = '\0';
|
|
|
|
buf[1] = 'g';
|
|
|
|
buf[2] = 'o';
|
|
|
|
buf[3] = '.';
|
|
|
|
|
|
|
|
/* Skip the '\0'. */
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
|
2012-04-25 22:07:23 +08:00
|
|
|
/* Search backwards looking for "N<digit(s)>". */
|
|
|
|
p = buf + len;
|
|
|
|
saw_digit = method_type = NULL;
|
|
|
|
saw_pointer = 0;
|
|
|
|
while (p > buf)
|
|
|
|
{
|
|
|
|
int current = *(const unsigned char *) --p;
|
|
|
|
int current_is_digit = isdigit (current);
|
|
|
|
|
|
|
|
if (saw_digit)
|
|
|
|
{
|
|
|
|
if (current_is_digit)
|
|
|
|
continue;
|
|
|
|
if (current == 'N'
|
|
|
|
&& ((p > buf && p[-1] == '.')
|
|
|
|
|| (p > buf + 1 && p[-1] == 'p' && p[-2] == '.')))
|
|
|
|
{
|
|
|
|
if (atoi (p + 1) == strlen (saw_digit + 2))
|
|
|
|
{
|
|
|
|
if (p[-1] == '.')
|
|
|
|
method_type = p - 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdb_assert (p[-1] == 'p');
|
|
|
|
saw_pointer = 1;
|
|
|
|
method_type = p - 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Not what we're looking for, reset and keep looking. */
|
|
|
|
saw_digit = NULL;
|
|
|
|
saw_pointer = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (current_is_digit && p[1] == '_')
|
|
|
|
{
|
|
|
|
/* Possible start of method "this" [sic] type. */
|
|
|
|
saw_digit = p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (method_type != NULL
|
|
|
|
/* Ensure not something like "..foo". */
|
|
|
|
&& (method_type > buf && method_type[-1] != '.'))
|
|
|
|
{
|
|
|
|
unpack_package_and_object (saw_digit + 2,
|
|
|
|
method_type_packagep, method_type_objectp);
|
|
|
|
*method_type = '\0';
|
|
|
|
*method_type_is_pointerp = saw_pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
unpack_package_and_object (buf, packagep, objectp);
|
2023-02-17 08:36:29 +08:00
|
|
|
return result;
|
2012-04-25 22:07:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements the la_demangle language_defn routine for language Go.
|
|
|
|
|
|
|
|
N.B. This may get passed *any* symbol, including symbols from other
|
|
|
|
languages and including symbols that are already demangled.
|
|
|
|
Both of these situations are kinda unfortunate, but that's how things
|
|
|
|
are today.
|
|
|
|
|
|
|
|
N.B. This currently only supports gccgo's mangling.
|
|
|
|
|
|
|
|
N.B. gccgo's mangling needs, I think, changing.
|
|
|
|
This demangler can't work in all situations,
|
|
|
|
thus not too much effort is currently put into it. */
|
|
|
|
|
2021-10-04 22:44:22 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char>
|
2020-10-20 21:03:42 +08:00
|
|
|
go_language::demangle_symbol (const char *mangled_name, int options) const
|
2012-04-25 22:07:23 +08:00
|
|
|
{
|
|
|
|
const char *package_name;
|
|
|
|
const char *object_name;
|
|
|
|
const char *method_type_package_name;
|
|
|
|
const char *method_type_object_name;
|
|
|
|
int method_type_is_pointer;
|
|
|
|
|
|
|
|
if (mangled_name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2021-10-04 22:44:22 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> name_buf
|
|
|
|
(unpack_mangled_go_symbol (mangled_name,
|
|
|
|
&package_name, &object_name,
|
|
|
|
&method_type_package_name,
|
|
|
|
&method_type_object_name,
|
|
|
|
&method_type_is_pointer));
|
2012-04-25 22:07:23 +08:00
|
|
|
if (name_buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2021-10-04 22:44:22 +08:00
|
|
|
auto_obstack tempbuf;
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
/* Print methods as they appear in "method expressions". */
|
|
|
|
if (method_type_package_name != NULL)
|
|
|
|
{
|
|
|
|
/* FIXME: Seems like we should include package_name here somewhere. */
|
|
|
|
if (method_type_is_pointer)
|
|
|
|
obstack_grow_str (&tempbuf, "(*");
|
|
|
|
obstack_grow_str (&tempbuf, method_type_package_name);
|
|
|
|
obstack_grow_str (&tempbuf, ".");
|
|
|
|
obstack_grow_str (&tempbuf, method_type_object_name);
|
|
|
|
if (method_type_is_pointer)
|
|
|
|
obstack_grow_str (&tempbuf, ")");
|
|
|
|
obstack_grow_str (&tempbuf, ".");
|
|
|
|
obstack_grow_str (&tempbuf, object_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
obstack_grow_str (&tempbuf, package_name);
|
|
|
|
obstack_grow_str (&tempbuf, ".");
|
|
|
|
obstack_grow_str (&tempbuf, object_name);
|
|
|
|
}
|
|
|
|
obstack_grow_str0 (&tempbuf, "");
|
|
|
|
|
2021-10-04 22:44:22 +08:00
|
|
|
return make_unique_xstrdup ((const char *) obstack_finish (&tempbuf));
|
2012-04-25 22:07:23 +08:00
|
|
|
}
|
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
/* See go-lang.h. */
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char>
|
2012-04-25 22:07:23 +08:00
|
|
|
go_symbol_package_name (const struct symbol *sym)
|
|
|
|
{
|
2019-11-23 02:05:14 +08:00
|
|
|
const char *mangled_name = sym->linkage_name ();
|
2012-04-25 22:07:23 +08:00
|
|
|
const char *package_name;
|
|
|
|
const char *object_name;
|
|
|
|
const char *method_type_package_name;
|
|
|
|
const char *method_type_object_name;
|
|
|
|
int method_type_is_pointer;
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> name_buf;
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2023-02-17 08:52:07 +08:00
|
|
|
if (sym->language () != language_go)
|
|
|
|
return nullptr;
|
2012-04-25 22:07:23 +08:00
|
|
|
name_buf = unpack_mangled_go_symbol (mangled_name,
|
|
|
|
&package_name, &object_name,
|
|
|
|
&method_type_package_name,
|
|
|
|
&method_type_object_name,
|
|
|
|
&method_type_is_pointer);
|
|
|
|
/* Some Go symbols don't have mangled form we interpret (yet). */
|
|
|
|
if (name_buf == NULL)
|
|
|
|
return NULL;
|
2023-02-17 08:36:29 +08:00
|
|
|
return make_unique_xstrdup (package_name);
|
2012-04-25 22:07:23 +08:00
|
|
|
}
|
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
/* See go-lang.h. */
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char>
|
2012-04-25 22:07:23 +08:00
|
|
|
go_block_package_name (const struct block *block)
|
|
|
|
{
|
|
|
|
while (block != NULL)
|
|
|
|
{
|
2022-01-29 00:19:50 +08:00
|
|
|
struct symbol *function = block->function ();
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
if (function != NULL)
|
|
|
|
{
|
2023-02-17 08:36:29 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> package_name
|
|
|
|
= go_symbol_package_name (function);
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
if (package_name != NULL)
|
|
|
|
return package_name;
|
|
|
|
|
|
|
|
/* Stop looking if we find a function without a package name.
|
|
|
|
We're most likely outside of Go and thus the concept of the
|
|
|
|
"current" package is gone. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-01-29 00:41:38 +08:00
|
|
|
block = block->superblock ();
|
2012-04-25 22:07:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
/* See language.h. */
|
gdb: Represent all languages as sub-classes of language_defn
This commit converts all languages to sub-classes of a language_defn
base class.
The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures. In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.
This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.
The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:
struct language_data
{
... old language_defn fields here ...
};
struct language_defn : public language_data
{
language_defn (const language_data d)
: language_data (d)
{ .... }
};
Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:
language_data ada_language_data =
{
... old ada_language_defn values here ...
};
struct ada_language : public language_defn
{
ada_language (ada_language_data)
{ .... }
};
What this means is that immediately after the conversion nothing much
changes. Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.
In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.
At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.
I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.
Most of the changes in the *-lang.c files are identical.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* gdb/ada-lang.c (ada_language_defn): Convert to...
(ada_language_data): ...this.
(class ada_language): New class.
(ada_language_defn): New static global.
* gdb/c-lang.c (c_language_defn): Convert to...
(c_language_data): ...this.
(class c_language): New class.
(c_language_defn): New static global.
(cplus_language_defn): Convert to...
(cplus_language_data): ...this.
(class cplus_language): New class.
(cplus_language_defn): New static global.
(asm_language_defn): Convert to...
(asm_language_data): ...this.
(class asm_language): New class.
(asm_language_defn): New static global.
(minimal_language_defn): Convert to...
(minimal_language_data): ...this.
(class minimal_language): New class.
(minimal_language_defn): New static global.
* gdb/d-lang.c (d_language_defn): Convert to...
(d_language_data): ...this.
(class d_language): New class.
(d_language_defn): New static global.
* gdb/f-lang.c (f_language_defn): Convert to...
(f_language_data): ...this.
(class f_language): New class.
(f_language_defn): New static global.
* gdb/go-lang.c (go_language_defn): Convert to...
(go_language_data): ...this.
(class go_language): New class.
(go_language_defn): New static global.
* gdb/language.c (unknown_language_defn): Remove declaration.
(current_language): Initialize to nullptr, real initialization is
moved to _initialize_language.
(languages): Delete global.
(language_defn::languages): Define.
(set_language_command): Use language_defn::languages.
(set_language): Likewise.
(range_error): Likewise.
(language_enum): Likewise.
(language_def): Likewise.
(add_set_language_command): Use language_def::languages for the
language list, and language_def to lookup language pointers.
(skip_language_trampoline): Use language_defn::languages.
(unknown_language_defn): Convert to...
(unknown_language_data): ...this.
(class unknown_language): New class.
(unknown_language_defn): New static global.
(auto_language_defn): Convert to...
(auto_language_data): ...this.
(class auto_language): New class.
(auto_language_defn): New static global.
(language_gdbarch_post_init): Use language_defn::languages.
(_initialize_language): Initialize current_language.
* gdb/language.h (struct language_defn): Rename to...
(struct language_data): ...this.
(struct language_defn): New.
(auto_language_defn): Delete.
(unknown_language_defn): Delete.
(minimal_language_defn): Delete.
(ada_language_defn): Delete.
(asm_language_defn): Delete.
(c_language_defn): Delete.
(cplus_language_defn): Delete.
(d_language_defn): Delete.
(f_language_defn): Delete.
(go_language_defn): Delete.
(m2_language_defn): Delete.
(objc_language_defn): Delete.
(opencl_language_defn): Delete.
(pascal_language_defn): Delete.
(rust_language_defn): Delete.
* gdb/m2-lang.c (m2_language_defn): Convert to...
(m2_language_data): ...this.
(class m2_language): New class.
(m2_language_defn): New static global.
* gdb/objc-lang.c (objc_language_defn): Convert to...
(objc_language_data): ...this.
(class objc_language): New class.
(objc_language_defn): New static global.
* gdb/opencl-lang.c (opencl_language_defn): Convert to...
(opencl_language_data): ...this.
(class opencl_language): New class.
(opencl_language_defn): New static global.
* gdb/p-lang.c (pascal_language_defn): Convert to...
(pascal_language_data): ...this.
(class pascal_language): New class.
(pascal_language_defn): New static global.
* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
language pointer, update comment format.
* gdb/rust-lang.c (rust_language_defn): Convert to...
(rust_language_data): ...this.
(class rust_language): New class.
(rust_language_defn): New static global.
2020-05-01 19:16:58 +08:00
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
void
|
|
|
|
go_language::language_arch_info (struct gdbarch *gdbarch,
|
|
|
|
struct language_arch_info *lai) const
|
gdb: Represent all languages as sub-classes of language_defn
This commit converts all languages to sub-classes of a language_defn
base class.
The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures. In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.
This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.
The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:
struct language_data
{
... old language_defn fields here ...
};
struct language_defn : public language_data
{
language_defn (const language_data d)
: language_data (d)
{ .... }
};
Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:
language_data ada_language_data =
{
... old ada_language_defn values here ...
};
struct ada_language : public language_defn
{
ada_language (ada_language_data)
{ .... }
};
What this means is that immediately after the conversion nothing much
changes. Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.
In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.
At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.
I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.
Most of the changes in the *-lang.c files are identical.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* gdb/ada-lang.c (ada_language_defn): Convert to...
(ada_language_data): ...this.
(class ada_language): New class.
(ada_language_defn): New static global.
* gdb/c-lang.c (c_language_defn): Convert to...
(c_language_data): ...this.
(class c_language): New class.
(c_language_defn): New static global.
(cplus_language_defn): Convert to...
(cplus_language_data): ...this.
(class cplus_language): New class.
(cplus_language_defn): New static global.
(asm_language_defn): Convert to...
(asm_language_data): ...this.
(class asm_language): New class.
(asm_language_defn): New static global.
(minimal_language_defn): Convert to...
(minimal_language_data): ...this.
(class minimal_language): New class.
(minimal_language_defn): New static global.
* gdb/d-lang.c (d_language_defn): Convert to...
(d_language_data): ...this.
(class d_language): New class.
(d_language_defn): New static global.
* gdb/f-lang.c (f_language_defn): Convert to...
(f_language_data): ...this.
(class f_language): New class.
(f_language_defn): New static global.
* gdb/go-lang.c (go_language_defn): Convert to...
(go_language_data): ...this.
(class go_language): New class.
(go_language_defn): New static global.
* gdb/language.c (unknown_language_defn): Remove declaration.
(current_language): Initialize to nullptr, real initialization is
moved to _initialize_language.
(languages): Delete global.
(language_defn::languages): Define.
(set_language_command): Use language_defn::languages.
(set_language): Likewise.
(range_error): Likewise.
(language_enum): Likewise.
(language_def): Likewise.
(add_set_language_command): Use language_def::languages for the
language list, and language_def to lookup language pointers.
(skip_language_trampoline): Use language_defn::languages.
(unknown_language_defn): Convert to...
(unknown_language_data): ...this.
(class unknown_language): New class.
(unknown_language_defn): New static global.
(auto_language_defn): Convert to...
(auto_language_data): ...this.
(class auto_language): New class.
(auto_language_defn): New static global.
(language_gdbarch_post_init): Use language_defn::languages.
(_initialize_language): Initialize current_language.
* gdb/language.h (struct language_defn): Rename to...
(struct language_data): ...this.
(struct language_defn): New.
(auto_language_defn): Delete.
(unknown_language_defn): Delete.
(minimal_language_defn): Delete.
(ada_language_defn): Delete.
(asm_language_defn): Delete.
(c_language_defn): Delete.
(cplus_language_defn): Delete.
(d_language_defn): Delete.
(f_language_defn): Delete.
(go_language_defn): Delete.
(m2_language_defn): Delete.
(objc_language_defn): Delete.
(opencl_language_defn): Delete.
(pascal_language_defn): Delete.
(rust_language_defn): Delete.
* gdb/m2-lang.c (m2_language_defn): Convert to...
(m2_language_data): ...this.
(class m2_language): New class.
(m2_language_defn): New static global.
* gdb/objc-lang.c (objc_language_defn): Convert to...
(objc_language_data): ...this.
(class objc_language): New class.
(objc_language_defn): New static global.
* gdb/opencl-lang.c (opencl_language_defn): Convert to...
(opencl_language_data): ...this.
(class opencl_language): New class.
(opencl_language_defn): New static global.
* gdb/p-lang.c (pascal_language_defn): Convert to...
(pascal_language_data): ...this.
(class pascal_language): New class.
(pascal_language_defn): New static global.
* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
language pointer, update comment format.
* gdb/rust-lang.c (rust_language_defn): Convert to...
(rust_language_data): ...this.
(class rust_language): New class.
(rust_language_defn): New static global.
2020-05-01 19:16:58 +08:00
|
|
|
{
|
2020-10-20 21:03:42 +08:00
|
|
|
const struct builtin_go_type *builtin = builtin_go_type (gdbarch);
|
2020-05-15 02:03:45 +08:00
|
|
|
|
2020-10-20 21:03:42 +08:00
|
|
|
/* Helper function to allow shorter lines below. */
|
|
|
|
auto add = [&] (struct type * t) -> struct type *
|
2020-05-15 01:41:39 +08:00
|
|
|
{
|
2020-10-20 21:03:42 +08:00
|
|
|
lai->add_primitive_type (t);
|
|
|
|
return t;
|
|
|
|
};
|
|
|
|
|
|
|
|
add (builtin->builtin_void);
|
|
|
|
add (builtin->builtin_char);
|
|
|
|
add (builtin->builtin_bool);
|
|
|
|
add (builtin->builtin_int);
|
|
|
|
add (builtin->builtin_uint);
|
|
|
|
add (builtin->builtin_uintptr);
|
|
|
|
add (builtin->builtin_int8);
|
|
|
|
add (builtin->builtin_int16);
|
|
|
|
add (builtin->builtin_int32);
|
|
|
|
add (builtin->builtin_int64);
|
|
|
|
add (builtin->builtin_uint8);
|
|
|
|
add (builtin->builtin_uint16);
|
|
|
|
add (builtin->builtin_uint32);
|
|
|
|
add (builtin->builtin_uint64);
|
|
|
|
add (builtin->builtin_float32);
|
|
|
|
add (builtin->builtin_float64);
|
|
|
|
add (builtin->builtin_complex64);
|
|
|
|
add (builtin->builtin_complex128);
|
|
|
|
|
|
|
|
lai->set_string_char_type (builtin->builtin_char);
|
|
|
|
lai->set_bool_type (builtin->builtin_bool, "bool");
|
|
|
|
}
|
gdb: Represent all languages as sub-classes of language_defn
This commit converts all languages to sub-classes of a language_defn
base class.
The motivation for this change is to make it easier to add new methods
onto languages without having to update all of the individual language
structures. In the future it might be possible to move more things,
like expression parsing, into the language class(es) for better
encapsulation, however I have no plans to tackle this in the short
term.
This commit sets up a strategy for transitioning from the current
language system, where each language is an instance of the
language_defn structure, to the class hierarchy system.
The plan is to rename the existing language_defn into language_data,
and make this a base class for the new language_defn class, something
like this:
struct language_data
{
... old language_defn fields here ...
};
struct language_defn : public language_data
{
language_defn (const language_data d)
: language_data (d)
{ .... }
};
Then each existing language, for example ada_language_defn can be
converted into an instance of language_data, and passed into the
constructor of a new language class, something like this:
language_data ada_language_data =
{
... old ada_language_defn values here ...
};
struct ada_language : public language_defn
{
ada_language (ada_language_data)
{ .... }
};
What this means is that immediately after the conversion nothing much
changes. Every language is now its own class, but all the old
language fields still exist and can be accessed in the same way.
In later commits I will convert function pointers from the old
language_defn structure into real class methods on language_defn, with
overrides on sub-classes where needed.
At this point I imagine that those fields of the old language_defn
structure that contained only data will probably remain as data fields
within the new language_data base structure, it is only the methods
that I plan to change initially.
I tweaked how we manage the list of languages a bit, each language is
now registered as it is created, and this resulted in a small number
of changes in language.c.
Most of the changes in the *-lang.c files are identical.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* gdb/ada-lang.c (ada_language_defn): Convert to...
(ada_language_data): ...this.
(class ada_language): New class.
(ada_language_defn): New static global.
* gdb/c-lang.c (c_language_defn): Convert to...
(c_language_data): ...this.
(class c_language): New class.
(c_language_defn): New static global.
(cplus_language_defn): Convert to...
(cplus_language_data): ...this.
(class cplus_language): New class.
(cplus_language_defn): New static global.
(asm_language_defn): Convert to...
(asm_language_data): ...this.
(class asm_language): New class.
(asm_language_defn): New static global.
(minimal_language_defn): Convert to...
(minimal_language_data): ...this.
(class minimal_language): New class.
(minimal_language_defn): New static global.
* gdb/d-lang.c (d_language_defn): Convert to...
(d_language_data): ...this.
(class d_language): New class.
(d_language_defn): New static global.
* gdb/f-lang.c (f_language_defn): Convert to...
(f_language_data): ...this.
(class f_language): New class.
(f_language_defn): New static global.
* gdb/go-lang.c (go_language_defn): Convert to...
(go_language_data): ...this.
(class go_language): New class.
(go_language_defn): New static global.
* gdb/language.c (unknown_language_defn): Remove declaration.
(current_language): Initialize to nullptr, real initialization is
moved to _initialize_language.
(languages): Delete global.
(language_defn::languages): Define.
(set_language_command): Use language_defn::languages.
(set_language): Likewise.
(range_error): Likewise.
(language_enum): Likewise.
(language_def): Likewise.
(add_set_language_command): Use language_def::languages for the
language list, and language_def to lookup language pointers.
(skip_language_trampoline): Use language_defn::languages.
(unknown_language_defn): Convert to...
(unknown_language_data): ...this.
(class unknown_language): New class.
(unknown_language_defn): New static global.
(auto_language_defn): Convert to...
(auto_language_data): ...this.
(class auto_language): New class.
(auto_language_defn): New static global.
(language_gdbarch_post_init): Use language_defn::languages.
(_initialize_language): Initialize current_language.
* gdb/language.h (struct language_defn): Rename to...
(struct language_data): ...this.
(struct language_defn): New.
(auto_language_defn): Delete.
(unknown_language_defn): Delete.
(minimal_language_defn): Delete.
(ada_language_defn): Delete.
(asm_language_defn): Delete.
(c_language_defn): Delete.
(cplus_language_defn): Delete.
(d_language_defn): Delete.
(f_language_defn): Delete.
(go_language_defn): Delete.
(m2_language_defn): Delete.
(objc_language_defn): Delete.
(opencl_language_defn): Delete.
(pascal_language_defn): Delete.
(rust_language_defn): Delete.
* gdb/m2-lang.c (m2_language_defn): Convert to...
(m2_language_data): ...this.
(class m2_language): New class.
(m2_language_defn): New static global.
* gdb/objc-lang.c (objc_language_defn): Convert to...
(objc_language_data): ...this.
(class objc_language): New class.
(objc_language_defn): New static global.
* gdb/opencl-lang.c (opencl_language_defn): Convert to...
(opencl_language_data): ...this.
(class opencl_language): New class.
(opencl_language_defn): New static global.
* gdb/p-lang.c (pascal_language_defn): Convert to...
(pascal_language_data): ...this.
(class pascal_language): New class.
(pascal_language_defn): New static global.
* gdb/rust-exp.y (rust_lex_tests): Use language_def to find
language pointer, update comment format.
* gdb/rust-lang.c (rust_language_defn): Convert to...
(rust_language_data): ...this.
(class rust_language): New class.
(rust_language_defn): New static global.
2020-05-01 19:16:58 +08:00
|
|
|
|
|
|
|
/* Single instance of the Go language class. */
|
|
|
|
|
|
|
|
static go_language go_language_defn;
|
|
|
|
|
2022-06-02 05:31:15 +08:00
|
|
|
static struct builtin_go_type *
|
2012-04-25 22:07:23 +08:00
|
|
|
build_go_types (struct gdbarch *gdbarch)
|
|
|
|
{
|
2022-06-02 05:31:15 +08:00
|
|
|
struct builtin_go_type *builtin_go_type = new struct builtin_go_type;
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2023-03-14 00:31:06 +08:00
|
|
|
type_allocator alloc (gdbarch);
|
2023-03-13 23:31:13 +08:00
|
|
|
builtin_go_type->builtin_void = builtin_type (gdbarch)->builtin_void;
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_char
|
2023-03-14 00:57:56 +08:00
|
|
|
= init_character_type (alloc, 8, 1, "char");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_bool
|
2023-03-14 01:09:08 +08:00
|
|
|
= init_boolean_type (alloc, 8, 0, "bool");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_int
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, gdbarch_int_bit (gdbarch), 0, "int");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_uint
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, gdbarch_int_bit (gdbarch), 1, "uint");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_uintptr
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, gdbarch_ptr_bit (gdbarch), 1, "uintptr");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_int8
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 8, 0, "int8");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_int16
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 16, 0, "int16");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_int32
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 32, 0, "int32");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_int64
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 64, 0, "int64");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_uint8
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 8, 1, "uint8");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_uint16
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 16, 1, "uint16");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_uint32
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 32, 1, "uint32");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_uint64
|
2023-03-14 00:31:06 +08:00
|
|
|
= init_integer_type (alloc, 64, 1, "uint64");
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_float32
|
2023-03-14 01:30:08 +08:00
|
|
|
= init_float_type (alloc, 32, "float32", floatformats_ieee_single);
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_float64
|
2023-03-14 01:30:08 +08:00
|
|
|
= init_float_type (alloc, 64, "float64", floatformats_ieee_double);
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_complex64
|
2020-04-02 04:09:52 +08:00
|
|
|
= init_complex_type ("complex64", builtin_go_type->builtin_float32);
|
2012-04-25 22:07:23 +08:00
|
|
|
builtin_go_type->builtin_complex128
|
2020-04-02 04:09:52 +08:00
|
|
|
= init_complex_type ("complex128", builtin_go_type->builtin_float64);
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
return builtin_go_type;
|
|
|
|
}
|
|
|
|
|
2022-06-02 05:31:15 +08:00
|
|
|
static const registry<gdbarch>::key<struct builtin_go_type> go_type_data;
|
2012-04-25 22:07:23 +08:00
|
|
|
|
|
|
|
const struct builtin_go_type *
|
|
|
|
builtin_go_type (struct gdbarch *gdbarch)
|
|
|
|
{
|
2022-06-02 05:31:15 +08:00
|
|
|
struct builtin_go_type *result = go_type_data.get (gdbarch);
|
|
|
|
if (result == nullptr)
|
|
|
|
{
|
|
|
|
result = build_go_types (gdbarch);
|
|
|
|
go_type_data.set (gdbarch, result);
|
|
|
|
}
|
2012-04-25 22:07:23 +08:00
|
|
|
|
2022-06-02 05:31:15 +08:00
|
|
|
return result;
|
2012-04-25 22:07:23 +08:00
|
|
|
}
|