From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14490 invoked by alias); 14 Feb 2017 18:03:09 -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 13172 invoked by uid 89); 14 Feb 2017 18:03:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS,URIBL_RED autolearn=no version=3.3.2 spammy=sk:get_cur, Apr, arnezlinuxvnetibmcom, arnez@linux.vnet.ibm.com X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Tue, 14 Feb 2017 18:02:58 +0000 Received: (qmail 16812 invoked by uid 0); 14 Feb 2017 18:02:56 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy5.mail.unifiedlayer.com with SMTP; 14 Feb 2017 18:02:56 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id ki2B1u01D2f2jeq01i2GEg; Tue, 14 Feb 2017 11:02:18 -0700 X-Authority-Analysis: v=2.1 cv=WOnsABcR 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=n2v9WMKugxEA:10 a=pGLkceISAAAA:8 a=zstS-IiYAAAA:8 a=QyXUC8HyAAAA:8 a=lzDhS8hmAAAA:8 a=VnNF1IyMAAAA:8 a=09Eu5WC0LB9X0d1WD_UA:9 a=6kGIvZw6iX1k4Y-7sg4_:22 a=4G6NA9xxw8l3yy4pmD5M:22 a=avl4LiGQNoF5OB0DmCJ7:22 a=rigQk1bY_8VmChEzA3fK:22 a=skCgnbhlp52w9zbo2JeP:22 Received: from 174-16-128-54.hlrn.qwest.net ([174.16.128.54]:34434 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cdhQZ-00068G-3H; Tue, 14 Feb 2017 11:02:11 -0700 From: Tom Tromey To: Yao Qi Cc: Tom Tromey , "gdb-patches\@sourceware.org" Subject: Re: [RFA] PR python/13598 - add before_prompt event References: <1463806850-11001-1-git-send-email-tom@tromey.com> <87y3xc4u9e.fsf@tromey.com> Date: Tue, 14 Feb 2017 18:03:00 -0000 In-Reply-To: (Yao Qi's message of "Sun, 12 Feb 2017 23:02:38 +0000") Message-ID: <87mvdozm5b.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BWhitelist: no X-Exim-ID: 1cdhQZ-00068G-3H X-Source-Sender: 174-16-128-54.hlrn.qwest.net (bapiya) [174.16.128.54]:34434 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2017-02/txt/msg00393.txt.bz2 >>>>> "Yao" == Yao Qi writes: Yao> I am convinced by your arguments. Your patch is good to me. Thanks! The patch needed a minor tweak to account for changes that have happened in the meantime; and the buildbot pointed out that the patch put a #include in the wrong spot, breaking the disable-python build. I'm appending the version I'm checking in, which fixes both of these (trivial) problems. Tested on the buildbot and locally on x86-64 Fedora 25. Tom commit 3f77c7691fc5ff92eef90f39bb972f25c7422fb0 Author: Tom Tromey Date: Wed Apr 29 09:44:24 2015 -0600 PR python/13598 - add before_prompt event This adds an event that is emitted just before GDB presents a prompt to the user. This provides Python code a way to react to whatever changes might have been made by the previous command. For example, in my GUI I use this to track changes to the selected frame and reflect them in the UI. Built and regtested on x86-64 Fedora 23. gdb/ChangeLog 2017-02-14 Tom Tromey PR python/13598: * python/python.c (gdbpy_before_prompt_hook): Emit before_prompt event. * python/py-evts.c (gdbpy_initialize_py_events): Add before_prompt registry. * python/py-events.h (events_object) : New field. gdb/doc/ChangeLog 2017-02-14 Tom Tromey PR python/13598: * python.texi (Events In Python): Document events.before_prompt. gdb/testsuite/ChangeLog 2017-02-14 Tom Tromey PR python/13598: * gdb.python/py-events.exp: Add before_prompt event tests. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ae33435..2cd6ac9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2017-02-14 Tom Tromey + + PR python/13598: + * python/python.c (gdbpy_before_prompt_hook): Emit before_prompt + event. + * python/py-evts.c (gdbpy_initialize_py_events): Add + before_prompt registry. + * python/py-events.h (events_object) : New field. + 2017-02-14 Markus Metzger * btrace.c (ftrace_new_switch): Preserve up link and flags. diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 7f125bc..0b6139d 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2017-02-14 Tom Tromey + + PR python/13598: + * python.texi (Events In Python): Document events.before_prompt. + 2017-02-13 Luis Machado * gdb.texinfo (Target Commands): Document the optional offset diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index d1cbadb..c3ea203 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2981,6 +2981,10 @@ emitted, the @code{gdb.Breakpoint} object will already be in its invalid state; that is, the @code{is_valid} method will return @code{False}. +@item events.before_prompt +This event carries no payload. It is emitted each time @value{GDBN} +presents a prompt to the user. + @end table @node Threads In Python diff --git a/gdb/python/py-events.h b/gdb/python/py-events.h index 98eb609..348dabc 100644 --- a/gdb/python/py-events.h +++ b/gdb/python/py-events.h @@ -53,6 +53,7 @@ typedef struct eventregistry_object *breakpoint_created; eventregistry_object *breakpoint_deleted; eventregistry_object *breakpoint_modified; + eventregistry_object *before_prompt; PyObject *module; diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c index dc7117f..4766bd6 100644 --- a/gdb/python/py-evts.c +++ b/gdb/python/py-evts.c @@ -100,6 +100,9 @@ gdbpy_initialize_py_events (void) "breakpoint_modified") < 0) return -1; + if (add_new_registry (&gdb_py_events.before_prompt, "before_prompt") < 0) + return -1; + if (gdb_pymodule_addobject (gdb_module, "events", (PyObject *) gdb_py_events.module) < 0) diff --git a/gdb/python/python.c b/gdb/python/python.c index f878f9a..73fb3d0 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -100,6 +100,7 @@ const struct extension_language_defn extension_language_python = #include "interps.h" #include "event-top.h" #include "py-ref.h" +#include "py-event.h" /* True if Python has been successfully initialized, false otherwise. */ @@ -969,6 +970,10 @@ gdbpy_before_prompt_hook (const struct extension_language_defn *extlang, gdbpy_enter enter_py (get_current_arch (), current_language); + if (!evregpy_no_listeners_p (gdb_py_events.before_prompt) + && evpy_emit_event (NULL, gdb_py_events.before_prompt) < 0) + return EXT_LANG_RC_ERROR; + if (gdb_python_module && PyObject_HasAttrString (gdb_python_module, "prompt_hook")) { diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a54eb67..a67a69c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-14 Tom Tromey + + PR python/13598: + * gdb.python/py-events.exp: Add before_prompt event tests. + 2017-02-14 Andreas Arnez * gdb.dwarf2/implptrpiece.exp: Fix check for big-endian targets. diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 16ea110..8ec2dd1 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -210,3 +210,28 @@ gdb_test "continue" ".*event type: continue.* .*exit code: 12.* .*exit inf: 2.* dir ok: True.*" "Inferior 2 terminated." + + +# Test before_prompt event. +gdb_py_test_multiple "define new user command" \ + "define xxz" "End with a line saying just .end.." \ + "set variable \$x = 72" "" \ + "set variable \$y = 93" "" \ + "end" "" + +gdb_py_test_multiple "add before_prompt listener" \ + "python" "" \ + "count = 0" "" \ + "def listener():" "" \ + " global count" "" \ + " count = count + 1" "" \ + "gdb.events.before_prompt.connect(listener)" "" \ + "end" "" + +gdb_test_no_output "set variable \$x = 32" "do something" +# Result is due to one emitted before "set var" and one emitted before +# this command. +gdb_test "python print(count)" 2 "check for before_prompt event" + +gdb_test_no_output "xxz" "run a canned sequence" +gdb_test "python print(count)" 4 "check for before_prompt event"