From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 434923856DFA; Thu, 21 Apr 2022 16:26:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 434923856DFA Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb/gdb-12-branch] gdb: fix 'remote show FOO-packet' aliases X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/gdb-12-branch X-Git-Oldrev: f0072f79e12d88ca361de04a52434430a10c5f0e X-Git-Newrev: 3ab22dba1b7ef469b743e5606731ebc1169fbafa Message-Id: <20220421162632.434923856DFA@sourceware.org> Date: Thu, 21 Apr 2022 16:26:32 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2022 16:26:32 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3ab22dba1b7e= f469b743e5606731ebc1169fbafa commit 3ab22dba1b7ef469b743e5606731ebc1169fbafa Author: Andrew Burgess Date: Thu Apr 21 11:16:18 2022 +0100 gdb: fix 'remote show FOO-packet' aliases =20 The following behaviour was observed in GDB: =20 (gdb) show remote X-packet Support for the `p' packet is auto-detected, currently unknown. =20 Note the message mentions the 'p' packet. This is a regression since this commit: =20 commit 8579fd136a614985bd27f20539c7bb7c5a51287d Date: Mon Nov 8 14:58:46 2021 +0000 =20 gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_p= tr =20 Before this commit the behaviour was: =20 (gdb) show remote X-packet Support for the `X' packet is auto-detected, currently unknown. =20 The problem was caused by a failed attempt to ensure that some allocated strings were deleted when GDB exits. The code in the above commit attempted to make use of 'static' to solve this problem, however, the solution was just wrong. =20 In this new commit I instead allocate a static vector into which all the allocated strings are stored, this ensures the strings are released when GDB exits (which makes output from tools like valgrind cleaner), but each string within the vector can be unique, which fixes the regression. Diff: --- gdb/remote.c | 10 ++++++---- gdb/testsuite/gdb.base/remote.exp | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index aa6a67a96e0..1a34812a4b8 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1968,15 +1968,17 @@ add_packet_config_cmd (struct packet_config *config= , const char *name, /* set/show remote NAME-packet {auto,on,off} -- legacy. */ if (legacy) { - /* It's not clear who should take ownership of this string, so, for - now, make it static, and give copies to each of the add_alias_cmd - calls below. */ - static gdb::unique_xmalloc_ptr legacy_name + /* It's not clear who should take ownership of the LEGACY_NAME string + created below, so, for now, place the string into a static vector + which ensures the strings is released when GDB exits. */ + static std::vector> legacy_names; + gdb::unique_xmalloc_ptr legacy_name =3D xstrprintf ("%s-packet", name); add_alias_cmd (legacy_name.get (), cmds.set, class_obscure, 0, &remote_set_cmdlist); add_alias_cmd (legacy_name.get (), cmds.show, class_obscure, 0, &remote_show_cmdlist); + legacy_names.emplace_back (std::move (legacy_name)); } } =20 diff --git a/gdb/testsuite/gdb.base/remote.exp b/gdb/testsuite/gdb.base/rem= ote.exp index 1f0869433f2..579dcd40e5c 100644 --- a/gdb/testsuite/gdb.base/remote.exp +++ b/gdb/testsuite/gdb.base/remote.exp @@ -195,4 +195,9 @@ gdb_test_no_output "set remote hardware-breakpoint-limi= t -1" gdb_test_no_output "set remote hardware-watchpoint-limit 2147483647" gdb_test_no_output "set remote hardware-breakpoint-limit 2147483647" =20 +# Check the X/P/p alias commands display the correct packet names. +foreach pkt {X P p} { + gdb_test "show remote ${pkt}-packet" "Support for the `${pkt}' packet = is.*" +} + gdb_exit