Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: gdb-patches@sourceware.org
Subject: Re: [RFA] Add basic Python API for convenience variables
Date: Mon, 30 Apr 2018 13:11:00 -0000	[thread overview]
Message-ID: <c4163ca2-2faa-77e1-961c-b89eae08183c@redhat.com> (raw)
In-Reply-To: <20180422211309.31251-1-tom@tromey.com>

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


  parent reply	other threads:[~2018-04-30 13:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-22 21:13 Tom Tromey
2018-04-23 16:53 ` Eli Zaretskii
2018-04-30 13:11 ` Phil Muldoon [this message]
2018-05-09 15:43 ` Tom Tromey
2018-05-25 17:31   ` Tom Tromey
2018-05-30 23:14 ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c4163ca2-2faa-77e1-961c-b89eae08183c@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox