From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id D943B385E836; Wed, 8 May 2024 12:12:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D943B385E836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1715170356; bh=kW9VWwlUAnX0haZ7UGeeVFtDaFargm/wtOjFW32OFCY=; h=From:To:Subject:Date:From; b=jdiZAyxlGW5jiSkKmkm1R+SPiTRfSIg0elqlixH/XTkXbCFPR8l/4oYRb6QTIIoVo iqSN+Xu0k75Lkd76/OffBfE68xQmQZg30WGlHUtLH1dhIZXRxV7r3MDxnCWDCaXDFz MyCedZz/FTjGbSabBXbLyS4nnZqXvMeao3ETvY8k= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: c144f638337944101131d9fe6de4ab908f6d4c2d X-Git-Newrev: 2236c5e384de20b0dd6b2fbc964a7269027cb2d9 Message-Id: <20240508121236.D943B385E836@sourceware.org> Date: Wed, 8 May 2024 12:12:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2236c5e384de= 20b0dd6b2fbc964a7269027cb2d9 commit 2236c5e384de20b0dd6b2fbc964a7269027cb2d9 Author: Tom de Vries Date: Wed May 8 14:13:11 2024 +0200 [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust =20 On arm-linux, until commit bbb12eb9c84 ("gdb/arm: Remove tpidruro regis= ter 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 ... =20 What happens is the following: - the TestUnwinder from inline-frame-cycle-unwind.py calls gdb.UnwindInfo.add_saved_register with reg =3D=3D 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 un= winder succeeds and returns the correct frame, and - the test-case fails because it's counting on the TestUnwinder to succ= eed and return an incorrect frame. =20 Fix this by checking for !value::entirely_available as well as valued::optimized_out in unwind_infopy_add_saved_register. =20 Tested on x86_64-linux and arm-linux. =20 Approved-By: Andrew Burgess =20 PR python/31437 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31437 Diff: --- 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 a86ccd2c94e..18125e56a46 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -361,6 +361,18 @@ unwind_infopy_add_saved_register (PyObject *self, PyOb= ject *args, PyObject *kw) return nullptr; } =20 + if (value->optimized_out () || !value->entirely_available ()) + { + /* If we allow this value to be registered here, pyuw_sniffer is goi= ng + 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; + } + gdbpy_ref<> new_value =3D gdbpy_ref<>::new_reference (pyo_reg_value); bool found =3D false; for (saved_reg ® : *unwind_info->saved_regs)