Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Pouget <kevin.pouget@gmail.com>
To: Tom Tromey <tromey@redhat.com>, Pedro Alves <pedro@codesourcery.com>
Cc: pmuldoon@redhat.com, gdb-patches@sourceware.org
Subject: Re: [RFC][Python] gdbpy_frame_stop_reason_string bug
Date: Thu, 13 Oct 2011 11:27:00 -0000	[thread overview]
Message-ID: <CAPftXULJkmUscOtCDsJn=fZeBuE0V4DxmLzv2S1U=Py2yp=atQ@mail.gmail.com> (raw)
In-Reply-To: <CAPftXUJ55Ty2P1KzwojCGjuoNmGDzB+M26Uc5KGjxjgLnwOX=Q@mail.gmail.com>

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

On Thu, Oct 13, 2011 at 1:24 PM, Kevin Pouget <kevin.pouget@gmail.com> wrote:
> On Wed, Oct 12, 2011 at 7:06 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:
>>
>> Pedro> We should definitely reimplement these enums in a table in a
>> Pedro> .def file.  That's 2 places already that map the enums to
>> Pedro> something else.  This one is missing UNWIND_UNAVAILABLE.
>>
>> Makes sense to me.
>>
>> Pedro> And what do you think of making UNWIND_FIRST_ERROR
>> Pedro> an alias like in my patch?  Do you think that's likely
>> Pedro> to break anything?
>>
>> I think it would be fine.
>
>
> Hello,
>
> here is a patch which implements the enums in a .def file, as
> suggested earlier. Please let me know what you think about it (tested
> with no regression on X86_64)
>
> UNWIND_FIRST_ERROR is now an "enum alias", instead of being defined by
> the preprocessor (the only way I managed to implement it), as well as
> UNWIND_FIRST and UNWIND_LAST, used for bound-checking in py-frame.c
>
> I also moved the original enum comments to the .def file with no modification
>
>
> Thanks,
>
> Kevin

(with the file attached this time, sorry for the repost)

