From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120849 invoked by alias); 30 Apr 2018 13:11:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 120838 invoked by uid 89); 30 Apr 2018 13:11:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f41.google.com Received: from mail-wm0-f41.google.com (HELO mail-wm0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Apr 2018 13:11:41 +0000 Received: by mail-wm0-f41.google.com with SMTP id j5so14177087wme.5 for ; Mon, 30 Apr 2018 06:11:40 -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:to:references:from:message-id:date :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=/xlX0Wg1+nDvAaYnGgXktNwAT/ndBcS4rsdVXZMBYQ4=; b=AI+taUtAJXIa6IjIuPcGe0dkX2LjcnmWZcXiMYTQzcNyukCpAt+hhAFfKrPpnmzMcZ Qu3qYr+vsQE+D7k4UwzYAsO8OB1fdCOFea/efjXdc+UyEhjp/TWHgxZIeec+5ULTtODY ha3eejD3mUR2O0wjO1CgqxqOXF2yuQNssg3Z2RoZTvGx0aDfzGCvOeBNTP/uxpGtpmiE Yh+rcb/wS9s2HjTOpgEGdAncUL9QXK49HkaJAcV5Y71raJ6NQG4C56bh8qpq8i+URz5J ECnKU5HhbcbzJUCe8w1Id2VzR6+DZOk5ZEZ0h1mV0LaU8R2KfTftR18rrNMdKIfDZ0do eH9w== X-Gm-Message-State: ALQs6tAtUjPu5bRvnJQ0ZDrW0IZEzsZG9L62GmRaX2z31U1b3lp9stq2 Uw618U3nleOfz1GU8UPpsh9tV1sH938= X-Google-Smtp-Source: AB8JxZrotQNOKgLJZGNXLwgu45/u5T7KXjiNpv9BZj8872E2PacOdD9J+N0k+IsJHWnR/5atp0XJ3g== X-Received: by 10.28.26.83 with SMTP id a80mr7836265wma.36.1525093898832; Mon, 30 Apr 2018 06:11:38 -0700 (PDT) Received: from ?IPv6:2a02:c7f:ae6a:ed00:4685:ff:fe66:9f4? ([2a02:c7f:ae6a:ed00:4685:ff:fe66:9f4]) by smtp.gmail.com with ESMTPSA id c124sm7659098wmd.36.2018.04.30.06.11.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 06:11:38 -0700 (PDT) Subject: Re: [RFA] Add basic Python API for convenience variables To: gdb-patches@sourceware.org References: <20180422211309.31251-1-tom@tromey.com> From: Phil Muldoon Message-ID: Date: Mon, 30 Apr 2018 13:11:00 -0000 MIME-Version: 1.0 In-Reply-To: <20180422211309.31251-1-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-04/txt/msg00621.txt.bz2 On 22/04/18 22:13, Tom Tromey wrote: > This adds a basic Python API for accessing convenience variables. > With this, convenience variables can be read and set from Python. > Although gdb supports convenience variables whose value changes at > each call, this is not exposed to Python; it could be, but I think > it's just as good to write a convenience function in this situation. > > > @findex gdb.find_pc_line > diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c > index bba6d0b8a4..30a0082da8 100644 > --- a/gdb/python/py-value.c > +++ b/gdb/python/py-value.c > @@ -1746,6 +1746,83 @@ gdbpy_history (PyObject *self, PyObject *args) > return value_to_value_object (res_val); > } > > +/* Return the value of a convenience variable. */ > +PyObject * > +gdbpy_convenience_variable (PyObject *self, PyObject *args) > +{ > + const char *varname; > + struct value *res_val = NULL; > + > + if (!PyArg_ParseTuple (args, "s", &varname)) > + return NULL; > + > + TRY > + { > + struct internalvar *var = lookup_only_internalvar (varname); > + > + if (var != NULL) > + { > + res_val = value_of_internalvar (python_gdbarch, var); > + if (TYPE_CODE (value_type (res_val)) == TYPE_CODE_VOID) > + res_val = NULL; > + } > + } > + CATCH (except, RETURN_MASK_ALL) > + { > + GDB_PY_HANDLE_EXCEPTION (except); > + } > + END_CATCH > + > + if (res_val == NULL) > + Py_RETURN_NONE; > + > + return value_to_value_object (res_val); > +} > + > +/* Set the value of a convenience variable. */ > +PyObject * > +gdbpy_set_convenience_variable (PyObject *self, PyObject *args) > +{ > + const char *varname; > + PyObject *value_obj; > + struct value *value = NULL; > + > + if (!PyArg_ParseTuple (args, "sO", &varname, &value_obj)) > + return NULL; > + > + /* None means to clear the variable. */ > + if (value_obj != Py_None) > + { > + value = convert_value_from_python (value_obj); > + if (value == NULL) > + return NULL; > + } > + > + TRY > + { > + if (value == NULL) > + { > + struct internalvar *var = lookup_only_internalvar (varname); > + > + if (var != NULL) > + clear_internalvar (var); > + } > + else > + { > + struct internalvar *var = lookup_internalvar (varname); > + > + set_internalvar (var, value); > + } > + } > + CATCH (except, RETURN_MASK_ALL) > + { > + GDB_PY_HANDLE_EXCEPTION (except); > + } > + END_CATCH > + > + Py_RETURN_NONE; > +} > + I've read the patch and it LGTM. Cheers Phil