public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use gdbpy_enter in py-breakpoint.c
@ 2019-06-10 13:28 Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2019-06-10 13:28 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=25ce02ee7b7667fb7bb882421ff869c080777bee

commit 25ce02ee7b7667fb7bb882421ff869c080777bee
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Jun 7 16:08:47 2019 -0600

    Use gdbpy_enter in py-breakpoint.c
    
    A few spots in py-breakpoint.c acquire the GIL manually.  However,
    because these spots generate events, and because events are expected
    to be arbitrary gdb-flavored Python code, it's important to use
    gdbpy_enter instead, in order to ensure that the other gdb-related
    Python globals are set correctly.
    
    This patch makes this change.  Tested on x86-64 Fedora 29.
    
    gdb/ChangeLog
    2019-06-10  Tom Tromey  <tom@tromey.com>
    
    	* python/py-breakpoint.c (gdbpy_breakpoint_created)
    	(gdbpy_breakpoint_deleted, gdbpy_breakpoint_modified): Use
    	gdbpy_enter.

Diff:
---
 gdb/ChangeLog              |  6 ++++++
 gdb/python/py-breakpoint.c | 18 ++++++++----------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 795ba45..8868073 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-10  Tom Tromey  <tom@tromey.com>
+
+	* python/py-breakpoint.c (gdbpy_breakpoint_created)
+	(gdbpy_breakpoint_deleted, gdbpy_breakpoint_modified): Use
+	gdbpy_enter.
+
 2019-06-10  Tom Tromey  <tromey@adacore.com>
 
 	* elfread.c (elf_read_minimal_symbols): Don't set the dbx objfile
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index fc9543e..88cd7de 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -1003,7 +1003,6 @@ static void
 gdbpy_breakpoint_created (struct breakpoint *bp)
 {
   gdbpy_breakpoint_object *newbp;
-  PyGILState_STATE state;
 
   if (!user_breakpoint_p (bp) && bppy_pending_object == NULL)
     return;
@@ -1015,7 +1014,8 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
       && bp->type != bp_access_watchpoint)
     return;
 
-  state = PyGILState_Ensure ();
+  struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
+  gdbpy_enter enter_py (garch, current_language);
 
   if (bppy_pending_object)
     {
@@ -1046,8 +1046,6 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
 			   gdb_py_events.breakpoint_created) < 0)
 	gdbpy_print_stack ();
     }
-
-  PyGILState_Release (state);
 }
 
 /* Callback that is used when a breakpoint is deleted.  This will
@@ -1056,13 +1054,14 @@ static void
 gdbpy_breakpoint_deleted (struct breakpoint *b)
 {
   int num = b->number;
-  PyGILState_STATE state;
   struct breakpoint *bp = NULL;
 
-  state = PyGILState_Ensure ();
   bp = get_breakpoint (num);
   if (bp)
     {
+      struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
+      gdbpy_enter enter_py (garch, current_language);
+
       gdbpy_ref<gdbpy_breakpoint_object> bp_obj (bp->py_bp_object);
       if (bp_obj != NULL)
 	{
@@ -1077,7 +1076,6 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
 	  --bppy_live;
 	}
     }
-  PyGILState_Release (state);
 }
 
 /* Callback that is used when a breakpoint is modified.  */
@@ -1086,13 +1084,14 @@ static void
 gdbpy_breakpoint_modified (struct breakpoint *b)
 {
   int num = b->number;
-  PyGILState_STATE state;
   struct breakpoint *bp = NULL;
 
-  state = PyGILState_Ensure ();
   bp = get_breakpoint (num);
   if (bp)
     {
+      struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
+      gdbpy_enter enter_py (garch, current_language);
+
       PyObject *bp_obj = (PyObject *) bp->py_bp_object;
       if (bp_obj)
 	{
@@ -1104,7 +1103,6 @@ gdbpy_breakpoint_modified (struct breakpoint *b)
 	    }
 	}
     }
-  PyGILState_Release (state);
 }


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [binutils-gdb] Use gdbpy_enter in py-breakpoint.c
@ 2017-01-11  5:22 Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2017-01-11  5:22 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=de2dc875c2ddb731741f3c326545ff91fd587dd5

commit de2dc875c2ddb731741f3c326545ff91fd587dd5
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Nov 7 15:59:41 2016 -0700

    Use gdbpy_enter in py-breakpoint.c
    
    Change py-breakpoint.c to use gdbpy_enter.
    
    2017-01-10  Tom Tromey  <tom@tromey.com>
    
    	* python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Use
    	gdbpy_enter.
    	(gdbpy_breakpoint_has_cond): Likewise.

Diff:
---
 gdb/ChangeLog              |  6 ++++++
 gdb/python/py-breakpoint.c | 14 ++++----------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b64e9e9..fb156a9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
+	* python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Use
+	gdbpy_enter.
+	(gdbpy_breakpoint_has_cond): Likewise.
+
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
 	* python/python.c (gdbpy_enter): New constructor.
 	(~gdbpy_enter): New destructor.
 	(restore_python_env, ensure_python_env): Rewrite.
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index eedb697..f3520cc 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -791,14 +791,14 @@ gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn *extlang,
   struct gdbpy_breakpoint_object *bp_obj = b->py_bp_object;
   PyObject *py_bp = (PyObject *) bp_obj;
   struct gdbarch *garch;
-  struct cleanup *cleanup;
 
   if (bp_obj == NULL)
     return EXT_LANG_BP_STOP_UNSET;
 
   stop = -1;
   garch = b->gdbarch ? b->gdbarch : get_current_arch ();
-  cleanup = ensure_python_env (garch, current_language);
+
+  gdbpy_enter enter_py (garch, current_language);
 
   if (bp_obj->is_finish_bp)
     bpfinishpy_pre_stop_hook (bp_obj);
@@ -829,8 +829,6 @@ gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn *extlang,
   if (bp_obj->is_finish_bp)
     bpfinishpy_post_stop_hook (bp_obj);
 
-  do_cleanups (cleanup);
-
   if (stop < 0)
     return EXT_LANG_BP_STOP_UNSET;
   return stop ? EXT_LANG_BP_STOP_YES : EXT_LANG_BP_STOP_NO;
@@ -844,21 +842,17 @@ int
 gdbpy_breakpoint_has_cond (const struct extension_language_defn *extlang,
 			   struct breakpoint *b)
 {
-  int has_func;
   PyObject *py_bp;
   struct gdbarch *garch;
-  struct cleanup *cleanup;
 
   if (b->py_bp_object == NULL)
     return 0;
 
   py_bp = (PyObject *) b->py_bp_object;
   garch = b->gdbarch ? b->gdbarch : get_current_arch ();
-  cleanup = ensure_python_env (garch, current_language);
-  has_func = PyObject_HasAttrString (py_bp, stop_func);
-  do_cleanups (cleanup);
 
-  return has_func;
+  gdbpy_enter enter_py (garch, current_language);
+  return PyObject_HasAttrString (py_bp, stop_func);
 }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-10 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 13:28 [binutils-gdb] Use gdbpy_enter in py-breakpoint.c Tom Tromey
  -- strict thread matches above, loose matches on Subject: below --
2017-01-11  5:22 Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).