From 43af2e08dc0af7796b557d14f13317c0c24f948a Mon Sep 17 00:00:00 2001 From: Thiago Jung Bauermann Date: Sun, 25 Aug 2024 20:34:13 -0300 Subject: [PATCH] gdbserver: aarch64: Fix expedited registers list 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 --- gdbserver/linux-aarch64-tdesc.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tdesc.cc index 5d3b6ddffff..31ec7854cc0 100644 --- a/gdbserver/linux-aarch64-tdesc.cc +++ b/gdbserver/linux-aarch64-tdesc.cc @@ -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 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 expedited_registers; expedited_registers.push_back ("x29"); expedited_registers.push_back ("sp"); expedited_registers.push_back ("pc"); -- 2.39.5