From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 812C43939C16 for ; Wed, 17 Jun 2020 17:38:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 812C43939C16 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x429.google.com with SMTP id h5so3258314wrc.7 for ; Wed, 17 Jun 2020 10:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ACcVdIjT8f7UjwpifU8wGeGb6IscAydG8m8xrHYxWIk=; b=XEaua08FrZx5rOWepK1TJNF32IcFJCYKT/r9CRV6pJdPBMo7VooPpBvpxAGmpg1EhJ t62+/7uMdncODEUQJfapHzrfjMaxt7qtw9vA5DOUmsYO/MOTOChHkIsRbwA1zzJeQ+Ju bTr4GvVTk/rJmD8hAwsceUshcvbJHqplrVIngPhau8KwsUwdfXm0bjBBXYJZFTI5LoQw mtxN/Zij+vOzRUJymXLA8kyRcw4Cq0Ec5g9pr8HjloxRX+zqExQohNF64+0V0+mKOnj0 +DxJ6pYvvP9uEvE1l/VVOt8fpA6igYX2+xLDUnIzRJAcxb/M15Y48YqZyeAWl9gu9DbL ApEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ACcVdIjT8f7UjwpifU8wGeGb6IscAydG8m8xrHYxWIk=; b=KkTvwph/kMiKs+6AaY/DV+ld58iJQidkJTkeuLO7TxXow/mZu5v0XbP9yLpBeN3ClM xRMWdp5blHv3G7//5uGr+qc87dUJEx67jb/m9u37sddd2BhExLvaBj0s2WlnQ99IzkOp DqapFpHu2ZycxVNEu/XzTq/MFYNkjNlo+TQHFNDuhPisy6UNN8FhlTYQutLbLfLO+I0x f0FehPP9FLxRBtClaxwLV/MSals+SKdFehdknRZdyfRl0pLuKbyREGF3flpBCoEL0Riu /8qVFXexP5vybSYEa5GoAePOLbXF6IbwUv9GgICRIkEXY5Y+Q5BWnf4LTjVE2RnIMssc A/wg== X-Gm-Message-State: AOAM531yyY2kg8kT0CiqQF9W5DPVpL4JtKmVb6b2zIBE/4FVKmcnsUKT FFX2bh0BZTlqHfydr+GB/dFmBBT1dOo= X-Google-Smtp-Source: ABdhPJyloo31dap1SjIM8g90R8X7fC0SuI0HDlBiCjjDdaSD+PUXTTcYvB3L+/lvkWsCxoR0aN7SrA== X-Received: by 2002:a5d:40d2:: with SMTP id b18mr345753wrq.131.1592415497120; Wed, 17 Jun 2020 10:38:17 -0700 (PDT) Received: from localhost (host86-128-12-16.range86-128.btcentralplus.com. [86.128.12.16]) by smtp.gmail.com with ESMTPSA id v6sm378815wrf.61.2020.06.17.10.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 10:38:16 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 2/5] gdb/python: Add architecture method to gdb.PendingFrame Date: Wed, 17 Jun 2020 18:38:06 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 17 Jun 2020 17:38:20 -0000 It could be useful to determine the architecture of a frame being unwound during the frame unwind process, that is, before we have a gdb.Frame, but when we only have a gdb.PendingFrame. The PendingFrame already has a pointer to the gdbarch internally, this commit just exposes an 'architecture' method to Python, and has this return a gdb.Architecture object (list gdb.Frame.architecture does). gdb/ChangeLog: * python/py-unwind.c (pending_framepy_architecture): New function. (pending_frame_object_methods): Add architecture method. gdb/testsuite/ChangeLog: * gdb.python/py-unwind.py (TestUnwinder::__call__): Add test for gdb.PendingFrame.architecture method. gdb/doc/ChangeLog: * python.texi (Unwinding Frames in Python): Document PendingFrame.architecture method. --- gdb/ChangeLog | 5 +++++ gdb/doc/ChangeLog | 5 +++++ gdb/doc/python.texi | 6 ++++++ gdb/python/py-unwind.c | 20 ++++++++++++++++++++ gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/py-unwind.py | 10 +++++++++- 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index a38f1dab426..e919b3cfd7e 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2518,6 +2518,12 @@ @end defun +@defun PendingFrame.architecture () +Return the @code{gdb.Architecture} (@pxref{Architectures In Python}) +for this @code{gdb.PendingFrame}. This represents the architecture of +the particual frame being unwound. +@end defun + @subheading Unwinder Output: UnwindInfo Use @code{PendingFrame.create_unwind_info} method described above to diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index d583ff462b0..1cef491cedf 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -441,6 +441,22 @@ pending_framepy_create_unwind_info (PyObject *self, PyObject *args) frame_id_build_special (sp, pc, special)); } +/* Implementation of PendingFrame.architecture (self) -> gdb.Architecture. */ + +static PyObject * +pending_framepy_architecture (PyObject *self, PyObject *args) +{ + pending_frame_object *pending_frame = (pending_frame_object *) self; + + if (pending_frame->frame_info == NULL) + { + PyErr_SetString (PyExc_ValueError, + "Attempting to read register from stale PendingFrame"); + return NULL; + } + return gdbarch_to_arch_object (pending_frame->gdbarch); +} + /* frame_unwind.this_id method. */ static void @@ -671,6 +687,10 @@ static PyMethodDef pending_frame_object_methods[] = "create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n" "Construct UnwindInfo for this PendingFrame, using FRAME_ID\n" "to identify it." }, + { "architecture", + pending_framepy_architecture, METH_NOARGS, + "architecture () -> gdb.Architecture\n" + "The architecture for this PendingFrame." }, {NULL} /* Sentinel */ }; diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py index 42dd6fe138c..d01da80f25b 100644 --- a/gdb/testsuite/gdb.python/py-unwind.py +++ b/gdb/testsuite/gdb.python/py-unwind.py @@ -30,7 +30,6 @@ class FrameId(object): def pc(self): return self._pc - class TestUnwinder(Unwinder): AMD64_RBP = 6 AMD64_RSP = 7 @@ -69,6 +68,15 @@ class TestUnwinder(Unwinder): This unwinder recognizes the corrupt frames by checking that *RBP == RBP, and restores previous RBP from the word above it. """ + + # Check that we can access the architecture of the pending + # frame, and that this is the same architecture as for the + # currently selected inferior. + inf_arch = gdb.selected_inferior ().architecture () + frame_arch = pending_frame.architecture () + if (inf_arch != frame_arch): + raise gdb.GdbError ("architecture mismatch") + try: # NOTE: the registers in Unwinder API can be referenced # either by name or by number. The code below uses both -- 2.25.4