From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1981 invoked by alias); 28 May 2014 05:02:37 -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 1967 invoked by uid 89); 28 May 2014 05:02:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f48.google.com Received: from mail-pb0-f48.google.com (HELO mail-pb0-f48.google.com) (209.85.160.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 28 May 2014 05:02:34 +0000 Received: by mail-pb0-f48.google.com with SMTP id rr13so10493583pbb.35 for ; Tue, 27 May 2014 22:02:33 -0700 (PDT) X-Received: by 10.68.240.68 with SMTP id vy4mr42200417pbc.127.1401253352938; Tue, 27 May 2014 22:02:32 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-50-sfba.hfc.comcastbusiness.net. [173.13.178.50]) by mx.google.com with ESMTPSA id ck10sm83038209pac.0.2014.05.27.22.02.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 May 2014 22:02:32 -0700 (PDT) From: Doug Evans To: Siva Chandra Cc: gdb-patches Subject: Re: [Patch v18 4/4] Add xmethod support to the Python API References: Date: Wed, 28 May 2014 05:02:00 -0000 In-Reply-To: (Doug Evans's message of "Sun, 25 May 2014 16:31:05 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2014-05/txt/msg00686.txt.bz2 Doug Evans 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.")); } ... }