]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdbserver: aarch64: Fix expedited registers list
authorThiago Jung Bauermann <thiago.bauermann@linaro.org>
Sun, 25 Aug 2024 23:34:13 +0000 (20:34 -0300)
committerThiago Jung Bauermann <thiago.bauermann@linaro.org>
Thu, 5 Sep 2024 04:02:51 +0000 (01:02 -0300)
Since this commit:

  commit a8651ef51822f91ec86d0d5caffbf2e50b174c23
  CommitDate: Fri Jun 14 14:47:38 2024 +0100

      gdb/aarch64: prevent crash from in process agent

gdbserver isn't sending expedited registers with its stop reply packets
anymore.  The problem is with how the constructor of the
expedited_registers std::vector is called:

The intent of the expedited_registers initialization in
aarch64_linux_read_description is to create a vector with capacity for 6
elements, but that's not how the std::vector constructor works.

Instead it creates a vector pre-populated with 6 elements initialized
with the default value for the type of the elements, and thus the first
6 elements are null pointers.  The actual expedited registers are added
starting at the 7th element.

This causes init_target_desc to consider that the expedite_regs list is
empty, since it stops checking at the first nullptr element.  The end
result is that gdbserver doesn't send any expedited registers to GDB in
its stop replies.

Fix by not specifying an element count when declaring the vector.

Tested for regressions on aarch64-linux-gnu native-extended-remote.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdbserver/linux-aarch64-tdesc.cc

index 5d3b6ddffffae9d1d0e64f618b46bc6dc78a62f1..31ec7854cc0bd1124ddb1c7954ee6f6964b2a134 100644 (file)
@@ -52,14 +52,10 @@ aarch64_linux_read_description (const aarch64_features &features)
     {
       tdesc = aarch64_create_target_description (features);
 
-      /* Configure the expedited registers.  By default we include x29, sp
-        and pc, but we allow for up to 6 pointers as this is (currently)
-        the most that we push.
-
-        Calling init_target_desc takes a copy of all the strings pointed
-        to by expedited_registers so this vector only needs to live for
-        the scope of this function.  */
-      std::vector<const char *> expedited_registers (6);
+      /* Configure the expedited registers.  Calling init_target_desc takes
+        a copy of all the strings pointed to by expedited_registers so this
+        vector only needs to live for the scope of this function.  */
+      std::vector<const char *> expedited_registers;
       expedited_registers.push_back ("x29");
       expedited_registers.push_back ("sp");
       expedited_registers.push_back ("pc");