diff options
author | George Barrett <bob@bob131.so> | 2020-01-11 06:30:28 +1100 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2020-01-10 14:58:37 -0500 |
commit | 7f0ae84c80aae6fe8f7573343fe1ab455d18b5d8 (patch) | |
tree | 16de1a790fb014f27a7c09d634df9f5215961da3 /gdb/stap-probe.c | |
parent | 47e9d49d2d795224f4b3f04c89c268627b850be4 (diff) | |
download | gdb-7f0ae84c80aae6fe8f7573343fe1ab455d18b5d8.zip gdb-7f0ae84c80aae6fe8f7573343fe1ab455d18b5d8.tar.gz gdb-7f0ae84c80aae6fe8f7573343fe1ab455d18b5d8.tar.bz2 |
Fix handling of null stap semaphores
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:
2020-01-11 George Barrett <bob@bob131.so>
* stap-probe.c (stap_modify_semaphore): Don't check for null
semaphores.
(stap_probe::set_semaphore, stap_probe::clear_semaphore): Check
for null semaphores.
gdb/testsuite/ChangeLog:
2020-01-11 George Barrett <bob@bob131.so>
* gdb.base/stap-probe.c (relocation_marker): Add dummy variable
to help in finding the image relocation offset.
* gdb.base/stap-probe.exp (stap_test): Accept arbitrary compile
options in arguments.
(stap_test_no_debuginfo): Likewise.
(stap-probe-nosem-noopt-pie, stap-probe-nosem-noopt-nopie): Add
test variants.
(stap_test): Add null semaphore relocation test.
Diffstat (limited to 'gdb/stap-probe.c')
-rw-r--r-- | gdb/stap-probe.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index 5e9a043..50f6d51 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -1430,9 +1430,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) { @@ -1466,6 +1463,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); } @@ -1474,6 +1473,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); } |