* [PATCH] [gdb/go] Handle v3 go_0 mangled prefix
@ 2023-10-05 14:50 Tom de Vries
2023-10-05 16:47 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2023-10-05 14:50 UTC (permalink / raw)
To: gdb-patches
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.
[1] https://go-review.googlesource.com/c/gofrontend/+/271726
[2] https://github.com/golang/go/issues/41862#issuecomment-707244103
---
gdb/go-lang.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 7561450b8e7..72ed9e73cd0 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -233,16 +233,28 @@ unpack_mangled_go_symbol (const char *mangled_name,
libgo_.*: used by gccgo's runtime
Thus we don't support -fgo-prefix (except as used by the runtime). */
- if (!startswith (mangled_name, "go.")
- && !startswith (mangled_name, "libgo_"))
+ 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
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;
+
/* It must have at least two dots. */
- first_dot = strchr (mangled_name, '.');
+ if (v3)
+ first_dot = strchr (mangled_name, '0');
+ else
+ first_dot = strchr (mangled_name, '.');
+
if (first_dot == NULL)
return NULL;
/* Treat "foo.bar" as unmangled. It can collide with lots of other
@@ -263,6 +275,18 @@ unpack_mangled_go_symbol (const char *mangled_name,
gdb::unique_xmalloc_ptr<char> result = make_unique_xstrdup (mangled_name);
buf = result.get ();
+ if (v3)
+ {
+ /* Replace "go_0" with "\0go.". */
+ buf[0] = '\0';
+ buf[1] = 'g';
+ buf[2] = 'o';
+ buf[3] = '.';
+
+ /* Skip the '\0'. */
+ buf++;
+ }
+
/* Search backwards looking for "N<digit(s)>". */
p = buf + len;
saw_digit = method_type = NULL;
base-commit: 8838ac1c9e05baa269fb50ebaa3318925b4df55b
--
2.35.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [gdb/go] Handle v3 go_0 mangled prefix
2023-10-05 14:50 [PATCH] [gdb/go] Handle v3 go_0 mangled prefix Tom de Vries
@ 2023-10-05 16:47 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-10-05 16:47 UTC (permalink / raw)
To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries
>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
Tom> A new v3 mangling scheme was used. The mangling schemes define a separator
Tom> character and mangling character:
Tom> - for v2, dot is used both as separator character and mangling character, and
Tom> - for v3, dot is used as separator character and underscore as mangling
Tom> character.
Tom> For more details, see [1] and [2].
Tom> In v3, "_0" demangles to ".". [ See gcc commit a01dda3c23b ("compiler, libgo:
Tom> change mangling scheme"), function Special_char_code::Special_char_code. ]
Tom> Handle the new go_0 prefix in unpack_mangled_go_symbol, which fixes the
Tom> test-case.
Looks good to me.
It took me a little while to realize that this:
Tom> gdb::unique_xmalloc_ptr<char> result = make_unique_xstrdup (mangled_name);
Tom> buf = result.get ();
...
Tom> + /* Skip the '\0'. */
Tom> + buf++;
... is ok, but it is because the callers only use the unique_xmalloc_ptr
to manage the memory, they don't examine the pointer directly.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-05 16:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-05 14:50 [PATCH] [gdb/go] Handle v3 go_0 mangled prefix Tom de Vries
2023-10-05 16:47 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).