Message ID | f6b5ec65-2f51-c66d-acc1-af182e3ca2fb@redhat.com |
---|---|
State | New |
Headers | show |
Series | PING Fwd: [patch] implement generic debug() for vectors and hash sets | expand |
On 10/23/2017 03:44 AM, Aldy Hernandez wrote: > > > > -------- Forwarded Message -------- > Subject: [patch] implement generic debug() for vectors and hash sets > Date: Mon, 16 Oct 2017 09:52:51 -0400 > From: Aldy Hernandez <aldyh@redhat.com> > To: gcc-patches <gcc-patches@gcc.gnu.org> > > We have a generic mechanism for dumping types from the debugger with: > > (gdb) call debug(some_type) > > However, even though most types are implemented, we have no canonical > way of dumping vectors or hash sets. > > The attached patch fixes this oversight. With it you can call > debug(vec<>) and debug(hash_set<>) with the following types: rtx, > tree, basic_block, edge, rtx_insn. More can be added simply by adding > a debug_slim(your_type) overload and calling: > > DEFINE_DEBUG_VEC (your_type) > DEFINE_DEBUG_HASH_SET (your_type) > > Here is an example of how things look with this patch: > > vec of edges: > [0] = <edge 0x0x7f3f81c0d700 (6 -> 10)> > > vec of bbs: > [0] = <basic_block 0x7f3f81ac9410 (6)> > [1] = <basic_block 0x7f3f81ac96e8 (10)> > > vec of trees: > [0] = <integer_type 0x7f3f81ad55e8 int> > [1] = <integer_type 0x7f3f81ad5498 short int> > [2] = <integer_cst 0x7f3f81ada078 0> > > vec of rtx: > [0] = (reg:SI 87) > [1] = (reg:SI 87) > > hash of bbs: > <basic_block 0x7f3f81ac96e8 (10)> > <basic_block 0x7f3f81ac9410 (6)> > > OK for mainline? > > > curr.patch > > > gcc/ > > * vec.h (debug_helper): New function. > (DEFINE_DEBUG_VEC): New macro. > * hash-set.h (debug_helper): New function. > (DEFINE_DEBUG_HASH_SET): New macro. > * cfg.c (debug_slim (edge)): New function. > Call DEFINE_DEBUG_VEC for edges. > Call DEFINE_DEBUG_HASH_SET for edges. > * cfghooks.c (debug_slim (basic_block)): New function. > Call DEFINE_DEBUG_VEC for basic blocks. > Call DEFINE_DEBUG_HASH_SET for basic blocks. > * print-tree.c (debug_slim): New function to handle trees. > Call DEFINE_DEBUG_VEC for trees. > Call DEFINE_DEBUG_HASH_SET for trees. > (debug (vec<tree, va_gc>) &): Remove. > (debug (<vec<tree, va_gc>) *): Remove. > * print-rtl.c (debug_slim): New function to handle const_rtx. > Call DEFINE_DEBUG_VEC for rtx_def. > Call DEFINE_DEBUG_VEC for rtx_insn. > Call DEFINE_DEBUG_HASH_SET for rtx_def. > Call DEFINE_DEBUG_HASH_SET for rtx_insn. > * sel-sched-dump.c (debug (vec<rtx_insn *> &): Remove. > (debug (vec<rtx_insn *> *ptr): Remove. > (debug_insn_vector): Remove. > * stor-layout.c (debug_rli): Call debug() instead of debug_vec_tree. OK. jeff
Minor oversight... debug_vec_tree() no longer exist. I forgot to remove the prototype. Also, gdbinit.in has a macro that uses it, but this is no longer necessary as we can print tree vectors generically with "print debug(xxx)". Applied as obvious. Aldy On Sun, Nov 19, 2017 at 5:45 PM, Jeff Law <law@redhat.com> wrote: > On 10/23/2017 03:44 AM, Aldy Hernandez wrote: >> >> >> >> -------- Forwarded Message -------- >> Subject: [patch] implement generic debug() for vectors and hash sets >> Date: Mon, 16 Oct 2017 09:52:51 -0400 >> From: Aldy Hernandez <aldyh@redhat.com> >> To: gcc-patches <gcc-patches@gcc.gnu.org> >> >> We have a generic mechanism for dumping types from the debugger with: >> >> (gdb) call debug(some_type) >> >> However, even though most types are implemented, we have no canonical >> way of dumping vectors or hash sets. >> >> The attached patch fixes this oversight. With it you can call >> debug(vec<>) and debug(hash_set<>) with the following types: rtx, >> tree, basic_block, edge, rtx_insn. More can be added simply by adding >> a debug_slim(your_type) overload and calling: >> >> DEFINE_DEBUG_VEC (your_type) >> DEFINE_DEBUG_HASH_SET (your_type) >> >> Here is an example of how things look with this patch: >> >> vec of edges: >> [0] = <edge 0x0x7f3f81c0d700 (6 -> 10)> >> >> vec of bbs: >> [0] = <basic_block 0x7f3f81ac9410 (6)> >> [1] = <basic_block 0x7f3f81ac96e8 (10)> >> >> vec of trees: >> [0] = <integer_type 0x7f3f81ad55e8 int> >> [1] = <integer_type 0x7f3f81ad5498 short int> >> [2] = <integer_cst 0x7f3f81ada078 0> >> >> vec of rtx: >> [0] = (reg:SI 87) >> [1] = (reg:SI 87) >> >> hash of bbs: >> <basic_block 0x7f3f81ac96e8 (10)> >> <basic_block 0x7f3f81ac9410 (6)> >> >> OK for mainline? >> >> >> curr.patch >> >> >> gcc/ >> >> * vec.h (debug_helper): New function. >> (DEFINE_DEBUG_VEC): New macro. >> * hash-set.h (debug_helper): New function. >> (DEFINE_DEBUG_HASH_SET): New macro. >> * cfg.c (debug_slim (edge)): New function. >> Call DEFINE_DEBUG_VEC for edges. >> Call DEFINE_DEBUG_HASH_SET for edges. >> * cfghooks.c (debug_slim (basic_block)): New function. >> Call DEFINE_DEBUG_VEC for basic blocks. >> Call DEFINE_DEBUG_HASH_SET for basic blocks. >> * print-tree.c (debug_slim): New function to handle trees. >> Call DEFINE_DEBUG_VEC for trees. >> Call DEFINE_DEBUG_HASH_SET for trees. >> (debug (vec<tree, va_gc>) &): Remove. >> (debug (<vec<tree, va_gc>) *): Remove. >> * print-rtl.c (debug_slim): New function to handle const_rtx. >> Call DEFINE_DEBUG_VEC for rtx_def. >> Call DEFINE_DEBUG_VEC for rtx_insn. >> Call DEFINE_DEBUG_HASH_SET for rtx_def. >> Call DEFINE_DEBUG_HASH_SET for rtx_insn. >> * sel-sched-dump.c (debug (vec<rtx_insn *> &): Remove. >> (debug (vec<rtx_insn *> *ptr): Remove. >> (debug_insn_vector): Remove. >> * stor-layout.c (debug_rli): Call debug() instead of debug_vec_tree. > OK. > jeff gcc/ * print-tree.h (debug_vec_tree): Remove prototype. * gdbinit.in (pvt): Remove macro. diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in index ebdeaf0f2c9..9e9485b0adf 100644 --- a/gcc/gdbinit.in +++ b/gcc/gdbinit.in @@ -130,14 +130,6 @@ document ptn Print the name of the type-node that is $. end -define pvt -set debug_vec_tree ($) -end - -document pvt -Print the VEC(tree) that is in $. -end - define pdd set debug_dwarf_die ($) end diff --git a/gcc/print-tree.h b/gcc/print-tree.h index 29efc071c53..1707665939a 100644 --- a/gcc/print-tree.h +++ b/gcc/print-tree.h @@ -31,7 +31,6 @@ extern void debug_head (const tree_node &ref); extern void debug_head (const tree_node *ptr); extern void debug_body (const tree_node &ref); extern void debug_body (const tree_node *ptr); -extern void debug_vec_tree (vec<tree, va_gc> *); extern void debug (vec<tree, va_gc> &ref); extern void debug (vec<tree, va_gc> *ptr); extern void debug_raw (vec<tree, va_gc> &ref);
On Mon, 20 Nov 2017, Aldy Hernandez wrote:
> Minor oversight...
Actually, there appears to be another issue related to this when
bootstrapping with clang 3.4.1 (FreeBSD 10.4):
/scratch/tmp/gerald/GCC-HEAD/gcc/print-rtl.c:982:1: error: explicit instantiation cannot have a storage class
DEFINE_DEBUG_VEC (rtx_def *)
^
/scratch/tmp/gerald/GCC-HEAD/gcc/vec.h:456:24: note: expanded from macro 'DEFINE_DEBUG_VEC'
template static void debug_helper (vec<T> &); \
^
The first failing boostrap seems to have been yesterday at 16:40 UTC,
24 hours before it still worked.
Gerald
On 11/21/2017 05:59 AM, Gerald Pfeifer wrote: > On Mon, 20 Nov 2017, Aldy Hernandez wrote: >> Minor oversight... > > Actually, there appears to be another issue related to this when > bootstrapping with clang 3.4.1 (FreeBSD 10.4): I have no idea how to bootstrap with clang :). Perhaps someone can throw a hint. I found a machine with clang, which seemed to compile hello worlds both for C and C++: $ clang -v clang version 3.8.1 (tags/RELEASE_381/final) Target: x86_64-unknown-linux-gnu ... Then I tried either this: CC=clang CXX=clang++ /blah/configure or this: /blah/configure CC=clang CXX=clang++ ...with numerous problems building stage1, among which are: make[3]: Entering directory '/opt/notnfs/aldyh/bld/trunk-with-clang/gcc' clang++ -std=gnu++98 -c -g -DIN_GCC -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE -fno-PIE -I. -Ibuild -I/home/cygnus/aldyh/src/gcc-pristine/gcc -I/home/cygnus/aldyh/src/gcc-pristine/gcc/build -I/home/cygnus/aldyh/src/gcc-pristine/gcc/../include -I/home/cygnus/aldyh/src/gcc-pristine/gcc/../libcpp/include \ -o build/print-rtl.o /home/cygnus/aldyh/src/gcc-pristine/gcc/print-rtl.c clang-3.8: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated In file included from /home/cygnus/aldyh/src/gcc-pristine/gcc/print-rtl.c:29: /home/cygnus/aldyh/src/gcc-pristine/gcc/coretypes.h:73:1: warning: class 'rtx_def' was previously declared as a struct [-Wmismatched-tags] class rtx_def; ^ /home/cygnus/aldyh/src/gcc-pristine/gcc/coretypes.h:55:8: note: previous use is here struct rtx_def; ^ In file included from /home/cygnus/aldyh/src/gcc-pristine/gcc/print-rtl.c:29: In file included from /home/cygnus/aldyh/src/gcc-pristine/gcc/coretypes.h:400: /home/cygnus/aldyh/src/gcc-pristine/gcc/machmode.h:313:1: warning: 'pod_mode' defined as a struct template here but previously declared as a class template [-Wmismatched-tags] struct pod_mode ^ /home/cygnus/aldyh/src/gcc-pristine/gcc/coretypes.h:66:20: note: did you mean struct here? template<typename> class pod_mode; ^~~~~ struct Is there a magic set of flags I should use? Aldy
On Tue, 21 Nov 2017, Aldy Hernandez wrote: > I have no idea how to bootstrap with clang :). Perhaps someone can > throw a hint. It just works. Usually. :-) I run two testers, one nightly, one weekly, on a FreeBSD.org cluster, one with clang 3.4 the other with clang 4.0 right now, and while both issue tons of warnings -- what you shared looks pretty familiar -- apart from the breakage I now reported it just works. No magic flags or anything. In fact, at one point one machine was upgraded from a GCC 4.x system compiler to clang 3.4 and things just kept working. > ...with numerous problems building stage1, among which are: You can safely ignore those. Just make sure there's no -Werror or similar in your environment. Gerald
On Tue, 21 Nov 2017, Gerald Pfeifer wrote: > /scratch/tmp/gerald/GCC-HEAD/gcc/print-rtl.c:982:1: error: explicit instantiation cannot have a storage class > DEFINE_DEBUG_VEC (rtx_def *) > ^ > /scratch/tmp/gerald/GCC-HEAD/gcc/vec.h:456:24: note: expanded from macro 'DEFINE_DEBUG_VEC' > template static void debug_helper (vec<T> &); \ > ^ > > The first failing boostrap seems to have been yesterday at 16:40 UTC, > 24 hours before it still worked. This fixes it for me; bootstrapped&tested on i586-unknown-freebsd10.4 (and compared with the last successbuild on the 19th). Okay? Gerald 2017-11-23 Gerald Pfeifer <gerald@pfeifer.com> * hash-set.h (DEFINE_DEBUG_HASH_SET): Remove static qualifier from explicit instantiation of debug_helper. * vec.h (DEFINE_DEBUG_VEC): Ditto. Index: hash-set.h =================================================================== --- hash-set.h (revision 255092) +++ hash-set.h (working copy) @@ -150,7 +150,7 @@ } #define DEFINE_DEBUG_HASH_SET(T) \ - template static void debug_helper (hash_set<T> &); \ + template void debug_helper (hash_set<T> &); \ DEBUG_FUNCTION void \ debug (hash_set<T> &ref) \ { \ Index: vec.h =================================================================== --- vec.h (revision 255092) +++ vec.h (working copy) @@ -453,8 +453,8 @@ functions for a type T. */ #define DEFINE_DEBUG_VEC(T) \ - template static void debug_helper (vec<T> &); \ - template static void debug_helper (vec<T, va_gc> &); \ + template void debug_helper (vec<T> &); \ + template void debug_helper (vec<T, va_gc> &); \ /* Define the vec<T> debug functions. */ \ DEBUG_FUNCTION void \ debug (vec<T> &ref) \
On 11/23/2017 02:12 PM, Gerald Pfeifer wrote: > On Tue, 21 Nov 2017, Gerald Pfeifer wrote: >> /scratch/tmp/gerald/GCC-HEAD/gcc/print-rtl.c:982:1: error: explicit instantiation cannot have a storage class >> DEFINE_DEBUG_VEC (rtx_def *) >> ^ >> /scratch/tmp/gerald/GCC-HEAD/gcc/vec.h:456:24: note: expanded from macro 'DEFINE_DEBUG_VEC' >> template static void debug_helper (vec<T> &); \ >> ^ >> >> The first failing boostrap seems to have been yesterday at 16:40 UTC, >> 24 hours before it still worked. > > This fixes it for me; bootstrapped&tested on i586-unknown-freebsd10.4 > (and compared with the last successbuild on the 19th). Sorry for dropping the ball on this over the US holidays. This looks good to me, though I can't approve. Thanks. > > Okay? > > Gerald > > > 2017-11-23 Gerald Pfeifer <gerald@pfeifer.com> > > * hash-set.h (DEFINE_DEBUG_HASH_SET): Remove static qualifier > from explicit instantiation of debug_helper. > * vec.h (DEFINE_DEBUG_VEC): Ditto. > > Index: hash-set.h > =================================================================== > --- hash-set.h (revision 255092) > +++ hash-set.h (working copy) > @@ -150,7 +150,7 @@ > } > > #define DEFINE_DEBUG_HASH_SET(T) \ > - template static void debug_helper (hash_set<T> &); \ > + template void debug_helper (hash_set<T> &); \ > DEBUG_FUNCTION void \ > debug (hash_set<T> &ref) \ > { \ > Index: vec.h > =================================================================== > --- vec.h (revision 255092) > +++ vec.h (working copy) > @@ -453,8 +453,8 @@ > functions for a type T. */ > > #define DEFINE_DEBUG_VEC(T) \ > - template static void debug_helper (vec<T> &); \ > - template static void debug_helper (vec<T, va_gc> &); \ > + template void debug_helper (vec<T> &); \ > + template void debug_helper (vec<T, va_gc> &); \ > /* Define the vec<T> debug functions. */ \ > DEBUG_FUNCTION void \ > debug (vec<T> &ref) \ >
On 11/27/2017 08:03 AM, Aldy Hernandez wrote: > > > On 11/23/2017 02:12 PM, Gerald Pfeifer wrote: >> On Tue, 21 Nov 2017, Gerald Pfeifer wrote: >>> /scratch/tmp/gerald/GCC-HEAD/gcc/print-rtl.c:982:1: error: explicit >>> instantiation cannot have a storage class >>> DEFINE_DEBUG_VEC (rtx_def *) >>> ^ >>> /scratch/tmp/gerald/GCC-HEAD/gcc/vec.h:456:24: note: expanded from >>> macro 'DEFINE_DEBUG_VEC' >>> template static void debug_helper (vec<T> &); \ >>> ^ >>> >>> The first failing boostrap seems to have been yesterday at 16:40 UTC, >>> 24 hours before it still worked. >> >> This fixes it for me; bootstrapped&tested on i586-unknown-freebsd10.4 >> (and compared with the last successbuild on the 19th). > > Sorry for dropping the ball on this over the US holidays. > > This looks good to me, though I can't approve. > > Thanks. > >> >> Okay? >> >> Gerald >> >> >> 2017-11-23 Gerald Pfeifer <gerald@pfeifer.com> >> >> * hash-set.h (DEFINE_DEBUG_HASH_SET): Remove static qualifier >> from explicit instantiation of debug_helper. >> * vec.h (DEFINE_DEBUG_VEC): Ditto. OK. I must have missed this... jeff
On Mon, Nov 20, 2017 at 6:47 AM, Aldy Hernandez <aldyh@redhat.com> wrote: > Minor oversight... > > debug_vec_tree() no longer exist. I forgot to remove the prototype. > > Also, gdbinit.in has a macro that uses it, but this is no longer > necessary as we can print tree vectors generically with "print > debug(xxx)". But that's a lot more to type than "pvt".... Jason
gcc/ * vec.h (debug_helper): New function. (DEFINE_DEBUG_VEC): New macro. * hash-set.h (debug_helper): New function. (DEFINE_DEBUG_HASH_SET): New macro. * cfg.c (debug_slim (edge)): New function. Call DEFINE_DEBUG_VEC for edges. Call DEFINE_DEBUG_HASH_SET for edges. * cfghooks.c (debug_slim (basic_block)): New function. Call DEFINE_DEBUG_VEC for basic blocks. Call DEFINE_DEBUG_HASH_SET for basic blocks. * print-tree.c (debug_slim): New function to handle trees. Call DEFINE_DEBUG_VEC for trees. Call DEFINE_DEBUG_HASH_SET for trees. (debug (vec<tree, va_gc>) &): Remove. (debug (<vec<tree, va_gc>) *): Remove. * print-rtl.c (debug_slim): New function to handle const_rtx. Call DEFINE_DEBUG_VEC for rtx_def. Call DEFINE_DEBUG_VEC for rtx_insn. Call DEFINE_DEBUG_HASH_SET for rtx_def. Call DEFINE_DEBUG_HASH_SET for rtx_insn. * sel-sched-dump.c (debug (vec<rtx_insn *> &): Remove. (debug (vec<rtx_insn *> *ptr): Remove. (debug_insn_vector): Remove. * stor-layout.c (debug_rli): Call debug() instead of debug_vec_tree. diff --git a/gcc/cfg.c b/gcc/cfg.c index 01e68aeda51..4d02fb56cbf 100644 --- a/gcc/cfg.c +++ b/gcc/cfg.c @@ -573,6 +573,16 @@ debug (edge_def *ptr) else fprintf (stderr, "<nil>\n"); } + +static void +debug_slim (edge e) +{ + fprintf (stderr, "<edge 0x%p (%d -> %d)>", (void *) e, + e->src->index, e->dest->index); +} + +DEFINE_DEBUG_VEC (edge) +DEFINE_DEBUG_HASH_SET (edge) /* Simple routines to easily allocate AUX fields of basic blocks. */ diff --git a/gcc/cfghooks.c b/gcc/cfghooks.c index 258a5eabf8d..73b196feec7 100644 --- a/gcc/cfghooks.c +++ b/gcc/cfghooks.c @@ -304,6 +304,14 @@ debug (basic_block_def *ptr) fprintf (stderr, "<nil>\n"); } +static void +debug_slim (basic_block ptr) +{ + fprintf (stderr, "<basic_block %p (%d)>", (void *) ptr, ptr->index); +} + +DEFINE_DEBUG_VEC (basic_block_def *) +DEFINE_DEBUG_HASH_SET (basic_block_def *) /* Dumps basic block BB to pretty-printer PP, for use as a label of a DOT graph record-node. The implementation of this hook is diff --git a/gcc/hash-set.h b/gcc/hash-set.h index d2247d39571..58f7750243a 100644 --- a/gcc/hash-set.h +++ b/gcc/hash-set.h @@ -123,6 +123,44 @@ private: hash_table<Traits> m_table; }; +/* Generic hash_set<TYPE> debug helper. + + This needs to be instantiated for each hash_set<TYPE> used throughout + the compiler like this: + + DEFINE_DEBUG_HASH_SET (TYPE) + + The reason we have a debug_helper() is because GDB can't + disambiguate a plain call to debug(some_hash), and it must be called + like debug<TYPE>(some_hash). */ +template<typename T> +void +debug_helper (hash_set<T> &ref) +{ + for (typename hash_set<T>::iterator it = ref.begin (); + it != ref.end (); ++it) + { + debug_slim (*it); + fputc ('\n', stderr); + } +} + +#define DEFINE_DEBUG_HASH_SET(T) \ + template static void debug_helper (hash_set<T> &); \ + DEBUG_FUNCTION void \ + debug (hash_set<T> &ref) \ + { \ + debug_helper <T> (ref); \ + } \ + DEBUG_FUNCTION void \ + debug (hash_set<T> *ptr) \ + { \ + if (ptr) \ + debug (*ptr); \ + else \ + fprintf (stderr, "<nil>\n"); \ + } + /* ggc marking routines. */ template<typename K, typename H> diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c index 28d99862cad..5fe23801ab2 100644 --- a/gcc/print-rtl.c +++ b/gcc/print-rtl.c @@ -967,6 +967,23 @@ debug (const rtx_def *ptr) fprintf (stderr, "<nil>\n"); } +/* Like debug_rtx but with no newline, as debug_helper will add one. + + Note: No debug_slim(rtx_insn *) variant implemented, as this + function can serve for both rtx and rtx_insn. */ + +static void +debug_slim (const_rtx x) +{ + rtx_writer w (stderr, 0, false, false, NULL); + w.print_rtx (x); +} + +DEFINE_DEBUG_VEC (rtx_def *) +DEFINE_DEBUG_VEC (rtx_insn *) +DEFINE_DEBUG_HASH_SET (rtx_def *) +DEFINE_DEBUG_HASH_SET (rtx_insn *) + /* Count of rtx's to print with debug_rtx_list. This global exists because gdb user defined commands have no arguments. */ diff --git a/gcc/print-tree.c b/gcc/print-tree.c index d534c76ee49..3a0f85d4038 100644 --- a/gcc/print-tree.c +++ b/gcc/print-tree.c @@ -1095,32 +1095,6 @@ debug_raw (vec<tree, va_gc> &ref) } DEBUG_FUNCTION void -debug (vec<tree, va_gc> &ref) -{ - tree elt; - unsigned ix; - - /* Print the slot this node is in, and its code, and address. */ - fprintf (stderr, "<VEC"); - dump_addr (stderr, " ", ref.address ()); - - FOR_EACH_VEC_ELT (ref, ix, elt) - { - fprintf (stderr, "elt:%d ", ix); - debug (elt); - } -} - -DEBUG_FUNCTION void -debug (vec<tree, va_gc> *ptr) -{ - if (ptr) - debug (*ptr); - else - fprintf (stderr, "<nil>\n"); -} - -DEBUG_FUNCTION void debug_raw (vec<tree, va_gc> *ptr) { if (ptr) @@ -1129,8 +1103,11 @@ debug_raw (vec<tree, va_gc> *ptr) fprintf (stderr, "<nil>\n"); } -DEBUG_FUNCTION void -debug_vec_tree (vec<tree, va_gc> *vec) +static void +debug_slim (tree t) { - debug_raw (vec); + print_node_brief (stderr, "", t, 0); } + +DEFINE_DEBUG_VEC (tree) +DEFINE_DEBUG_HASH_SET (tree) diff --git a/gcc/sel-sched-dump.c b/gcc/sel-sched-dump.c index 388a8af54c6..027b6b1c7c6 100644 --- a/gcc/sel-sched-dump.c +++ b/gcc/sel-sched-dump.c @@ -989,35 +989,6 @@ debug_blist (blist_t bnds) restore_dump (); } -/* Dump a rtx vector REF. */ -DEBUG_FUNCTION void -debug (vec<rtx_insn *> &ref) -{ - switch_dump (stderr); - dump_insn_vector (ref); - sel_print ("\n"); - restore_dump (); -} - -DEBUG_FUNCTION void -debug (vec<rtx_insn *> *ptr) -{ - if (ptr) - debug (*ptr); - else - fprintf (stderr, "<nil>\n"); -} - -/* Dump an insn vector SUCCS. */ -DEBUG_FUNCTION void -debug_insn_vector (rtx_vec_t succs) -{ - switch_dump (stderr); - dump_insn_vector (succs); - sel_print ("\n"); - restore_dump (); -} - /* Dump a hard reg set SET to stderr. */ DEBUG_FUNCTION void debug_hard_reg_set (HARD_REG_SET set) diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 02739b0ed7f..9577cfa47ef 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -941,7 +941,7 @@ debug_rli (record_layout_info rli) if (!vec_safe_is_empty (rli->pending_statics)) { fprintf (stderr, "pending statics:\n"); - debug_vec_tree (rli->pending_statics); + debug (rli->pending_statics); } } diff --git a/gcc/vec.h b/gcc/vec.h index cbdd439571b..b145eef2bc7 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -407,6 +407,83 @@ struct GTY((user)) vec { }; +/* Generic vec<> debug helpers. + + These need to be instantiated for each vec<TYPE> used throughout + the compiler like this: + + DEFINE_DEBUG_VEC (TYPE) + + The reason we have a debug_helper() is because GDB can't + disambiguate a plain call to debug(some_vec), and it must be called + like debug<TYPE>(some_vec). */ + +template<typename T> +void +debug_helper (vec<T> &ref) +{ + unsigned i; + for (i = 0; i < ref.length (); ++i) + { + fprintf (stderr, "[%d] = ", i); + debug_slim (ref[i]); + fputc ('\n', stderr); + } +} + +/* We need a separate va_gc variant here because default template + argument for functions cannot be used in c++-98. Once this + restriction is removed, those variant should be folded with the + above debug_helper. */ + +template<typename T> +void +debug_helper (vec<T, va_gc> &ref) +{ + unsigned i; + for (i = 0; i < ref.length (); ++i) + { + fprintf (stderr, "[%d] = ", i); + debug_slim (ref[i]); + fputc ('\n', stderr); + } +} + +/* Macro to define debug(vec<T>) and debug(vec<T, va_gc>) helper + functions for a type T. */ + +#define DEFINE_DEBUG_VEC(T) \ + template static void debug_helper (vec<T> &); \ + template static void debug_helper (vec<T, va_gc> &); \ + /* Define the vec<T> debug functions. */ \ + DEBUG_FUNCTION void \ + debug (vec<T> &ref) \ + { \ + debug_helper <T> (ref); \ + } \ + DEBUG_FUNCTION void \ + debug (vec<T> *ptr) \ + { \ + if (ptr) \ + debug (*ptr); \ + else \ + fprintf (stderr, "<nil>\n"); \ + } \ + /* Define the vec<T, va_gc> debug functions. */ \ + DEBUG_FUNCTION void \ + debug (vec<T, va_gc> &ref) \ + { \ + debug_helper <T> (ref); \ + } \ + DEBUG_FUNCTION void \ + debug (vec<T, va_gc> *ptr) \ + { \ + if (ptr) \ + debug (*ptr); \ + else \ + fprintf (stderr, "<nil>\n"); \ + } + /* Default-construct N elements in DST. */ template <typename T>
-------- Forwarded Message -------- Subject: [patch] implement generic debug() for vectors and hash sets Date: Mon, 16 Oct 2017 09:52:51 -0400 From: Aldy Hernandez <aldyh@redhat.com> To: gcc-patches <gcc-patches@gcc.gnu.org> We have a generic mechanism for dumping types from the debugger with: (gdb) call debug(some_type) However, even though most types are implemented, we have no canonical way of dumping vectors or hash sets. The attached patch fixes this oversight. With it you can call debug(vec<>) and debug(hash_set<>) with the following types: rtx, tree, basic_block, edge, rtx_insn. More can be added simply by adding a debug_slim(your_type) overload and calling: DEFINE_DEBUG_VEC (your_type) DEFINE_DEBUG_HASH_SET (your_type) Here is an example of how things look with this patch: vec of edges: [0] = <edge 0x0x7f3f81c0d700 (6 -> 10)> vec of bbs: [0] = <basic_block 0x7f3f81ac9410 (6)> [1] = <basic_block 0x7f3f81ac96e8 (10)> vec of trees: [0] = <integer_type 0x7f3f81ad55e8 int> [1] = <integer_type 0x7f3f81ad5498 short int> [2] = <integer_cst 0x7f3f81ada078 0> vec of rtx: [0] = (reg:SI 87) [1] = (reg:SI 87) hash of bbs: <basic_block 0x7f3f81ac96e8 (10)> <basic_block 0x7f3f81ac9410 (6)> OK for mainline?