From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id K1ucNYTv4mAOWwAAWB0awg (envelope-from ) for ; Mon, 05 Jul 2021 07:39:48 -0400 Received: by simark.ca (Postfix, from userid 112) id CD1801F1F2; Mon, 5 Jul 2021 07:39:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 97AD41E940 for ; Mon, 5 Jul 2021 07:39:47 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 093FA3847807 for ; Mon, 5 Jul 2021 11:39:47 +0000 (GMT) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by sourceware.org (Postfix) with ESMTPS id 74E9E385B836 for ; Mon, 5 Jul 2021 11:39:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74E9E385B836 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f41.google.com with SMTP id q17so1319359wrv.2 for ; Mon, 05 Jul 2021 04:39:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bRJ0Yy2k/QV2K5/M1YApMmsLBV13QQtIhOAhnKzYy2U=; b=PbwRwvlWM48sDjwDI1jz72vtQvhVaVrt63ebgu7x6ZjstuDmYMr2vC67LfhKA9108n 6tpVeKTI4kXHvUuV8kFzLMjydDoPd9Hsmje6uXgi7Mycrmd8L3qzvRgxr6FdCBvFWusL z7YGWIxYmRmHuz834Bgeotw9oIVLQxOgZI+GA43cmkM4zYr6hEmllVYljn1uZrzhQR6y s6p1X+S4zGh0etj45Viu6lGYA/vT+XUwLz/8SRnUxE6C9XO6N3DZmUBOvk7q2y2m1fem 9+bhs7RB1lqQUpgyaysEswDgmTZxSz6tnvt6ey82GTG1Y9epB09G1LFY7A1yxLxkpWxG oKTw== X-Gm-Message-State: AOAM530cLlhNVKyVj/6XjFp/nuDA8o/KwXapKg3fbYxcQreX9pyWX8DE lxPiIQhgFofvU/m8Z4f0J3aIEsg3DPy/+w== X-Google-Smtp-Source: ABdhPJwe87YnSnuvzh2oUKqpSmVNKlXxu0RYgcemPottVHF/ld/quSmDTwmf0JXhnWFuyHdFUSxjmg== X-Received: by 2002:a5d:40c7:: with SMTP id b7mr15017006wrq.169.1625485173904; Mon, 05 Jul 2021 04:39:33 -0700 (PDT) Received: from ?IPv6:2001:8a0:f932:6a00:46bc:d03b:7b3a:2227? ([2001:8a0:f932:6a00:46bc:d03b:7b3a:2227]) by smtp.gmail.com with ESMTPSA id u15sm21444294wmq.48.2021.07.05.04.39.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jul 2021 04:39:32 -0700 (PDT) Subject: Re: [PATCHv2 1/2] gdb: prevent an assertion when computing the frame_id for an inline frame From: Pedro Alves To: Andrew Burgess , gdb-patches@sourceware.org References: <0bb59b0323e01b0fe5d3b7e101418b05f7b8d43d.1624304637.git.andrew.burgess@embecosm.com> Message-ID: <9c6022ea-4f2b-bae9-6c41-8b0c87952c5a@palves.net> Date: Mon, 5 Jul 2021 12:39:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <0bb59b0323e01b0fe5d3b7e101418b05f7b8d43d.1624304637.git.andrew.burgess@embecosm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi Andrew, I've read this, and I think you came up with a reasonable solution. Some minor-ish comments below. On 2021-06-21 8:46 p.m., Andrew Burgess wrote: > +static void foo (void); > +static void bar (void); > + > +volatile int global_var; > +volatile int level_counter; > + > +static void __attribute__((noinline)) > +bar (void) > +{ > + /* Do some work. */ > + ++global_var; > + > + /* Now the inline function. */ > + --level_counter; > + foo (); > + ++level_counter; > + > + /* Do some work. */ > + ++global_var; > +} > + > +static inline void __attribute__((__always_inline__)) > +foo (void) > +{ > + if (level_counter > 1) > + { > + --level_counter; > + bar (); > + ++level_counter; > + } > + else > + ++global_var; /* Break here. */ > +} I'd suggest renaming these "foo" "bar" functions to "normal_func" "inline_func" or "norm" "inln" or something like that. I think it'll make the backtraces in the .exp code more obvious. > + > +int > +main () > +{ > + level_counter = 6; > + bar (); > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/inline-frame-bad-unwind.exp b/gdb/testsuite/gdb.base/inline-frame-bad-unwind.exp > new file mode 100644 > index 00000000000..49c35517801 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/inline-frame-bad-unwind.exp I'd suggest naming this something with "cycle" instead of "bad" as being more to the point. There can be many forms of badness. > + > +# This test checks for an edge case when unwinding inline frames which > +# occur towards the older end of the stack when the stack ends with a > +# cycle. Consider this well formed stack: > +# > +# main -> normal_frame -> inline_frame > +# > +# Now consider that, for whatever reason, the stack unwinding of > +# "normal_frame" becomes corrupted, such that the stack appears to be > +# this: > +# > +# .-> normal_frame -> inline_frame > +# | | > +# '------' > +# > +# When confrontend with such a situation we would expect GDB to detect Typo: confrontend -> confronted > + > +# Check the unbroken stack. > +gdb_test_sequence "bt" "Backtrace when the unwind is left unbroken" { > + "\\r\\n#0 \[^\r\n\]* foo \\(\\) at " > + "\\r\\n#1 \[^\r\n\]* bar \\(\\) at " > + "\\r\\n#2 \[^\r\n\]* foo \\(\\) at " > + "\\r\\n#3 \[^\r\n\]* bar \\(\\) at " > + "\\r\\n#4 \[^\r\n\]* foo \\(\\) at " > + "\\r\\n#5 \[^\r\n\]* bar \\(\\) at " > + "\\r\\n#6 \[^\r\n\]* main \\(\\) at " > +} > + > +# Arrange to introduce a stack cycle at frame 5. > +gdb_test_no_output "python stop_at_level=5" > +gdb_test "maint flush register-cache" \ > + "Register cache flushed\\." "" How about using with_test_prefix instead of suppressing the test message? Like: with_test_prefix "broken at frame 5 { # Arrange to introduce a stack cycle at frame 5. gdb_test_no_output "python stop_at_level=5" gdb_test "maint flush register-cache" "Register cache flushed\\." gdb_test_sequence "bt" "" { ... } } > +gdb_test_sequence "bt" "Backtrace when the unwind is broken at frame 5" { Spurious double space, and lowercase "Backtrace". > + "\\r\\n#0 \[^\r\n\]* foo \\(\\) at " > + "\\r\\n#1 \[^\r\n\]* bar \\(\\) at " > + "\\r\\n#2 \[^\r\n\]* foo \\(\\) at " > + "\\r\\n#3 \[^\r\n\]* bar \\(\\) at " > + "\\r\\n#4 \[^\r\n\]* foo \\(\\) at " > + "\\r\\n#5 \[^\r\n\]* bar \\(\\) at " > + "\\r\\nBacktrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)" Actually, I don't think gdb_test_sequence is the right proc for these tests, because it consumes lines between each pattern. I mean, above, the test will pass if GDB prints frame #6 too, before printing the "Backtrace stopped" line. E.g., with this change, the test will still pass: @@ -92,10 +90,6 @@ gdb_test "maint flush register-cache" \ gdb_test_sequence "bt" "Backtrace when the unwind is broken at frame 5" { "\\r\\n#0 \[^\r\n\]* foo \\(\\) at " "\\r\\n#1 \[^\r\n\]* bar \\(\\) at " - "\\r\\n#2 \[^\r\n\]* foo \\(\\) at " - "\\r\\n#3 \[^\r\n\]* bar \\(\\) at " - "\\r\\n#4 \[^\r\n\]* foo \\(\\) at " - "\\r\\n#5 \[^\r\n\]* bar \\(\\) at " "\\r\\nBacktrace stopped: previous frame identical to this frame \\(corrupt stack\\?\\)" } > diff --git a/gdb/testsuite/gdb.base/inline-frame-bad-unwind.py b/gdb/testsuite/gdb.base/inline-frame-bad-unwind.py > new file mode 100644 > index 00000000000..370f86cc610 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/inline-frame-bad-unwind.py > @@ -0,0 +1,85 @@ > +# Copyright (C) 2021 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 . > + > +import gdb > +from gdb.unwinder import Unwinder > + > +# Set this to the stack level the backtrace should be corrupted at. > +# This will only work for frame 1, 3, or 5 in the test this unwinder > +# was written for. > +stop_at_level = None > + > +# Set this to the stack frame size of frames 1, 3, and 5. These > +# frames wil all have the same stack frame size as they are the same Typo "wil" -> "will".