From patchwork Fri Apr 5 15:10:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 88106 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D78753847718 for ; Fri, 5 Apr 2024 15:10:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id C79B0384640D for ; Fri, 5 Apr 2024 15:10:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C79B0384640D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C79B0384640D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712329811; cv=none; b=W+sL3j+jUUq7pqHeZqGniodZjb6kgpSfVtHH18S1NjRTDa1nVczOtQ2jsYAZhXKTB+lxIYBiDd0wdjqn/bQ095pRg3eIDcLLfA4YOnCaAPhKRSRbzzKfl17g0566w4+zVPyizaLm4izAe2rvQUnkeISYpTJRi3Uo7nwwHTSzEeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712329811; c=relaxed/simple; bh=KBCtHBNg2ll7STIwaSrB3mcwPM5ljXOK6yhOISaLbq0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=JrgyDt+UuuoBt7zBI22ZaLN8BbROWnZQ+w7UY1a4/TiHihU+2prylS/SfKbs42AbB/LfQDzpunmYy9z4DzIxcKv9IHtf6a0izmFLKfBPY53eViHCN9z4o7ajAYPzUMLBOoJ8YbyoyYXEakDdRopPz6/6uMdJwGxAfsCWCm6Hlmc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7C8711F7DD for ; Fri, 5 Apr 2024 15:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712329807; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=szzdqs63x+HJIR4ssfRaIegaFkBezdaIo4qZm0RuiE4=; b=jrp20OroPnIWVjiIJC7QpZ7PYDrVNFMSUfEgKyFasKOJGhWzPoq28xKDRhSv+/DB8DvD1s gx71ws7kCLBcTfuFRSmvy3+c+IS83l+lY1VszWlRni0Osc4aJ3oN2opcdzJ5bp6fN9bMXw EjUAmj+1jabheTHCemE/zjvjdiHZxJ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712329807; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=szzdqs63x+HJIR4ssfRaIegaFkBezdaIo4qZm0RuiE4=; b=VAOM8mrWIeMT84lqUK4Ps2FxxZHGKswb3ZNmxFa6xmhyiUqYBDvevcnUFnt/JUzjBSDw+N HoZnlPH3m2oQXoBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=NbpJoowU; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=NWckYuaN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712329806; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=szzdqs63x+HJIR4ssfRaIegaFkBezdaIo4qZm0RuiE4=; b=NbpJoowU5MWyXcdC3aEh4hRU3OP7XDSuwO4dxCvepSRCju0nXiG9HGHjOoIbAZSslbExAD LSGn2zjzoHivGNuIgT3wjtPJX91wMmmE53ndvjVj+97gVvNKydAjdvKLgIDODFU2p3xy6S VC9yertrNNnbdKOB/w6HI5qK68D4pd0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712329806; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=szzdqs63x+HJIR4ssfRaIegaFkBezdaIo4qZm0RuiE4=; b=NWckYuaNyqVc159DKFiuLGvXGgg+b64SVJ3B5IaXFQOkfdX00+Hg41YPQNcLwIHn0sETwP 85pnLZDQMJoWKdCA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 66339139F1 for ; Fri, 5 Apr 2024 15:10:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id glOVF04UEGYFUwAAn2gu4w (envelope-from ) for ; Fri, 05 Apr 2024 15:10:06 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v3 1/2] [gdb/symtab] Fix an out of bounds array access in find_epilogue_using_linetable Date: Fri, 5 Apr 2024 17:10:11 +0200 Message-Id: <20240405151012.14763-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[hotmail.de:email,imap2.dmz-prg2.suse.org:helo,imap2.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.de:email,sourceware.org:url]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 7C8711F7DD X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: -3.01 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org From: Bernd Edlinger An out of bounds array access in find_epilogue_using_linetable causes random test failures like these: FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $fba_value == $fn_fba FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: check frame-id matches FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: bt 2 FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: up FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $sp_value == $::main_sp FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: $fba_value == $::main_fba FAIL: gdb.base/unwind-on-each-insn-amd64.exp: foo: instruction 6: [string equal $fid $::main_fid] Here the read happens below the first element of the line table, and the test failure depends on the value that is read from there. It also happens that std::lower_bound returns a pointer exactly at the upper bound of the line table, also here the read value is undefined, that happens in this test: FAIL: gdb.dwarf2/dw2-epilogue-begin.exp: confirm watchpoint doesn't trigger Fixes: 528b729be1a2 ("gdb/dwarf2: Add support for DW_LNS_set_epilogue_begin in line-table") Co-Authored-By: Tom de Vries PR symtab/31268 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31268 --- gdb/symtab.c | 85 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 10 deletions(-) base-commit: c0419c024bf922128131671e40de0aed736e38ed diff --git a/gdb/symtab.c b/gdb/symtab.c index 86603dfebc3..0c126d99cd4 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4166,10 +4166,14 @@ find_epilogue_using_linetable (CORE_ADDR func_addr) = unrelocated_addr (end_pc - objfile->text_section_offset ()); const linetable *linetable = sal.symtab->linetable (); - /* This should find the last linetable entry of the current function. - It is probably where the epilogue begins, but since the DWARF 5 - spec doesn't guarantee it, we iterate backwards through the function - until we either find it or are sure that it doesn't exist. */ + if (linetable->nitems == 0) + { + /* Empty line table. */ + return {}; + } + + /* Find the first linetable entry after the current function. Note that + this also may be an end_sequence entry. */ auto it = std::lower_bound (linetable->item, linetable->item + linetable->nitems, unrel_end, [] (const linetable_entry <e, unrelocated_addr pc) @@ -4177,13 +4181,74 @@ find_epilogue_using_linetable (CORE_ADDR func_addr) return lte.unrelocated_pc () < pc; }); - while (it->unrelocated_pc () >= unrel_start) - { - if (it->epilogue_begin) - return {it->pc (objfile)}; - it --; - } + if (it == linetable->item + linetable->nitems) + { + /* We couldn't find either: + - a linetable entry starting the function after the current + function, or + - an end_sequence entry that terminates the current function + at unrel_end. + This can happen when the linetable doesn't describe the full + extent of the function. Even though this is a corner case, which + may not happen other than in dwarf assembly test-cases, let's + handle this. + + Move to the last entry in the linetable, and check that it's an + end_sequence terminating the current function. */ + gdb_assert (it != &linetable->item[0]); + it--; + if (!(it->line == 0 + && unrel_start <= it->unrelocated_pc () + && it->unrelocated_pc () < unrel_end)) + return {}; + } + else + gdb_assert (unrel_end <= it->unrelocated_pc ()); + + /* Move to the last linetable entry of the current function. */ + if (it == &linetable->item[0]) + { + /* Doing it-- would introduce undefined behaviour, avoid it by + explicitly handling this case. */ + return {}; + } + it--; + if (it->unrelocated_pc () < unrel_start) + { + /* Not in the current function. */ + return {}; + } + gdb_assert (it->unrelocated_pc () < unrel_end); + + /* We're at the the last linetable entry of the current function. This + is probably where the epilogue begins, but since the DWARF 5 spec + doesn't guarantee it, we iterate backwards through the current + function until we either find the epilogue beginning, or are sure + that it doesn't exist. */ + for (; it >= &linetable->item[0]; it--) + { + if (it->unrelocated_pc () < unrel_start) + { + /* No longer in the current function. */ + break; + } + + if (it->epilogue_begin) + { + /* Found the beginning of the epilogue. */ + return {it->pc (objfile)}; + } + + if (it == &linetable->item[0]) + { + /* No more entries in the current function. + Doing it-- would introduce undefined behaviour, avoid it by + explicitly handling this case. */ + break; + } + } } + return {}; } From patchwork Fri Apr 5 15:10:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 88107 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B75983846422 for ; Fri, 5 Apr 2024 15:10:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id E08B23846078 for ; Fri, 5 Apr 2024 15:10:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E08B23846078 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E08B23846078 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712329812; cv=none; b=Ocft+/UZ4CxSmrL2LvlfwQfpZq1B/CQTtdIE8JwoIkuNU92VtF0znSPiIZzFKE4glTcKSMkh2n9y8MnBz3IwgEeI9tIrBc06SxG++glMZ8f03YE/taZu6aRMEwfNdhv+z+hIXjWWQFKWf3bZlOgs1Ixt9tUpelJHx96ia50lyd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712329812; c=relaxed/simple; bh=YtpK64iz19BWFiufWZlmyu0/sPvv/E183NWOWwbe/s8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=JFESQM8dzx9FM/WTCdiYUX6wRLpBGZhlKFN7dOnsCtRsX3uwTQt5jO20c/V2z47ZXkA2CgcCciBFhBPET0G3zCdYpIM/WVJVFmUR7XeZuacGd3Y3EnX//HZC0tBWAcNvPMgljBfekziig8woi231Zw+J9iQE9gXGlnJVApjjCiM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9CD3821A56 for ; Fri, 5 Apr 2024 15:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712329807; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M8Jq5ysP2J/O1FdwxqcpNDfI5uclS6Mn3vCjV9Hz/rQ=; b=MEWPJj/a1QjrPznwXHA9qTHnq+9ST1Rnmc51D2zGVBGYU9l/QLF1Drj56m74yXX0WWtu+9 ZpSFmmnmdcttwQOqlvQMGOsdTXrpT9u1sd6M0iXwh+AHw4msA1rELlYMb5Q/3otOKFSVJO Oxj61iGggMxVV/ufyiKK1wtLFnVm+d8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712329807; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M8Jq5ysP2J/O1FdwxqcpNDfI5uclS6Mn3vCjV9Hz/rQ=; b=LVF31keRMgl8YdelxdB5PcfglHcIvt2x87Nw77M/rIgdmGMd8qpRGMznoRbLMj3Wvo38Dd H9KMCskSg4vEZcAg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712329806; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M8Jq5ysP2J/O1FdwxqcpNDfI5uclS6Mn3vCjV9Hz/rQ=; b=g8aDdNRXa95QteBKPGmekkmznSTIDFu/9t5j0dpKJHa56f2JdZBnB8JSv3lpA06Om9lesV 1kz9qE4bROo2IC+F1kR8h6MJmgIFsPILLVNNtbqkewnDnRhUeqDT1N/wIjrA0o6a/d21L0 2aNcTv4ibFg5zCVTHMHvaxsZ6uwrzN0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712329806; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M8Jq5ysP2J/O1FdwxqcpNDfI5uclS6Mn3vCjV9Hz/rQ=; b=w8yc7pZcEZQRlxPB8NdyXztI/cFtOplO8rn2dPcaWL0sdnpXzwymy4q9AUlG3bqlMYixjo Y1ABG8k/4AATr9Dw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 831F413A92 for ; Fri, 5 Apr 2024 15:10:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 6KunHk4UEGYFUwAAn2gu4w (envelope-from ) for ; Fri, 05 Apr 2024 15:10:06 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v3 2/2] [gdb/testsuite] Add gdb.dwarf2/dw2-epilogue-begin-2.exp Date: Fri, 5 Apr 2024 17:10:12 +0200 Message-Id: <20240405151012.14763-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240405151012.14763-1-tdevries@suse.de> References: <20240405151012.14763-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url,imap2.dmz-prg2.suse.org:helo,imap2.dmz-prg2.suse.org:rdns]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org Test-case gdb.dwarf2/dw2-epilogue-begin.exp has an end_sequence at 0x4004ff: ... File name Line number Starting address View Stmt dw2-epilogue-begin.c 20 0x4004b7 x dw2-epilogue-begin.c 27 0x4004be x dw2-epilogue-begin.c 34 0x4004d0 x dw2-epilogue-begin.c 37 0x4004de x dw2-epilogue-begin.c 38 0x4004ec x dw2-epilogue-begin.c 43 0x4004ef x dw2-epilogue-begin.c 47 0x4004fa x dw2-epilogue-begin.c 50 0x4004ff x dw2-epilogue-begin.c - 0x4004ff ... which is before the actual exclusive end of the main function at 0x40050d: ... 00000000004004ff : 4004ff: c6 05 1b 1b 00 00 0a movb $0xa,0x1b1b(%rip) 400506: b8 00 00 00 00 mov $0x0,%eax 40050b: 5d pop %rbp 40050c: c3 ret ... This triggers the corner case in find_epilogue_using_linetable that the call to std::lower_bound returns the "not found" case. However, if we handle the corner case explicitly by returning something incorrect: ... + if (it == linetable->item + linetable->nitems) + return {}; ... the test-case still passes. Fix this by: - rearranging the test-case to move the watch function to after the main function, and - reworking the test-case into two variants: - end_sequence at the watch function end (the correct version), and - end_sequence before the watch function end (triggered the corner-case). Tested on x86_64-linux. --- .../gdb.dwarf2/dw2-epilogue-begin-2.exp | 20 ++ gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c | 28 +-- .../gdb.dwarf2/dw2-epilogue-begin.exp | 156 +------------- .../gdb.dwarf2/dw2-epilogue-begin.exp.tcl | 191 ++++++++++++++++++ 4 files changed, 229 insertions(+), 166 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp new file mode 100644 index 00000000000..64cd85644e0 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin-2.exp @@ -0,0 +1,20 @@ +# Copyright 2022-2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +standard_testfile dw2-epilogue-begin.c dw2-epilogue-begin.S + +set early_end_sequence 1 + +source $srcdir/$subdir/dw2-epilogue-begin.exp.tcl diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c index 4ff445cf37d..2fcc4807904 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.c @@ -22,6 +22,20 @@ trivial (void) char global; +extern void watch (void); + +int +main (void) +{ /* main prologue */ + asm ("main_label: .global main_label"); + global = 0; + asm ("main_fun_call: .global main_fun_call"); + watch (); /* main function call */ + asm ("main_epilogue: .global main_epilogue"); + global = 10; + return 0; /* main end */ +} + void watch (void) { /* watch start */ @@ -36,16 +50,6 @@ watch (void) asm ("mov $0x2, %rax"); local = 2; /* watch reassign */ asm ("watch_end: .global watch_end"); /* watch end */ -} - -int -main (void) -{ /* main prologue */ - asm ("main_label: .global main_label"); - global = 0; - asm ("main_fun_call: .global main_fun_call"); - watch (); /* main function call */ - asm ("main_epilogue: .global main_epilogue"); - global = 10; - return 0; /* main end */ + local = 3; + asm ("watch_early_end_sequence: .global watch_early_end_sequence"); } diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp index f646e23da62..9552dd764dd 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp @@ -13,161 +13,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Check that GDB can honor the epilogue_begin flag the compiler can place -# in the line-table data. -# We test 2 things: 1. that a software watchpoint triggered in an epilogue -# is correctly ignored -# 2. that GDB can mark the same line as both prologue and epilogue - -load_lib dwarf.exp - -# This test can only be run on targets which support DWARF-2 and use gas. -require dwarf2_support -# restricted to x86 to make it simpler to follow a variable -require is_x86_64_m64_target - standard_testfile .c .S -set trivial_line [gdb_get_line_number "trivial function"] -set main_prologue [gdb_get_line_number "main prologue"] -set main_epilogue [gdb_get_line_number "main end"] -set watch_start_line [gdb_get_line_number "watch start"] - -set asm_file [standard_output_file $srcfile2] - -# The producer will be set to clang because at the time of writing -# we only care about epilogues if the producer is clang. When the -# producer is GCC, variables use CFA locations, so watchpoints can -# continue working even on epilogues. -Dwarf::assemble $asm_file { - global srcdir subdir srcfile srcfile2 - global trivial_line main_prologue main_epilogue watch_start_line - declare_labels lines_label - - get_func_info main - get_func_info trivial - get_func_info watch - - cu {} { - compile_unit { - {language @DW_LANG_C} - {name dw2-prologue-end.c} - {stmt_list ${lines_label} DW_FORM_sec_offset} - {producer "clang version 17.0.1"} - } { - declare_labels char_label - - char_label: base_type { - {name char} - {encoding @DW_ATE_signed} - {byte_size 1 DW_FORM_sdata} - } - - subprogram { - {external 1 flag} - {name trivial} - {low_pc $trivial_start addr} - {high_pc "$trivial_start + $trivial_len" addr} - } - subprogram { - {external 1 flag} - {name watch} - {low_pc $watch_start addr} - {high_pc "$watch_start + $watch_len" addr} - } { - DW_TAG_variable { - {name local} - {type :$char_label} - {DW_AT_location {DW_OP_reg0} SPECIAL_expr} - } - } - subprogram { - {external 1 flag} - {name main} - {low_pc $main_start addr} - {high_pc "$main_start + $main_len" addr} - } - } - } - - lines {version 5} lines_label { - set diridx [include_dir "${srcdir}/${subdir}"] - file_name "$srcfile" $diridx - - program { - DW_LNS_set_file $diridx - DW_LNE_set_address $trivial_start - line $trivial_line - DW_LNS_set_prologue_end - DW_LNS_set_epilogue_begin - DW_LNS_copy - - DW_LNE_set_address watch - line $watch_start_line - DW_LNS_copy - - DW_LNE_set_address watch_start - line [gdb_get_line_number "watch assign"] - DW_LNS_set_prologue_end - DW_LNS_copy - - DW_LNE_set_address watch_reassign - line [gdb_get_line_number "watch reassign"] - DW_LNS_set_epilogue_begin - DW_LNS_copy - - DW_LNE_set_address watch_end - line [gdb_get_line_number "watch end"] - DW_LNS_copy - - DW_LNE_set_address $main_start - line $main_prologue - DW_LNS_set_prologue_end - DW_LNS_copy - - DW_LNE_set_address main_fun_call - line [gdb_get_line_number "main function call"] - DW_LNS_copy - - DW_LNE_set_address main_epilogue - line $main_epilogue - DW_LNS_set_epilogue_begin - DW_LNS_copy - - DW_LNE_end_sequence - } - } -} - -if { [prepare_for_testing "failed to prepare" ${testfile} \ - [list $srcfile $asm_file] {nodebug}] } { - return -1 -} - -if ![runto_main] { - return -1 -} - -# Moving to the scope with a local variable. -gdb_breakpoint $watch_start_line -gdb_continue_to_breakpoint "continuing to function" ".*" -gdb_test "next" "local = 2.*" "stepping to epilogue" - -# Forcing software watchpoints because hardware ones don't care if we -# are in the epilogue or not. -gdb_test_no_output "set can-use-hw-watchpoints 0" +set early_end_sequence 0 -# Test that the software watchpoint will not trigger in this case -gdb_test "watch local" "\[W|w\]atchpoint .: local" "set watchpoint" -gdb_test "continue" ".*\[W|w\]atchpoint . deleted.*" \ - "confirm watchpoint doesn't trigger" +source $srcdir/$subdir/dw2-epilogue-begin.exp.tcl -# First we test that the trivial function has a line with both a prologue -# and an epilogue. Do this by finding a line that has 3 Y columns -set sep "\[ \t\]" -set hex_number "0x\[0-9a-f\]+" -gdb_test_multiple "maint info line-table" "test epilogue in linetable" -lbl { - -re "\[0-9\]$sep+$trivial_line$sep+$hex_number$sep+$hex_number$sep+Y$sep+Y$sep+Y" { - pass $gdb_test_name - } -} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl new file mode 100644 index 00000000000..18282e884e4 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-epilogue-begin.exp.tcl @@ -0,0 +1,191 @@ +# Copyright 2022-2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check that GDB can honor the epilogue_begin flag the compiler can place +# in the line-table data. +# We test 2 things: 1. that a software watchpoint triggered in an epilogue +# is correctly ignored +# 2. that GDB can mark the same line as both prologue and epilogue + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +require dwarf2_support +# restricted to x86 to make it simpler to follow a variable +require is_x86_64_m64_target + +set trivial_line [gdb_get_line_number "trivial function"] +set main_prologue [gdb_get_line_number "main prologue"] +set main_epilogue [gdb_get_line_number "main end"] +set watch_start_line [gdb_get_line_number "watch start"] + +set asm_file [standard_output_file $srcfile2] + +# The producer will be set to clang because at the time of writing +# we only care about epilogues if the producer is clang. When the +# producer is GCC, variables use CFA locations, so watchpoints can +# continue working even on epilogues. +Dwarf::assemble $asm_file { + global srcdir subdir srcfile srcfile2 + global trivial_line main_prologue main_epilogue watch_start_line + declare_labels lines_label + + get_func_info main + get_func_info trivial + get_func_info watch + + if { $::early_end_sequence == 1 } { + set watch_end_sequence watch_early_end_sequence + } else { + set watch_end_sequence $watch_end + } + + cu {} { + compile_unit { + {language @DW_LANG_C} + {name dw2-prologue-end.c} + {stmt_list ${lines_label} DW_FORM_sec_offset} + {producer "clang version 17.0.1"} + } { + declare_labels char_label + + char_label: base_type { + {name char} + {encoding @DW_ATE_signed} + {byte_size 1 DW_FORM_sdata} + } + + subprogram { + {external 1 flag} + {name trivial} + {low_pc $trivial_start addr} + {high_pc "$trivial_start + $trivial_len" addr} + } + subprogram { + {external 1 flag} + {name watch} + {low_pc $watch_start addr} + {high_pc "$watch_start + $watch_len" addr} + } { + DW_TAG_variable { + {name local} + {type :$char_label} + {DW_AT_location {DW_OP_reg0} SPECIAL_expr} + } + } + subprogram { + {external 1 flag} + {name main} + {low_pc $main_start addr} + {high_pc "$main_start + $main_len" addr} + } + } + } + + lines {version 5} lines_label { + set diridx [include_dir "${srcdir}/${subdir}"] + file_name "$srcfile" $diridx + + program { + DW_LNS_set_file $diridx + + DW_LNE_set_address $trivial_start + line $trivial_line + DW_LNS_set_prologue_end + DW_LNS_set_epilogue_begin + DW_LNS_copy + + DW_LNE_set_address $trivial_end + DW_LNE_end_sequence + + + DW_LNS_set_file $diridx + + DW_LNE_set_address $main_start + line $main_prologue + DW_LNS_set_prologue_end + DW_LNS_copy + + DW_LNE_set_address main_fun_call + line [gdb_get_line_number "main function call"] + DW_LNS_copy + + DW_LNE_set_address main_epilogue + line $main_epilogue + DW_LNS_set_epilogue_begin + DW_LNS_copy + + DW_LNE_set_address $main_end + DW_LNE_end_sequence + + + DW_LNS_set_file $diridx + + DW_LNE_set_address $watch_start + line $watch_start_line + DW_LNS_copy + + DW_LNE_set_address watch_start + line [gdb_get_line_number "watch assign"] + DW_LNS_set_prologue_end + DW_LNS_copy + + DW_LNE_set_address watch_reassign + line [gdb_get_line_number "watch reassign"] + DW_LNS_set_epilogue_begin + DW_LNS_copy + + DW_LNE_set_address watch_end + line [gdb_get_line_number "watch end"] + DW_LNS_copy + + DW_LNE_set_address $watch_end_sequence + DW_LNE_end_sequence + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Moving to the scope with a local variable. +gdb_breakpoint $watch_start_line +gdb_continue_to_breakpoint "continuing to function" ".*" +gdb_test "next" "local = 2.*" "stepping to epilogue" + +# Forcing software watchpoints because hardware ones don't care if we +# are in the epilogue or not. +gdb_test_no_output "set can-use-hw-watchpoints 0" + +# Test that the software watchpoint will not trigger in this case +gdb_test "watch local" "\[W|w\]atchpoint .: local" "set watchpoint" +gdb_test "continue" ".*\[W|w\]atchpoint . deleted.*" \ + "confirm watchpoint doesn't trigger" + +# First we test that the trivial function has a line with both a prologue +# and an epilogue. Do this by finding a line that has 3 Y columns +set sep "\[ \t\]" +set hex_number "0x\[0-9a-f\]+" +gdb_test_multiple "maint info line-table" "test epilogue in linetable" -lbl { + -re "\[0-9\]$sep+$trivial_line$sep+$hex_number$sep+$hex_number$sep+Y$sep+Y$sep+Y" { + pass $gdb_test_name + } +}