From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 B27EC3849AFB for ; Wed, 8 May 2024 12:03:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B27EC3849AFB 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 B27EC3849AFB 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=1715169794; cv=none; b=nLxBBvTjTdPU5/HaAo43dl7L+dKO19KfjGHOHywbQY1vUz1T1r0htnd8niu0WrUJP3RQr+x5FkWl+oco5cWMtWcOoeJiCd6lOSgg8keTqeIaEGK3KFUyMsO9EP0xN3WuBYtFpVLD68yuA2OlGUdksxH3AJiRhfOzvJIs9M+x/0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715169794; c=relaxed/simple; bh=Eabl52lqWw5r1FxsAsERZ6KMVqOa2TmaG8wHch81Evk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aj7QICZqHUzW5W92h8EKVhJ+/HcleC952bF6UIcbxqh/TvU4LSPv4PYlojVA1sn2g4gndhRUzcRWuwFajLvRJy3D4hYvKJtLc8GfwmH+6aLijVLYzI81NUDN62ER7+fXYdQPreJbtSCm3PLSRuEK36Snx0Xqw0KagETKFRrksoA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715169783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HqVWH+8MLrepJ2J7I/9Cr0e8OLyIDCw3vow6E5mB+RE=; b=BoV/WEjsCdyeXjVqfSsV9N6FCaJQZfsFJDwrViAZFKYhQNJLLCY3Wd2vGmLHiZ+EuaSXcg X+b0syr9KOVTGpwokD5eTwRpmyjfgyAztRnL6FK1vOGHN47AUpuRjy96eOVn2BJ9k3SyZe w+O5sMWxlvZFjaxm6znda25L0+oLKDM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-v_mfDokXPqO0vjFtnpZJSA-1; Wed, 08 May 2024 08:03:01 -0400 X-MC-Unique: v_mfDokXPqO0vjFtnpZJSA-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-34dcec2cbbbso2867107f8f.0 for ; Wed, 08 May 2024 05:03:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715169780; x=1715774580; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HqVWH+8MLrepJ2J7I/9Cr0e8OLyIDCw3vow6E5mB+RE=; b=qGhWoJL5C5HneXJ1Lhs/1C8LxQyIjkxJ7s1BxtXXzwo+nLGyBGytcmAxPos7LEdtDH qNmTVQHqVa6ov4eg3m414J0H3BwZIUERoUQwQrjOw4ZhkFzlPRAUSkhicbfVYsV6Plue tFz/wDw7wQvcnGzQ9YcGFRyBi1mkbluLHwPskz++P38Tfm1136HdaIDG8iK+t4gI0+D/ v4+z/fL1Ou1+GpIZy0uO/Rn4BOz+HEsHqeDvp9iLfvQ/gCUSxNokskuJbszc6KF8rfzr owPBb0GqojETh8k3LCRBfvJMnQfeXTfA0Pz2EmJy5F8hFPxCW4cvbCnp57mLNCklAN3c R94w== X-Forwarded-Encrypted: i=1; AJvYcCUZrIY9mL5mLkHcIo2F4Xw4gz8M6Nr2JBZoz5ggizVRgj6r8GMKQoo2bt8xOpKlgfqpg/cpJRuXQ60wlAPRXeOWwtGC784aMj2bmA== X-Gm-Message-State: AOJu0YyK7x00o1WHaOA/xeZcZGnfZaLbWK3kmtNLJmfjpSJFZcwv4M1U 5+RE4S/3SU5atCuizuuSgoM86n2HUoGDYA0jcj6Scz2LQv3jUlJO3FAUWxoBO4JvGzVSVFeWG9J FKe287ZczqvG+9qLm6/D5KtzztO8B8XaXYRBZsS+f3kukeJ7Pb0ptjWx+MMzY2SrWd3g= X-Received: by 2002:a5d:544c:0:b0:34c:ca8d:ab94 with SMTP id ffacd0b85a97d-34fcade23e0mr1784942f8f.23.1715169779978; Wed, 08 May 2024 05:02:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeySb/Ol/wFZ+Evj+OUL22H6r8UVV97t6yAUsgmXzVq0K/pKaqsWO+cmB536hX8JeUhp2/Dw== X-Received: by 2002:a5d:544c:0:b0:34c:ca8d:ab94 with SMTP id ffacd0b85a97d-34fcade23e0mr1784913f8f.23.1715169779355; Wed, 08 May 2024 05:02:59 -0700 (PDT) Received: from localhost ([31.111.84.240]) by smtp.gmail.com with ESMTPSA id m18-20020adfa3d2000000b0034dfede0071sm15314728wrb.46.2024.05.08.05.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 05:02:59 -0700 (PDT) From: Andrew Burgess To: Tom de Vries , gdb-patches@sourceware.org Subject: Re: [PATCH] [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust In-Reply-To: <20240302123653.16923-1-tdevries@suse.de> References: <20240302123653.16923-1-tdevries@suse.de> Date: Wed, 08 May 2024 13:02:58 +0100 Message-ID: <87bk5gtsst.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.0 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 List-Id: Tom de Vries writes: > On arm-linux, until commit bbb12eb9c84 ("gdb/arm: Remove tpidruro register > from non-FreeBSD target descriptions") I ran into: > ... > FAIL: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 5: \ > backtrace when the unwind is broken at frame 5 > ... > > What happens is the following: > - the TestUnwinder from inline-frame-cycle-unwind.py calls > gdb.UnwindInfo.add_saved_register with reg == tpidruro and value > "", > - pyuw_sniffer calls value->contents ().data () to access the value of the > register, which throws an UNAVAILABLE_ERROR, > - this causes the TestUnwinder unwinder to fail, after which another unwinder > succeeds and returns the correct frame, and > - the test-case fails because it's counting on the TestUnwinder to succeed and > return an incorrect frame. > > Fix this by checking for !value::entirely_available as well as > valued::optimized_out in unwind_infopy_add_saved_register. > > Tested on x86_64-linux and arm-linux. > > PR python/31437 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31437 > --- > gdb/python/py-unwind.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c > index 56f925bc57f..1c1289f7e7d 100644 > --- a/gdb/python/py-unwind.c > +++ b/gdb/python/py-unwind.c > @@ -362,6 +362,18 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args, PyObject *kw) > return nullptr; > } > > + if (value->optimized_out () || !value->entirely_available ()) > + { > + /* If we allow this value to be registered here, pyuw_sniffer is going > + to run into an exception when trying to access its contents. > + Throwing an exception here just puts a burden on the user to > + implement the same checks on the user side. We could return False > + here and True otherwise, but again that might require changes in user > + code. So, handle this with minimal impact for the user, while > + improving robustness: silently ignore the register/value pair. */ > + Py_RETURN_NONE; > + } Thanks for fixing this. I agree with this approach. Registers that aren't saved will be reported as optimized out anyway, which seems good enough -- though having them report as unavailable might be better, but that's not a problem for this patch. I think returning True/False would be OK, I don't think users are likely to be depending on this function returning None. But that said, I don't see any immediate need to change the return type; if a user really wants to know then they can check for unavailable/optimized-out values prior to saving the register value. Approved-By: Andrew Burgess Thanks, Andrew > + > gdbpy_ref<> new_value = gdbpy_ref<>::new_reference (pyo_reg_value); > bool found = false; > for (saved_reg ® : *unwind_info->saved_regs) > > base-commit: a6a3b67fa9052bba81ed91a38569c11ecb95baf1 > -- > 2.35.3