]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: fix 'remote show FOO-packet' aliases
authorAndrew Burgess <aburgess@redhat.com>
Thu, 21 Apr 2022 10:16:18 +0000 (11:16 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 21 Apr 2022 16:25:46 +0000 (17:25 +0100)
The following behaviour was observed in GDB:

  (gdb) show remote X-packet
  Support for the `p' packet is auto-detected, currently unknown.

Note the message mentions the 'p' packet.  This is a regression since
this commit:

  commit 8579fd136a614985bd27f20539c7bb7c5a51287d
  Date:   Mon Nov 8 14:58:46 2021 +0000

      gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr

Before this commit the behaviour was:

  (gdb) show remote X-packet
  Support for the `X' packet is auto-detected, currently unknown.

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.

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.

gdb/remote.c
gdb/testsuite/gdb.base/remote.exp

index 75d6bf3919d01cede8dd1d4c4830fb9053f7cb0c..562cc586f2bfe2d764a64fb228a1260888461ae6 100644 (file)
@@ -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<char> 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<gdb::unique_xmalloc_ptr<char>> legacy_names;
+      gdb::unique_xmalloc_ptr<char> legacy_name
        = 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));
     }
 }
 
index 1f0869433f2da8708dd74be231d1706e084e9614..579dcd40e5c18e02814c0ef24948c3e6d0d88a41 100644 (file)
@@ -195,4 +195,9 @@ gdb_test_no_output "set remote hardware-breakpoint-limit -1"
 gdb_test_no_output "set remote hardware-watchpoint-limit 2147483647"
 gdb_test_no_output "set remote hardware-breakpoint-limit 2147483647"
 
+# 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