From patchwork Thu Nov 10 22:19:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17402 Received: (qmail 82881 invoked by alias); 10 Nov 2016 22:26:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 82862 invoked by uid 89); 10 Nov 2016 22:26:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=sk:bootstr X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 10 Nov 2016 22:26:42 +0000 Received: (qmail 9493 invoked by uid 0); 10 Nov 2016 22:20:01 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy10.mail.unifiedlayer.com with SMTP; 10 Nov 2016 22:20:01 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 6NKx1u00B2f2jeq01NL0sr; Thu, 10 Nov 2016 15:20:00 -0700 X-Authority-Analysis: v=2.1 cv=beT4Do/B c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=FVNSiQe__sg7vFcdMX4A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:60120 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c4xhO-0002sd-FZ; Thu, 10 Nov 2016 15:19:58 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 12/20] Introduce htab_up and use gdbpy_enter in py-framefilter.c Date: Thu, 10 Nov 2016 15:19:39 -0700 Message-Id: <1478816387-27064-13-git-send-email-tom@tromey.com> In-Reply-To: <1478816387-27064-1-git-send-email-tom@tromey.com> References: <1478816387-27064-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c4xhO-0002sd-FZ X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:60120 X-Source-Auth: tom+tromey.com X-Email-Count: 13 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This introduces a new "htab_up" typedef, which is a std::unique_ptr that can call htab_delete. Then it changes some code in py-framefilter.c to use both gdbpy_enter and the new htab_up. 2016-11-10 Tom Tromey * utils.h (htab_deleter): New struct. (htab_up): New typedef. * python/py-framefilter.c (gdbpy_apply_frame_filter): Use gdbpy_enter, gdbpy_reference, htab_up. --- gdb/ChangeLog | 7 ++++++ gdb/python/py-framefilter.c | 55 +++++++++++++++++---------------------------- gdb/utils.h | 12 ++++++++++ 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 2101045..80d4329 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2016-11-10 Tom Tromey + * utils.h (htab_deleter): New struct. + (htab_up): New typedef. + * python/py-framefilter.c (gdbpy_apply_frame_filter): Use + gdbpy_enter, gdbpy_reference, htab_up. + +2016-11-10 Tom Tromey + * python/py-unwind.c (pending_frame_invalidate): Remove. (pyuw_sniffer): Use gdbpy_enter and gdbpy_reference. diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index 021b3d4..b14440a 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -1491,11 +1491,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, struct ui_out *out, int frame_low, int frame_high) { struct gdbarch *gdbarch = NULL; - struct cleanup *cleanups; enum ext_lang_bt_status success = EXT_LANG_BT_ERROR; - PyObject *iterable; - PyObject *item; - htab_t levels_printed; if (!gdb_python_initialized) return EXT_LANG_BT_NO_FILTERS; @@ -1511,9 +1507,10 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, } END_CATCH - cleanups = ensure_python_env (gdbarch, current_language); + gdbpy_enter enter_py (gdbarch, current_language); - iterable = bootstrap_python_frame_filters (frame, frame_low, frame_high); + gdbpy_reference iterable (bootstrap_python_frame_filters (frame, frame_low, + frame_high)); if (iterable == NULL) { @@ -1531,34 +1528,36 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, default backtrace. */ gdbpy_print_stack (); - do_cleanups (cleanups); return EXT_LANG_BT_NO_FILTERS; } /* If iterable is None, then there are no frame filters registered. If this is the case, defer to default GDB printing routines in MI and CLI. */ - make_cleanup_py_decref (iterable); if (iterable == Py_None) - { - success = EXT_LANG_BT_NO_FILTERS; - goto done; - } + return EXT_LANG_BT_NO_FILTERS; - levels_printed = htab_create (20, - htab_hash_pointer, - htab_eq_pointer, - NULL); - make_cleanup_htab_delete (levels_printed); + htab_up levels_printed (htab_create (20, + htab_hash_pointer, + htab_eq_pointer, + NULL)); - while ((item = PyIter_Next (iterable))) + while (true) { - struct cleanup *item_cleanup = make_cleanup_py_decref (item); + gdbpy_reference item (PyIter_Next (iterable.get ())); - success = py_print_frame (item, flags, args_type, out, 0, - levels_printed); + if (item == NULL) + { + if (PyErr_Occurred ()) + { + gdbpy_print_stack (); + return EXT_LANG_BT_ERROR; + } + break; + } - do_cleanups (item_cleanup); + success = py_print_frame (item.get (), flags, args_type, out, 0, + levels_printed.get ()); /* Do not exit on error printing a single frame. Print the error and continue with other frames. */ @@ -1566,17 +1565,5 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang, gdbpy_print_stack (); } - if (item == NULL && PyErr_Occurred ()) - goto error; - - done: - do_cleanups (cleanups); return success; - - /* Exit and abandon backtrace on error, printing the exception that - is set. */ - error: - gdbpy_print_stack (); - do_cleanups (cleanups); - return EXT_LANG_BT_ERROR; } diff --git a/gdb/utils.h b/gdb/utils.h index 36f5294..a1692c6 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -99,6 +99,18 @@ extern struct cleanup *make_cleanup_free_so (struct so_list *so); extern struct cleanup *make_cleanup_restore_current_language (void); +/* A deleter for a hash table. */ +struct htab_deleter +{ + void operator() (htab *ptr) const + { + htab_delete (ptr); + } +}; + +/* A unique_ptr wrapper for htab_t. */ +typedef std::unique_ptr htab_up; + extern struct cleanup *make_cleanup_htab_delete (htab_t htab); struct parser_state;