From patchwork Thu Mar 30 12:10:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 67118 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 EE4A53854830 for ; Thu, 30 Mar 2023 12:11:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE4A53854830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680178290; bh=FhS9FfB17Fjr0lZuTzHxadBmFfsJUEfyMDd8HkH3aiY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fcQmVHRZeaNuk5O2ttQqJ2526ar0U88/Yl0HCedi/w5J8UvBwcH+AtnagoxOonFAW LY+FVQjcOqFMy/0rwaQZyRDQh8q14shAY3DXbp79Zo25T/0LCHCAQqDdx79Qz9rqJo DwuvtvlZ4NSr1gEABemUFZmwPmTZnohwcpF+5xxU= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id CA27E3858C53 for ; Thu, 30 Mar 2023 12:10:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA27E3858C53 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-n-BwZvh5PSmHWxum-cz_CQ-1; Thu, 30 Mar 2023 08:10:31 -0400 X-MC-Unique: n-BwZvh5PSmHWxum-cz_CQ-1 Received: by mail-wm1-f72.google.com with SMTP id k1-20020a05600c1c8100b003ee6dbceb81so9720791wms.5 for ; Thu, 30 Mar 2023 05:10:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680178230; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FhS9FfB17Fjr0lZuTzHxadBmFfsJUEfyMDd8HkH3aiY=; b=N0zd4kkhq0ERzjF9o3IjFN2PoKx4K8jdRSFpDGzsSDTKrEE1oIXd7wxG3e2VKW/qg0 GufsbNxS/o6Qznn7LdvVrP8/jrANOQ7wWrLJ+8SVDcIt+jhrgTkYjwG8lDhcQVs2fd2m vjdvhAfEZxN/v/aM+fFrVwdzo74p5VJKbaYHXggTVGQ/jiqSJR0KqUVtvu9suu+BH7lf 9X0bkKBdkfTzNBe0x/G9sTGi1uoq0g4RxFTWbxAvezSZaK+g3CkHDOV+rN6dt692/iC8 4pZ/mzThQJ9SrXp5FP2edI0xGwpKcgfS5pLX5bPwm1rFxnjWemOmhg/3lKWeedkNwfD0 MjDQ== X-Gm-Message-State: AAQBX9d1amQqEWA9pZvDCeG/151GXJek2c0WZX8cPUDaW/jb6uOZB3pb Wd7Nx7wA7gqmkBt48I7LA5t9WRqu57vQ+UbSvI6xDjOGiBkVv7Gqz6UL5QYctDl0cg1WMTbid0a nxLsMvpPOHlAjxVfBK0Ka1Za2PdFrzzTmi4gGKrsBBlx3D06St4av7fTgrD+pcScs4UZE57LDYZ JrqaCPSg== X-Received: by 2002:a5d:4a51:0:b0:2d3:33d4:1cfb with SMTP id v17-20020a5d4a51000000b002d333d41cfbmr18189530wrs.36.1680178229797; Thu, 30 Mar 2023 05:10:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Zhq5YnXd2Y1r2rkSlDPGVTcdXNTcYdaELIqPf0DqHVgw68jjQepAQ9KpjpPOz0V0NPav/Bkg== X-Received: by 2002:a5d:4a51:0:b0:2d3:33d4:1cfb with SMTP id v17-20020a5d4a51000000b002d333d41cfbmr18189513wrs.36.1680178229413; Thu, 30 Mar 2023 05:10:29 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id p5-20020a5d4e05000000b002d75909c76esm25871959wrt.73.2023.03.30.05.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 05:10:29 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/4] gdb/python: have PendingFrame methods accept keyword arguments Date: Thu, 30 Mar 2023 13:10:21 +0100 Message-Id: <2b2fd6d7cda91c3bd4f8ea3241041fe6ae44f584.1680177890.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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_H2, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Update the two gdb.PendingFrame methods gdb.PendingFrame.read_register and gdb.PendingFrame.create_unwind_info accept keyword arguments. There's no huge benefit for making this change, both of these methods only take a single argument, so it is (maybe) less likely that a user will take advantage of the keyword arguments in these cases, but I think it's nice to be consistent, and I don't see any particular draw backs to making this change. There should be no user visible changes (for existing code) after this commit. Reviewed-By: Eli Zaretskii --- gdb/doc/python.texi | 10 +++++----- gdb/python/py-unwind.c | 23 ++++++++++++++--------- gdb/testsuite/gdb.python/py-unwind.py | 4 ++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index ef50e6dbe7b..4f62ca7d95e 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2756,11 +2756,11 @@ An object passed to an unwinder (a @code{gdb.PendingFrame} instance) provides a method to read frame's registers: -@defun PendingFrame.read_register (reg) -This method returns the contents of the register @var{reg} in the +@defun PendingFrame.read_register (@var{register}) +This method returns the contents of the register @var{register} in the frame as a @code{gdb.Value} object. For a description of the -acceptable values of @var{reg} see -@ref{gdbpy_frame_read_register,,Frame.read_register}. If @var{reg} +acceptable values of @var{register} see +@ref{gdbpy_frame_read_register,,Frame.read_register}. If @var{register} does not name a register for the current architecture, this method will throw an exception. @@ -2783,7 +2783,7 @@ instance to be returned to @value{GDBN}: @anchor{gdb.PendingFrame.create_unwind_info} -@defun PendingFrame.create_unwind_info (frame_id) +@defun PendingFrame.create_unwind_info (@var{frame_id}) Returns a new @code{gdb.UnwindInfo} instance identified by given @var{frame_id}. The @var{frame_id} is used internally by @value{GDBN} to identify the frames within the current thread's stack. The diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 2e13b84eb12..d83979bed2b 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -443,16 +443,17 @@ pending_framepy_repr (PyObject *self) Returns the value of register REG as gdb.Value instance. */ static PyObject * -pending_framepy_read_register (PyObject *self, PyObject *args) +pending_framepy_read_register (PyObject *self, PyObject *args, PyObject *kw) { pending_frame_object *pending_frame = (pending_frame_object *) self; PENDING_FRAMEPY_REQUIRE_VALID (pending_frame); - int regnum; PyObject *pyo_reg_id; + static const char *keywords[] = { "register", nullptr }; + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, &pyo_reg_id)) + return nullptr; - if (!PyArg_UnpackTuple (args, "read_register", 1, 1, &pyo_reg_id)) - return NULL; + int regnum; if (!gdbpy_parse_register_id (pending_frame->gdbarch, pyo_reg_id, ®num)) return nullptr; @@ -681,7 +682,8 @@ pending_framepy_function (PyObject *self, PyObject *args) PendingFrame.create_unwind_info (self, frameId) -> UnwindInfo. */ static PyObject * -pending_framepy_create_unwind_info (PyObject *self, PyObject *args) +pending_framepy_create_unwind_info (PyObject *self, PyObject *args, + PyObject *kw) { PyObject *pyo_frame_id; CORE_ADDR sp; @@ -690,7 +692,9 @@ pending_framepy_create_unwind_info (PyObject *self, PyObject *args) PENDING_FRAMEPY_REQUIRE_VALID ((pending_frame_object *) self); - if (!PyArg_ParseTuple (args, "O:create_unwind_info", &pyo_frame_id)) + static const char *keywords[] = { "frame_id", nullptr }; + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O", keywords, + &pyo_frame_id)) return nullptr; pyuw_get_attr_code code @@ -1002,11 +1006,12 @@ gdbpy_initialize_unwind (void) static PyMethodDef pending_frame_object_methods[] = { - { "read_register", pending_framepy_read_register, METH_VARARGS, + { "read_register", (PyCFunction) pending_framepy_read_register, + METH_VARARGS | METH_KEYWORDS, "read_register (REG) -> gdb.Value\n" "Return the value of the REG in the frame." }, - { "create_unwind_info", - pending_framepy_create_unwind_info, METH_VARARGS, + { "create_unwind_info", (PyCFunction) pending_framepy_create_unwind_info, + METH_VARARGS | METH_KEYWORDS, "create_unwind_info (FRAME_ID) -> gdb.UnwindInfo\n" "Construct UnwindInfo for this PendingFrame, using FRAME_ID\n" "to identify it." }, diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py index 5853abc7486..201b629f9fe 100644 --- a/gdb/testsuite/gdb.python/py-unwind.py +++ b/gdb/testsuite/gdb.python/py-unwind.py @@ -99,7 +99,7 @@ class TestUnwinder(Unwinder): read_register_error = str(ve) frame_id = FrameId( - pending_frame.read_register(TestUnwinder.AMD64_RSP), + pending_frame.read_register(register=TestUnwinder.AMD64_RSP), pending_frame.read_register(TestUnwinder.AMD64_RIP), ) unwind_info = pending_frame.create_unwind_info(frame_id) @@ -156,7 +156,7 @@ class simple_unwinder(Unwinder): captured_pending_frame = pending_frame captured_pending_frame_repr = repr(pending_frame) fid = FrameId(self._sp, self._pc) - uw = pending_frame.create_unwind_info(fid) + uw = pending_frame.create_unwind_info(frame_id=fid) uw.add_saved_register("rip", gdb.Value(0x123)) uw.add_saved_register("rbp", gdb.Value(0x456)) uw.add_saved_register("rsp", gdb.Value(0x789))