Hi All,

when trying to debug the gfortran frontend, I often get lost in the
forest: too much forest, trees everywhere, leaves, ...

OK, seriously, what is an efficient way to debug under e.g. gdb,
when there is code that uses macros on trees, like TREE_TYPE ()
etc., without losing your sanity?

I do know that there exists e.g. debug_tree, but this can dump a lot
of stuff on me.  And the comment at the top of gcc/print-tree.cc:

/* Prints out tree in human readable form - GCC

makes me feel non-human.  :-(

I was now thinking of writing helper functions, like:

diff --git a/gcc/fortran/dump-parse-tree.cc b/gcc/fortran/dump-parse-tree.cc
index eda0659d6e2..9156c440bcb 100644
--- a/gcc/fortran/dump-parse-tree.cc
+++ b/gcc/fortran/dump-parse-tree.cc
@@ -39,6 +39,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "parse.h"  /* For gfc_ascii_statement.  */
 #include "omp-api.h"  /* For omp_get_name_from_fr_id.  */
 #include "gomp-constants.h"  /* For GOMP_INTEROP_IFR_SEPARATOR.  */
+#include "tree.h"
+#include "print-tree.h"

 /* Keep track of indentation for symbol tree dumps.  */
 static int show_level = 0;
@@ -4670,3 +4672,10 @@ debug (gfc_array_ref *ar)
   fputc ('\n', dumpfile);
   dumpfile = tmp;
 }
+
+/* Helper function for looking at TREE_TYPE (node).  */
+DEBUG_FUNCTION void
+debug_tree_type (tree node)
+{
+  debug_tree (TREE_TYPE (node));
+}

This way I can do:

(gdb) call debug_tree_type(tree)

and get more concise output.  But the code uses the various macros
TREE_* also in nested form, so I would have to write a wrapper for
each combination that appears in the code.

So is there a better way?  There should be!

Thanks for any insight!

Harald



Reply via email to