[1/2,gdb/python] Use GDB_PY_HANDLE_EXCEPTION more often

Message ID 20240821165308.11295-1-tdevries@suse.de
State Committed
Headers
Series [1/2,gdb/python] Use GDB_PY_HANDLE_EXCEPTION more often |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Aug. 21, 2024, 4:53 p.m. UTC
  I found a few more places where we can use GDB_PY_HANDLE_EXCEPTION.

Tested on x86_64-linux.
---
 gdb/python/py-arch.c          | 3 +--
 gdb/python/py-breakpoint.c    | 3 +--
 gdb/python/py-connection.c    | 3 +--
 gdb/python/py-frame.c         | 6 ++----
 gdb/python/py-gdb-readline.c  | 3 +--
 gdb/python/py-mi.c            | 3 +--
 gdb/python/py-record-btrace.c | 3 +--
 gdb/python/py-record.c        | 7 ++-----
 gdb/python/py-stopevent.c     | 3 +--
 gdb/python/py-tui.c           | 3 +--
 gdb/python/py-value.c         | 3 +--
 gdb/python/python.c           | 3 +--
 12 files changed, 14 insertions(+), 29 deletions(-)


base-commit: 28c3bf55f0f9aca8619c6d01be34a02a887c5577
  

Comments

Tom Tromey Aug. 23, 2024, 3:52 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> I found a few more places where we can use GDB_PY_HANDLE_EXCEPTION.

This is ok.  Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Tom de Vries Aug. 27, 2024, 7:22 a.m. UTC | #2
On 8/23/24 17:52, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> I found a few more places where we can use GDB_PY_HANDLE_EXCEPTION.
> 
> This is ok.  Thank you.
> Approved-By: Tom Tromey <tom@tromey.com>

Hi Tom,

thanks for the reviews.

I found another spot to use GDB_PY_SET_HANDLE_EXCEPTION, in 
python/py-finishbreakpoint.c.

I've pushed the series with that additional change.

Thanks,
- Tom
  

Patch

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index c6f566221d8..178efab4cee 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -199,8 +199,7 @@  archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 	}
       catch (const gdb_exception &except)
 	{
-	  gdbpy_convert_exception (except);
-	  return NULL;
+	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
 
       gdbpy_ref<> pc_obj = gdb_py_object_from_ulongest (pc);
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index e7dd47020c5..0bb7d44cfea 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -640,8 +640,7 @@  bppy_get_commands (PyObject *self, void *closure)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return NULL;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   return host_string_to_python_string (stb.c_str ()).release ();
diff --git a/gdb/python/py-connection.c b/gdb/python/py-connection.c
index dcca76b7867..79e27677442 100644
--- a/gdb/python/py-connection.c
+++ b/gdb/python/py-connection.c
@@ -431,8 +431,7 @@  connpy_send_packet (PyObject *self, PyObject *args, PyObject *kw)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return nullptr;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 }
 
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index bbb42afb2ed..7f617fa5cea 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -389,8 +389,7 @@  frame_info_to_frame_object (const frame_info_ptr &frame)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return NULL;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   return (PyObject *) frame_obj.release ();
@@ -538,8 +537,7 @@  frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
 	}
       catch (const gdb_exception &except)
 	{
-	  gdbpy_convert_exception (except);
-	  return NULL;
+	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
 
       if (!var)
diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c
index 92287eea7c9..14a76b4fa13 100644
--- a/gdb/python/py-gdb-readline.c
+++ b/gdb/python/py-gdb-readline.c
@@ -59,8 +59,7 @@  gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
       /* This readline callback is called without the GIL held.  */
       gdbpy_gil gil;
 
-      gdbpy_convert_exception (except);
-      return NULL;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   /* Detect EOF (Ctrl-D).  */
diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c
index bc95e86a456..0a636543f9a 100644
--- a/gdb/python/py-mi.c
+++ b/gdb/python/py-mi.c
@@ -168,8 +168,7 @@  gdbpy_execute_mi_command (PyObject *self, PyObject *args, PyObject *kw)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return nullptr;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   return uiout.result ().release ();
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 68b474cc1b4..30d0e8305db 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -318,8 +318,7 @@  recpy_bt_insn_decoded (PyObject *self, void *closure)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return NULL;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   return PyBytes_FromString (strfile.string ().c_str ());
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index 2e0834c15ac..759bf3049cb 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -670,7 +670,6 @@  gdbpy_start_recording (PyObject *self, PyObject *args)
 {
   const char *method = NULL;
   const char *format = NULL;
-  PyObject *ret = NULL;
 
   if (!PyArg_ParseTuple (args, "|ss", &method, &format))
     return NULL;
@@ -678,14 +677,12 @@  gdbpy_start_recording (PyObject *self, PyObject *args)
   try
     {
       record_start (method, format, 0);
-      ret = gdbpy_current_recording (self, args);
+      return gdbpy_current_recording (self, args);
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
-
-  return ret;
 }
 
 /* Implementation of gdb.current_recording (self) -> gdb.Record.  */
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index be26bc17f85..47f81bd6c9a 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -74,8 +74,7 @@  py_print_bpstat (bpstat *bs, enum gdb_signal stop_signal)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return nullptr;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   gdbpy_ref<> dict = uiout.result ();
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 984fa9b6b45..3bcd02da387 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -415,8 +415,7 @@  gdbpy_register_tui_window (PyObject *self, PyObject *args, PyObject *kw)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return nullptr;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   Py_RETURN_NONE;
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 5c62ef681d4..14daa7d46df 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -2056,8 +2056,7 @@  convert_value_from_python (PyObject *obj)
     }
   catch (const gdb_exception &except)
     {
-      gdbpy_convert_exception (except);
-      return NULL;
+      GDB_PY_HANDLE_EXCEPTION (except);
     }
 
   return value;
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 043c221b0d8..a2ce1f6545a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -972,8 +972,7 @@  gdbpy_decode_line (PyObject *self, PyObject *args)
   catch (const gdb_exception &ex)
     {
       /* We know this will always throw.  */
-      gdbpy_convert_exception (ex);
-      return NULL;
+      GDB_PY_HANDLE_EXCEPTION (ex);
     }
 
   if (!sals.empty ())