From patchwork Tue Dec 3 19:59:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Barrett X-Patchwork-Id: 36483 Received: (qmail 112659 invoked by alias); 3 Dec 2019 19:59:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 112648 invoked by uid 89); 3 Dec 2019 19:59:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:server2, H*RU:sk:server2, HX-Spam-Relays-External:sk:server2, systemtap X-HELO: mail.bob131.so Received: from server2.bob131.so (HELO mail.bob131.so) (128.199.153.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Dec 2019 19:59:29 +0000 Received: from internal.mail.bob131.so (localhost [127.0.0.1]) by mail.bob131.so (Postfix) with ESMTP id 5B13E3FDC5 for ; Tue, 3 Dec 2019 19:59:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.bob131.so 5B13E3FDC5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bob131.so; s=default; t=1575403167; bh=rNUjN/tNxGjoGklPVtk6ISiZBEsxK730WWpHx2iPaG8=; h=Date:From:To:Subject:From; b=OtjnVOpPSoNAp5ofZ9d3Hsty0rJokwDeQ8j6PQlw3SRcu62/Cn7t1jfZFaPA0YV// lpMWsGDs/8fI1TDnaPKgVdE0e3g1LiXdUf+1pPRmMyPVrjlnk5W/LzLlDFupmSa5IC xgo11xo9K6ij5FDjlF/NiUFAbOHh62G0M96iOxaXB0zJCivlKyopyMypMpoEfITj5U GJO8zo0pkrc2Ap9vkg7SN92TwHE0DxELaKtF6+w/IX8JZZ0vlVeKjx4EUCqE4BMvTt 9+UM9yn92OmvXfxGUeH6JS8BOsJul64opYl8UatyDDOpxeBZgPcHCtM0bzF4u8kx6l Vx3i91IBu3+6w== Date: Wed, 4 Dec 2019 06:59:25 +1100 From: George Barrett To: gdb-patches@sourceware.org Subject: [PATCH] Fix handling of null stap semaphores Message-ID: <5we87igzwt5_kr.5b-38floyexzwmozuj6vb-.hmx8r4u3r41_sy@mail.bob131.so> MIME-Version: 1.0 Content-Disposition: inline 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); }