gdb: Introduce 'print max-depth' feature
[deliverable/binutils-gdb.git] / gdb / python / py-prettyprint.c
index e64d1f88af892c38b7a2b97a572f62a25cada696..fdc520d84432a8bee1cfc59901176ab10914848e 100644 (file)
@@ -190,7 +190,7 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
   gdbpy_ref<> result;
 
   *out_value = NULL;
-  TRY
+  try
     {
       if (!PyObject_HasAttr (printer, gdbpy_to_string_cst))
        result = gdbpy_ref<>::new_reference (Py_None);
@@ -212,10 +212,9 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
            }
        }
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const gdb_exception &except)
     {
     }
-  END_CATCH
 
   return result;
 }
@@ -518,7 +517,17 @@ print_children (PyObject *printer, const char *hint,
              error (_("Error while executing Python code."));
            }
          else
-           common_val_print (value, stream, recurse + 1, options, language);
+           {
+             /* When printing the key of a map we allow one additional
+                level of depth.  This means the key will print before the
+                value does.  */
+             struct value_print_options opt = *options;
+             if (is_map && i % 2 == 0
+                 && opt.max_depth != -1
+                 && opt.max_depth < INT_MAX)
+               ++opt.max_depth;
+             common_val_print (value, stream, recurse + 1, &opt, language);
+           }
        }
 
       if (is_map && i % 2 == 0)
@@ -591,6 +600,9 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
   if (printer == Py_None)
     return EXT_LANG_RC_NOP;
 
+  if (val_print_check_max_depth (stream, recurse, options, language))
+    return EXT_LANG_RC_OK;
+
   /* If we are printing a map, we want some special formatting.  */
   gdb::unique_xmalloc_ptr<char> hint (gdbpy_get_display_hint (printer.get ()));
 
@@ -637,15 +649,14 @@ apply_varobj_pretty_printer (PyObject *printer_obj,
 gdbpy_ref<>
 gdbpy_get_varobj_pretty_printer (struct value *value)
 {
-  TRY
+  try
     {
       value = value_copy (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   gdbpy_ref<> val_obj (value_to_value_object (value));
   if (val_obj == NULL)
This page took 0.025641 seconds and 4 git commands to generate.