On AArch64, even if the Guarded Control Stack feature is present on the
system the inferior may not have enabled it.
There's a bug in GDB's GCS support in that if the system supports GCS,
GDB will always push a GCS entry when doing an inferior function call
even if the inferior doesn't have it enabled. This causes inferior
function calls to fail. E.g.:
(gdb) p foo ()
Can't write to Guarded Control Stack.
The error message is because the GCSPR doesn't point to a valid memory
address.
Fix by checking whether GCS is enabled in the inferior before trying to
push a GCS entry.
Regression tested on an aarch64-linux-gnu QEMU VM with GCS present.
Approved-By: Luis Machado <luis.machado.foss@gmail.com>
aarch64_shadow_stack_push (gdbarch *gdbarch, CORE_ADDR new_addr,
regcache *regcache)
{
- aarch64_push_gcs_entry (regcache, new_addr);
+ bool gcs_is_enabled;
+
+ (void) gdbarch_get_shadow_stack_pointer (gdbarch, regcache, gcs_is_enabled);
+ if (gcs_is_enabled)
+ aarch64_push_gcs_entry (regcache, new_addr);
}
/* Implement the "push_dummy_call" gdbarch method. */