- success = py_print_frame (item, flags, args_type, out, 0,
- levels_printed);
+ gdbpy_ref<> item (PyIter_Next (iterable.get ()));
+
+ if (item == NULL)
+ {
+ if (PyErr_Occurred ())
+ {
+ gdbpy_print_stack_or_quit ();
+ return EXT_LANG_BT_ERROR;
+ }
+ break;
+ }
+
+ if (frame_countdown != -1)
+ {
+ gdb_assert ((flags & PRINT_MORE_FRAMES) != 0);
+ --frame_countdown;
+ if (frame_countdown == 0)
+ {
+ /* We've printed all the frames we were asked to
+ print, but more frames existed. */
+ printf_filtered (_("(More stack frames follow...)\n"));
+ break;
+ }
+ }
+
+ try
+ {
+ success = py_print_frame (item.get (), flags, args_type, out, 0,
+ levels_printed.get ());
+ }
+ catch (const gdb_exception_error &except)
+ {
+ gdbpy_convert_exception (except);
+ success = EXT_LANG_BT_ERROR;
+ }