Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <xdje42@gmail.com>
To: Siva Chandra <sivachandra@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [Patch v18 4/4] Add xmethod support to the Python API
Date: Wed, 28 May 2014 05:02:00 -0000	[thread overview]
Message-ID: <m3mwe2fqcp.fsf@sspiff.org> (raw)
In-Reply-To: <m3ha4dh1vq.fsf@sspiff.org> (Doug Evans's message of "Sun, 25 May	2014 16:31:05 -0700")

Doug Evans <xdje42@gmail.com> writes:

> This whole block from here ...
>
>> +  obj_type = check_typedef (value_type (obj));
>> +  this_type = check_typedef (type_object_to_type (worker_data->this_type));
>> +  if (TYPE_CODE (obj_type) == TYPE_CODE_PTR)
>> +    {
>> +      struct type *this_ptr = lookup_pointer_type (this_type);
>> +
>> +      if (!types_equal (obj_type, this_ptr))
>> +	obj = value_cast (this_ptr, obj);
>> +    }
>> +  else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
>> +    {
>> +      struct type *this_ref = lookup_reference_type (this_type);
>> +
>> +      if (!types_equal (obj_type, this_ref))
>> +	obj = value_cast (this_ref, obj);
>> +    }
>> +  else
>> +    {
>> +      if (!types_equal (obj_type, this_type))
>> +	obj = value_cast (this_type, obj);
>> +    }
>> +  py_value_obj = value_to_value_object (obj);
>> +  if (py_value_obj == NULL)
>> +    {
>> +      gdbpy_print_stack ();
>> +      do_cleanups (cleanups);
>> +
>> +      return EXT_LANG_RC_ERROR;
>> +    }
>> +  make_cleanup_py_decref (py_value_obj);
>
> ... to here needs to be wrapped in a TRY_CATCH.
> There's several examples in python/*.c
> The problem here is that check_typedef and value_cast can throw gdb
> exceptions.  We need to catch them, flag them if necessary, and
> return EXT_LANG_RC_ERROR (I think).

Ok, let's do this.

extension.c:invoke_xmethod will throw an error if this function
returns EXT_LANG_RC_ERROR:

  if (rc == EXT_LANG_RC_ERROR)
    {
      error (_("Error while invoking a xmethod defined in %s"),
	     worker->extlang->capitalized_name);
    }

So there's no real difference between a gdb-detected error in, say,
value_cast and a python-detected error from invoking the xmethod.
So why not have gdbpy_invoke_xmethod return a struct value *,
and if a python error is detected then throw a gdb error.

IOW:

struct value *
gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
		      struct xmethod_worker *worker,
		      struct value *obj, struct value **args, int nargs)
{
  ...
  if (error_return_from_python)
    {
      gdbpy_print_stack ();
      error (_("Error while executing Python code."));
    }
  ...
}


  reply	other threads:[~2014-05-28  5:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-23 21:02 Siva Chandra
2014-05-25 23:31 ` Doug Evans
2014-05-28  5:02   ` Doug Evans [this message]
2014-05-28 20:44     ` Siva Chandra
2014-05-28 20:58       ` Doug Evans
2014-05-28  5:41 ` Doug Evans
2014-05-28 19:12   ` Siva Chandra
2014-05-28 20:31     ` Doug Evans

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=m3mwe2fqcp.fsf@sspiff.org \
    --to=xdje42@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sivachandra@google.com \
    /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