From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id F009D3851C2C for ; Sun, 20 Sep 2020 21:08:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F009D3851C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (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 55AE31EF4D; Sun, 20 Sep 2020 17:08:41 -0400 (EDT) Subject: Re: [PATCH 2/2] gdb: handle unmapped overlays in find_pc_line To: Andrew Burgess , gdb-patches@sourceware.org References: From: Simon Marchi Message-ID: Date: Sun, 20 Sep 2020 17:08:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Sep 2020 21:08:43 -0000 On 2020-09-18 2:17 p.m., Andrew Burgess wrote: > I configured and build an m32r-elf toolchain, and ran the build -> built > gdb.base/overlays.exp test. I saw a couple of errors where GDB would > place a breakpoint in the wrong place when placing a breakpoint using > a function name, for example in this function: > > /* 1 */ int foo (int x) > /* 2 */ { > /* 3 */ if (x) > /* 4 */ return foox; "foox" or "x"? > /* 5 */ else > /* 6 */ return 0; > /* 7 */ } > > GDB would place the breakpoint on line 2 instead of line 3. The issue > is that GDB was failing to skip the prologue correctly. > > The reason for this is that in m32r-tdep.c:m32r_skip_prologue, we > first use find_pc_partial_function to find the functions start and end > addresses, then we use find_pc_line to find the start and end of the > first line of the function. > > Currently, if the pc value passed to find_pc_partial_function is in an > unmapped overlay then the function start and end addresses that are > returned are also the unmapped addresses. > > However, this is not the case for find_pc_line, here, if the address > passed in is in an unmapped overlay then we still get back a > symtab_and_line describing the mapped location. > > What this means is that if a functions mapped location is 0x100 -> "functions" -> "function's" > 0x120, and its unmapped locations is 0x400 -> 0x420 then we think that > the start/end is 0x400 and 0x420 respectively, but the first line > might run from 0x100 to 0x108. > > GDB will then try to scan the prologue starting from 0x400 and ending > at 0x108, this immediately gives up as it thinks we have gone past the > end of the prologue and the breakpoint is placed at 0x400. > > In this commit I propose that we change find_pc_line to return > addresses in the unmapped range if the address passed in is already in > the unmapped range. Now the first line will appear to run from 0x400 > to 0x408 and the prologue scanner will correctly find the end of the > prologue. > > With this commit gdb.base/overlays.exp now completely passes with an > m32r-elf toolchain. I'm not too familiar with overlays (apart from understanding the general concept), so I'm not sure how they are usually handled. Do two pieces of code in the same overlay have different unmapped addresses, which are used to uniquely identify them? In any case, what you did makes sense to me. It makes the two functions, find_pc_partial_function and find_pc_line behave in a more consistent manner. Simon