From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mcZxNrzC1WiDhBMAWB0awg (envelope-from ) for ; Thu, 25 Sep 2025 18:31:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1758839484; bh=NcsRU+lj0M3t6uAkNpY4C1+y407S+Mv9hTsGrPDRmko=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=sh7Wz3l42AMJXah67svlSJ9Pg+G6xiuDlkPN1PUrPGggQMU4ugGg2ldb14FCb7vGT xe9weTX78IphxS9RLXQ17gL2AXxzYal6bxWOL6Ii878lt5o3O8g5T7uFZRmos2IuAC x9BpxyUIBJwUVwZLmvExONnjkFbxF86rFttMHQ0c= Received: by simark.ca (Postfix, from userid 112) id C28591E0BA; Thu, 25 Sep 2025 18:31:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=RzB9u1Tx; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4506F1E04C for ; Thu, 25 Sep 2025 18:31:23 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A87113858424 for ; Thu, 25 Sep 2025 22:31:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A87113858424 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=RzB9u1Tx Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 8F5693858C98 for ; Thu, 25 Sep 2025 22:30:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F5693858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8F5693858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758839449; cv=none; b=Dvnrxy30lE6ziWBx8PHHsG1UVbUKEOfrR3vSwXXujdWdmeQc2YyX+b4FC6tE2RS5CWT3BdN/GTM6cZ+l+vPHpGpO8pxq0fYO4WPxr6h0xabcA/GUTA6ARd9lBEkmPSP0att6sy4lqNmNLXyNMjtWqhcBq2r+92DoYzdiRRKhTxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758839449; c=relaxed/simple; bh=NcsRU+lj0M3t6uAkNpY4C1+y407S+Mv9hTsGrPDRmko=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=uqYV8SoivhDjdX0wWta2QsPQ0OcwzEOTvD7QXwWh8gIedaKB7SC/0MJbvjK1pgkAkT+KPz6z5EAYk5Yn751onrkpAE3qlf8wlN39FGhFoH5Ph2zrC3+pHs57Brk8w3xzQcSYDRJgi0LJxVoaKxznU/8NTPvij3TZqGOV72f20h8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F5693858C98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1758839448; bh=NcsRU+lj0M3t6uAkNpY4C1+y407S+Mv9hTsGrPDRmko=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=RzB9u1Tx1B37/K5Hm6IfgA4kT4nPBkBgSYxKal09Ssf/NIHpLivTHP3lhoq/Q3l5a OFnSfBupuEfjjfF9S790nuCWgRtwmKo22VBecmgO1iQJ9DNyja5NCE7YqSNBnxLU6R zxfdhAiQrgdFpYPRl8R/pgogNMUCdLnF7akqN3V0= Received: by simark.ca (Postfix) id C57A61E04C; Thu, 25 Sep 2025 18:30:48 -0400 (EDT) Message-ID: <52d348d4-9069-4ea9-bcff-d1557855170c@simark.ca> Date: Thu, 25 Sep 2025 18:30:48 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: ensure bp_location::section is set correct to avoid an assert To: Andrew Burgess , =?UTF-8?Q?S=C3=A9bastien_Darche?= Cc: gdb-patches@sourceware.org References: <7febb0c1-7bbd-45d5-8ebe-91c34bb4a6ce@efficios.com> <87tt0qe7qf.fsf@redhat.com> <87ldm2dxcl.fsf@redhat.com> Content-Language: en-US From: Simon Marchi In-Reply-To: <87ldm2dxcl.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 2025-09-25 17:40, Andrew Burgess wrote: > Simon Marchi writes: > >> On 9/25/25 1:56 PM, Andrew Burgess wrote: >>> Part of the reason I'd push for a wider fix is that there are lots >>> different linespec formats, and I don't think they all pass through >>> minsym_found (or maybe they do?). >> >> It's certainly possble to create SALs without going through >> minsym_found. >> >>> If they don't then it feels like you should be able to adjust your >>> original test such that minsym_found isn't called, and you'll have the >>> same incorrect gdbarch problem. So then you'll have to add a >>> find_pc_section in _another_ place.... >> >> If the test was compiled with DWARF info, the SAL would be created from >> a full (DWARF) symbol, and we'd go through another path that would cause >> the section field to be set. I think find_function_start_sal -> >> find_function_start_sal_1. In this case the section would be known from >> the struct symbol. >> >> I went a bit down the overlay rabbit hole, and I think that your change >> might have broken that (but... I don't know how to test that). Here's >> the summary of my findings (I'm perhaps completely wrong). >> >> Two ELF sections overlay each other if they have the same VMA but >> different LMA. >> >> - LMA is the address where the code is permanently stored (e.g. large >> flash memory, non-executable). Unique for each section. >> - VMA is the address where the code gets copied when executed (e.g. >> small RAM, executable). >> >> An overlay manager in the program takes care of copying the right >> section from its LMA to its VMA before executing it. >> >> My understanding is that the ELF symbols for the various functions in >> these overlaying region have VMA region of memory. So, you would have >> overlapping ELF symbols, but you can know which ELF symbol is part of >> which section, because ELF symbols have a "section index" property. We >> record that in minimal_symbol::m_section. >> >> Before your patch, when seting a breakpoint by minimal symbol in an >> overlay situation, this: >> >> sal.section = msymbol->obj_section (objfile); >> >> would return the right section based on the minimal symbol you >> specified. I guess this is important later. To know if it should >> insert the breakpoint location, GDB must decide if the breakpoint >> location is in the section currently mapped at the VMA or not. For >> that, it needs to know in which section you intended to put the >> breakpoint. However, the new line: >> >> sal.section = find_pc_overlay (sal.pc); >> >> would return one of the multiple sections in which sal.pc (a VMA) >> appears, possibly the wrong one. This would mess up the "should we >> insert this location" logic later. > > That sounds reasonable enough. But the original code was still wrong I > think. > > I don't have time right now to reexamine the code I'm afraid, so I'm > going from memory a bit here. > > But in the ifunc case, I think MSYMBOL is the symbol from the resolver, > not the actual function where the breakpoint is being placed. Oh, absolutely. Your fix was correct for the ifunc case. We just need to find something that works for ifunc and overlays. > Maybe the answer is as simple as moving the .section assignment into the > earlier if block, something like: > > if (is_function && want_start_sal) > { > sal = find_function_start_sal (func_addr, NULL, self->funfirstline); > > /* This breakpoint is for the ifunc case, FUNC_ADDR is can be > anywhere, in a completely different section to MSYMBOL, or even > in a different objfile! > > TODO: I haven't checked, maybe find_function_start_sal already > fills this stuff in for us? Or maybe it could be made too? > For now I'm assuming all we have is an address, but this needs > checking. */ > sal.section = find_pc_overlay (func_addr); > if (sal.section == nullptr) > sal.section = find_pc_section (func_addr); > } > else > { > sal.objfile = objfile; > sal.msymbol = msymbol; > /* Store func_addr, not the minsym's address in case this was an > ifunc that hasn't been resolved yet. */ > if (is_function) > sal.pc = func_addr; > else > sal.pc = msymbol->value_address (objfile); > sal.pspace = current_program_space; > > /* We can assign the section based on MSYMBOL here because the > breakpoint is actually being placed at (or near) MSYMBOL. */ > sal.section = msymbol->obj_section (objfile); > } > > Now we retain the use of MSYMBOL where we can, which addresses the valid > issues you identify above. > > But we no longer use MSYMBOL when it's the wrong thing to do, which > addresses the problem I was trying to fix. Yeah, I was also thinking about something along those lines. Only look up the section if the func addr is different from the original minsym. Otherwise, you can trust the original minsym's section. Perhaps we can assume that it's not possible to have both ifuncs and overlays. I think that these are used in really different use cases (system with a full fledged dynamic linker vs embedded system with very constrained memory). > Does this look like a valid path forward maybe? > > FYI: I'm off work for a couple of days now, but will catch up when I > return. There was a test with my original change, so as long as that's > still passing I'm happy with whatever you think best. I'm officially off tomorrow as well, but Sébastien might chime in. Simon