This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Yet another tree dumper
- From: Devang Patel <dpatel at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 9 Oct 2003 18:16:47 -0700
- Subject: [PATCH] Yet another tree dumper
Most of the GCC developers use debug_tree() to debug GCC. It tries
to display as much info as possible. For example,
--- hello.c ---
#include <stdio.h>
int main()
{
printf ("Hello World\n");
}
---
(gdb) c
Breakpoint 1, finish_function () at
/Volumes/src/fsf.gcc/gcc/c-decl.c:6028
tree fndecl = current_function_decl;
(gdb) call debug_tree (current_function_decl)
<function_decl 0x7b6af8 main
type <function_type 0x7b6bd0
type <integer_type 0x40f47438 int SI
size <integer_cst 0x40f4521c constant 32>
unit size <integer_cst 0x40f452a8 constant 4>
align 32 symtab 0 alias set -1 precision 32 min
<integer_cst 0x40f45280 -2147483648> max <integer_cst 0x40f45294
2147483647>
pointer_to_this <pointer_type 0x40f51c3c>>
DI
size <integer_cst 0x40f455b4 constant 64>
unit size <integer_cst 0x40f457a8 constant 8>
align 64 symtab 0 alias set -1>
public static SI file h.c line 3 context <translation_unit_decl
0x40f470d8>
result <result_decl 0x7b6b64 type <integer_type 0x40f47438 int>
SI file h.c line 3 size <integer_cst 0x40f4521c 32> unit size
<integer_cst 0x40f452a8 4>
align 32> initial <block 0x40f461b8>
(mem:SI (symbol_ref:SI ("!T__main") [flags 0x3] <function_decl
0x7b6af8 main>) [0 S4 A8])
saved-insns 0x40f97800>
(gdb)
This patch introduces new tree dumper. Its main goals are:
- Produce more condensed display
- Display each node on single line (possibly line wrapped)
- Concentrate on tree nodes as opposed to RTL info
- Pay attention to where info is displayed on the screen
- More human readable
New tree dumper displays following for the above example
(gdb) call dmp_tree2(current_function_decl)
function_decl:0x7b6af8 t=0x7b6bd0 {function_type} line=3(h.c) pub
initial=0x40f461b8
saved-insns=0x40f97800 0x7b6b64(0x0){0x7b77bc}
cntxt=0x40f470d8
rtl=0x40ff60d8 main
result_decl:0x7b6b64 t=0x40f47438 {int} line=3
expr_stmt:0x7b77bc (dummy, to be deleted) 0x40f545f0
compound_stmt:0x7b77d0 line=3 0x7b77e4
scope_stmt:0x7b77e4 line=4 BEGIN block=0x40f461b8
block:0x40f461b8 vars=0x0 abs-orig=0x0 super=0x0 sub=0x0
frag-origin=0x0 frag-chain=0x0
expr_stmt:0x7b7924 line=4 0x7b8138
call_expr:0x7b8138 t=0x40f47438 {int} func=0x7b78ac args=0x7b78fc
addr_expr:0x7b78ac (func) t=0x7b6d80 {pointer_type} 0x7ac000
function_decl:0x7ac000 t=0x40f84654 {int} BUILT_IN_NORMAL
attr=0x40f7fcbc cntxt=0x40f470d8
rtl=0x40f70d5c printf
tree_list:0x7b78fc (args) purpose=0x0 value=0x7b78e8 chain=0x0
scope_stmt:0x7b7938 line=5 END block=0x40f461b8
(gdb)
Three functions are available to use from gdb. If require one can add
command line
interface. We are using this here at Apple for Darwin GCC 3.3
development. Today,
I ported it on FSF main trunk. I have done minimal tested to make sure
that its
behavior is OK for 3.4 changes.
dmp_tree(tree node) : Visit all nodes
dmp_tree1(tree node, int max_depth): Same as dmp_tree(), but limit the
nesting to
specified depth.
dmp_tree2(tree node): Same as dmp_tree() but never display a referenced
node more
than once.
Bootstrapped on powerpc-darwin using 'configure; make -j4 bootstrap'.
--
Devang
2003-10-09 Devang Patel <dpatel@apple.com>
* c-dmp-tree.c: New file.
* dmp-tree.c: New file.
* dmp-tree.h: New file.
* objc-dmp-tree.c: New file.
* Makefile.in (C_OBJS): Add c-dmp-tree.o.
(OBJS-common): Add dmp-tree.o.
(c-dmp-tree.o): New.
(dmp-tree.o): New.
* c-decl.c (c_init_decl_processing): set lang_dump_tree_p.
(dmp-tree.h): Include.
* c-lang.c (LANG_HOOKS_DUMP_DECL, LANG_HOOKS_DUMP_TYPE,
LANG_HOOKS_DUMP_IDENTIFIER, LANG_HOOKS_DUMP_BLANK_LINE_P,
LANG_HOOKS_DMP_LINENO_P, LANG_HOOKS_DMP_TREE3): New hooks.
* c-tree.h (c_dump_identifier, c_dump_decl, c_dump_type,
c_dump_blank_line_p, c_dump_lineno_p, c_dmp_tree3): New extern
decls.
* langhooks-def.h (LANG_HOOKS_DUMP_DECL, LANG_HOOKS_DUMP_TYPE,
LANG_HOOKS_DUMP_IDENTIFIER, LANG_HOOKS_DUMP_BLANK_LINE_P,
LANG_HOOKS_DMP_LINENO_P, LANG_HOOKS_DMP_TREE3): New hooks.
* langhoos.c (lhd_dump_tree_do_nothing): New.
(lhd_dump_tree_blank_line_do_nothing): New.
(lhd_dump_tree_lineno_do_nothing): New.
(lhd_dmp_tree3_do_nothing): New.
* langhooks.h (struct lang_hooks): New members for dmp_tree.
objc/Make-lang.in (OBJC_OBJS): Add objc-dmp-tree.o
(objc-dmp-tree.o): New rule.
* objc/objc-lang.c (LANG_HOOKS_DUMP_DECL, LANG_HOOKS_DUMP_TYPE,
LANG_HOOKS_DUMP_IDENTIFIER, LANG_HOOKS_DUMP_BLANK_LINE_P,
LANG_HOOKS_DMP_LINENO_P, LANG_HOOKS_DMP_TREE3): New hooks.
cp
* cp-dmp-tree.c: New file.
* Make-lang.in (CXX_OBJS): Add cp-dmp-tree.o
(cp/cp-dmp-tree.o): New rule.
* cp-tree.h: Add externs for dmp_tree.
* tree.c (init_tree): Init cp_dump_tree_p for dmp_tree.
Attachment:
dmp-tree.diff
Description: Binary data