[-- Attachment #2: unwind_stop_reasons.def.patch --]
[-- Type: text/x-patch, Size: 5110 bytes --]

diff --git a/gdb/frame.c b/gdb/frame.c
index 5824020..70c372f 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2351,23 +2351,11 @@ frame_stop_reason_string (enum unwind_stop_reason reason)
 {
   switch (reason)
     {
-    case UNWIND_NULL_ID:
-      return _("unwinder did not report frame ID");
+#define SET(name, description) \
+    case name: return _(description);
+#include "gdb/unwind_stop_reasons.def"
+#undef SET
 
-    case UNWIND_UNAVAILABLE:
-      return _("Not enough registers or memory available to unwind further");
-
-    case UNWIND_INNER_ID:
-      return _("previous frame inner to this frame (corrupt stack?)");
-
-    case UNWIND_SAME_ID:
-      return _("previous frame identical to this frame (corrupt stack?)");
-
-    case UNWIND_NO_SAVED_PC:
-      return _("frame did not save the PC");
-
-    case UNWIND_NO_REASON:
-    case UNWIND_FIRST_ERROR:
     default:
       internal_error (__FILE__, __LINE__,
 		      "Invalid frame stop reason");
diff --git a/gdb/frame.h b/gdb/frame.h
index f5866bd..317714c 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -446,47 +446,16 @@ extern struct address_space *get_frame_address_space (struct frame_info *);
 
 enum unwind_stop_reason
   {
-    /* No particular reason; either we haven't tried unwinding yet,
-       or we didn't fail.  */
-    UNWIND_NO_REASON,
-
-    /* The previous frame's analyzer returns an invalid result
-       from this_id.
-
-       FIXME drow/2006-08-16: This is how GDB used to indicate end of
-       stack.  We should migrate to a model where frames always have a
-       valid ID, and this becomes not just an error but an internal
-       error.  But that's a project for another day.  */
-    UNWIND_NULL_ID,
-
-    /* This frame is the outermost.  */
-    UNWIND_OUTERMOST,
-
-    /* All the conditions after this point are considered errors;
-       abnormal stack termination.  If a backtrace stops for one
-       of these reasons, we'll let the user know.  This marker
-       is not a valid stop reason.  */
-    UNWIND_FIRST_ERROR,
-
-    /* Can't unwind further, because that would require knowing the
-       values of registers or memory that haven't been collected.  */
-    UNWIND_UNAVAILABLE,
-
-    /* This frame ID looks like it ought to belong to a NEXT frame,
-       but we got it for a PREV frame.  Normally, this is a sign of
-       unwinder failure.  It could also indicate stack corruption.  */
-    UNWIND_INNER_ID,
-
-    /* This frame has the same ID as the previous one.  That means
-       that unwinding further would almost certainly give us another
-       frame with exactly the same ID, so break the chain.  Normally,
-       this is a sign of unwinder failure.  It could also indicate
-       stack corruption.  */
-    UNWIND_SAME_ID,
-
-    /* The frame unwinder didn't find any saved PC, but we needed
-       one to unwind further.  */
-    UNWIND_NO_SAVED_PC,
+#define SET(name, description) name,
+#define FIRST_ENTRY(name) UNWIND_FIRST = name,
+#define LAST_ENTRY(name) UNWIND_LAST = name,
+#define FIRST_ERROR(name) UNWIND_FIRST_ERROR = name,
+
+#include "gdb/unwind_stop_reasons.def"
+#undef SET
+#undef FIRST_ENTRY
+#undef LAST_ENTRY
+#undef FIRST_ERROR
   };
 
 /* Return the reason why we can't unwind past this frame.  */
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 75aa44e..64388dd 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -542,7 +542,7 @@ gdbpy_frame_stop_reason_string (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "i", &reason))
     return NULL;
 
-  if (reason < 0 || reason > UNWIND_NO_SAVED_PC)
+  if (reason < UNWIND_FIRST || reason > UNWIND_LAST)
     {
       PyErr_SetString (PyExc_ValueError, 
 		       _("Invalid frame stop reason."));
@@ -585,6 +585,8 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)
 void
 gdbpy_initialize_frames (void)
 {
+  int unwind_cpt = 0;
+
   frame_object_type.tp_new = PyType_GenericNew;
   if (PyType_Ready (&frame_object_type) < 0)
     return;
@@ -599,18 +601,11 @@ gdbpy_initialize_frames (void)
   PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME", SIGTRAMP_FRAME);
   PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME);
   PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME", SENTINEL_FRAME);
-  PyModule_AddIntConstant (gdb_module,
-			   "FRAME_UNWIND_NO_REASON", UNWIND_NO_REASON);
-  PyModule_AddIntConstant (gdb_module,
-			   "FRAME_UNWIND_NULL_ID", UNWIND_NULL_ID);
-  PyModule_AddIntConstant (gdb_module,
-			   "FRAME_UNWIND_FIRST_ERROR", UNWIND_FIRST_ERROR);
-  PyModule_AddIntConstant (gdb_module,
-			   "FRAME_UNWIND_INNER_ID", UNWIND_INNER_ID);
-  PyModule_AddIntConstant (gdb_module,
-			   "FRAME_UNWIND_SAME_ID", UNWIND_SAME_ID);
-  PyModule_AddIntConstant (gdb_module,
-			   "FRAME_UNWIND_NO_SAVED_PC", UNWIND_NO_SAVED_PC);
+
+#define SET(name, description) \
+  PyModule_AddIntConstant (gdb_module, "FRAME_"#name, unwind_cpt++);
+#include "gdb/unwind_stop_reasons.def"
+#undef SET
 
   Py_INCREF (&frame_object_type);
   PyModule_AddObject (gdb_module, "Frame", (PyObject *) &frame_object_type);

  reply	other threads:[~2011-10-13 11:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12 14:02 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPftXULJkmUscOtCDsJn=fZeBuE0V4DxmLzv2S1U=Py2yp=atQ@mail.gmail.com' \
    --to=kevin.pouget@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@codesourcery.com \
    --cc=pmuldoon@redhat.com \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox