From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83286 invoked by alias); 30 Dec 2019 17:59:35 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 83276 invoked by uid 89); 30 Dec 2019 17:59:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=AWL,BAYES_00,NORMAL_HTTP_TO_IP,NUMERIC_HTTP_ADDR,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=UD:m, alpine, Alpine, pays X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Dec 2019 17:59:33 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8746A1E818; Mon, 30 Dec 2019 12:59:31 -0500 (EST) Subject: Re: [PATCH] Fix handling of null stap semaphores To: George Barrett Cc: gdb-patches@sourceware.org References: <5we87igzwt5_kr.5b-38floyexzwmozuj6vb-.hmx8r4u3r41_sy@mail.bob131.so> <63-043i577lrr0nz3p9q-864io50kubhf/q6&oul1hzd/xh4.u6c@mail.bob131.so> From: Simon Marchi Message-ID: <825af859-3594-5e29-9921-822f4193750a@simark.ca> Date: Mon, 30 Dec 2019 17:59:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <63-043i577lrr0nz3p9q-864io50kubhf/q6&oul1hzd/xh4.u6c@mail.bob131.so> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-12/txt/msg01076.txt.bz2 On 2019-12-30 10:38 a.m., George Barrett wrote: > On Sun, Dec 29, 2019 at 01:58:46PM -0500, Simon Marchi wrote: >> Though the ChangeLog should mention the modified functions, I propose to use >> this: >> >> * stap-probe.c (stap_modify_semaphore): Don't check for null >> semaphores. >> (stap_probe::set_semaphore, stap_probe::clear_semaphore): Check >> for null semaphores. > > Ack. > >> I'd really like if we could have a test for this, so that eventual refactors >> don't re-introduce this bug. Perhaps the gdb.base/stap-probe.exp test could >> be enhanced to test that the ELF magic number hasn't been changed? > > I was secretly hoping no-one would notice the absence of a test case ;) Yeah, I know writing a test case is not the most fun part, but it pays in the long run. I can help if you are not familiar enough with tcl/expect/dejagnu. >> One difficulty is finding out where it is, I don't know if there's a GDB >> command that will compute that directly. One way is to take the address of >> a global variable before and after starting the process, and see how it has >> been relocated, that would be the base of the image: >> >> (gdb) p &some_global >> $1 = (int *) 0x402c >> (gdb) start >> Temporary breakpoint 1 at 0x111d: file test.c, line 9. >> Starting program: /home/simark/src/aoc/08/p2/a.out >> >> Temporary breakpoint 1, main () at test.c:9 >> 9 for (i = 0; i < 1000; i++) { >> (gdb) p &some_global >> $2 = (int *) 0x55555555802c >> (gdb) p/x 0x55555555802c - 0x402c >> $3 = 0x555555554000 >> (gdb) p (*(char*) 0x555555554000)@4 >> $4 = "\177ELF" > > Is it too glibc-specific to use _r_debug? Something like the following: > > (gdb) start > Temporary breakpoint 1 at 0x4e60: file ../src/ls.c, line 1451. > Starting program: /usr/bin/ls > > Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd8d8) at ../src/ls.c:1451 > (gdb) p/x _r_debug.r_map->l_addr > $1 = 0x555555554000 > (gdb) p (*(char*) _r_debug.r_map->l_addr)@4 > $2 = "\177ELF" Hmm, it is not only glibc-specific (I believe?), but it also requires having glibc debug symbols installed. I just tried in an Alpine docker image (which uses musl), and the address subtraction method works. So between the two methods, I'd prefer the address subtraction, since it works on more libc's, and it works without debug info for the libc. Simon