[PING] [PATCH] Fix handling of null stap semaphores
George Barrett
bob@bob131.so
Wed Dec 18 17:20:00 GMT 2019
Ping
On Wed, Dec 04, 2019 at 06:59:25AM +1100, George Barrett wrote:
> According to the SystemTap documentation on user-space probes[0], stap
> probe points without semaphores are denoted by setting the semaphore
> address in the probe's note to zero. At present the code does do a
> comparison of the semaphore address against zero, but only after it's
> been relocated; as such it will (almost?) always fail, commonly
> resulting in GDB trying to overwrite the ELF magic located at the
> image's base address.
>
> This commit tests the address as specified in the SDT note rather than
> the relocated value in order to correctly detect absent probe
> semaphores.
>
> [0]: https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
>
> gdb/Changelog:
>
> * stap-probe.c: Fix handling of null stap semaphores
> ---
> gdb/stap-probe.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
> index ba927790a5..e5e3cceacd 100644
> --- a/gdb/stap-probe.c
> +++ b/gdb/stap-probe.c
> @@ -1425,9 +1425,6 @@ stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
> struct type *type = builtin_type (gdbarch)->builtin_unsigned_short;
> ULONGEST value;
>
> - if (address == 0)
> - return;
> -
> /* Swallow errors. */
> if (target_read_memory (address, bytes, TYPE_LENGTH (type)) != 0)
> {
> @@ -1461,6 +1458,8 @@ stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
> void
> stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
> {
> + if (m_sem_addr == 0)
> + return;
> stap_modify_semaphore (relocate_address (m_sem_addr, objfile), 1, gdbarch);
> }
>
> @@ -1469,6 +1468,8 @@ stap_probe::set_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
> void
> stap_probe::clear_semaphore (struct objfile *objfile, struct gdbarch *gdbarch)
> {
> + if (m_sem_addr == 0)
> + return;
> stap_modify_semaphore (relocate_address (m_sem_addr, objfile), 0, gdbarch);
> }
>
> --
> 2.23.0
More information about the Gdb-patches
mailing list