From patchwork Fri Oct 27 08:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 78607 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 2FD4C3853513 for ; Fri, 27 Oct 2023 08:58:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C6C873858D3C for ; Fri, 27 Oct 2023 08:57:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C6C873858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C6C873858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698397078; cv=none; b=Pa9ibDJSlnFL+e4STtUu8GCQwTYi+9FQtnpbKizEnigw4VWYGHWCajwhIgtz0ypo4MlGm/L3HhkdOrTe2RTQkCHDHXlFXFSIOZW8wmxDQd8JoUc60WUqyyOZuqAWTqah9AQ1dR7uTFv550kqPxw3zBns4H4rJNKD+T2bfrFpwEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698397078; c=relaxed/simple; bh=YWjd4l+HoJMJ4o/+JDKDI126Ca9N6dHehxzGgyDUXJU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZTRj0pKg0FzTG6ujjJsRD8aU7Slj+NW8dZ0cx3acARUBF26ANVSELiamqTvjLGPLvHR9afjwko1kr6Jui/fnGhokoAofznOVJJsmA5KncZ5VYo5mtMGVq/7r/HxZzHhBoYiWYjXxhjFbVQg6w7jtCYsyfRmBvLUshE+V1rc4MuM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698397076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8URkaOeiDTPvrxctpow1kch/3X7i2yjJrVgNxVuMU2A=; b=R2aAOxiRAXm9gWoRq5yDoKLPByKK2FS7S9P31ch26wo/oENqdFs229WvOfctF7Xb0G56OV wiNJNxS70injZ0rkq5rsdgRIxK5+/K8DgDxneGtQeQT6Xs5gNe0ODGDi1cluK/IrAaZBMx InbPTlQLOTBCP9JdSuME1LwNtr81PpU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-35-NUG02re5OMWsH5L8BZu1FA-1; Fri, 27 Oct 2023 04:57:55 -0400 X-MC-Unique: NUG02re5OMWsH5L8BZu1FA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C1AC03823322 for ; Fri, 27 Oct 2023 08:57:54 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.226.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 493191C060B0; Fri, 27 Oct 2023 08:57:54 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH] gdb: Guarantee that an SAL's end is right before the next statement Date: Fri, 27 Oct 2023 10:57:21 +0200 Message-ID: <20231027085720.2124554-2-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 When examining a failure that happens when testing gdb.python/py-symtab.c with clang, I noticed that it was going wrong because the test assumed that whenever we get an SAL, its end would always be right before statement in the line table. This is true for GCC compiled binaries, since gcc only adds statements to the line table, but not true for clang compiled binaries. This is the second time I run into a problem where GDB doesn't handle non-statement line table entries correctly. The other was eventually committed as 9ab50efc463ff723b8e9102f1f68a6983d320517: "gdb: fix until behavior with trailing !is_stmt lines", but that commit only changes the behavior for the 'until' command. In this patch I propose a more general solution, making it so every time we generate the SAL for a given pc, we set the end of the SAL to before the next statement or the first instruciton in the next line, instead of naively assuming that to be the case. With this new change, the edge case is removed from the processing of the 'until' command without regressing the accompanying test case, and no other regressions were observed in the testsuite. Regression tested on fedora 37 with GCC and clang. --- gdb/infcmd.c | 39 --------------------------------------- gdb/symtab.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index cf8cd527955..72dc8231523 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1363,45 +1363,6 @@ until_next_command (int from_tty) tp->control.step_range_start = func->value_block ()->entry_pc (); tp->control.step_range_end = sal.end; - - /* By setting the step_range_end based on the current pc, we are - assuming that the last line table entry for any given source line - will have is_stmt set to true. This is not necessarily the case, - there may be additional entries for the same source line with - is_stmt set false. Consider the following code: - - for (int i = 0; i < 10; i++) - loop_body (); - - Clang-13, will generate multiple line table entries at the end of - the loop all associated with the 'for' line. The first of these - entries is marked is_stmt true, but the other entries are is_stmt - false. - - If we only use the values in SAL, then our stepping range may not - extend to the end of the loop. The until command will reach the - end of the range, find a non is_stmt instruction, and step to the - next is_stmt instruction. This stopping point, however, will be - inside the loop, which is not what we wanted. - - Instead, we now check any subsequent line table entries to see if - they are for the same line. If they are, and they are marked - is_stmt false, then we extend the end of our stepping range. - - When we finish this process the end of the stepping range will - point either to a line with a different line number, or, will - point at an address for the same line number that is marked as a - statement. */ - - struct symtab_and_line final_sal - = find_pc_line (tp->control.step_range_end, 0); - - while (final_sal.line == sal.line && final_sal.symtab == sal.symtab - && !final_sal.is_stmt) - { - tp->control.step_range_end = final_sal.end; - final_sal = find_pc_line (final_sal.end, 0); - } } tp->control.may_range_step = 1; diff --git a/gdb/symtab.c b/gdb/symtab.c index 5ec56f4f2af..090f6415af6 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3207,10 +3207,16 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) unrelocated_addr (pc - objfile->text_section_offset ()), pc_compare)); if (item != first) - prev = item - 1; /* Found a matching item. */ + { + prev = item - 1; /* Found a matching item. */ + /* At this point, prev is a line whose address is <= pc. However, we + don't know if ITEM is pointing to the same statement or not. */ + while (item != last && prev->line == item->line && !item->is_stmt) + item++; + } /* At this point, prev points at the line whose start addr is <= pc, and - item points at the next line. If we ran off the end of the linetable + item points at the next statement. If we ran off the end of the linetable (pc >= start of the last line), then prev == item. If pc < start of the first line, prev will not be set. */