Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC][Python] gdbpy_frame_stop_reason_string bug
@ 2011-10-12 14:02 Kevin Pouget
  2011-10-12 14:33 ` Phil Muldoon
  2011-10-12 14:52 ` Pedro Alves
  0 siblings, 2 replies; 27+ messages in thread
From: Kevin Pouget @ 2011-10-12 14:02 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

Hi,

I wanted to discuss the best way to solve this bug before going any
further in the development:

> (gdb) py print gdb.frame_stop_reason_string(2)
> /home/kevin/travail/git/gdb/gdb/frame.c:2372: internal-error: Invalid frame stop reason
> A problem internal to GDB has been detected,further debugging may prove unreliable.


I prepared the attached patch, which requires to change
'internal_error' to a simple 'error' (I assume that it can't break
anything because it ends up calling `exit()', but I didn't check yet),

but "Frame.unwind_stop_reason ()" easily returns 'invalid frame stop
reason', for instance

> (gdb) start
> ...
> (gdb) pp gdb.newest_frame().unwind_stop_reason()
> 0

so I'm not convinced that it's the best solution.

Would it be better to return (in frame_stop_reason_string) a reason
for each value of "enum unwind_stop_reason reason", but breaking the
original intend of the `internal_error' call?

thanks for your comments,

Kevin

[-- Attachment #2: gdbpy_frame_stop_reason_string.patch --]
[-- Type: text/x-patch, Size: 1396 bytes --]

diff --git a/gdb/frame.c b/gdb/frame.c
index 5824020..1c1a18b 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2369,8 +2369,7 @@ frame_stop_reason_string (enum unwind_stop_reason reason)
     case UNWIND_NO_REASON:
     case UNWIND_FIRST_ERROR:
     default:
-      internal_error (__FILE__, __LINE__,
-		      "Invalid frame stop reason");
+      error (_("Invalid frame stop reason"));
     }
 }
 
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 75aa44e..2b95112 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -538,19 +538,20 @@ gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
 {
   int reason;
   const char *str;
+  PyObject *py_str_reason = NULL;
+  volatile struct gdb_exception except;
 
   if (!PyArg_ParseTuple (args, "i", &reason))
     return NULL;
 
-  if (reason < 0 || reason > UNWIND_NO_SAVED_PC)
+  TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      PyErr_SetString (PyExc_ValueError, 
-		       _("Invalid frame stop reason."));
-      return NULL;
+      str = frame_stop_reason_string (reason);
+      py_str_reason = PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
     }
+  GDB_PY_HANDLE_EXCEPTION (except);
 
-  str = frame_stop_reason_string (reason);
-  return PyUnicode_Decode (str, strlen (str), host_charset (), NULL);
+  return py_str_reason;
 }
 
 /* Implements the equality comparison for Frame objects.

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

end of thread, other threads:[~2011-10-27 11:10 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-12 14:02 [RFC][Python] gdbpy_frame_stop_reason_string bug Kevin Pouget
2011-10-12 14:33 ` Phil Muldoon
2011-10-12 14:52 ` Pedro Alves
2011-10-12 15:18   ` Kevin Pouget
2011-10-12 15:28     ` Phil Muldoon
2011-10-12 15:59       ` Pedro Alves
2011-10-12 17:07         ` Tom Tromey
2011-10-13 11:25           ` Kevin Pouget
2011-10-13 11:27             ` Kevin Pouget
2011-10-13 15:19               ` Pedro Alves
2011-10-14  8:18                 ` Kevin Pouget
2011-10-14 14:22                   ` Tom Tromey
2011-10-14 14:41                     ` Kevin Pouget
2011-10-14 15:00                       ` Pedro Alves
2011-10-17 10:31                         ` Kevin Pouget
2011-10-19 21:22                           ` Tom Tromey
2011-10-24 16:53                             ` Kevin Pouget
2011-10-25  0:59                               ` Eli Zaretskii
2011-10-25  8:31                                 ` Kevin Pouget
2011-10-25 12:49                                   ` Eli Zaretskii
2011-10-25 14:27                                     ` Kevin Pouget
2011-10-27 10:02                                       ` Kevin Pouget
2011-10-27 10:16                                         ` Eli Zaretskii
2011-10-27 12:11                                           ` Kevin Pouget
2011-10-12 15:31     ` Pedro Alves
2011-10-12 17:06     ` Tom Tromey
2011-10-12 17:00   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox